diff --git a/internal/gateway/agy_agent_test.go b/internal/gateway/agy_agent_test.go index 308b50e66..42d088140 100644 --- a/internal/gateway/agy_agent_test.go +++ b/internal/gateway/agy_agent_test.go @@ -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]`)} diff --git a/internal/gateway/automode_test.go b/internal/gateway/automode_test.go index 63d1d15c2..02165359f 100644 --- a/internal/gateway/automode_test.go +++ b/internal/gateway/automode_test.go @@ -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 diff --git a/internal/gateway/claude_code_websearch_test.go b/internal/gateway/claude_code_websearch_test.go index 7c9d4c221..494c826f3 100644 --- a/internal/gateway/claude_code_websearch_test.go +++ b/internal/gateway/claude_code_websearch_test.go @@ -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"}]}`) diff --git a/internal/gateway/claude_subscription_test.go b/internal/gateway/claude_subscription_test.go index 6ba3672f7..fdca03a5d 100644 --- a/internal/gateway/claude_subscription_test.go +++ b/internal/gateway/claude_subscription_test.go @@ -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 diff --git a/internal/gateway/claude_warmup_test.go b/internal/gateway/claude_warmup_test.go index 9e7539ba7..1bada7e6c 100644 --- a/internal/gateway/claude_warmup_test.go +++ b/internal/gateway/claude_warmup_test.go @@ -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") diff --git a/internal/gateway/codex_accounts_test.go b/internal/gateway/codex_accounts_test.go index 2d57406a9..b1a0fcea8 100644 --- a/internal/gateway/codex_accounts_test.go +++ b/internal/gateway/codex_accounts_test.go @@ -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() diff --git a/internal/gateway/codex_backend_test.go b/internal/gateway/codex_backend_test.go index 6d3d1f5bf..24b56a519 100644 --- a/internal/gateway/codex_backend_test.go +++ b/internal/gateway/codex_backend_test.go @@ -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 diff --git a/internal/gateway/decide_test.go b/internal/gateway/decide_test.go index 31bb2f97e..d2c088ee3 100644 --- a/internal/gateway/decide_test.go +++ b/internal/gateway/decide_test.go @@ -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 { diff --git a/internal/gateway/draw_test.go b/internal/gateway/draw_test.go index 8fdb241e4..8ade6b7aa 100644 --- a/internal/gateway/draw_test.go +++ b/internal/gateway/draw_test.go @@ -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")) diff --git a/internal/gateway/fallback_plans_test.go b/internal/gateway/fallback_plans_test.go index faa308683..92d0f299b 100644 --- a/internal/gateway/fallback_plans_test.go +++ b/internal/gateway/fallback_plans_test.go @@ -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() diff --git a/internal/gateway/fallback_test.go b/internal/gateway/fallback_test.go index 095e46e33..c634ed122 100644 --- a/internal/gateway/fallback_test.go +++ b/internal/gateway/fallback_test.go @@ -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() diff --git a/internal/gateway/gateway_test.go b/internal/gateway/gateway_test.go index 55c3bd709..59cfc9335 100644 --- a/internal/gateway/gateway_test.go +++ b/internal/gateway/gateway_test.go @@ -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}}`) diff --git a/internal/gateway/group_test.go b/internal/gateway/group_test.go index 8a36a258c..5e5681cbf 100644 --- a/internal/gateway/group_test.go +++ b/internal/gateway/group_test.go @@ -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) diff --git a/internal/gateway/pi_responses_test.go b/internal/gateway/pi_responses_test.go index 458a530ae..f42ef887d 100644 --- a/internal/gateway/pi_responses_test.go +++ b/internal/gateway/pi_responses_test.go @@ -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 { diff --git a/internal/gateway/quotas_lan_test.go b/internal/gateway/quotas_lan_test.go index bff2a2e29..22dcf7e1a 100644 --- a/internal/gateway/quotas_lan_test.go +++ b/internal/gateway/quotas_lan_test.go @@ -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) { diff --git a/internal/gateway/refusal_accounts_test.go b/internal/gateway/refusal_accounts_test.go index 79eb29092..db1e99ffb 100644 --- a/internal/gateway/refusal_accounts_test.go +++ b/internal/gateway/refusal_accounts_test.go @@ -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() diff --git a/internal/gateway/reqlog_test.go b/internal/gateway/reqlog_test.go index 493bddfcc..57dea51bf 100644 --- a/internal/gateway/reqlog_test.go +++ b/internal/gateway/reqlog_test.go @@ -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 diff --git a/internal/gateway/search_test.go b/internal/gateway/search_test.go index 6946a3d40..7e70af0eb 100644 --- a/internal/gateway/search_test.go +++ b/internal/gateway/search_test.go @@ -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"}], diff --git a/internal/gateway/side_call_kind_test.go b/internal/gateway/side_call_kind_test.go index be933df52..7d6ff25a3 100644 --- a/internal/gateway/side_call_kind_test.go +++ b/internal/gateway/side_call_kind_test.go @@ -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 }() diff --git a/internal/gateway/standin_test.go b/internal/gateway/standin_test.go index ddfa4c961..e16dec6d0 100644 --- a/internal/gateway/standin_test.go +++ b/internal/gateway/standin_test.go @@ -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 { diff --git a/internal/gateway/switch_test.go b/internal/gateway/switch_test.go index 0427b9be7..ad5100251 100644 --- a/internal/gateway/switch_test.go +++ b/internal/gateway/switch_test.go @@ -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() diff --git a/internal/provider/migrate_parity_test.go b/internal/provider/migrate_parity_test.go index eb6418eb5..3a8ec60c2 100644 --- a/internal/provider/migrate_parity_test.go +++ b/internal/provider/migrate_parity_test.go @@ -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)