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(peer-sync): no-op auto-subscribe in record fixtures

Adam Eivyc352e1201fcb
diff --git a/server/lib/mockPathsDataRoot.js b/server/lib/mockPathsDataRoot.js
index c037017458..2ffb6f941b 100644
--- a/server/lib/mockPathsDataRoot.js
+++ b/server/lib/mockPathsDataRoot.js
@@ -30,6 +30,8 @@
* - `createTempDataRoot()` — returns `{ tempRoot }` allocated under os.tmpdir().
* - `mockNoPeers(actual?, overrides?)` — shared `instances.js` mock guard
* for record-creating tests that should never auto-subscribe to live peers.
+ * - `mockNoPeerSync(actual?, overrides?)` — shared `peerSync.js` mock guard
+ * that makes fire-and-forget record auto-subscribe a clean no-op in tests.
*
* Migration: tests that need MULTIPLE PATHS members redirected
* (e.g. `images`, `videos`) can pass `extraOverrides` (object or function)
@@ -105,6 +107,23 @@ export function mockNoPeers(actual = {}, overrides = {}) {
};
}
+/**
+ * Build a `sharing/peerSync.js` mock that disables create-time peer fan-out.
+ *
+ * This is intentionally separate from `mockNoPeers`: stubbing `getPeers → []`
+ * prevents live registry reads once `peerSync.js` loads, while this helper
+ * prevents record-creating tests from loading the peer-sync module graph at
+ * all through the fire-and-forget dynamic import.
+ */
+export function mockNoPeerSync(actual = {}, overrides = {}) {
+ return {
+ ...actual,
+ autoSubscribeRecordToAllPeers: () => Promise.resolve([]),
+ unsubscribeAllForRecord: () => Promise.resolve({ removed: [], failed: [] }),
+ ...overrides,
+ };
+}
+
/**
* Convenience wrapper for the most-common case: a single per-file temp dir
* plus a Proxy factory. Returns `{ tempRoot, makeProxy, cleanup }` where
diff --git a/server/lib/mockPathsDataRoot.test.js b/server/lib/mockPathsDataRoot.test.js
index ceaea73941..fbdcd4b6bb 100644
--- a/server/lib/mockPathsDataRoot.test.js
+++ b/server/lib/mockPathsDataRoot.test.js
@@ -2,7 +2,7 @@ import { describe, it, expect, afterAll } from 'vitest';
import { existsSync, rmSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
-import { createTempDataRoot, makePathsProxy, mockNoPeers, mockPathsDataRoot } from './mockPathsDataRoot.js';
+import { createTempDataRoot, makePathsProxy, mockNoPeers, mockNoPeerSync, mockPathsDataRoot } from './mockPathsDataRoot.js';
describe('mockPathsDataRoot', () => {
describe('createTempDataRoot', () => {
@@ -96,4 +96,18 @@ describe('mockPathsDataRoot', () => {
await expect(mock.getInstanceId()).resolves.toBe('test-id');
});
});
+
+ describe('mockNoPeerSync', () => {
+ it('preserves peerSync exports while forcing autoSubscribeRecordToAllPeers to []', async () => {
+ const mock = mockNoPeerSync(
+ { autoSubscribeRecordToAllPeers: async () => [{ peerId: 'real-peer' }], otherExport: 1 },
+ { custom: true },
+ );
+
+ await expect(mock.autoSubscribeRecordToAllPeers()).resolves.toEqual([]);
+ await expect(mock.unsubscribeAllForRecord()).resolves.toEqual({ removed: [], failed: [] });
+ expect(mock.otherExport).toBe(1);
+ expect(mock.custom).toBe(true);
+ });
+ });
});
diff --git a/server/services/importer.test.js b/server/services/importer.test.js
index 2089d9b4e0..56992a13f9 100644
--- a/server/services/importer.test.js
+++ b/server/services/importer.test.js
@@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach, afterAll, vi } from 'vitest';
import { mkdtempSync, rmSync, readdirSync, unlinkSync, existsSync, statSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
-import { mockNoPeers } from '../lib/mockPathsDataRoot.js';
+import { mockNoPeerSync, mockNoPeers } from '../lib/mockPathsDataRoot.js';
// Create the tempRoot at top-level so PATHS.data resolves before any
// service module runs its `const STATE_PATH = join(PATHS.data, ...)` at
@@ -52,6 +52,7 @@ vi.mock('../lib/fileUtils.js', async () => {
// ephemeral:true on the direct fixtures, downstream production code may
// still create non-ephemeral records.
vi.mock('./instances.js', () => mockNoPeers());
+vi.mock('./sharing/peerSync.js', () => mockNoPeerSync());
// Mock runStagedLLM so tests never hit a real provider — every importer
// LLM call resolves to a canned JSON shape we control per-test.
diff --git a/server/services/pipeline/arcPlanner.test.js b/server/services/pipeline/arcPlanner.test.js
index 7cdaed8502..e4ebf8898f 100644
--- a/server/services/pipeline/arcPlanner.test.js
+++ b/server/services/pipeline/arcPlanner.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
-import { mockNoPeers } from '../../lib/mockPathsDataRoot.js';
+import { mockNoPeerSync, mockNoPeers } from '../../lib/mockPathsDataRoot.js';
const fileStore = new Map();
let stageRunnerSpy;
@@ -19,6 +19,7 @@ vi.mock('crypto', async () => {
});
vi.mock('../instances.js', () => mockNoPeers());
+vi.mock('../sharing/peerSync.js', () => mockNoPeerSync());
// Stub the staged-LLM runner so the test owns the LLM response shape.
// Each test sets `stageRunnerSpy = vi.fn(...)` to control what comes back.
diff --git a/server/services/pipeline/autoRunner.test.js b/server/services/pipeline/autoRunner.test.js
index 3e52a75411..a0193b4104 100644
--- a/server/services/pipeline/autoRunner.test.js
+++ b/server/services/pipeline/autoRunner.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
-import { mockNoPeers } from '../../lib/mockPathsDataRoot.js';
+import { mockNoPeerSync, mockNoPeers } from '../../lib/mockPathsDataRoot.js';
const fileStore = new Map();
@@ -18,6 +18,7 @@ vi.mock('crypto', async () => {
});
vi.mock('../instances.js', () => mockNoPeers());
+vi.mock('../sharing/peerSync.js', () => mockNoPeerSync());
// Inline generator that flips the stage to ready without doing any real work.
// We're testing the coordinator, not the LLM call site.
diff --git a/server/services/pipeline/coverUniverseFiler.test.js b/server/services/pipeline/coverUniverseFiler.test.js
index 61047664f5..8fa83d6a45 100644
--- a/server/services/pipeline/coverUniverseFiler.test.js
+++ b/server/services/pipeline/coverUniverseFiler.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach, vi } from 'vitest';
-import { mockNoPeers } from '../../lib/mockPathsDataRoot.js';
+import { mockNoPeerSync, mockNoPeers } from '../../lib/mockPathsDataRoot.js';
const fileStore = new Map();
@@ -20,6 +20,7 @@ vi.mock('crypto', async () => {
});
vi.mock('../instances.js', () => mockNoPeers());
+vi.mock('../sharing/peerSync.js', () => mockNoPeerSync());
const collections = await import('../mediaCollections.js');
const seriesSvc = await import('./series.js');
diff --git a/server/services/pipeline/episodeVideo.test.js b/server/services/pipeline/episodeVideo.test.js
index 19e93fcfdb..83b4b705d7 100644
--- a/server/services/pipeline/episodeVideo.test.js
+++ b/server/services/pipeline/episodeVideo.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
-import { mockNoPeers } from '../../lib/mockPathsDataRoot.js';
+import { mockNoPeerSync, mockNoPeers } from '../../lib/mockPathsDataRoot.js';
const fileStore = new Map();
@@ -18,6 +18,7 @@ vi.mock('crypto', async () => {
});
vi.mock('../instances.js', () => mockNoPeers());
+vi.mock('../sharing/peerSync.js', () => mockNoPeerSync());
const cdCreated = [];
const cdTreatments = [];
diff --git a/server/services/pipeline/issues.test.js b/server/services/pipeline/issues.test.js
index 2a14d3ad14..e64fb5fd74 100644
--- a/server/services/pipeline/issues.test.js
+++ b/server/services/pipeline/issues.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
-import { mockNoPeers } from '../../lib/mockPathsDataRoot.js';
+import { mockNoPeerSync, mockNoPeers } from '../../lib/mockPathsDataRoot.js';
const fileStore = new Map();
@@ -18,6 +18,7 @@ vi.mock('crypto', async () => {
});
vi.mock('../instances.js', () => mockNoPeers());
+vi.mock('../sharing/peerSync.js', () => mockNoPeerSync());
const svc = await import('./issues.js');
const seriesSvc = await import('./series.js');
diff --git a/server/services/pipeline/migrateSeriesCanon.test.js b/server/services/pipeline/migrateSeriesCanon.test.js
index 4dcf0fd8ad..dce2e32042 100644
--- a/server/services/pipeline/migrateSeriesCanon.test.js
+++ b/server/services/pipeline/migrateSeriesCanon.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach, vi } from 'vitest';
-import { mockNoPeers } from '../../lib/mockPathsDataRoot.js';
+import { mockNoPeerSync, mockNoPeers } from '../../lib/mockPathsDataRoot.js';
const ERR_DUPLICATE = 'DUPLICATE';
const ERR_NOT_FOUND = 'NOT_FOUND';
@@ -43,6 +43,7 @@ vi.mock('../../lib/fileUtils.js', () => ({
readJSONFile: vi.fn(async (_p, fallback) => fallback),
}));
vi.mock('../instances.js', () => mockNoPeers());
+vi.mock('../sharing/peerSync.js', () => mockNoPeerSync());
const { applyLegacySeriesCanonToUniverse, deriveOrphanUniverseId } = await import('./migrateSeriesCanon.js');
const universeBuilder = await import('../universeBuilder.js');
diff --git a/server/services/pipeline/seasons.test.js b/server/services/pipeline/seasons.test.js
index f706c44e06..a607309792 100644
--- a/server/services/pipeline/seasons.test.js
+++ b/server/services/pipeline/seasons.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
-import { mockNoPeers } from '../../lib/mockPathsDataRoot.js';
+import { mockNoPeerSync, mockNoPeers } from '../../lib/mockPathsDataRoot.js';
const fileStore = new Map();
@@ -18,6 +18,7 @@ vi.mock('crypto', async () => {
});
vi.mock('../instances.js', () => mockNoPeers());
+vi.mock('../sharing/peerSync.js', () => mockNoPeerSync());
const seriesSvc = await import('./series.js');
const issuesSvc = await import('./issues.js');
diff --git a/server/services/pipeline/series.test.js b/server/services/pipeline/series.test.js
index e62f87d679..8564d80e6d 100644
--- a/server/services/pipeline/series.test.js
+++ b/server/services/pipeline/series.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
-import { mockNoPeers } from '../../lib/mockPathsDataRoot.js';
+import { mockNoPeerSync, mockNoPeers } from '../../lib/mockPathsDataRoot.js';
const fileStore = new Map();
@@ -18,6 +18,7 @@ vi.mock('crypto', async () => {
});
vi.mock('../instances.js', () => mockNoPeers());
+vi.mock('../sharing/peerSync.js', () => mockNoPeerSync());
const svc = await import('./series.js');
diff --git a/server/services/pipeline/textStages.test.js b/server/services/pipeline/textStages.test.js
index 5285abea99..2ea688f6a0 100644
--- a/server/services/pipeline/textStages.test.js
+++ b/server/services/pipeline/textStages.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
-import { mockNoPeers } from '../../lib/mockPathsDataRoot.js';
+import { mockNoPeerSync, mockNoPeers } from '../../lib/mockPathsDataRoot.js';
const fileStore = new Map();
@@ -18,6 +18,7 @@ vi.mock('crypto', async () => {
});
vi.mock('../instances.js', () => mockNoPeers());
+vi.mock('../sharing/peerSync.js', () => mockNoPeerSync());
const llmCalls = [];
diff --git a/server/services/pipeline/volumeBeatsRunner.test.js b/server/services/pipeline/volumeBeatsRunner.test.js
index 70f72e46c6..ffc7a79b82 100644
--- a/server/services/pipeline/volumeBeatsRunner.test.js
+++ b/server/services/pipeline/volumeBeatsRunner.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
-import { mockNoPeers } from '../../lib/mockPathsDataRoot.js';
+import { mockNoPeerSync, mockNoPeers } from '../../lib/mockPathsDataRoot.js';
const fileStore = new Map();
@@ -18,6 +18,7 @@ vi.mock('crypto', async () => {
});
vi.mock('../instances.js', () => mockNoPeers());
+vi.mock('../sharing/peerSync.js', () => mockNoPeerSync());
// Inline generator that writes ready beats without making an LLM call —
// we're testing the coordinator, not the prompt.
diff --git a/server/services/sharing/integration.test.js b/server/services/sharing/integration.test.js
index c896d5e001..45d6d11401 100644
--- a/server/services/sharing/integration.test.js
+++ b/server/services/sharing/integration.test.js
@@ -13,7 +13,7 @@ import { mkdtempSync, rmSync, writeFileSync, existsSync, mkdirSync, readFileSync
import { tmpdir } from 'os';
import { join } from 'path';
import { createHash } from 'crypto';
-import { mockNoPeers } from '../../lib/mockPathsDataRoot.js';
+import { mockNoPeerSync, mockNoPeers } from '../../lib/mockPathsDataRoot.js';
function sha256Hex(buf) {
return createHash('sha256').update(buf).digest('hex');
@@ -46,6 +46,7 @@ vi.mock('../instances.js', () => mockNoPeers({}, {
getInstanceId: () => Promise.resolve('test-instance-id'),
UNKNOWN_INSTANCE_ID: 'unknown',
}));
+vi.mock('./peerSync.js', () => mockNoPeerSync());
// Stub mediaJobQueue.getJob — exporter uses it for full-fidelity gen
// metadata on each shared imageJobId. Returns null so the exporter falls
diff --git a/server/services/sharing/subscriptions.test.js b/server/services/sharing/subscriptions.test.js
index b41eda5d3f..0e489b0ea0 100644
--- a/server/services/sharing/subscriptions.test.js
+++ b/server/services/sharing/subscriptions.test.js
@@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import { mkdtempSync, rmSync, mkdirSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
-import { mockNoPeers } from '../../lib/mockPathsDataRoot.js';
+import { mockNoPeerSync, mockNoPeers } from '../../lib/mockPathsDataRoot.js';
// Universe builder evaluates PATHS.data at module top, so allocate a stable
// temp dir before any service imports. beforeEach wipes + reseeds inside.
@@ -27,6 +27,7 @@ vi.mock('../instances.js', () => mockNoPeers({}, {
getInstanceId: () => Promise.resolve('inst-test'),
UNKNOWN_INSTANCE_ID: 'unknown',
}));
+vi.mock('./peerSync.js', () => mockNoPeerSync());
vi.mock('../mediaJobQueue/index.js', () => ({ getJob: () => null }));
const buckets = await import('./buckets.js');
diff --git a/server/services/universeBuilder.test.js b/server/services/universeBuilder.test.js
index 0511aabc21..270a9db24b 100644
--- a/server/services/universeBuilder.test.js
+++ b/server/services/universeBuilder.test.js
@@ -3,7 +3,7 @@ import { mkdtempSync, rmSync, mkdirSync } from "fs";
import { writeFile, mkdir } from "fs/promises";
import { tmpdir } from "os";
import { join } from "path";
-import { mockNoPeers } from "../lib/mockPathsDataRoot.js";
+import { mockNoPeerSync, mockNoPeers } from "../lib/mockPathsDataRoot.js";
// Real per-suite tmpdir backing the universes/ layout. Each test wipes the
// tree in beforeEach. The fileUtils mock below overrides PATHS.data so the
@@ -45,6 +45,7 @@ vi.mock("../lib/fileUtils.js", async (importOriginal) => {
// federation and the receiving instance persists it into the real data/universes/.
// Mirrors the same guard in importer.test.js and writersRoom/promoteToPipeline.test.js.
vi.mock("./instances.js", () => mockNoPeers());
+vi.mock('./sharing/peerSync.js', () => mockNoPeerSync());
// Pre-seed state into the new per-record layout. Mirrors what migration 034
// produces — each universe lands in `universes/<id>/index.json` and the
diff --git a/server/services/universeBuilderAutoSort.test.js b/server/services/universeBuilderAutoSort.test.js
index 4b33faec1f..8e96e5ec54 100644
--- a/server/services/universeBuilderAutoSort.test.js
+++ b/server/services/universeBuilderAutoSort.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
-import { mockNoPeers } from '../lib/mockPathsDataRoot.js';
+import { mockNoPeerSync, mockNoPeers } from '../lib/mockPathsDataRoot.js';
// In-memory file store mirrors universeBuilderPromote.test.js so a single
// readState/writeState path roundtrips through the same code the real
@@ -21,6 +21,7 @@ vi.mock('crypto', async () => {
});
vi.mock('./instances.js', () => mockNoPeers());
+vi.mock('./sharing/peerSync.js', () => mockNoPeerSync());
const resolveProviderAndModelMock = vi.fn();
const runPromptThroughProviderMock = vi.fn();
diff --git a/server/services/universeBuilderCollectionHook.test.js b/server/services/universeBuilderCollectionHook.test.js
index 66ccbddcc2..2cde8226cf 100644
--- a/server/services/universeBuilderCollectionHook.test.js
+++ b/server/services/universeBuilderCollectionHook.test.js
@@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
-import { mockNoPeers } from '../lib/mockPathsDataRoot.js';
+import { mockNoPeerSync, mockNoPeers } from '../lib/mockPathsDataRoot.js';
const tempData = mkdtempSync(join(tmpdir(), 'portos-ubhook-test-data-'));
@@ -26,6 +26,7 @@ vi.mock('../lib/fileUtils.js', async () => {
// uses dataPath whose closure points at REAL PATHS, bypassing the mock
// above).
vi.mock('./instances.js', () => mockNoPeers());
+vi.mock('./sharing/peerSync.js', () => mockNoPeerSync());
const { mediaJobEvents } = await import('./mediaJobQueue/index.js');
const collections = await import('./mediaCollections.js');
diff --git a/server/services/universeBuilderPromote.test.js b/server/services/universeBuilderPromote.test.js
index 65ece5b573..7b38a48c39 100644
--- a/server/services/universeBuilderPromote.test.js
+++ b/server/services/universeBuilderPromote.test.js
@@ -1,6 +1,6 @@
import { describe, it, expect, vi, beforeEach, afterAll } from 'vitest';
import { rmSync, mkdirSync } from 'fs';
-import { mockNoPeers, mockPathsDataRoot } from '../lib/mockPathsDataRoot.js';
+import { mockNoPeerSync, mockNoPeers, mockPathsDataRoot } from '../lib/mockPathsDataRoot.js';
// `wrapExports: ['atomicWrite']` exposes a delegating vi.fn at
// `spies.atomicWrite` so the atomicity test can count writes WITHOUT
@@ -29,6 +29,7 @@ vi.mock('crypto', async () => {
// dataPath closure to the real PATHS once the post-return microtask runs outside this
// file's fileUtils mock window). Mirrors importer.test.js / promoteToPipeline.test.js.
vi.mock('./instances.js', () => mockNoPeers());
+vi.mock('./sharing/peerSync.js', () => mockNoPeerSync());
// Stub the LLM dispatch so tests don't need a live runner. The
// `runPromptThroughProvider` mock is overridden per-test to return the
diff --git a/server/services/universeCanon.test.js b/server/services/universeCanon.test.js
index 07ef8c4553..c62bd5fd37 100644
--- a/server/services/universeCanon.test.js
+++ b/server/services/universeCanon.test.js
@@ -1,6 +1,6 @@
import { describe, it, expect, vi, beforeEach, afterAll } from 'vitest';
import { rmSync, mkdirSync } from 'fs';
-import { mockNoPeers, mockPathsDataRoot } from '../lib/mockPathsDataRoot.js';
+import { mockNoPeerSync, mockNoPeers, mockPathsDataRoot } from '../lib/mockPathsDataRoot.js';
// Real tmpdir backing the per-record store. `mockPathsDataRoot` redirects
// PATHS.data so collectionStore lands under tempRoot/universes/. Everything
@@ -34,6 +34,7 @@ vi.mock('crypto', async () => {
// dataPath closure to the real PATHS once the post-return microtask runs outside this
// file's fileUtils mock window). Mirrors importer.test.js / promoteToPipeline.test.js.
vi.mock('./instances.js', () => mockNoPeers());
+vi.mock('./sharing/peerSync.js', () => mockNoPeerSync());
// The bible extractor + staged-LLM runner + prompt-refine helpers all reach
// out to live AI providers. Stub them to return deterministic shapes so we
diff --git a/server/services/writersRoom/promoteToPipeline.test.js b/server/services/writersRoom/promoteToPipeline.test.js
index 66d2dc9bb0..12e17037eb 100644
--- a/server/services/writersRoom/promoteToPipeline.test.js
+++ b/server/services/writersRoom/promoteToPipeline.test.js
@@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import { mkdtempSync, rmSync, existsSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
-import { makePathsProxy, mockNoPeers } from '../../lib/mockPathsDataRoot.js';
+import { makePathsProxy, mockNoPeerSync, mockNoPeers } from '../../lib/mockPathsDataRoot.js';
let tempRoot;
@@ -16,6 +16,7 @@ vi.mock('../../lib/fileUtils.js', async () => {
// peerSync's autoSubscribeRecordToAllPeers (which reads the live peer
// registry through dataPath closure to the real PATHS).
vi.mock('../instances.js', () => mockNoPeers());
+vi.mock('../sharing/peerSync.js', () => mockNoPeerSync());
const wrLocal = await import('./local.js');
const { promoteWorkToPipeline, ERR_NO_DRAFT_BODY } = await import('./promoteToPipeline.js');