From f2412fd599452e69f8da7d2e0a2df9f4064da959 Mon Sep 17 00:00:00 2001 From: yetone Date: Sat, 7 Nov 2026 18:40:53 +0800 Subject: [PATCH] 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 --- internal/gateway/claude_code_headers_test.go | 6 ++++-- internal/gateway/codex_client_headers_test.go | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/gateway/claude_code_headers_test.go b/internal/gateway/claude_code_headers_test.go index 3bbb5820a..b0ef67463 100644 --- a/internal/gateway/claude_code_headers_test.go +++ b/internal/gateway/claude_code_headers_test.go @@ -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) } } diff --git a/internal/gateway/codex_client_headers_test.go b/internal/gateway/codex_client_headers_test.go index 2476deb15..8375e5753 100644 --- a/internal/gateway/codex_client_headers_test.go +++ b/internal/gateway/codex_client_headers_test.go @@ -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) } }