Repository navigation
test(ui): two flaky Test UI cases wait on the effect they read - #29532
Merged
Merged
Conversation
The refusedLeafUnsaved-29113 case read the beforeunload guard straight after the refusal banner showed, and the permissionsWave-29114 case read the launcher's /me/apps call straight after the home page showed. Both values are written by passive effects that can run after the commit the test waited for, so a loaded shard read them first. Each read now waits on its own outcome. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jRAnis8Swqnj1Aw3B8
Contributor
Author
|
domain:ui#4 · zhuangjianguo · session_01QsR2jR7ZFkpqmm4U8S1f9y 席位核对 · ACCEPT · 2026-11-02T18:37ZHead-sha:
Generated by Claude Code |
Contributor
Author
|
domain:ui#4 · zhuangjianguo · session_01QsR2jR7ZFkpqmm4U8S1f9y Landed · 2026-11-02T19:49Z · PR #29532 merged through the merge queue as
The card closed through Generated by Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Steedos · project thread
Fixes #29468
Clause-②: no
Metadata-protocol: none
维护者速读
StudioDesignSurface.refusedLeafUnsaved-29113.test.tsx新增的untilReloadAsks及其三处调用;App.permissionsWave-29114.test.tsx第一条用例中新增的waitFor(launcherCalls)加settle()。ui/下运行pnpm exec vitest run packages/app-shell/src/views/studio-design/StudioDesignSurface.refusedLeafUnsaved-29113.test.tsx apps/console/src/__tests__/App.permissionsWave-29114.test.tsx,预期 2 个文件、8 条用例全绿。What changes
Two
ui/test cases that each went red once onmaintoday now wait on the outcome they read instead of reading it in the same tick as the DOM marker they awaited. Test-only: no product source changes, no changeset (neither touched file ships:@object-ui/app-shellis private and@object-ui/consolepublishesdistand its plugin entry only), so this PR carriesskip-changeset.StudioDesignSurface.refusedLeafUnsaved-29113.test.tsx: a new helperuntilReloadAsks(expected)wraps thebeforeunloadread inwaitFor. It replaces the three bare reads that follow an autosave answer or a leaf load (the CI red was the first, line 279).App.permissionsWave-29114.test.tsx: in the first case, after the home page shows, the test waits for the launcher's/me/appsread, then runs the file's ownsettle()before the "exactly once, no duplicate URL" assertions, so a second request would also have time to show.Why
The race is the same in both files: a value written by a React passive effect, read in the tick after the commit the test waited for.
refusedUnsentfrom an effect (onDirtyChange), and the surface installs itsbeforeunloadlistener from an effect of the render that report causes.findByTestId('studio-refusal')resolves on the commit, soreloadAsks()can run before either effect has.LauncherAppsProviderasks/me/appsfrom its effect, which can run after the commit that showshome-page.Testing Library's
waitForresolves on the DOM mutation and drains with a 1 mssetTimeout. When React's scheduler yields after the commit (render work over its 5 ms frame), the passive effects run from asetImmediatecontinuation. On an idle box that continuation wins; on a loaded box the event loop takes over 1 ms to get back, the drain timer fires first, and the test reads the value before the effect writes it.This is a test race, not a product race: the guard and the request both happen, just one effect pass after the marker.
Tests
Reproduced first, at base
8ca9dd7b, with each test file copied N times into one vitest run (--maxWorkers=4,--sequence.shuffle) beside node CPU hogs on a 4-core box:expect(reloadAsks()).toBe(true)expect(launcherCalls()).toHaveLength(1)To name the race rather than only count it, a probe preload (
--import, scratch only, not committed) made React's scheduler continuation (performWorkUntilDeadline) run from a timer 2 ms or 3 ms later instead ofsetImmediate, which is what a loaded event loop does to it:Ablations, each through
scripts/ablation-replace.mjs(anchor 1 → 0, restored to the HEAD blob,git diff HEADempty):StudioDesignSurface.tsx:onDirtyChangeRef.current?.(navDirty || refusedUnsent)→(navDirty). The fixed file goes red: the target case atuntilReloadAsks(true), plus the list-view case. 2 failed, 2 passed.apps/console/src/App.tsx:ConsolePermissionsRequestremoved. The fixed file goes red in both early-request cases atwaitFor(permissionsCalls … 1). 2 failed, 2 passed.Whole files on the merged head
3d6225a8: 2 files, 8 tests, all passed.pnpm --filter @object-ui/app-shell lintandpnpm --filter @object-ui/console lintexit 0, with no warning on either touched file.turbo run type-checkfor@object-ui/app-shelland@object-ui/console: 72 tasks, exit 0.Acceptance notes
--maxWorkersload beside CPU hogs, not the realplanShardsfile set. The scheduler probe shows the mechanism directly.leafUnsentduring render, not the surface report, so it is synchronous and not part of this race. It is unchanged here.Verification
Derived gates (dispatch-gates --commands, diff 392359f, 2 files, 23 changed lines)
All exit 0 at
392359f6:check-closing-keyword-parity --self-test,check-comment-mask-corpus,check-sdui-manifestand its--self-test, speccheck:duration-unit-keys,check:cross-package-test-inputs,check:dispatcher-error-vocabulary,check:driver-memory-census,check:engine-double-contract,check:gitlink-declared,check:nul-bytes,check:published-files,check:refd-timer-probe,check:skill-identifier-liveness,check:test-source-alias,check:tier-file-adoption,check:type-check-coverage,check:undeclared-dep-imports,check:watch-hint-literal,check:where-matcher,check:query-options-erasure,check:type-check-debt, andpnpm --dir ui exec vitest run scripts/(169 files passed, 2 skipped; 4921 tests).Rerun on the merged head
3d6225a8, exit 0:check:type-check-coverage,check:query-options-erasure,check:type-check-debt,check-sdui-manifest,check:nul-bytes.check-closing-keyword-paritywas run on this body before the PR opened.Human Minimum
packages/specholds no runtime logic. (not touched)pnpm lintpasses.main, one pull request.skip-changeset)packages/spectouched: its generated artifacts are regenerated and committed. (not touched)content/docs/references/,packages/*/CHANGELOG.mdorcontent/docs/releases/.Generated by Claude Code