Skip to content

test(ui): two flaky Test UI cases wait on the effect they read - #29532

Merged
objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/project-thread-wozppz
Nov 2, 2026
Merged

objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/project-thread-wozppz

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Steedos · project thread

Fixes #29468

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么:两个今天在 main 上各红过一次的 UI 测试,断言改为等待它真正读取的那个 effect 产出的结果,不再在 DOM 出现后立即同步读取。只改两个测试文件,产品代码不动。
  • 为什么改:两处读到的值(Studio 的 beforeunload 守卫、Console 的 /me/apps 请求)都由 React 的 passive effect 写出,而 effect 可能晚于测试等待的那次提交执行;负载高的分片上测试先读到旧值就红了。
  • 风险与回滚:仅测试改动,不发布任何包;回滚即 revert 本 PR。消融验证证明两条断言仍能钉住原卡的行为。
  • 先看: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 on main today 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-shell is private and @object-ui/console publishes dist and its plugin entry only), so this PR carries skip-changeset.

  • StudioDesignSurface.refusedLeafUnsaved-29113.test.tsx: a new helper untilReloadAsks(expected) wraps the beforeunload read in waitFor. 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/apps read, then runs the file's own settle() 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.

  • Studio: the refusal banner shows in one commit. The pillar reports refusedUnsent from an effect (onDirtyChange), and the surface installs its beforeunload listener from an effect of the render that report causes. findByTestId('studio-refusal') resolves on the commit, so reloadAsks() can run before either effect has.
  • Console: LauncherAppsProvider asks /me/apps from its effect, which can run after the commit that shows home-page.

Testing Library's waitFor resolves on the DOM mutation and drains with a 1 ms setTimeout. When React's scheduler yields after the commit (render work over its 5 ms frame), the passive effects run from a setImmediate continuation. 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:

File · case Base: red / runs Fixed: red / runs Red line (same as CI)
refusedLeafUnsaved-29113 · "a refused report save makes a reload and the pillar link ask…" 1 / 80 0 / 32 279 expect(reloadAsks()).toBe(true)
permissionsWave-29114 · "the session names the organization…" 1 / 36 0 / 36 230 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 of setImmediate, which is what a loaded event loop does to it:

File Base: red / runs Fixed: red / runs
refusedLeafUnsaved-29113 14 / 20 (all at line 279) 0 / 20
permissionsWave-29114 15 / 20 (all at line 230) 0 / 20

Ablations, each through scripts/ablation-replace.mjs (anchor 1 → 0, restored to the HEAD blob, git diff HEAD empty):

  • StudioDesignSurface.tsx: onDirtyChangeRef.current?.(navDirty || refusedUnsent) → (navDirty). The fixed file goes red: the target case at untilReloadAsks(true), plus the list-view case. 2 failed, 2 passed.
  • apps/console/src/App.tsx: ConsolePermissionsRequest removed. The fixed file goes red in both early-request cases at waitFor(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 lint and pnpm --filter @object-ui/console lint exit 0, with no warning on either touched file. turbo run type-check for @object-ui/app-shell and @object-ui/console: 72 tasks, exit 0.

Acceptance notes

  • The shard-sized run used the --maxWorkers load beside CPU hogs, not the real planShards file set. The scheduler probe shows the mechanism directly.
  • The second case of the 29113 file (the rail) did not go red under the ablation. It reads the pillar's own leafUnsent during 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-manifest and its --self-test, spec check: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, and pnpm --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-parity was run on this body before the PR opened.

Human Minimum

  • 1. Schemas start as Zod; packages/spec holds no runtime logic. (not touched)
  • 2. Every name I added uses the casing for its kind.
  • 3. No formatter ran; pnpm lint passes.
  • 4. One issue, one branch off an up-to-date main, one pull request.
  • 5. A change that publishes carries a changeset. (publishes nothing: skip-changeset)
  • 6. packages/spec touched: its generated artifacts are regenerated and committed. (not touched)
  • 7. No hand edits to content/docs/references/, packages/*/CHANGELOG.md or content/docs/releases/.
  • 8. Title, body and comments are in English.

Generated by Claude Code

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
@objectstack-fleet objectstack-fleet Bot added the skip-changeset PR has no user-facing published change; bypasses the changeset gate label Nov 2, 2026
@github-actions github-actions Bot added the size/s label Nov 2, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:ui#4 · zhuangjianguo · session_01QsR2jR7ZFkpqmm4U8S1f9y

席位核对 · ACCEPT · 2026-11-02T18:37Z

Head-sha: 3d6225a85dd2b7cd39af08fb80515d47b48ab8dc

  • Shape: draft → main, Fixes #29468 in the body only. 2 files, +20 / −3, test-only, skip-changeset. No governed path: check-governed-merges --pr 29532 hit 0 of 2 paths. Clause-②: no and Metadata-protocol: none are line-initial in the body.
  • File surface: the two test files the card names, exactly the claim (6581800254). No product source is touched.
  • The race, named: both files read a value a React passive effect writes, in the tick after the commit the test awaited. In Studio, the beforeunload guard lands two effect passes after the refusal banner shows. In the Console, LauncherAppsProvider asks /me/apps from its effect after home-page shows. When the scheduler yields, those effects run from setImmediate, and on a loaded box RTL's 1 ms waitFor drain fires first.
  • Read in the diff:
    • Studio: the three reloadAsks() reads become await untilReloadAsks(…) (waitFor on the outcome).
    • Console: the test waits for the first /me/apps call, then settles. The pins that follow are kept unchanged: one permissions call, one launcher call and no duplicate URL. A second request still reds the case.
    • No retry, no skip, no quarantine, and no raised timeout, as ruled.
  • Counts:
  • Deviations, accepted: the parallel run used CPU-hog load rather than the planShards file set; the scheduler-delay probe reproduces the CI line deterministically, which is the stronger proof. The full gate loop ran at 392359f6, and the ratchet subset re-ran green after the main merge.
  • Gates: 24 of 24 derived gates exited 0, and lint plus the app-shell and console type-checks are green. Check-runs on this head: 44 success, 16 skipped, 0 failed or pending, including all 16 Test UI shards. All ten required contexts succeeded, or were skipped by their path filter (Build Core).
  • Landing: ordinary queue landing, pr_ready then automerge_enable. Fixes #29468 closes the card on merge.

Generated by Claude Code

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 2, 2026 18:39
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 2, 2026
Merged via the queue into main with commit 208d3e2 Nov 2, 2026
61 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-wozppz branch November 2, 2026 19:07
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:ui#4 · zhuangjianguo · session_01QsR2jR7ZFkpqmm4U8S1f9y

Landed · 2026-11-02T19:49Z · PR #29532 merged through the merge queue as 208d3e2e. Record: ACCEPT 6585209945 at 3d6225a8 (Clause-②: no, test-only, no contract review owed).

probe before (208d3e2e~1) now (origin/main)
async function untilReloadAsks(expected: boolean): Promise<void> { in ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.refusedLeafUnsaved-29113.test.tsx (the reload-guard reads wait on the guard) 0 1
await waitFor(() => expect(launcherCalls()).toHaveLength(1)); in ui/apps/console/src/__tests__/App.permissionsWave-29114.test.tsx (the launcher read waits on its provider's effect) 0 1

The card closed through Fixes. pm:dispatched comes off with this note. If either case reds main again, that is a new reading against this fix: file it with the run id, not a retry.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s skip-changeset PR has no user-facing published change; bypasses the changeset gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(ui): two Test UI cases landed today each red once on a main push and green on the next — refusedLeafUnsaved-29113 and App.permissionsWave-29114

1 participant