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
extract the wait-until-enabled test barrier into a shared helper (#7596)
[._.]/ Adam Eivye3bd2b45d696
diff --git a/client/src/components/apps/AppQualityRunner.test.jsx b/client/src/components/apps/AppQualityRunner.test.jsxindex 57354514ac..ba293a1df0 100644--- a/client/src/components/apps/AppQualityRunner.test.jsx+++ b/client/src/components/apps/AppQualityRunner.test.jsx@@ -3,6 +3,7 @@ import { MemoryRouter } from 'react-router';import { beforeEach, expect, it, vi } from 'vitest';import AppQualityRunner from './AppQualityRunner';import AppQuality from './AppQuality';+import { awaitEnabled, findEnabledByLabelText, findEnabledByRole } from '../../test/enabledBarrier.js';vi.mock('./AppQualityHistory', () => ({ default: () => null }));import { getMaintenanceRuns, startMaintenanceRun, stopMaintenanceRun } from '../../services/apiAgents';import useProviderModels from '../../hooks/useProviderModels';@@ -19,7 +20,7 @@ it('launches missing checks with visible mode and effort, then exposes held runnstartMaintenanceRun.mockResolvedValue({ run: { id: 'run-1', status: 'running', reason: 'Enable security in Schedule', steps: [] } });render(<MemoryRouter><AppQualityRunner app={app} /></MemoryRouter>);const button = screen.getByRole('button', { name: 'Run 2 checks now' });- await waitFor(() => expect(button).toBeEnabled());+ await awaitEnabled(button);fireEvent.change(screen.getByLabelText('Mode'), { target: { value: 'fix' } });fireEvent.click(screen.getByText('Use high effort'));fireEvent.click(button);@@ -32,7 +33,7 @@ it('allows one category and recovers from launch failure without reporting a runrender(<MemoryRouter><AppQualityRunner app={app} /></MemoryRouter>);fireEvent.change(screen.getByLabelText('Checks'), { target: { value: 'performance' } });const button = screen.getByRole('button', { name: 'Run now' });- await waitFor(() => expect(button).toBeEnabled());+ await awaitEnabled(button);fireEvent.click(button);expect(await screen.findByRole('alert')).toHaveTextContent('Provider unavailable');expect(button).toBeEnabled();@@ -42,7 +43,7 @@ it('allows one category and recovers from launch failure without reporting a runit('preserves run overrides when moving controls into a category row', async () => {startMaintenanceRun.mockResolvedValue({ run: { id: 'run-2', status: 'running', steps: [] } });render(<MemoryRouter><AppQuality app={app} detail /></MemoryRouter>);- await waitFor(() => expect(screen.getByRole('button', { name: 'Run 2 checks now' })).toBeEnabled());+ await findEnabledByRole('button', { name: 'Run 2 checks now' });fireEvent.change(screen.getByLabelText('Mode'), { target: { value: 'fix' } });fireEvent.click(screen.getByText('Use high effort'));fireEvent.click(screen.getByRole('link', { name: 'Configure and run Security' }));@@ -88,11 +89,11 @@ it('excludes known unavailable and N/A assessments from suggestions while allowi] } }} /></MemoryRouter>);fireEvent.click(screen.getByRole('button', { name: 'Run now' }));await waitFor(() => expect(startMaintenanceRun).toHaveBeenLastCalledWith(expect.objectContaining({ taskTypes: ['security'] }), { silent: true }));- await waitFor(() => expect(screen.getByLabelText('Checks')).toBeEnabled());+ await findEnabledByLabelText('Checks');fireEvent.change(screen.getByLabelText('Checks'), { target: { value: 'typing' } });fireEvent.click(screen.getByRole('button', { name: 'Run now' }));await waitFor(() => expect(startMaintenanceRun).toHaveBeenLastCalledWith(expect.objectContaining({ taskTypes: ['typing'] }), { silent: true }));- await waitFor(() => expect(screen.getByLabelText('Checks')).toBeEnabled());+ await findEnabledByLabelText('Checks');fireEvent.change(screen.getByLabelText('Checks'), { target: { value: 'all' } });fireEvent.click(screen.getByRole('button', { name: 'Run 3 checks now' }));await waitFor(() => expect(startMaintenanceRun).toHaveBeenLastCalledWith(expect.objectContaining({ taskTypes: ['typing', 'console-errors', 'security'] }), { silent: true }));diff --git a/client/src/components/apps/AppQualityScheduleForm.test.jsx b/client/src/components/apps/AppQualityScheduleForm.test.jsxindex e4f80427eb..9a8e73661b 100644--- a/client/src/components/apps/AppQualityScheduleForm.test.jsx+++ b/client/src/components/apps/AppQualityScheduleForm.test.jsx@@ -2,6 +2,7 @@ import { fireEvent, render, screen, waitFor, within } from '@testing-library/reaimport { MemoryRouter } from 'react-router';import { describe, it, expect, vi, beforeEach } from 'vitest';import AppQualityScheduleForm from './AppQualityScheduleForm';+import { findEnabledByRole } from '../../test/enabledBarrier.js';vi.mock('../../services/apiApps', () => ({getAppQualitySchedule: vi.fn(),@@ -119,7 +120,7 @@ describe('AppQualityScheduleForm', () => {fireEvent.click(screen.getByLabelText('Security'));expect(screen.getByRole('button', { name: /Re-planning/ })).toBeDisabled();expect(applyAppQualitySchedule).not.toHaveBeenCalled();- await waitFor(() => expect(screen.getByRole('button', { name: /Apply schedule/ })).toBeEnabled());+ await findEnabledByRole('button', { name: /Apply schedule/ });});it('re-enables Apply after a failed save instead of locking the form', async () => {diff --git a/client/src/components/apps/tabs/AutomationTab.test.jsx b/client/src/components/apps/tabs/AutomationTab.test.jsxindex 22d57a0b5c..863fd86f6d 100644--- a/client/src/components/apps/tabs/AutomationTab.test.jsx+++ b/client/src/components/apps/tabs/AutomationTab.test.jsx@@ -1,5 +1,6 @@import { describe, it, expect, vi, beforeEach } from 'vitest';import { render, screen, fireEvent, waitFor, within, act } from '@testing-library/react';+import { awaitEnabled } from '../../../test/enabledBarrier.js';// ── Mock router — capture navigate calls, no real Router needed ────────────────const mockNavigate = vi.hoisted(() => vi.fn());@@ -149,7 +150,7 @@ describe('AutomationTab per-app options', () => {expect(within(row).getByRole('switch', { name: 'security enabled for this app: off' })).toHaveAttribute('aria-checked', 'false');fireEvent.click(within(row).getByRole('switch', { name: 'security enabled for this app: off' }));api.updateAppTaskTypeOverride.mockResolvedValue({ success: true });- await waitFor(() => expect(within(row).getByRole('button', { name: 'Run Now' })).toBeEnabled());+ await awaitEnabled(() => within(row).getByRole('button', { name: 'Run Now' }));api.triggerCosOnDemandTask.mockResolvedValue({ success: true });fireEvent.click(within(row).getByRole('button', { name: 'Run Now' }));await waitFor(() => expect(api.triggerCosOnDemandTask).toHaveBeenCalledWith('security', 'app-1', { silent: true }));diff --git a/client/src/components/apps/tabs/IssuesTab.test.jsx b/client/src/components/apps/tabs/IssuesTab.test.jsxindex b85c2514d9..91184cb39a 100644--- a/client/src/components/apps/tabs/IssuesTab.test.jsx+++ b/client/src/components/apps/tabs/IssuesTab.test.jsx@@ -1,6 +1,7 @@import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';import { render, screen, fireEvent, cleanup, waitFor, act } from '@testing-library/react';import { MemoryRouter } from 'react-router';+import { findEnabledByRole } from '../../../test/enabledBarrier.js';const { socketHandlers, socketMock } = vi.hoisted(() => {const handlers = new Map();@@ -429,7 +430,7 @@ describe('IssuesTab', () => {fireEvent.click(await screen.findByRole('button', { name: /Claim/ }));- await waitFor(() => expect(screen.getByRole('button', { name: /Claim/ })).toBeEnabled());+ await findEnabledByRole('button', { name: /Claim/ });expect(screen.queryByRole('link', { name: /Queued/ })).not.toBeInTheDocument();});@@ -850,7 +851,7 @@ describe('IssuesTab replan', () => {await renderTab();fireEvent.click(await screen.findByRole('button', { name: /Replan/ }));- await waitFor(() => expect(screen.getByRole('button', { name: /Replan/ })).toBeEnabled());+ await findEnabledByRole('button', { name: /Replan/ });});it('allows selecting merge-on-green, hides reviewer controls, and sends prCompletion', async () => {diff --git a/client/src/components/apps/tabs/RepositorySourcePanel.test.jsx b/client/src/components/apps/tabs/RepositorySourcePanel.test.jsxindex f24c93330f..f70a45a28e 100644--- a/client/src/components/apps/tabs/RepositorySourcePanel.test.jsx+++ b/client/src/components/apps/tabs/RepositorySourcePanel.test.jsx@@ -1,5 +1,6 @@import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react';+import { awaitEnabled } from '../../../test/enabledBarrier.js';vi.mock('../../../services/api', () => ({PORTOS_APP_ID: 'portos-default',@@ -429,7 +430,7 @@ describe('PortOS self-update restart handoff', () => {expect(screen.queryByRole('button', { name: 'Update app' })).not.toBeInTheDocument();expect(api.addCosTask).not.toHaveBeenCalled();const start = screen.getByRole('button', { name: 'Start recovery agent' });- await waitFor(() => expect(start).toBeEnabled());+ await awaitEnabled(start);fireEvent.change(screen.getByLabelText('Model'), { target: { value: 'example-model' } });fireEvent.click(start);await screen.findByRole('link', { name: 'Recovery queued · View agents' });diff --git a/client/src/components/calendar/SyncTab.test.jsx b/client/src/components/calendar/SyncTab.test.jsxindex 2b39ff5203..14f302f7c3 100644--- a/client/src/components/calendar/SyncTab.test.jsx+++ b/client/src/components/calendar/SyncTab.test.jsx@@ -2,6 +2,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';import { MemoryRouter } from 'react-router';import SyncTab from './SyncTab';+import { awaitEnabled } from '../../test/enabledBarrier.js';const api = vi.hoisted(() => ({getCalendarTokenStatus: vi.fn(),@@ -69,7 +70,7 @@ describe('Calendar sync lifecycle', () => {api.syncCalendarAccount.mockResolvedValue({ status: 'skipped' });render(<SyncTab accounts={[account]} onRefresh={vi.fn()} />);fireEvent.click(syncButton());- await waitFor(() => expect(syncButton()).toBeEnabled());+ await awaitEnabled(syncButton);emit('started'); // The socket can deliver its start after HTTP settled.expect(syncButton()).toBeEnabled();expect(toast.warning).toHaveBeenCalledWith(expect.stringContaining('no usable token'));diff --git a/client/src/components/cos/TaskAddForm.test.jsx b/client/src/components/cos/TaskAddForm.test.jsxindex 683c505a85..800f0689e7 100644--- a/client/src/components/cos/TaskAddForm.test.jsx+++ b/client/src/components/cos/TaskAddForm.test.jsx@@ -3,6 +3,7 @@ import { render, screen, waitFor, act } from '@testing-library/react';import userEvent from '@testing-library/user-event';import TaskAddForm from './TaskAddForm';import { __resetToolUseModelIdsCache } from '../../hooks/useToolUseModelIds.js';+import { findEnabledByLabelText } from '../../test/enabledBarrier.js';const api = vi.hoisted(() => ({getCosPopularTemplates: vi.fn(),@@ -761,7 +762,7 @@ describe('TaskAddForm Codex model catalog', () => {onTaskAdded={vi.fn()}/>);- await waitFor(() => expect(screen.getByLabelText('AI provider')).not.toBeDisabled());+ await findEnabledByLabelText('AI provider');await user.selectOptions(screen.getByLabelText('AI provider'), 'codex');return user;};diff --git a/client/src/components/cos/tabs/JobsTab.test.jsx b/client/src/components/cos/tabs/JobsTab.test.jsxindex 6f92d513e5..52dddf44d5 100644--- a/client/src/components/cos/tabs/JobsTab.test.jsx+++ b/client/src/components/cos/tabs/JobsTab.test.jsx@@ -1,6 +1,7 @@import { describe, it, expect, vi, beforeEach } from 'vitest';import { fireEvent, render, screen, waitFor } from '@testing-library/react';import JobsTab from './JobsTab';+import { findEnabledByRole } from '../../../test/enabledBarrier.js';const api = vi.hoisted(() => ({getCosJobs: vi.fn(),@@ -93,7 +94,7 @@ describe('JobsTab / JobCard Run Now disable behavior (#4036)', () => {const saveButton = screen.getByRole('button', { name: 'Save' });fireEvent.click(saveButton);- await waitFor(() => expect(screen.getByRole('button', { name: 'Run now' })).not.toBeDisabled());+ await findEnabledByRole('button', { name: 'Run now' });});it('re-enables the Run now button when exiting edit mode via Cancel', async () => {diff --git a/client/src/components/cos/tabs/MindTab.test.jsx b/client/src/components/cos/tabs/MindTab.test.jsxindex 0ac5d41329..2ed8b4fc4a 100644--- a/client/src/components/cos/tabs/MindTab.test.jsx+++ b/client/src/components/cos/tabs/MindTab.test.jsx@@ -3,6 +3,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';import { createEvent, fireEvent, render, screen, waitFor, within } from '@testing-library/react';import userEvent from '@testing-library/user-event';import { MemoryRouter } from 'react-router';+import { awaitEnabled, findEnabledByLabelText, findEnabledByRole } from '../../../test/enabledBarrier.js';const api = vi.hoisted(() => ({getPersistentMind: vi.fn(),@@ -194,8 +195,7 @@ describe('MindTab', () => {it('offers an immediate wake and displays failures', async () => {api.wakePersistentMind.mockRejectedValue(new Error('Wake unavailable'));renderTab();- const button = await screen.findByRole('button', { name: 'Wake now' });- await waitFor(() => expect(button).not.toBeDisabled());+ const button = await findEnabledByRole('button', { name: 'Wake now' });fireEvent.click(button);await screen.findByText('Wake unavailable');expect(api.wakePersistentMind).toHaveBeenCalledWith({ silent: true });@@ -352,7 +352,7 @@ describe('MindTab', () => {expect(start).toBeDisabled();finishSave({ success: true });- await waitFor(() => expect(start).toBeEnabled());+ await awaitEnabled(start);await user.click(start);await waitFor(() => expect(api.startPersistentMind).toHaveBeenCalledTimes(1));});@@ -375,7 +375,7 @@ describe('MindTab', () => {expect(document.querySelector(`time[datetime="${nextWakeAt}"]`)).toBeInTheDocument();const cadence = screen.getByLabelText('Wake cadence');expect(cadence).toHaveValue('30');- await waitFor(() => expect(screen.getByLabelText('Wake cadence')).toBeEnabled());+ await findEnabledByLabelText('Wake cadence');fireEvent.change(cadence, { target: { value: '60' } });@@ -459,7 +459,7 @@ describe('MindTab', () => {expect(api.startPersistentMind).not.toHaveBeenCalled();finishSave({ success: true });- await waitFor(() => expect(start).toBeEnabled());+ await awaitEnabled(start);});it('keeps a failed message for a visible idempotent retry', async () => {@@ -826,7 +826,7 @@ describe('MindTab', () => {await user.selectOptions(within(editor).getByLabelText('Cleanup protection'), 'standard');await user.click(within(editor).getByRole('button', { name: 'Save memory' }));await waitFor(() => expect(memory.protection).toBe('standard'));- await waitFor(() => expect(within(editor).getByRole('button', { name: 'Save memory' })).toBeEnabled());+ await awaitEnabled(() => within(editor).getByRole('button', { name: 'Save memory' }));memory.protection = 'important';await user.click(within(editor).getByRole('button', { name: 'Save memory' }));await waitFor(() => expect(api.updatePersistentMindMemory).toHaveBeenCalledTimes(3));diff --git a/client/src/components/cos/tabs/schedule/MaintenanceRunForm.test.jsx b/client/src/components/cos/tabs/schedule/MaintenanceRunForm.test.jsxindex c49bee268f..4b36af17b2 100644--- a/client/src/components/cos/tabs/schedule/MaintenanceRunForm.test.jsx+++ b/client/src/components/cos/tabs/schedule/MaintenanceRunForm.test.jsx@@ -6,6 +6,7 @@ import { MemoryRouter } from 'react-router';import { MAINTENANCE_TASK_ORDER } from '../../../../lib/quotaBurnTasks';import { MAINTENANCE_SEQUENCE_TYPES } from '../../../../../../server/lib/maintenanceSequence';import MaintenanceRunForm from './MaintenanceRunForm';+import { findEnabledByRole } from '../../../../test/enabledBarrier.js';const socket = vi.hoisted(() => ({ on: vi.fn(), off: vi.fn(), emit: vi.fn() }));vi.mock('../../../../services/socket', () => ({ default: socket }));@@ -145,7 +146,7 @@ it('enables only missing prerequisites and waits for refreshed saved settings beexpect(screen.getByRole('combobox', { name: 'App' })).toBeDisabled();expect(api.startMaintenanceRun).not.toHaveBeenCalled();finishRefresh();- await waitFor(() => expect(screen.getByRole('button', { name: 'Run now' })).toBeEnabled());+ await findEnabledByRole('button', { name: 'Run now' });await user.click(screen.getByRole('button', { name: 'Run now' }));expect(await screen.findByText(/Maintenance started/)).toBeInTheDocument();});diff --git a/client/src/components/fableloom/LoomEpisodeOutlinePlanner.test.jsx b/client/src/components/fableloom/LoomEpisodeOutlinePlanner.test.jsxindex 583733ce62..5208a40e0e 100644--- a/client/src/components/fableloom/LoomEpisodeOutlinePlanner.test.jsx+++ b/client/src/components/fableloom/LoomEpisodeOutlinePlanner.test.jsx@@ -1,6 +1,7 @@import { describe, expect, it, vi, beforeEach } from 'vitest';import { render, screen, waitFor } from '@testing-library/react';import userEvent from '@testing-library/user-event';+import { findEnabledByRole } from '../../test/enabledBarrier.js';const toastMocks = vi.hoisted(() => ({ error: vi.fn(), success: vi.fn(), warning: vi.fn() }));vi.mock('../ui/Toast', () => ({ default: toastMocks }));@@ -166,5 +167,5 @@ it('blocks competing outline work until shot planning settles', async () => {expect(screen.getByRole('button', { name: 'Validate outline' })).toBeDisabled();expect(screen.getByRole('button', { name: 'Expand validated outline to teleplay' })).toBeDisabled();finish({ review: { summary: 'Ready.' }, groups: [] });- await waitFor(() => expect(screen.getByRole('button', { name: 'Expand validated outline to teleplay' })).toBeEnabled());+ await findEnabledByRole('button', { name: 'Expand validated outline to teleplay' });});diff --git a/client/src/components/fableloom/LoomNodeEditor.test.jsx b/client/src/components/fableloom/LoomNodeEditor.test.jsxindex 3973f9711f..dcf318d976 100644--- a/client/src/components/fableloom/LoomNodeEditor.test.jsx+++ b/client/src/components/fableloom/LoomNodeEditor.test.jsx@@ -2,6 +2,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';import { render, screen, waitFor } from '@testing-library/react';import { MemoryRouter } from 'react-router';import userEvent from '@testing-library/user-event';+import { findEnabledByRole } from '../../test/enabledBarrier.js';vi.mock('../../services/api', () => ({addLoomTransition: vi.fn(),@@ -335,7 +336,7 @@ describe('LoomNodeEditor scene media', () => {await waitFor(() => expect(updateLoomNode).toHaveBeenCalledWith('loom-1', 'ep-1', 'n1', { videoPrompt: 'A fast practical-effects reveal.' }, { silent: true },));- await waitFor(() => expect(screen.getByRole('button', { name: 'Automate fal.ai' })).toBeEnabled());+ await findEnabledByRole('button', { name: 'Automate fal.ai' });await user.click(screen.getByRole('button', { name: 'Automate fal.ai' }));await waitFor(() => expect(onAutomateFalVideo).toHaveBeenCalledWith(expect.objectContaining({diff --git a/client/src/components/instances/TailnetHelpBanner.test.jsx b/client/src/components/instances/TailnetHelpBanner.test.jsxindex 36106e1435..da2835ac8c 100644--- a/client/src/components/instances/TailnetHelpBanner.test.jsx+++ b/client/src/components/instances/TailnetHelpBanner.test.jsx@@ -1,6 +1,7 @@import { beforeEach, describe, expect, it, vi } from 'vitest';import { render, screen, waitFor } from '@testing-library/react';import userEvent from '@testing-library/user-event';+import { findEnabledByRole } from '../../test/enabledBarrier.js';vi.mock('../../services/api', () => ({handleSelfRestart: vi.fn(),@@ -134,7 +135,7 @@ describe('TailnetHelpBanner HTTPS activation', () => {await user.click(screen.getByRole('button', { name: 'Enable HTTPS' }));await user.click(await screen.findByRole('button', { name: 'Restart PortOS' }));- await waitFor(() => expect(screen.getByRole('button', { name: 'Restart PortOS' })).toBeEnabled());+ await findEnabledByRole('button', { name: 'Restart PortOS' });expect(toast.error).toHaveBeenCalledWith('Restart unavailable');expect(handleSelfRestart).not.toHaveBeenCalled();});diff --git a/client/src/components/meatspace/post/MemoryPractice.test.jsx b/client/src/components/meatspace/post/MemoryPractice.test.jsxindex 3477d8022b..5bc36c4eab 100644--- a/client/src/components/meatspace/post/MemoryPractice.test.jsx+++ b/client/src/components/meatspace/post/MemoryPractice.test.jsx@@ -1,5 +1,6 @@import { describe, it, expect, vi, beforeEach } from 'vitest';import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';+import { awaitEnabled } from '../../../test/enabledBarrier.js';import MemoryPractice, {fuzzyMatch,generateHint,@@ -304,7 +305,7 @@ describe('MemoryPractice daily routine actions', () => {await waitFor(() => expect(submitMemoryPractice).toHaveBeenCalledTimes(1));expect(onContinue).not.toHaveBeenCalled();- await waitFor(() => expect(screen.getByText("Continue Today's Routine")).toBeEnabled());+ await awaitEnabled(() => screen.getByText("Continue Today's Routine"));submitMemoryPractice.mockResolvedValueOnce({ mastery: {} });fireEvent.click(screen.getByText("Continue Today's Routine"));diff --git a/client/src/components/meatspace/post/MorseTrainer.test.jsx b/client/src/components/meatspace/post/MorseTrainer.test.jsxindex ca4a60ac02..e19a181de9 100644--- a/client/src/components/meatspace/post/MorseTrainer.test.jsx+++ b/client/src/components/meatspace/post/MorseTrainer.test.jsx@@ -1,6 +1,7 @@import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';import { MemoryRouter, Routes, Route, useLocation } from 'react-router';+import { awaitEnabled } from '../../../test/enabledBarrier.js';// Stub the training-log API so mount-time fetches (refreshTrainingStats) and// round-completion writes (logTraining) never hit the network — mirrors the@@ -216,7 +217,7 @@ describe('MorseTrainer training log integration', () => {await waitFor(() => expect(submitTrainingEntry).toHaveBeenCalledTimes(2));expect(onContinue).not.toHaveBeenCalled();- await waitFor(() => expect(screen.getByText("Continue Today's Routine")).toBeEnabled());+ await awaitEnabled(() => screen.getByText("Continue Today's Routine"));});describe('round completion', () => {diff --git a/client/src/components/meatspace/post/RhetoricTrainer.test.jsx b/client/src/components/meatspace/post/RhetoricTrainer.test.jsxindex 8aa03153fc..d557d6c41b 100644--- a/client/src/components/meatspace/post/RhetoricTrainer.test.jsx+++ b/client/src/components/meatspace/post/RhetoricTrainer.test.jsx@@ -1,6 +1,7 @@import { fireEvent, render, screen, waitFor } from '@testing-library/react';import { beforeEach, describe, expect, it, vi } from 'vitest';import RhetoricTrainer from './RhetoricTrainer';+import { findEnabledByRole } from '../../../test/enabledBarrier.js';import { evaluateRhetoricAttempt, getLoadedLlmModels, getProviders, submitTrainingEntry } from '../../../services/api';vi.mock('../../../services/api', () => ({@@ -245,6 +246,6 @@ describe('RhetoricTrainer', () => {expect(saved.scorerProvenance).toBe('post-rhetoric-self+ai');expect(saved.questions).toHaveLength(5);expect(saved.questions.every((question) => question.evaluation?.overallScore === 82)).toBe(true);- await waitFor(() => expect(screen.getByRole('button', { name: 'Continue POST' })).not.toBeDisabled());+ await findEnabledByRole('button', { name: 'Continue POST' });});});diff --git a/client/src/components/meatspace/post/WordplayTrainer.test.jsx b/client/src/components/meatspace/post/WordplayTrainer.test.jsxindex 287e7d49ee..2c0ed7f47e 100644--- a/client/src/components/meatspace/post/WordplayTrainer.test.jsx+++ b/client/src/components/meatspace/post/WordplayTrainer.test.jsx@@ -1,6 +1,7 @@import { describe, it, expect, vi, beforeEach } from 'vitest';import { useState } from 'react';import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';+import { awaitEnabled } from '../../../test/enabledBarrier.js';// Stub every API call WordplayTrainer (and the shared WordplayDrillUI scoring// core it now delegates to) can reach — mirrors the mocking convention used@@ -192,7 +193,7 @@ describe('WordplayTrainer — training-log persistence (issue #2097)', () => {fireEvent.click(screen.getByText("Continue Today's Routine"));await waitFor(() => expect(submitTrainingEntry).toHaveBeenCalledTimes(2));expect(onContinue).not.toHaveBeenCalled();- await waitFor(() => expect(screen.getByText("Continue Today's Routine")).toBeEnabled());+ await awaitEnabled(() => screen.getByText("Continue Today's Routine"));});it('does not wedge on a permanent spinner after leaving a mode mid-generation then picking another (issue #2098)', async () => {diff --git a/client/src/components/media/MediaJobsQueue.test.jsx b/client/src/components/media/MediaJobsQueue.test.jsxindex 3d5e386bc7..a614413240 100644--- a/client/src/components/media/MediaJobsQueue.test.jsx+++ b/client/src/components/media/MediaJobsQueue.test.jsx@@ -2,6 +2,7 @@ import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest';import { act, render, screen, waitFor } from '@testing-library/react';import userEvent from '@testing-library/user-event';import { retypeSettled } from '../../test/settledInput';+import { findEnabledByRole } from '../../test/enabledBarrier.js';// Mock the media-jobs API so the queue renders a controlled job list without// the network. useAutoRefetch calls the fetcher on mount.@@ -739,7 +740,7 @@ describe('MediaJobsQueue — local video holds', () => {expect(await screen.findByText('2 video jobs held')).toBeInTheDocument();expect(screen.getByText('Shader compilation failed')).toBeInTheDocument();await user.click(screen.getByRole('button', { name: 'Resume' }));- await waitFor(() => expect(screen.getByRole('button', { name: 'Resume' })).toBeEnabled());+ await findEnabledByRole('button', { name: 'Resume' });expect(screen.getByText('2 video jobs held')).toBeInTheDocument();let finishResume;resumeMediaVideoHold.mockImplementationOnce(() => new Promise((resolve) => { finishResume = resolve; }));diff --git a/client/src/components/media/PromptRefineModal.test.jsx b/client/src/components/media/PromptRefineModal.test.jsxindex f6cf56170a..8f7460f681 100644--- a/client/src/components/media/PromptRefineModal.test.jsx+++ b/client/src/components/media/PromptRefineModal.test.jsx@@ -3,6 +3,7 @@ import { fireEvent, render, screen, waitFor } from '@testing-library/react';import PromptRefineModal from './PromptRefineModal';import { normalizeVideo } from './normalize';import * as api from '../../services/api';+import { findEnabledByRole } from '../../test/enabledBarrier.js';vi.mock('../../hooks/useProviderModels', () => ({default: () => ({@@ -45,7 +46,7 @@ describe('PromptRefineModal video queue payload', () => {render(<PromptRefineModal item={item} open onClose={vi.fn()} />);fireEvent.change(screen.getByLabelText('Feedback'), { target: { value: 'Add motion' } });fireEvent.click(screen.getByRole('button', { name: 'Refine Prompt' }));- await waitFor(() => expect(screen.getByRole('button', { name: 'Queue Render' })).toBeEnabled());+ await findEnabledByRole('button', { name: 'Queue Render' });fireEvent.click(screen.getByRole('button', { name: 'Queue Render' }));await waitFor(() => expect(api.generateVideo).toHaveBeenCalled());}diff --git a/client/src/components/media/RigPanel.test.jsx b/client/src/components/media/RigPanel.test.jsxindex aa54525638..32685440a9 100644--- a/client/src/components/media/RigPanel.test.jsx+++ b/client/src/components/media/RigPanel.test.jsx@@ -1,5 +1,6 @@import { describe, expect, it, beforeEach, vi } from 'vitest';import { fireEvent, render, screen, waitFor } from '@testing-library/react';+import { findEnabledByRole } from '../../test/enabledBarrier.js';const mock = vi.hoisted(() => ({getRiggingReadiness: vi.fn(),@@ -71,7 +72,7 @@ describe('RigPanel', () => {const onRecordChange = vi.fn();const { rerender } = render(<RigPanel record={READY_RECORD} onRecordChange={onRecordChange} />);- await waitFor(() => expect(screen.getByRole('button', { name: /rig this character/i })).toBeEnabled());+ await findEnabledByRole('button', { name: /rig this character/i });fireEvent.click(screen.getByRole('button', { name: /rig this character/i }));await waitFor(() => expect(onRecordChange).toHaveBeenCalledWith(rigged));diff --git a/client/src/components/messages/BeeperTab.test.jsx b/client/src/components/messages/BeeperTab.test.jsxindex bf7f1f7120..1739723a2f 100644--- a/client/src/components/messages/BeeperTab.test.jsx+++ b/client/src/components/messages/BeeperTab.test.jsx@@ -5,6 +5,7 @@ import {act, cleanup, fireEvent, render, screen, waitFor, within,} from '@testing-library/react';import { MemoryRouter, Route, Routes } from 'react-router';+import { awaitEnabled } from '../../test/enabledBarrier.js';/*** The Beeper chat surface (#35), tested at the page boundary — the same seam a@@ -1059,7 +1060,7 @@ describe('thread pagination', () => {});// The finally clause must clear `loadingMore` even though the generation// guard drops the stale response itself.- await waitFor(() => expect(loadMoreForB).toBeEnabled());+ await awaitEnabled(loadMoreForB);expect(screen.queryByText('Placeholder A older')).toBeNull();});});diff --git a/client/src/components/messages/SyncTab.test.jsx b/client/src/components/messages/SyncTab.test.jsxindex 2c6836d162..d28231dfeb 100644--- a/client/src/components/messages/SyncTab.test.jsx+++ b/client/src/components/messages/SyncTab.test.jsx@@ -1,5 +1,6 @@import { beforeEach, describe, expect, it, vi } from 'vitest';import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';+import { findEnabledByRole } from '../../test/enabledBarrier.js';const api = vi.hoisted(() => ({getMessageSelectors: vi.fn(),@@ -130,7 +131,7 @@ describe('Messages sync lifecycle', () => {fireEvent.click(screen.getByRole('button', { name: 'Sync Unread' }));emit('started');emit('failed', { error: 'Connection lost' });- await waitFor(() => expect(screen.getByRole('button', { name: 'Sync Unread' })).toBeEnabled());+ await findEnabledByRole('button', { name: 'Sync Unread' });expect(toast.error).toHaveBeenCalledExactlyOnceWith('Sync failed: Connection lost');});});diff --git a/client/src/components/music/MusicDesigner.test.jsx b/client/src/components/music/MusicDesigner.test.jsxindex 01e3530df1..97e9f40539 100644--- a/client/src/components/music/MusicDesigner.test.jsx+++ b/client/src/components/music/MusicDesigner.test.jsx@@ -3,6 +3,7 @@ import { render, screen, fireEvent, waitFor, cleanup } from '@testing-library/reimport { MemoryRouter, Routes, Route, useLocation } from 'react-router';import MusicDesigner from './MusicDesigner';import * as api from '../../services/api';+import { findEnabledByLabelText } from '../../test/enabledBarrier.js';vi.mock('../../services/api', () => ({createTrack: vi.fn(),@@ -61,19 +62,6 @@ const renderAt = (path) => render(</MemoryRouter>,);-// Every step's field is on screen from the first paint but sits `disabled`-// until the draft create/get resolves, and the step's action buttons are gated-// on that same `draftReady`. A bare `findByLabelText` therefore resolves on the-// FIRST poll, before any of it — the interaction that follows lands on a-// disabled control, silently does nothing, and the next wait burns the whole-// async budget (#7592, the #7448 wrong-barrier shape). Wait for the field to be-// usable, which is exactly the state "the draft has loaded and hydrated".-const awaitDraftLoaded = async (label) => {- const field = await screen.findByLabelText(label);- await waitFor(() => expect(field).not.toBeDisabled());- return field;-};-describe('<MusicDesigner>', () => {beforeEach(() => {vi.clearAllMocks();@@ -130,11 +118,11 @@ describe('<MusicDesigner>', () => {// The resume hint is written by the hydrate that ends the draft load, so// unmounting on the weaker barrier would leave storage empty and the// second visit with nothing to reopen.- await awaitDraftLoaded(/what do you want to hear/i);+ await findEnabledByLabelText(/what do you want to hear/i);cleanup();renderAt('/music/generate/lyrics');- await awaitDraftLoaded('Lyrics');+ await findEnabledByLabelText('Lyrics');expect(api.getTrack).toHaveBeenCalledWith('track-draft', { silent: true });});@@ -145,7 +133,7 @@ describe('<MusicDesigner>', () => {});renderAt('/music/generate/lyrics?trackId=track-saved');- expect(await awaitDraftLoaded('Lyrics')).toHaveValue('[verse]\nKeep moving');+ expect(await findEnabledByLabelText('Lyrics')).toHaveValue('[verse]\nKeep moving');expect(api.getTrack).toHaveBeenCalledWith('track-saved', { silent: true });expect(api.createTrack).not.toHaveBeenCalled();});@@ -159,7 +147,7 @@ describe('<MusicDesigner>', () => {// Hydration is what could clobber the unrelated `activeDraft` key, so the// assertion below only means something once it has actually run.- await awaitDraftLoaded(/what do you want to hear/i);+ await findEnabledByLabelText(/what do you want to hear/i);expect(window.localStorage.getItem('portos.musicDesigner.activeDraft')).toBe('track-draft');});@@ -170,7 +158,7 @@ describe('<MusicDesigner>', () => {});renderAt('/music/generate/render?trackId=track-saved');- const prompt = await awaitDraftLoaded(/prompt for this render/i);+ const prompt = await findEnabledByLabelText(/prompt for this render/i);expect(prompt).toHaveValue('Warm synths and a patient beat.');fireEvent.change(prompt, { target: { value: 'A brighter pulse with hand percussion.' } });expect(screen.getByTestId('gen-panel')).toHaveAttribute('data-prompt', 'A brighter pulse with hand percussion.');@@ -184,7 +172,7 @@ describe('<MusicDesigner>', () => {it('lets a direct render visit supply the prompt before generating', async () => {renderAt('/music/generate/render?trackId=track-draft');- const prompt = await awaitDraftLoaded(/prompt for this render/i);+ const prompt = await findEnabledByLabelText(/prompt for this render/i);expect(prompt).toHaveValue('');fireEvent.change(prompt, { target: { value: 'A quiet piano loop with tape hiss.' } });@@ -205,7 +193,7 @@ describe('<MusicDesigner>', () => {api.describeMusic.mockResolvedValue({ description: 'Lush pads over a broken beat.', llm: { provider: 'provider-a', model: 'model-a' } });renderAt('/music/generate/concept');- fireEvent.change(await awaitDraftLoaded(/what do you want to hear/i), { target: { value: 'a rainy downtempo loop' } });+ fireEvent.change(await findEnabledByLabelText(/what do you want to hear/i), { target: { value: 'a rainy downtempo loop' } });fireEvent.change(screen.getByLabelText(/extra guidance/i), { target: { value: 'under 100 BPM' } });fireEvent.click(screen.getByRole('button', { name: /describe it/i }));@@ -234,7 +222,7 @@ describe('<MusicDesigner>', () => {it('persists the provider pin after a successful describe', async () => {api.describeMusic.mockResolvedValue({ description: 'Lush pads.', llm: {} });renderAt('/music/generate/concept');- fireEvent.change(await awaitDraftLoaded(/what do you want to hear/i), { target: { value: 'x' } });+ fireEvent.change(await findEnabledByLabelText(/what do you want to hear/i), { target: { value: 'x' } });fireEvent.click(screen.getByRole('button', { name: /describe it/i }));await waitFor(() => expect(api.updateSettings).toHaveBeenCalledWith(@@ -246,7 +234,7 @@ describe('<MusicDesigner>', () => {it('keeps the user on the concept step when the call fails', async () => {api.describeMusic.mockRejectedValue(new Error('no provider'));renderAt('/music/generate/concept');- fireEvent.change(await awaitDraftLoaded(/what do you want to hear/i), { target: { value: 'x' } });+ fireEvent.change(await findEnabledByLabelText(/what do you want to hear/i), { target: { value: 'x' } });fireEvent.click(screen.getByRole('button', { name: /describe it/i }));await waitFor(() => expect(api.describeMusic).toHaveBeenCalled());@@ -260,7 +248,7 @@ describe('<MusicDesigner>', () => {api.generateLyrics.mockResolvedValue({ lyrics: '[verse]\nrain on the window', llm: {} });renderAt('/music/generate/concept');- fireEvent.change(await awaitDraftLoaded(/what do you want to hear/i), { target: { value: 'a rainy downtempo loop' } });+ fireEvent.change(await findEnabledByLabelText(/what do you want to hear/i), { target: { value: 'a rainy downtempo loop' } });fireEvent.click(screen.getByRole('button', { name: /describe it/i }));await waitFor(() => expect(screen.getByTestId('location')).toHaveTextContent('/music/generate/description'));fireEvent.click(screen.getByRole('button', { name: /next: lyrics/i }));@@ -291,7 +279,7 @@ describe('<MusicDesigner>', () => {api.describeMusic.mockResolvedValue({ description: 'Lush pads over a broken beat.', llm: {} });renderAt('/music/generate/concept');- fireEvent.change(await awaitDraftLoaded(/what do you want to hear/i), { target: { value: 'a rainy downtempo loop' } });+ fireEvent.change(await findEnabledByLabelText(/what do you want to hear/i), { target: { value: 'a rainy downtempo loop' } });fireEvent.click(screen.getByRole('button', { name: /describe it/i }));await waitFor(() => expect(screen.getByTestId('location')).toHaveTextContent('/music/generate/description'));fireEvent.click(screen.getByRole('button', { name: /next: lyrics/i }));@@ -369,7 +357,7 @@ describe('<MusicDesigner>', () => {api.describeMusic.mockResolvedValue({ description: 'Terse.', llm: {} });renderAt('/music/generate/concept');- fireEvent.change(await awaitDraftLoaded(/what do you want to hear/i), { target: { value: 'x' } });+ fireEvent.change(await findEnabledByLabelText(/what do you want to hear/i), { target: { value: 'x' } });fireEvent.click(screen.getByRole('button', { name: /advanced — meta-prompts/i }));await waitFor(() => expect(screen.getByLabelText(/description instruction/i)).toHaveValue('Be terse.'));diff --git a/client/src/components/settings/AiAssignmentsTab.test.jsx b/client/src/components/settings/AiAssignmentsTab.test.jsxindex 7fda689f02..3191bf3fee 100644--- a/client/src/components/settings/AiAssignmentsTab.test.jsx+++ b/client/src/components/settings/AiAssignmentsTab.test.jsx@@ -2,6 +2,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';import { render, screen, waitFor } from '@testing-library/react';import userEvent from '@testing-library/user-event';import { MemoryRouter } from 'react-router';+import { findEnabledByLabelText } from '../../test/enabledBarrier.js';vi.mock('../../services/api', () => ({ getAiAssignments: vi.fn(), updateAiAssignment: vi.fn() }));vi.mock('../../services/apiLocalLlm', () => ({ getVisionModels: vi.fn(), getToolUseModels: vi.fn() }));@@ -336,10 +337,9 @@ describe('AiAssignmentsTab assignment management', () => {getVisionModels.mockResolvedValue({ models: [{ providerId: 'ollama', backend: 'ollama', id: 'qwen3.6:35b', vision: true }] });renderTab();- const picker = await screen.findByLabelText('Provider for Scene evaluation vision model');// The picker is held until the capability scan settles — seeding from a// stale answer is what would leave a text-only default on a vision row.- await waitFor(() => expect(picker).not.toBeDisabled());+ const picker = await findEnabledByLabelText('Provider for Scene evaluation vision model');await userEvent.selectOptions(picker, 'ollama');expect(screen.getByLabelText('Model for Scene evaluation vision model')).toHaveValue('qwen3.6:35b');diff --git a/client/src/components/settings/SharingTab.test.jsx b/client/src/components/settings/SharingTab.test.jsxindex b6d4302e12..194046a0da 100644--- a/client/src/components/settings/SharingTab.test.jsx+++ b/client/src/components/settings/SharingTab.test.jsx@@ -1,5 +1,6 @@import { describe, it, expect, vi, beforeEach } from 'vitest';import { render, screen, fireEvent, waitFor } from '@testing-library/react';+import { awaitEnabled } from '../../test/enabledBarrier.js';vi.mock('../../services/api', () => ({getAuthStatus: vi.fn(),@@ -71,7 +72,7 @@ describe('SharingTab — federated media provider (#4348)', () => {});render(<SharingTab />);- await waitFor(() => expect(providerToggle()).toBeEnabled());+ await awaitEnabled(providerToggle);await waitFor(() => expect(screen.getByLabelText('MiniMax model')).toBeInTheDocument());fireEvent.click(providerToggle());fireEvent.click(screen.getByRole('button', { name: 'Save provider' }));@@ -109,7 +110,7 @@ describe('SharingTab — federated media provider (#4348)', () => {},});render(<SharingTab />);- await waitFor(() => expect(providerToggle()).toBeEnabled());+ await awaitEnabled(providerToggle);fireEvent.click(providerToggle());fireEvent.click(screen.getByRole('button', { name: 'Save provider' }));await waitFor(() => expect(updateSettings).toHaveBeenCalledWith(expect.objectContaining({diff --git a/client/src/components/shell/ShellImageDrop.test.jsx b/client/src/components/shell/ShellImageDrop.test.jsxindex d3d700a521..a7d0cd16e9 100644--- a/client/src/components/shell/ShellImageDrop.test.jsx+++ b/client/src/components/shell/ShellImageDrop.test.jsx@@ -1,6 +1,7 @@import { describe, it, expect, vi, beforeEach } from 'vitest';import { render, screen, fireEvent, waitFor } from '@testing-library/react';import ShellImageDrop from './ShellImageDrop';+import { findEnabledByRole } from '../../test/enabledBarrier.js';const toastMock = vi.hoisted(() => ({ error: vi.fn(), success: vi.fn() }));vi.mock('../ui/Toast', () => ({ default: toastMock }));@@ -75,7 +76,7 @@ describe('ShellImageDrop', () => {fireEvent.change(screen.getByLabelText('Message'), { target: { value: 'retry me' } });fireEvent.click(screen.getByRole('button', { name: 'Send' }));- await waitFor(() => expect(screen.getByRole('button', { name: 'Send' })).toBeEnabled());+ await findEnabledByRole('button', { name: 'Send' });expect(screen.getByLabelText('Message').value).toBe('retry me');expect(screen.getByAltText('photo.jpg')).toBeTruthy();});@@ -161,7 +162,7 @@ describe('ShellImageDrop', () => {fireEvent.change(screen.getByLabelText('Message'), { target: { value: 'second ask' } });settle(true);- await waitFor(() => expect(screen.getByRole('button', { name: 'Send' })).toBeEnabled());+ await findEnabledByRole('button', { name: 'Send' });expect(screen.getByLabelText('Message').value).toBe('second ask');expect(screen.getByAltText('second.jpg')).toBeTruthy();});diff --git a/client/src/components/universe/VisionDescribeModal.test.jsx b/client/src/components/universe/VisionDescribeModal.test.jsxindex 84d2b69360..f4f775fcc3 100644--- a/client/src/components/universe/VisionDescribeModal.test.jsx+++ b/client/src/components/universe/VisionDescribeModal.test.jsx@@ -1,6 +1,7 @@import { describe, it, expect, vi } from 'vitest';-import { render, screen, fireEvent, waitFor } from '@testing-library/react';+import { render, screen, fireEvent } from '@testing-library/react';import VisionDescribeModal from './VisionDescribeModal';+import { awaitEnabled } from '../../test/enabledBarrier.js';// One enabled API provider so the action buttons are enabled-by-provider.vi.mock('../../hooks/useProviderModels', () => ({@@ -73,7 +74,7 @@ describe('VisionDescribeModal', () => {target: { files: [new File(['x'], 'up.png', { type: 'image/png' })] },});const buildBtn = screen.getByRole('button', { name: /Build character details/i });- await waitFor(() => expect(buildBtn).not.toBeDisabled());+ await awaitEnabled(buildBtn);fireEvent.click(buildBtn);// Review list renders both proposed fields; edit pronouns and uncheck age.@@ -103,7 +104,7 @@ describe('VisionDescribeModal', () => {});// Describe → prose panel appears.const describeBtn = screen.getByRole('button', { name: /Describe from image/i });- await waitFor(() => expect(describeBtn).not.toBeDisabled());+ await awaitEnabled(describeBtn);fireEvent.click(describeBtn);await screen.findByRole('textbox', { name: /Generated description/i });diff --git a/client/src/components/videoGen/EpisodeComposer.test.jsx b/client/src/components/videoGen/EpisodeComposer.test.jsxindex fe682fa3f9..d009794122 100644--- a/client/src/components/videoGen/EpisodeComposer.test.jsx+++ b/client/src/components/videoGen/EpisodeComposer.test.jsx@@ -2,6 +2,7 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';import EpisodeComposer from './EpisodeComposer';import { MockEventSource, lastEventSource } from '../../test/mockEventSource';+import { awaitEnabled } from '../../test/enabledBarrier.js';vi.mock('../../services/api', () => ({lintContinuousVideoEpisode: vi.fn(),@@ -69,7 +70,7 @@ describe('EpisodeComposer', () => {await waitFor(() => expect(lintContinuousVideoEpisode).toHaveBeenCalled(), { timeout: 2000 });const queueButton = await screen.findByRole('button', { name: /Queue episode/i });- await waitFor(() => expect(queueButton).not.toBeDisabled());+ await awaitEnabled(queueButton);fireEvent.click(queueButton);await waitFor(() => expect(generateContinuousVideoEpisode).toHaveBeenCalled());diff --git a/client/src/pages/AIProviders.test.jsx b/client/src/pages/AIProviders.test.jsxindex 1dcba2bc12..852ce713c2 100644--- a/client/src/pages/AIProviders.test.jsx+++ b/client/src/pages/AIProviders.test.jsx@@ -1,6 +1,7 @@import { describe, it, expect, vi, beforeEach } from 'vitest';import { render, screen, fireEvent, waitFor, within } from '@testing-library/react';import { MemoryRouter, Route, Routes } from 'react-router';+import { findEnabledByRole } from '../test/enabledBarrier.js';const api = vi.hoisted(() => ({getProviders: vi.fn(),@@ -176,7 +177,7 @@ describe('AIProviders page load error handling', () => {{ id: 'codex-tui', name: 'Codex TUI', type: 'tui', command: 'codex', enabled: true, textTransportEnabled: false, executionModes },] });renderPage();- await waitFor(() => expect(screen.getByRole('button', { name: 'Set CLI default' })).toBeEnabled());+ await findEnabledByRole('button', { name: 'Set CLI default' });expect(screen.getByRole('button', { name: 'Set TUI default' })).toBeEnabled();fireEvent.click(screen.getByRole('button', { name: 'Set TUI default' }));await waitFor(() => expect(api.setActiveProvider).toHaveBeenCalledWith('codex-tui'));diff --git a/client/src/pages/Apps.test.jsx b/client/src/pages/Apps.test.jsxindex 3cd7933ffe..504e8fac4f 100644--- a/client/src/pages/Apps.test.jsx+++ b/client/src/pages/Apps.test.jsx@@ -2,6 +2,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';import { act, render, screen, waitFor } from '@testing-library/react';import userEvent from '@testing-library/user-event';import { MemoryRouter } from 'react-router';+import { findEnabledByRole } from '../test/enabledBarrier.js';const APPS = [{@@ -216,7 +217,7 @@ describe('Apps row action hierarchy', () => {expect(screen.getByText('Building…')).toBeTruthy();await act(async () => { resolveBuild({ success: true }); });- await waitFor(() => expect(screen.getByRole('button', { name: 'Build production UI: npm run build' })).toBeEnabled());+ await findEnabledByRole('button', { name: 'Build production UI: npm run build' });});it('opens a plain-HTTP managed app without inheriting PortOS HTTPS', async () => {diff --git a/client/src/pages/CapabilityMap.test.jsx b/client/src/pages/CapabilityMap.test.jsxindex 8e4c452538..9813d7213a 100644--- a/client/src/pages/CapabilityMap.test.jsx+++ b/client/src/pages/CapabilityMap.test.jsx@@ -1,6 +1,7 @@import { describe, expect, it, vi } from 'vitest';import { fireEvent, render, screen, waitFor } from '@testing-library/react';import { MemoryRouter } from 'react-router';+import { awaitEnabled } from '../test/enabledBarrier.js';vi.mock('../hooks/useAutoRefetch', () => ({useAutoRefetch: () => ({@@ -80,6 +81,6 @@ it('saves Tailcat and not-desired choices and retains the saved choice on failurexpect(api.updateSettings).toHaveBeenLastCalledWith({ networkSetupPreference: 'none' }, { silent: true });api.updateSettings.mockRejectedValueOnce(new Error('Save failed'));fireEvent.change(select, { target: { value: 'tailscale' } });- await waitFor(() => expect(select).not.toBeDisabled());+ await awaitEnabled(select);expect(select).toHaveValue('none');});diff --git a/client/src/pages/Eidoverse.test.jsx b/client/src/pages/Eidoverse.test.jsxindex 436be3224b..8a0cd55a9b 100644--- a/client/src/pages/Eidoverse.test.jsx+++ b/client/src/pages/Eidoverse.test.jsx@@ -3,6 +3,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';import { act, fireEvent, render, screen, waitFor, within } from '@testing-library/react';import userEvent from '@testing-library/user-event';import { MemoryRouter } from 'react-router';+import { awaitEnabled, findEnabledByRole } from '../test/enabledBarrier.js';vi.mock('../services/api', () => ({getApp: vi.fn(),@@ -543,7 +544,7 @@ describe('Eidoverse hosted page', () => {await user.type(nameInput, '-edited');resolveSave({ ...worldResponse, human: worldResponse.identity });- await waitFor(() => expect(screen.getByRole('button', { name: 'Save and project' })).toBeEnabled());+ await findEnabledByRole('button', { name: 'Save and project' });expect(nameInput).toHaveValue('example-portos-user-edited');expect(screen.queryByText('Saved locally and queued for projection.')).not.toBeInTheDocument();});@@ -649,7 +650,7 @@ describe('Eidoverse hosted page', () => {design: { ...design, reconciliation: { status: 'complete', checkpoint: 'projection-committed' } },recipe,});- await waitFor(() => expect(refresh).toBeEnabled());+ await awaitEnabled(refresh);});it('keeps a fresh-world curtain up until the dawn environment is applied', async () => {@@ -763,7 +764,7 @@ describe('Eidoverse hosted page', () => {expect(screen.getByLabelText('Sun hour')).toHaveValue(8.4);const save = screen.getByRole('button', { name: 'Save and project' });- await waitFor(() => expect(save).toBeEnabled());+ await awaitEnabled(save);expect([...save.closest('form').elements].filter((element) => typeof element.checkValidity === 'function' && !element.checkValidity()).map((element) => ({ id: element.id, value: element.value, validationMessage: element.validationMessage })))@@ -806,7 +807,7 @@ describe('Eidoverse hosted page', () => {await user.click(screen.getByRole('button', { name: 'Save and project' }));await waitFor(() => expect(api.updateEidoverseWorldConfig).toHaveBeenCalledOnce());await waitFor(() => expect(api.projectEidoverseWorld).toHaveBeenCalledTimes(2));- await waitFor(() => expect(apply).toBeEnabled());+ await awaitEnabled(apply);expect(refresh).toBeEnabled();expect(screen.getByRole('button', { name: 'Refresh world' })).toBeEnabled();});@@ -821,7 +822,7 @@ describe('Eidoverse hosted page', () => {await user.clear(screen.getByLabelText('Exposure'));await user.clear(screen.getByLabelText('Grass density'));const save = screen.getByRole('button', { name: 'Save and project' });- await waitFor(() => expect(save).toBeEnabled());+ await awaitEnabled(save);fireEvent.submit(save.closest('form'));await waitFor(() => expect(api.updateEidoverseWorldConfig).toHaveBeenCalledOnce());@@ -870,7 +871,7 @@ describe('Eidoverse hosted page', () => {expect(screen.getByText(legacyPath)).toBeInTheDocument();const clear = screen.getByRole('button', { name: 'Clear legacy Feature override' });- await waitFor(() => expect(clear).toBeEnabled());+ await awaitEnabled(clear);await user.click(clear);expect(screen.queryByRole('button', { name: 'Clear legacy Feature override' })).not.toBeInTheDocument();diff --git a/client/src/pages/FableLoomStory.test.jsx b/client/src/pages/FableLoomStory.test.jsxindex bd91535331..f0d1a4008a 100644--- a/client/src/pages/FableLoomStory.test.jsx+++ b/client/src/pages/FableLoomStory.test.jsx@@ -2,6 +2,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';import { render, screen, waitFor, within } from '@testing-library/react';import { MemoryRouter, Route, Routes } from 'react-router';import userEvent from '@testing-library/user-event';+import { findEnabledByRole } from '../test/enabledBarrier.js';const toastMocks = vi.hoisted(() => ({ error: vi.fn(), success: vi.fn(), warning: vi.fn() }));vi.mock('../components/ui/Toast', () => ({ default: toastMocks }));@@ -407,8 +408,7 @@ describe('FableLoomStory scene media lifecycle', () => {api.generateImage.mockResolvedValue({ jobId: 'image-job-1', status: 'queued' });renderEditor();- const generate = await screen.findByRole('button', { name: 'Canvas generate image' });- await waitFor(() => expect(generate).toBeEnabled());+ const generate = await findEnabledByRole('button', { name: 'Canvas generate image' });await user.click(generate);await waitFor(() => expect(api.generateImage).toHaveBeenCalledTimes(1));diff --git a/client/src/pages/MediaAnnotate.test.jsx b/client/src/pages/MediaAnnotate.test.jsxindex 52064a9f67..1539a3d522 100644--- a/client/src/pages/MediaAnnotate.test.jsx+++ b/client/src/pages/MediaAnnotate.test.jsx@@ -2,6 +2,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';import { render, screen, fireEvent, waitFor, within } from '@testing-library/react';import { MemoryRouter, Routes, Route } from 'react-router';import MediaAnnotate from './MediaAnnotate';+import { awaitEnabled } from '../test/enabledBarrier.js';// Re-render (issue #2036 phase 2) is the focus: annotate an image, then feed the// flattened markup back through img2img. The canvas itself is exercised by@@ -71,8 +72,7 @@ describe('MediaAnnotate re-render with annotations', () => {renderPage();// The button enables once the canvas reports dims AND saved strokes load.- const btn = await screen.findByTitle('Re-render this image guided by your annotations');- await waitFor(() => expect(btn).not.toBeDisabled());+ const btn = await awaitEnabled(() => screen.getByTitle('Re-render this image guided by your annotations'));fireEvent.click(btn);// Provider/model is visible before any AI call (no cold-bootstrap).@@ -97,8 +97,7 @@ describe('MediaAnnotate re-render with annotations', () => {getRegenAvailability.mockResolvedValue({ available: false, reason: 'No local FLUX runner installed.' });renderPage();- const btn = await screen.findByTitle('Re-render this image guided by your annotations');- await waitFor(() => expect(btn).not.toBeDisabled());+ const btn = await awaitEnabled(() => screen.getByTitle('Re-render this image guided by your annotations'));fireEvent.click(btn);expect(await screen.findByText('No local FLUX runner installed.')).toBeInTheDocument();@@ -133,8 +132,7 @@ describe('MediaAnnotate blank-canvas sketch (phase 3)', () => {// No img2img availability probe for a blank canvas.expect(getRegenAvailability).not.toHaveBeenCalled();- const saveBtn = await screen.findByTitle('Save sketch');- await waitFor(() => expect(saveBtn).not.toBeDisabled());+ const saveBtn = await awaitEnabled(() => screen.getByTitle('Save sketch'));fireEvent.click(saveBtn);await waitFor(() => expect(saveMediaSketch).toHaveBeenCalledTimes(1));expect(saveMediaSketch).toHaveBeenCalledWith(@@ -151,8 +149,7 @@ describe('MediaAnnotate blank-canvas sketch (phase 3)', () => {['invalid dimensions', '?w=invalid&h=Infinity', 1024, 1024],])('saves the canvas size for %s', async (_label, search, width, height) => {renderBlank(search);- const saveBtn = await screen.findByTitle('Save sketch');- await waitFor(() => expect(saveBtn).not.toBeDisabled());+ const saveBtn = await awaitEnabled(() => screen.getByTitle('Save sketch'));fireEvent.click(saveBtn);await waitFor(() => expect(saveMediaSketch).toHaveBeenCalledWith('sketch:11111111-1111-1111-1111-111111111111',diff --git a/client/src/pages/MusicVideo.test.jsx b/client/src/pages/MusicVideo.test.jsxindex 09f885f3ae..cb2713b83a 100644--- a/client/src/pages/MusicVideo.test.jsx+++ b/client/src/pages/MusicVideo.test.jsx@@ -4,6 +4,7 @@*/import { describe, it, expect, vi, beforeEach } from 'vitest';import { render, screen, waitFor, fireEvent, within, act } from '@testing-library/react';+import { findEnabledByRole } from '../test/enabledBarrier.js';import { MemoryRouter, Routes, Route, useNavigate, useLocation } from 'react-router';import toast from '../components/ui/Toast';@@ -486,8 +487,7 @@ describe('MusicVideo restricted-model license gate', () => {generateVideo.mockResolvedValue({ jobId: 'gated-job' });await openProject(PROJECT_NO_CLIP);- const generate = await screen.findByRole('button', { name: /^Generate video$/ });- await waitFor(() => expect(generate).toBeEnabled());+ const generate = await findEnabledByRole('button', { name: /^Generate video$/ });expect(screen.queryByRole('checkbox', { name: /I am eligible/ })).toBeNull();fireEvent.click(generate);await waitFor(() => expect(generateVideo).toHaveBeenCalled());diff --git a/client/src/pages/QuotaBurn.test.jsx b/client/src/pages/QuotaBurn.test.jsxindex 4bc93ee3b6..543e2ba5a7 100644--- a/client/src/pages/QuotaBurn.test.jsx+++ b/client/src/pages/QuotaBurn.test.jsx@@ -1,5 +1,6 @@import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';import { act, render, screen, waitFor } from '@testing-library/react';+import { findEnabledByLabelText, findEnabledByRole } from '../test/enabledBarrier.js';import userEvent from '@testing-library/user-event';import { MemoryRouter, Route, Routes } from 'react-router';import QuotaBurn, { PENDING_POLL_MS, SAVE_DEBOUNCE_MS } from './QuotaBurn';@@ -458,7 +459,7 @@ describe('QuotaBurn page', () => {expect(screen.getByLabelText('Run step 1 now')).toBeDisabled();expect(screen.getByRole('button', { name: 'Evaluate now' })).toBeDisabled();await flushSave();- await waitFor(() => expect(screen.getByLabelText('Run step 1 now')).toBeEnabled());+ await findEnabledByLabelText('Run step 1 now');});it('removes a burn step without deleting the scheduled task it referenced', async () => {@@ -655,7 +656,7 @@ describe('QuotaBurn save debounce', () => {await flushSave();expect(api.saveQuotaBurn).toHaveBeenCalledTimes(1);expect(api.saveQuotaBurn.mock.calls[0][0].families.grok.jobs[0].label).toBe('Bible imagesabc');- await waitFor(() => expect(screen.getByRole('button', { name: /Evaluate now/ })).not.toBeDisabled());+ await findEnabledByRole('button', { name: /Evaluate now/ });});});diff --git a/client/src/pages/StackerNews.test.jsx b/client/src/pages/StackerNews.test.jsxindex 1a423c1b0a..0156e5125e 100644--- a/client/src/pages/StackerNews.test.jsx+++ b/client/src/pages/StackerNews.test.jsx@@ -3,6 +3,7 @@ import { act, render, screen, waitFor, within } from '@testing-library/react';import userEvent from '@testing-library/user-event';import { MemoryRouter, Route, Routes, useLocation } from 'react-router';import { clearSettled, retypeSettled, typeSettled } from '../test/settledInput';+import { findEnabledByRole } from '../test/enabledBarrier.js';const api = {getStackerNewsAccounts: vi.fn(),@@ -250,7 +251,7 @@ describe('StackerNews', () => {await user.click(screen.getByRole('button', { name: 'Save account' }));expect(screen.getByRole('button', { name: 'Sync now' })).toBeDisabled();await act(async () => save.resolve({ ...accounts[0], monitoringIntervalMinutes: 20 }));- await waitFor(() => expect(screen.getByRole('button', { name: 'Sync now' })).toBeEnabled());+ await findEnabledByRole('button', { name: 'Sync now' });});it('discards an unsaved account draft left behind by closing the drawer', async () => {diff --git a/client/src/pages/StartStory.test.jsx b/client/src/pages/StartStory.test.jsxindex 2a8037fc6d..7241a29028 100644--- a/client/src/pages/StartStory.test.jsx+++ b/client/src/pages/StartStory.test.jsx@@ -1,6 +1,7 @@import { describe, it, expect, vi, beforeEach } from 'vitest';import { render, screen, fireEvent, waitFor } from '@testing-library/react';import StartStory from './StartStory';+import { findEnabledByLabelText } from '../test/enabledBarrier.js';const navigateMock = vi.hoisted(() => vi.fn());vi.mock('react-router', async (io) => {@@ -20,19 +21,16 @@ vi.mock('../components/ui/Toast', () => ({// Opt into "use an existing universe" and return the picker it renders.//-// The universe list gates that radio — it renders `disabled` until a NAMED-// universe lands — but all three mode cards come from a static list and are on-// screen synchronously. Waiting on card text therefore resolves on the FIRST-// poll, before the fetch: the click then lands on a disabled radio, silently-// does nothing, and the next `findBy*` burns the whole async budget waiting for-// a select that will never render (#7592, the #7448 wrong-barrier shape).+// The radio is gated by the async universe list, but all three mode cards+// come from a static list and are on screen synchronously — a helper that+// waited on card text would resolve before the fetch and click a+// still-disabled radio (#7592). See enabledBarrier.js for the general hazard.//// Returning the select rather than nothing is deliberate — it makes the helper// assert that opting in actually TOOK, so it stays honest even if the// `disabled` gate it waits on is ever removed.const openExistingUniversePicker = async () => {- const radio = await screen.findByLabelText('Use an existing universe');- await waitFor(() => expect(radio).not.toBeDisabled());+ const radio = await findEnabledByLabelText('Use an existing universe');fireEvent.click(radio);return screen.findByLabelText('Existing universe');};diff --git a/client/src/pages/VideoGen.composeWhileBusy.test.jsx b/client/src/pages/VideoGen.composeWhileBusy.test.jsxindex c5d9f854db..730fefc176 100644--- a/client/src/pages/VideoGen.composeWhileBusy.test.jsx+++ b/client/src/pages/VideoGen.composeWhileBusy.test.jsx@@ -1,5 +1,6 @@import { beforeEach, describe, expect, it, vi } from 'vitest';import { fireEvent, screen, waitFor } from '@testing-library/react';+import { findEnabledByRole } from '../test/enabledBarrier.js';import {loadVideoGenPage,@@ -43,7 +44,7 @@ describe('VideoGen compose-while-busy', () => {const prompt = await screen.findByLabelText('Prompt');fireEvent.change(prompt, { target: { value: 'a fox watches the rain' } });- await waitFor(() => expect(screen.getByRole('button', { name: /^Generate$/ })).toBeEnabled());+ await findEnabledByRole('button', { name: /^Generate$/ });fireEvent.click(screen.getByRole('button', { name: /^Generate$/ }));await waitFor(() => expect(screen.getByRole('button', { name: /Cancel/i })).toBeInTheDocument());@@ -69,7 +70,7 @@ describe('VideoGen compose-while-busy', () => {const prompt = await screen.findByLabelText('Prompt');fireEvent.change(prompt, { target: { value: 'a fox watches the rain' } });- await waitFor(() => expect(screen.getByRole('button', { name: /^Generate$/ })).toBeEnabled());+ await findEnabledByRole('button', { name: /^Generate$/ });fireEvent.click(screen.getByRole('button', { name: /^Generate$/ }));await waitFor(() => expect(screen.getByRole('button', { name: /Cancel/i })).toBeInTheDocument());diff --git a/client/src/pages/VideoGen.displaySleep.test.jsx b/client/src/pages/VideoGen.displaySleep.test.jsxindex 908c8dc00f..1efa235d87 100644--- a/client/src/pages/VideoGen.displaySleep.test.jsx+++ b/client/src/pages/VideoGen.displaySleep.test.jsx@@ -1,5 +1,6 @@import { beforeEach, describe, expect, it } from 'vitest';import { fireEvent, screen, waitFor } from '@testing-library/react';+import { findEnabledByRole } from '../test/enabledBarrier.js';import {loadVideoGenPage,@@ -23,7 +24,7 @@ await loadVideoGenPage();// field the render was actually submitted with.const submitAndGetDisplaySleep = async () => {fireEvent.change(await screen.findByLabelText('Prompt'), { target: { value: 'a fox watches the rain' } });- await waitFor(() => expect(screen.getByRole('button', { name: /Add to queue/ })).toBeEnabled());+ await findEnabledByRole('button', { name: /Add to queue/ });fireEvent.click(screen.getByRole('button', { name: /Add to queue/ }));await waitFor(() => expect(state.generateVideo).toHaveBeenCalled());return state.generateVideo.mock.calls[0][0].displaySleep;diff --git a/client/src/pages/VideoGen.federatedTarget.test.jsx b/client/src/pages/VideoGen.federatedTarget.test.jsxindex acec56fd2c..ba11ad5783 100644--- a/client/src/pages/VideoGen.federatedTarget.test.jsx+++ b/client/src/pages/VideoGen.federatedTarget.test.jsx@@ -1,5 +1,6 @@import { beforeEach, describe, expect, it } from 'vitest';import { act, fireEvent, screen, waitFor } from '@testing-library/react';+import { findEnabledByRole } from '../test/enabledBarrier.js';import {loadVideoGenPage,@@ -62,7 +63,7 @@ describe('VideoGen federated render target', () => {it('submits the peer, its engine and its model — and no local-only fields', async () => {await startRender();fireEvent.change(await screen.findByRole('combobox', { name: /generation target/i }), { target: { value: 'peer-example' } });- await waitFor(() => expect(screen.getByRole('button', { name: /^Generate$/ })).toBeEnabled());+ await findEnabledByRole('button', { name: /^Generate$/ });await act(async () => { fireEvent.click(screen.getByRole('button', { name: /^Generate$/ })); });@@ -103,7 +104,7 @@ describe('VideoGen federated render target', () => {it('lets image mode be selected on a peer, since a mode alone conditions nothing', async () => {await startRender();fireEvent.change(await screen.findByRole('combobox', { name: /generation target/i }), { target: { value: 'peer-example' } });- await waitFor(() => expect(screen.getByRole('button', { name: /^Generate$/ })).toBeEnabled());+ await findEnabledByRole('button', { name: /^Generate$/ });fireEvent.click(screen.getByRole('button', { name: /^Image$/ }));@@ -119,7 +120,7 @@ describe('VideoGen federated render target', () => {it.each([['Extend'], ['Audio']])('blocks %s mode, which cannot cross at all', async (label) => {await startRender();fireEvent.change(await screen.findByRole('combobox', { name: /generation target/i }), { target: { value: 'peer-example' } });- await waitFor(() => expect(screen.getByRole('button', { name: /^Generate$/ })).toBeEnabled());+ await findEnabledByRole('button', { name: /^Generate$/ });fireEvent.click(screen.getByRole('button', { name: new RegExp(`^${label}$`) }));diff --git a/client/src/pages/VideoGen.reactor.test.jsx b/client/src/pages/VideoGen.reactor.test.jsxindex cb9fb60d3b..7e5cdab03e 100644--- a/client/src/pages/VideoGen.reactor.test.jsx+++ b/client/src/pages/VideoGen.reactor.test.jsx@@ -1,5 +1,6 @@import { beforeEach, describe, expect, it } from 'vitest';import { act, fireEvent, screen, waitFor } from '@testing-library/react';+import { findEnabledByRole } from '../test/enabledBarrier.js';import {loadVideoGenPage,@@ -44,7 +45,7 @@ const selectReactor = async () => {};const submit = async () => {- await waitFor(() => expect(screen.getByRole('button', { name: /Add to queue/ })).toBeEnabled());+ await findEnabledByRole('button', { name: /Add to queue/ });fireEvent.click(screen.getByRole('button', { name: /Add to queue/ }));await waitFor(() => expect(state.generateVideo).toHaveBeenCalled());return state.generateVideo.mock.calls[0][0];@@ -77,7 +78,7 @@ describe('VideoGen reactor.inc lane', () => {expect(screen.getByRole('button', { name: /Add to queue/ })).toBeDisabled();fireEvent.change(promptField, { target: { value: 'x'.repeat(REACTOR_MAX_PROMPT_LENGTH) } });- await waitFor(() => expect(screen.getByRole('button', { name: /Add to queue/ })).toBeEnabled());+ await findEnabledByRole('button', { name: /Add to queue/ });});// Enhancing to exactly 800 characters still gets rejected once the stylediff --git a/client/src/pages/VideoGen.terms.test.jsx b/client/src/pages/VideoGen.terms.test.jsxindex e3fc1f78d6..c37a5cbb8f 100644--- a/client/src/pages/VideoGen.terms.test.jsx+++ b/client/src/pages/VideoGen.terms.test.jsx@@ -1,5 +1,6 @@import { beforeEach, describe, expect, it } from 'vitest';import { act, fireEvent, screen, waitFor } from '@testing-library/react';+import { awaitEnabled } from '../test/enabledBarrier.js';import {loadVideoGenPage,@@ -49,7 +50,7 @@ describe('VideoGen MiniMax H3 orchestration', () => {expect(screen.queryByText(/eligibility and terms/i)).toBeNull();fireEvent.change(prompt(), { target: { value: 'a fox watches the rain' } });- await waitFor(() => expect(enqueue()).toBeEnabled());+ await awaitEnabled(enqueue);fireEvent.click(enqueue());await waitFor(() => expect(state.generateVideo).toHaveBeenCalledWith(expect.objectContaining({modelId: H3_ONE.id,diff --git a/client/src/pages/VideoGen.weightIntegrity.test.jsx b/client/src/pages/VideoGen.weightIntegrity.test.jsxindex 38df1e02cb..ff70baae99 100644--- a/client/src/pages/VideoGen.weightIntegrity.test.jsx+++ b/client/src/pages/VideoGen.weightIntegrity.test.jsx@@ -1,5 +1,6 @@import { beforeEach, describe, expect, it } from 'vitest';import { fireEvent, screen, waitFor, within } from '@testing-library/react';+import { awaitEnabled } from '../test/enabledBarrier.js';import {loadVideoGenPage, renderVideoGenPage, resetVideoGenMockState, state,videoGenModel, videoGenModelContext, videoGenStatus,@@ -99,7 +100,7 @@ describe('VideoGen downloadable asset integrity', () => {await renderVideoGenPage();refreshRender();fireEvent.click(await screen.findByRole('button', { name: 'Grok', exact: true }));- await waitFor(() => expect(generate()).toBeEnabled());+ await awaitEnabled(generate);const banner = screen.getByRole('group', { name: 'Repair encoder', exact: true });expect(banner).toHaveTextContent('shared text encoder');expect(banner).not.toHaveTextContent('undefined');diff --git a/client/src/test/README.md b/client/src/test/README.mdnew file mode 100644index 0000000000..fba7066718--- /dev/null+++ b/client/src/test/README.md@@ -0,0 +1,30 @@+# client/src/test/++Shared test helpers for the client suite. Deliberately **not** a barrel — these are+test-only utilities, kept out of the enforced browser barrel described in the root+`AGENTS.md` Module Organization section on purpose (see the comments atop+`pageNavTabAssertions.js` / `ariaRefAssertions.js`). Grep this table before writing+a new one.++| File | What it's for |+| --- | --- |+| `ariaRefAssertions.js` | Asserts a rendered tree's `aria-controls`/`aria-labelledby` IDREFs all resolve to a real element. |+| `classNameScan.js` | Shared string-literal scanner (comment-stripping + literal walk) for the class-string convention guards. |+| `dndKeyboardDrag.js` | Drives a real `@dnd-kit` keyboard drag under happy-dom, stubbing the layout happy-dom can't provide. |+| `downloadPreflightConfirm.js` | `clickStartDownload` — waits for the confirm button to be enabled (built on `enabledBarrier.js`) before clicking, then settles. |+| `enabledBarrier.js` | `awaitEnabled` / `findEnabledByLabelText` / `findEnabledByRole` — wait for a control to be enabled, not just present, before interacting. |+| `fakeAudioContext.js` | Minimal Web Audio fake for playback tests (jsdom/node have no Web Audio). |+| `formValidityPolyfill.js` | Fixes happy-dom's constraint-validation (`stepMismatch`) so implicit form submission behaves like a real browser. |+| `imageGenPageMocks.jsx` | Shared `vi.mock` scaffold + fixtures + `renderImageGenPage()` for the ImageGen page suites. |+| `mockEventSource.js` | Minimal `EventSource` stand-in for jsdom, with manual `emit`/`emitRaw`/`fail` control. |+| `pageLoadBarrier.js` | `awaitPageLoaded` — waits for a page's loading skeleton (by its accessible label) to be removed. |+| `pageNavTabAssertions.js` | Pins a tabbed page's rendered tab id/label list against drift from the nav manifest it was built from. |+| `settledInput.js` | `typeSettled`/`clearSettled`/`retypeSettled` — waits for a controlled input's value to actually reflect the typed text before it's read. |+| `setup.js` | Vitest setup (auto-loaded): jest-dom matchers, the storage/form-validity polyfills, and the suite-wide async timeout. |+| `storagePolyfill.js` | In-memory `Storage` polyfill installed when the test environment's real one is absent or unusable. |+| `stripComments.js` | Blanks block/line comments out of a source string for the tree-wide convention guards that grep source. |+| `swSandbox.js` | Evaluates the real `public/sw.js` in an isolated vm sandbox to exercise its event listeners directly. |+| `timeouts.js` | `ASYNC_UTIL_TIMEOUT_MS` / `TEST_TIMEOUT_MS` — the suite's async time budgets, defined once so the ordering can't drift apart. |+| `trackedFiles.js` | Shared git-tracked file walker for the repo-hygiene guards. |+| `videoGenPageMocks.jsx` | Shared `vi.mock` scaffold + fixtures + `renderVideoGenPage()` for the VideoGen page suites. |+| `voiceHotkeySpy.js` | Stand-in for the voice widget's app-global push-to-talk hotkey, for asserting a surface claimed/didn't leak a key. |diff --git a/client/src/test/downloadPreflightConfirm.js b/client/src/test/downloadPreflightConfirm.jsindex d084afb5cc..fd14570195 100644--- a/client/src/test/downloadPreflightConfirm.js+++ b/client/src/test/downloadPreflightConfirm.js@@ -1,23 +1,16 @@-import { act, fireEvent, screen, waitFor } from '@testing-library/react';-import { expect } from 'vitest';+import { act, fireEvent, screen } from '@testing-library/react';+import { awaitEnabled } from './enabledBarrier.js';// DownloadPreflightConfirm renders its confirm button the instant the modal// opens — disabled, mid-`loading` — and only enables it once the preview()-// promise settles the size/destination assessment (#6266). `findByRole`-// matches a disabled button too, so `fireEvent.click(await-// screen.findByRole('button', { name: 'Start download' }))` can land on the-// still-disabled button under CPU contention and silently no-op. Wait for-// enabled, not just present, before clicking — then settle with-// `act(async () => {})`, because waiting the extra tick for "enabled" is-// itself enough to leave the confirm handler's own promise chain (e.g. the-// status reload a successful install kicks off) unflushed past whatever the-// caller asserts next.+// promise settles the size/destination assessment (#6266). See+// enabledBarrier.js for why this waits for enabled rather than just present.+// Settle with `act(async () => {})` afterward, because waiting the extra tick+// for "enabled" is itself enough to leave the confirm handler's own promise+// chain (e.g. the status reload a successful install kicks off) unflushed+// past whatever the caller asserts next.export async function clickStartDownload(name = 'Start download') {- const button = await waitFor(() => {- const el = screen.getByRole('button', { name });- expect(el).toBeEnabled();- return el;- });+ const button = await awaitEnabled(() => screen.getByRole('button', { name }));fireEvent.click(button);await act(async () => {});return button;diff --git a/client/src/test/enabledBarrier.js b/client/src/test/enabledBarrier.jsnew file mode 100644index 0000000000..14a77b37a5--- /dev/null+++ b/client/src/test/enabledBarrier.js@@ -0,0 +1,31 @@+import { screen, waitFor } from '@testing-library/react';+import { expect } from 'vitest';++// `findBy*`/`getBy*` match a DISABLED control too — they only assert it is on+// screen, never that it is safe to interact with. A page that renders a+// control the instant it mounts and enables it only once some async gate+// resolves (a fetch, a capability scan, a `draftReady` flag) leaves a naive+// `fireEvent.click(await screen.findByRole(...))` free to land on the+// still-disabled control under CPU contention: the click silently no-ops, and+// whatever the test asserts next burns its own async budget waiting on+// something that will never happen (#7448, #7592, #6266).+//+// Wait for ENABLED, not just present, before interacting. Kept one-sided —+// this only ever asserts the eventual enabled state, never that the control+// started out disabled — on purpose: a two-sided form is racy, because the+// gate can legitimately have cleared before the first poll. That is exactly+// how the analogous `waitForElementToBeRemoved` barrier failed during #7592+// (see `pageLoadBarrier.js`, which stayed two-sided for a different reason).++// Pass a getter (`() => screen.getByRole(...)`) when the control may not+// exist yet or may be replaced across renders — `waitFor` re-invokes it on+// every poll. Pass a plain element when it is already known to be mounted.+export const awaitEnabled = (elementOrGetter) => waitFor(() => {+ const el = typeof elementOrGetter === 'function' ? elementOrGetter() : elementOrGetter;+ expect(el).toBeEnabled();+ return el;+});++export const findEnabledByLabelText = (label) => awaitEnabled(() => screen.getByLabelText(label));++export const findEnabledByRole = (role, options) => awaitEnabled(() => screen.getByRole(role, options));