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: tighten the dead-export guard after review (#5727)

Adam Eivy4b905299d469
diff --git a/client/src/components/brain/tabs/InboxTab.test.jsx b/client/src/components/brain/tabs/InboxTab.test.jsx
index 5e2c1f3891..cb43735a20 100644
--- a/client/src/components/brain/tabs/InboxTab.test.jsx
+++ b/client/src/components/brain/tabs/InboxTab.test.jsx
@@ -5,7 +5,6 @@ import { MemoryRouter } from 'react-router';
vi.mock('../../../services/api', () => ({
getBrainInbox: vi.fn(),
captureBrainThought: vi.fn(),
- getBrainInboxEntry: vi.fn(),
resolveBrainReview: vi.fn(),
fixBrainClassification: vi.fn(),
retryBrainClassification: vi.fn(),
diff --git a/client/src/components/universe/CharacterDetailEditor.test.jsx b/client/src/components/universe/CharacterDetailEditor.test.jsx
index 88c497bdac..24f77ce72d 100644
--- a/client/src/components/universe/CharacterDetailEditor.test.jsx
+++ b/client/src/components/universe/CharacterDetailEditor.test.jsx
@@ -8,7 +8,6 @@ vi.mock('../voice/VoicePicker', () => ({ default: () => null }));
vi.mock('../../services/apiVoice', () => ({
listVoiceEngines: vi.fn().mockResolvedValue({ engines: [] }),
listVoiceProfiles: vi.fn(),
- promotePresetProfile: vi.fn(),
promoteVoicePreset: vi.fn(),
renderVoiceProfileBenchmark: vi.fn(),
createVoiceDesignCandidate: vi.fn(),
diff --git a/client/src/pages/CatalogIngredient.test.jsx b/client/src/pages/CatalogIngredient.test.jsx
index a7921e5f92..c21d05e22f 100644
--- a/client/src/pages/CatalogIngredient.test.jsx
+++ b/client/src/pages/CatalogIngredient.test.jsx
@@ -60,7 +60,6 @@ vi.mock('../services/apiCatalog', () => ({
getCatalogIngredientDetails: vi.fn(async () => detailsOf(CHAR_FIXTURE)),
updateCatalogIngredient: vi.fn(),
deleteCatalogIngredient: vi.fn(),
- listCatalogIngredientRelations: vi.fn(async () => ({ outbound: [], inbound: [] })),
linkCatalogIngredientRelation: vi.fn(),
unlinkCatalogIngredientRelation: vi.fn(),
listCatalogIngredientRevisions: vi.fn(async () => ({ items: [] })),
diff --git a/client/src/pages/Loras.jsx b/client/src/pages/Loras.jsx
index 91bef12c13..0923e6cafc 100644
--- a/client/src/pages/Loras.jsx
+++ b/client/src/pages/Loras.jsx
@@ -1135,7 +1135,7 @@ function LoraCard({ lora, onDelete, onMeasured, deleting, deleteConfirm }) {
// and "Delete undefined" is a bad thing to announce over a destructive action.
const displayName = lora.name || lora.filename;
- // Read straight off the server's CACHED report (listLoras never probes) — an
+ // Read straight off the server's CACHED report (listLorasFull never probes) — an
// explicit re-check hands the new one to `onMeasured`, which updates the list
// entry, so the badge survives this card being unmounted by a filter change.
const effect = lora.effectReport || null;
diff --git a/client/src/pages/MusicVideo.test.jsx b/client/src/pages/MusicVideo.test.jsx
index f652e51323..975a0d6128 100644
--- a/client/src/pages/MusicVideo.test.jsx
+++ b/client/src/pages/MusicVideo.test.jsx
@@ -85,10 +85,6 @@ vi.mock('../services/apiImageVideo.js', () => ({
getVideoHistoryItem: vi.fn(async (id) => (id === 'rh-9'
? { id: 'rh-9', filename: 'final.mp4' }
: Promise.reject(Object.assign(new Error('Not found'), { status: 404 })))),
- // Restricted-model license gate — none of the models above carry a
- // `termsGate`, so the board renders no acceptance panel and nothing blocks.
- getVideoModelTerms: vi.fn(async () => ({ accepted: [] })),
- setVideoModelTerms: vi.fn(async () => ({ accepted: [] })),
}));
vi.mock('../services/apiTracks.js', () => ({
listTracks: vi.fn(async () => []),
diff --git a/client/src/pages/Privacy.test.jsx b/client/src/pages/Privacy.test.jsx
index 3852647d45..5c762d8318 100644
--- a/client/src/pages/Privacy.test.jsx
+++ b/client/src/pages/Privacy.test.jsx
@@ -41,7 +41,6 @@ vi.mock('../services/api', () => ({
]),
// Broker case summary chips on the Overview tab (#2146).
getPrivacyScanStatus: vi.fn().mockResolvedValue({ enabledBrokers: 2, caseCounts: { found: 1 }, dueForRecheck: 0 }),
- getPrivacyOrg: vi.fn(),
createPrivacyOrg: vi.fn(),
updatePrivacyOrg: vi.fn(),
deletePrivacyOrg: vi.fn().mockResolvedValue({ ok: true }),
diff --git a/client/src/pages/VideoGen.composeWhileBusy.test.jsx b/client/src/pages/VideoGen.composeWhileBusy.test.jsx
index 479d99092d..bed308fad6 100644
--- a/client/src/pages/VideoGen.composeWhileBusy.test.jsx
+++ b/client/src/pages/VideoGen.composeWhileBusy.test.jsx
@@ -34,11 +34,6 @@ const state = vi.hoisted(() => ({
eventSourceRef: { current: null },
}));
-vi.mock('../services/apiImageVideo.js', () => ({
- getVideoModelTerms: vi.fn(async () => ({ accepted: [TERMS_ID] })),
- setVideoModelTerms: vi.fn(async () => ({ accepted: [TERMS_ID] })),
-}));
-
vi.mock('../services/api', () => ({
// The page offers a federated render target (#4348); with no peer opted in
// as a media provider the picker renders nothing and every local path below
diff --git a/client/src/pages/VideoGen.federatedTarget.test.jsx b/client/src/pages/VideoGen.federatedTarget.test.jsx
index e42a4a2a13..caacef5061 100644
--- a/client/src/pages/VideoGen.federatedTarget.test.jsx
+++ b/client/src/pages/VideoGen.federatedTarget.test.jsx
@@ -57,11 +57,6 @@ const state = vi.hoisted(() => ({
eventSourceRef: { current: null },
}));
-vi.mock('../services/apiImageVideo.js', () => ({
- getVideoModelTerms: vi.fn(async () => ({ accepted: [TERMS_ID] })),
- setVideoModelTerms: vi.fn(async () => ({ accepted: [TERMS_ID] })),
-}));
-
vi.mock('../services/api', () => ({
getInstances: vi.fn(async () => ({ peers: [PEER] })),
getVideoGenStatus: vi.fn(async () => ({
diff --git a/client/src/pages/VideoGen.terms.test.jsx b/client/src/pages/VideoGen.terms.test.jsx
index 1ddc69eef0..1be975380f 100644
--- a/client/src/pages/VideoGen.terms.test.jsx
+++ b/client/src/pages/VideoGen.terms.test.jsx
@@ -38,22 +38,10 @@ const state = vi.hoisted(() => ({
repairModel: vi.fn(),
attach: vi.fn(),
eventSourceRef: { current: null },
- // Stands in for the persisted install-wide acceptance list
- // (settings.videoGen.acceptedModelTerms) the terms endpoints read and write.
- acceptedTerms: [],
- setVideoModelTerms: vi.fn(),
getVideoGenStatus: vi.fn(),
runtimeInstallComplete: null,
}));
-// Acceptance lives on the server, not in this browser, so a single
-// acknowledgement authorizes every render surface. The page reads and writes it
-// through these two endpoints.
-vi.mock('../services/apiImageVideo.js', () => ({
- getVideoModelTerms: vi.fn(async () => ({ accepted: [...state.acceptedTerms] })),
- setVideoModelTerms: (...args) => state.setVideoModelTerms(...args),
-}));
-
vi.mock('../services/api', () => ({
// The page offers a federated render target (#4348); with no peer opted in
// as a media provider the picker renders nothing and every local path below
@@ -168,13 +156,6 @@ describe('VideoGen MiniMax H3 orchestration', () => {
state.generateVideo.mockReset().mockResolvedValue({ jobId: 'job-1' });
state.startDownload.mockReset();
state.repairModel.mockReset().mockResolvedValue({ ok: true });
- state.acceptedTerms = [];
- state.setVideoModelTerms.mockReset().mockImplementation(async (termsId, accepted) => {
- state.acceptedTerms = accepted
- ? [...new Set([...state.acceptedTerms, termsId])]
- : state.acceptedTerms.filter((id) => id !== termsId);
- return { accepted: [...state.acceptedTerms] };
- });
state.getVideoGenStatus.mockReset().mockResolvedValue({
connected: true,
pythonPath: '/opt/example/python3',
diff --git a/client/src/pages/VideoGen.textEncoderAutoDownload.test.jsx b/client/src/pages/VideoGen.textEncoderAutoDownload.test.jsx
index 0ec987d0ed..bb09e6e013 100644
--- a/client/src/pages/VideoGen.textEncoderAutoDownload.test.jsx
+++ b/client/src/pages/VideoGen.textEncoderAutoDownload.test.jsx
@@ -54,11 +54,6 @@ const state = vi.hoisted(() => ({
eventSourceRef: { current: null },
}));
-vi.mock('../services/apiImageVideo.js', () => ({
- getVideoModelTerms: vi.fn(async () => ({ accepted: [TERMS_ID] })),
- setVideoModelTerms: vi.fn(async () => ({ accepted: [TERMS_ID] })),
-}));
-
vi.mock('../services/api', () => ({
// The page offers a federated render target (#4348); with no peer opted in
// as a media provider the picker renders nothing and every local path below
diff --git a/client/src/services/README.md b/client/src/services/README.md
index 1487054eb6..59d644ecb1 100644
--- a/client/src/services/README.md
+++ b/client/src/services/README.md
@@ -64,7 +64,7 @@ toasts on throw). **Custom catch ⇒ `silent: true`** — otherwise toasts fire
| `apiQuotaBurn.js` | Quota Burn plan + live status, the job-type catalog its config form renders, and manual runs (`getQuotaBurn`/`getQuotaBurnCatalog`/`saveQuotaBurn`/`runQuotaBurn`), plus `rearmQuotaBurn` to put spent `run once` steps back into the rotation. |
| `apiRapidReader.js` | Rapid Reader's optional author-hosted Accelerando loader and machine-local shelf API. |
| `apiSystem.js` | System info (CPU/memory/ports/alerts/active processing and local hardware capabilities) + D&D-style character sheet getter, plus the usage cost report and explicit historical reconciliation (`getUsage`, `getProviderUsage`, `getUsageBackfillStatus`/`startUsageBackfill`, `updateSubscriptionCosts` for the subscription-vs-API savings comparison). |
-| `apiAuth.js` | Optional login password — status, login/logout, set/clear password. |
+| `apiAuth.js` | Optional login password — status, login, set/clear password. |
| `apiLoops.js` | Scheduled loops. |
## Personal data / identity
@@ -98,7 +98,7 @@ toasts on throw). **Custom catch ⇒ `silent: true`** — otherwise toasts fire
| File | Purpose |
|---|---|
| `apiImageVideo.js` | Image-gen local backend extras (gallery, models, LoRAs, cancel, delete). |
-| `apiLoraTraining.js` | Character LoRA training — datasets (CRUD, upload, generate, slice, caption), training runs (start/list/cancel/delete + status), character→LoRA link lookup. |
+| `apiLoraTraining.js` | Character LoRA training — datasets (CRUD, upload, generate, slice, caption), training runs (start/list/cancel + status), character→LoRA link lookup. |
| `apiMedia.js` | Screenshots + media assets. Also owns the multi-file upload orchestration — `processScreenshotUploads` / `processAttachmentUploads` — moved from `utils/fileUpload.js` since they perform network I/O, not pure transforms. `utils/fileUpload.js` keeps only the pure helpers/constants and no longer re-exports these. |
| `apiMediaJobs.js` | Media generation job tracking + `refineMediaPrompt` / `promptFromMedia` (vision reverse-prompt). |
| `apiCreativeDirector.js` | Creative Director (video production). |
diff --git a/client/src/services/api.deadExports.test.js b/client/src/services/api.deadExports.test.js
index 9f0439c770..248d7d5444 100644
--- a/client/src/services/api.deadExports.test.js
+++ b/client/src/services/api.deadExports.test.js
@@ -8,9 +8,8 @@ const SRC_ROOT = join(HERE, '..');
const BARRELS = new Set(['api.js']);
// Deliberate keeps — a one-line, reviewed decision rather than silent
-// accumulation. CLIENT_BUILD_ID lives on socket.js (a build-injected identity
-// for the stale-client check) and is listed here so a future api*.js keep
-// follows the same seam.
+// accumulation. CLIENT_BUILD_ID is the build-injected identity on socket.js
+// for the stale-client check; it has no UI importer by design.
const INTENTIONALLY_UNREFERENCED = Object.freeze(['CLIENT_BUILD_ID']);
const isTest = (name) => /\.test\.(js|jsx)$/.test(name);
@@ -24,6 +23,53 @@ function walk(dir, acc = []) {
return acc;
}
+function stripComments(src) {
+ let out = '';
+ let i = 0;
+ const n = src.length;
+ while (i < n) {
+ const c = src[i];
+ const n1 = src[i + 1];
+ if (c === '/' && n1 === '/') {
+ i += 2;
+ while (i < n && src[i] !== '\n') i++;
+ continue;
+ }
+ if (c === '/' && n1 === '*') {
+ i += 2;
+ while (i < n - 1 && !(src[i] === '*' && src[i + 1] === '/')) i++;
+ i = Math.min(n, i + 2);
+ continue;
+ }
+ if (c === '\'' || c === '"') {
+ const q = c;
+ out += c;
+ i++;
+ while (i < n) {
+ out += src[i];
+ if (src[i] === '\\') { out += src[i + 1] || ''; i += 2; continue; }
+ if (src[i] === q) { i++; break; }
+ i++;
+ }
+ continue;
+ }
+ if (c === '`') {
+ out += c;
+ i++;
+ while (i < n) {
+ out += src[i];
+ if (src[i] === '\\') { out += src[i + 1] || ''; i += 2; continue; }
+ if (src[i] === '`') { i++; break; }
+ i++;
+ }
+ continue;
+ }
+ out += c;
+ i++;
+ }
+ return out;
+}
+
function collectNamedExports(src) {
const names = new Set();
let m;
@@ -45,7 +91,7 @@ function identFiles(files) {
const map = new Map();
const ident = /\b[A-Za-z_][A-Za-z0-9_]*\b/g;
for (const file of files) {
- const src = readFileSync(file, 'utf8');
+ const src = stripComments(readFileSync(file, 'utf8'));
const seen = new Set();
let m;
while ((m = ident.exec(src))) {
@@ -59,31 +105,32 @@ function identFiles(files) {
return map;
}
-function findDeadExports({ extra } = {}) {
- const all = walk(SRC_ROOT);
- const sources = all.filter((f) => !isTest(f));
- const apiFiles = readdirSync(HERE)
- .filter((f) => f.startsWith('api') && f.endsWith('.js') && !isTest(f) && f !== 'api.js')
+function exportModules() {
+ return readdirSync(HERE)
+ .filter((f) => !isTest(f) && (
+ f === 'socket.js'
+ || (f.startsWith('api') && f.endsWith('.js') && f !== 'api.js')
+ ))
.map((f) => join(HERE, f));
+}
+function findDeadExports({ extraModule } = {}) {
+ const all = walk(SRC_ROOT);
+ const sources = all.filter((f) => !isTest(f));
+ const modules = exportModules();
const corpus = sources.filter((f) => !BARRELS.has(relative(HERE, f)));
const filesFor = identFiles(corpus);
const dead = [];
- for (const file of apiFiles) {
- const names = collectNamedExports(readFileSync(file, 'utf8'));
- for (const name of names) {
+ const consider = (file, src) => {
+ for (const name of collectNamedExports(src)) {
if (INTENTIONALLY_UNREFERENCED.includes(name)) continue;
const hits = (filesFor.get(name) || []).filter((f) => f !== file);
if (hits.length === 0) dead.push(`${relative(SRC_ROOT, file)}:${name}`);
}
- }
- if (extra) {
- const hits = (filesFor.get(extra.name) || []).filter((f) => f !== extra.file);
- if (hits.length === 0 && !INTENTIONALLY_UNREFERENCED.includes(extra.name)) {
- dead.push(`${extra.file}:${extra.name}`);
- }
- }
+ };
+ for (const file of modules) consider(file, readFileSync(file, 'utf8'));
+ if (extraModule) consider(join(HERE, extraModule.file), extraModule.src);
return dead;
}
@@ -94,14 +141,18 @@ describe('client API wrappers have callers', () => {
});
it('fails when a caller-less wrapper is added', () => {
+ const src = 'export const definitelyUnusedApiWrapper5727 = () => {};\n';
+ expect(collectNamedExports(src).has('definitelyUnusedApiWrapper5727')).toBe(true);
const dead = findDeadExports({
- extra: { file: 'services/apiFake.js', name: 'definitelyUnusedApiWrapper5727' },
+ extraModule: { file: 'apiFake.js', src },
});
expect(dead.some((row) => row.endsWith(':definitelyUnusedApiWrapper5727'))).toBe(true);
});
- it('keeps the intentional-unreferenced allowlist explicit', () => {
+ it('allowlists CLIENT_BUILD_ID as the only intentional keep', () => {
expect(INTENTIONALLY_UNREFERENCED).toEqual(['CLIENT_BUILD_ID']);
+ const socketSrc = readFileSync(join(HERE, 'socket.js'), 'utf8');
+ expect(collectNamedExports(socketSrc).has('CLIENT_BUILD_ID')).toBe(true);
});
});
// @vitest-environment node