Repository navigation
test(dashboard): stub the frame window only after its mount ping ran - #32345
Conversation
The refetch tests swap a stand-in window under the dashboard frame as soon as the iframe is in the DOM. useFrameAliveRecovery pings the frame from a passive effect, which on a busy runner runs after that swap, so the mount ping landed in the stand-in and 'expect(posted).toEqual([])' saw mc-frame-ping. Wait on the real signal instead: wrap the real hook and record, from an effect declared after its own, the frame it armed on; the shared mountedFrame helper waits for that before the test stubs the window. Fixes #32286
First Principles Review (Opus 5.5) — ⏭️ skippedRevision |
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing to check. This PR only changes a test file and adds or changes no user-visible control, so it needs no screenshots. [UX-REVIEWED] 99399af Description read[DESCRIPTION-READ] 6131c2fdbc4c47c0a26ae7697b39b55f17a50b469d8564e3de5312b6c24e0546 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 |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS The fix replaces a timing race with a signal that the frame's mount effect has run, and the assertions are unchanged. [DESIGN-REVIEWED] 99399af Description read[DESCRIPTION-READ] a2354dd052026929fd078453cd9d2dc92100273d9f98748f3fbf6e2b6fa35d06 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 |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: test (1 files). 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: the dashboard frame test stubs the frame window only after the frame-alive mount ping ran, removing a race on busy runners.
bolichen97
left a comment
There was a problem hiding this comment.
Approving 99399af.
What I checked on this head:
- The base is main. All 96 checks are green and none is pending. The UX and Design lanes pass, the Opus and GPT lanes have no blocking findings, and the First Principles lane is skipped for a test-only change.
- The diff is one test file,
CrewDynamicDashboard.refetch.test.tsx, and no product code. The cause in the description holds up against the test: the test put its stand-in window under the frame as soon as the<iframe>was in the DOM, and the frame-alive hook pings from a passive effect, so on a loaded runner the mount ping landed in the recorder. The fix keeps the real hook and adds a mock wrapper that records each armed frame from an effect declared right after the hook's own. React runs effects of one component in declaration order, so the record means the mount ping has already gone. The three tests then wait for that record before stubbing the window, through one sharedmountedFramehelper, and the record is cleared in eachbeforeEach. - What the tests assert is unchanged, and
CrewDynamicDashboardanduseFrameAliveRecoveryare untouched. - No regex, no product change, and nothing made stricter.
I set auto-merge on this head.
Problem / Motivation
Goal:
CrewDynamicDashboard.refetch.test.tsxstops failing at random on CI.a late refetch reply > is not posted into the document that replaced the one that askedfailed on an unrelated PR (Frontend Tests shard 2/4):expect(posted).toEqual([])received[{ type: 'mc-frame-ping' }]. It passes locally.Why it matters
A red Frontend Tests shard blocks PR Readiness on any open PR that happens to draw it, so contributors rerun CI for a defect that is not theirs.
Not a goal
CrewDynamicDashboardoruseFrameAliveRecovery: both behave as designed.Intended? / Repro
Intended? Yes, the product behaviour is intended; the defect is in the test.
useFrameAliveRecoverypings the frame's own window when it mounts (website/src/hooks/useFrameAliveRecovery.ts:84 on main,else ping(), documented at lines 13-34 of the same file). The ping goes from a passiveuseEffect. The test (website/src/pages/members/CrewDynamicDashboard.refetch.test.tsx:106-115 on main) stubsframe.contentWindowwith a recorder as soon as the<iframe>is in the DOM. That is a commit, not a settled state: when React runs the passive effects a task later, which happens on a loaded runner, the mount ping lands in the recorder. On a fast run the effect has already run and pinged happy-dom's real (null) window, so nothing is recorded. happy-dom never firesloadon this frame (disableIframePageLoadingin website/vite.config.ts), so the mount ping is the only ping these tests can see.Repro (CI): run 42368210842, job 128392111188 (Frontend Tests (2), head 64a0e4c of #31793, which touches none of this code). The job summary has exactly 1 failed test (
Tests 1 failed | 15885 passed). Failing line:The same race applies to the other tests in the file, which assert
postedequals exactly[DATA_MESSAGE_TYPE].What changed (motivation → approach → change)
Symptom: a stray
mc-frame-pingin the recorder. Root cause: the test installs its stand-in window before the frame's mount effects have run. Fix: wait for a real signal that they have run.useFrameAliveRecovery(it still runs unchanged) and adds one effect, declared after the hook's own in the same component. That effect records the frame the hook armed on. Effects in one component run in declaration order, so once the frame is recorded, the mount ping has already been sent.mountedFrame(container)helper finds the iframe and then waits until it is recorded. All three places that found the frame now use it, including thebandUphelper.Alternatives considered: filtering
mc-frame-pingout ofpostedwould hide any unexpected ping and weaken the assertion. Waiting for a frameloaddoes not work, because happy-dom never fires one here.Backwards compatibility
Compatible: test-only change.
Removes nothing: only a test file changes.
Tests
website/src/pages/members/CrewDynamicDashboard.refetch.test.tsx: every test now installs its stand-in window only after the frame-alive mount ping has run. The assertions are unchanged.Proof: not provable -- test-only change
Manual verification
N/A — test-only change. Static gates run locally:
eslinton the file (clean) andtsc -p tsconfig.app.json(clean). Tests were not run locally because CI is the only test runner on this host.Related Issues
Fixes #32286
Sibling sweep
Swept: git grep -ln "defineProperty(frame, 'contentWindow'" -- website/src website/integration
Sibling: website/src/pages/members/CrewDynamicDashboard.refetch.test.tsx -- changed here
Sibling: website/src/pages/members/CrewDynamicDashboard.remint.test.tsx -- not affected -- the exact-count assertion runs on scripts:false pages, where the alive hook is not armed
Sibling: website/src/pages/members/CrewDynamicDashboard.spentUrl.test.tsx -- not affected -- it records pings on purpose and fires load itself
Sibling: website/src/pages/members/CrewDynamicDashboard.behind.test.tsx -- not affected -- it makes no assertion on posted messages
Pattern harvest
Rule candidate: agents-md
Pattern: stubbing an element's contentWindow right after it mounts races the component's passive-effect postMessage; wait on a signal that the effects ran first
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license.