Skip to content

Test suite is not hermetic: config, cache and home dirs leak into tests #1103

Closed

Description

@PierrunoYT

Found in the 2026-09-28 code audit (finding N-8).

Where: internal/config/paths.go:49-62 (UserConfigDir has no override seam); internal/tui/model.go:891-892 (newModel reads the real config.UserConfigDir()/zero/commands/*.md); internal/cli/app.go:754, internal/cli/observability.go:43 (call config.DefaultResolveOptions directly, bypassing the deps.userConfigPath seam at app.go:141).

Problem: 551 newModel( calls in TUI tests, only one TUI test file sets APPDATA/XDG_CONFIG_HOME/HOME. Repo-wide only 5 test files set APPDATA/LOCALAPPDATA, while 22 non-test files call os.User{Config,Home,Cache}Dir directly (e.g. skills/skills.go x3, sandbox/profile.go x3, sessions/store.go, cron/store.go, hooks/hooks.go). This violates the "Hermetic tests" rule in AGENTS.md: developer config leaks into tests and tests can write to real state directories.

Suggested fix: add a ZERO_CONFIG_DIR (or package-level) override in config, route the 22 callers through it, and add a per-package TestMain pointing HOME, USERPROFILE, APPDATA, LOCALAPPDATA, XDG_CONFIG_HOME, XDG_CACHE_HOME at a temp dir.

Activity

  1. added
    issue-approved
    on Oct 12, 2026
  2. Vasanthdev2004 commented on Oct 12, 2026

    @Vasanthdev2004
    Collaborator

    Confirmed, and it's worse than reading: on main, go test ./internal/tui/ writes into the user's real directories. With HOME, USERPROFILE, APPDATA, LOCALAPPDATA, XDG_CONFIG_HOME and XDG_CACHE_HOME pointed at an empty temp dir, one run left two sessions under .local/share/zero/sessions/ and a windows-cap-sids.json under .config/zero/ there. On a developer's machine those land in the real session list.

    Approving, but in slices rather than one change across 22 callers. First slice: a TestMain in internal/tui that points every root the package resolves (HOME, USERPROFILE, APPDATA, LOCALAPPDATA, XDG_CONFIG_HOME, XDG_DATA_HOME, XDG_CACHE_HOME) at a temp dir, the way isolateCLIUserState does for internal/cli, plus a test that a model built with default options keeps its session store inside that dir. The config override seam and the other packages can follow as their own PRs, each with the same before-and-after check.

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

    issue-approved

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions