Skip to content

Commit 46d996e

Browse files
huangyiireneclaude
andauthored
test(app-shell): the hooks panel's AI-draft discard case waits out the AI label instead of reading it once (#38887)
<!-- claude-projects-attribution: {"github_login":"huangyiirene"} --> _Requested by **Irene** · [project thread](https://claude.ai/code/project/chan_01TJXtQ1tVD26ecLDZxFS67x?thread=cmsg_01TJXtQ1tVD26ecLDZxFS67xNzHbYk18yx89SKfqeJ2c9k)_ Fixes #38877 ## What changes `ui/packages/app-shell/src/views/studio-design/ObjectHooksPanel.aiDraftNotice-36660.test.tsx`, case "discard with nothing unsaved asks nothing, drops that one hook's draft at its package, and the live hook is back": the last check, a synchronous `expect(screen.queryByText('Guard (AI)')).toBeNull()`, becomes `await waitFor(() => expect(screen.queryAllByText('Guard (AI)')).toHaveLength(0), { timeout: 8000 })`. This is the same wait the sibling case ("discard over an unsaved edit, confirmed") already uses. Test only: no product code changes, and no changeset. ## Why The 4-hourly full run on `6d163f41` ([run 46603840101](https://github.com/objectstack-ai/objectstack/actions/runs/46603840101), `Test UI (11/16)`) failed this case at line 170: `Found multiple elements with the text: Guard (AI)`. The two elements CI printed are a 12px `span` and the open hook's header `div`. **No commit in the card's range causes it.** - The test passes alone at `6d163f41` (3/3). - The whole `Test UI` shard 11/16 run locally at `6d163f41` (`vitest run --shard=11/16`) passes: 452 passed, 1 skipped, the same 453 files CI ran. - The test's import graph (209 modules, an esbuild metafile walk with bare imports external) does not contain `ResourceEditPage.tsx`, the only file #38860 changes, so the triage's first suspect is cleared. The only file the range `00f97b30..6d163f4` touches inside that graph is `useNavTargetLabel.ts` (#38856). It arrives through the inspector registry, and the hooks panel never renders it. `94d552cb` and `6d163f41` give this test the same tree, so a commit bisect has nothing to find. **The race.** After the discard, `discardAiDraft` clears the AI mark and bumps the list nonce. The list re-read then `setListed`s the published row, and that commit draws the list row as "Guard". The open hook is re-buffered by the install effect (`useEffect` on `[selected, hooks, refusedHooks]` in `objectHooksBuffer.ts`), which runs one commit later. `findAllByText('Guard')` resolves on the first commit. I logged the DOM at that point on three runs, and every run showed the same thing: ``` 'Guard' -> <span class="min-w-0 flex-1 truncate font-medium">Guard</span> 'Guard (AI)' -> <span class="min-w-0 flex-1 truncate text-[12px] font-medium">Guard (AI)</span> <div class="mt-1 truncate text-sm font-medium" title="Guard (AI)">Guard (AI)</div> notice present: false ``` These are exactly the two elements in the CI failure. The next line, `waitFor` on the notice, passes on its first check, so the case passed only when that wait's closing `setTimeout(0)` drain let React's scheduler (`setImmediate`) flush the effect first. On a loaded runner the timer can come first. **Forced.** I preloaded a module into the vitest workers (`NODE_OPTIONS=--import`) that delays `setImmediate` by 30 ms, so React's scheduled work lands after a `setTimeout(0)`, the order a loaded runner can give: | | forced | normal | |---|---|---| | before (main) | 1 failed, 6 passed: the same `Found multiple elements … Guard (AI)` at line 170 | 7 passed | | after (this PR) | 7 passed | 7 passed (3 runs) | The one-commit gap between the list and the buffer is a passing frame the user never acts in, so the product stays as it is. ## Verification - The file, normal: 7/7, three runs. - The file under the forced ordering: 7/7 (main: 1 failed, the CI error). - eslint on the file: exit 0. - Commit trailer check (pre-push): passed. Clause-②: no Metadata-protocol: none ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (not touched) - [x] 2. Every name I added uses the casing for its kind. (none added) - [x] 3. No formatter ran; `pnpm lint` passes. (eslint on the touched file) - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. (test only: publishes nothing) - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. (not touched) - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. --- _Generated by [Claude Code](https://claude.ai/code)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent b26bb22 commit 46d996e

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎ui/packages/app-shell/src/views/studio-design/ObjectHooksPanel.aiDraftNotice-36660.test.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ describe('ObjectHooksPanel — the AI assistant\'s pending draft of a hook (obje
167167
// The published row is what the list and the open hook hold now.
168168
expect(await screen.findAllByText('Guard', undefined, { timeout: 8000 })).not.toHaveLength(0);
169169
await waitFor(() => expect(screen.queryByTestId('studio-ai-draft-notice')).toBeNull());
170-
expect(screen.queryByText('Guard (AI)')).toBeNull();
170+
// objectstack#38877 — the list row turns "Guard" one commit before the open
171+
// hook is re-buffered by its install effect, so the AI label is waited out.
172+
await waitFor(() => expect(screen.queryAllByText('Guard (AI)')).toHaveLength(0), { timeout: 8000 });
171173
});
172174

173175
it('discard over an unsaved edit asks first; declined, the draft and the edit stay', async () => {

0 commit comments

Comments
 (0)