import { readFileSync } from 'node:fs'; import { describe, expect, it } from 'vitest'; const sql = readFileSync(new URL('../../server/postgres/migrations/026_regulatory_mapping.sql', import.meta.url), 'utf8'); describe('regulatory mapping batch persistence schema', () => { it('keeps orchestration project-scoped and protects idempotency and active scope', () => { expect(sql).toContain('CREATE TABLE assessor_regulatory_mapping_batches'); expect(sql).toContain('project_id text NOT NULL REFERENCES assessor_projects(id) ON DELETE CASCADE'); expect(sql).toContain('filter_hash text NOT NULL'); expect(sql).toContain('UNIQUE (project_id, idempotency_key)'); expect(sql).toMatch(/UNIQUE INDEX assessor_regulatory_mapping_batches_active_scope_uq[\s\S]*WHERE run_status IN \('queued', 'running'\)/); expect(sql).toContain('(project_id, scope_key, created_at DESC, id DESC)'); expect(sql).not.toContain('source_result_id'); }); });