Skip to content

test: make the unit and integration lanes reliable - #98

Merged
johnnyhuy merged 2 commits into
mainfrom
agent/issue-97-test-gate-reliability
Nov 30, 2026
Merged

johnnyhuy merged 2 commits into
mainfrom
agent/issue-97-test-gate-reliability

Conversation

@johnnyhuy

Copy link
Copy Markdown
Contributor

The unit and integration lanes were failing for reasons that had nothing to do with the code under test. This slice makes both gates reliable: an explicit timeout budget for each project, and a jsdom storage read that survives Node's own localStorage accessor.

Closes #97

This slice has no parent issue. The five roadmap parents are closed, so the improvement was filed on its own as #97, following the fallback in the work loop.

What changed

vitest.unit.config.ts and vitest.integration.config.ts carry a timeout budget. The unit lane gets 120 seconds, the same budget the Electron e2e lane already uses, because its cases build real Git repositories in temporary folders and spawn around a dozen Git processes each. The integration lane gets 60 seconds. The three per-case overrides in tests/unit/workbench.test.ts are gone, so one number governs the lane.

tests/integration/setup.ts now reads storage from the jsdom window instead of from window.localStorage. Node 24 and later define their own localStorage accessor on the global, and Vitest only copies window properties across when the key is missing from the Node global, so on those versions window.localStorage resolved to Node's accessor, which returns undefined. The setup then installed undefined and six integration tests failed with TypeError: Cannot read properties of undefined (reading 'clear'). The jsdom window is still reachable as globalThis.jsdom.window and its storage works on every Node version.

tests/integration/storage.test.ts is new. It asserts the renderer receives a usable Storage, and it fails on Node 26 without the setup fix.

What the failure looked like before

On a loaded machine the unit lane failed between 3 and 9 tests and the integration lane failed around 10, every one of them a timeout with a clean assertion trail, and the failing set changed from run to run.

FAIL  |unit| tests/unit/workbench.test.ts > workspace inspection and preview > compares local upstream refs from nested roots and refreshes ahead, behind and diverged counts without fetching
Error: Test timed out in 5000ms.
If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout".
FAIL  |integration| tests/integration/SettingsView.test.ts > workspace settings > saves the selected model and reasoning defaults and disables duplicate saves
TypeError: Cannot read properties of undefined (reading 'clear')
 ❯ tests/integration/SettingsView.test.ts:15:16
    13|   cleanup();
    14|   vi.unstubAllGlobals();
    15|   localStorage.clear();

How it was verified

Every gate ran on this branch with the repo toolchain from mise (Node 22.23.0, Bun 1.3.14).

Command Result
bun install --frozen-lockfile 515 installs checked, no changes
bun run lint clean, oxlint src tests
bun run typecheck clean, renderer, main and preload projects
bun run test:unit 10 files, 115 tests passed
bun run test:integration 16 files, 135 tests passed
mise run build lint, typecheck, unit, integration and bundle all passed

The unit and integration lanes were also run against Node 26.13.1, the Node that exposed the storage problem, and both lanes passed there too.

Proof

This slice changes test infrastructure only. Nothing in src/ moves, so there is no screen to capture and no screenshot is offered.

Terminal transcript from mise run build, which runs lint, typecheck, both test lanes and the bundle:

[build] $ bun run lint
$ bunx oxlint src tests
[build] $ bun run typecheck
$ bunx tsc -p tsconfig.json --noEmit && bunx tsc -p tsconfig.main.json --noEmit && bunx tsc -p tsconfig.preload.json --noEmit
[build] $ bun run test:unit
$ bunx vitest run --project unit
 RUN  v4.1.10
 Test Files  10 passed (10)
      Tests  115 passed (115)
   Duration  84.73s (transform 9.59s, setup 0ms, import 11.08s, tests 83.73s, environment 1ms)
[build] $ bun run test:integration
$ bunx vitest run --project integration
 RUN  v4.1.10
 Test Files  16 passed (16)
      Tests  135 passed (135)
   Duration  72.88s (transform 38.91s, setup 26.26s, import 102.00s, tests 101.13s, environment 180.07s)
[build] $ mise run bundle
[bundle] $ bunx tsc -p tsconfig.main.json
[bundle] $ bunx tsc -p tsconfig.preload.json
[bundle] $ bunx vite build
vite v8.0.11 building client environment for production...
✓ 745 modules transformed.
✓ built in 12.66s

The same two lanes run directly against Node 26.13.1:

$ bunx vitest run --project unit
 Test Files  10 passed (10)
      Tests  115 passed (115)
   Duration  64.56s (transform 1.90s, setup 0ms, import 4.00s, tests 62.88s, environment 1ms)

$ bunx vitest run --project integration
 Test Files  16 passed (16)
      Tests  135 passed (135)
   Duration  40.86s (transform 10.56s, setup 9.19s, import 41.95s, tests 69.85s, environment 110.10s)

The new guard test, listed by name:

$ bunx vitest run --project integration tests/integration/storage.test.ts --reporter=verbose
 ✓ |integration| tests/integration/storage.test.ts > jsdom test environment > gives the renderer a working storage 4ms

 Test Files  1 passed (1)
      Tests  1 passed (1)

The same test against the old setup file, which shows the guard earns its place:

Expected: "object"
Received: "undefined"

 ❯ tests/integration/storage.test.ts:5:33
      3| describe('jsdom test environment', () => {
      4|   it('gives the renderer a working storage', () => {
      5|     expect(typeof localStorage).toBe('object');

For the reviewer

No user-facing behaviour changes. src/ is untouched, so the e2e lane has no new behaviour to reach and the hosted macOS runner covers the Electron suites as usual.

The timeout budget is deliberately generous because the unit lane does real Git work. A reviewer who prefers a tighter number should look at tests/unit/workbench.test.ts first, since that lane spawns around a dozen Git processes per case and is the reason the budget is 120 seconds rather than 10.

Two things worth knowing. The unit lane already carried per-case budgets of 15 and 30 seconds, so the change here is mostly about the cases that were left on the five second default, and moving the budget to config level so one number governs the lane. And the storage fix only changes behaviour on Node 24 and later, which is why hosted CI on Node 22.23.0 was already green and the problem was invisible until a local run on a newer Node.

Follow-up worth considering: the unit lane could stop spawning a dozen Git processes per case by folding the workspace inspection into fewer Git calls. That would be a change to src/main/workbench.ts rather than to the tests.

johnnyhuy and others added 2 commits November 30, 2026 04:33
Vitest's five second default was below what these lanes need. The unit
lane builds real Git repositories in temporary folders and spawns around
a dozen Git processes per case, and the integration lane renders the
whole workbench in jsdom. On a loaded machine both lanes failed a
changing set of tests, each one a timeout with a clean assertion trail.

Carry the budget at config level, the way the Electron e2e lane already
does, and drop the per-case overrides in the workbench tests so one
number governs the lane.

Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>
Node 24 and later define their own localStorage accessor on the global.
Vitest only copies window properties across when the key is missing from
the Node global, so window.localStorage resolved to Node's accessor,
which returns undefined. The setup then installed undefined and six
integration tests failed with a TypeError.

Read the jsdom window instead. Its storage works on every Node version,
and the new guard test proves the renderer receives a usable Storage.

Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>
@johnnyhuy
johnnyhuy merged commit 88e4f8a into main Nov 30, 2026
15 checks passed
@johnnyhuy
johnnyhuy deleted the agent/issue-97-test-gate-reliability branch November 30, 2026 07:31
@johnnyhuy

Copy link
Copy Markdown
Contributor Author

Verified the merged main commit 88e4f8a958327b233f3833a859ab534e4520f267 in a clean linked worktree with the pinned mise toolchain.

  • mise exec -- bun install --frozen-lockfile passed.
  • mise run build passed, including bun run lint, bun run typecheck, bun run test:unit (10 files, 115 tests), bun run test:integration (16 files, 135 tests), and the main/preload/renderer bundle.
  • Unit duration was 75.65 seconds; integration duration was 66.12 seconds.
  • Hosted Electron e2e passed before merging. No local e2e rerun or screenshot was needed for this test-infrastructure-only slice. Terminal proof is in the PR body.

Sweep merged one green agent PR and closed zero dead PRs. Issue #97 is closed, no open issues remain, and roadmap parents #1-#5 are completed. Release-please #31 is the only open PR and was left for the release workflow. The scheduled automation remains enabled because the PR list is not clear.

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.

Make the unit and integration test gates pass reliably

1 participant