refactor(test): gadfly round 1 — share the OpenAI-compat test fixtures
Both findings were the same one, and both were fair: the PR that retires two byte-identical DSN factories into openaiCompatScheme then copy-pasted the test fixtures. qwenResponse was byte-identical to kimiResponse, and the single-key env-lookup closure appeared three times in the new file (plus a fourth in the kimi file, which neither reviewer was looking at). Fixed for the class rather than for qwen: captureRT, the canned Chat Completions body (now chatCompletionOK), and a new singleKeyEnv helper move to builtin_openaicompat_test.go, owned by no single provider. The kimi tests adopt them too, so the next OpenAI-compat built-in has nothing left to copy — the same argument the production helper makes. Also aligned the test model ids to the current Model Studio names (qwen3.8-max / qwen3.7-plus), which the docs already cited. One reviewer called those ids fictional and named the 2025 ones instead; they shipped 2026-08-03 and 2026-05-21 respectively, so that finding is stale model knowledge, not a defect — but having tests and prose name the same models removes the smell that prompted it. A dotted id also now proves it passes through verbatim. Break-checked again after the refactor: all six mutations still fail their test. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
+15
-35
@@ -11,23 +11,13 @@ import (
|
||||
"gitea.stevedudenhoeffer.com/steve/majordomo/llm"
|
||||
)
|
||||
|
||||
// qwenResponse is a minimal valid Chat Completions body so Generate returns a
|
||||
// non-empty response (an empty one would trigger failover, not a clean pass).
|
||||
const qwenResponse = `{"id":"c1","object":"chat.completion","choices":[` +
|
||||
`{"index":0,"message":{"role":"assistant","content":"ok"},"finish_reason":"stop"}]}`
|
||||
|
||||
// TestQwenBuiltin: the built-in "qwen" provider resolves in Parse, targets
|
||||
// Model Studio's international OpenAI-compatible endpoint, and authenticates
|
||||
// with QWEN_API_KEY.
|
||||
func TestQwenBuiltin(t *testing.T) {
|
||||
rt := &captureRT{body: qwenResponse}
|
||||
rt := &captureRT{body: chatCompletionOK}
|
||||
r := newTestRegistry(t,
|
||||
WithEnvLookup(func(k string) string {
|
||||
if k == "QWEN_API_KEY" {
|
||||
return "qwen-secret"
|
||||
}
|
||||
return ""
|
||||
}),
|
||||
WithEnvLookup(singleKeyEnv("QWEN_API_KEY", "qwen-secret")),
|
||||
WithHTTPClient(&http.Client{Transport: rt}),
|
||||
)
|
||||
|
||||
@@ -37,11 +27,11 @@ func TestQwenBuiltin(t *testing.T) {
|
||||
t.Errorf("name = %q, want %q", p.Name(), ProviderQwen)
|
||||
}
|
||||
|
||||
m, err := r.Parse("qwen/qwen3-max")
|
||||
m, err := r.Parse("qwen/qwen3.8-max")
|
||||
if err != nil {
|
||||
t.Fatalf("Parse: %v", err)
|
||||
}
|
||||
if got := targetsOf(t, m); len(got) != 1 || got[0] != "qwen/qwen3-max" {
|
||||
if got := targetsOf(t, m); len(got) != 1 || got[0] != "qwen/qwen3.8-max" {
|
||||
t.Fatalf("targets = %v", got)
|
||||
}
|
||||
|
||||
@@ -64,10 +54,10 @@ func TestQwenBuiltin(t *testing.T) {
|
||||
// the credential does not fall through to the openai client's default), and
|
||||
// without hitting the network.
|
||||
func TestQwenBuiltinMissingKey(t *testing.T) {
|
||||
rt := &captureRT{body: qwenResponse}
|
||||
rt := &captureRT{body: chatCompletionOK}
|
||||
r := newTestRegistry(t, WithHTTPClient(&http.Client{Transport: rt}))
|
||||
|
||||
m, err := r.Parse("qwen/qwen3-max")
|
||||
m, err := r.Parse("qwen/qwen3.8-max")
|
||||
if err != nil {
|
||||
t.Fatalf("Parse: %v", err)
|
||||
}
|
||||
@@ -102,14 +92,9 @@ func TestQwenBuiltinKeyDoesNotLeakToOpenAI(t *testing.T) {
|
||||
// below would pass without a single byte reaching the wire.
|
||||
t.Setenv("OPENAI_API_KEY", "openai-secret")
|
||||
|
||||
rt := &captureRT{body: qwenResponse}
|
||||
rt := &captureRT{body: chatCompletionOK}
|
||||
r := newTestRegistry(t,
|
||||
WithEnvLookup(func(k string) string {
|
||||
if k == "QWEN_API_KEY" {
|
||||
return "qwen-secret"
|
||||
}
|
||||
return ""
|
||||
}),
|
||||
WithEnvLookup(singleKeyEnv("QWEN_API_KEY", "qwen-secret")),
|
||||
WithHTTPClient(&http.Client{Transport: rt}),
|
||||
)
|
||||
|
||||
@@ -133,7 +118,7 @@ func TestQwenBuiltinKeyDoesNotLeakToOpenAI(t *testing.T) {
|
||||
// Studio host (here the China endpoint) that is first-class in Parse and
|
||||
// carries the DSN token as its bearer credential.
|
||||
func TestQwenScheme(t *testing.T) {
|
||||
rt := &captureRT{body: qwenResponse}
|
||||
rt := &captureRT{body: chatCompletionOK}
|
||||
r := newTestRegistry(t, WithHTTPClient(&http.Client{Transport: rt}))
|
||||
if err := r.LoadEnv(map[string]string{
|
||||
"LLM_QCN": "qwen://[email protected]/compatible-mode/v1",
|
||||
@@ -141,7 +126,7 @@ func TestQwenScheme(t *testing.T) {
|
||||
t.Fatalf("LoadEnv: %v", err)
|
||||
}
|
||||
|
||||
m, err := r.Parse("qcn/qwen-plus")
|
||||
m, err := r.Parse("qcn/qwen3.7-plus")
|
||||
if err != nil {
|
||||
t.Fatalf("Parse: %v", err)
|
||||
}
|
||||
@@ -164,7 +149,7 @@ func TestQwenScheme(t *testing.T) {
|
||||
// the defining LLM_<NAME> env var, never QWEN_API_KEY (which does nothing for a
|
||||
// DSN-defined provider).
|
||||
func TestQwenSchemeMissingToken(t *testing.T) {
|
||||
rt := &captureRT{body: qwenResponse}
|
||||
rt := &captureRT{body: chatCompletionOK}
|
||||
r := newTestRegistry(t, WithHTTPClient(&http.Client{Transport: rt}))
|
||||
if err := r.LoadEnv(map[string]string{
|
||||
"LLM_QCN": "qwen://dashscope.aliyuncs.com/compatible-mode/v1", // no token
|
||||
@@ -172,7 +157,7 @@ func TestQwenSchemeMissingToken(t *testing.T) {
|
||||
t.Fatalf("LoadEnv: %v", err)
|
||||
}
|
||||
|
||||
m, err := r.Parse("qcn/qwen-plus")
|
||||
m, err := r.Parse("qcn/qwen3.7-plus")
|
||||
if err != nil {
|
||||
t.Fatalf("Parse: %v", err)
|
||||
}
|
||||
@@ -200,18 +185,13 @@ func TestQwenSchemeMissingToken(t *testing.T) {
|
||||
// drop it silently (provider/anthropic ignores ReasoningEffort by design), and
|
||||
// that difference would be invisible without asserting on the wire body.
|
||||
func TestQwenReasoningEffortReachesWire(t *testing.T) {
|
||||
rt := &captureRT{body: qwenResponse}
|
||||
rt := &captureRT{body: chatCompletionOK}
|
||||
r := newTestRegistry(t,
|
||||
WithEnvLookup(func(k string) string {
|
||||
if k == "QWEN_API_KEY" {
|
||||
return "qwen-secret"
|
||||
}
|
||||
return ""
|
||||
}),
|
||||
WithEnvLookup(singleKeyEnv("QWEN_API_KEY", "qwen-secret")),
|
||||
WithHTTPClient(&http.Client{Transport: rt}),
|
||||
)
|
||||
|
||||
m, err := r.Parse("qwen/qwen3-max")
|
||||
m, err := r.Parse("qwen/qwen3.8-max")
|
||||
if err != nil {
|
||||
t.Fatalf("Parse: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user