From 2bc9e927be04100128226dd214869a2974166cff Mon Sep 17 00:00:00 2001 From: jubnl Date: Mon, 21 Sep 2026 10:22:18 +0200 Subject: [PATCH] test(server): snapshot harness keeps the legacy id semantics --- server/tests/helpers/db-mock.ts | 10 ++++++++++ server/tests/helpers/test-db.ts | 15 +++++++-------- server/tests/integration/immich.test.ts | 5 +++++ server/tests/integration/memories-immich.test.ts | 5 +++++ server/tests/integration/memories-unified.test.ts | 5 +++++ 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/server/tests/helpers/db-mock.ts b/server/tests/helpers/db-mock.ts index 026187452..ebc3c72ff 100644 --- a/server/tests/helpers/db-mock.ts +++ b/server/tests/helpers/db-mock.ts @@ -46,6 +46,16 @@ export function createSnapshotTestDb(): Database.Database { db.exec('PRAGMA journal_mode = WAL'); db.exec('PRAGMA busy_timeout = 5000'); db.exec('PRAGMA foreign_keys = ON'); + // The snapshot carries the first-run seeded `admin` row (id 1); the legacy + // createTestDb() started with no users at all, so the first user a test + // created was always id 1. Normalise ONCE, here, rather than resetting the + // sequence on every resetTestDb() call: ids then keep growing across tests + // within a file exactly as they did under the legacy helper, which several + // suites (oauth.test.ts's per-user client cap, mcp.test.ts's in-memory + // session registry, memories-synology.test.ts's insert-once fixtures) rely + // on to stay disjoint from one test to the next. + db.exec('DELETE FROM users'); + db.exec("DELETE FROM sqlite_sequence WHERE name = 'users'"); return db; } diff --git a/server/tests/helpers/test-db.ts b/server/tests/helpers/test-db.ts index 02692d932..ef94f5132 100644 --- a/server/tests/helpers/test-db.ts +++ b/server/tests/helpers/test-db.ts @@ -248,14 +248,13 @@ export function resetTestDb(db: Database.Database): void { db.exec(`DELETE FROM "${table}"`); } } - // Restart ids at 1, exactly as a fresh legacy database did — the snapshot's - // seeded `admin` user (id 1) was just deleted above, and the factories assume - // a clean autoincrement sequence. - const seqTable = existingTables.has('sqlite_sequence'); - if (seqTable) { - const clear = db.prepare('DELETE FROM sqlite_sequence WHERE name = ?'); - for (const table of RESET_TABLES) if (existingTables.has(table)) clear.run(table); - } + // No sqlite_sequence reset here, on purpose: the legacy helper never reset + // sequences either, so ids keep growing across tests within a file. Several + // suites (oauth.test.ts's per-user client cap, mcp.test.ts's in-memory + // session registry keyed by user id, memories-synology.test.ts's + // insert-once fixtures) rely on that to stay disjoint from one test to the + // next. The snapshot's one seeded row (the first-run `admin` user) is + // normalised away once, in createSnapshotTestDb() (db-mock.ts), not here. db.exec('PRAGMA foreign_keys = ON'); seedDefaults(db); } diff --git a/server/tests/integration/immich.test.ts b/server/tests/integration/immich.test.ts index fb3e4fd06..df20363dc 100644 --- a/server/tests/integration/immich.test.ts +++ b/server/tests/integration/immich.test.ts @@ -68,6 +68,11 @@ beforeEach(() => { resetRateLimits(nestApp); // Providers only count as enabled under an enabled journey addon (migration 84 seeds it off). setAddonEnabled(testDb, 'journey', true); + // The migrated snapshot seeds photo_providers.immich.enabled = 0 (an admin must + // configure it before it's usable in production); the legacy test helper always + // seeded it enabled, which is what these tests assume. Same convention + // memories-synology.test.ts already uses for its own provider. + testDb.prepare("UPDATE photo_providers SET enabled = 1 WHERE id = 'immich'").run(); }); afterAll(async () => { diff --git a/server/tests/integration/memories-immich.test.ts b/server/tests/integration/memories-immich.test.ts index 61609b9a8..c6bdb8455 100644 --- a/server/tests/integration/memories-immich.test.ts +++ b/server/tests/integration/memories-immich.test.ts @@ -219,6 +219,11 @@ beforeEach(() => { resetRateLimits(nestApp); // Providers only count as enabled under an enabled journey addon (migration 84 seeds it off). setAddonEnabled(testDb, 'journey', true); + // The migrated snapshot seeds photo_providers.immich.enabled = 0 (an admin must + // configure it before it's usable in production); the legacy test helper always + // seeded it enabled, which is what these tests assume. Same convention + // memories-synology.test.ts already uses for its own provider. + testDb.prepare("UPDATE photo_providers SET enabled = 1 WHERE id = 'immich'").run(); immichState.albumAssets = DEFAULT_ALBUM_ASSETS.map((a) => ({ ...a })); immichState.albumAssetPages = null; immichState.searchCalls = []; diff --git a/server/tests/integration/memories-unified.test.ts b/server/tests/integration/memories-unified.test.ts index 00af86911..a82f63a28 100644 --- a/server/tests/integration/memories-unified.test.ts +++ b/server/tests/integration/memories-unified.test.ts @@ -57,6 +57,11 @@ beforeEach(() => { resetRateLimits(nestApp); // Providers only count as enabled under an enabled journey addon (migration 84 seeds it off). setAddonEnabled(testDb, 'journey', true); + // The migrated snapshot seeds photo_providers.immich.enabled = 0 (an admin must + // configure it before it's usable in production); the legacy test helper always + // seeded it enabled, which is what these tests assume. Same convention + // memories-synology.test.ts already uses for its own provider. + testDb.prepare("UPDATE photo_providers SET enabled = 1 WHERE id = 'immich'").run(); }); afterAll(async () => {