Files

28 lines
1.7 KiB
JavaScript

// Run only under Sage's explicit CLEAR. Reads the pinned baseline Git objects,
// not the edited model or rebuilt candidate bundle. Never writes product files.
import { execFileSync } from 'node:child_process';
import { createHash } from 'node:crypto';
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
import vm from 'node:vm';
import { WIKILINK_CASES } from '../../../../packages/webui/tests/helpers/wikilink-cases.mjs';
const repo = resolve(dirname(fileURLToPath(import.meta.url)), '../../../..');
const base = '487500a16f4ab5902c318509fdec6acc56a543ca';
const git = (...args) => execFileSync('git', args, { cwd: repo, encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 });
const read = path => git('show', `${base}:${path}`);
const source = read('packages/webui/src/public/editor.js');
const build = JSON.parse(read('packages/webui/editor/BUILD.json'));
const sha256 = createHash('sha256').update(source).digest('hex');
if (sha256 !== build.outputs['src/public/editor.js'].sha256) throw Error('baseline bundle differs from its recorded build');
const context = { console }; context.window = context; context.globalThis = context;
vm.createContext(context);
for (const [name, text] of [['markdown-preview.js', read('packages/webui/src/public/markdown-preview.js')], ['editor.js', source]])
vm.runInContext(text, context, { filename: name });
const results = WIKILINK_CASES.map(({ name, text }) => {
const output = context.MosaicEditor.roundTrip(text);
return { name, input: text, output, equal: output === text };
});
console.log(JSON.stringify({ base: git('rev-parse', base).trim(), bundleSha256: sha256,
measuredAt: new Date().toISOString(), allEqual: results.every(r => r.equal), results }, null, 2));