Skip to content

Commit 8960ace

Browse files
committed
fix(provider): normalize --protocol before named-provider conflict check
Normalize the raw --protocol value in ResolveNamedProvider before comparing it against the spec's protocol. An invalid value (e.g. "openai_api") now surfaces the clear "unknown --protocol" error listing the accepted set, instead of a misleading conflict message; valid aliases no longer falsely conflict.
1 parent 2995505 commit 8960ace

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

internal/provider/resolve.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,18 @@ func ResolveNamedProvider(name, model, baseURL, protocol string, env func(string
136136
return nil, "", fmt.Errorf("unknown --provider %q (available: %s)", name, strings.Join(ProviderNames(), ", "))
137137
}
138138
// A concurrently-set --protocol must agree with the provider's own protocol;
139-
// an incompatible pair is a user error naming both flags.
140-
if p := strings.TrimSpace(protocol); p != "" && p != spec.Protocol {
141-
return nil, "", fmt.Errorf("--provider %q speaks the %q protocol, which conflicts with --protocol %q; drop --protocol or set it to %q", name, spec.Protocol, p, spec.Protocol)
139+
// an incompatible pair is a user error naming both flags. Normalize the raw
140+
// value first so aliases (e.g. "openai/chat" for an "openai" spec) don't
141+
// falsely conflict, and a genuine typo surfaces as a clear "unknown --protocol"
142+
// error rather than a misleading conflict message.
143+
if strings.TrimSpace(protocol) != "" {
144+
canonical, err := NormalizeProtocol(protocol)
145+
if err != nil {
146+
return nil, "", err
147+
}
148+
if canonical != spec.Protocol {
149+
return nil, "", fmt.Errorf("--provider %q speaks the %q protocol, which conflicts with --protocol %q; drop --protocol or set it to %q", name, spec.Protocol, protocol, spec.Protocol)
150+
}
142151
}
143152
// Special-auth providers (Azure / Bedrock / Vertex / Cloudflare) compose
144153
// their endpoint from several env vars and/or need non-standard credential

internal/provider/resolve_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ func TestResolveProviderExplicitProvider(t *testing.T) {
158158
if !strings.Contains(err.Error(), "deepseek") {
159159
t.Errorf("unknown-provider error should list available names, got: %v", err)
160160
}
161+
// An invalid --protocol paired with a named provider surfaces the clear
162+
// "unknown --protocol" error (listing the accepted set) rather than a
163+
// misleading conflict message.
164+
_, _, err = ResolveProvider("deepseek-chat", "", "openai_api", "deepseek", os.Getenv)
165+
if err == nil {
166+
t.Fatal("provider=deepseek + protocol=openai_api should error")
167+
}
168+
if !strings.Contains(err.Error(), "unknown --protocol") {
169+
t.Errorf("invalid --protocol should surface the unknown-protocol error, got: %v", err)
170+
}
161171
}
162172

163173
// TestResolveProviderCNPresets verifies the Chinese-cloud preset ids route to

0 commit comments

Comments
 (0)