Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
test: settle mount-effect promises inside act across 12 client test files
[._.]/ Adam Eivyc11acc252d0b
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex a31c1728f1..b99f199cb2 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -57,6 +57,8 @@## Fixed+- **The client test suite no longer floods CI logs with ~100 React `act(...)` warnings.** Twelve test files rendered components whose mount effects fetch data through pre-resolved mock promises and never settled them, so the `.then(setState)` microtasks landed outside `act` — invisible locally (vitest hides console output from passing tests) but printed in full by the CI reporter, burying real failures, and marking exactly the unsettled-async pattern behind our known CI test flakes. Each affected file now drains those updates inside act via a small settle-after-render helper (`await act(async () => {})`), with no assertion changes; tests that deliberately assert an in-flight pending state settle at the end instead. Promoting this to an enforced zero-warning gate in `src/test/setup.js` is tracked in #2406.+- **CoS tasks with Review Loop turned off now explicitly disable saved external-review defaults when opening a PR.** Their completion prompt passes `--review-with none`, so an inherited Copilot (or other reviewer) default cannot launch a review that was not requested.- **[issue-2387] Theme initialization and switching now survive unavailable localStorage.** The `useTheme` and `useCitySettings` hooks read/wrote `localStorage` directly (persisted theme, and the CyberCity settings that render on the same theme path), so a browser where storage access throws (Safari private mode, blocked cookies, disabled storage) or is absent would throw inside a `useState` initializer and crash the initial render, and a failing `setItem` could break theme switching. Both hooks now route every read/write/remove through a shared, guarded `safeReadStorage`/`safeWriteStorage`/`safeRemoveStorage` helper (`client/src/lib/safeStorage.js`) that swallows access failures, and corrupt stored JSON falls back to defaults instead of throwing — so init always resolves to a valid default and in-memory switching keeps working when persistence fails. `setTheme` also applies the in-memory theme (DOM + state) before any persistence/side-effect work so a later failure can never leave the UI on the stale theme. Focused hook tests cover read-throws-on-init, corrupt/invalid stored value, and write-throws-on-switch for both hooks.diff --git a/client/src/components/apps/tabs/AutomationTab.test.jsx b/client/src/components/apps/tabs/AutomationTab.test.jsxindex e8fcedb6ce..2889fb8c7a 100644--- a/client/src/components/apps/tabs/AutomationTab.test.jsx+++ b/client/src/components/apps/tabs/AutomationTab.test.jsx@@ -1,5 +1,5 @@import { describe, it, expect, vi, beforeEach } from 'vitest';-import { render, screen, fireEvent, waitFor, within } from '@testing-library/react';+import { render, screen, fireEvent, waitFor, within, act } from '@testing-library/react';// ── Mock router — capture navigate calls, no real Router needed ────────────────const mockNavigate = vi.hoisted(() => vi.fn());@@ -57,6 +57,9 @@ const renderTab = async (overrides = {}) => {api.updateAppTaskTypeOverride.mockResolvedValue({ success: true });render(<AutomationTab appId="app-1" appName="MyApp" />);await screen.findByText('layered-intelligence');+ // Drain the remaining mount fetches (CustomTasksSection's getCosJobs etc.)+ // inside act — the schedule findByText above can win before they land.+ await act(async () => {});};// Find the task-row card that contains the given task-type label.diff --git a/client/src/components/creative-director/PlanTab.test.jsx b/client/src/components/creative-director/PlanTab.test.jsxindex 8d8cf7ac61..60cbdd5060 100644--- a/client/src/components/creative-director/PlanTab.test.jsx+++ b/client/src/components/creative-director/PlanTab.test.jsx@@ -2,7 +2,7 @@* Plan-board state transitions + blocked-step triage (CDO Phase 4, #2186).*/import { describe, it, expect, vi, beforeEach } from 'vitest';-import { render, screen, waitFor, fireEvent } from '@testing-library/react';+import { render, screen, waitFor, fireEvent, act } from '@testing-library/react';import { MemoryRouter } from 'react-router-dom';vi.mock('../../services/apiCreativeDirector.js', () => ({@@ -53,16 +53,21 @@ const directiveProject = (overrides = {}) => ({const renderTab = (project, onProjectUpdate = () => {}) =>render(<MemoryRouter><PlanTab project={project} onProjectUpdate={onProjectUpdate} /></MemoryRouter>);+// Drain the mount fetches (catalog/universes/series) inside act so their state+// updates can't land outside it after a test body that never awaits them.+const settle = () => act(async () => {});+beforeEach(() => {vi.clearAllMocks();getCreativeToolCatalog.mockResolvedValue(CATALOG);});describe('legacy project (no directive)', () => {- it('offers to add a directive', () => {+ it('offers to add a directive', async () => {renderTab({ id: 'cd-1', name: 'X', status: 'draft', directive: null, plan: null, runs: [] });expect(screen.getByText(/No production directive/i)).toBeTruthy();expect(screen.getByRole('button', { name: /Add a directive/i })).toBeTruthy();+ await settle();});});@@ -87,12 +92,13 @@ describe('plan board', () => {expect(link.getAttribute('href')).toBe('/pipeline/series/s9');});- it('shows the directive goal + deliverables + budget cap', () => {+ it('shows the directive goal + deliverables + budget cap', async () => {renderTab(directiveProject());expect(screen.getByText('Produce a noir series')).toBeTruthy();expect(screen.getByText('story')).toBeTruthy();expect(screen.getByText('covers')).toBeTruthy();expect(screen.getByText(/Budget cap: 50/)).toBeTruthy();+ await settle();});it('renders a dry-run banner when creative autonomy is dry-run', async () => {diff --git a/client/src/components/meatspace/post/MorseTrainer.test.jsx b/client/src/components/meatspace/post/MorseTrainer.test.jsxindex e85ceae7a7..9ad3490640 100644--- a/client/src/components/meatspace/post/MorseTrainer.test.jsx+++ b/client/src/components/meatspace/post/MorseTrainer.test.jsx@@ -1,5 +1,5 @@import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';-import { render, screen, fireEvent, waitFor } from '@testing-library/react';+import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';import { MemoryRouter, Routes, Route, useLocation } from 'react-router-dom';// Stub the training-log API so mount-time fetches (refreshTrainingStats) and@@ -61,8 +61,8 @@ function LocationProbe() {return <div data-testid="loc">{loc.pathname}{loc.search}</div>;}-function renderMorse(props = {}, { route = '/post/morse' } = {}) {- return render(+async function renderMorse(props = {}, { route = '/post/morse' } = {}) {+ const result = render(<MemoryRouter initialEntries={[route]}><Routes><Route@@ -72,6 +72,11 @@ function renderMorse(props = {}, { route = '/post/morse' } = {}) {</Routes></MemoryRouter>,);+ // Settle the mount-effect fetches (training stats + morse progress) inside+ // act — the mocks are pre-resolved promises, so one microtask flush drains+ // every pending .then before the test's own interactions begin.+ await act(async () => {});+ return result;}describe('MorseTrainer deep-linking', () => {@@ -85,9 +90,9 @@ describe('MorseTrainer deep-linking', () => {expect(MODES.map((m) => m.id)).toEqual(MORSE_MODE_IDS);});- it('shows the mode grid and routes on pick (mode=null)', () => {+ it('shows the mode grid and routes on pick (mode=null)', async () => {const onSelectMode = vi.fn();- renderMorse({ mode: null, onSelectMode });+ await renderMorse({ mode: null, onSelectMode });// All three mode cards render as pickable entries.fireEvent.click(screen.getByText('Copy'));expect(onSelectMode).toHaveBeenCalledWith('copy');@@ -97,27 +102,27 @@ describe('MorseTrainer deep-linking', () => {expect(onSelectMode).toHaveBeenCalledWith('send');});- it('defaults the reference tab to tree with no ?ref param', () => {- renderMorse({ mode: null, onSelectMode: vi.fn() });+ it('defaults the reference tab to tree with no ?ref param', async () => {+ await renderMorse({ mode: null, onSelectMode: vi.fn() });// Tree view legend is unique to the tree reference.expect(screen.getByText('start')).toBeInTheDocument();});- it('reads the reference tab from the ?ref search param', () => {- renderMorse({ mode: null, onSelectMode: vi.fn() }, { route: '/post/morse?ref=length' });+ it('reads the reference tab from the ?ref search param', async () => {+ await renderMorse({ mode: null, onSelectMode: vi.fn() }, { route: '/post/morse?ref=length' });// Length view groups by symbol count.expect(screen.getByText('1 symbol')).toBeInTheDocument();});- it('encodes the selected reference tab in the URL', () => {- renderMorse({ mode: null, onSelectMode: vi.fn() });+ it('encodes the selected reference tab in the URL', async () => {+ await renderMorse({ mode: null, onSelectMode: vi.fn() });// Exact name — a loose /List/ also matches the "Listen to Morse" mode card.fireEvent.click(screen.getByRole('button', { name: 'List' }));expect(screen.getByTestId('loc').textContent).toBe('/post/morse?ref=list');});- it('drops the ?ref param when returning to the default tree tab', () => {- renderMorse({ mode: null, onSelectMode: vi.fn() }, { route: '/post/morse?ref=list' });+ it('drops the ?ref param when returning to the default tree tab', async () => {+ await renderMorse({ mode: null, onSelectMode: vi.fn() }, { route: '/post/morse?ref=list' });fireEvent.click(screen.getByRole('button', { name: 'Tree' }));expect(screen.getByTestId('loc').textContent).toBe('/post/morse');});@@ -129,16 +134,16 @@ describe('MorseTrainer head-copy mode', () => {getTrainingStats.mockClear();});- it('hides the reference cheat sheet and explains the audio-only rules', () => {- renderMorse({ mode: 'head-copy', onSelectMode: vi.fn(), onExitMode: vi.fn() });+ it('hides the reference cheat sheet and explains the audio-only rules', async () => {+ await renderMorse({ mode: 'head-copy', onSelectMode: vi.fn(), onExitMode: vi.fn() });// The Tree/Length/List reference tabs only render via ReferenceWidget,// which head-copy mode suppresses entirely.expect(screen.queryByRole('button', { name: 'Tree' })).not.toBeInTheDocument();expect(screen.getByText(/No code hints on the results screen/)).toBeInTheDocument();});- it('keeps the reference widget visible in plain copy mode (unchanged behavior)', () => {- renderMorse({ mode: 'copy', onSelectMode: vi.fn(), onExitMode: vi.fn() });+ it('keeps the reference widget visible in plain copy mode (unchanged behavior)', async () => {+ await renderMorse({ mode: 'copy', onSelectMode: vi.fn(), onExitMode: vi.fn() });expect(screen.getByRole('button', { name: 'Tree' })).toBeInTheDocument();});});@@ -150,7 +155,7 @@ describe('MorseTrainer training log integration', () => {});it('fetches 30-day training stats on mount and renders the streak summary', async () => {- const { container } = renderMorse({ mode: null, onSelectMode: vi.fn() });+ const { container } = await renderMorse({ mode: null, onSelectMode: vi.fn() });expect(getTrainingStats).toHaveBeenCalledWith(30);await waitFor(() => {expect(container.textContent).toContain('Training streak: 3d');@@ -171,7 +176,7 @@ describe('MorseTrainer training log integration', () => {});it('logs a completed Head Copy round to the training log with the right payload shape', async () => {- renderMorse({ mode: 'head-copy', onSelectMode: vi.fn(), onExitMode: vi.fn() });+ await renderMorse({ mode: 'head-copy', onSelectMode: vi.fn(), onExitMode: vi.fn() });fireEvent.click(await screen.findByRole('button', { name: /Start Round/i }));@@ -199,7 +204,7 @@ describe('MorseTrainer training log integration', () => {it('submits the completed round to the server with per-character items', async () => {submitMorseRound.mockClear();- renderMorse({ mode: 'head-copy', onSelectMode: vi.fn(), onExitMode: vi.fn() });+ await renderMorse({ mode: 'head-copy', onSelectMode: vi.fn(), onExitMode: vi.fn() });fireEvent.click(await screen.findByRole('button', { name: /Start Round/i }));for (let i = 0; i < 10; i++) {@@ -272,7 +277,7 @@ describe('MorseTrainer server Koch-level hydration', () => {});it('fetches server progress on mount', async () => {- renderMorse({ mode: null, onSelectMode: vi.fn() });+ await renderMorse({ mode: null, onSelectMode: vi.fn() });await waitFor(() => expect(getMorseProgress).toHaveBeenCalled());});@@ -280,7 +285,7 @@ describe('MorseTrainer server Koch-level hydration', () => {// Cache a level beyond the base (2) and a server with kochLevelSet:false.window.localStorage.setItem('portos-post-morse-prefs', JSON.stringify({ kochLevel: 9 }));updateMorseLevel.mockResolvedValueOnce({ kochLevel: 9, kochLevelSet: true, adopted: true, settings: null });- renderMorse({ mode: null, onSelectMode: vi.fn() });+ await renderMorse({ mode: null, onSelectMode: vi.fn() });await waitFor(() => {expect(updateMorseLevel).toHaveBeenCalledWith(expect.objectContaining({ kochLevel: 9, adopt: true }),@@ -291,7 +296,7 @@ describe('MorseTrainer server Koch-level hydration', () => {it('does not adopt when the cached level is only the base default', async () => {window.localStorage.setItem('portos-post-morse-prefs', JSON.stringify({ kochLevel: 2 }));- renderMorse({ mode: null, onSelectMode: vi.fn() });+ await renderMorse({ mode: null, onSelectMode: vi.fn() });await waitFor(() => expect(getMorseProgress).toHaveBeenCalled());expect(updateMorseLevel).not.toHaveBeenCalled();});@@ -335,7 +340,7 @@ describe('MorseTrainer iOS audio unlock', () => {afterEach(() => { delete window.AudioContext; });it('awaits resume() before scheduling any tone (no oscillator while suspended)', async () => {- renderMorse({ mode: 'copy', onSelectMode: vi.fn(), onExitMode: vi.fn() });+ await renderMorse({ mode: 'copy', onSelectMode: vi.fn(), onExitMode: vi.fn() });fireEvent.click(await screen.findByRole('button', { name: /Start Round/i }));// The round input only renders once playMorse has finished, so by here the// first tone has been scheduled and played.@@ -349,7 +354,7 @@ describe('MorseTrainer iOS audio unlock', () => {// window must be ignored — otherwise two playPrompt runs schedule two Morse// prompts over each other. playMorse uses exactly one oscillator per prompt, so// two overlapping prompts would create two oscillators for one round start.- renderMorse({ mode: 'copy', onSelectMode: vi.fn(), onExitMode: vi.fn() });+ await renderMorse({ mode: 'copy', onSelectMode: vi.fn(), onExitMode: vi.fn() });const startBtn = await screen.findByRole('button', { name: /Start Round/i });// Two synchronous taps land inside the unlock window (resume() resolves on a// later macrotask, so neither startRound has reached createOscillator yet).@@ -361,8 +366,8 @@ describe('MorseTrainer iOS audio unlock', () => {});describe('MorseTrainer Tree reference view', () => {- it('renders a labeled, reachable node for all 41 characters', () => {- const { container } = renderMorse({ mode: null, onSelectMode: vi.fn() });+ it('renders a labeled, reachable node for all 41 characters', async () => {+ const { container } = await renderMorse({ mode: null, onSelectMode: vi.fn() });// Every node (including the root) carries its own morse code (or 'start'// for the root) as its `title` — the most reliable way to pick each tree// node out individually, since letter text alone can collide with other@@ -376,8 +381,8 @@ describe('MorseTrainer Tree reference view', () => {}});- it('centers the start node roughly under "start", not pinned to one edge', () => {- const { container } = renderMorse({ mode: null, onSelectMode: vi.fn() });+ it('centers the start node roughly under "start", not pinned to one edge', async () => {+ const { container } = await renderMorse({ mode: null, onSelectMode: vi.fn() });const root = container.querySelector('[title="start"]');expect(root).toBeTruthy();expect(root.textContent).toBe('·');diff --git a/client/src/components/meatspace/post/PostDrillConfig.test.jsx b/client/src/components/meatspace/post/PostDrillConfig.test.jsxindex cc1d5e8c4b..f2ac42c05f 100644--- a/client/src/components/meatspace/post/PostDrillConfig.test.jsx+++ b/client/src/components/meatspace/post/PostDrillConfig.test.jsx@@ -1,5 +1,5 @@import { describe, it, expect, vi, beforeEach } from 'vitest';-import { render, screen, fireEvent, waitFor } from '@testing-library/react';+import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';vi.mock('../../../services/api', () => ({updatePostConfig: vi.fn(),@@ -71,23 +71,33 @@ beforeEach(() => {});});+// Render + settle the mount-effect fetches (providers, adaptive preview,+// multiplication + cognitive progress) inside act — the mocks are pre-resolved+// promises, so one microtask flush drains every pending .then before the+// test's own interactions begin.+async function renderConfig(ui) {+ const result = render(ui);+ await act(async () => {});+ return result;+}+describe('PostDrillConfig', () => {- it('renders a card for every one of the 14 LLM drill types', () => {- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ it('renders a card for every one of the 14 LLM drill types', async () => {+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);for (const type of ALL_LLM_TYPES) {expect(screen.getByText(DRILL_LABELS[type])).toBeTruthy();}});- it('groups LLM drills under Wordplay / Verbal Agility / Imagination headers', () => {- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ it('groups LLM drills under Wordplay / Verbal Agility / Imagination headers', async () => {+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);expect(screen.getByText('Wordplay')).toBeTruthy();expect(screen.getByText('Verbal Agility')).toBeTruthy();expect(screen.getByText('Imagination')).toBeTruthy();});it('persists all 14 LLM drill types on save, with the 9 newly-exposed drills defaulting off', async () => {- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);fireEvent.click(screen.getByText('Save'));await waitFor(() => expect(updatePostConfig).toHaveBeenCalled());@@ -106,7 +116,7 @@ describe('PostDrillConfig', () => {});it('saves goals and sessionModules (issue #2100)', async () => {- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);// Set a streak-target goal, then include AI drills in composed sessions.fireEvent.change(screen.getByLabelText(/Streak/i), { target: { value: '10' } });fireEvent.click(screen.getByRole('checkbox', { name: 'Wit & Memory (AI)' }));@@ -119,7 +129,7 @@ describe('PostDrillConfig', () => {});it('clears a previously-set goal to an empty goals patch on save', async () => {- render(<PostDrillConfig config={{ ...config, goals: { streakTarget: 5 } }} onSaved={vi.fn()} onBack={vi.fn()} />);+ await renderConfig(<PostDrillConfig config={{ ...config, goals: { streakTarget: 5 } }} onSaved={vi.fn()} onBack={vi.fn()} />);fireEvent.change(screen.getByLabelText(/Streak/i), { target: { value: '' } });fireEvent.click(screen.getByText('Save'));await waitFor(() => expect(updatePostConfig).toHaveBeenCalled());@@ -127,7 +137,7 @@ describe('PostDrillConfig', () => {});it('enabling a newly-exposed drill persists it as enabled', async () => {- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);// Toggle the "What If?" card (a previously-inaccessible imagination drill) on.fireEvent.click(screen.getByRole('switch', { name: 'What If?' }));fireEvent.click(screen.getByText('Save'));@@ -150,22 +160,22 @@ describe('PostDrillConfig', () => {drillTypes: { ...config.llmDrills.drillTypes, 'what-if': { count: 3 } },},};- render(<PostDrillConfig config={withPresentNewType} onSaved={vi.fn()} onBack={vi.fn()} />);+ await renderConfig(<PostDrillConfig config={withPresentNewType} onSaved={vi.fn()} onBack={vi.fn()} />);expect(screen.getByRole('switch', { name: 'What If?' }).getAttribute('aria-checked')).toBe('true');fireEvent.click(screen.getByText('Save'));await waitFor(() => expect(updatePostConfig).toHaveBeenCalled());expect(updatePostConfig.mock.calls[0][0].llmDrills.drillTypes['what-if'].enabled).toBe(true);});- it('exposes toggles as accessible switches reflecting on/off state', () => {- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ it('exposes toggles as accessible switches reflecting on/off state', async () => {+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);// Legacy enabled drill → switch checked; newly-exposed drill → unchecked.expect(screen.getByRole('switch', { name: 'Pun & Wordplay' }).getAttribute('aria-checked')).toBe('true');expect(screen.getByRole('switch', { name: 'Reframe' }).getAttribute('aria-checked')).toBe('false');});it('defaults the Adaptive difficulty toggle to off and persists it on save', async () => {- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);const toggle = screen.getByRole('switch', { name: 'Adaptive difficulty' });expect(toggle.getAttribute('aria-checked')).toBe('false');fireEvent.click(screen.getByText('Save'));@@ -188,7 +198,7 @@ describe('PostDrillConfig', () => {mentalMath: { drillTypes: { multiplication: { enabled: true, count: 10, progressive: false } } },adaptive: { enabled: true },};- render(<PostDrillConfig config={withAdaptive} onSaved={vi.fn()} onBack={vi.fn()} />);+ await renderConfig(<PostDrillConfig config={withAdaptive} onSaved={vi.fn()} onBack={vi.fn()} />);expect(screen.getByRole('switch', { name: 'Adaptive difficulty' }).getAttribute('aria-checked')).toBe('true');await waitFor(() => expect(getPostAdaptivePreview).toHaveBeenCalled());// The enabled multiplication card surfaces the effective (adapted) difficulty.@@ -209,14 +219,14 @@ describe('PostDrillConfig', () => {mentalMath: { drillTypes: { ...config.mentalMath.drillTypes, estimation: { enabled: true, tolerancePct: 3 } } },adaptive: { enabled: true },};- render(<PostDrillConfig config={withAdaptive} onSaved={vi.fn()} onBack={vi.fn()} />);+ await renderConfig(<PostDrillConfig config={withAdaptive} onSaved={vi.fn()} onBack={vi.fn()} />);await waitFor(() => expect(getPostAdaptivePreview).toHaveBeenCalled());await waitFor(() => expect(screen.getByText(/hardest tolerance % 3/)).toBeTruthy());expect(screen.queryByText(/at max tolerance/)).toBeNull();});it('multiplication defaults to Progressive difficulty on, hiding Max Digits and showing the ladder', async () => {- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);const toggle = screen.getByRole('switch', { name: 'Progressive difficulty — Multiplication' });expect(toggle.getAttribute('aria-checked')).toBe('true');// Max Digits is ignored while progressive is on, so its field is hidden.@@ -227,7 +237,7 @@ describe('PostDrillConfig', () => {});it('toggling Progressive off reveals Max Digits and persists progressive=false', async () => {- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);fireEvent.click(screen.getByRole('switch', { name: 'Progressive difficulty — Multiplication' }));expect(screen.getByText('Max Digits')).toBeTruthy();fireEvent.click(screen.getByText('Save'));@@ -236,7 +246,7 @@ describe('PostDrillConfig', () => {});it('cognitive drills default to Progressive on — n-back hides its knobs and shows its rung', async () => {- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);const toggle = screen.getByRole('switch', { name: 'Progressive difficulty — N-Back' });expect(toggle.getAttribute('aria-checked')).toBe('true');// Progressive on → the ladder-managed knobs (incl. Stimulus) are hidden.@@ -249,7 +259,7 @@ describe('PostDrillConfig', () => {});it('turning n-back Progressive off exposes the Stimulus (ms) knob and persists progressive=false', async () => {- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);fireEvent.click(screen.getByRole('switch', { name: 'Progressive difficulty — N-Back' }));expect(screen.getByText('Stimulus (ms)')).toBeTruthy();fireEvent.click(screen.getByText('Save'));@@ -258,7 +268,7 @@ describe('PostDrillConfig', () => {});it('toggling Adaptive on persists enabled=true', async () => {- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);fireEvent.click(screen.getByRole('switch', { name: 'Adaptive difficulty' }));fireEvent.click(screen.getByText('Save'));await waitFor(() => expect(updatePostConfig).toHaveBeenCalled());@@ -266,7 +276,7 @@ describe('PostDrillConfig', () => {});it('defaults the Daily Reminder toggle to off, hides the time picker, and persists off on save', async () => {- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);const toggle = screen.getByRole('switch', { name: 'Daily reminder' });expect(toggle.getAttribute('aria-checked')).toBe('false');expect(screen.queryByLabelText('Remind me at')).toBeNull();@@ -276,7 +286,7 @@ describe('PostDrillConfig', () => {});it('enabling the Daily Reminder reveals the time picker and persists the chosen time', async () => {- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);fireEvent.click(screen.getByRole('switch', { name: 'Daily reminder' }));const timeInput = screen.getByLabelText('Remind me at');fireEvent.change(timeInput, { target: { value: '18:30' } });@@ -285,16 +295,16 @@ describe('PostDrillConfig', () => {expect(updatePostConfig.mock.calls[0][0].reminder).toEqual({ enabled: true, time: '18:30' });});- it('reflects a saved reminder.enabled=true with its stored time', () => {+ it('reflects a saved reminder.enabled=true with its stored time', async () => {const withReminder = { ...config, reminder: { enabled: true, time: '20:15' } };- render(<PostDrillConfig config={withReminder} onSaved={vi.fn()} onBack={vi.fn()} />);+ await renderConfig(<PostDrillConfig config={withReminder} onSaved={vi.fn()} onBack={vi.fn()} />);expect(screen.getByRole('switch', { name: 'Daily reminder' }).getAttribute('aria-checked')).toBe('true');expect(screen.getByLabelText('Remind me at').value).toBe('20:15');});describe('presets', () => {it('"Balanced daily" enables 2 math + 2 cognitive drills, turns cognitive on, and turns LLM off', async () => {- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);fireEvent.click(screen.getByText('Balanced daily'));expect(screen.getByRole('switch', { name: 'Multiplication' }).getAttribute('aria-checked')).toBe('true');expect(screen.getByRole('switch', { name: 'Estimation' }).getAttribute('aria-checked')).toBe('true');@@ -320,8 +330,8 @@ describe('PostDrillConfig', () => {expect(payload.llmDrills.enabled).toBe(false);});- it('"Math focus" enables every math drill and turns cognitive + LLM off', () => {- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ it('"Math focus" enables every math drill and turns cognitive + LLM off', async () => {+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);fireEvent.click(screen.getByText('Math focus'));for (const label of ['Doubling Chain', 'Serial Subtraction', 'Multiplication', 'Powers', 'Estimation']) {expect(screen.getByRole('switch', { name: label }).getAttribute('aria-checked')).toBe('true');@@ -330,8 +340,8 @@ describe('PostDrillConfig', () => {expect(screen.getByRole('switch', { name: 'Wit & Memory (LLM) drills' }).getAttribute('aria-checked')).toBe('false');});- it('"Cognitive focus" disables all math drills and enables every cognitive drill', () => {- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ it('"Cognitive focus" disables all math drills and enables every cognitive drill', async () => {+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);fireEvent.click(screen.getByText('Cognitive focus'));expect(screen.getByRole('switch', { name: 'Multiplication' }).getAttribute('aria-checked')).toBe('false');expect(screen.getByRole('switch', { name: 'Cognitive drills' }).getAttribute('aria-checked')).toBe('true');@@ -341,8 +351,8 @@ describe('PostDrillConfig', () => {expect(screen.getByRole('switch', { name: 'Wit & Memory (LLM) drills' }).getAttribute('aria-checked')).toBe('false');});- it('"Everything (local-only)" enables every math + cognitive drill but never LLM', () => {- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ it('"Everything (local-only)" enables every math + cognitive drill but never LLM', async () => {+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);fireEvent.click(screen.getByText('Everything (local-only)'));expect(screen.getByRole('switch', { name: 'Powers' }).getAttribute('aria-checked')).toBe('true');expect(screen.getByRole('switch', { name: 'Mental Rotation' }).getAttribute('aria-checked')).toBe('true');@@ -352,8 +362,8 @@ describe('PostDrillConfig', () => {});describe('per-group enable/disable-all', () => {- it('Mental Math "Enable all" / "Disable all" toggle every math drill', () => {- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ it('Mental Math "Enable all" / "Disable all" toggle every math drill', async () => {+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);fireEvent.click(screen.getByLabelText('Enable all Mental Math drills'));for (const label of ['Doubling Chain', 'Serial Subtraction', 'Multiplication', 'Powers', 'Estimation']) {expect(screen.getByRole('switch', { name: label }).getAttribute('aria-checked')).toBe('true');@@ -364,8 +374,8 @@ describe('PostDrillConfig', () => {}});- it('Cognitive "Enable all" / "Disable all" toggle every cognitive drill', () => {- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ it('Cognitive "Enable all" / "Disable all" toggle every cognitive drill', async () => {+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);fireEvent.click(screen.getByLabelText('Enable all Cognitive drills'));expect(screen.getByRole('switch', { name: 'Digit Span' }).getAttribute('aria-checked')).toBe('true');fireEvent.click(screen.getByLabelText('Disable all Cognitive drills'));@@ -376,7 +386,7 @@ describe('PostDrillConfig', () => {// Regression: bulk-enabling drills in a collapsed/off domain used to// flip only the hidden per-drill flags — Save would persist// cognitive.enabled=false and the launcher would never run them.- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);fireEvent.click(screen.getByText('Math focus')); // sets cognitiveEnabled=falseexpect(screen.getByRole('switch', { name: 'Cognitive drills' }).getAttribute('aria-checked')).toBe('false');fireEvent.click(screen.getByLabelText('Enable all Cognitive drills'));@@ -389,8 +399,8 @@ describe('PostDrillConfig', () => {expect(payload.cognitive.drillTypes['digit-span'].enabled).toBe(true);});- it('Cognitive "Disable all" leaves the domain toggle alone', () => {- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ it('Cognitive "Disable all" leaves the domain toggle alone', async () => {+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);expect(screen.getByRole('switch', { name: 'Cognitive drills' }).getAttribute('aria-checked')).toBe('true');fireEvent.click(screen.getByLabelText('Disable all Cognitive drills'));expect(screen.getByRole('switch', { name: 'Cognitive drills' }).getAttribute('aria-checked')).toBe('true');@@ -398,15 +408,15 @@ describe('PostDrillConfig', () => {it('LLM "Enable all" is blocked without a chosen provider — no toggles flip, an error toast fires', async () => {const toastModule = await import('../../ui/Toast');- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);fireEvent.click(screen.getByLabelText('Enable all LLM drills'));// Untouched drills stay at their config-seeded (opt-in-disabled) state.expect(screen.getByRole('switch', { name: 'Reframe' }).getAttribute('aria-checked')).toBe('false');expect(toastModule.default.error).toHaveBeenCalled();});- it('a blocked LLM "Enable all" reveals the collapsed LLM section so the provider picker is visible', () => {- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ it('a blocked LLM "Enable all" reveals the collapsed LLM section so the provider picker is visible', async () => {+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);// Every preset collapses the LLM section; the bulk button stays visible.fireEvent.click(screen.getByText('Balanced daily'));expect(screen.queryByText('AI Provider')).toBeNull();@@ -421,7 +431,7 @@ describe('PostDrillConfig', () => {getProviders.mockResolvedValue({providers: [{ id: 'prov-1', name: 'Test Provider', type: 'api', enabled: true, models: [] }],});- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);await waitFor(() => expect(getProviders).toHaveBeenCalled());const providerSelect = screen.getByLabelText('Provider');await waitFor(() => expect(providerSelect.querySelectorAll('option')).toHaveLength(2));@@ -438,7 +448,7 @@ describe('PostDrillConfig', () => {getProviders.mockResolvedValue({providers: [{ id: 'prov-1', name: 'Test Provider', type: 'api', enabled: true, models: [] }],});- render(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);await waitFor(() => expect(getProviders).toHaveBeenCalled());const providerSelect = screen.getByLabelText('Provider');await waitFor(() => expect(providerSelect.querySelectorAll('option')).toHaveLength(2));diff --git a/client/src/components/meatspace/tabs/PostTab.test.jsx b/client/src/components/meatspace/tabs/PostTab.test.jsxindex ee91611b0a..1ad65a974a 100644--- a/client/src/components/meatspace/tabs/PostTab.test.jsx+++ b/client/src/components/meatspace/tabs/PostTab.test.jsx@@ -1,8 +1,13 @@import { describe, it, expect, vi } from 'vitest';-import { render, screen, fireEvent } from '@testing-library/react';+import { render, screen, fireEvent, act } from '@testing-library/react';import { MemoryRouter, Routes, Route, useLocation } from 'react-router-dom';import PostTab from './PostTab';+// Settle the mount-effect fetches (config/sessions/stats/morse progress) inside+// act so their state updates can't land outside it mid-test — the mocks are all+// pre-resolved promises, so one microtask flush drains every pending .then.+const settle = () => act(async () => {});+// PostTab pulls config/sessions/stats on mount and drives a session hook; stub// both so the component renders in isolation. The Morse tab doesn't depend on// any of this data — it's the pure routing surface under test here.@@ -46,7 +51,7 @@ describe('PostTab morse deep-linking', () => {// A wildcard route keeps the probe mounted after navigation moves the URL to a// different /post/morse* path (PostTab's tab/subtab arrive as props here, so the// fixed element re-renders while LocationProbe reports the new location).- it('preserves the ?ref reference tab when entering a mode from the grid', () => {+ it('preserves the ?ref reference tab when entering a mode from the grid', async () => {render(<MemoryRouter initialEntries={['/post/morse?ref=list']}><Routes>@@ -54,12 +59,13 @@ describe('PostTab morse deep-linking', () => {</Routes></MemoryRouter>,);+ await settle();// Pick the Send mode from the grid — the ?ref=list selection must survive.fireEvent.click(screen.getByText('Send'));expect(screen.getByTestId('loc').textContent).toBe('/post/morse/send?ref=list');});- it('preserves the ?ref reference tab when exiting a mode back to the grid', () => {+ it('preserves the ?ref reference tab when exiting a mode back to the grid', async () => {render(<MemoryRouter initialEntries={['/post/morse/send?ref=length']}><Routes>@@ -67,10 +73,15 @@ describe('PostTab morse deep-linking', () => {</Routes></MemoryRouter>,);+ await settle();// Check surfaces the send-drill feedback, whose "Pick Mode" button exits the// mode back to the grid; ?ref=length must not reset to tree on the way out.fireEvent.click(screen.getByText('Check'));+ // Check submits the round + training entry — settle those writes before+ // navigating away so their state updates stay act-wrapped.+ await settle();fireEvent.click(screen.getByText('Pick Mode'));+ await settle();expect(screen.getByTestId('loc').textContent).toBe('/post/morse?ref=length');});});diff --git a/client/src/components/pipeline/IssueJudgePanel.test.jsx b/client/src/components/pipeline/IssueJudgePanel.test.jsxindex 7048429690..2a7738bf59 100644--- a/client/src/components/pipeline/IssueJudgePanel.test.jsx+++ b/client/src/components/pipeline/IssueJudgePanel.test.jsx@@ -1,5 +1,5 @@import { describe, it, expect, vi, beforeEach } from 'vitest';-import { fireEvent, render, screen, waitFor } from '@testing-library/react';+import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';vi.mock('../../services/apiPipeline', () => ({getIssueJudge: vi.fn(),@@ -38,9 +38,12 @@ beforeEach(() => {});describe('IssueJudgePanel', () => {- it('renders nothing when no text stage has content', () => {+ it('renders nothing when no text stage has content', async () => {const { container } = render(<IssueJudgePanel issue={{ id: 'iss-x', stages: {} }} stageId="prose" />);expect(container.firstChild).toBeNull();+ // Drain the mount getIssueJudge fetch inside act so its state update+ // can't land outside it after the test body.+ await act(async () => {});});it('shows the not-judged state then the quality chip after a stored score loads', async () => {diff --git a/client/src/components/pipeline/manuscript/ManuscriptCommentCard.test.jsx b/client/src/components/pipeline/manuscript/ManuscriptCommentCard.test.jsxindex c5e2107853..38e31d77e5 100644--- a/client/src/components/pipeline/manuscript/ManuscriptCommentCard.test.jsx+++ b/client/src/components/pipeline/manuscript/ManuscriptCommentCard.test.jsx@@ -1,5 +1,5 @@import { describe, it, expect, vi, beforeEach } from 'vitest';-import { render, screen, fireEvent, waitFor } from '@testing-library/react';+import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';import ManuscriptCommentCard, { Badge } from './ManuscriptCommentCard';import { Toaster, toast } from '../../ui/Toast';import {@@ -53,6 +53,10 @@ const renderCard = (props) => render(// Single-key shortcut dispatched against document.body (no editable focus).const pressKey = (key) => fireEvent.keyDown(window, { key });+// Drain pending pre-resolved mock promises inside act so their state updates+// (card status, Toaster toast) can't land outside it after the test body.+const settle = () => act(async () => {});+describe('ManuscriptCommentCard keyboard shortcuts (#1603)', () => {beforeEach(() => {acceptPipelineManuscriptFix.mockReset();@@ -67,11 +71,12 @@ describe('ManuscriptCommentCard keyboard shortcuts (#1603)', () => {expect(screen.getByText('dismiss')).toBeTruthy();});- it('g triggers generate when there is no fix', () => {+ it('g triggers generate when there is no fix', async () => {generatePipelineManuscriptFix.mockResolvedValue({ comment: baseComment });renderCard();pressKey('g');expect(generatePipelineManuscriptFix).toHaveBeenCalledWith('ser-1', 'c1', expect.any(Object));+ await settle();});it('d dismisses the note via the patch endpoint', async () => {@@ -104,7 +109,7 @@ describe('ManuscriptCommentCard keyboard shortcuts (#1603)', () => {expect(screen.queryByText('False positive')).toBeNull();});- it('a accepts the suggested fix when one exists, and shows accept/regenerate hints', () => {+ it('a accepts the suggested fix when one exists, and shows accept/regenerate hints', async () => {acceptPipelineManuscriptFix.mockResolvedValue({ comment: { ...withFix, status: 'accepted' } });renderCard({ comment: withFix });expect(screen.getByText('accept')).toBeTruthy();@@ -113,6 +118,7 @@ describe('ManuscriptCommentCard keyboard shortcuts (#1603)', () => {expect(acceptPipelineManuscriptFix).toHaveBeenCalledWith('ser-1', 'c1', expect.objectContaining({edits: expect.arrayContaining([expect.objectContaining({ replace: 'new text' })]),}));+ await settle();});it('arrow keys step through the triage order, and the step hint renders only with nav', () => {diff --git a/client/src/components/songs/ReferenceAnalysis.test.jsx b/client/src/components/songs/ReferenceAnalysis.test.jsxindex 378b7b560b..bad10bfef9 100644--- a/client/src/components/songs/ReferenceAnalysis.test.jsx+++ b/client/src/components/songs/ReferenceAnalysis.test.jsx@@ -44,6 +44,10 @@ vi.mock('../../hooks/useReferenceAudioImport.js', () => ({import { act } from '@testing-library/react';import ReferenceAnalysis, { ReferenceAudioAttach } from './ReferenceAnalysis.jsx';+// Drain the mount decode effect's pre-resolved promises (fetch → decodeAudioData)+// inside act so their state updates can't land outside it after the test body.+const settle = () => act(async () => {});+const SR = 16000;const sine = (hz, seconds) => {const n = Math.round(seconds * SR);@@ -271,7 +275,7 @@ describe('ReferenceAnalysis — extract → review → apply (solo segment)', ()});describe('ReferenceAnalysis — stacked-mix extraction (#2121)', () => {- it('toggling Stacked seeds a backing window ending where the voice enters', () => {+ it('toggling Stacked seeds a backing window ending where the voice enters', async () => {installFakeAudio();const onUpdateReference = vi.fn();render(@@ -292,9 +296,10 @@ describe('ReferenceAnalysis — stacked-mix extraction (#2121)', () => {// the segment start (the voice's entrance).{ layerId: 'bass', startMs: 3000, endMs: 6000, bgStartMs: 0, bgEndMs: 3000 },]);+ await settle();});- it('warns when there is no audio before the segment to use as a backing ref', () => {+ it('warns when there is no audio before the segment to use as a backing ref', async () => {installFakeAudio();render(<ReferenceAnalysis@@ -310,6 +315,7 @@ describe('ReferenceAnalysis — stacked-mix extraction (#2121)', () => {);fireEvent.click(screen.getByRole('button', { name: /stacked/i }));expect(toastError).toHaveBeenCalledWith(expect.stringMatching(/not enough audio before/i));+ await settle();});it('rejects an invalid backing-window edit instead of silently dropping stacked mode', async () => {diff --git a/client/src/hooks/useChartColors.test.jsx b/client/src/hooks/useChartColors.test.jsxindex 4e1adb2cbd..e26eb39d52 100644--- a/client/src/hooks/useChartColors.test.jsx+++ b/client/src/hooks/useChartColors.test.jsx@@ -46,7 +46,7 @@ describe('useChartColors', () => {it('re-resolves when the theme dataset attribute changes', async () => {const root = document.documentElement;root.style.setProperty('--port-accent', '1 1 1');- const { result } = renderHook(() => useChartColors());+ const { result, unmount } = renderHook(() => useChartColors());expect(result.current.accent).toBe('rgb(1, 1, 1)');await act(async () => {@@ -57,5 +57,8 @@ describe('useChartColors', () => {});expect(result.current.accent).toBe('rgb(2, 2, 2)');+ // Unmount before afterEach strips data-port-theme — that mutation would+ // otherwise fire the observer's setColors outside act.+ unmount();});});diff --git a/client/src/hooks/useMediaJobProgress.test.jsx b/client/src/hooks/useMediaJobProgress.test.jsxindex eb26f39ecd..bbbfec2b1d 100644--- a/client/src/hooks/useMediaJobProgress.test.jsx+++ b/client/src/hooks/useMediaJobProgress.test.jsx@@ -20,6 +20,9 @@ vi.mock('../services/apiMediaJobs', () => ({ getMediaJob: (...a) => getMediaJob(const useMediaJobProgress = (await import('./useMediaJobProgress.js')).default;const fire = (event, payload) => act(() => { handlers.get(event)?.(payload); });+// Drain the mount hydrate fetch (a pre-resolved mock promise) inside act so its+// setStatus can't land outside it after the test body.+const settle = () => act(async () => {});describe('useMediaJobProgress — canceled handling (#1791)', () => {beforeEach(() => { handlers.clear(); getMediaJob.mockClear(); getMediaJob.mockResolvedValue({ status: 'running' }); });@@ -42,16 +45,18 @@ describe('useMediaJobProgress — canceled handling (#1791)', () => {expect(result.current.status).toBe('running');});- it('subscribes to the video-gen:canceled event when kind=video', () => {+ it('subscribes to the video-gen:canceled event when kind=video', async () => {renderHook(() => useMediaJobProgress('job-1', { kind: 'video' }));+ await settle();expect(handlers.has('video-gen:canceled')).toBe(true);expect(handlers.has('image-gen:canceled')).toBe(false);});// Audio (first-pass music-bed, #1933) rides the audio-gen:* namespace so the// Creative Director detail page can surface a failed background render.- it('subscribes to audio-gen:* events when kind=audio', () => {+ it('subscribes to audio-gen:* events when kind=audio', async () => {renderHook(() => useMediaJobProgress('job-1', { kind: 'audio' }));+ await settle();expect(handlers.has('audio-gen:failed')).toBe(true);expect(handlers.has('audio-gen:completed')).toBe(true);expect(handlers.has('image-gen:failed')).toBe(false);diff --git a/client/src/hooks/useMoltworldWs.test.jsx b/client/src/hooks/useMoltworldWs.test.jsxindex b3f9090890..4e1bac6da5 100644--- a/client/src/hooks/useMoltworldWs.test.jsx+++ b/client/src/hooks/useMoltworldWs.test.jsx@@ -22,18 +22,23 @@ vi.mock('../services/api', () => ({const useMoltworldWs = (await import('./useMoltworldWs.js')).default;const fire = (event, payload) => act(() => { handlers.get(event)?.(payload); });+// Drain the mount-effect status fetch (a pre-resolved mock promise) inside act+// so its setConnectionStatus can't land outside it after the test body.+const settle = () => act(async () => {});describe('useMoltworldWs — presence empty-event transition (#2022)', () => {beforeEach(() => { handlers.clear(); });afterEach(cleanup);- it('starts null (not-yet-known) before any presence event', () => {+ it('starts null (not-yet-known) before any presence event', async () => {const { result } = renderHook(() => useMoltworldWs());expect(result.current.presence).toBeNull();+ await settle();});- it('clears the presence list when an empty presence event follows a populated one', () => {+ it('clears the presence list when an empty presence event follows a populated one', async () => {const { result } = renderHook(() => useMoltworldWs());+ await settle();fire('moltworld:presence', { agents: [{ id: 'a1', name: 'Alice' }, { id: 'a2', name: 'Bob' }] });expect(result.current.presence).toHaveLength(2);@@ -42,8 +47,9 @@ describe('useMoltworldWs — presence empty-event transition (#2022)', () => {expect(result.current.presence).toEqual([]);});- it('clears the presence list on an empty nearby event too', () => {+ it('clears the presence list on an empty nearby event too', async () => {const { result } = renderHook(() => useMoltworldWs());+ await settle();fire('moltworld:nearby', { nearby: [{ id: 'a1', name: 'Alice' }] });expect(result.current.presence).toHaveLength(1);@@ -52,8 +58,9 @@ describe('useMoltworldWs — presence empty-event transition (#2022)', () => {expect(result.current.presence).toEqual([]);});- it('ignores a malformed (non-array) presence payload, preserving prior state', () => {+ it('ignores a malformed (non-array) presence payload, preserving prior state', async () => {const { result } = renderHook(() => useMoltworldWs());+ await settle();fire('moltworld:presence', { agents: [{ id: 'a1', name: 'Alice' }] });expect(result.current.presence).toHaveLength(1);@@ -63,8 +70,9 @@ describe('useMoltworldWs — presence empty-event transition (#2022)', () => {expect(result.current.presence).toHaveLength(1);});- it('ignores a payload missing both keys ({}), preserving prior state', () => {+ it('ignores a payload missing both keys ({}), preserving prior state', async () => {const { result } = renderHook(() => useMoltworldWs());+ await settle();fire('moltworld:presence', { agents: [{ id: 'a1', name: 'Alice' }] });expect(result.current.presence).toHaveLength(1);diff --git a/client/src/pages/MusicVideo.test.jsx b/client/src/pages/MusicVideo.test.jsxindex ec1c362925..2177cda50b 100644--- a/client/src/pages/MusicVideo.test.jsx+++ b/client/src/pages/MusicVideo.test.jsx@@ -3,7 +3,7 @@* gates on a scene having a generated clip, and clicking it kicks off the render.*/import { describe, it, expect, vi, beforeEach } from 'vitest';-import { render, screen, waitFor, fireEvent, within } from '@testing-library/react';+import { render, screen, waitFor, fireEvent, within, act } from '@testing-library/react';import { MemoryRouter, Routes, Route, useNavigate, useLocation } from 'react-router-dom';import toast from '../components/ui/Toast';@@ -103,6 +103,10 @@ const renderMV = () => render(</MemoryRouter>,);+// Flush pending pre-resolved mock promises inside act so their .then setState+// callbacks can't land outside it after the test body.+const settle = () => act(async () => {});+const openProject = async (project) => {listMusicVideoProjects.mockResolvedValue([project]);renderMV();@@ -408,6 +412,9 @@ describe('MusicVideo YouTube audio import (#1945)', () => {expect(listBtnA).toHaveClass('border-port-accent');resolveKickoff({ jobId: 'yt-job-pending' });+ // Settle the kickoff's .then (jobId + SSE-subscription state) inside act —+ // the pending-window assertions above must stay pre-settle.+ await settle();});it('blocks creating the project while the create-form YouTube import is in flight', async () => {