mirror of
https://github.com/actualbudget/actual.git
synced 2026-07-10 12:31:32 -05:00
[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:
@@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user