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
test: isolate author and track DB sync tests (#10524)
[._.]/ Adam Eivybc34fe85bdb7
diff --git a/server/services/authors/db.test.js b/server/services/authors/db.test.jsindex 3a8c448b7e..e0515068b3 100644--- a/server/services/authors/db.test.js+++ b/server/services/authors/db.test.js@@ -11,9 +11,17 @@* survive the run even on the test DB.*/-import { describe, it, expect, afterAll, beforeAll, beforeEach } from 'vitest';+import { describe, it, expect, afterAll, beforeAll, beforeEach, vi } from 'vitest';+import { readFile } from 'node:fs/promises';+import { join } from 'node:path';+import { makePathsProxy, lazyTempDataRoot, cleanupTempDataRoots } from '../../lib/mockPathsDataRoot.js';++vi.mock('../../lib/fileUtils.js', async (importOriginal) =>+ makePathsProxy(await importOriginal(), { dataRoot: () => lazyTempDataRoot('portos-authors-db-') }));+import { checkHealth, ensureSchema, query, close } from '../../lib/db.js';import { requireDbOrSkip } from '../../lib/dbTestGate.js';+import { contentHashForRecord, flushBaseHashes, __resetBaseHashCacheForTests } from '../../lib/conflictJournal.js';let dbReady = false;let skipReason = '';@@ -44,17 +52,29 @@ describe.skipIf(!runDb)('authors DB adapter round-trip', () => {beforeEach(async () => { await query(`DELETE FROM authors`); });afterAll(async () => {- // Restore the developer's real personas: clear the test rows, re-insert the- // snapshot. ON CONFLICT DO NOTHING so a partially-restored run is idempotent.- await query(`DELETE FROM authors`).catch(() => {});- for (const r of snap) {- await query(- `INSERT INTO authors (id, name, data, created_at, updated_at, deleted, deleted_at)- VALUES ($1,$2,$3::jsonb,$4,$5,$6,$7) ON CONFLICT (id) DO NOTHING`,- [r.id, r.name, JSON.stringify(r.data), r.created_at, r.updated_at, r.deleted, r.deleted_at],- ).catch(() => {});+ try {+ // Restore the test DB snapshot even after a failed test. ON CONFLICT DO NOTHING+ // makes a partially-restored run idempotent.+ await query(`DELETE FROM authors`).catch(() => {});+ for (const r of snap) {+ await query(+ `INSERT INTO authors (id, name, data, created_at, updated_at, deleted, deleted_at)+ VALUES ($1,$2,$3::jsonb,$4,$5,$6,$7) ON CONFLICT (id) DO NOTHING`,+ [r.id, r.name, JSON.stringify(r.data), r.created_at, r.updated_at, r.deleted, r.deleted_at],+ ).catch(() => {});+ }+ } finally {+ try {+ await close();+ } finally {+ try {+ await flushBaseHashes();+ } finally {+ __resetBaseHashCacheForTests();+ cleanupTempDataRoots();+ }+ }}- await close();});it('creates an author and mirrors name into the queryable column', async () => {@@ -119,6 +139,11 @@ describe.skipIf(!runDb)('authors DB adapter round-trip', () => {const newer = { ...a, name: 'Fresh', updatedAt: '2099-01-01T00:00:00.000Z' };expect(await db.mergeAuthorsFromSync([newer])).toEqual({ applied: true, count: 1 });expect((await db.getAuthor(a.id)).name).toBe('Fresh');+ const bases = JSON.parse(await readFile(+ join(lazyTempDataRoot('portos-authors-db-'), 'sharing', 'sync_base_hashes.json'), 'utf8',+ ));+ expect(bases[`author:${a.id}`].h)+ .toBe(contentHashForRecord('author', await db.getAuthor(a.id)));});it('a newer remote tombstone deletes a live local record', async () => {diff --git a/server/services/tracks/db.test.js b/server/services/tracks/db.test.jsindex 1a3c82d68f..4e3ef7db04 100644--- a/server/services/tracks/db.test.js+++ b/server/services/tracks/db.test.js@@ -4,9 +4,17 @@* Snapshots + restores the `tracks` table. Mirrors albums/db.test.js.*/-import { describe, it, expect, afterAll, beforeAll, beforeEach } from 'vitest';+import { describe, it, expect, afterAll, beforeAll, beforeEach, vi } from 'vitest';+import { readFile } from 'node:fs/promises';+import { join } from 'node:path';+import { makePathsProxy, lazyTempDataRoot, cleanupTempDataRoots } from '../../lib/mockPathsDataRoot.js';++vi.mock('../../lib/fileUtils.js', async (importOriginal) =>+ makePathsProxy(await importOriginal(), { dataRoot: () => lazyTempDataRoot('portos-tracks-db-') }));+import { checkHealth, ensureSchema, query, close } from '../../lib/db.js';import { requireDbOrSkip } from '../../lib/dbTestGate.js';+import { contentHashForRecord, flushBaseHashes, __resetBaseHashCacheForTests } from '../../lib/conflictJournal.js';let dbReady = false;let skipReason = '';@@ -35,15 +43,27 @@ describe.skipIf(!runDb)('tracks DB adapter round-trip', () => {});beforeEach(async () => { await query(`DELETE FROM tracks`); });afterAll(async () => {- await query(`DELETE FROM tracks`).catch(() => {});- for (const r of snap) {- await query(- `INSERT INTO tracks (id, title, data, created_at, updated_at, deleted, deleted_at)- VALUES ($1,$2,$3::jsonb,$4,$5,$6,$7) ON CONFLICT (id) DO NOTHING`,- [r.id, r.title, JSON.stringify(r.data), r.created_at, r.updated_at, r.deleted, r.deleted_at],- ).catch(() => {});+ try {+ await query(`DELETE FROM tracks`).catch(() => {});+ for (const r of snap) {+ await query(+ `INSERT INTO tracks (id, title, data, created_at, updated_at, deleted, deleted_at)+ VALUES ($1,$2,$3::jsonb,$4,$5,$6,$7) ON CONFLICT (id) DO NOTHING`,+ [r.id, r.title, JSON.stringify(r.data), r.created_at, r.updated_at, r.deleted, r.deleted_at],+ ).catch(() => {});+ }+ } finally {+ try {+ await close();+ } finally {+ try {+ await flushBaseHashes();+ } finally {+ __resetBaseHashCacheForTests();+ cleanupTempDataRoots();+ }+ }}- await close();});it('creates a track and mirrors title into the column', async () => {@@ -69,5 +89,10 @@ describe.skipIf(!runDb)('tracks DB adapter round-trip', () => {expect(await db.mergeTracksFromSync([{ ...t, title: 'Old', updatedAt: '2000-01-01T00:00:00.000Z' }])).toEqual({ applied: false, count: 0 });expect(await db.mergeTracksFromSync([{ ...t, title: 'Fresh', updatedAt: '2099-01-01T00:00:00.000Z' }])).toEqual({ applied: true, count: 1 });expect((await db.getTrack(t.id)).title).toBe('Fresh');+ const bases = JSON.parse(await readFile(+ join(lazyTempDataRoot('portos-tracks-db-'), 'sharing', 'sync_base_hashes.json'), 'utf8',+ ));+ expect(bases[`track:${t.id}`].h)+ .toBe(contentHashForRecord('track', await db.getTrack(t.id)));});});