Files
magpie/internal/appdir/claude_homes_test.go
T
yetone 26d1c5619a sessions: every Claude Code folder is read, not only one (@fivesmallq on X)
Accounts run with their own CLAUDE_CONFIG_DIR (~/.claude-work beside
~/.claude) had only one folder's sessions and token use counted. Claude
folders are now found as Codex's are (appdir.ClaudeHomes): the one in use,
siblings named claude*/.claude* (or one level down) that hold projects/, and
the folders of Claude accounts saved in magpie. The sessions list, calls
(Usage), traces, the read-permission check, Dirs and a deleted session's
companion folders (file-history etc., taken from the session's own folder)
all go through it. A session id in two folders is kept once.

No setting to add folders by hand and no GUI change: discovery needs no
configuration; a folder with another name is not found.

Run (mote): go test appdir, sessions, cli, usage ok; gofmt clean; go vet on
darwin, linux and windows for appdir and sessions. New tests
(TestClaudeHomesIn, TestCallsReadEveryClaudeFolder,
TestListReadsEveryClaudeFolderOnce) fail on the old code for the second
folder's sessions. Broke by hand: dropping the key dedupe in claudeFiles
still passes, since the list and calls dedupe by key later; it is kept as a
guard, not tested alone.
Not tried: real second Claude account, Windows/WSL, GUI.
2026-11-11 07:24:28 +08:00

44 lines
1.3 KiB
Go

package appdir
import (
"os"
"path/filepath"
"slices"
"testing"
)
// The folders Claude Code is run in with CLAUDE_CONFIG_DIR set, one account
// each, are found beside ~/.claude: ~/.claude-work, one folder down in
// ~/.claude-profiles, a saved account's own, and not a folder Claude Code
// kept no session in, nor ~/.claude a second time through a link.
func TestClaudeHomesIn(t *testing.T) {
t.Setenv("CLAUDE_CONFIG_DIR", "")
home := t.TempDir()
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, "cfg"))
mk := func(p string) string {
p = filepath.Join(home, p)
if err := os.MkdirAll(p, 0o755); err != nil {
t.Fatal(err)
}
return p
}
main := mk(".claude/projects")
work := mk(".claude-work/projects")
nested := mk(".claude-profiles/b/projects")
mk(".claude-notes/todo")
mk("projects")
saved := mk("cfg/magpie/claude-accounts/abc/projects")
if err := os.Symlink(filepath.Dir(main), filepath.Join(home, ".claude-link")); err != nil {
t.Skip(err)
}
got := ClaudeHomesIn(home)
for _, w := range []string{filepath.Dir(work), filepath.Dir(nested), filepath.Dir(saved)} {
if !slices.Contains(got, w) {
t.Errorf("ClaudeHomesIn = %v, lacks %s", got, w)
}
}
if len(got) != 4 || got[0] != filepath.Dir(main) {
t.Fatalf("ClaudeHomesIn = %v", got)
}
}