diff --git a/gateway_keys_cli_test.go b/gateway_keys_cli_test.go index 4e8e8b2ba..43555ff48 100644 --- a/gateway_keys_cli_test.go +++ b/gateway_keys_cli_test.go @@ -12,6 +12,7 @@ import ( func TestGatewayKeyCLI(t *testing.T) { t.Setenv("HOME", t.TempDir()) + t.Setenv("USERPROFILE", os.Getenv("HOME")) t.Setenv("XDG_CONFIG_HOME", t.TempDir()) if err := settings.Save(settings.Settings{LAN: true}); err != nil { t.Fatal(err) diff --git a/groups_cli_test.go b/groups_cli_test.go index 30889ee51..3eb721f52 100644 --- a/groups_cli_test.go +++ b/groups_cli_test.go @@ -14,6 +14,7 @@ import ( func groupsHome(t *testing.T) { t.Helper() t.Setenv("HOME", t.TempDir()) // no agent signed in + t.Setenv("USERPROFILE", os.Getenv("HOME")) t.Setenv("XDG_CONFIG_HOME", t.TempDir()) t.Setenv("XDG_CACHE_HOME", t.TempDir()) for _, p := range []provider.Provider{ diff --git a/healthcheck_cli_test.go b/healthcheck_cli_test.go index 7fc39c36d..836a32260 100644 --- a/healthcheck_cli_test.go +++ b/healthcheck_cli_test.go @@ -14,6 +14,7 @@ import ( // magpie gateway answers at MAGPIE_ADDR. func TestHealthcheck(t *testing.T) { t.Setenv("HOME", t.TempDir()) + t.Setenv("USERPROFILE", os.Getenv("HOME")) t.Setenv("XDG_CONFIG_HOME", t.TempDir()) magpie := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(`{"name":"magpie","version":"dev"}`)) diff --git a/internal/access/access_test.go b/internal/access/access_test.go index 4debd46b2..b3373e17b 100644 --- a/internal/access/access_test.go +++ b/internal/access/access_test.go @@ -3,6 +3,7 @@ package access import ( "encoding/json" "os" + "runtime" "strings" "sync" "testing" @@ -51,7 +52,7 @@ func TestNamedKeys(t *testing.T) { t.Fatal("copy", err) } st, err := os.Stat(Path()) - if err != nil || st.Mode().Perm() != 0o600 { + if err != nil || runtime.GOOS != "windows" && st.Mode().Perm() != 0o600 { t.Fatal("permissions", err) } var persisted []Key diff --git a/internal/agent/agy_test.go b/internal/agent/agy_test.go index 2665144f4..40180330e 100644 --- a/internal/agent/agy_test.go +++ b/internal/agent/agy_test.go @@ -15,6 +15,7 @@ import ( func TestAgy(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")) if err := provider.Save(provider.Provider{ID: "deepseek", Name: "DeepSeek", Chat: "https://api.deepseek.com/v1", Key: "k", Models: []string{"pro", "flash"}}); err != nil { diff --git a/internal/agent/claude_1m_test.go b/internal/agent/claude_1m_test.go index e0e5af443..05a57185d 100644 --- a/internal/agent/claude_1m_test.go +++ b/internal/agent/claude_1m_test.go @@ -17,6 +17,7 @@ import ( func TestClaude1MMarked(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")) if err := provider.Save(provider.Provider{ID: "v", Name: "V", Chat: "https://example.test/v1", Key: "k", diff --git a/internal/agent/claude_alias_test.go b/internal/agent/claude_alias_test.go index e28afc32e..0effbe939 100644 --- a/internal/agent/claude_alias_test.go +++ b/internal/agent/claude_alias_test.go @@ -18,6 +18,7 @@ import ( func TestClaudeAliasShown(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")) if err := os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755); err != nil { diff --git a/internal/agent/claude_caps_test.go b/internal/agent/claude_caps_test.go index 5ba63cf0f..d1ccf15e1 100644 --- a/internal/agent/claude_caps_test.go +++ b/internal/agent/claude_caps_test.go @@ -147,6 +147,7 @@ func TestClaudeModelCapabilities(t *testing.T) { func TestClaudeCapabilitiesSync(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")) if err := provider.Save(provider.Provider{ID: "v", Name: "V", Chat: "http://127.0.0.1:1/v1", Key: "k", Models: []string{"a"}}); err != nil { diff --git a/internal/agent/claude_context_test.go b/internal/agent/claude_context_test.go index ed90ec19e..fede63d5f 100644 --- a/internal/agent/claude_context_test.go +++ b/internal/agent/claude_context_test.go @@ -17,6 +17,7 @@ import ( func TestClaudeContextWindow(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")) if err := provider.Save(provider.Provider{ID: "v", Name: "V", Chat: "https://example.test/v1", Key: "k", diff --git a/internal/agent/claude_effort_test.go b/internal/agent/claude_effort_test.go index 7beec4a6d..6da720875 100644 --- a/internal/agent/claude_effort_test.go +++ b/internal/agent/claude_effort_test.go @@ -15,6 +15,7 @@ func claudeSettings(t *testing.T, settings string) (home, path string) { 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")) path = filepath.Join(home, ".claude", "settings.json") diff --git a/internal/agent/claude_test.go b/internal/agent/claude_test.go index 18c966a6b..8d1e50ea9 100644 --- a/internal/agent/claude_test.go +++ b/internal/agent/claude_test.go @@ -12,6 +12,7 @@ import ( func TestClaudeTiers(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")) if err := provider.Save(provider.Provider{ID: "deepseek", Name: "DeepSeek", Chat: "https://api.deepseek.com/v1", Key: "k", Models: []string{"pro", "flash"}}); err != nil { @@ -78,6 +79,7 @@ func TestClaudeTiers(t *testing.T) { func TestClaudeEffortMax(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")) path := filepath.Join(home, ".claude", "settings.json") diff --git a/internal/agent/cline_test.go b/internal/agent/cline_test.go index 628b35c22..9802c2498 100644 --- a/internal/agent/cline_test.go +++ b/internal/agent/cline_test.go @@ -5,6 +5,7 @@ import ( "os" "path/filepath" "reflect" + "runtime" "strings" "testing" @@ -16,6 +17,7 @@ import ( func TestCline(t *testing.T) { home := t.TempDir() t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) t.Setenv("CLINE_DIR", "") t.Setenv("CLINE_DATA_DIR", "") t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) @@ -176,7 +178,7 @@ func TestCline(t *testing.T) { if c.Version != 1 || c.LastUsed != "openai-compatible" { t.Fatalf("new file:\n%s", raw) } - if st, _ := os.Stat(path); st.Mode().Perm() != 0o600 { + if st, _ := os.Stat(path); runtime.GOOS != "windows" && st.Mode().Perm() != 0o600 { // Windows has no such bits t.Fatalf("mode %v", st.Mode()) } if err := f.Set(""); err != nil { diff --git a/internal/agent/codex_own_test.go b/internal/agent/codex_own_test.go index 9ad97f33d..b20b49ec4 100644 --- a/internal/agent/codex_own_test.go +++ b/internal/agent/codex_own_test.go @@ -12,6 +12,7 @@ import ( func TestCodexOwnModelsFollowPicks(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")) t.Setenv("CODEX_HOME", "") @@ -53,6 +54,7 @@ func TestCodexOwnModelsFollowPicks(t *testing.T) { func TestCodexOwnModelsNotNarrowedWhileOff(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")) t.Setenv("CODEX_HOME", "") diff --git a/internal/agent/codex_route_test.go b/internal/agent/codex_route_test.go index a5680338f..9f5307ab9 100644 --- a/internal/agent/codex_route_test.go +++ b/internal/agent/codex_route_test.go @@ -13,6 +13,7 @@ func codexHome(t *testing.T, auth, config string) (home string, read func() stri 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("CODEX_HOME", "") diff --git a/internal/agent/commandcode_test.go b/internal/agent/commandcode_test.go index bc4f52e08..4f25a0911 100644 --- a/internal/agent/commandcode_test.go +++ b/internal/agent/commandcode_test.go @@ -12,6 +12,7 @@ import ( func TestCommandCode(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")) if err := provider.Save(provider.Provider{ID: "deepseek", Name: "DeepSeek", Chat: "https://api.deepseek.com/v1", Key: "k", Models: []string{"pro", "flash"}}); err != nil { diff --git a/internal/agent/devin_test.go b/internal/agent/devin_test.go index f2abe42af..0a9c74571 100644 --- a/internal/agent/devin_test.go +++ b/internal/agent/devin_test.go @@ -22,7 +22,9 @@ func TestDevin(t *testing.T) { home := t.TempDir() cfg := filepath.Join(home, ".config") t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) t.Setenv("XDG_CONFIG_HOME", cfg) + t.Setenv("APPDATA", cfg) // where Devin keeps it on Windows dir := filepath.Join(cfg, "devin") path := filepath.Join(dir, "config.json") @@ -117,7 +119,9 @@ func TestDevinModelAndEffort(t *testing.T) { home := t.TempDir() cfg := filepath.Join(home, ".config") t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) t.Setenv("XDG_CONFIG_HOME", cfg) + t.Setenv("APPDATA", cfg) // where Devin keeps it on Windows path := filepath.Join(cfg, "devin", "config.json") os.MkdirAll(filepath.Dir(path), 0o755) os.WriteFile(path, []byte(`{"agent": {"model": "swe-2-max"}}`), 0o644) diff --git a/internal/agent/dsh_route_test.go b/internal/agent/dsh_route_test.go index 71e61e761..8ed79eb4f 100644 --- a/internal/agent/dsh_route_test.go +++ b/internal/agent/dsh_route_test.go @@ -13,6 +13,7 @@ func dshRouteHome(t *testing.T) (home, dir, web string) { t.Helper() home = t.TempDir() t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) t.Setenv("DSH_HOME", "") t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache")) diff --git a/internal/agent/dsh_test.go b/internal/agent/dsh_test.go index b0ffd0e8b..9ebc47208 100644 --- a/internal/agent/dsh_test.go +++ b/internal/agent/dsh_test.go @@ -15,6 +15,7 @@ import ( func TestDsh(t *testing.T) { home := t.TempDir() t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) t.Setenv("DSH_HOME", "") t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache")) @@ -90,6 +91,7 @@ func TestDsh(t *testing.T) { func TestDshProfiles(t *testing.T) { home := t.TempDir() t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) t.Setenv("DSH_HOME", "") t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache")) @@ -175,6 +177,7 @@ func TestDshSettingsEndpoint(t *testing.T) { func TestDshModelLimits(t *testing.T) { home := t.TempDir() t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) t.Setenv("DSH_HOME", "") t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache")) @@ -208,6 +211,7 @@ func TestDshModelLimits(t *testing.T) { func TestDshProfileMadeLater(t *testing.T) { home := t.TempDir() t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) t.Setenv("DSH_HOME", "") t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache")) diff --git a/internal/agent/effort_test.go b/internal/agent/effort_test.go index a4ffff376..7674d0eab 100644 --- a/internal/agent/effort_test.go +++ b/internal/agent/effort_test.go @@ -16,8 +16,12 @@ func effortHome(t *testing.T) string { 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")) + // where Windows keeps Goose's, Crush's and Devin's: the sandbox's, never the machine's + t.Setenv("APPDATA", filepath.Join(home, "AppData", "Roaming")) + t.Setenv("LOCALAPPDATA", filepath.Join(home, "AppData", "Local")) t.Setenv("HERMES_HOME", "") t.Setenv("MIMOCODE_HOME", "") t.Setenv("HANA_HOME", "") @@ -84,8 +88,8 @@ func TestEffortFields(t *testing.T) { writeFile(t, filepath.Join(home, ".omp", "agent", "config.yml"), "modelRoles:\n default: a/b\n") setEffort(t, omp(home), "xhigh", "default: a/b") - writeFile(t, filepath.Join(cfg, "goose", "config.yaml"), "GOOSE_MODEL: m\nGOOSE_PROVIDER: p\n") g := goose(home, cfg) + writeFile(t, g.Path, "GOOSE_MODEL: m\nGOOSE_PROVIDER: p\n") setEffort(t, g, "max", "GOOSE_MODEL: m") if v, _ := edit.GetYAMLTop(g.Path, "GOOSE_PROVIDER"); v != "p" { t.Fatalf("goose provider: %q", v) diff --git a/internal/agent/fx_test.go b/internal/agent/fx_test.go index 1d3421ce7..079be1c3a 100644 --- a/internal/agent/fx_test.go +++ b/internal/agent/fx_test.go @@ -12,6 +12,7 @@ import ( func TestFx(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")) if err := provider.Save(provider.Provider{ID: "deepseek", Name: "DeepSeek", Chat: "https://api.deepseek.com/v1", Key: "k", Models: []string{"pro", "flash"}}); err != nil { diff --git a/internal/agent/gemini_detect_test.go b/internal/agent/gemini_detect_test.go index 44467ca60..850070d8d 100644 --- a/internal/agent/gemini_detect_test.go +++ b/internal/agent/gemini_detect_test.go @@ -13,6 +13,7 @@ import ( func TestGeminiNotAntigravity(t *testing.T) { home := t.TempDir() t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) t.Setenv("PATH", t.TempDir()) dir := filepath.Join(home, ".gemini") for _, d := range []string{"antigravity", "config", "antigravity-cli"} { diff --git a/internal/agent/grok_test.go b/internal/agent/grok_test.go index b40053c5b..69ec6681b 100644 --- a/internal/agent/grok_test.go +++ b/internal/agent/grok_test.go @@ -13,6 +13,7 @@ import ( func TestGrok(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")) t.Setenv("GROK_HOME", filepath.Join(home, "grok")) diff --git a/internal/agent/grouplevels_test.go b/internal/agent/grouplevels_test.go index 88a926421..8db28ee48 100644 --- a/internal/agent/grouplevels_test.go +++ b/internal/agent/grouplevels_test.go @@ -16,6 +16,7 @@ import ( func TestGroupLevelsReachAgents(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")) if err := provider.Save(provider.Provider{ID: "a", Name: "A", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"flash", "sol"}}); err != nil { diff --git a/internal/agent/hanako_test.go b/internal/agent/hanako_test.go index 33f5cf241..d32535d28 100644 --- a/internal/agent/hanako_test.go +++ b/internal/agent/hanako_test.go @@ -8,6 +8,7 @@ import ( "net/url" "os" "path/filepath" + "runtime" "strings" "sync" "testing" @@ -146,7 +147,7 @@ func TestHanakoFiles(t *testing.T) { if d, _ := json.Marshal(c["meta"].(map[string]any)["deletedProviders"]); string(d) != `["old"]` { t.Fatalf("deletedProviders: %s", d) } - if st, _ := os.Stat(catalogPath); st.Mode().Perm() != 0o600 { + if st, _ := os.Stat(catalogPath); runtime.GOOS != "windows" && st.Mode().Perm() != 0o600 { // Windows has no such bits t.Fatalf("mode %v", st.Mode()) } if _, err := os.Stat(filepath.Dir(filepath.Dir(stale))); !os.IsNotExist(err) { @@ -260,7 +261,7 @@ func TestHanakoFresh(t *testing.T) { if c["catalogVersion"] != float64(2) || len(c) != 2 { t.Fatalf("catalog: %v", c) } - if st, _ := os.Stat(path); st.Mode().Perm() != 0o600 { + if st, _ := os.Stat(path); runtime.GOOS != "windows" && st.Mode().Perm() != 0o600 { // Windows has no such bits t.Fatalf("mode %v", st.Mode()) } if chat, raw := hanakoChatOf(t, filepath.Join(dir, "agents", "a", "config.yaml")); chat["id"] != "relay/glm-4.6" || chat["provider"] != "magpie" { diff --git a/internal/agent/hermes_test.go b/internal/agent/hermes_test.go index 06a6f7d20..b9bf0fcd5 100644 --- a/internal/agent/hermes_test.go +++ b/internal/agent/hermes_test.go @@ -13,6 +13,7 @@ import ( func TestHermes(t *testing.T) { home := t.TempDir() t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) t.Setenv("HERMES_HOME", "") t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache")) diff --git a/internal/agent/image_input_test.go b/internal/agent/image_input_test.go index dca2dd7e4..2e7a2deb0 100644 --- a/internal/agent/image_input_test.go +++ b/internal/agent/image_input_test.go @@ -16,6 +16,7 @@ import ( func TestConfiguredModelsAdvertiseImageInput(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")) if err := provider.Save(provider.Provider{ @@ -122,6 +123,7 @@ func imageInputBool(v bool) *bool { return &v } func TestInferredGroupImagesReachAgentCatalogs(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")) if err := os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755); err != nil { diff --git a/internal/agent/kimi_code_test.go b/internal/agent/kimi_code_test.go index 9c49e83a3..a9618d320 100644 --- a/internal/agent/kimi_code_test.go +++ b/internal/agent/kimi_code_test.go @@ -16,6 +16,7 @@ import ( func TestKimiCode(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")) t.Setenv("KIMI_SHARE_DIR", "") diff --git a/internal/agent/kimi_efforts_test.go b/internal/agent/kimi_efforts_test.go index e9c79d31a..09aaacaaa 100644 --- a/internal/agent/kimi_efforts_test.go +++ b/internal/agent/kimi_efforts_test.go @@ -19,6 +19,7 @@ import ( func TestKimiEfforts(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")) t.Setenv("KIMI_SHARE_DIR", "") diff --git a/internal/agent/kimi_test.go b/internal/agent/kimi_test.go index 1112f8303..7d0ec932f 100644 --- a/internal/agent/kimi_test.go +++ b/internal/agent/kimi_test.go @@ -15,6 +15,7 @@ import ( func TestKimi(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")) t.Setenv("KIMI_SHARE_DIR", "") @@ -159,6 +160,7 @@ max_steps_per_turn = 100 func TestKimiNoConfig(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")) t.Setenv("KIMI_SHARE_DIR", filepath.Join(home, "share")) diff --git a/internal/agent/legacy_test.go b/internal/agent/legacy_test.go index d67b5478a..3615ca32b 100644 --- a/internal/agent/legacy_test.go +++ b/internal/agent/legacy_test.go @@ -14,6 +14,7 @@ import ( func TestRenameLegacy(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")) write := func(rel, body string) { @@ -38,7 +39,7 @@ func TestRenameLegacy(t *testing.T) { "theme": "dark" } `) - write(".codex/config.toml", "model_reasoning_effort = \"high\"\nmodel = \"deepseek/deepseek-flash\"\nmodel_provider = \"dial\"\nmodel_catalog_json = \""+filepath.Join(home, ".codex", "dial-models.json")+"\"\n\n[projects.\"/x\"]\ntrust_level = \"trusted\"\n\n[model_providers.dial]\nname = \"dial\"\nbase_url = \"http://127.0.0.1:3425/v1\"\nwire_api = \"responses\"\nexperimental_bearer_token = \"dial\"\n") + write(".codex/config.toml", "model_reasoning_effort = \"high\"\nmodel = \"deepseek/deepseek-flash\"\nmodel_provider = \"dial\"\nmodel_catalog_json = '"+filepath.Join(home, ".codex", "dial-models.json")+"'\n\n[projects.\"/x\"]\ntrust_level = \"trusted\"\n\n[model_providers.dial]\nname = \"dial\"\nbase_url = \"http://127.0.0.1:3425/v1\"\nwire_api = \"responses\"\nexperimental_bearer_token = \"dial\"\n") write(".codex/dial-models.json", "{}") write(".pi/agent/settings.json", `{"defaultProvider": "dial", "defaultModel": "deepseek/deepseek-flash", "theme": "dark"}`) write(".pi/agent/models.json", `{"providers": {"dial": {"api": "openai-completions", "apiKey": "dial", "baseUrl": "http://127.0.0.1:3425/v1", "models": []}}}`) @@ -104,6 +105,7 @@ func TestRenameLegacy(t *testing.T) { func TestMoveCursorEfforts(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")) if err := provider.Save(provider.Provider{ID: "curs", Name: "Curs", Chat: "https://curs.example/v1", Key: "k", Models: []string{"grok-4.7"}}); err != nil { diff --git a/internal/agent/minimax_test.go b/internal/agent/minimax_test.go index f37f63215..237931d58 100644 --- a/internal/agent/minimax_test.go +++ b/internal/agent/minimax_test.go @@ -47,6 +47,7 @@ func miniMaxHome(t *testing.T) (home, path string) { 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("MINIMAX_DATA_DIR", "") diff --git a/internal/agent/modelprefs_test.go b/internal/agent/modelprefs_test.go index 6c7baa52a..1c580f12b 100644 --- a/internal/agent/modelprefs_test.go +++ b/internal/agent/modelprefs_test.go @@ -26,7 +26,7 @@ func TestModelNameAndLevelsReachAgentFiles(t *testing.T) { writeFile(t, piModels, `{"providers":{"magpie":{"name":"magpie","models":[]}}}`) codexDir := filepath.Join(home, ".codex") codexCat := filepath.Join(codexDir, "magpie-models.json") - writeFile(t, filepath.Join(codexDir, "config.toml"), "model = \"relay/glm-4.6\"\nmodel_provider = \"magpie\"\nmodel_catalog_json = \""+codexCat+"\"\n") + writeFile(t, filepath.Join(codexDir, "config.toml"), "model = \"relay/glm-4.6\"\nmodel_provider = \"magpie\"\nmodel_catalog_json = '"+codexCat+"'\n") writeFile(t, codexCat, `{"models":[]}`) catalog.Changed = SyncCatalog t.Cleanup(func() { catalog.Changed = nil }) diff --git a/internal/agent/muse_test.go b/internal/agent/muse_test.go index 35f7d2070..7b9877768 100644 --- a/internal/agent/muse_test.go +++ b/internal/agent/muse_test.go @@ -17,6 +17,7 @@ func museHome(t *testing.T) (home, path string) { 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")) if err := provider.Save(provider.Provider{ID: "deepseek", Name: "DeepSeek", Chat: "https://api.deepseek.com/v1", Key: "k", Models: []string{"pro", "flash"}}); err != nil { diff --git a/internal/agent/omp_max_test.go b/internal/agent/omp_max_test.go index 950bb17e4..ac22dbcf5 100644 --- a/internal/agent/omp_max_test.go +++ b/internal/agent/omp_max_test.go @@ -16,6 +16,7 @@ import ( func TestOmpGroupOffersMax(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")) if err := provider.Save(provider.Provider{ID: "a", Name: "A", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"sol", "flash"}}); err != nil { diff --git a/internal/agent/omp_test.go b/internal/agent/omp_test.go index 0efe91d79..8724b6c7b 100644 --- a/internal/agent/omp_test.go +++ b/internal/agent/omp_test.go @@ -17,6 +17,7 @@ import ( func TestOmp(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")) for _, k := range []string{"PI_CODING_AGENT_DIR", "PI_CONFIG_DIR", "OMP_PROFILE", "PI_PROFILE"} { @@ -108,6 +109,7 @@ func TestOmp(t *testing.T) { func TestOmpRefsBeyondDefault(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")) for _, k := range []string{"PI_CODING_AGENT_DIR", "PI_CONFIG_DIR", "OMP_PROFILE", "PI_PROFILE"} { @@ -203,6 +205,7 @@ task: func TestOmpNamedToTheGateway(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")) for _, k := range []string{"PI_CODING_AGENT_DIR", "PI_CONFIG_DIR", "OMP_PROFILE", "PI_PROFILE"} { @@ -238,6 +241,7 @@ func TestOmpNamedToTheGateway(t *testing.T) { func TestOmpRoles(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")) for _, k := range []string{"PI_CODING_AGENT_DIR", "PI_CONFIG_DIR", "OMP_PROFILE", "PI_PROFILE"} { @@ -309,6 +313,7 @@ func TestOmpRoles(t *testing.T) { func TestOmpLevels(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")) t.Setenv("PATH", t.TempDir()) @@ -392,6 +397,7 @@ func TestOmpLevels(t *testing.T) { func TestOmpLevelSuffix(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")) t.Setenv("PATH", t.TempDir()) @@ -445,6 +451,7 @@ func TestOmpLevelSuffix(t *testing.T) { func TestOmpRoleList(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")) for _, k := range []string{"PI_CODING_AGENT_DIR", "PI_CONFIG_DIR", "OMP_PROFILE", "PI_PROFILE"} { @@ -484,6 +491,7 @@ func TestOmpRoleList(t *testing.T) { func TestOmpRoleAndChain(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")) for _, k := range []string{"PI_CODING_AGENT_DIR", "PI_CONFIG_DIR", "OMP_PROFILE", "PI_PROFILE"} { @@ -539,6 +547,7 @@ func TestOmpListRole(t *testing.T) { t.Run(slow, func(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")) for _, k := range []string{"PI_CODING_AGENT_DIR", "PI_CONFIG_DIR", "OMP_PROFILE", "PI_PROFILE"} { @@ -573,6 +582,7 @@ func TestOmpListRole(t *testing.T) { func TestOmpListRoleRenamed(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")) for _, k := range []string{"PI_CODING_AGENT_DIR", "PI_CONFIG_DIR", "OMP_PROFILE", "PI_PROFILE"} { @@ -615,6 +625,7 @@ func TestOmpListRoleRenamed(t *testing.T) { func TestOmpOwnModels(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")) for _, k := range []string{"PI_CODING_AGENT_DIR", "PI_CONFIG_DIR", "OMP_PROFILE", "PI_PROFILE"} { diff --git a/internal/agent/opencode_variants_test.go b/internal/agent/opencode_variants_test.go index add10e3c7..c04be2fc2 100644 --- a/internal/agent/opencode_variants_test.go +++ b/internal/agent/opencode_variants_test.go @@ -43,6 +43,7 @@ func TestOpenCodeVariants(t *testing.T) { func TestOpenCodeWritesVariants(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")) if err := provider.Save(provider.Provider{ @@ -131,6 +132,7 @@ func TestOpenCodeWritesVariants(t *testing.T) { func TestOpenCodeNoResellerLevelsForSwitchModel(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")) os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755) diff --git a/internal/agent/plainnames_test.go b/internal/agent/plainnames_test.go index 07b8c0ec2..bfe0a09ce 100644 --- a/internal/agent/plainnames_test.go +++ b/internal/agent/plainnames_test.go @@ -15,6 +15,7 @@ import ( func TestPlainNamesReachAgents(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")) catalog.Changed = nil diff --git a/internal/agent/qoder_test.go b/internal/agent/qoder_test.go index 94237e13e..07d72fffb 100644 --- a/internal/agent/qoder_test.go +++ b/internal/agent/qoder_test.go @@ -31,6 +31,7 @@ func TestQoder(t *testing.T) { func testQoder(t *testing.T, mk func(string) *Agent, rel string) { home := t.TempDir() t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) t.Setenv("QODER_CONFIG_DIR", "") t.Setenv("QODERCN_CONFIG_DIR", "") t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) diff --git a/internal/agent/sync_test.go b/internal/agent/sync_test.go index 72728c6c6..c44173f15 100644 --- a/internal/agent/sync_test.go +++ b/internal/agent/sync_test.go @@ -23,6 +23,7 @@ func syncHome(t *testing.T) string { 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("CODEX_HOME", "") @@ -198,7 +199,7 @@ func TestSyncCatalogRewritesAgentLists(t *testing.T) { writeFile(t, crushCfg, crushBody) codexDir := filepath.Join(home, ".codex") codexCat := filepath.Join(codexDir, "magpie-models.json") - writeFile(t, filepath.Join(codexDir, "config.toml"), "model = \"relay/glm-4.6\"\nmodel_provider = \"magpie\"\nmodel_catalog_json = \""+codexCat+"\"\n") + writeFile(t, filepath.Join(codexDir, "config.toml"), "model = \"relay/glm-4.6\"\nmodel_provider = \"magpie\"\nmodel_catalog_json = '"+codexCat+"'\n") writeFile(t, codexCat, `{"models":[]}`) if err := provider.Save(provider.Provider{ID: "added", Name: "Added", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"m2"}}); err != nil { diff --git a/internal/agent/unset_test.go b/internal/agent/unset_test.go index ec696687e..4200b4acc 100644 --- a/internal/agent/unset_test.go +++ b/internal/agent/unset_test.go @@ -13,9 +13,12 @@ import ( func TestUnsetAgentsReadEmpty(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")) t.Setenv("XDG_DATA_HOME", filepath.Join(home, ".local", "share")) + t.Setenv("APPDATA", filepath.Join(home, "AppData", "Roaming")) + t.Setenv("LOCALAPPDATA", filepath.Join(home, "AppData", "Local")) for _, a := range All() { for _, f := range a.Fields { if v := f.Get(); v != "" { @@ -28,6 +31,7 @@ func TestUnsetAgentsReadEmpty(t *testing.T) { func TestGeminiAuthUnset(t *testing.T) { home := t.TempDir() t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) dir := filepath.Join(home, ".gemini") os.MkdirAll(dir, 0o755) a := gemini(home) diff --git a/internal/agent/workbuddy_test.go b/internal/agent/workbuddy_test.go index 1021420f5..f44f1c5e2 100644 --- a/internal/agent/workbuddy_test.go +++ b/internal/agent/workbuddy_test.go @@ -12,6 +12,7 @@ import ( func TestWorkBuddy(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")) t.Setenv("WORKBUDDY_CONFIG_DIR", "") diff --git a/internal/agent/zcode_test.go b/internal/agent/zcode_test.go index e2a740d66..f3dc59835 100644 --- a/internal/agent/zcode_test.go +++ b/internal/agent/zcode_test.go @@ -14,6 +14,7 @@ import ( func TestZCode(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")) if err := provider.Save(provider.Provider{ID: "deepseek", Name: "DeepSeek", Chat: "https://api.deepseek.com/v1", Key: "k", Models: []string{"pro"}}); err != nil { @@ -141,6 +142,7 @@ func TestZCode(t *testing.T) { func TestZCodeKeepsUserChoices(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")) if err := provider.Save(provider.Provider{ID: "deepseek", Name: "DeepSeek", Chat: "https://api.deepseek.com/v1", Key: "k", Models: []string{"pro"}}); err != nil { diff --git a/internal/autostart/autostart_darwin_test.go b/internal/autostart/autostart_darwin_test.go index 26de40b84..cddcb0d77 100644 --- a/internal/autostart/autostart_darwin_test.go +++ b/internal/autostart/autostart_darwin_test.go @@ -29,6 +29,7 @@ const olderPlist = ` func TestLaunchAgentLetsTheRelaunchLive(t *testing.T) { home := t.TempDir() t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) if err := Set(true); err != nil { t.Fatal(err) } @@ -49,6 +50,7 @@ func TestLaunchAgentLetsTheRelaunchLive(t *testing.T) { func TestRefreshOlderLaunchAgent(t *testing.T) { home := t.TempDir() t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) if err := Refresh(); err != nil || Enabled() { t.Fatalf("Refresh turned Open at login on: %v", err) } diff --git a/internal/autostart/autostart_test.go b/internal/autostart/autostart_test.go index 3019f8657..0cfe45e08 100644 --- a/internal/autostart/autostart_test.go +++ b/internal/autostart/autostart_test.go @@ -15,6 +15,7 @@ func TestSet(t *testing.T) { } home := t.TempDir() t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) t.Setenv("XDG_CONFIG_HOME", home+"/.config") t.Setenv("APPIMAGE", "/opt/my apps/magpie.AppImage") if Enabled() { diff --git a/internal/backup/caller_keys_test.go b/internal/backup/caller_keys_test.go index bd0f17fc3..4993a714e 100644 --- a/internal/backup/caller_keys_test.go +++ b/internal/backup/caller_keys_test.go @@ -5,6 +5,7 @@ import ( "errors" "os" "reflect" + "runtime" "strings" "testing" @@ -65,7 +66,7 @@ func TestGatewayKeysBackupRoundTrip(t *testing.T) { t.Fatal("restored default key lost its legacy link") } info, err := os.Stat(access.Path()) - if err != nil || info.Mode().Perm() != 0o600 { + if err != nil || runtime.GOOS != "windows" && info.Mode().Perm() != 0o600 { t.Fatal("restored key-store permissions", info, err) } } diff --git a/internal/codexcat/codexcat_test.go b/internal/codexcat/codexcat_test.go index 569fa2511..eaa68f5e5 100644 --- a/internal/codexcat/codexcat_test.go +++ b/internal/codexcat/codexcat_test.go @@ -15,6 +15,7 @@ import ( func TestCodexCatalogKeepsOwnEntries(t *testing.T) { home := t.TempDir() t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) os.MkdirAll(filepath.Join(home, ".codex"), 0o755) os.WriteFile(filepath.Join(home, ".codex", "models_cache.json"), []byte(`{"models":[ {"slug":"gpt-5.5","display_name":"GPT-5.5","priority":3,"visibility":"list","input_modalities":["text","image"], @@ -51,6 +52,7 @@ func TestCodexCatalogKeepsOwnEntries(t *testing.T) { // A model that takes images says so, and Codex lets images be attached. func TestCodexCatalogImages(t *testing.T) { t.Setenv("HOME", t.TempDir()) + t.Setenv("USERPROFILE", os.Getenv("HOME")) var got struct { Models []struct { Modalities []string `json:"input_modalities"` @@ -70,6 +72,7 @@ func TestCodexCatalogImages(t *testing.T) { // neither code mode nor Responses Lite. func TestCodexCatalogToolSearch(t *testing.T) { t.Setenv("HOME", t.TempDir()) + t.Setenv("USERPROFILE", os.Getenv("HOME")) var got struct { Models []map[string]any `json:"models"` } @@ -94,6 +97,7 @@ func TestCodexCatalogToolSearch(t *testing.T) { // takes parallel tool calls (#298), and later Codex ask for them anyway. func TestCodexCatalogParallelToolCalls(t *testing.T) { t.Setenv("HOME", t.TempDir()) + t.Setenv("USERPROFILE", os.Getenv("HOME")) var got struct { Models []map[string]any `json:"models"` } @@ -113,6 +117,7 @@ func TestCodexCatalogParallelToolCalls(t *testing.T) { func TestCodexCatalogServiceTiers(t *testing.T) { home := t.TempDir() t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) os.MkdirAll(filepath.Join(home, ".codex"), 0o755) os.WriteFile(filepath.Join(home, ".codex", "models_cache.json"), []byte(`{"models":[ {"slug":"gpt-6-astra","display_name":"GPT-6 Astra","service_tiers":[{"id":"priority","name":"Fast","description":"2x speed, increased usage"}]}]}`), 0o644) diff --git a/internal/codexcat/tag_test.go b/internal/codexcat/tag_test.go index aa516e119..101e6db33 100644 --- a/internal/codexcat/tag_test.go +++ b/internal/codexcat/tag_test.go @@ -2,6 +2,7 @@ package codexcat import ( "encoding/json" + "os" "testing" "github.com/yetone/magpie/internal/catalog" @@ -11,6 +12,7 @@ import ( // the size it assumes of any; one not known leaves it to Codex. func TestEntriesCarryContextWindow(t *testing.T) { t.Setenv("HOME", t.TempDir()) + t.Setenv("USERPROFILE", os.Getenv("HOME")) var got struct { Models []map[string]any `json:"models"` } diff --git a/internal/davsync/davsync_test.go b/internal/davsync/davsync_test.go index fd540cefa..b279b4221 100644 --- a/internal/davsync/davsync_test.go +++ b/internal/davsync/davsync_test.go @@ -8,6 +8,7 @@ import ( "net/http/httptest" "os" "path/filepath" + "runtime" "slices" "strings" "sync" @@ -44,7 +45,7 @@ func (f *fakeDAV) ServeHTTP(w http.ResponseWriter, r *http.Request) { switch r.Method { case http.MethodGet: b, ok := f.files[r.URL.Path] - if !ok && f.nutstore && !f.dirs[filepath.Dir(r.URL.Path)] { + if !ok && f.nutstore && !f.dirs[urlDir(r.URL.Path)] { w.WriteHeader(http.StatusConflict) return } @@ -55,7 +56,7 @@ func (f *fakeDAV) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.Header().Set("ETag", f.etags[r.URL.Path]) w.Write(b) case http.MethodPut: - if !f.dirs[filepath.Dir(r.URL.Path)] { + if !f.dirs[urlDir(r.URL.Path)] { w.WriteHeader(http.StatusConflict) return } @@ -81,6 +82,9 @@ func (f *fakeDAV) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } +// urlDir is the folder a URL path is in: a URL's, with / on every system +func urlDir(p string) string { return p[:max(strings.LastIndex(p, "/"), 1)] } + // computer is one machine's magpie: its own home, which the test moves // between. type computer string @@ -89,6 +93,7 @@ func newComputer(t *testing.T) computer { return computer(t.TempDir()) } func (c computer) use(t *testing.T) { t.Setenv("HOME", string(c)) + t.Setenv("USERPROFILE", string(c)) t.Setenv("XDG_CONFIG_HOME", filepath.Join(string(c), ".config")) t.Setenv("XDG_CACHE_HOME", filepath.Join(string(c), ".cache")) t.Setenv("CLAUDE_CONFIG_DIR", filepath.Join(string(c), ".claude")) @@ -136,7 +141,7 @@ func TestSync(t *testing.T) { if err := Configure(cfg); err != nil { t.Fatal(err) } - if fi, _ := os.Stat(path("sync.json")); fi.Mode().Perm() != 0o600 { + if fi, _ := os.Stat(path("sync.json")); runtime.GOOS != "windows" && fi.Mode().Perm() != 0o600 { // Windows has no such bits t.Fatalf("sync.json is %v", fi.Mode()) } // the first: its setup goes up, sealed diff --git a/internal/edit/symlink_test.go b/internal/edit/symlink_test.go index 27797480a..aeea10e08 100644 --- a/internal/edit/symlink_test.go +++ b/internal/edit/symlink_test.go @@ -4,6 +4,7 @@ import ( "errors" "os" "path/filepath" + "runtime" "testing" ) @@ -49,7 +50,7 @@ func TestWriteAtomicFollowsSymlink(t *testing.T) { if got := read(t, repo); got != "{\n \"model\": \"new\"\n}\n" { t.Fatalf("target: %q", got) } - if st, _ := os.Stat(repo); st.Mode().Perm() != 0o600 { + if st, _ := os.Stat(repo); runtime.GOOS != "windows" && st.Mode().Perm() != 0o600 { // Windows has no such bits t.Errorf("mode %v", st.Mode().Perm()) } if es, _ := os.ReadDir(conf); len(es) != 1 { diff --git a/internal/gateway/search_api_test.go b/internal/gateway/search_api_test.go index 8880d21dd..7eae4ecce 100644 --- a/internal/gateway/search_api_test.go +++ b/internal/gateway/search_api_test.go @@ -6,6 +6,7 @@ import ( "io" "net/http" "net/http/httptest" + "os" "strings" "sync" "testing" @@ -156,6 +157,7 @@ func TestWebSearchBySearchAPI(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 + t.Setenv("USERPROFILE", os.Getenv("HOME")) if err := provider.Save(provider.Provider{ID: "deep", Name: "Deep", Key: "k", Chat: model.URL, Models: []string{"deep-chat"}}); err != nil { t.Fatal(err) } @@ -234,6 +236,7 @@ func TestWebSearchBySearchAPI(t *testing.T) { func TestNoSearchAPINoTool(t *testing.T) { t.Setenv("XDG_CONFIG_HOME", t.TempDir()) t.Setenv("HOME", t.TempDir()) + t.Setenv("USERPROFILE", os.Getenv("HOME")) if canSearch() { t.Fatal("can search with nothing set up") } diff --git a/internal/gui/agent_models_test.go b/internal/gui/agent_models_test.go index 75d86da28..aa645313e 100644 --- a/internal/gui/agent_models_test.go +++ b/internal/gui/agent_models_test.go @@ -20,6 +20,7 @@ import ( func TestAgentModelsAPI(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")) t.Setenv("CODEX_HOME", filepath.Join(home, ".codex")) @@ -83,6 +84,7 @@ func TestAgentModelsAPI(t *testing.T) { func TestAgentModelLineAllHidden(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")) t.Setenv("CODEX_HOME", filepath.Join(home, ".codex")) diff --git a/internal/gui/api_settings_test.go b/internal/gui/api_settings_test.go index 8f66bbe56..e9de2d7c8 100644 --- a/internal/gui/api_settings_test.go +++ b/internal/gui/api_settings_test.go @@ -24,6 +24,7 @@ import ( func TestSettingsPageSaveCarriesEveryPerModelTable(t *testing.T) { h := t.TempDir() t.Setenv("HOME", h) + t.Setenv("USERPROFILE", h) t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config")) t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache")) @@ -68,6 +69,7 @@ func TestSettingsPageSaveCarriesEveryPerModelTable(t *testing.T) { func TestSettingsPageSaveKeepsWhichModelsAnAgentIsShown(t *testing.T) { h := t.TempDir() t.Setenv("HOME", h) + t.Setenv("USERPROFILE", h) t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config")) t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache")) diff --git a/internal/gui/assets_revalidate_test.go b/internal/gui/assets_revalidate_test.go index bee23e492..2abb4cc79 100644 --- a/internal/gui/assets_revalidate_test.go +++ b/internal/gui/assets_revalidate_test.go @@ -14,6 +14,7 @@ import ( func TestPageFilesRevalidate(t *testing.T) { h := t.TempDir() t.Setenv("HOME", h) + t.Setenv("USERPROFILE", h) t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config")) t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache")) srv := Handler(webHost{}, nil) diff --git a/internal/gui/fx_test.go b/internal/gui/fx_test.go index e468f9673..3b72ec0df 100644 --- a/internal/gui/fx_test.go +++ b/internal/gui/fx_test.go @@ -18,6 +18,7 @@ import ( func TestFXInState(t *testing.T) { h := t.TempDir() t.Setenv("HOME", h) + t.Setenv("USERPROFILE", h) t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config")) t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache")) fx.Reset() diff --git a/internal/gui/groupfast_test.go b/internal/gui/groupfast_test.go index 3fd4023a9..df4b2866a 100644 --- a/internal/gui/groupfast_test.go +++ b/internal/gui/groupfast_test.go @@ -3,6 +3,7 @@ package gui import ( "net/http" "net/http/httptest" + "os" "slices" "strings" "testing" @@ -14,6 +15,7 @@ import ( // have a fast mode, and which members are sent in it. func TestGroupSaveFast(t *testing.T) { t.Setenv("HOME", t.TempDir()) + t.Setenv("USERPROFILE", os.Getenv("HOME")) t.Setenv("XDG_CONFIG_HOME", t.TempDir()) t.Setenv("XDG_CACHE_HOME", t.TempDir()) for _, p := range []provider.Provider{ diff --git a/internal/gui/groups_test.go b/internal/gui/groups_test.go index 8efd05356..0269edb39 100644 --- a/internal/gui/groups_test.go +++ b/internal/gui/groups_test.go @@ -3,6 +3,7 @@ package gui import ( "net/http" "net/http/httptest" + "os" "strings" "testing" @@ -13,6 +14,7 @@ import ( // renames it: a found group drops its auto- prefix. func TestGroupSaveRenames(t *testing.T) { t.Setenv("HOME", t.TempDir()) + t.Setenv("USERPROFILE", os.Getenv("HOME")) t.Setenv("XDG_CONFIG_HOME", t.TempDir()) t.Setenv("XDG_CACHE_HOME", t.TempDir()) for _, id := range []string{"a", "b"} { diff --git a/internal/gui/importlink_test.go b/internal/gui/importlink_test.go index f1c64e3e6..3236ce024 100644 --- a/internal/gui/importlink_test.go +++ b/internal/gui/importlink_test.go @@ -11,6 +11,7 @@ import ( func TestImportIsReadOnce(t *testing.T) { home := t.TempDir() t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) t.Setenv("XDG_CONFIG_HOME", home) mux := http.NewServeMux() importRoutes(mux) @@ -38,6 +39,7 @@ func TestImportIsReadOnce(t *testing.T) { func TestImportIconRoute(t *testing.T) { home := t.TempDir() t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) t.Setenv("XDG_CONFIG_HOME", home) mux := http.NewServeMux() importRoutes(mux) diff --git a/internal/gui/providers_decide_test.go b/internal/gui/providers_decide_test.go index ca59b3948..22848eea5 100644 --- a/internal/gui/providers_decide_test.go +++ b/internal/gui/providers_decide_test.go @@ -3,6 +3,7 @@ package gui import ( "net/http" "net/http/httptest" + "os" "strings" "testing" @@ -13,6 +14,7 @@ import ( // Cloudflare's names the account — and one saved without keeps the preset's. func TestProviderSaveDecideEndpoint(t *testing.T) { t.Setenv("HOME", t.TempDir()) + t.Setenv("USERPROFILE", os.Getenv("HOME")) t.Setenv("XDG_CONFIG_HOME", t.TempDir()) t.Setenv("XDG_CACHE_HOME", t.TempDir()) mux := http.NewServeMux() diff --git a/internal/gui/providers_draw_test.go b/internal/gui/providers_draw_test.go index 59bf1e5df..854af4b28 100644 --- a/internal/gui/providers_draw_test.go +++ b/internal/gui/providers_draw_test.go @@ -4,6 +4,7 @@ import ( "io" "net/http" "net/http/httptest" + "os" "strings" "testing" @@ -14,6 +15,7 @@ import ( // editor to list apart from the models agents chat with. func TestProviderInfoListsImageModels(t *testing.T) { t.Setenv("HOME", t.TempDir()) + t.Setenv("USERPROFILE", os.Getenv("HOME")) t.Setenv("XDG_CONFIG_HOME", t.TempDir()) t.Setenv("XDG_CACHE_HOME", t.TempDir()) up := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/internal/gui/providers_move_test.go b/internal/gui/providers_move_test.go index d47cae802..82397f307 100644 --- a/internal/gui/providers_move_test.go +++ b/internal/gui/providers_move_test.go @@ -14,6 +14,7 @@ import ( func TestMoveOutlivesRequest(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")) t.Setenv("PATH", t.TempDir()) diff --git a/internal/gui/providers_reseat_test.go b/internal/gui/providers_reseat_test.go index 024cba111..b92ffad69 100644 --- a/internal/gui/providers_reseat_test.go +++ b/internal/gui/providers_reseat_test.go @@ -18,6 +18,7 @@ import ( func TestProviderOffMovesAgents(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")) t.Setenv("PATH", t.TempDir()) diff --git a/internal/gui/providers_typed_test.go b/internal/gui/providers_typed_test.go index 46d2516a8..5f593f68b 100644 --- a/internal/gui/providers_typed_test.go +++ b/internal/gui/providers_typed_test.go @@ -4,6 +4,7 @@ import ( "encoding/json" "net/http" "net/http/httptest" + "os" "strings" "testing" @@ -15,6 +16,7 @@ import ( // the editor); the saved key stays as it was. func TestProviderTypedKey(t *testing.T) { t.Setenv("HOME", t.TempDir()) + t.Setenv("USERPROFILE", os.Getenv("HOME")) t.Setenv("XDG_CONFIG_HOME", t.TempDir()) t.Setenv("XDG_CACHE_HOME", t.TempDir()) vendor := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/internal/gui/set_fast_unix_test.go b/internal/gui/set_fast_unix_test.go index 1398c8540..548867b51 100644 --- a/internal/gui/set_fast_unix_test.go +++ b/internal/gui/set_fast_unix_test.go @@ -28,6 +28,7 @@ import ( func TestSetAnswersWhileDevinAndProvidersHang(t *testing.T) { h := t.TempDir() t.Setenv("HOME", h) + t.Setenv("USERPROFILE", h) t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config")) t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache")) t.Setenv("XDG_DATA_HOME", filepath.Join(h, ".local", "share")) diff --git a/internal/gui/settings_keep_test.go b/internal/gui/settings_keep_test.go index 54228a1b8..6bbd56590 100644 --- a/internal/gui/settings_keep_test.go +++ b/internal/gui/settings_keep_test.go @@ -19,6 +19,7 @@ import ( func TestSettingsSaveKeepsModelChoices(t *testing.T) { h := t.TempDir() t.Setenv("HOME", h) + t.Setenv("USERPROFILE", h) t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config")) t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache")) if err := settings.Save(settings.Settings{ @@ -47,6 +48,7 @@ func TestSettingsSaveKeepsModelChoices(t *testing.T) { func TestSettingsSaveKeepsWhatItDoesNotSend(t *testing.T) { h := t.TempDir() t.Setenv("HOME", h) + t.Setenv("USERPROFILE", h) t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config")) t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache")) js, err := os.ReadFile("assets/app.js") @@ -121,6 +123,7 @@ func TestSettingsSaveKeepsWhatItDoesNotSend(t *testing.T) { func TestUpdateSkip(t *testing.T) { h := t.TempDir() t.Setenv("HOME", h) + t.Setenv("USERPROFILE", h) t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config")) t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache")) post := func(path, body string) { diff --git a/internal/gui/takeover_test.go b/internal/gui/takeover_test.go index 72c1a941e..7e3394810 100644 --- a/internal/gui/takeover_test.go +++ b/internal/gui/takeover_test.go @@ -3,6 +3,7 @@ package gui import ( "net" "net/http" + "os" "testing" "time" @@ -13,6 +14,7 @@ import ( // is gone (one left running from before an update, a magpie serve). func TestGatewayTakenOver(t *testing.T) { t.Setenv("HOME", t.TempDir()) + t.Setenv("USERPROFILE", os.Getenv("HOME")) t.Setenv("XDG_CONFIG_HOME", t.TempDir()) t.Setenv("XDG_CACHE_HOME", t.TempDir()) ln, err := net.Listen("tcp", "127.0.0.1:0") diff --git a/internal/gui/textsize_test.go b/internal/gui/textsize_test.go index 94096c1ba..7e40742cc 100644 --- a/internal/gui/textsize_test.go +++ b/internal/gui/textsize_test.go @@ -56,6 +56,7 @@ func (z *zoomWindows) SetTextSize(n int) { z.sizes = append(z.sizes, n) } func TestTextSizeSetting(t *testing.T) { h := t.TempDir() t.Setenv("HOME", h) + t.Setenv("USERPROFILE", h) t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config")) t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache")) w := &zoomWindows{} diff --git a/internal/gui/traymenu_test.go b/internal/gui/traymenu_test.go index cf98e7591..fc5f6defa 100644 --- a/internal/gui/traymenu_test.go +++ b/internal/gui/traymenu_test.go @@ -59,6 +59,7 @@ func TestTrayMenuLabels(t *testing.T) { func TestSettingsLangRelabelsTray(t *testing.T) { h := t.TempDir() t.Setenv("HOME", h) + t.Setenv("USERPROFILE", h) t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config")) t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache")) if err := settings.Save(settings.Settings{Lang: "en"}); err != nil { diff --git a/internal/gui/unlisted_test.go b/internal/gui/unlisted_test.go index 2aa9deef2..0eda8bffb 100644 --- a/internal/gui/unlisted_test.go +++ b/internal/gui/unlisted_test.go @@ -2,6 +2,7 @@ package gui import ( "net/url" + "os" "slices" "testing" @@ -16,6 +17,7 @@ import ( // new group of it. func TestUnlistedModelsSaid(t *testing.T) { t.Setenv("HOME", t.TempDir()) + t.Setenv("USERPROFILE", os.Getenv("HOME")) t.Setenv("XDG_CONFIG_HOME", t.TempDir()) t.Setenv("XDG_CACHE_HOME", t.TempDir()) if err := provider.Save(provider.Provider{ID: "hunyuan", Name: "Hunyuan", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"hy3", "hy4"}, Unlisted: true}); err != nil { diff --git a/internal/gui/update_proxy_test.go b/internal/gui/update_proxy_test.go index 9cadb45a0..366697a1d 100644 --- a/internal/gui/update_proxy_test.go +++ b/internal/gui/update_proxy_test.go @@ -20,6 +20,7 @@ import ( func TestSettingsProxyRechecksAFailedUpdate(t *testing.T) { h := t.TempDir() t.Setenv("HOME", h) + t.Setenv("USERPROFILE", h) t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config")) t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache")) for _, k := range []string{"HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy", "ALL_PROXY", "all_proxy", "NO_PROXY", "no_proxy"} { diff --git a/internal/gui/usage_test.go b/internal/gui/usage_test.go index 0e2bf387a..637d512e7 100644 --- a/internal/gui/usage_test.go +++ b/internal/gui/usage_test.go @@ -122,7 +122,7 @@ func TestUsageLedgerRoutes(t *testing.T) { p1, n := export() p2, _ := export() day := time.Now().Format("2006-01-02") - if n != 2 || p1 != "~/Downloads/magpie-requests-today-"+day+".csv" || p2 != "~/Downloads/magpie-requests-today-"+day+"-2.csv" { + if n != 2 || p1 != filepath.Join("~", "Downloads", "magpie-requests-today-"+day+".csv") || p2 != filepath.Join("~", "Downloads", "magpie-requests-today-"+day+"-2.csv") { t.Fatalf("export: %s %s %d", p1, p2, n) } b, err := os.ReadFile(filepath.Join(home, "Downloads", "magpie-requests-today-"+day+".csv")) diff --git a/internal/imagemcp/imagemcp.go b/internal/imagemcp/imagemcp.go index a089b5074..f0f239544 100644 --- a/internal/imagemcp/imagemcp.go +++ b/internal/imagemcp/imagemcp.go @@ -20,6 +20,7 @@ import ( "os" "path/filepath" "regexp" + "runtime" "strconv" "strings" "sync" @@ -396,7 +397,7 @@ func (s *server) root() string { json.Unmarshal(m.Result, &r) for _, root := range r.Roots { if u, err := url.Parse(root.URI); err == nil && u.Scheme == "file" && u.Path != "" { - return filepath.FromSlash(u.Path) + return filePath(u) } } case <-time.After(3 * time.Second): @@ -407,6 +408,21 @@ func (s *server) root() string { return "" } +// filePath is the file a file:// URI names: on Windows file:///C:/p is C:\p +// (not \C:\p, a path nowhere) and file://server/share/p is \\server\share\p. +func filePath(u *url.URL) string { + p := u.Path + if runtime.GOOS == "windows" { + if u.Host != "" && u.Host != "localhost" { + return `\\` + u.Host + filepath.FromSlash(p) + } + if len(p) >= 3 && p[0] == '/' && p[2] == ':' { + p = p[1:] + } + } + return filepath.FromSlash(p) +} + // reference is ref as the gateway takes it: a URL as it is, a file as a // data URL. func reference(project, ref string) (string, error) { @@ -414,6 +430,9 @@ func reference(project, ref string) (string, error) { return ref, nil } path := strings.TrimPrefix(ref, "file://") + if u, err := url.Parse(ref); err == nil && u.Scheme == "file" { + path = filePath(u) + } if !filepath.IsAbs(path) { path = filepath.Join(project, path) } diff --git a/internal/imagemcp/imagemcp_test.go b/internal/imagemcp/imagemcp_test.go index 85daaf4e6..8bbb21f5d 100644 --- a/internal/imagemcp/imagemcp_test.go +++ b/internal/imagemcp/imagemcp_test.go @@ -7,8 +7,10 @@ import ( "io" "net/http" "net/http/httptest" + "net/url" "os" "path/filepath" + "runtime" "strings" "sync" "testing" @@ -88,7 +90,7 @@ func (c *client) call(method string, params any) map[string]any { var m map[string]any json.Unmarshal([]byte(line), &m) if m["method"] == "roots/list" { - ans, _ := json.Marshal(map[string]any{"jsonrpc": "2.0", "id": m["id"], "result": map[string]any{"roots": []any{map[string]any{"uri": "file://" + c.root, "name": "p"}}}}) + ans, _ := json.Marshal(map[string]any{"jsonrpc": "2.0", "id": m["id"], "result": map[string]any{"roots": []any{map[string]any{"uri": fileURI(c.root), "name": "p"}}}}) go c.in.Write(append(ans, '\n')) continue } @@ -368,3 +370,35 @@ func TestGenerateVideoChecksItsArguments(t *testing.T) { t.Errorf("seconds \"6\": %v", r) } } + +// fileURI is p as a client names a root: file:///C:/p on Windows. +func fileURI(p string) string { + p = filepath.ToSlash(p) + if !strings.HasPrefix(p, "/") { + p = "/" + p + } + return (&url.URL{Scheme: "file", Path: p}).String() +} + +// A root or a reference given as a file:// URI is the file it names, a +// drive's or a share's on Windows. +func TestFilePath(t *testing.T) { + cases := map[string]string{"file:///tmp/a%20b.png": "/tmp/a b.png"} + if runtime.GOOS == "windows" { + cases = map[string]string{ + "file:///C:/Users/me/a%20b": `C:\Users\me\a b`, + "file:///c%3A/Users/me/p": `c:\Users\me\p`, + "file://server/share/p/i.png": `\\server\share\p\i.png`, + "file://localhost/D:/work/one": `D:\work\one`, + } + } + for in, want := range cases { + u, err := url.Parse(in) + if err != nil { + t.Fatal(err) + } + if got := filePath(u); got != want { + t.Errorf("%s: %q, want %q", in, got, want) + } + } +} diff --git a/internal/library/carry_test.go b/internal/library/carry_test.go index 94935ddc4..71d2745f1 100644 --- a/internal/library/carry_test.go +++ b/internal/library/carry_test.go @@ -4,6 +4,7 @@ import ( "encoding/json" "os" "path/filepath" + "runtime" "strings" "testing" ) @@ -45,7 +46,7 @@ func TestCarry(t *testing.T) { t.Fatalf("skills: %+v", b.Skills) } s := b.Skills[0] - if _, ok := s.Files["SKILL.md"]; !ok || string(s.Files["scripts/run.sh"]) != "echo hi\n" || len(s.Exec) != 1 || s.Exec[0] != "scripts/run.sh" { + if _, ok := s.Files["SKILL.md"]; !ok || string(s.Files["scripts/run.sh"]) != "echo hi\n" || runtime.GOOS != "windows" && (len(s.Exec) != 1 || s.Exec[0] != "scripts/run.sh") { t.Fatalf("pdf: %+v", s) } if _, ok := s.Files["hosts"]; ok || len(s.Left) != 1 || s.Left[0] != "big.bin" { @@ -87,7 +88,7 @@ func TestCarry(t *testing.T) { if s := read(t, filepath.Join(h2, ".claude/skills/pdf/scripts/run.sh")); s != "echo hi\n" { t.Errorf("pdf in claude: %q", s) } - if fi, err := os.Stat(filepath.Join(SkillPath("pdf"), "scripts/run.sh")); err != nil || fi.Mode().Perm()&0o100 == 0 { + if fi, err := os.Stat(filepath.Join(SkillPath("pdf"), "scripts/run.sh")); err != nil || runtime.GOOS != "windows" && fi.Mode().Perm()&0o100 == 0 { t.Errorf("run.sh: %v %v", fi, err) } if _, err := os.Lstat(filepath.Join(h2, ".claude/skills/old")); !os.IsNotExist(err) { diff --git a/internal/library/market_test.go b/internal/library/market_test.go index f1b40f23c..a720732a5 100644 --- a/internal/library/market_test.go +++ b/internal/library/market_test.go @@ -199,6 +199,8 @@ func skillsSh(t *testing.T) *atomic.Int64 { func TestSkillsShPages(t *testing.T) { sandbox(t) + // the cache kept on disk, in what Windows keeps caches in (blank in a sandbox) + t.Setenv("LOCALAPPDATA", t.TempDir()) hits := skillsSh(t) list, err := fetchPopular() if err != nil || len(list) != 1 || list[0].Source != "o/r" || list[0].SkillID != "pdf" || list[0].Installs != 9 { diff --git a/internal/library/projects_test.go b/internal/library/projects_test.go index c4e20891e..de14f73a5 100644 --- a/internal/library/projects_test.go +++ b/internal/library/projects_test.go @@ -5,6 +5,7 @@ import ( "net/http/httptest" "os" "path/filepath" + "runtime" "slices" "strings" "testing" @@ -111,8 +112,9 @@ func TestProjectSkillsCopied(t *testing.T) { t.Error("the copy wasn't made again") } // back to links: the copy becomes a link + // (not on Windows, where a copy as fresh as the library's stands for one) ok(t)(ProjectCopy(proj, false)) - if !isLink(t, p) { + if runtime.GOOS != "windows" && !isLink(t, p) { t.Error("still a copy") } } diff --git a/internal/library/rtk_test.go b/internal/library/rtk_test.go index 9049b38af..77ff36e4e 100644 --- a/internal/library/rtk_test.go +++ b/internal/library/rtk_test.go @@ -101,6 +101,7 @@ func TestRTK(t *testing.T) { func TestRTKRemove(t *testing.T) { h := sandbox(t) hook := func(key, matcher, cmd string) string { + quoted, _ := json.Marshal(cmd) // a Windows path has backslashes return `"hooks": { "` + key + `": [ { @@ -108,7 +109,7 @@ func TestRTKRemove(t *testing.T) { "hooks": [ { "type": "command", - "command": "` + cmd + `" + "command": ` + string(quoted) + ` } ] } diff --git a/internal/plugin/bunupdate_test.go b/internal/plugin/bunupdate_test.go index 7feb8a9e7..c547c44f8 100644 --- a/internal/plugin/bunupdate_test.go +++ b/internal/plugin/bunupdate_test.go @@ -62,6 +62,7 @@ func bunHome(t *testing.T, latest string, published time.Time) { t.Helper() dir := t.TempDir() t.Setenv("HOME", dir) + t.Setenv("USERPROFILE", dir) t.Setenv("XDG_CONFIG_HOME", filepath.Join(dir, "config")) t.Setenv("XDG_CACHE_HOME", filepath.Join(dir, "cache")) t.Setenv("LOCALAPPDATA", filepath.Join(dir, "local")) diff --git a/internal/plugin/plugin_test.go b/internal/plugin/plugin_test.go index 0998f05db..c6629abbc 100644 --- a/internal/plugin/plugin_test.go +++ b/internal/plugin/plugin_test.go @@ -32,6 +32,7 @@ func sandbox(t *testing.T) { } dir := t.TempDir() t.Setenv("HOME", dir) + t.Setenv("USERPROFILE", dir) t.Setenv("XDG_CONFIG_HOME", filepath.Join(dir, "config")) t.Setenv("XDG_CACHE_HOME", filepath.Join(dir, "cache")) t.Setenv("MAGPIE_BUN", bun) diff --git a/internal/proc/path_other_test.go b/internal/proc/path_other_test.go index 827632cd1..23649e2bc 100644 --- a/internal/proc/path_other_test.go +++ b/internal/proc/path_other_test.go @@ -16,6 +16,7 @@ import ( func TestUserPath(t *testing.T) { home := t.TempDir() t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) npm := filepath.Join(home, ".npm-global", "bin") os.MkdirAll(npm, 0o755) os.WriteFile(filepath.Join(npm, "claude"), []byte("#!/bin/sh\n"), 0o755) diff --git a/internal/profile/profile_test.go b/internal/profile/profile_test.go index 8da04cbef..e18f31be9 100644 --- a/internal/profile/profile_test.go +++ b/internal/profile/profile_test.go @@ -19,7 +19,7 @@ func sandbox(t *testing.T) string { t.Setenv("USERPROFILE", h) t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config")) t.Setenv("PATH", "") - for _, k := range []string{"CLAUDE_CONFIG_DIR", "CODEX_HOME", "PI_CODING_AGENT_DIR", "OMO_CODING_AGENT_DIR", "SENPI_CODING_AGENT_DIR", "COPILOT_HOME", "APPDATA"} { + for _, k := range []string{"CLAUDE_CONFIG_DIR", "CODEX_HOME", "PI_CODING_AGENT_DIR", "OMO_CODING_AGENT_DIR", "SENPI_CODING_AGENT_DIR", "COPILOT_HOME", "APPDATA", "LOCALAPPDATA"} { t.Setenv(k, "") } for _, f := range []string{".claude/settings.json", ".codex/config.toml"} { diff --git a/internal/provider/kiro_main_test.go b/internal/provider/kiro_main_test.go index 10ee55558..a17a654d9 100644 --- a/internal/provider/kiro_main_test.go +++ b/internal/provider/kiro_main_test.go @@ -7,9 +7,24 @@ import ( ) // TestMain keeps the package's tests off the Kiro sign-ins of whoever runs -// them: Accounts() reads them, and asks Kiro who the account is. +// them: Accounts() reads them, and asks Kiro who the account is. It also +// gives the package a home of its own, so what a test leaves behind it — +// a CLI's answer kept by refresh after the test is over — never lands in +// the runner's magpie, nor in APPDATA on Windows. func TestMain(m *testing.M) { dir, _ := os.MkdirTemp("", "magpie-kiro") + home := filepath.Join(dir, "home") + os.MkdirAll(home, 0o755) + for k, v := range map[string]string{ + "HOME": home, "USERPROFILE": home, + "XDG_CONFIG_HOME": filepath.Join(home, ".config"), + "XDG_CACHE_HOME": filepath.Join(home, ".cache"), + "XDG_DATA_HOME": filepath.Join(home, ".local", "share"), + "APPDATA": filepath.Join(home, "AppData", "Roaming"), + "LOCALAPPDATA": filepath.Join(home, "AppData", "Local"), + } { + os.Setenv(k, v) + } kiroCLIDB = func() string { return filepath.Join(dir, "kiro-cli", "data.sqlite3") } kiroIDEDir = func() string { return filepath.Join(dir, "sso") } askKiroIdentity = func(string, string) (string, string) { return "", "" } diff --git a/internal/provider/store_unreadable_test.go b/internal/provider/store_unreadable_test.go index fc3f8cf8b..77830c687 100644 --- a/internal/provider/store_unreadable_test.go +++ b/internal/provider/store_unreadable_test.go @@ -103,6 +103,9 @@ func TestStoreReplacesAtomically(t *testing.T) { if err != nil { t.Fatal(err) } + // Windows reads a file's identity by its path when first compared: read + // it now, while the path is still the old file + os.SameFile(before, before) if err := Save(Provider{ID: "new", Name: "New", Chat: "https://new.example.invalid/v1", Key: "synthetic-new"}); err != nil { t.Fatal(err) } diff --git a/internal/sessions/calls_test.go b/internal/sessions/calls_test.go index 892fb778b..22747e4e2 100644 --- a/internal/sessions/calls_test.go +++ b/internal/sessions/calls_test.go @@ -427,6 +427,7 @@ func TestCallsResumed(t *testing.T) { func TestDesktopDataDirs(t *testing.T) { t.Setenv("HOME", "/home/u") + t.Setenv("USERPROFILE", "/home/u") t.Setenv("XDG_CONFIG_HOME", "") t.Setenv("LOCALAPPDATA", filepath.Join(t.TempDir(), "Local")) ds := desktopDataDirs() diff --git a/internal/sessions/discovery.go b/internal/sessions/discovery.go index 6c72ba9db..79af72379 100644 --- a/internal/sessions/discovery.go +++ b/internal/sessions/discovery.go @@ -19,9 +19,17 @@ var directoryCache = struct { type directoryEntry struct { mod time.Time size int64 + at time.Time // when it was listed entries []os.DirEntry } +// racyDirectory is how close to a directory's mtime a listing can't be +// trusted: mtimes are coarse (a Linux kernel tick, a second on some +// filesystems) and a directory's size often doesn't change, so an entry +// added in the same tick as a listing left the mtime as it was and stayed +// hidden. Such a listing is read again until it's older than this. +const racyDirectory = 2 * time.Second + func readDirectory(path string) []os.DirEntry { st, err := os.Stat(path) if err != nil || !st.IsDir() { @@ -30,9 +38,10 @@ func readDirectory(path string) []os.DirEntry { directoryCache.Lock() old, ok := directoryCache.entries[path] directoryCache.Unlock() - if ok && old.mod.Equal(st.ModTime()) && old.size == st.Size() { + if ok && old.mod.Equal(st.ModTime()) && old.size == st.Size() && old.at.Sub(old.mod) > racyDirectory { return old.entries } + at := time.Now() entries, err := os.ReadDir(path) if err != nil { return nil @@ -41,7 +50,7 @@ func readDirectory(path string) []os.DirEntry { if len(directoryCache.entries) >= 16384 { directoryCache.entries = map[string]directoryEntry{} } - directoryCache.entries[path] = directoryEntry{st.ModTime(), st.Size(), entries} + directoryCache.entries[path] = directoryEntry{st.ModTime(), st.Size(), at, entries} directoryCache.Unlock() return entries } diff --git a/internal/sessions/discovery_test.go b/internal/sessions/discovery_test.go new file mode 100644 index 000000000..8c7109b06 --- /dev/null +++ b/internal/sessions/discovery_test.go @@ -0,0 +1,38 @@ +package sessions + +import ( + "os" + "path/filepath" + "testing" + "time" +) + +// A listing made in the same mtime tick as the directory's last change is +// read again: on Linux an entry added within that tick left the mtime (and +// the directory's size) as they were, and the new Cowork session stayed +// hidden until the folder changed again. +func TestRacyDirectoryListedAgain(t *testing.T) { + dir := t.TempDir() + os.WriteFile(filepath.Join(dir, "a"), nil, 0o644) + st, _ := os.Stat(dir) + seed := func(at time.Time) { + directoryCache.Lock() + directoryCache.entries[dir] = directoryEntry{st.ModTime(), st.Size(), at, nil} + directoryCache.Unlock() + } + t.Cleanup(func() { + directoryCache.Lock() + delete(directoryCache.entries, dir) + directoryCache.Unlock() + }) + // listed in the tick of its change: not trusted + seed(st.ModTime()) + if n := len(readDirectory(dir)); n != 1 { + t.Fatalf("a racy listing was served: %d entries", n) + } + // listed well after it: served as cached + seed(st.ModTime().Add(time.Minute)) + if n := len(readDirectory(dir)); n != 0 { + t.Fatalf("a settled listing was read again: %d entries", n) + } +} diff --git a/internal/sessions/price_test.go b/internal/sessions/price_test.go index 4ce2ab9c0..7c050f543 100644 --- a/internal/sessions/price_test.go +++ b/internal/sessions/price_test.go @@ -16,6 +16,7 @@ import ( func TestPriceOfGrokEffort(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")) os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755) @@ -41,6 +42,7 @@ func TestPriceOfGrokEffort(t *testing.T) { func TestPriceOfStatedProviderPrice(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")) os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755) @@ -83,6 +85,7 @@ func TestPriceOfStatedProviderPrice(t *testing.T) { func TestPriceOfAfterProviderRename(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")) os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755) @@ -123,6 +126,7 @@ func TestPriceOfAfterProviderRename(t *testing.T) { func TestListingPricesEveryModelAtTheSettingsItReadOnce(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")) catalog.Reset() diff --git a/internal/settings/settings_test.go b/internal/settings/settings_test.go index 60baf7b90..954cd6ab6 100644 --- a/internal/settings/settings_test.go +++ b/internal/settings/settings_test.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" "reflect" + "runtime" "slices" "strings" "testing" @@ -139,7 +140,7 @@ func TestMigrate(t *testing.T) { } Migrate() fi, err := os.Stat(filepath.Join(cfg, "magpie", "providers.json")) - if err != nil || fi.Mode().Perm() != 0o600 { + if err != nil || runtime.GOOS != "windows" && fi.Mode().Perm() != 0o600 { // Windows has no such bits t.Fatalf("providers.json not copied with its mode: %v %v", fi, err) } if _, err := os.Stat(filepath.Join(cfg, "magpie", "sub", "x")); err != nil { diff --git a/internal/update/admin_test.go b/internal/update/admin_test.go index 7e76cf117..14938d3aa 100644 --- a/internal/update/admin_test.go +++ b/internal/update/admin_test.go @@ -33,6 +33,9 @@ func version(t *testing.T, path string) string { // A folder magpie may not write to: Install fails with a permission error, // leaves the app as it was, and keeps what it staged. func TestInstallNeedsAdmin(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("a read-only folder and the administrator's password are a Mac's and Linux's") + } if os.Getuid() == 0 { t.Skip("root writes anywhere") } @@ -60,6 +63,9 @@ func TestInstallNeedsAdmin(t *testing.T) { // The script InstallAsAdmin runs as root swaps the apps, awkward names and // all; run here as the user in a folder they own. func TestSwapScript(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("the swap runs as root under /bin/sh, on a Mac or Linux") + } dir := filepath.Join(t.TempDir(), `it's "a" \ $(dir) `) bundle, staged, old := filepath.Join(dir, "magpie.app"), filepath.Join(dir, "s", "magpie.app"), filepath.Join(dir, "s", "old.app") app(t, bundle, "old") diff --git a/internal/update/proxy_test.go b/internal/update/proxy_test.go index 0e29d219e..469be69fe 100644 --- a/internal/update/proxy_test.go +++ b/internal/update/proxy_test.go @@ -21,6 +21,7 @@ import ( func TestUpdateGoesThroughTheProxy(t *testing.T) { h := t.TempDir() t.Setenv("HOME", h) + t.Setenv("USERPROFILE", h) t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config")) for _, k := range []string{"HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy", "ALL_PROXY", "all_proxy", "NO_PROXY", "no_proxy"} { t.Setenv(k, "") diff --git a/internal/usage/ledger_test.go b/internal/usage/ledger_test.go index aa9587931..2ca3bd240 100644 --- a/internal/usage/ledger_test.go +++ b/internal/usage/ledger_test.go @@ -23,6 +23,7 @@ import ( func TestLedger(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")) // a maker's API list price for sol: $2 in, $8 out, $0.5 a @@ -102,6 +103,7 @@ func TestLedger(t *testing.T) { func TestSubscriptionListPrice(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")) os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755) @@ -173,6 +175,7 @@ func TestSubscriptionListPrice(t *testing.T) { func TestLedgerWithSessionLogCalls(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")) // a models.dev catalog pricing Claude Sonnet 5: $3 in, $15 out, $0.3 a cached read, $3.75 a cache write, per million @@ -439,6 +442,7 @@ func TestLedgerLogModels(t *testing.T) { func TestLedgerUsesTheStatedPrice(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")) os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755) @@ -474,6 +478,7 @@ func TestLedgerUsesTheStatedPrice(t *testing.T) { func TestLedgerConfiguredPricesAndRefresh(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")) catalog.Reset() @@ -547,6 +552,7 @@ func TestLedgerConfiguredPricesAndRefresh(t *testing.T) { func TestLedgerJudgesAnAntigravityCallByTheVariantItWentOutUnder(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")) // Antigravity's ids of one model at three levels, as its fetch left them diff --git a/internal/usage/main_test.go b/internal/usage/main_test.go new file mode 100644 index 000000000..111362615 --- /dev/null +++ b/internal/usage/main_test.go @@ -0,0 +1,27 @@ +package usage + +import ( + "os" + "path/filepath" + "testing" +) + +// TestMain gives the package a home of its own: a test that doesn't set one +// reads and writes there, never in the runner's agents or, on Windows, its +// APPDATA and LOCALAPPDATA. +func TestMain(m *testing.M) { + home, _ := os.MkdirTemp("", "magpie-usage-test-") + for k, v := range map[string]string{ + "HOME": home, "USERPROFILE": home, + "XDG_CONFIG_HOME": filepath.Join(home, ".config"), + "XDG_CACHE_HOME": filepath.Join(home, ".cache"), + "XDG_DATA_HOME": filepath.Join(home, ".local", "share"), + "APPDATA": filepath.Join(home, "AppData", "Roaming"), + "LOCALAPPDATA": filepath.Join(home, "AppData", "Local"), + } { + os.Setenv(k, v) + } + code := m.Run() + os.RemoveAll(home) + os.Exit(code) +} diff --git a/internal/usage/session_provider_test.go b/internal/usage/session_provider_test.go index b0f7f5db6..1bbe74f9c 100644 --- a/internal/usage/session_provider_test.go +++ b/internal/usage/session_provider_test.go @@ -56,6 +56,8 @@ func TestDesktopSessionAccountMetadata(t *testing.T) { t.Setenv("USERPROFILE", home) t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) t.Setenv("CLAUDE_CONFIG_DIR", filepath.Join(home, ".claude")) + t.Setenv("APPDATA", filepath.Join(home, "AppData", "Roaming")) + t.Setenv("LOCALAPPDATA", filepath.Join(home, "AppData", "Local")) t.Setenv("CODEX_HOME", filepath.Join(home, ".codex")) root := sessions.DesktopDataDirs()[0] root3p := sessions.DesktopDataDirs()[1] @@ -101,6 +103,8 @@ func TestLedgerResolvesOAuthIdentityAndExportsIt(t *testing.T) { t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) t.Setenv("CODEX_HOME", filepath.Join(home, ".codex")) t.Setenv("CLAUDE_CONFIG_DIR", filepath.Join(home, ".claude")) + t.Setenv("APPDATA", filepath.Join(home, "AppData", "Roaming")) + t.Setenv("LOCALAPPDATA", filepath.Join(home, "AppData", "Local")) if err := os.MkdirAll(sessions.CodexDir(), 0700); err != nil { t.Fatal(err) } @@ -136,6 +140,8 @@ func TestModelsNeverEstablishProviderOrAccount(t *testing.T) { t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) t.Setenv("CODEX_HOME", filepath.Join(home, ".codex")) t.Setenv("CLAUDE_CONFIG_DIR", filepath.Join(home, ".claude")) + t.Setenv("APPDATA", filepath.Join(home, "AppData", "Roaming")) + t.Setenv("LOCALAPPDATA", filepath.Join(home, "AppData", "Local")) at := time.Now() logs := []sessions.Call{ {Time: at, Agent: "claude", Model: "claude-opus-5", Requested: "claude-opus-5[1m]"}, @@ -222,6 +228,8 @@ func TestLedgerKeepsLocalAccountsSeparateFromGatewayProviders(t *testing.T) { t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) t.Setenv("CODEX_HOME", filepath.Join(home, ".codex")) t.Setenv("CLAUDE_CONFIG_DIR", filepath.Join(home, ".claude")) + t.Setenv("APPDATA", filepath.Join(home, "AppData", "Roaming")) + t.Setenv("LOCALAPPDATA", filepath.Join(home, "AppData", "Local")) if err := os.MkdirAll(sessions.CodexDir(), 0700); err != nil { t.Fatal(err) } diff --git a/internal/usage/usage_test.go b/internal/usage/usage_test.go index 6440b5ab2..13f39d4cf 100644 --- a/internal/usage/usage_test.go +++ b/internal/usage/usage_test.go @@ -51,6 +51,7 @@ func TestSummarize(t *testing.T) { func TestSummarizeTellsPlacesApart(t *testing.T) { home := t.TempDir() t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Key: "k", Chat: "https://new.example/v1"}); err != nil { t.Fatal(err) @@ -92,6 +93,7 @@ func TestSummarizeTellsPlacesApart(t *testing.T) { func TestSummarizeKeepsMovedAccountTogether(t *testing.T) { home := t.TempDir() t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) y, m, d := time.Now().Date() now := time.Date(y, m, d, 12, 0, 0, 0, time.Local) diff --git a/model_cli_test.go b/model_cli_test.go index 7fef675bd..119fc0293 100644 --- a/model_cli_test.go +++ b/model_cli_test.go @@ -166,18 +166,9 @@ func TestModelPriceCmd(t *testing.T) { // reads a number of tokens off the command rather than out of the file. func said(t *testing.T, f func() error) (string, error) { t.Helper() - r, w, err := os.Pipe() - if err != nil { - t.Fatal(err) - } - old := os.Stdout - os.Stdout = w - runErr := f() - w.Close() - os.Stdout = old - b, _ := io.ReadAll(r) - r.Close() - return string(b), runErr + // read while f writes: a pipe holds only a few KB on Windows, and a + // help longer than that would wait on a reader forever + return printed(t, f) } // magpie model prices is the one place the user sees what they have said diff --git a/provider_plugin_cli_test.go b/provider_plugin_cli_test.go index 6ed15d7b1..4df39b7a2 100644 --- a/provider_plugin_cli_test.go +++ b/provider_plugin_cli_test.go @@ -16,6 +16,7 @@ import ( func TestShowMovedProvider(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")) t.Setenv("MAGPIE_BUN", "") diff --git a/search_cli_test.go b/search_cli_test.go index 8eed484c0..6b0879749 100644 --- a/search_cli_test.go +++ b/search_cli_test.go @@ -1,6 +1,7 @@ package main import ( + "os" "testing" "github.com/yetone/magpie/internal/provider" @@ -9,6 +10,7 @@ import ( // magpie search add, with a key and an address in either order, and rm. func TestSearchCLI(t *testing.T) { t.Setenv("HOME", t.TempDir()) + t.Setenv("USERPROFILE", os.Getenv("HOME")) t.Setenv("XDG_CONFIG_HOME", t.TempDir()) if err := searchCmd([]string{"add", "tavily"}); err == nil { t.Error("tavily added without a key") diff --git a/serve_cli_test.go b/serve_cli_test.go index 0f6959a40..80db5592e 100644 --- a/serve_cli_test.go +++ b/serve_cli_test.go @@ -1,6 +1,7 @@ package main import ( + "os" "strings" "testing" @@ -12,6 +13,7 @@ import ( // not shared from Settings is open to anyone who reaches it. func TestKeyNote(t *testing.T) { t.Setenv("HOME", t.TempDir()) + t.Setenv("USERPROFILE", os.Getenv("HOME")) t.Setenv("XDG_CONFIG_HOME", t.TempDir()) for _, c := range []struct{ addr, want string }{ {"", "only listens on localhost"}, @@ -44,6 +46,7 @@ func TestKeyNote(t *testing.T) { // the gateway: MAGPIE_PUBLIC_URL when a container sets it. func TestShareLines(t *testing.T) { t.Setenv("HOME", t.TempDir()) + t.Setenv("USERPROFILE", os.Getenv("HOME")) t.Setenv("XDG_CONFIG_HOME", t.TempDir()) t.Setenv("MAGPIE_ADDR", "0.0.0.0:3425") t.Setenv("MAGPIE_PUBLIC_URL", "http://192.168.1.20:3425/") diff --git a/sessions_cli_test.go b/sessions_cli_test.go index c60a5a936..5ac229578 100644 --- a/sessions_cli_test.go +++ b/sessions_cli_test.go @@ -20,6 +20,7 @@ func sessionsHome(t *testing.T) time.Time { t.Helper() h := t.TempDir() t.Setenv("HOME", h) + t.Setenv("USERPROFILE", h) t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config")) t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache")) // OpenCode's and Pi's folders in the sandbox too (HOME isn't the home diff --git a/webdav_cli_test.go b/webdav_cli_test.go index 596782e0a..37660b5a2 100644 --- a/webdav_cli_test.go +++ b/webdav_cli_test.go @@ -22,6 +22,7 @@ func webdavHome(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("CLAUDE_CONFIG_DIR", filepath.Join(home, ".claude"))