gateway: the Claude Code and Codex header tests expect another agent's own User-Agent

abe7b0063 (v0.1.3237) made a key+URL provider receive the agent's own
User-Agent by default. Two tests still asserted that a non-Claude-Code
or non-Codex agent ("opencode/1.0") reaches the relay as magpie/..., so
internal/gateway was red in the full suite on mote at abe7b0063. They
now assert the agent's own UA. They still check that none of Claude
Code's or Codex's own headers is copied.

Run (mote): go test -run
'TestClaudeCodeHeadersReachAnthropicRelay|TestCodexHeadersReachKeyedRelay'
./internal/gateway: ok. The full ./... run at abe7b0063 had no other red
(87 packages ok).

Reported-by: nb5p on Discord
This commit is contained in:
yetone
2026-11-07 18:40:57 +08:00
parent e9bde2520d
commit f2412fd599
2 changed files with 8 additions and 4 deletions
+4 -2
View File
@@ -81,9 +81,11 @@ func TestClaudeCodeHeadersReachAnthropicRelay(t *testing.T) {
t.Errorf("x-app: %v", f.head)
}
// another agent's request goes as magpie's
// another agent's request goes with its own User-Agent (a key+URL
// provider is sent the agent's, nb5p on Discord) and none of Claude
// Code's headers
send("/v1/messages?beta=true", http.Header{"User-Agent": {"opencode/1.0"}, "X-App": {"other"}, "X-Stainless-Lang": {"js"}})
if ua := f.head.Get("User-Agent"); !strings.HasPrefix(ua, "magpie/") || f.head.Get("X-App") != "" || f.head.Get("X-Stainless-Lang") != "" || query != "" {
if ua := f.head.Get("User-Agent"); ua != "opencode/1.0" || f.head.Get("X-App") != "" || f.head.Get("X-Stainless-Lang") != "" || query != "" {
t.Errorf("other agent: %q %v %q", ua, f.head, query)
}
}
@@ -117,9 +117,11 @@ func TestCodexHeadersReachKeyedRelay(t *testing.T) {
t.Errorf("%s: desktop: %v", c.proto, f.head)
}
// another agent's request goes as magpie's
// another agent's request goes with its own User-Agent (a key+URL
// provider is sent the agent's, nb5p on Discord) and none of
// Codex's headers
send(http.Header{"User-Agent": {"opencode/1.0"}, "X-Codex-Window-Id": {"w"}, "Session-Id": {"s"}})
if ua := f.head.Get("User-Agent"); !strings.HasPrefix(ua, "magpie/") || f.head.Get("X-Codex-Window-Id") != "" || f.head.Get("Session-Id") != "" {
if ua := f.head.Get("User-Agent"); ua != "opencode/1.0" || f.head.Get("X-Codex-Window-Id") != "" || f.head.Get("Session-Id") != "" {
t.Errorf("%s: other agent: %q %v", c.proto, ua, f.head)
}
}