import { describe, expect, it } from 'vitest'; import { assertAppliedMigrationsPresent, assertMigrationChecksum, migrationChecksum, } from '../../scripts/migration-checksum.mjs'; describe('migration checksums', () => { it('is stable for the exact migration bytes', () => { const content = Buffer.from('SELECT 1;\n', 'utf8'); expect(migrationChecksum(content)).toBe(migrationChecksum(content)); }); it('rejects a modified applied migration', () => { const expected = migrationChecksum(Buffer.from('SELECT 1;\n', 'utf8')); const actual = migrationChecksum(Buffer.from('SELECT 2;\n', 'utf8')); expect(() => assertMigrationChecksum('0001', expected, actual)).toThrow( /Applied migration 0001 was modified/, ); }); it('rejects an applied migration removed from the repository', () => { expect(() => assertAppliedMigrationsPresent(['0001', '0002'], ['0002'])).toThrow( /Applied migration 0001 is missing/, ); }); });