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: make stale-response client tests flush before asserting absence (#11890)
Adam Eivyd0188a3cab4f
diff --git a/client/src/components/decks/DeckStyleSources.test.jsx b/client/src/components/decks/DeckStyleSources.test.jsxindex 652b4a58f7..0b9dc85d38 100644--- a/client/src/components/decks/DeckStyleSources.test.jsx+++ b/client/src/components/decks/DeckStyleSources.test.jsx@@ -1,4 +1,4 @@-import { fireEvent, render, screen, waitFor } from '@testing-library/react';+import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';import { beforeEach, describe, expect, it, vi } from 'vitest';import DeckStyleSources from './DeckStyleSources';import { getUniverse, listMoodBoardNames, synthesizeMoodBoardStyle } from '../../services/api';@@ -36,8 +36,8 @@ describe('Deck style imports', () => {getUniverse.mockReturnValueOnce(new Promise((done) => { resolve = done; }));fireEvent.click(screen.getByRole('button', { name: 'Re-import universe style' }));view.unmount();- resolve({ styleNotes: 'Stale style' });- await waitFor(() => expect(onPatch).not.toHaveBeenCalled());+ await act(async () => { resolve({ styleNotes: 'Stale style' }); });+ expect(onPatch).not.toHaveBeenCalled();});it('previews mood board synthesis and keeps adoption open when saving fails', async () => {diff --git a/client/src/components/instances/PeerAdministrationPanel.test.jsx b/client/src/components/instances/PeerAdministrationPanel.test.jsxindex 36df62327b..bb842c30df 100644--- a/client/src/components/instances/PeerAdministrationPanel.test.jsx+++ b/client/src/components/instances/PeerAdministrationPanel.test.jsx@@ -72,8 +72,8 @@ describe('planning-only peer administration', () => {const view = render(<PeerAdministrationPanel peer={peer} />);fireEvent.click(screen.getByRole('button', { name: /Peer administration/ }));view.rerender(<PeerAdministrationPanel peer={{ ...peer, instanceId: '33333333-3333-4333-8333-333333333333' }} />);- resolveOld(setup);- await waitFor(() => expect(screen.queryByText(setup.hostInstanceId)).toBeNull());+ await act(async () => { resolveOld(setup); });+ expect(screen.queryByText(setup.hostInstanceId)).toBeNull();expect(savePeerAdminGrant).not.toHaveBeenCalled();});});diff --git a/client/src/components/musicVideo/ReviewDraftPanel.test.jsx b/client/src/components/musicVideo/ReviewDraftPanel.test.jsxindex c227f14088..af81f6b2e0 100644--- a/client/src/components/musicVideo/ReviewDraftPanel.test.jsx+++ b/client/src/components/musicVideo/ReviewDraftPanel.test.jsx@@ -1,5 +1,5 @@import { afterEach, describe, expect, it, vi } from 'vitest';-import { fireEvent, render, screen, waitFor } from '@testing-library/react';+import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';import ReviewDraftPanel from './ReviewDraftPanel.jsx';const artifact = (id, day, version) => {@@ -41,7 +41,8 @@ describe('implicit imported draft review', () => {await waitFor(() => expect(finishOld).toBeTypeOf('function'));rerender(<ReviewDraftPanel project={{ id: 'other', devArtifacts: [artifact('old', '01', 2)] }} onOpen={vi.fn()} />);expect(await screen.findByLabelText('old film v2')).toHaveAttribute('src', '/api/music-video/other/dev-artifacts/old/file?version=2');- finishOld({ ok: true });- await waitFor(() => expect(screen.queryByLabelText('new film v3')).toBeNull());+ await act(async () => { finishOld({ ok: true }); });+ expect(screen.queryByLabelText('new film v3')).toBeNull();+ expect(screen.getByLabelText('old film v2')).toBeInTheDocument();});});diff --git a/client/src/components/musicVideo/SharingCopyPanel.test.jsx b/client/src/components/musicVideo/SharingCopyPanel.test.jsxindex ca8b7cc235..7f3b04135f 100644--- a/client/src/components/musicVideo/SharingCopyPanel.test.jsx+++ b/client/src/components/musicVideo/SharingCopyPanel.test.jsx@@ -1,5 +1,5 @@import { afterEach, beforeEach, expect, it, vi } from 'vitest';-import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';+import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';import SharingCopyPanel from './SharingCopyPanel.jsx';const { api, sse } = vi.hoisted(() => ({ api: {@@ -59,7 +59,8 @@ it('isolates a delayed lookup when navigating to another final render', async ()const view = render(<SharingCopyPanel key="old" projectId="mv-old" />);view.rerender(<SharingCopyPanel key="new" projectId="mv-new" />);await screen.findByRole('button', { name: 'Prepare sharing copy' });- resolveOld({ copy: { bytes: 10, width: 10, height: 10, fps: 10 }, jobId: 'old-job' });- await waitFor(() => expect(screen.queryByRole('link', { name: 'Download sharing copy' })).not.toBeInTheDocument());+ await act(async () => { resolveOld({ copy: { bytes: 10, width: 10, height: 10, fps: 10 }, jobId: 'old-job' }); });+ expect(screen.queryByRole('link', { name: 'Download sharing copy' })).not.toBeInTheDocument();+ expect(screen.getByRole('button', { name: 'Prepare sharing copy' })).toBeInTheDocument();expect(screen.queryByRole('button', { name: 'Cancel export' })).not.toBeInTheDocument();});diff --git a/client/src/pages/PromptManager.test.jsx b/client/src/pages/PromptManager.test.jsxindex 5a60a6b0b4..a3bcbb1d09 100644--- a/client/src/pages/PromptManager.test.jsx+++ b/client/src/pages/PromptManager.test.jsx@@ -989,9 +989,10 @@ describe('PromptManager job skill unsaved-edit guard', () => {fireEvent.click(screen.getByRole('button', { name: /preview/i }));fireEvent.click(screen.getByText('doc-writer'));await screen.findByText('Job doc-writer');- resolvePreview({ preview: 'code-fixer rendered' });+ await act(async () => { resolvePreview({ preview: 'code-fixer rendered' }); });- await waitFor(() => expect(screen.queryByText('code-fixer rendered')).toBeNull());+ expect(screen.queryByText('code-fixer rendered')).toBeNull();+ expect(screen.getByText('Job doc-writer')).toBeTruthy();});it('does not prompt when a clean editor switches skills', async () => {diff --git a/client/src/staleResponseTestConventions.test.js b/client/src/staleResponseTestConventions.test.jsnew file mode 100644index 0000000000..41384ece4b--- /dev/null+++ b/client/src/staleResponseTestConventions.test.js@@ -0,0 +1,104 @@+// @vitest-environment node++/**+ * Repo-wide guard: a stale-response test must flush before it asserts absence.+ *+ * The vacuous shape:+ *+ * resolveOld(payload);+ * await waitFor(() => expect(screen.queryByText('old')).toBeNull());+ *+ * `waitFor` runs its callback once synchronously, before the resolved+ * promise's continuation has run, so the absence check passes on the first try+ * and the test stays green with the staleness guard deleted (#11890: four+ * guards in DeckStyleSources, PeerAdministrationPanel, useMusicVideoReviewDraft+ * and PromptManager were uncovered this way).+ *+ * Fix: `await act(async () => { resolveOld(payload); });` then assert+ * synchronously, ideally followed by a positive assertion about the current+ * record that must survive the flush. A waitFor is only legitimate when the+ * absent thing is PRESENT before the trigger, so it really waits.+ *+ * ## What this guard CANNOT see+ *+ * Lexical scan: a bare `resolve*(`/`finish*(` statement followed within two+ * lines by `await waitFor(() => expect(...)` with `.not` or `toBeNull()`.+ * Other resolver names, multi-line waitFor bodies, and `await`ed or+ * act-wrapped resolves are not examined.+ */++import { describe, it, expect } from 'vitest';+import { readFileSync } from 'fs';+import { join, dirname } from 'path';+import { fileURLToPath } from 'url';+import { execSync } from 'child_process';++const CLIENT_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');++const BARE_RESOLVE = /^\s*(?:resolve|finish)\w*\(/;+const ABSENCE_WAIT = /await waitFor\(\(\) => expect\(.*(?:\.not\.|toBeNull\(\))/;+const LOOKAHEAD = 2;++/** Zero-based indexes of vacuous waitFor lines in `source`. */+const findVacuousAbsenceWaits = (source) => {+ const lines = source.split('\n');+ const hits = [];+ lines.forEach((line, i) => {+ if (!BARE_RESOLVE.test(line)) return;+ for (let j = i + 1; j <= i + LOOKAHEAD && j < lines.length; j += 1) {+ if (ABSENCE_WAIT.test(lines[j])) { hits.push(j); break; }+ }+ });+ return hits;+};++/** `file:line` -> reason the waitFor is real (the absent state is present before the trigger). */+const ALLOWED = {+ 'src/pages/SongBookViewer.test.jsx:1057': 'the editor sheet is open (Content label present) until the save settles, so waitFor genuinely waits',+};++// Git-tracked only, so an untracked scratch file can't fail the suite.+const testFiles = () => execSync('git ls-files src', { cwd: CLIENT_ROOT, encoding: 'utf8' })+ .trim().split('\n').filter((f) => /\.test\.jsx?$/.test(f));++describe('stale-response tests flush before asserting absence', () => {+ it('has no un-flushed absence waitFor after a bare resolve', () => {+ const files = testFiles();+ expect(files.length).toBeGreaterThan(100);+ const violations = files.flatMap((file) =>+ findVacuousAbsenceWaits(readFileSync(join(CLIENT_ROOT, file), 'utf8'))+ .map((i) => `${file}:${i + 1}`))+ .filter((loc) => !(loc in ALLOWED));+ expect(+ violations,+ 'waitFor checks synchronously first, so an absence assertion right after a bare resolve passes '+ + 'before the response lands. Use `await act(async () => { resolveX(...); })` then assert '+ + 'synchronously (plus a positive assertion on the current record), or allowlist with a reason.\n'+ + `Offenders:\n ${violations.join('\n ')}`,+ ).toEqual([]);+ });++ it('has no stale allowlist entry', () => {+ const stale = Object.keys(ALLOWED).filter((loc) => {+ const [file, line] = loc.split(/:(?=\d+$)/);+ try {+ return !findVacuousAbsenceWaits(readFileSync(join(CLIENT_ROOT, file), 'utf8')).includes(Number(line) - 1);+ } catch { return true; }+ });+ expect(stale, `Allowlist rows that no longer match a flagged line:\n ${stale.join('\n ')}`).toEqual([]);+ });++ it('flags the vacuous shape and accepts the flushed one', () => {+ const vacuous = [+ 'resolveOld(data);',+ "await waitFor(() => expect(screen.queryByText('old')).toBeNull());",+ ].join('\n');+ expect(findVacuousAbsenceWaits(vacuous)).toEqual([1]);+ expect(findVacuousAbsenceWaits("finishLoad();\nawait waitFor(() => expect(x).not.toBeInTheDocument());")).toEqual([1]);+ expect(findVacuousAbsenceWaits([+ 'await act(async () => { resolveOld(data); });',+ "await waitFor(() => expect(screen.queryByText('old')).toBeNull());",+ ].join('\n'))).toEqual([]);+ expect(findVacuousAbsenceWaits('resolveOld(data);\nawait waitFor(() => expect(fn).toHaveBeenCalled());')).toEqual([]);+ });+});