From 780a3fa8cb42928e56a3155c18d08a35458743ef Mon Sep 17 00:00:00 2001 From: sudacode Date: Thu, 9 Jul 2026 22:39:41 -0700 Subject: [PATCH] fix: apply CodeRabbit auto-fixes --- launcher/test-support/immersion-db-fixture.ts | 1 + .../test-support/immersion-db-schema.test.ts | 34 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/launcher/test-support/immersion-db-fixture.ts b/launcher/test-support/immersion-db-fixture.ts index cc11a36e..3edbaa14 100644 --- a/launcher/test-support/immersion-db-fixture.ts +++ b/launcher/test-support/immersion-db-fixture.ts @@ -53,6 +53,7 @@ export function insertFixtureSession(dbPath: string, input: FixtureSessionInput) const db = new Database(dbPath, { readwrite: true }); const stamp = String(input.startedAtMs); try { + db.run('PRAGMA foreign_keys = ON'); let animeId: number | null = null; if (input.animeTitleKey) { const existing = db diff --git a/launcher/test-support/immersion-db-schema.test.ts b/launcher/test-support/immersion-db-schema.test.ts index 87d79877..f4f1d24e 100644 --- a/launcher/test-support/immersion-db-schema.test.ts +++ b/launcher/test-support/immersion-db-schema.test.ts @@ -5,7 +5,7 @@ import os from 'node:os'; import path from 'node:path'; import { Database as BunDatabase } from 'bun:sqlite'; import { ensureSchema } from '../../src/core/services/immersion-tracker/storage.js'; -import { createImmersionDbFixture } from './immersion-db-fixture.js'; +import { createImmersionDbFixture, insertFixtureSession } from './immersion-db-fixture.js'; type SchemaRow = { type: string; name: string; tbl_name: string; sql: string | null }; @@ -107,3 +107,35 @@ test('fixture schema stays aligned with production sync-touched tables and index fs.rmSync(dir, { recursive: true, force: true }); } }); + +test('fixture session inserts enforce foreign keys', () => { + const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-fixture-foreign-keys-')); + const fixturePath = path.join(dir, 'fixture.sqlite'); + try { + createImmersionDbFixture(fixturePath); + const db = new BunDatabase(fixturePath, { readwrite: true }); + try { + db.run(` + CREATE TRIGGER remove_fixture_video + BEFORE INSERT ON imm_sessions + BEGIN + DELETE FROM imm_videos WHERE video_id = NEW.video_id; + END + `); + } finally { + db.close(); + } + + assert.throws( + () => + insertFixtureSession(fixturePath, { + uuid: 'foreign-key-check', + videoKey: 'foreign-key-check', + startedAtMs: Date.UTC(2026, 6, 9), + }), + /FOREIGN KEY constraint failed/, + ); + } finally { + fs.rmSync(dir, { recursive: true, force: true }); + } +});