Skip to content

test(cli): make browser timeout cleanup independent of child startup - #12254

Merged
cixzhang merged 1 commit into
mainfrom
recut/12184-browser-timeout-cleanup
Nov 18, 2026
Merged

cixzhang merged 1 commit into
mainfrom
recut/12184-browser-timeout-cleanup

Conversation

@cixzhang

Copy link
Copy Markdown
Contributor

Re-cut of #12184 by astracat-bot, byte for byte, on current main: the commit's diff is identical to #12184's. Credit stays with astracat-bot (a Co-authored-by trailer on the commit). The drain shepherd drives it and closes #12184 when this one merges.


validation: ran pnpm test:node packages/cli/api/theme-edit/theme-preview-follows-through-browser.test.mjs --maxWorkers=4: all 6 tests passed; the timeout case also passed 20/20 with ordinary startup and 20/20 with a two-second Node startup preload. ESLint, Prettier, the spec lookup, and pnpm review:pre passed.

Maintainer impact

The unit check at f233077 failed with ENOENT when the timeout test read its stand-in script's temp record. The browser run had correctly timed out, but a slow child process can exhaust the 1500 ms bound before it writes that record. The test then fails before it can check cleanup.

The first failing commit changes an unrelated smoke check. This is a startup race in the existing test, not a regression in that commit's code.

Intended invariant and change

No behavior change. A bounded browser run must still report timedOut and remove its own temporary profile folder.

Use fake timeout timers only in this test. Observe the stand-in's completed record through a filesystem watcher, verify that its profile exists, then advance the same 1500 ms bound. The real child process, process-group stop, and filesystem cleanup still run. Every original assertion remains; the profile-existence assertion additionally proves that cleanup removes a folder the child used. The test timeout and production code are unchanged.

Evidence

  • With unchanged tracked code, a Node preload that awaits a two-second timer reproduced the exact missing-record failure in 2/2 runs at f233077, and 2/2 on current main 5a3fd39. Ordinary startup passed, consistent with the race.
  • With the fix, Vitest's temporary repeats: 19 option ran the timeout case 20 times with that same startup delay and 20 times without it: all 40 passed. The other five tests passed in both suite runs. The repeat option and preload are not included in the change.
  • After restoring the normal test declaration, the submitted file passed its complete six-test suite again. ESLint and Prettier passed; pre-review reported no findings.
  • CodeBunny CI lab repro 3989755178234518597 was requested for 20 runs at the failing commit. It remains running with 0 completed runs and no log; it is not credited as reproduction or validation evidence. The local controlled-startup reproduction and repeat results above are the evidence for this fix.

This test checks timeout classification and cleanup, not whether the operating system can start Node within 1.5 seconds. The alternative would be to replace the process with a mock; keeping the real child retains the process and filesystem coverage.

Scope

Components: CLI browser-run test only.

Fixes test 0155f792dcf50f850793369fe45229446c36f7f7e988c53dfc6bd6003b395d24: packages/cli/api/theme-edit/theme-preview-follows-through-browser.test.mjs › the browser run › a run stopped at the bound is said to have timed out, and its temp folder goes.

See also #12097.

#12097 by josephfarina also changes this test file.

Overlap checked: #12184 (astracat-bot's original of this same change, byte for byte; it closes when this re-cut merges)

Owning session: noopbot (a61f66c2), under CI & Release (ca77f950); driven by the drain shepherd (66fc5b74). Land path: the shipper, through merge-guard.

Re-cut of #12184 by astracat-bot, byte for byte on current main.

Co-authored-by: astracat-bot[bot] <323722387+astracat-bot[bot]@users.noreply.github.com>
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 17, 2026
@astracat-bot

astracat-bot Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 18, 2026, 10:41 AM UTC

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec ec1d597

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · ec1d597

Storybook · Sandbox · built from this PR's head

Package size: no published package changed; no new dependencies.

Not run on this PR: add ci:run-visual for Visual, ci:run-a11y for Accessibility, ci:run-rtl for RTL.


Generated by PR Enrichment workflow | View full report

@vercel

vercel Bot commented Nov 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 17, 2026 8:03am UTC

Request Review

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved. CI's run on this head passed, including the node test shard that runs this file.

The timeout case now holds the 1500 ms bound with fake timers until the stand-in has written its record, so a slow child startup can no longer fail it before cleanup is checked. With Node startup delayed by two seconds, the old test fails with ENOENT and the new one passes, also merged into main.

  • Non-blocking: if an assertion fails before the bound is advanced, the stand-in process and its temp folder stay until the test worker exits; advancing the bound and awaiting running in finally, before vi.useRealTimers(), stops it (see the existing inline comment on line 121).
Claims and files checked

Review mode: same-head; reason: none

  • changed rules (0): none
  • Claim: the change repeats the earlier pull request it re-cuts line for line, on current main, with credit in a co-author trailer. Verified: the 25 added and removed lines are identical (the earlier pull request's hunk starts one line earlier), and the commit carries the trailer.
  • Claim: a slow child can use up the 1500 ms bound before it writes its record, so the old test fails reading it before it checks cleanup. Verified: with a two-second startup delay the base test fails with ENOENT at the record read.
  • Claim: the first failing commit changes an unrelated smoke check, so this is a startup race, not a regression. Partly verified: that commit only touches the CLI global-mode smoke script and its test; the failing unit run itself could not be found.
  • Claim: no behavior change; a bounded run must still report timedOut and remove its temp profile folder. Verified: only this test file changes, and lines 117 and 118 still assert both.
  • Claim: fake timers apply only to this test. Verified: installed on line 103 and restored on line 121.
  • Claim: the test waits for the record through a filesystem watcher, checks the profile folder, then advances the same 1500 ms bound. Verified: lines 94-101, 114 and 115.
  • Claim: the real child process, process-group stop and folder removal still run. Verified: the module mock passes runBrowser through unchanged, and after the advance it stops the group and removes the folder.
  • Claim: every original assertion remains, and the profile check shows that cleanup removes a folder the child used. Verified: lines 113, 117 and 118 remain, and the stand-in makes the profile folder before it writes its record.
  • Claim: the test timeout and production code are unchanged. Verified: the 30-second timeout stays on line 124, and no other file changes.
  • Claim: the delayed-startup reproduction fails on the earlier commit and on main. Partly verified: the same failure reproduces on the base, which contains both commits; the commits themselves were not run.
  • Claim: all six tests pass, and the timeout case passes with ordinary and with delayed startup, 20 runs each. Verified for six of six with ordinary and with delayed startup, merged into main; the 20-run repeats were not rerun.
  • Claim: the repeat option and the startup preload used while testing are not part of the change. Verified from the diff.
  • Claim: ESLint, Prettier, the spec lookup and the pre-review report pass. Verified: ESLint and Prettier pass on the file, and the pre-review report lists no findings and no baseline claims.
  • Claim: a separate lab reproduction was requested and is not counted as evidence. Not relied on.
  • Claim: keeping the real child, rather than a mock, keeps process and filesystem coverage. Verified: no process or filesystem call is mocked in this case.
  • Claim: the scope is the CLI browser-run test only, and the fixed test is the browser run's timeout case. Verified: one file under packages/cli, the case on line 91.
  • Claim: #12097 also changes this test file. Verified: it did, and it is merged into the base.
  • Notes on who drives and lands the change, and on closing the original pull request: process statements, not code claims.
  • File packages/cli/api/theme-edit/theme-preview-follows-through-browser.test.mjs: one non-blocking finding (above); otherwise clear.

Automated review (maintainer link)

Comment on lines +120 to +121
watcher.close();
vi.useRealTimers();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Non-blocking: if an assertion above fails before line 115, the faked bound is still pending when vi.useRealTimers() runs, so it never fires. The stand-in keeps running and its temp folder stays until the test worker exits. Firing the bound here stops it on every path, with let running; declared before try:

} finally {
  watcher.close();
  await vi.advanceTimersByTimeAsync(1500);
  await running;
  vi.useRealTimers();
  fs.rmSync(dir, {recursive: true, force: true});
}

On the passing path running has already settled, and the extra advance stays short of the 5 s grace timer.

@cixzhang
cixzhang marked this pull request as ready for review November 18, 2026 09:02
@cixzhang
cixzhang marked this pull request as draft November 18, 2026 10:21
@cixzhang
cixzhang marked this pull request as ready for review November 18, 2026 10:22
@cixzhang
cixzhang merged commit f6d900c into main Nov 18, 2026
195 of 201 checks passed
@github-actions
github-actions Bot deleted the recut/12184-browser-timeout-cleanup branch November 19, 2026 06:05

This branch was successfully deployed

1 active deployment
Preview — ec1d5975 Deployed Nov 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant