Skip to content

fix(web): the phone sidebar's Add project test no longer reads other files' drafts - #617

Merged
NoahHendrickson merged 3 commits into
customfrom
t3/fix-sidebar-sheet-picker-flake
Nov 29, 2026
Merged

NoahHendrickson merged 3 commits into
customfrom
t3/fix-sidebar-sheet-picker-flake

Conversation

@NoahHendrickson

Copy link
Copy Markdown
Owner

Sidebar.browser.test.tsx › "closes the sheet when Add project opens the picker, as New thread does" has failed in CI Test Web 2 in 9 of the last ~13 runs since the #591 sync, including custom's own run 46315453950. Every time, the Add project click times out because no Add project button exists.

Cause. All Vitest browser test files run in iframes on one origin, so they share localStorage. The composer draft store (t3code:composer-drafts:v1) loads its saved drafts from it when the module is imported. A ChatView browser test ("a stashed prompt ending in a file chip…") saves a draft, "Check package.json". When ChatView runs before Sidebar, the Sidebar test loads that draft. The fork renders drafts as sidebar rows (sidebar-v2-draft-rows), so the row replaced the "No projects yet / Add project" empty state the test clicks. Whether it fails depends on which file runs first. CI's 4-vCPU runners use 3 workers and hit it; the Mac's default worker count usually didn't. It is a test isolation bug, not an app bug.

Fix. The test empties the draft store it depends on and restores it afterwards. SidebarDraftBlock.browser.test.tsx already does the same. I didn't add per-file storage isolation to browserSetup.ts: useEnvironmentSpeechInput.browser.test.tsx "revokes across windows…" needs real localStorage shared with a child iframe.

Proof.

  • Running ChatView and Sidebar in one worker (--maxWorkers=1) without the fix, the test failed 3/3 when ChatView ran first and passed 3/3 when Sidebar ran first. With the fix it passed 10/10 with ChatView first.
  • Web shard 2/2 at --maxWorkers=3 failed on this test before the fix and passed 475/475 files (4144 tests) after.
  • A dump of the failing run's DOM showed the leaked draft row and no empty state.
  • vp run check:changed, node .fork/lint-owned.mjs, node .fork/design-lint.mjs --check and src/__fork_guards__/ (158/158) all pass.

Reviewed with sol-loop: 1 round with GPT-6.1 Sol on high. Sol verdict: approved


🤖 Signed: Claude Opus 5.5 (claude-opus-5-5) via Claude Code
🤖 Reviewed: GPT-6.1 Sol (gpt-6.1-sol, high) via Codex, one sol-loop round, approved with no findings

…files' drafts

Every browser test file runs in an iframe on the same origin, so they share
localStorage, and the composer draft store hydrates from it at import. When
ChatView's browser tests ran first, the draft they saved became a sidebar row
in Sidebar.browser.test.tsx, replacing the "No projects yet" empty state, so
the Add project click waited for a button that never rendered.

The test now empties the draft store it depends on and restores it after.

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

Copy link
Copy Markdown
Owner Author

Code-quality review of aa1bd4543063416055228178f3c08597c9931d49 (base de4874b9ed): no major structural issues found.

  • Right place for the fix. The test only needs an empty draft store because the fork shows drafts as sidebar rows. So the reset belongs in the fenced Sidebar case, not in the upstream ChatView test that leaves the draft behind. Clearing t3code:composer-drafts:v1 in test/browserSetup.ts would be worse in two ways. It would put one feature's storage key into setup that every browser test uses. It would also still race: with 3 workers, a ChatView file running at the same time can write after setup clears the key and before Sidebar imports the store. Resetting the in-memory store doesn't have that race, because the store reads localStorage only once, on import, and has no storage listener.
  • No helper needed. The using reset block is the third copy of this pattern. The other two are upstream's own, in SidebarDraftBlock.browser.test.tsx. Removing the copies would mean changing upstream files or adding a fork-only wrapper with a single caller. Both add more fork surface than the nine lines they save, so matching upstream's pattern is the better choice.
  • Scope is tight. One fenced import, one fenced block, and a manifest note. The file grows from 496 to 510 lines, with no new branches in app code.

Not approving: this automation only leaves comments.

@NoahHendrickson NoahHendrickson left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review of aa1bd4543063416055228178f3c08597c9931d49 (base de4874b9ed)

No blocking findings. The fix does what the description says. It empties the three draft maps the Sidebar empty state reads, using restores the snapshot when the test ends, the fence markers point at the right manifest entry, and the customizations.yaml note matches the code.

I checked two possible issues and kept neither as a blocker:

  1. The reset also reaches shared localStorage. This is not new. The store persists through a 300 ms debounced write, and mergeDraftRecord (composerDraftStore.ts:157) deletes keys that were in the baseline but are missing from local state. If the test runs longer than 300 ms, emptying the store removes other files' drafts from t3code:composer-drafts:v1. The restore then writes the snapshot back. In theory, this could bring back a draft that a concurrent file deleted in the meantime. However, at least eight other browser test files reset the store with the same setState(..., true) pattern, including SidebarDraftBlock, ProjectSettingsPanel, PreviewView and PullRequestDetailPanel.permissions. I also couldn't build a real cross-file failure from it. This is worth knowing if more draft-related flakes show up, but it shouldn't block this PR.
  2. Other cases in Sidebar.browser.test.tsx still render with leaked drafts. They don't depend on them. "opens another thread…", "New thread on branch…", "Settle…" and "settled pagination" all find rows by their exact thread titles and don't count rows. A leaked "Check [package.json]…" draft row can't match those selectors, so moving the reset into a beforeEach isn't needed yet.

Not run locally (this worktree has no node_modules). When I posted this, CI on this commit was still pending, including Test Web 2.


🤖 Review: Claude Opus 5.5 (claude-opus-5-5) via Claude Code /code-review, findings checked against the source

@github-actions github-actions Bot added size:XS vouch:trusted Author is trusted by repo permissions or the VOUCHED list. labels Nov 29, 2026
@NoahHendrickson

Copy link
Copy Markdown
Owner Author

Thanks, both reviews checked against the source; no changes made.

  • Reset reaching shared storage: agreed it's real and not new. The merge in composerDraftStore.ts deletes only keys this tab changed since load, and the restore writes the snapshot back. Eight other browser files already reset the store this way, and I couldn't make it fail across files either. Noted as a follow-up in case draft-related flakes come back.
  • Other Sidebar cases with leaked drafts: agreed. They select rows by exact thread title and never count rows, so the reset stays in the one case that needs an empty list.
  • Placement and no helper: agreed. Clearing in browserSetup.ts would still race a ChatView file running at the same time, and a helper would add fork surface for a single caller.

🤖 Signed: Claude Opus 5.5 (claude-opus-5-5) via Claude Code

@NoahHendrickson
NoahHendrickson merged commit 0b3e3c8 into custom Nov 29, 2026
32 checks passed
@NoahHendrickson
NoahHendrickson deleted the t3/fix-sidebar-sheet-picker-flake branch November 29, 2026 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants