26 lines
1.5 KiB
TypeScript
26 lines
1.5 KiB
TypeScript
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');
|
|
const [globalSql, batchSql] = sql.split('CREATE TABLE assessor_regulatory_mapping_batches');
|
|
|
|
describe('global regulatory mapping persistence schema', () => {
|
|
it('creates global, rule-keyed mapping tables beside the project-scoped batch table', () => {
|
|
|
|
// Mappings are global: keyed by rule identity plus pipeline versions, never by project or occurrence.
|
|
expect(sql).toContain('CREATE TABLE assessor_regulatory_mappings');
|
|
expect(globalSql).not.toContain('project_id');
|
|
expect(sql).not.toContain('source_result_id');
|
|
expect(sql).not.toContain('DROP TABLE');
|
|
expect(batchSql).toContain('project_id text NOT NULL REFERENCES assessor_projects(id) ON DELETE CASCADE');
|
|
expect(sql).toContain('rule_key text NOT NULL');
|
|
expect(sql).toContain('UNIQUE (rule_key, corpus_version, retrieval_version, prompt_version, model)');
|
|
|
|
// Decisions are global, append-only, keyed by rule identity and control.
|
|
expect(sql).toContain('CREATE TABLE assessor_regulatory_mapping_decisions');
|
|
expect(sql).toContain('previous_decision_id text REFERENCES assessor_regulatory_mapping_decisions(id)');
|
|
expect(sql).toContain("decision text NOT NULL CHECK (decision IN ('accepted', 'rejected'))");
|
|
expect(sql).toMatch(/assessor_regulatory_mapping_decisions_rule_control_idx[\s\S]*\(rule_key, control_id/);
|
|
});
|
|
});
|