tests: keep the suite out of a real DSH_HOME, as the other homes already are (#454)
DSH_HOME beats HOME in DshDir and in dsh's own dir, so a suite that sandboxes HOME still reads and writes the developer's ~/.dsh.
This commit is contained in:
1 parent
eb4c4910c3
commit
a3704c422b
7 files changed
+44
-3
No files matched your search
@@ -17,6 +17,7 @@ func groupsHome(t *testing.T) {
|
||||
t.Setenv("USERPROFILE", os.Getenv("HOME"))
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
||||
t.Setenv("DSH_HOME", "") // a dsh profile is found through it, not through HOME
|
||||
for _, p := range []provider.Provider{
|
||||
{ID: "a", Name: "A", Key: "ka", Models: []string{"m", "only-a", "claude-opus-5-5"}, Chat: "http://127.0.0.1:1/v1"},
|
||||
{ID: "b", Name: "B", Key: "kb", Models: []string{"vendor/m", "gpt-5.5"}, Chat: "http://127.0.0.1:1/v1"},
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestMain gives the package a home of its own. A home an agent is found
|
||||
// through can sit outside HOME — DSH_HOME does — and the package's tests
|
||||
// sandbox HOME alone: left as the developer has it, a test that picks a model
|
||||
// writes it into the real ~/.dsh/profiles, and dsh then refuses every turn
|
||||
// with a model its provider does not list. internal/gateway, internal/provider
|
||||
// and internal/usage isolate themselves the same way.
|
||||
func TestMain(m *testing.M) {
|
||||
home, _ := os.MkdirTemp("", "magpie-agent-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)
|
||||
}
|
||||
for _, k := range []string{
|
||||
"CLAUDE_CONFIG_DIR", "CODEX_HOME", "COPILOT_HOME", "GROK_HOME", "DSH_HOME",
|
||||
"PI_CODING_AGENT_DIR", "PI_CODING_AGENT_SESSION_DIR", "PI_CONFIG_DIR",
|
||||
"OMP_PROFILE", "PI_PROFILE", "OPENCODE_DB", "CLINE_DIR", "CLINE_DATA_DIR",
|
||||
"CLINE_SESSION_DATA_DIR", "WORKBUDDY_CONFIG_DIR",
|
||||
} {
|
||||
os.Unsetenv(k)
|
||||
}
|
||||
code := m.Run()
|
||||
os.RemoveAll(home)
|
||||
os.Exit(code)
|
||||
}
|
||||
@@ -37,7 +37,7 @@ func isolatedTests(m *testing.M) (int, error) {
|
||||
return 1, err
|
||||
}
|
||||
}
|
||||
for _, name := range []string{"CLAUDE_CONFIG_DIR", "CODEX_HOME", "COPILOT_HOME", "GROK_HOME"} {
|
||||
for _, name := range []string{"CLAUDE_CONFIG_DIR", "CODEX_HOME", "COPILOT_HOME", "GROK_HOME", "DSH_HOME"} {
|
||||
if err := os.Unsetenv(name); err != nil {
|
||||
return 1, err
|
||||
}
|
||||
|
||||
@@ -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", "LOCALAPPDATA"} {
|
||||
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", "DSH_HOME"} {
|
||||
t.Setenv(k, "")
|
||||
}
|
||||
for _, f := range []string{".claude/settings.json", ".codex/config.toml"} {
|
||||
|
||||
@@ -22,6 +22,7 @@ func setupCalls(t *testing.T) callDirs {
|
||||
t.Setenv("XDG_DATA_HOME", filepath.Join(dir, "data"))
|
||||
t.Setenv("CLAUDE_CONFIG_DIR", d.claude)
|
||||
t.Setenv("CODEX_HOME", d.codex)
|
||||
t.Setenv("DSH_HOME", "")
|
||||
t.Setenv("HOME", filepath.Join(dir, "home"))
|
||||
t.Setenv("USERPROFILE", filepath.Join(dir, "home"))
|
||||
callDesktopDirs = func() []string { return []string{d.desktop} }
|
||||
|
||||
@@ -24,7 +24,7 @@ func home(t *testing.T) string {
|
||||
t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache"))
|
||||
t.Setenv("PATH", "")
|
||||
t.Setenv("XDG_DATA_HOME", filepath.Join(h, ".local", "share"))
|
||||
for _, k := range []string{"CLAUDE_CONFIG_DIR", "CODEX_HOME", "APPDATA", "VISUAL", "EDITOR", "OPENCODE_DB", "PI_CODING_AGENT_DIR", "OMO_CODING_AGENT_DIR", "SENPI_CODING_AGENT_DIR", "PI_CODING_AGENT_SESSION_DIR"} {
|
||||
for _, k := range []string{"CLAUDE_CONFIG_DIR", "CODEX_HOME", "APPDATA", "VISUAL", "EDITOR", "OPENCODE_DB", "PI_CODING_AGENT_DIR", "OMO_CODING_AGENT_DIR", "SENPI_CODING_AGENT_DIR", "PI_CODING_AGENT_SESSION_DIR", "DSH_HOME"} {
|
||||
t.Setenv(k, "")
|
||||
}
|
||||
for _, f := range []string{".claude/settings.json", ".codex/config.toml"} {
|
||||
|
||||
@@ -29,6 +29,7 @@ func sessionsHome(t *testing.T) time.Time {
|
||||
t.Setenv("PI_CODING_AGENT_DIR", filepath.Join(h, ".pi", "agent"))
|
||||
t.Setenv("OPENCODE_DB", "")
|
||||
t.Setenv("PI_CODING_AGENT_SESSION_DIR", "")
|
||||
t.Setenv("DSH_HOME", "")
|
||||
for from, env := range map[string]string{"claude": "CLAUDE_CONFIG_DIR", "codex": "CODEX_HOME"} {
|
||||
dir := filepath.Join(h, "."+from)
|
||||
if err := os.CopyFS(dir, os.DirFS(filepath.Join("internal", "sessions", "testdata", from))); err != nil {
|
||||
|
||||
Reference in new issue
Block a user