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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix([issue-1964]): make peerSync full-sync coverage test hermetic
[._.]/ Adam Eivy7665514f6512
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 3754635e02..bc9665f040 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -93,6 +93,7 @@## Internal+- **[issue-1964] Made `peerSync.test.js` full-sync coverage hermetic** — `getFullSyncCoverageForPeer` walks every subscribable record kind, but the test only mocked the universe/series/collection/artist/album/track/music-video list backends. The author, creative-director-project, mood-board, and writers-room (work/folder/exercise) list backends were left unmocked, so a developer running the full server suite against a populated local `portos` Postgres saw the coverage `total` count real rows instead of the fixture (`expected 3 to be 1`) — an order-dependent flake that repeatedly forced a "known flake or real break?" judgment during merge gating. Those six list functions are now partially mocked (the module's real merge/get/tombstone surface is preserved via `importOriginal`; only the DB-reading list function is overridden) and defaulted to empty in `beforeEach`, so coverage is driven purely by each test's fixture regardless of suite order or DB contents. Test-only. (#1964)- **[issue-1947] Boot migrations no longer crash when a server is booted from inside a CoS agent worktree** — every path in the boot-migration chain derived its data root from where the executing file lives (`import.meta.url`), so a `node server/index.js` launched from inside a CoS agent's git worktree (`data/cos/worktrees/agent-*/`) resolved `data/`/`data.reference/` to the worktree's checkout, which has no gitignored runtime tree — boot migrations then crashed on ENOENT (observed: migration 005 writing `data/prompts/stages/pipeline-arc-overview.md`). Two fixes: (1) a durable `PORTOS_DATA_ROOT` env var (new `server/lib/dataRoot.js` `resolveInstallRoot`), pinned at real launch in `ecosystem.config.cjs`, that lets a process pin its install root explicitly instead of inferring it from the executing file — now preferred over the derived path in `PATHS` (`server/lib/fileUtils.js`), `server/index.js`'s migration call, and `scripts/run-migrations.js`; falls back to the derived path when unset (backward compatible). (2) a defensive backstop in `runMigrations` — `isWorktreeRoot()` detects a `data/cos/worktrees/`-rooted path and skips the migration pass with a single-line warning instead of crashing (keyed on the path segment only, so a fresh install's empty `data/` isn't a false positive). (Closes #1947)- **[issue-1848] Strengthened weak truthiness test assertions** — replaced `toBeTruthy()` checks that would pass on wrong values with concrete value/shape assertions: `autobiography.test.js` now asserts the next-prompt object shape and round-trippable ISO-8601 timestamps for `createdAt`/`updatedAt`/`lastPromptAt`/`followUpsGeneratedAt` (with `updatedAt`/`lastPromptAt` proven strictly newer than the seeded old values); `storyBuilder.test.js` asserts `getSeries()` returns the matching `series.id` and `lockedAt` is a valid ISO timestamp; `commandSecurity.test.js` anchors the allowlist against known-safe membership (`git`/`gh`/`node`/`npm`/`pm2`/`ls`/`cat`/`echo`) and asserts dangerous commands stay absent, replacing the self-referential array-vs-Set check; and `fileUtils.test.js`'s visualTemplates resolution now asserts the returned path carries the `data/templates/` segment + unique basename. (#1848)- **[issue-1842] Replaced magic numbers with canonical constants** — consolidated the duplicated chars-per-token estimate (`Math.ceil(len / 4)`) onto the canonical `estimateTokens()` / `CHARS_PER_TOKEN` from `server/lib/contextBudget.js` at the usage-recording (`server/index.js`, `services/agentRunTracking.js`) and digital-twin-export (×5) sites, and dropped the shadow `estimateTokens` in `services/memoryEmbeddings.js` (now re-exported from `contextBudget` so existing importers are unaffected; `truncateToTokens` uses `CHARS_PER_TOKEN` too). The CoS runner port `5558` was a raw literal in `cos-runner/index.js`, `services/cosRunnerClient.js`, and `services/apps.js`; the importable `server/lib/ports.js` mirror (previously only API/API_LOCAL/UI) now carries the remaining static ecosystem ports (CDP, CDP_HEALTH, `COS`, AUTOFIXER, AUTOFIXER_UI) and those sites use `PORTS.COS` (and `PORTS.CDP`/`AUTOFIXER`/`AUTOFIXER_UI` for the sibling app definitions that were also literals). The CoS runner's kill/cleanup `setTimeout` literals are now named (`SIGKILL_GRACE_MS`, `ORPHAN_CLEANUP_DELAY_MS`, `SHUTDOWN_DRAIN_MS`) and the server's graceful-shutdown force-exit timeout is `GRACEFUL_SHUTDOWN_TIMEOUT_MS`. Behavior-preserving. (#1842)diff --git a/server/services/sharing/peerSync.test.js b/server/services/sharing/peerSync.test.jsindex a13a256ce8..4542d624ef 100644--- a/server/services/sharing/peerSync.test.js+++ b/server/services/sharing/peerSync.test.js@@ -124,6 +124,35 @@ vi.mock('../musicVideo/projects.js', async () => ({mergeProjectsFromSync: vi.fn(),}));+// #1964 — getFullSyncCoverageForPeer walks EVERY PEER_SUBSCRIBABLE_KIND and+// calls listRecordsForKind for each. These four backends were previously left+// unmocked, so on a developer machine with a populated `portos` Postgres the+// coverage `total` counted REAL author / CD-project / mood-board / writers-room+// rows instead of the fixture — the order-dependent flake tracked in #1964+// (`expected 3 to be 1`). Partially mock them (spread the real module via+// importOriginal so the merge/get/tombstone/asset surface other sharing modules+// import stays intact) and override ONLY the DB-reading list functions, so+// coverage is driven purely by the per-test fixture, hermetic regardless of+// suite order or DB contents.+vi.mock('../authors/index.js', async (importOriginal) => ({+ ...(await importOriginal()),+ listAuthors: vi.fn().mockResolvedValue([]),+}));+vi.mock('../creativeDirector/local.js', async (importOriginal) => ({+ ...(await importOriginal()),+ listProjects: vi.fn().mockResolvedValue([]),+}));+vi.mock('../moodBoard/index.js', async (importOriginal) => ({+ ...(await importOriginal()),+ listBoards: vi.fn().mockResolvedValue([]),+}));+vi.mock('../writersRoom/sync.js', async (importOriginal) => ({+ ...(await importOriginal()),+ listWorksForSync: vi.fn().mockResolvedValue([]),+ listFoldersForSync: vi.fn().mockResolvedValue([]),+ listExercisesForSync: vi.fn().mockResolvedValue([]),+}));+vi.mock('../../lib/peerHttpClient.js', async () => ({peerFetch: vi.fn(),peerSocketOptions: {},@@ -198,6 +227,12 @@ import {listProjects as listMusicVideoProjects,mergeProjectsFromSync as mergeMusicVideoProjectsFromSync,} from '../musicVideo/projects.js';+// #1964 — list backends the full-sync coverage path reads; imported so the+// beforeEach can reset each to an empty fixture (see the partial mocks above).+import { listAuthors } from '../authors/index.js';+import { listProjects as listCreativeDirectorProjects } from '../creativeDirector/local.js';+import { listBoards } from '../moodBoard/index.js';+import { listWorksForSync, listFoldersForSync, listExercisesForSync } from '../writersRoom/sync.js';import { peerFetch } from '../../lib/peerHttpClient.js';import { reconcileMediaAssets } from '../mediaAssetIndex/index.js';import { getBackendName } from '../memoryBackend.js';@@ -298,6 +333,14 @@ beforeEach(async () => {vi.mocked(getMusicVideoProject).mockReset().mockResolvedValue(null);vi.mocked(listMusicVideoProjects).mockReset().mockResolvedValue([]);vi.mocked(mergeMusicVideoProjectsFromSync).mockReset().mockResolvedValue({ applied: true, count: 1 });+ // #1964 — default the remaining coverage list backends to empty so the full-+ // sync coverage `total` is fixture-driven, never leaking real Postgres rows.+ vi.mocked(listAuthors).mockReset().mockResolvedValue([]);+ vi.mocked(listCreativeDirectorProjects).mockReset().mockResolvedValue([]);+ vi.mocked(listBoards).mockReset().mockResolvedValue([]);+ vi.mocked(listWorksForSync).mockReset().mockResolvedValue([]);+ vi.mocked(listFoldersForSync).mockReset().mockResolvedValue([]);+ vi.mocked(listExercisesForSync).mockReset().mockResolvedValue([]);// Catalog bundle defaults: non-postgres backend (no bundle), empty DB read,// no-op apply. The catalog-bundle suite overrides these per-test.vi.mocked(getBackendName).mockReset().mockReturnValue('file');