38 lines
1.6 KiB
TypeScript
38 lines
1.6 KiB
TypeScript
import { readFile } from 'node:fs/promises';
|
|
import { resolve } from 'node:path';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { databaseMigrations } from '../../server/postgres/migration-catalog';
|
|
|
|
const migrationPath = resolve(
|
|
import.meta.dirname,
|
|
'..',
|
|
'..',
|
|
'server',
|
|
'postgres',
|
|
'migrations',
|
|
'016_policy_evaluation_rule_catalogs.sql'
|
|
);
|
|
|
|
describe('PostgreSQL policy evaluation rule catalog migration', () => {
|
|
it('persists released rule catalog provenance and explicit baseline states', async () => {
|
|
const sql = await readFile(migrationPath, 'utf8');
|
|
expect(databaseMigrations.find(migration => migration.version === '016')).toMatchObject({
|
|
version: '016',
|
|
name: 'policy-evaluation-rule-catalogs'
|
|
});
|
|
expect(sql).toContain('ADD COLUMN rule_catalog_id text');
|
|
expect(sql).toContain('ADD COLUMN rule_catalog_version text');
|
|
expect(sql).toContain('ADD COLUMN baseline_state text');
|
|
expect(sql).toContain('ADD COLUMN dependency_rule_ids text[]');
|
|
expect(sql).toContain('ADD COLUMN risk_rule_ids text[]');
|
|
});
|
|
|
|
it('keeps not-applicable and risk-gated finding eligibility closed relationally', async () => {
|
|
const sql = await readFile(migrationPath, 'utf8');
|
|
expect(sql).toContain("classification IN ('configured_match', 'confirmed_configured_deviation', 'not_applicable', 'review_required')");
|
|
expect(sql).toContain("classification <> 'not_applicable' OR baseline_state = 'explicitly-not-applicable'");
|
|
expect(sql).toContain('baseline_state IS NULL OR NOT finding_eligible OR cardinality(risk_rule_ids) > 0');
|
|
expect(sql).not.toMatch(/finding_definition|finding_occurrence/i);
|
|
});
|
|
});
|