Documentation
¶
Overview ¶
Package testhome keeps tests out of the real home folder.
komando reads and writes under the home folder in many places: its own data in ~/.komando, and ~/.ssh, ~/.aws, ~/.kube and the like. A test that moves only komando's folder (KOMANDO_HOME) still has the real home behind os.UserHomeDir, and one such test once wrote over a person's private key. So every package whose code names a home folder starts its tests with Use, which gives the whole test binary a throwaway home.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var SettingsVars = []string{"CLAUDE_CONFIG_DIR", "CODEX_HOME", "GEMINI_CLI_HOME", "CURSOR_CONFIG_DIR"}
SettingsVars move an AI agent's settings folder out of the home: with one set, `agent skill install` in a test would write the hook into the real folder it names. Use takes them out.
Functions ¶
func InTemp ¶ added in v0.18.2
InTemp says whether p lies in the throwaway home or in the system's temp folder, where its links lead: the only places a test may write.
func Path ¶
Path returns p when it lies in the throwaway home or in the system's temp folder (t.TempDir), and fails the test otherwise. A test that writes to a path built from the home folder passes the path through it, so a test started without Use cannot reach the real home.
func Real ¶
func Real() string
Real is the home folder the tests were started with. Nothing may be written there; tests use it only to say "not this one".
func Use ¶
func Use() (done func())
Use points HOME, USERPROFILE, APPDATA, LOCALAPPDATA and the XDG folders at one new, empty folder for the rest of the test binary, and returns the function that removes it. Call it first in TestMain:
func TestMain(m *testing.M) {
done := testhome.Use()
code := m.Run()
done()
os.Exit(code)
}
A test binary that a test started itself keeps its parent's folder and removes nothing. The Go tool keeps the caches and the toolchain it had (they live under the real home), so a test may still run `go`.
The tests also run as a script, whoever starts them: for an AI agent komando takes the home folder from the system's user database, which no variable moves (store.UserHome), so the variables an agent's shell sets are taken out. A test about agents sets one itself, and then answers for store.AccountHome too.