| 1 | package boot |
| 2 | |
| 3 | import ( |
| 4 | "reflect" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | |
| 8 | "reasonix/internal/config" |
| 9 | "reasonix/internal/netclient" |
| 10 | ) |
| 11 | |
| 12 | func TestRuntimeRejectsProtocolEndpointMismatch(t *testing.T) { |
| 13 | entry := &config.ProviderEntry{ |
| 14 | Name: "deepseek-anthropic", PresetID: "deepseek-anthropic", Kind: "openai", |
| 15 | BaseURL: "https://api.deepseek.com/anthropic/v1", RequestURL: "https://api.deepseek.com/anthropic/v1/chat/completions", |
| 16 | Model: "deepseek-v4-flash", |
| 17 | } |
| 18 | _, err := NewProviderWithProxyAndModelInfo(entry, netclient.ProxySpec{}, nil) |
| 19 | if err == nil || !strings.Contains(err.Error(), "https://api.deepseek.com/v1/chat/completions") { |
| 20 | t.Fatalf("runtime mismatch error = %v", err) |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | func TestRuntimeRepairsExactCatalogProtocolMismatch(t *testing.T) { |
| 25 | entry := &config.ProviderEntry{ |
| 26 | Name: "deepseek-anthropic", PresetID: "deepseek-anthropic", Kind: "responses", |
| 27 | BaseURL: "https://api.deepseek.com", RequestURL: "https://api.deepseek.com/anthropic/v1/messages", |
| 28 | Model: "deepseek-v4-flash", ResponsesMode: "stateful", |
| 29 | } |
| 30 | p, err := NewProviderWithProxyAndModelInfo(entry, netclient.ProxySpec{}, nil) |
| 31 | if err != nil { |
| 32 | t.Fatalf("runtime repair: %v", err) |
| 33 | } |
| 34 | typ := reflect.TypeOf(p) |
| 35 | if p == nil || typ == nil || typ.Kind() != reflect.Pointer || |
| 36 | typ.Elem().PkgPath() != "reasonix/internal/provider/anthropic" { |
| 37 | t.Fatalf("runtime provider was not repaired: provider=%T", p) |
| 38 | } |
| 39 | if entry.Kind != "responses" || entry.BaseURL != "https://api.deepseek.com" || |
| 40 | entry.RequestURL != "https://api.deepseek.com/anthropic/v1/messages" || entry.ResponsesMode != "stateful" { |
| 41 | t.Fatalf("runtime construction mutated shared config entry: %+v", entry) |
| 42 | } |
| 43 | } |
| 44 |