Repository navigation
Commit 6b11d13
test(console): record the route probes in a layout effect so a drawn page is already recorded (#38000)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6Jao7TkF6tARYTW3zLaaPzFK5G)_
Fixes #37996
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户无感:只改两份控制台路由测试,产品代码一行未动。
- 为什么做:这两份测试在慢的 CI 机器上偶发变红,挡住了与它们无关的 PR(如问 AI 的那张)。
- 出错会怎样:只影响测试,可随时撤回;改坏的话这两份测试会稳定变红,不会伤到用户。
- 要你做什么:无。
## What changes
Both files record the router's history through a private `LocationProbe`
that pushed in a passive `useEffect`. Each case waits for the routed DOM
(`findByTestId`, or the outside-`act` `drawn()` poll) and then reads the
history array. React may flush a passive effect after the DOM is
visible, so on a slow runner the read came one entry short: CI run
46013899997, `Test UI (2/16)`, `expected [ '/apps/policy' ] to deeply
equal [ '/apps/policy', …(1) ]` at the outside-`act` "a member with no
AI seat: the home is the next entry, not a hold that never ends" case.
Both probes now record in `useLayoutEffect`, which runs in the same
commit that writes the DOM. Once a routed page is drawn, its location is
already recorded. No assertion, wait or timeout changes; the diff is the
effect hook and a comment on each probe.
The race was in the probe, not only in the two cases the card names, so
the fix covers every case in both files that reads `seen` / `pathnames`
(31 of 46).
Files:
`ui/apps/console/src/components/StudioRoute.metadataArea-28561.test.tsx`,
`ui/packages/app-shell/src/console/__tests__/AppContent.aiChatEntryGate-37833.test.tsx`.
Test-only: neither file ships in a package's `files[]`
(`@object-ui/app-shell` is private and ships `dist`;
`@object-ui/console` ships `dist` and its plugin entry), so this PR
carries `skip-changeset`.
## Tests
<details><summary>Reproduction on origin/main dc45b1e (before the
fix)</summary>
- Baseline: both files, 46/46 passed.
- Each probe's push delayed 30 ms with `setTimeout` (a late
passive-effect flush): 31 failed / 15 passed of 46, including both cases
the card names, with CI's failure shape (`expected [ '/apps/policy' ] to
deeply equal [ '/apps/policy', …(1) ]`, and for the Studio case an array
one entry short of `[ '/studio/~all', … ]`). Mutation reverted, `git
diff HEAD` empty.
</details>
<details><summary>After the fix, head 556804f</summary>
- `pnpm --dir ui exec vitest run
apps/console/src/components/StudioRoute.metadataArea-28561.test.tsx
packages/app-shell/src/console/__tests__/AppContent.aiChatEntryGate-37833.test.tsx`:
46/46 passed, eight runs in a row (8/8).
</details>
<details><summary>Ablations (teeth kept), each through
scripts/ablation-replace.mjs, restored to the HEAD blob with git diff
HEAD empty</summary>
- S1, two hops: `StudioAllLegAddress` first sends any `~all` URL to
`/studio/~all/hop`, then to its target. Studio file: 5 failed / 28
passed. The three "lands on Setup's environment directory, in one hop,
never on a pillar" rows fail at line 188 (`expect(seen).toEqual([url,
'/apps/setup/component/security/access-directory'])`), the two "without
Setup's entry capability" rows at line 200.
- S2, lands on a pillar: `StudioAllLegAddress` always sends a Setup
holder to the area's root. The three Setup-directory rows fail at line
185 (`findByTestId('setup-directory')`; the builder is drawn instead).
- G1, changed next entry: `resolveLandingRoute` skips the first entry
the member is shown. Gate file: 6 failed / 7 passed. The card's case ("a
member with no AI seat: the home is the next entry, not a hold that
never ends") fails at line 418
(`expect(pathnames).toEqual(['/apps/policy',
'/apps/policy/crm_case'])`); the others at lines 300, 313, 324, 357 and
461.
</details>
## Acceptance notes
- Same probe shape elsewhere, named per the card and not edited here
(each is a private function in its own file, none shares a helper with
these two). A census of `useLocation` probes that push in a passive
`useEffect` found:
`ui/packages/app-shell/src/views/ObjectView.listUrlState-11860.test.tsx`,
`ui/packages/app-shell/src/views/ObjectView.ufViewSwitch-11992.test.tsx`,
`ui/packages/app-shell/src/views/ObjectView.listPageInUrl-30850.test.tsx`,
`ui/packages/app-shell/src/layout/__tests__/usePhoneNavDrawerHistory-29131.test.tsx`,
`ui/packages/app-shell/src/console/ai/__tests__/AiChatPage.buildClosedRoutes-36969.test.tsx`,
`ui/apps/console/src/pages/system/ApprovalsInboxPage.lateBulkReload-37548.test.tsx`,
`ui/apps/console/src/pages/system/ApprovalsInboxPage.lateBulkToast-37328.test.tsx`.
The census matched a push within a short `useEffect` body, so a probe
spelled across a longer body may be missing from it. Whether each one
races depends on whether it reads the array right after a DOM wait; not
measured here. carrier: seat repo:objectstack#3.
## Verification
Run the two files with the command under Tests; expect 46 passed. To see
the race the assertions are exposed to, delay either probe's push with
`setTimeout(…, 30)`, which stands in for a late passive-effect flush:
the history assertions go red.
Co-authored-by: Claude <noreply@anthropic.com>1 parent 34f7078 commit 6b11d13
2 files changed
Lines changed: 14 additions & 3 deletions
File tree
- ui
- apps/console/src/components
- packages/app-shell/src/console/__tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
102 | 108 | | |
103 | 109 | | |
104 | 110 | | |
105 | | - | |
| 111 | + | |
106 | 112 | | |
107 | 113 | | |
108 | 114 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
145 | 150 | | |
146 | 151 | | |
147 | 152 | | |
148 | | - | |
| 153 | + | |
149 | 154 | | |
150 | 155 | | |
151 | 156 | | |
| |||
0 commit comments