Skip to content

Tests in some packages write to the developer's real home directory #5013

In progress

Description

@yunus25jmi1

Follow-up from #4999 (review by @lmilbaum).

A few test packages write into the real home directory of whoever runs go test ./..., because they have no TestMain using testutil.RunWithTempHome (or equivalent). This predates #4999 and happens on main; that PR only changes where the files land.

What gets written

Found by running each package with HOME pointed at an empty directory and listing what appeared:

Package File left behind
pkg/skills <cache-dir>/skills/<hash>/remote-skill/SKILL.md and SKILL.md.meta
pkg/runtime <cache-dir>/models_dev.json (about 7 MB)
pkg/tools/builtin/rag <data-dir>/rag/<hash>/rag_knowledge_chunked_embeddings.db
pkg/telemetry, pkg/model/provider/base, pkg/model/provider/anthropic, pkg/model/provider/openai <config-dir>/user-uuid

A full go test ./... run leaves exactly these four kinds of file. The user-uuid row may be incomplete: I only checked the packages above individually, and other packages that initialise telemetry could write it too.

Why it matters

  • Tests read and write developer state, so results can depend on what is already in the home directory.
  • user-uuid is the telemetry identity; a test run can create it on a machine where the developer never ran Docker Agent.
  • pkg/runtime leaves a 7 MB catalog in the developer's cache.

Suggested fix

Add a TestMain calling testutil.RunWithTempHome(m.Run) to each package above, as the other state-touching packages already do. Then a CI check that fails when a go test ./... run leaves anything under a throwaway HOME would keep it from regressing.

Activity

  1. added
    area/testing
    area/skills
    area/runtime
    area/rag
    area/telemetry
    on Nov 23, 2026
  2. added theissue type on Nov 23, 2026
  3. added a commit that references this issue on Nov 23, 2026
    37c86aa
  4. lmilbaum commented on Nov 24, 2026

    @lmilbaum

    Thanks for writing this up. I ran it on current main (af7c8a66a, macOS) with HOME pointed at an empty directory, each test package on its own, and all seven packages in your table reproduce exactly as described.

    A few things to add.

    The list is longer. pkg/fake, pkg/evaluator/provider and pkg/model/provider/dmr also write user-uuid, and pkg/remote leaves an empty <data-dir>/store directory. #5018 already found those four. The one I think everybody has missed is e2e: go test ./e2e -run TestDebug_Toolsets_None on its own leaves <config-dir>/.cagent_first_run and the 7 MB models_dev.json. It doesn't show up in a full run. From reading the code I think that's because chatserver_test.go passes --cache-dir/--config-dir/--data-dir first, and those overrides are process-global and never reset, so later tests inherit them. I'd expect -shuffle=on to expose it. pkg/model/provider/gemini probably writes user-uuid too, same gateway path, but those tests skip without the opt-in env var so I couldn't confirm.

    Two details on what gets written. The skills cache and the RAG db are keyed by a hash of a random port or temp dir, so every run adds two new directories of each instead of overwriting. On a real home that just keeps growing. And models_dev.json is there because the six teamloader.Load calls in the pkg/runtime tests don't set ModelsDevStoreOverride, so unit tests do a live GET to models.dev. That network dependency bothers me more than the 7 MB.

    On the fix. Wrapping in RunWithTempHome is right for user-uuid, the RAG db and the store dir. For the cache dir I think it's only complete on macOS and plain Linux: the helper sets HOME (plus USERPROFILE on Windows), but the cache dir comes from os.UserCacheDir(), which uses XDG_CACHE_HOME on Linux and %LocalAppData% on Windows. So the skills cache and models_dev.json would still escape there, including in test-windows. I haven't run that, it's from reading pkg/paths and pkg/testutil/home.go. #4999's version of the helper covers it, so the order those two land in matters.

    For pkg/runtime I'd rather inject a store at those six call sites than wrap the package. With an always-empty temp home, wrapping turns "cached for a day" into "download 7 MB on every run".

    Worth knowing: leaving user-uuid alone was a deliberate call in #4893 ("It is not a setting, so they are left alone"). I agree with you that it should be isolated, a test run shouldn't mint a telemetry ID on someone's machine, but a maintainer may want to weigh in. Instead of wrapping N packages, userid's default resolver could skip persisting under testing.Testing(), the way pkg/chatgpt and the keyring token store already do. That would also cover gemini, e2e and whatever comes next.

    The CI check is a good idea but it can't literally be "nothing left under HOME". Go's build cache, module cache and its own telemetry land there, and pkg/tools/builtin/lsp spawns gopls, which writes its cache and telemetry too when it's installed. It would need GOCACHE/GOMODCACHE/GOPATH pinned and should only look at the three cagent directories. It could be a step in the existing test-linux job, so gate.needs doesn't change. It still wouldn't catch the e2e case in default order.

    Small one: I didn't find a test whose pass/fail depends on what's in the home dir, so "results can depend on" reads a bit strong. What does change is behaviour: an existing models_dev.json suppresses the fetch, and an invalid user-uuid gets overwritten. Shout if you've seen an actual flake from it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/ragarea/runtimearea/skillsarea/telemetryarea/testing

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions