Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

1.4 KB
Raw Blame
//go:build !windows

package appdir

import (
	"os"
	"path/filepath"
	"testing"
)

// A ~/.config the user can't write (sudo made it root's) is named as what
// blocks magpie; a writable one, or one not there yet under a writable
// home, isn't; and a folder outside the home folder is never named.
func TestBlockedNamesTheFolderInTheWay(t *testing.T) {
	if os.Getuid() == 0 {
		t.Skip("root writes any folder")
	}
	UseExecutable("")
	home := t.TempDir()
	t.Setenv("HOME", home)
	t.Setenv("XDG_CONFIG_HOME", "")
	t.Setenv("XDG_CACHE_HOME", "")
	if b := Blocked(); b != "" {
		t.Fatalf("Blocked = %q with nothing made yet, want empty", b)
	}
	cfg := filepath.Join(home, ".config")
	os.Mkdir(cfg, 0o555)
	t.Cleanup(func() { os.Chmod(cfg, 0o755) })
	if b := Blocked(); b != cfg {
		t.Fatalf("Blocked = %q, want %s", b, cfg)
	}
	if !Mine(cfg) {
		t.Fatal("Mine = false for the user's own folder")
	}
	if Own(cfg) || !Own(filepath.Join(cfg, "magpie")) || !Own(filepath.Join(cfg, "magpie", "x")) {
		t.Fatal("Own: only magpie's own folder and what is in it")
	}
	os.Chmod(cfg, 0o755)
	if b := Blocked(); b != "" {
		t.Fatalf("Blocked = %q once writable, want empty", b)
	}
	outside := t.TempDir()
	os.Chmod(outside, 0o555)
	t.Cleanup(func() { os.Chmod(outside, 0o755) })
	t.Setenv("XDG_CONFIG_HOME", filepath.Join(outside, "cfg"))
	if b := Blocked(); b != "" {
		t.Fatalf("Blocked = %q outside the home folder, want empty: not the user's to take back", b)
	}
}