Skip to content

test: wait for the next row's draft read in the code block slot test - #33343

Merged
bolichen97 merged 1 commit into
mainfrom
fix/32131-selection-toolbar-flake
Nov 8, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/32131-selection-toolbar-flake

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: The code block test "keeps an out-of-range passage in the fallback slot and the next row in its own slot" stops failing at random on CI, and still fails when the next row's draft is filed under the fallback slot.

website/src/test/SelectionToolbar.codeBlock.test.tsx > "keeps an out-of-range passage in the fallback slot and the next row in its own slot" failed on a Frontend Tests shard of a PR that never touched the toolbar (#31792), with AssertionError: expected -1 to be less than -1 at expect(nextStart).toBeLessThan(-1). The same file passes when run alone.

Why it matters

A random red on a frontend shard lands on whoever pushed last. They rerun the shard and spend time proving the red is not theirs, while the test guards a real behaviour: a draft typed over one code row must not come back over another row.

Not a goal

  • Any change to SelectionToolbar itself: it files the next row's draft under that row's own slot; only the test read the slot too early.
  • The other tests in the file that read draftStore.read.mock.lastCall: each of their drags fires one mouseup, and the view unmounts between drags, which cancels any check still pending (see Sibling sweep).

What changed (motivation → approach → change)

The test drags twice in one view. Its first drag fires two mouseups (one from the dragInCode helper, one from the test after it swaps in the out-of-range range), and each mouseup makes the toolbar look at the selection 50 ms later. On a busy CI worker the second look can come after the test has typed a draft and pressed Escape. It then re-opens the box over the first drag, filed under the fallback slot (-1). The second drag's findByLabelText finds that box straight away, before the second drag's own look has run, so the draft key the test reads is still -1.

The test now waits for the second drag's draft read before it looks at the box: await waitFor(() => expect(draftStore.read.mock.lastCall![1]).toBeLessThan(-1)). Every assertion stays. If the toolbar filed the next row under the fallback slot, the wait would give up after one second and the test would fail by name.

Backwards compatibility

Compatible: test-only change; no product code, API or stored data changes.
Removes nothing: one test gains a wait before its existing assertions.

Tests

Changed: "keeps an out-of-range passage in the fallback slot and the next row in its own slot" in website/src/test/SelectionToolbar.codeBlock.test.tsx waits for the next row's draft read.

Determinism proof (all from website/). The test and SelectionToolbar.tsx are byte-identical at this PR's base, at d1a9a812d7 (unmarked rows) and at 2caa69b7a6 (rows marked *):

Run Without this change This change
Forced condition (the first drag's second check runs late), the test, 3 runs red 3/3 at expect(nextStart).toBeLessThan(-1), expected -1 to be less than -1, the CI assertion green 3/3
* The same, 5 runs red 5/5, same assertion green 5/5
* Forced condition, the whole file n/a 30/30 green
* Forced condition, { repeats: 49 } on the test (50 runs) n/a green
* Plain, { repeats: 49 } on the test (50 runs) n/a green
Whole file, shuffled, --maxWorkers=1 n/a 30/30 green, seeds 4242, 17; * seeds 11807, 2731, 30115
* With SelectionToolbar.composer.test.tsx + MarkdownPanelCodeBlock.test.tsx, shuffled, --maxWorkers=3 n/a 131/131 green, seeds 9466, 21410
* KIROCREW_ACT_STRICT=1, whole file n/a 30/30 green, 0 act() warnings
* Negative control: every code selection filed under -1 in SelectionToolbar.tsx n/a red by name at the new wait (:457)

The forced condition is a throwaway edit to the test, never committed. It delays the check that the first drag's second mouseup schedules, then pauses after Escape so that check lands before the second drag, as it did on CI:

const realSetTimeout = globalThis.setTimeout
vi.spyOn(globalThis, 'setTimeout').mockImplementationOnce(((fn: () => void) => realSetTimeout(fn, 400)) as typeof setTimeout)
fireEvent.mouseUp(document, { clientX: 100, clientY: 50 }) // the first drag's second mouseup
// ... after the Escape's waitFor:
await new Promise(resolve => setTimeout(resolve, 450))
npx vitest run src/test/SelectionToolbar.codeBlock.test.tsx -t "keeps an out-of-range passage" --maxWorkers=1
npx vitest run src/test/SelectionToolbar.codeBlock.test.tsx --maxWorkers=1 --sequence.shuffle --sequence.seed=<seed>

The repeat runs above were taken on a heavily loaded shared host; the forced condition, not host load, is what reproduces the race.

Proof: not provable -- frontend test (prove.py runs Python only)

Manual verification

N/A: test-only change; the forced-condition runs above are the verification.

Screenshots / video

Why no screenshot: nothing renders differently; this change touches one test file only.

Related Issues

Closes #32131

Sibling sweep

Swept: git grep -n "draftStore.read.mock.lastCall" -- website/src/test/
Sibling: website/src/test/SelectionToolbar.codeBlock.test.tsx:457 -- changed here: the new wait, before the read at :459
Sibling: website/src/test/SelectionToolbar.codeBlock.test.tsx:171 -- not affected -- one mouseup per drag, and the view unmounts between drags
Sibling: website/src/test/SelectionToolbar.codeBlock.test.tsx:182 -- not affected -- one mouseup per drag, and the view unmounts between drags
Sibling: website/src/test/SelectionToolbar.codeBlock.test.tsx:206 -- not affected -- one mouseup per drag, and the view unmounts between drags
Sibling: website/src/test/SelectionToolbar.codeBlock.test.tsx:221 -- not affected -- one mouseup per drag, and the view unmounts between drags
Sibling: website/src/test/SelectionToolbar.codeBlock.test.tsx:230 -- not affected -- one mouseup per drag, and the view unmounts between drags
Sibling: website/src/test/SelectionToolbar.codeBlock.test.tsx:241 -- not affected -- one mouseup per drag, and the view unmounts between drags
Sibling: website/src/test/SelectionToolbar.codeBlock.test.tsx:250 -- not affected -- one mouseup per drag, and the view unmounts between drags
Sibling: website/src/test/SelectionToolbar.codeBlock.test.tsx:374 -- not affected -- one mouseup per drag, and the view unmounts between drags
Sibling: website/src/test/SelectionToolbar.codeBlock.test.tsx:411 -- not affected -- one mouseup per drag, and the view unmounts between drags
Sibling: website/src/test/SelectionToolbar.codeBlock.test.tsx:424 -- not affected -- two mouseups, but the test makes no second drag after them
Sibling: website/src/test/MarkdownPanelCodeBlock.test.tsx -- not affected -- each test makes one drag through dragInCode alone

Pattern harvest

Rule candidate: review-prompt
Pattern: a findBy* used as the barrier for a mock call that a deferred handler makes, when an earlier gesture in the same render can still have a deferred handler pending that renders the same element

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributed under the project's Apache-2.0 license.

The out-of-range test drags twice in one view. Its first drag fires
two mouseups, and each schedules a selection check 50 ms later. When
the second check lands after Escape, it re-opens the box over the
first drag, filed under the fallback slot. The next drag's
findByLabelText then resolves on that box before the next row's own
check has run, so the draft key the test reads is still -1.

Wait for the next row's draft read before asserting on it. Delaying
the first drag's second check turns the test red on the parent every
run with the CI assertion and leaves it green here; with the per-row
draft key removed from the toolbar it still fails by name.

Closes #32131
@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 8, 2026 18:20
@bolichen97
bolichen97 requested a review from Zedmor November 8, 2026 18:20
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ⏭️ skipped

Revision 889a04aafc66160d51c76fe522e06cae5c3a7e63 ships no reviewable capability (docs, tests or generated files only), so there is nothing to inventory. Does not block merge.

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 889a04aafc66160d51c76fe522e06cae5c3a7e63 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: this is a test-only change that waits on the second drag's own draft read, so the test can no longer read too early. If the next row is filed under the fallback slot, the test still fails.

[DESIGN-REVIEWED] 889a04a

Description read

[DESCRIPTION-READ] 1229f51975cd6d9fbcec93c60059b50490722ad764f320740fa0bf3a8c44bb2b

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of 889a04aafc66160d51c76fe522e06cae5c3a7e63 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing to check. The PR only changes one test file and adds or changes no user-visible control, so no screenshot is needed.

[UX-REVIEWED] 889a04a

Description read

[DESCRIPTION-READ] 42acb25157b6aef955861fbd0fb01702912b40f88cadc6595ccb87d6a01e52db

That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 889a04aafc66160d51c76fe522e06cae5c3a7e63 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 889a04a

Verdict parsed from the review's SHA-scoped output markers for commit 889a04aafc66160d51c76fe522e06cae5c3a7e63.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 889a04aafc66160d51c76fe522e06cae5c3a7e63 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 889a04aafc66160d51c76fe522e06cae5c3a7e63 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 889a04a

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 889a04aafc66160d51c76fe522e06cae5c3a7e63 false-positive: <reason, 20 to 500 characters>

@bolichen97
bolichen97 enabled auto-merge (squash) November 8, 2026 18:44
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 8, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tier 1 auto-approve: test (1 file). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: test-only change that adds one wait in the code block selection toolbar test so a late check from the first drag cannot reopen the comment box.

@bolichen97
bolichen97 merged commit 1502382 into main Nov 8, 2026
98 checks passed
@bolichen97
bolichen97 deleted the fix/32131-selection-toolbar-flake branch November 8, 2026 19:06
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 8, 2026
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.

Flaky: SelectionToolbar.codeBlock "keeps an out-of-range passage in the fallback slot and the next row in its own slot"

2 participants