import test from 'node:test';import assert from 'node:assert/strict';import {ACCOUNT_MIGRATION_ALLOWLIST} from '../node/minimal-account-migration.mjs';import {compareMigrationSchema,inspectMigrationSchema} from '../node/migration-schema-contract.mjs'; test('all expected migration columns pass schema check',()=>{const actual=Object.fromEntries(Object.entries(ACCOUNT_MIGRATION_ALLOWLIST).map(([k,v])=>[k,[...v]]));assert.deepEqual(compareMigrationSchema(actual),{ok:true,errors:[]});}); test('missing email table or rank column fails closed',()=>{const actual=Object.fromEntries(Object.entries(ACCOUNT_MIGRATION_ALLOWLIST).map(([k,v])=>[k,[...v]]));delete actual.site_contact_emails;actual.cp_account_ranks=actual.cp_account_ranks.filter(c=>c!=='rank_key');const result=compareMigrationSchema(actual);assert.equal(result.ok,false);assert.deepEqual(result.errors,['Missing table site_contact_emails','Missing cp_account_ranks.rank_key']);}); test('inspector reads information_schema without changing data',async()=>{const expected=Object.entries(ACCOUNT_MIGRATION_ALLOWLIST).flatMap(([TABLE_NAME,cols])=>cols.map(COLUMN_NAME=>({TABLE_NAME,COLUMN_NAME})));let sql,params;const db={prepare(query){sql=query;return {bind(...args){params=args;return {async all(){return {results:expected};}};}};}};const result=await inspectMigrationSchema(db);assert.equal(result.ok,true);assert.match(sql,/information_schema\.COLUMNS/);assert.equal(params.length,Object.keys(ACCOUNT_MIGRATION_ALLOWLIST).length);});