Skip to content

test(ui): keep tests off the developer's real config and state files - #1365

Open
yongjincho wants to merge 1 commit into
modem-dev:mainfrom
yongjincho:test/isolate-user-state
Open

yongjincho wants to merge 1 commit into
modem-dev:mainfrom
yongjincho:test/isolate-user-state

Conversation

@yongjincho

Copy link
Copy Markdown

Why

bun run test should not touch the developer's own Hunk files. Today one run rewrites ~/.config/hunk/config.toml with theme = "github-dark-dimmed" and the other view-preference defaults. It also adds extensionTrust entries for deleted temp repos to ~/.local/state/hunk/state.json.

What changed

  • HunkSessionHost.test.tsx, "blocks reopening until dirty-quit cancellation settles", meant to cancel the save-view-preferences prompt with pressKey("escape"). OpenTUI's KeyCodes only has ESCAPE, so the mock typed e, s, c, a, p, e. s is the prompt's save key, so the test saved to the global config instead of cancelling. The test now calls pressEscape() and waits past the stdin parser's 20 ms lone-ESC timeout. Without that wait, ESC and the next Enter parse as meta+return, which also saves. It then asserts that the prompt closed before it presses Enter. This was the only pressKey("escape") in the repo.
  • AppHost.extensions.test.tsx and AppHost.status-line.test.tsx isolated only XDG_CONFIG_HOME. fix: store persistent state under XDG state directory #920 moved trust decisions to $XDG_STATE_HOME/hunk/state.json. Both files now also point XDG_STATE_HOME at a temp directory and restore it after each test. I removed one comment that credited the config override with that isolation.
  • The change is test-only, so the changeset is empty.

Scope

app/documents/documentSaveClaim.test.ts still creates an empty ~/.config/hunk/document-save-claims/<host>/. It resolves the account home from OS records on purpose, so redirecting it needs its own discussion.

Verification

I ran each file with HOME and XDG_CONFIG_HOME set to a fresh temp directory and listed the config.toml and state.json files left there.

File Before (015d39b) After
ui/session/HunkSessionHost.test.tsx xdg/hunk/config.toml none, 16 pass (5 runs)
ui/AppHost.extensions.test.tsx .local/state/hunk/state.json none, 24 pass
ui/AppHost.status-line.test.tsx .local/state/hunk/state.json none, 11 pass
  • With pressEscape() and no wait, the dirty-quit test failed 5 of 5 runs and wrote config.toml. With a 20 ms or 60 ms wait, it passed 5 of 5.
  • I ran the full bun run test with the same isolation. It left neither file and finished with 5969 pass and 10 fail. The same 10 tests fail on main on this machine (macOS, Bun 1.4.5). They hit /var vs /private/var path mismatches in AppHost.reload, filesystemSource.observe, brokerLauncher, installedPackageResolution, and hostRuntimeModules.
  • bun run typecheck, bun run lint, and bun run format:check pass. I tested on macOS only.

🤖 Generated with Claude Code

Running `bun run test` rewrote the developer's global config.toml and
added extension trust entries for deleted temp repos to their state.json.

- HunkSessionHost "blocks reopening until dirty-quit cancellation
  settles" called pressKey("escape"). OpenTUI's KeyCodes only has
  ESCAPE, so the mock typed e, s, c, a, p, e. `s` is the prompt's save
  key, so the test saved view preferences to the real config.toml
  instead of cancelling. Send a real Escape, let the lone ESC byte
  flush, and assert the prompt closed before pressing Enter.
- AppHost.extensions and AppHost.status-line isolated XDG_CONFIG_HOME
  only. Trust decisions moved to $XDG_STATE_HOME/hunk/state.json in
  modem-dev#920, so they landed in ~/.local/state/hunk/state.json. Isolate
  XDG_STATE_HOME as well and drop a comment that credited the config
  override with that isolation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

This PR does not match any of the 1 configured review trigger rule.

@benvinegar

Copy link
Copy Markdown
Member

Oof good find

This branch has not been deployed

No deployments
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.

2 participants