// tests/kb-update/test-driver-atomic-writes.test.mjs // RX-OPS2 acceptance: every corpus-writing driver routes its writes through the // crash-safe atomicWriteSync (tmp+rename), never a bare writeFileSync that can leave a // half-written reference file. Mirrors the existing migrate-corpus source guard // (test-migrate-apply.test.mjs) for the five standalone drivers. import { test } from 'node:test'; import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; import { join, dirname } from 'node:path'; import { fileURLToPath } from 'node:url'; const KB = join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'scripts', 'kb-update'); const DRIVERS = [ 'backfill-status.mjs', 'backfill-category.mjs', 'dedup-plain-header.mjs', 'relabel-dato.mjs', 'relabel-dialect.mjs', ]; for (const driver of DRIVERS) { test(`${driver} — writes corpus files via atomicWriteSync, never bare writeFileSync`, () => { const src = readFileSync(join(KB, driver), 'utf8'); assert.match(src, /atomicWriteSync/, `${driver} must import/use the atomic writer`); assert.doesNotMatch(src, /\bwriteFileSync\b/, `${driver} must not call writeFileSync directly`); }); }