carlos / platform Public

Test isolation leaks into ~/.carlos/config when TMPDIR is inside $HOME Issue open

Migrated from github.com/carlosframework/platform issue #326, opened 2026-08-27. GitHub issues are closed for this repo; see AGENTS.md, "Work is tracked on amadan, not GitHub".

Still outstanding: Test isolation leaks into ~/.carlos/config when TMPDIR sits inside $HOME; configDefault's cwd-ancestor walk needs a boundary.

---

Five root-package tests fail on any machine whose TMPDIR lives inside $HOME. Pre-existing on main.

> Third diagnosis; the first two were wrong. I said $HOME, then the checkout's location. Both were wrong, and the wrong mechanism implies the wrong fix, so the working is shown below.

Proven mechanism

useTempCredentials (auth_test.go:21) does everything right:

home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("CARLOS_CONSOLE", "")
t.Chdir(t.TempDir())

And configDefault (config.go:167) resolves in two steps: walk cwd upward for .carlos/config, then fall back to ~/.carlos/config.

The leak is that t.TempDir() creates its directory under $TMPDIR — and on this machine TMPDIR=/home/paulca/.cache/tmp, which is inside $HOME. So the test chdirs to /home/paulca/.cache/tmp/TestX/001, and the cwd walk climbs:

/home/paulca/.cache/tmp/TestX/001
/home/paulca/.cache/tmp/TestX
/home/paulca/.cache/tmp
/home/paulca/.cache
/home/paulca                      ← .carlos/config. Found.

Masking HOME cannot help, because the walk finds the file by path, not through $HOME. That is why my first fix attempt did nothing, and why moving the checkout to /tmp also did nothing — t.Chdir sends cwd back under $TMPDIR regardless of where the checkout lives.

Proof

One variable changed, nothing else:

$ go test . -run 'TestAccountsList|TestResolveMode'                     → FAIL ×5
$ TMPDIR=/tmp/outside-home go test . -run 'TestAccountsList|TestResolveMode'  → ok

Failure text, which names the escape outright:

error "not logged in to https://console.carloku.com
  (the default from /home/paulca/.carlos/config)" does not mention CARLOS_DEPLOYMENT_BUCKET

Why it matters

  • Green on CI, red on a developer machine — and red for a reason that has nothing to do with the change under test. On a repo where .amadan/ci.d/ is now the only gate, that trains people to ignore a red make test.
  • It is the same family as the incident AGENTS.md records, where a logged-in laptop running go test ./... minted 40+ real accounts on the production console. These five fail safely — but only because of what happens to be in one operator's config, not because anything isolated them.
  • The isolation helper silently depends on an environment variable nobody set deliberately.

Fix

Do not let the guard depend on $TMPDIR being outside $HOME. Either chdir to a directory guaranteed outside $HOME, or — better, since it removes the environmental dependency entirely — give the resolver an injectable root so configDefault's walk is bounded in tests. carlosTestEnv should grow the same seam so both halves of the guard match.

🤖 Generated with Claude Code