Repository navigation
Conversation
Packages that touch Docker Agent state wrote into the real home directory of
whoever ran `go test ./...`:
- pkg/skills: cached remote skills
- pkg/runtime: models.dev catalog
- pkg/tools/builtin/rag: RAG embeddings database
- pkg/telemetry and pkg/model/provider/{base,anthropic,openai,dmr}: user-uuid
- pkg/fake and pkg/evaluator/provider: user-uuid
- pkg/remote: data-dir store directory
Run those suites under testutil.RunWithTempHome from TestMain, like the
state-touching packages already do. Add testutil.RequireTempHome and a guard
test to every affected package so removing the isolated TestMain fails in CI
instead of silently writing to the developer's home directory again.
Fixes docker#5013
Signed-off-by: PerryLink <novelnexusai@outlook.com>
aheritier
requested changes
Nov 24, 2026
aheritier
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for tracking down the extra packages that write to the developer’s home. The suite-level wrappers cover the reported paths that resolve through HOME or USERPROFILE, but the cache writes in #5013 still escape on Windows and on Linux with XDG_CACHE_HOME set.
Collaborator
|
Moving to draft, please mark as ready when feedback are reviewed and potentially addressed if they make sense to you. |
aheritier
marked this pull request as draft
November 24, 2026 11:46
RunWithTempHome changed HOME and USERPROFILE only, but paths.GetCacheDir() resolves through os.UserCacheDir(), which on Windows reads %LocalAppData% and on Linux prefers an absolute $XDG_CACHE_HOME over $HOME/.cache. On those platforms a suite kept writing the developer's cache while its home directory already looked isolated: pkg/skills cached remote skills under <cache>/cagent/skills and pkg/runtime could write <cache>/cagent/ models_dev.json, yet TestTempHomeIsolation still passed. Point the effective cache root inside the temporary tree for the duration of the run: - Windows: LocalAppData -> <temp home>/AppData/Local - Linux/BSD: XDG_CACHE_HOME -> <temp home>/.cache, absolute because os.UserCacheDir rejects a relative value (pkg/paths.GetCacheDir would then fall back to the shared system temporary directory) - macOS/iOS: no extra variable; os.UserCacheDir derives the cache directory from $HOME, which is already redirected RequireTempHome now also fails when the effective cache directory escapes the temporary home, so the existing TestTempHomeIsolation guards catch a suite that still writes the developer's cache instead of only one that drops the isolated TestMain. Add regression tests: the helper test presets the cache roots outside the temporary tree and asserts the suite resolves its cache inside it and writes nothing into the preset root; a resolver-input test pins the per-platform variables; pkg/skills re-executes the test binary with preset cache roots and verifies TestLoadWithRemoteSources leaves them empty. TestLazyModelStore_GatesCustomProvider keeps its cold-cache intent by overriding the cache variables for its own temporary home. Signed-off-by: PerryLink <novelnexusai@outlook.com> Verification (see EVIDENCE.md): go build ./...; go vet ./...; go test ./... 266 packages ok; go test -race ./pkg/testutil ./pkg/skills; golangci-lint 2.14.0 full repo 0 issues; go run ./lint . 3010 files no offenses; GOOS=windows/darwin compile; PATCH.diff applies cleanly to 37c86aa.
PerryLink
marked this pull request as ready for review
November 24, 2026 14:33
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Some test packages still write Docker Agent state into the real home directory
of whoever runs
go test ./.... This adds aTestMainusingtestutil.RunWithTempHometo every package that was missing one, and a smallguard test so the isolation cannot silently regress.
Fixes #5013. Follow-up to the review on #4999 (the
~/.cagentpath work); nopath-resolution code is touched here.
Reproduction
Run each package with
HOMEpointed at an empty directory and list whatsurvives the test run (before this change):
pkg/skills<cache-dir>/skills/<hash>/remote-skill/SKILL.md+.metapkg/runtime<cache-dir>/models_dev.json(~7 MB)pkg/tools/builtin/rag<data-dir>/rag/<hash>/rag_knowledge_chunked_embeddings.dbpkg/telemetry<config-dir>/user-uuidpkg/model/provider/{base,anthropic,openai}<config-dir>/user-uuidThe issue noted the
user-uuidrow might be incomplete. It was: running thewhole suite this way also found
pkg/fakeandpkg/evaluator/provider— gateway clients whose transportresolves the install UUID;
pkg/model/provider/dmr— same, via the shared provider base;pkg/remote— creates an empty<data-dir>/storedirectory(
content.NewStore()with the default base directory).A full
go test ./...left 8 files and 13 directories behind in a throwawayhome.
Changes
main_test.gowithTestMainrunningos.Exit(testutil.RunWithTempHome(m.Run))topkg/telemetry,pkg/tools/builtin/rag,pkg/model/provider/{base,anthropic,openai,dmr},pkg/fake,pkg/evaluator/providerandpkg/remote.TestMainofpkg/skillsandpkg/runtimewithtestutil.RunWithTempHome.testutil.RequireTempHomeand aTestTempHomeIsolationtest to each ofthose packages. It fails when the package stops running under
RunWithTempHome, so dropping the isolation breaks the normal test runinstead of silently writing to the developer's home again. That replaces the
separate "CI check against a throwaway HOME" suggested in the issue with an
in-suite check that costs no extra test run.
pkg/runtimekeeps its explicitpaths.SetConfigDirbecause the prompt-fileguard tests write
userconfig.Path(); the temporary home is layered on top.No production code changes.
Verification
With
HOMEat an empty directory,go test ./... -count=1:main @ c0062b8aRed/green step: the new guard tests fail on
main(
tests must run with testutil.RunWithTempHome from TestMain) and pass afterthe
TestMainchanges. Each affected package was also run individually with athrowaway
HOMEbefore/after: residue → none.Gates on the branch:
go build ./...,go vet ./...,go run ./lint .(3008 files, no offenses),
golangci-lint run2.14.0 (0 issues),go mod tidy --diffclean,gofmtclean.Note:
pkg/runtime'sTestDoCompactAfterHookFiresneedsjqinPATHfor its hook command; without
jqit fails on unmodifiedmaintoo(
exited with status 127), so it is a local environment gap, not a regression.Notes
RunWithTempHomedoes not clearXDG_*variables onmain; feat(paths): resolve XDG and OS-native state dirs without migration #4999 addsthat, so these suites also stay isolated under XDG roots once it lands.
Nothing in this PR depends on that.