| 1 | package boot |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | |
| 7 | "reasonix/internal/config" |
| 8 | "reasonix/internal/provider" |
| 9 | ) |
| 10 | |
| 11 | func TestAuxiliaryProviderPluginName(t *testing.T) { |
| 12 | for _, test := range []struct { |
| 13 | ref, want string |
| 14 | }{ |
| 15 | {"plugin/providerdemo/fake/x", "providerdemo"}, |
| 16 | {"plugin/providerdemo/fake", ""}, |
| 17 | {"openai/gpt-5", ""}, |
| 18 | {"", ""}, |
| 19 | } { |
| 20 | if got := auxiliaryProviderPluginName(test.ref); got != test.want { |
| 21 | t.Fatalf("auxiliaryProviderPluginName(%q) = %q, want %q", test.ref, got, test.want) |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | func TestAcquireAuxiliaryProviderConfigModelNeedsNoExtensionRuntime(t *testing.T) { |
| 27 | cfg := &config.Config{ |
| 28 | DefaultModel: "test/title-model", |
| 29 | Providers: []config.ProviderEntry{{ |
| 30 | Name: "test", Kind: "openai", Model: "title-model", |
| 31 | BaseURL: "https://example.invalid", |
| 32 | }}, |
| 33 | } |
| 34 | handle, err := AcquireAuxiliaryProvider(t.Context(), AuxiliaryProviderRequest{ |
| 35 | Config: cfg, SessionID: "cold-session", WorkspaceRoot: t.TempDir(), ModelRef: "test/title-model", |
| 36 | }) |
| 37 | if err != nil { |
| 38 | t.Fatal(err) |
| 39 | } |
| 40 | t.Cleanup(func() { _ = handle.Close() }) |
| 41 | if handle.manager != nil { |
| 42 | t.Fatal("config-backed auxiliary provider started extension sidecars") |
| 43 | } |
| 44 | if _, err := handle.Resolver.Resolve(provider.Selection{Ref: "test/title-model"}); err != nil { |
| 45 | t.Fatalf("resolve config-backed model: %v", err) |
| 46 | } |
| 47 | if err := handle.Close(); err != nil { |
| 48 | t.Fatal(err) |
| 49 | } |
| 50 | if err := handle.Close(); err != nil { |
| 51 | t.Fatalf("second Close must be idempotent: %v", err) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | func TestAcquireAuxiliaryProviderRejectsUnavailableRecordedModel(t *testing.T) { |
| 56 | cfg := &config.Config{ |
| 57 | DefaultModel: "test/title-model", |
| 58 | Providers: []config.ProviderEntry{{ |
| 59 | Name: "test", Kind: "openai", Model: "title-model", |
| 60 | BaseURL: "https://example.invalid", |
| 61 | }}, |
| 62 | } |
| 63 | handle, err := AcquireAuxiliaryProvider(t.Context(), AuxiliaryProviderRequest{ |
| 64 | Config: cfg, SessionID: "cold-session", WorkspaceRoot: t.TempDir(), ModelRef: "missing/model", |
| 65 | }) |
| 66 | if handle != nil { |
| 67 | _ = handle.Close() |
| 68 | t.Fatal("unavailable recorded model returned a provider handle") |
| 69 | } |
| 70 | if err == nil || !strings.Contains(err.Error(), "unavailable") { |
| 71 | t.Fatalf("AcquireAuxiliaryProvider unavailable model error = %v", err) |
| 72 | } |
| 73 | } |
| 74 |