tests: the gateway's and Devin's tests run on Windows in a home of their own — on Windows os.UserHomeDir reads USERPROFILE, not HOME, so a test that set HOME to a temp dir still found the one USERPROFILE every gateway test shares (and the box's real agents); Devin's CLI keeps its sign-in under APPDATA. Each such test now sets USERPROFILE with HOME (setHome), TestDevinOwnMovesWithPlan sets APPDATA, and the tests whose Claude Code is a shell script skip on Windows, where it can't run and the box's real claude ran instead. Tests only. The gateway suite and TestDevinOwnMovesWithPlan pass on Windows; go test -tags nogui ./... passes on macOS.

This commit is contained in:
yetone
2026-10-01 20:26:53 +08:00
parent 7caba10d9c
commit b9895c2ded
22 changed files with 66 additions and 14 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ import (
// copied before, with the plain token, still gets an answer, recorded as
// the SDK's as it was.
func TestAgyAgent(t *testing.T) {
t.Setenv("HOME", t.TempDir())
setHome(t, t.TempDir())
f := &fake{t: t, reply: sse(
`data: {"id":"c1","choices":[{"delta":{"content":"OK"},"finish_reason":"stop"}],"usage":{"prompt_tokens":5,"completion_tokens":2}}`,
`data: [DONE]`)}
+4
View File
@@ -5,6 +5,7 @@ import (
"net/http/httptest"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
@@ -199,6 +200,9 @@ func TestAutoModeServerSideReviewRelayed(t *testing.T) {
// isn't kept waiting for a next turn it will never have, which would push
// the conversations' own runs out.
func TestAutoModeClassifierOnTheClaudeBridge(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("a shell script stands in for Claude Code")
}
dir := t.TempDir()
args := filepath.Join(dir, "args")
script := `#!/bin/sh
@@ -78,7 +78,7 @@ func TestClaudeCodeWebSearchKeepsMetadata(t *testing.T) {
t.Run("no searcher", func(t *testing.T) {
f := &fake{t: t, reply: ccRelayReply, refuse: ccOnly}
t.Setenv("HOME", t.TempDir()) // no signed-in agent searches
setHome(t, t.TempDir()) // no signed-in agent searches
setup(t, provider.Anthropic, f)
if _, _, ok := searcher(); ok {
t.Fatal("a searcher is set up")
@@ -94,7 +94,7 @@ func TestClaudeCodeWebSearchKeepsMetadata(t *testing.T) {
t.Run("magpie searches", func(t *testing.T) {
f := &fake{t: t, reply: ccRelayReply, refuse: ccOnly}
t.Setenv("HOME", t.TempDir())
setHome(t, t.TempDir())
setup(t, provider.Anthropic, f)
srch := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, `{"data":[{"id":"claude-haiku-4-5"}]}`)
@@ -6,6 +6,7 @@ import (
"net/http/httptest"
"os"
"path/filepath"
"runtime"
"slices"
"strconv"
"strings"
@@ -80,6 +81,9 @@ func TestCleanClaudeEnvRemovesGatewayOverrides(t *testing.T) {
// how many turns that process has had, as Claude Code's stream-json does.
func fakeClaude(t *testing.T) {
t.Helper()
if runtime.GOOS == "windows" {
t.Skip("a shell script stands in for Claude Code")
}
dir := t.TempDir()
script := `#!/bin/sh
n=0
@@ -414,6 +418,9 @@ func TestSweepBridgeProjectsTakesOnlyTheBridgesFolders(t *testing.T) {
// message_stop, then waits on its next input: the reply is a 429 at once,
// streamed or not, so another account can take over (#177).
func TestClaudeQuotaResultEndsTheReply(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("a shell script stands in for Claude Code")
}
dir := t.TempDir()
script := `#!/bin/sh
while read -r line; do
+7
View File
@@ -5,6 +5,7 @@ import (
"encoding/json"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
@@ -15,6 +16,9 @@ import (
// answers as out says.
func fakeWarmClaude(t *testing.T, out string, code int) string {
t.Helper()
if runtime.GOOS == "windows" {
t.Skip("a shell script stands in for Claude Code")
}
dir := t.TempDir()
log := filepath.Join(dir, "log")
script := "#!/bin/sh\n" +
@@ -90,6 +94,9 @@ func TestClaudeTestRunsClaudeCode(t *testing.T) {
// Claude's usage is Claude Code's own /usage, run with nothing of the
// user's settings and nothing kept, as the account it is signed in to.
func TestClaudeUsageRunsClaudeCode(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("a shell script stands in for Claude Code")
}
dir := t.TempDir()
log := filepath.Join(dir, "log")
out := filepath.Join(dir, "out")
+1
View File
@@ -22,6 +22,7 @@ func codexSignedIn(t *testing.T, spares ...string) {
t.Helper()
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home) // Windows finds the home there
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
restingUntil.Lock()
+1 -1
View File
@@ -20,7 +20,7 @@ import (
// chatgpt stands in for the ChatGPT backend behind CodexBase.
func chatgpt(t *testing.T, h http.HandlerFunc) *httptest.Server {
t.Helper()
t.Setenv("HOME", t.TempDir()) // no sign-ins but the test's
setHome(t, t.TempDir()) // no sign-ins but the test's
up := httptest.NewServer(h)
t.Cleanup(up.Close)
was := provider.CodexBase
+1 -1
View File
@@ -82,7 +82,7 @@ func (u *jevUp) turns() []map[string]any {
// the model prefix, with that prefix taken off the model. /systemone is
// not served.
func TestSystemOneRoutesByPrefix(t *testing.T) {
t.Setenv("HOME", t.TempDir())
setHome(t, t.TempDir())
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
t.Setenv("XDG_CACHE_HOME", t.TempDir())
type hit struct {
+1
View File
@@ -329,6 +329,7 @@ func grokSignedIn(t *testing.T) {
t.Helper()
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
t.Setenv("GROK_HOME", filepath.Join(home, ".grok"))
+1
View File
@@ -22,6 +22,7 @@ import (
func TestSubscriptionAccountSkippedForModelItLacks(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
restingUntil.Lock()
+6
View File
@@ -9,6 +9,7 @@ import (
"net/http/httptest"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"time"
@@ -169,6 +170,7 @@ func TestSeveralKeysOnTakeOverFromEachOther(t *testing.T) {
func TestSubscriptionAccountsTakeOver(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
restingUntil.Lock()
@@ -231,8 +233,12 @@ func TestSubscriptionAccountsTakeOver(t *testing.T) {
// token and no email: the account is still named from ~/.claude.json, so it
// is the saved me@example.com, not a "Claude Max" served beside it.
func TestClaudeAccountsTakeOver(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("a shell script stands in for Claude Code")
}
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
far := time.Now().Add(24 * time.Hour).UnixMilli()
+3 -2
View File
@@ -847,6 +847,7 @@ func mustJSON(v any) []byte { b, _ := json.Marshal(v); return b }
func TestCodexAccountUpstream(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
claims := func(m map[string]any) string {
@@ -1260,7 +1261,7 @@ func TestRequestValidationBeforeRouting(t *testing.T) {
}
func TestGeminiRequestValidation(t *testing.T) {
t.Setenv("HOME", t.TempDir())
setHome(t, t.TempDir())
f := &fake{t: t, reply: sse(
`data: {"id":"c1","choices":[{"delta":{"content":"OK"},"finish_reason":"stop"}]}`,
`data: [DONE]`)}
@@ -1286,7 +1287,7 @@ func TestGeminiRequestValidation(t *testing.T) {
}
func TestRequestValidationPreservesPayload(t *testing.T) {
t.Setenv("HOME", t.TempDir())
setHome(t, t.TempDir())
f := &fake{t: t, ctype: "application/json", reply: `{"id":"r1","output":[]}`}
setup(t, provider.Responses, f)
code, body := post(t, "/v1/responses", `{"model":" fake/vendor/new-model ","input":"hi","extension":{"number":9007199254740993}}`)
+10 -1
View File
@@ -34,7 +34,9 @@ func (k *keyed) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func fresh(t *testing.T) {
t.Helper()
t.Setenv("HOME", t.TempDir()) // no agent signed in
home := t.TempDir() // no agent signed in
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home) // Windows finds the home there
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
t.Setenv("XDG_CACHE_HOME", t.TempDir())
restingUntil.Lock()
@@ -51,6 +53,13 @@ func fresh(t *testing.T) {
classified.Unlock()
}
// setHome makes dir the home, where Windows (USERPROFILE) finds it too.
func setHome(t *testing.T, dir string) {
t.Helper()
t.Setenv("HOME", dir)
t.Setenv("USERPROFILE", dir)
}
func serveOn(t *testing.T, id, key string, models []string, v http.Handler, keys ...string) {
t.Helper()
up := httptest.NewServer(v)
+1
View File
@@ -81,6 +81,7 @@ func TestPiResponsesRelayed(t *testing.T) {
func TestPiResponsesRelayedToChatGPT(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
claims := func(m map[string]any) string {
+1 -1
View File
@@ -12,7 +12,7 @@ import (
// a wrong key, none, or a gateway not shared still get nothing, and the
// refusal says how.
func TestQuotasOverLAN(t *testing.T) {
t.Setenv("HOME", t.TempDir())
setHome(t, t.TempDir())
t.Setenv("MAGPIE_ADDR", "")
h := lanGuard(New().Handler())
call := func(from string, hdr ...string) (int, string) {
@@ -6,6 +6,7 @@ import (
"net/http/httptest"
"os"
"path/filepath"
"runtime"
"slices"
"strings"
"testing"
@@ -218,8 +219,12 @@ func TestClaudeRefusalMovesToNextKey(t *testing.T) {
// Claude Code's own "unable to respond" result), and the spare answers —
// streamed to Codex and to an Anthropic client, and not streamed.
func TestClaudeSubscriptionRefusalMovesToNextAccount(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("a shell script stands in for Claude Code")
}
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
restingUntil.Lock()
+7
View File
@@ -5,6 +5,7 @@ import (
"net/http/httptest"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"time"
@@ -121,6 +122,9 @@ func TestTurnedAwayRequestIsLogged(t *testing.T) {
// its name for the error and the id of the request. The reply is that
// status, not one guessed from the words, and the log has all three.
func TestClaudeFailureKeepsClaudeCodesStatus(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("a shell script stands in for Claude Code")
}
dir := t.TempDir()
script := `#!/bin/sh
while read -r line; do
@@ -158,6 +162,9 @@ done
// The id of an answered Claude Code request is the one on its messages,
// given with its stream's usage.
func TestClaudeAnswerKeepsClaudeCodesRequestID(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("a shell script stands in for Claude Code")
}
dir := t.TempDir()
script := `#!/bin/sh
while read -r line; do
+2 -2
View File
@@ -87,7 +87,7 @@ func TestWebSearchForAModelThatCannot(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
t.Setenv("XDG_CACHE_HOME", t.TempDir())
t.Setenv("HOME", t.TempDir()) // no signed-in agent searches first
setHome(t, t.TempDir()) // no signed-in agent searches first
hosts := searchHosts[provider.Anthropic]
searchHosts[provider.Anthropic] = append(hosts, provider.HostOf(search.URL))
defer func() { searchHosts[provider.Anthropic] = hosts }()
@@ -385,7 +385,7 @@ func TestWebSearchOfARelayThatSearches(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
t.Setenv("XDG_CACHE_HOME", t.TempDir())
t.Setenv("HOME", t.TempDir()) // no signed-in agent searches for it
setHome(t, t.TempDir()) // no signed-in agent searches for it
// Claude Code 2.1.285's WebSearch
body := `{"model":"relay/claude-haiku-4-5","max_tokens":32000,"stream":false,
"system":[{"type":"text","text":"x-anthropic-billing-header: cc_version=2.1.285.3c7; cc_entrypoint=cli;"},{"type":"text","text":"You are Claude Code, Anthropic's official CLI for Claude."},{"type":"text","text":"You are an assistant for performing a web search tool use"}],
+1 -1
View File
@@ -72,7 +72,7 @@ func TestWebSearchCallSaysWhose(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
t.Setenv("XDG_CACHE_HOME", t.TempDir())
t.Setenv("HOME", t.TempDir())
setHome(t, t.TempDir())
hosts := searchHosts[provider.Anthropic]
searchHosts[provider.Anthropic] = append(hosts, provider.HostOf(search.URL))
defer func() { searchHosts[provider.Anthropic] = hosts }()
+2 -2
View File
@@ -11,7 +11,7 @@ import (
// a model the agent names that magpie doesn't serve goes to the one the
// agent is set to use for it; one magpie serves is sent as asked
func TestStandIn(t *testing.T) {
t.Setenv("HOME", t.TempDir())
setHome(t, t.TempDir())
f := &fake{t: t, ctype: "application/json", reply: `{"id":"c1","choices":[{"message":{"role":"assistant","content":"OK"},"finish_reason":"stop"}]}`}
setup(t, provider.Chat, f)
var asked []string
@@ -38,7 +38,7 @@ func TestStandIn(t *testing.T) {
// Codex's auto-review asks magpie, its provider, for "codex-auto-review":
// the review goes to the model that stands in (Codex's, TestCodexStandIn).
func TestCodexAutoReviewStandIn(t *testing.T) {
t.Setenv("HOME", t.TempDir())
setHome(t, t.TempDir())
f := &fake{t: t, ctype: "application/json", reply: `{"id":"c1","choices":[{"message":{"role":"assistant","content":"OK"},"finish_reason":"stop"}]}`}
setup(t, provider.Chat, f)
StandIn = func(agent, model string) string {
+1
View File
@@ -52,6 +52,7 @@ func TestAddedKeyLeavesRunningConversations(t *testing.T) {
func TestForeignReasoningIsLeftOut(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
restingUntil.Lock()
+1
View File
@@ -55,6 +55,7 @@ func TestDevinOwnMovesWithPlan(t *testing.T) {
home := claudeHome(t)
data := filepath.Join(home, "data")
t.Setenv("XDG_DATA_HOME", data)
t.Setenv("APPDATA", data) // where Windows' Devin CLI keeps it
os.MkdirAll(filepath.Join(data, "devin"), 0o700)
if err := os.WriteFile(filepath.Join(data, "devin", "credentials.toml"), devinCredentials("cog_own_key_1234", "", "", ""), 0o600); err != nil {
t.Fatal(err)