[AI] Make embedded migration order deterministic and assert DB in manifest

Address further review feedback:

- Sort migration file names at the source so the embedded dataFiles order
  (and the worker bundle hash) is stable regardless of the filesystem's
  readdirSync ordering.
- Assert the default DB is listed in the embedded manifest, not just that
  its bytes are embedded.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
github-actions[bot]
2026-06-28 21:10:34 +01:00
parent cf97d5c8ac
commit 072e548121
2 changed files with 6 additions and 2 deletions

View File

@@ -23,9 +23,12 @@ export const sqlWasmPath =
require.resolve('@jlongster/sql.js/dist/sql-wasm.wasm');
function migrationFileNames() {
// Sort so the embedded `dataFiles` order (and thus the worker bundle hash) is
// stable regardless of the filesystem's `readdirSync` ordering.
return fs
.readdirSync(migrationsDir)
.filter(name => name.endsWith('.sql') || name.endsWith('.js'));
.filter(name => name.endsWith('.sql') || name.endsWith('.js'))
.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
}
/**

View File

@@ -39,10 +39,11 @@ describe('embedded default filesystem', () => {
});
it('embeds the default database and sql.js wasm byte-for-byte', () => {
const { dataFiles, wasmBase64 } = collectEmbeddedAssets();
const { dataFiles, index, wasmBase64 } = collectEmbeddedAssets();
const embeddedDb = Buffer.from(dataFiles['default-db.sqlite'], 'base64');
expect(embeddedDb.equals(fs.readFileSync(defaultDbPath))).toBe(true);
expect(index.split('\n').filter(Boolean)).toContain('default-db.sqlite');
const embeddedWasm = Buffer.from(wasmBase64, 'base64');
expect(embeddedWasm.equals(fs.readFileSync(sqlWasmPath))).toBe(true);