Skip to content

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

test: stop unexpected client fetches in related suites (#8254)

[._.]/ Adam Eivyb21e56d0fe34
diff --git a/client/src/components/QuickImagePrompt.test.jsx b/client/src/components/QuickImagePrompt.test.jsx
index 28c9bf9085..cc176a0abd 100644
--- a/client/src/components/QuickImagePrompt.test.jsx
+++ b/client/src/components/QuickImagePrompt.test.jsx
@@ -92,7 +92,7 @@ describe('QuickImagePrompt — universe styling', () => {
listUniverseStyles.mockResolvedValue(STYLES);
await renderWidget();
- fireEvent.change(screen.getByLabelText('Universe style'), { target: { value: 'u-1' } });
+ fireEvent.change(await screen.findByLabelText('Universe style'), { target: { value: 'u-1' } });
fireEvent.change(screen.getByLabelText('Image prompt'), { target: { value: 'a quiet harbor' } });
fireEvent.click(screen.getByTitle('Generate with these settings'));
diff --git a/client/src/components/apps/tabs/CustomTasksSection.test.jsx b/client/src/components/apps/tabs/CustomTasksSection.test.jsx
index c5faec2664..f6f8dccb94 100644
--- a/client/src/components/apps/tabs/CustomTasksSection.test.jsx
+++ b/client/src/components/apps/tabs/CustomTasksSection.test.jsx
@@ -13,6 +13,10 @@ const api = vi.hoisted(() => ({
const toast = vi.hoisted(() => ({ success: vi.fn(), error: vi.fn() }));
vi.mock('../../../services/api', () => api);
+vi.mock('../../../services/apiLocalLlm', async (importOriginal) => ({
+ ...await importOriginal(),
+ getToolUseModels: vi.fn().mockResolvedValue({ models: [] }),
+}));
vi.mock('../../ui/Toast', () => ({ default: toast }));
import CustomTasksSection, { emptyForm, formFromJob, toPayload } from './CustomTasksSection';
diff --git a/client/src/components/apps/tabs/IssuesTab.test.jsx b/client/src/components/apps/tabs/IssuesTab.test.jsx
index e820a1e5d9..a6bf3979ff 100644
--- a/client/src/components/apps/tabs/IssuesTab.test.jsx
+++ b/client/src/components/apps/tabs/IssuesTab.test.jsx
@@ -17,6 +17,10 @@ const { socketHandlers, socketMock } = vi.hoisted(() => {
});
vi.mock('../../../services/socket', () => ({ default: socketMock }));
+vi.mock('../../../services/apiLocalLlm', async (importOriginal) => ({
+ ...await importOriginal(),
+ getToolUseModels: vi.fn().mockResolvedValue({ models: [] }),
+}));
// Label chips grade their color against the ACTIVE theme mode, so the mode has
// to be steerable per test. The real provider runs a settings fetch on mount,
diff --git a/client/src/components/apps/tabs/RepositorySourcePanel.test.jsx b/client/src/components/apps/tabs/RepositorySourcePanel.test.jsx
index f70a45a28e..2443da3a47 100644
--- a/client/src/components/apps/tabs/RepositorySourcePanel.test.jsx
+++ b/client/src/components/apps/tabs/RepositorySourcePanel.test.jsx
@@ -10,6 +10,10 @@ vi.mock('../../../services/api', () => ({
getProviders: vi.fn(),
addCosTask: vi.fn(),
}));
+vi.mock('../../../services/apiLocalLlm', async (importOriginal) => ({
+ ...await importOriginal(),
+ getToolUseModels: vi.fn().mockResolvedValue({ models: [] }),
+}));
vi.mock('../../../hooks/useAppOperation', () => ({
useAppOperation: vi.fn(),
}));
diff --git a/client/src/components/digital-twin/SectionNav.test.jsx b/client/src/components/digital-twin/SectionNav.test.jsx
index 512460a943..8af78e57c5 100644
--- a/client/src/components/digital-twin/SectionNav.test.jsx
+++ b/client/src/components/digital-twin/SectionNav.test.jsx
@@ -1,5 +1,10 @@
import { describe, it, expect, vi } from 'vitest';
-import { render, screen, fireEvent, within } from '@testing-library/react';
+import { act, render, screen, fireEvent, within } from '@testing-library/react';
+
+vi.mock('../../services/api', async (importOriginal) => ({
+ ...await importOriginal(),
+ getInstanceFeatures: vi.fn().mockResolvedValue({ features: [], groups: [] }),
+}));
import SectionNav from './SectionNav';
import { TABS, SECTION_GROUPS, groupSections, sectionGroupId } from './constants';
@@ -50,8 +55,9 @@ describe('digital-twin section taxonomy', () => {
const groupTab = (name) => within(screen.getByRole('tablist', { name: 'Digital Twin groups' })).getByRole('tab', { name });
describe('SectionNav', () => {
- it('derives the active group from the section in the URL, with no local state', () => {
+ it('derives the active group from the section in the URL, with no local state', async () => {
const { rerender } = render(<SectionNav activeSection="documents" onChange={() => {}} />);
+ await act(async () => {});
expect(groupTab('Sources').getAttribute('aria-selected')).toBe('true');
const sourcesRow = screen.getByRole('tablist', { name: 'Sources sections' });
expect(within(sourcesRow).getByRole('tab', { name: /^Documents/ }).getAttribute('aria-selected')).toBe('true');
diff --git a/client/src/components/music/MusicGenPanel.test.jsx b/client/src/components/music/MusicGenPanel.test.jsx
index 1196fd70b3..b95bf109f9 100644
--- a/client/src/components/music/MusicGenPanel.test.jsx
+++ b/client/src/components/music/MusicGenPanel.test.jsx
@@ -16,6 +16,11 @@ vi.mock('../../services/api', () => ({
installAudioModel: vi.fn(),
removeAudioModel: vi.fn(),
}));
+// useMediaJobProgress reads the job endpoint directly; keep it on the same
+// fixture as the panel's API-barrel request.
+vi.mock('../../services/apiMediaJobs', () => ({
+ getMediaJob: (...args) => api.getMediaJob(...args),
+}));
vi.mock('../ui/Toast', () => ({
default: { error: vi.fn(), success: vi.fn(), info: vi.fn() },
diff --git a/client/src/components/pipeline/AutopilotPanel.test.jsx b/client/src/components/pipeline/AutopilotPanel.test.jsx
index 6423fe032c..f5de198d80 100644
--- a/client/src/components/pipeline/AutopilotPanel.test.jsx
+++ b/client/src/components/pipeline/AutopilotPanel.test.jsx
@@ -16,6 +16,15 @@ vi.mock('../../services/api', () => ({
getSettings: vi.fn(),
patchSettingsSlice: vi.fn(),
}));
+// The nested schedule control reads these modules directly, outside the API barrel.
+vi.mock('../../services/apiSystem', async (importOriginal) => ({
+ ...await importOriginal(),
+ getSettings: vi.fn().mockResolvedValue({ seriesAutopilot: { schedules: [] } }),
+}));
+vi.mock('../../services/apiAgents', async (importOriginal) => ({
+ ...await importOriginal(),
+ getCosConfig: vi.fn().mockResolvedValue({ domainAutonomy: { cos: 'execute' }, domainBudgets: {} }),
+}));
// The default export is CALLABLE (a neutral toast) as well as carrying the
// typed helpers — the panel uses the bare call for the self-improvement line.
vi.mock('../ui/Toast', () => ({
diff --git a/client/src/pages/CreativeDirector.test.jsx b/client/src/pages/CreativeDirector.test.jsx
index acdb6b2edb..ab9813fdbc 100644
--- a/client/src/pages/CreativeDirector.test.jsx
+++ b/client/src/pages/CreativeDirector.test.jsx
@@ -1,4 +1,8 @@
vi.mock('../services/apiMusic.js', () => ({ listMusicEngines: vi.fn(() => Promise.resolve({ engines: [] })) }));
+vi.mock('../services/apiTracks.js', async (importOriginal) => ({
+ ...await importOriginal(),
+ listTracks: vi.fn().mockResolvedValue([]),
+}));
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { act, render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
diff --git a/client/src/pages/MusicVideo.test.jsx b/client/src/pages/MusicVideo.test.jsx
index cb2713b83a..2161d6c359 100644
--- a/client/src/pages/MusicVideo.test.jsx
+++ b/client/src/pages/MusicVideo.test.jsx
@@ -59,6 +59,16 @@ vi.mock('../services/apiMusicVideo.js', () => ({
cancelMusicVideoMidiTranscription: vi.fn(async () => ({ ok: true })),
}));
vi.mock('../services/apiSystem.js', () => ({ generateImage: vi.fn() }));
+vi.mock('../hooks/useProviderModels', () => ({
+ default: () => ({
+ providers: [], selectedProviderId: '', selectedModel: '', availableModels: [],
+ setSelectedProviderId: vi.fn(), setSelectedModel: vi.fn(), loading: false,
+ }),
+}));
+// MIDI loading/parsing is covered by useMidiNotes; this page checks the link.
+vi.mock('../hooks/useMidiNotes.js', () => ({
+ default: () => ({ status: 'idle', data: null, error: null, reload: vi.fn() }),
+}));
vi.mock('../services/apiImageVideo.js', () => ({
generateVideo: vi.fn(),
listLorasFull: vi.fn(async () => [{
diff --git a/client/src/pages/PipelineManuscriptEditor.test.jsx b/client/src/pages/PipelineManuscriptEditor.test.jsx
index 815e734a3b..3bfbe8d76a 100644
--- a/client/src/pages/PipelineManuscriptEditor.test.jsx
+++ b/client/src/pages/PipelineManuscriptEditor.test.jsx
@@ -21,6 +21,10 @@ const api = vi.hoisted(() => ({
getProviders: vi.fn(),
}));
vi.mock('../services/api', () => api);
+vi.mock('../services/apiLocalLlm', async (importOriginal) => ({
+ ...await importOriginal(),
+ getLocalLlmStatus: vi.fn().mockResolvedValue({ ollama: { models: [] }, lmstudio: { models: [] } }),
+}));
vi.mock('../components/ui/Toast', () => ({ default: Object.assign(vi.fn(), { success: vi.fn(), error: vi.fn() }) }));
import PipelineManuscriptEditor from './PipelineManuscriptEditor';
diff --git a/client/src/pages/PromptManager.test.jsx b/client/src/pages/PromptManager.test.jsx
index 643e9344c8..e9d51a441d 100644
--- a/client/src/pages/PromptManager.test.jsx
+++ b/client/src/pages/PromptManager.test.jsx
@@ -43,6 +43,10 @@ vi.mock('../services/apiPrompts', () => ({
vi.mock('../services/apiProviders', () => ({
getProviders: vi.fn(() => Promise.resolve({ providers: [], activeProvider: null })),
}));
+vi.mock('../services/api', async (importOriginal) => ({
+ ...await importOriginal(),
+ getInstanceFeatures: vi.fn().mockResolvedValue({ features: [], groups: [] }),
+}));
vi.mock('../components/ui/Toast', () => ({
default: { success: vi.fn(), error: vi.fn() },
diff --git a/client/src/pages/loadingSkeletons.test.jsx b/client/src/pages/loadingSkeletons.test.jsx
index 88d44b6ce1..13b40bc09f 100644
--- a/client/src/pages/loadingSkeletons.test.jsx
+++ b/client/src/pages/loadingSkeletons.test.jsx
@@ -22,8 +22,10 @@ function pendingModule(path) {
vi.mock('../services/api', pendingModule('../services/api'));
vi.mock('../services/apiCatalog.js', pendingModule('../services/apiCatalog.js'));
+vi.mock('../services/apiCatalogTypes.js', pendingModule('../services/apiCatalogTypes.js'));
vi.mock('../services/apiCreativeDirector.js', pendingModule('../services/apiCreativeDirector.js'));
vi.mock('../services/apiImageVideo.js', pendingModule('../services/apiImageVideo.js'));
+vi.mock('../services/apiLocalLlm.js', pendingModule('../services/apiLocalLlm.js'));
vi.mock('../services/apiPipeline.js', pendingModule('../services/apiPipeline.js'));
vi.mock('../services/apiPrompts', pendingModule('../services/apiPrompts'));
vi.mock('../services/apiProviders', pendingModule('../services/apiProviders'));
diff --git a/client/src/test/networkGuard.js b/client/src/test/networkGuard.js
new file mode 100644
index 0000000000..efd5db85d2
--- /dev/null
+++ b/client/src/test/networkGuard.js
@@ -0,0 +1,31 @@
+// Stop an unmocked happy-dom fetch before it reaches its localhost test origin.
+// A caller may catch the rejection as an ordinary offline state, so the test
+// runner must also check takeError() after each test.
+export function createUnexpectedFetchGuard(testName) {
+ const requests = new Map();
+
+ const fetch = (input) => {
+ let path = '<invalid URL>';
+ try {
+ const target = typeof input === 'string' || input instanceof URL ? input : input?.url;
+ path = new URL(target, 'http://test.invalid').pathname;
+ } catch {
+ // Keep malformed input out of reports as well.
+ }
+ const owner = testName() || '<outside a test>';
+ const key = `${owner}: ${path}`;
+ requests.set(key, (requests.get(key) || 0) + 1);
+ return Promise.reject(new Error(`Unexpected test fetch in ${key}`));
+ };
+
+ const takeError = () => {
+ if (requests.size === 0) return null;
+ const entries = [...requests];
+ requests.clear();
+ const first = entries.slice(0, 5).map(([key, count]) => `${key} (${count}x)`);
+ const remaining = entries.length - first.length;
+ return new Error(`Unexpected test fetch; mock this request or use an owned fixture: ${first.join(', ')}${remaining ? `, and ${remaining} more` : ''}`);
+ };
+
+ return { fetch, takeError };
+}
diff --git a/client/src/test/networkGuard.test.js b/client/src/test/networkGuard.test.js
new file mode 100644
index 0000000000..cf93c1b77d
--- /dev/null
+++ b/client/src/test/networkGuard.test.js
@@ -0,0 +1,23 @@
+import { describe, expect, it } from 'vitest';
+import { createUnexpectedFetchGuard } from './networkGuard.js';
+
+describe('unexpected test fetch guard', () => {
+ it('stops a request, identifies its test and path, and omits query values', async () => {
+ const guard = createUnexpectedFetchGuard(() => 'example test');
+ await expect(guard.fetch('/api/example?token=private-value')).rejects.toThrow('example test: /api/example');
+ await expect(guard.fetch(new URL('https://example.com/api/example?secret=another-value'))).rejects.toThrow();
+ const error = guard.takeError();
+ expect(error.message).toContain('example test: /api/example (2x)');
+ expect(error.message).not.toMatch(/private-value|another-value|example\.com/);
+ expect(guard.takeError()).toBeNull();
+ });
+
+ it('bounds the report when a test makes many distinct requests', async () => {
+ const guard = createUnexpectedFetchGuard(() => 'many requests');
+ for (let n = 0; n < 7; n += 1) await expect(guard.fetch(`/api/item-${n}`)).rejects.toThrow();
+ const error = guard.takeError();
+ expect(error.message).toContain('/api/item-4');
+ expect(error.message).toContain('and 2 more');
+ expect(error.message).not.toContain('/api/item-6');
+ });
+});
diff --git a/client/src/test/setup.js b/client/src/test/setup.js
index 20982a0003..26ad2f54fa 100644
--- a/client/src/test/setup.js
+++ b/client/src/test/setup.js
@@ -5,6 +5,7 @@ import { installTestStorage } from './storagePolyfill.js';
import { installFormValidityFix } from './formValidityPolyfill.js';
import { ASYNC_UTIL_TIMEOUT_MS } from './timeouts.js';
import { actWarningEntry, formatActWarningError } from './actWarnings.js';
+import { createUnexpectedFetchGuard } from './networkGuard.js';
// The suite-wide Testing Library async budget. The value, and why the per-test
// and hook budgets in vitest.config.js are derived from it rather than written
@@ -19,6 +20,11 @@ installTestStorage();
// swallowed by a float-modulo step check. See formValidityPolyfill.js / #6144.
installFormValidityFix();
+// A missing transport mock must never fall through to happy-dom's localhost:3000
+// server. Explicit integration fixtures can replace fetch for their own tests.
+const networkGuard = createUnexpectedFetchGuard(() => expect.getState().currentTestName);
+globalThis.fetch = networkGuard.fetch;
+
// The test DOM doesn't implement Element.prototype.scrollIntoView; components call it
// (often from a requestAnimationFrame callback that can fire AFTER a test unmounts),
// and the resulting unhandled error fails the whole run despite passing assertions
@@ -95,13 +101,16 @@ console.error = (...args) => {
afterEach(() => {
cleanup();
+ const networkError = networkGuard.takeError();
// Reset storage between tests so a file that forgets its own `clear()` can't leak
// state into the next — reinforces the isolation the polyfill restores.
globalThis.localStorage?.clear();
globalThis.sessionStorage?.clear();
- if (actWarnings.length > 0) {
- const message = formatActWarningError(actWarnings, expect.getState().currentTestName);
- actWarnings.length = 0;
- throw new Error(message);
+ const actError = actWarnings.length > 0
+ ? formatActWarningError(actWarnings, expect.getState().currentTestName)
+ : null;
+ actWarnings.length = 0;
+ if (networkError || actError) {
+ throw new Error([networkError?.message, actError].filter(Boolean).join('\n'));
}
});