Skip to content

Make the test suite hermetic and green under -shuffle#45

Open
LukasIngemarsson wants to merge 1 commit into
Cidan:mainfrom
LukasIngemarsson:fix/test-home-symlink-hermeticity
Open

Make the test suite hermetic and green under -shuffle#45
LukasIngemarsson wants to merge 1 commit into
Cidan:mainfrom
LukasIngemarsson:fix/test-home-symlink-hermeticity

Conversation

@LukasIngemarsson

Copy link
Copy Markdown
Contributor

Problem

The test suite was non-hermetic and order-dependent on macOS — go test ./... failures shifted with test order, and a contributor's local config/cwd state could flip any run red. Three independent causes:

  1. HOME/config reads — keybinding tests (Ctrl+P/O/Z) read the developer's real ~/.config/ask/ask.json via currentKeyMap, so custom or unbound shortcuts failed them.
  2. macOS temp-dir symlinkst.TempDir() lives under /var (a symlink to /private/var), but production resolves cwd via filepath.EvalSymlinks (memoryProjectRoot). The mismatch keyed seeded vs. read project config under different roots, failing the workflow_* MCP tests (and an index out of range panic that was masking later failures).
  3. cwd leakage — production os.Chdir (closeTab, the cd handler, shell mode) left the process in a temp dir, breaking later relative-path tests (e.g. the usage-plugin file reads).

Fix (test-only, all in testhelpers_test.go)

  • A package TestMain points $HOME/$XDG_CONFIG_HOME/$XDG_CACHE_HOME at a throwaway dir, so config reads fall back to compiled defaults; it also invalidates the keymap cache and restores cwd at the suite boundary.
  • isolateHome resolves the temp dir through filepath.EvalSymlinks so seeded and read project-config keys agree.
  • newTestModel captures cwd and restores it via t.Cleanup.

Verification

go test ./... is green in default order and under -shuffle (seeds 1/42/9999 + random), 1729 passed.

🤖 Generated with Claude Code

Three pre-existing non-hermeticity classes made the macOS suite a moving
target: failures shifted with test order, and config/cwd state could flip
any run red.

- HOME/config: keybinding tests (Ctrl+P/O/Z) read the developer's real
  ~/.config/ask/ask.json via currentKeyMap, so a contributor's custom or
  unbound shortcuts failed them. A package TestMain now points $HOME/$XDG
  at a throwaway dir, so config reads fall back to compiled defaults.
- macOS temp symlinks: t.TempDir() lives under /var (symlink to
  /private/var), but production resolves cwd via EvalSymlinks
  (memoryProjectRoot). isolateHome now resolves up front so seeded and
  read project-config keys match -- fixes the workflow_* MCP tests and
  the index-out-of-range panic that was masking later failures.
- cwd leakage: production os.Chdir (closeTab / cd handler / shell mode)
  left the process in a temp dir, breaking later relative-path tests
  (usage-plugin reads). newTestModel now restores cwd via t.Cleanup, and
  TestMain restores it at the suite boundary.

Verified green in default order and under -shuffle (seeds 1/42/9999 +
random), 1729 passed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant