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: capture media admission timeout phases (#12504)

[._.]/ Adam Eivydd97ac736978
diff --git a/server/lib/vaultCrypto.test.js b/server/lib/vaultCrypto.test.js
index 2b47a65c59..2262fedcf1 100644
--- a/server/lib/vaultCrypto.test.js
+++ b/server/lib/vaultCrypto.test.js
@@ -9,13 +9,21 @@ import { mkdtempSync, rmSync, readFileSync, writeFileSync, existsSync, statSync,
import { tmpdir } from 'os';
import { join } from 'path';
import {
- encryptValue, decryptValue, ensureVaultKey, isVaultKeyConfigured, maskValue,
+ encryptValue, decryptValue, ensureVaultKey as ensureVaultKeyImpl, isVaultKeyConfigured, maskValue,
__setVaultEnvPathForTests,
} from './vaultCrypto.js';
// Fixed 32-byte test key (hex). Never a real key.
const HEX_KEY = 'a'.repeat(64);
const originalKey = process.env.PRIVACY_VAULT_KEY;
+const vaultRoots = new Set();
+let pendingKeyWrites = 0;
+let removedVaultRoots = 0;
+async function ensureVaultKey(options) {
+ pendingKeyWrites += 1;
+ try { return await ensureVaultKeyImpl(options); }
+ finally { pendingKeyWrites -= 1; }
+}
// Point the module's .env fallback at a nonexistent file so "key not
// configured" tests can't be satisfied by (or write into) the real install's
@@ -24,6 +32,9 @@ const NO_ENV = join(tmpdir(), 'vault-crypto-no-such-dir', '.env');
beforeAll(() => __setVaultEnvPathForTests(NO_ENV));
afterAll(() => {
+ const remaining = [...vaultRoots].filter(root => existsSync(root)).length;
+ const log = remaining || pendingKeyWrites ? console.error : console.log;
+ log(`🧭 Vault cleanup allocated=${vaultRoots.size},removed=${removedVaultRoots},remaining=${remaining},pendingKeyWrites=${pendingKeyWrites}`);
__setVaultEnvPathForTests(null);
if (originalKey === undefined) delete process.env.PRIVACY_VAULT_KEY;
else process.env.PRIVACY_VAULT_KEY = originalKey;
@@ -131,6 +142,7 @@ describe('ensureVaultKey', () => {
beforeEach(() => {
dir = mkdtempSync(join(tmpdir(), 'vault-crypto-'));
+ vaultRoots.add(dir);
envPath = join(dir, '.env');
delete process.env.PRIVACY_VAULT_KEY;
});
@@ -229,7 +241,10 @@ describe('ensureVaultKey', () => {
expect(process.env.PRIVACY_VAULT_KEY).toBeUndefined();
});
- afterEach(() => rmSync(dir, { recursive: true, force: true }));
+ afterEach(() => {
+ rmSync(dir, { recursive: true, force: true });
+ removedVaultRoots += 1;
+ });
});
describe('maskValue', () => {
diff --git a/server/services/musicVideo/mediaModes.test.js b/server/services/musicVideo/mediaModes.test.js
index a79cb78a4b..08455befee 100644
--- a/server/services/musicVideo/mediaModes.test.js
+++ b/server/services/musicVideo/mediaModes.test.js
@@ -1,7 +1,61 @@
-import { afterAll, describe, expect, it, vi } from 'vitest';
+import { afterAll, afterEach, describe, expect, it, vi } from 'vitest';
import { mkdir, readFile, writeFile, stat } from 'node:fs/promises';
import { join } from 'node:path';
import { cleanupTempDataRoots, lazyTempDataRoot, makePathsProxy } from '../../lib/mockPathsDataRoot.js';
+// Aggregate fixed phase names only: no fixture paths, record ids or error text.
+const importPhases = vi.hoisted(() => {
+ let phases = null;
+ return {
+ start: () => { phases = new Map(); },
+ async run(name, work) {
+ if (!phases) return work();
+ const phase = phases.get(name) ?? { calls: 0, pending: 0, maxMs: 0, pendingSince: 0 };
+ phases.set(name, phase);
+ phase.calls += 1;
+ if (!phase.pending) phase.pendingSince = performance.now();
+ phase.pending += 1;
+ const started = performance.now();
+ try { return await work(); }
+ finally {
+ phase.pending -= 1;
+ phase.maxMs = Math.max(phase.maxMs, performance.now() - started);
+ }
+ },
+ report() {
+ if (!phases) return;
+ const summary = [...phases].map(([name, phase]) =>
+ `${name}:calls=${phase.calls},pending=${phase.pending},pendingMs=${phase.pending ? Math.round(performance.now() - phase.pendingSince) : 0},maxMs=${Math.round(phase.maxMs)}`).join('; ');
+ const log = [...phases.values()].some(phase => phase.pending) ? console.error : console.log;
+ log(`🧭 Media admission awaited phases ${summary}`);
+ phases = null;
+ },
+ };
+});
+vi.mock('fs/promises', async (original) => {
+ const fs = await original();
+ const phases = { readdir: 'scan', lstat: 'scan', realpath: 'scan', readFile: 'read',
+ mkdir: 'copy', cp: 'copy', writeFile: 'copy', rename: 'copy', rm: 'cleanup' };
+ return { ...fs, ...Object.fromEntries(Object.entries(phases).map(([name, phase]) =>
+ [name, (...args) => importPhases.run(phase, () => fs[name](...args))])) };
+});
+vi.mock('./documentMediaPolicy.js', async (original) => {
+ const policy = await original();
+ return { ...policy, assertDocumentMediaPolicy: (...args) =>
+ importPhases.run('policy', () => policy.assertDocumentMediaPolicy(...args)) };
+});
+vi.mock('../../lib/backupSnapshotBoundary.js', async (original) => {
+ const boundary = await original();
+ return { ...boundary, withBackupAssetPublication: (work, ...args) =>
+ importPhases.run('publication', () => boundary.withBackupAssetPublication(
+ () => importPhases.run('admitted-work', work), ...args)) };
+});
+vi.mock('./projects.js', async (original) => {
+ const store = await original();
+ return { ...store, mutateProjectRecord: (...args) =>
+ importPhases.run('persist', () => store.mutateProjectRecord(...args)),
+ listProjects: (...args) => importPhases.run('prune-list', () => store.listProjects(...args)) };
+});
+afterEach(() => importPhases.report());
vi.mock('../../lib/paths.js', async (original) => makePathsProxy(await original(), { dataRoot: () => lazyTempDataRoot('mv-media-policy-') }));
vi.mock('./devArtifactStore.js', async (original) => {
const store = await original();
@@ -48,6 +102,7 @@ describe('whole-workflow media modes', () => {
});
it('refuses raster and embedded image documents before activation, accepts code+local fonts', async () => {
+ importPhases.start();
const project = await projects.createProject({ name: 'Document', mediaMode: 'code-only' });
const dir = join(PATHS.data, 'candidate'); await mkdir(dir, { recursive: true });
await writeFile(join(dir, 'index.html'), '<img src="data:image/png;base64,AAAA">');