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

fix([issue-1150]): address claude review — boot sanity check, doc refresh, test cleanup hygiene

[._.]/ Adam Eivye742d828584c
diff --git a/server/services/pipeline/series.test.js b/server/services/pipeline/series.test.js
index dd6ec998bd..d9f1596e86 100644
--- a/server/services/pipeline/series.test.js
+++ b/server/services/pipeline/series.test.js
@@ -1,4 +1,4 @@
-import { describe, it, expect, vi, beforeEach } from 'vitest';
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { mockNoPeerSync, mockNoPeers } from '../../lib/mockPathsDataRoot.js';
const fileStore = new Map();
@@ -29,6 +29,12 @@ describe('pipeline series service', () => {
uuidCounter = 0;
});
+ // A test that registers a subscription-adapter double must not leak it into
+ // later tests even when its assertions fail mid-body.
+ afterEach(() => {
+ __resetSubscriptionAdapter();
+ });
+
it('listSeries returns [] for fresh state', async () => {
expect(await svc.listSeries()).toEqual([]);
});
@@ -184,7 +190,6 @@ describe('pipeline series service', () => {
expect(subscribeSpy).toHaveBeenCalledWith('series', id);
emitSpy.mockRestore();
- __resetSubscriptionAdapter();
});
it('insertSeriesWithId fresh insert does NOT fire emitRecordUpdated', async () => {
diff --git a/server/services/sharing/index.js b/server/services/sharing/index.js
index c42b9ba354..eef5360e02 100644
--- a/server/services/sharing/index.js
+++ b/server/services/sharing/index.js
@@ -13,6 +13,7 @@ import { attachAllWatchers, attachWatcher, detachWatcher, shutdownAllWatchers, l
import { sharingEvents } from './importer.js';
import { installSubscriptionListener } from './subscriptions.js';
import { installPeerSyncListener, uninstallPeerSyncListener, peerSyncEvents } from './peerSync.js';
+import { hasSubscriptionAdapter } from './recordEvents.js';
import { initAnnotationsSync } from './annotationsSync.js';
export { sharingEvents } from './importer.js';
@@ -26,6 +27,13 @@ export async function initSharing({ io: socketIo } = {}) {
if (initialized) return;
initialized = true;
io = socketIo || null;
+ // Boot sanity check: peerSync.js wires the subscription adapter at module
+ // load (this file imports it statically, so it's registered by the time we
+ // run). If a future refactor lazies that import, every auto-subscribe
+ // becomes a silent no-op — make that loud instead.
+ if (!hasSubscriptionAdapter()) {
+ console.error('❌ sharing: subscription adapter not registered — peer auto-subscribe is disabled (peerSync.js failed to load?)');
+ }
await ensureDir(join(PATHS.data, 'sharing'));
await ensureDir(join(PATHS.data, 'sharing', 'cursors'));
await ensureDir(join(PATHS.data, 'sharing', 'inbox'));
diff --git a/server/services/sharing/recordEvents.js b/server/services/sharing/recordEvents.js
index 83bbf2106e..cee0a2b723 100644
--- a/server/services/sharing/recordEvents.js
+++ b/server/services/sharing/recordEvents.js
@@ -81,6 +81,11 @@ export function registerSubscriptionAdapter(adapter) {
subscriptionAdapter = adapter;
}
+/** Whether an adapter is wired — initSharing() uses this as a boot sanity check. */
+export function hasSubscriptionAdapter() {
+ return subscriptionAdapter !== null;
+}
+
/** Test-only: detach the adapter so later suites see the unregistered state. */
export function __resetSubscriptionAdapter() {
subscriptionAdapter = null;
diff --git a/server/services/universeBuilder.test.js b/server/services/universeBuilder.test.js
index 0eef6de2b6..d153a054cc 100644
--- a/server/services/universeBuilder.test.js
+++ b/server/services/universeBuilder.test.js
@@ -1,4 +1,4 @@
-import { describe, it, expect, vi, beforeEach, afterAll } from "vitest";
+import { describe, it, expect, vi, beforeEach, afterEach, afterAll } from "vitest";
import { mkdtempSync, rmSync, mkdirSync } from "fs";
import { writeFile, mkdir } from "fs/promises";
import { tmpdir } from "os";
@@ -126,6 +126,12 @@ describe("universeBuilder service", () => {
refSheetFilesByName.clear();
});
+ // A test that registers a subscription-adapter double must not leak it into
+ // later tests even when its assertions fail mid-body.
+ afterEach(() => {
+ __resetSubscriptionAdapter();
+ });
+
it("listUniverses returns [] for fresh state", async () => {
expect(await svc.listUniverses()).toEqual([]);
});
@@ -734,7 +740,6 @@ describe("universeBuilder service", () => {
expect(subscribeSpy).toHaveBeenCalledWith("universe", id);
emitSpy.mockRestore();
- __resetSubscriptionAdapter();
});
it("insertUniverseWithId fresh insert does NOT fire emitRecordUpdated", async () => {
diff --git a/server/vitest.setup.js b/server/vitest.setup.js
index d88a13e629..760350898d 100644
--- a/server/vitest.setup.js
+++ b/server/vitest.setup.js
@@ -2,18 +2,21 @@
* Global Vitest setup — peer fan-out firewall.
*
* WHY: `createUniverse` / `createSeries` / `createIssue` fire a non-awaited
- * `autoSubscribeRecordToAllPeers` call after creation. That path reads the
- * real `data/instances.json` via `getPeers()` and then issues live HTTP POSTs
- * to any registered peers (e.g. the user's `null` sync machine). Without a
- * global guard, every `npm test` run creates spurious records on live peers.
+ * `autoSubscribeRecordToAllPeers` call after creation — through the
+ * `recordEvents.js` subscription adapter, which is a no-op until a suite
+ * loads `peerSync.js` (whose module-load registration wires in the real
+ * implementation). The real path reads `data/instances.json` via
+ * `getPeers()` and then issues live HTTP POSTs to any registered peers
+ * (e.g. the user's `null` sync machine). Without a global guard, any suite
+ * that loads the peer-sync graph would create spurious records on live peers.
*
* Forcing `getPeers → []` is sufficient to stop the fan-out on its own:
* `autoSubscribeRecordToAllPeers` early-returns the moment the target list is
- * empty, before any `subscribePeer`/HTTP work — so the `peerSync.js` module
- * may still get dynamically imported, but it issues no network calls. A suite
- * only needs the additional `peerSync.js` mock (per the CLAUDE.md convention)
- * when it wants to *assert against* the peer-sync import path, not to suppress
- * fan-out, which this guard already handles.
+ * empty, before any `subscribePeer`/HTTP work — so even a *registered* real
+ * adapter issues no network calls. A suite only needs the additional
+ * `peerSync.js` mock (per the CLAUDE.md convention) when it imports the
+ * peer-sync graph and wants to keep the registration side effect out
+ * entirely; suites that never load `peerSync.js` get a no-op adapter for free.
*
* WHAT: This file is loaded by Vitest as a `setupFiles` entry (see
* `vitest.config.js`). It registers a global `vi.mock` for