refactor: gadfly round 3 — one table owns the OpenAI-compat contract
Three findings, and the first two are the same recurring shape. envKeyForProvider (env.go) is now the single definition of the LLM_<NAME> form. It lived in two places — lazy resolution in registry.go and the missing-key hint in openaiCompatScheme — with a comment on the second asserting it matched the first. A comment is not enforcement: if either had drifted, a keyless DSN target would have named a variable that does nothing, and nothing would have failed. The kimi and qwen test files had become near-identical, which is round 1's finding at the level above it: I deduped the fixtures, then left two parallel suites asserting the same four things. They are now ONE table in builtin_openaicompat_test.go — endpoint + credential, missing key fails closed naming its own variable and never reaching the network, the name:// DSN reaching another host, and a keyless DSN naming LLM_<NAME> instead of the built-in's key. Adding an OpenAI-compat built-in is a table row that immediately owes all four; builtin_kimi_test.go is deleted because the table covers it. Only genuinely qwen-specific tests remain in the qwen file: the reverse credential leak and the reasoning_effort wire claim ADR-0027 rests on. Also trimmed ProviderQwen's doc comment, which restated the ADR-0027 rationale already given at the registration site. The break-check suite caught its own rot again — two mutations went stale when these tests were renamed, and the landed-check reported them loudly instead of passing them off as green. Now 9 cases, including one that drifts envKeyForProvider to prove the shared helper is load-bearing. 9/9 apply and are caught. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
+3
-7
@@ -2,7 +2,6 @@ package majordomo
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"gitea.stevedudenhoeffer.com/steve/majordomo/llm"
|
||||
"gitea.stevedudenhoeffer.com/steve/majordomo/provider/anthropic"
|
||||
@@ -22,11 +21,8 @@ const (
|
||||
// ProviderQwen is Alibaba's Qwen models over Model Studio's
|
||||
// OpenAI-compatible Chat Completions endpoint. Reuses the openai client
|
||||
// (like kimi and llama-swap); keyed by QWEN_API_KEY, default base URL
|
||||
// qwenBaseURL. Why OpenAI-compat and not the Anthropic-compat endpoint
|
||||
// Model Studio also exposes: see ADR-0027 — the OpenAI surface is the
|
||||
// first-class one there (reasoning_effort, json_schema structured output,
|
||||
// cached_tokens accounting all ride it), while the Anthropic shim exists
|
||||
// mainly to host Claude Code.
|
||||
// qwenBaseURL. ADR-0027 records why the OpenAI surface and not the
|
||||
// Anthropic-compatible one Model Studio also exposes.
|
||||
ProviderQwen = "qwen"
|
||||
ProviderAnthropic = "anthropic"
|
||||
ProviderGoogle = "google"
|
||||
@@ -67,7 +63,7 @@ func openaiCompatScheme(wrap func(...openai.Option) []openai.Option) SchemeFacto
|
||||
openai.WithName(name),
|
||||
openai.WithBaseURL(dsn.BaseURL()),
|
||||
openai.WithAPIKey(dsn.Token),
|
||||
openai.WithAPIKeyName("LLM_"+strings.ToUpper(strings.ReplaceAll(name, "-", "_"))),
|
||||
openai.WithAPIKeyName(envKeyForProvider(name)),
|
||||
)...), nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user