test: honor baseline fingerprint contracts

User-Visible: no
Issue: #108
This commit is contained in:
Matysh
2026-08-13 01:05:19 +03:00
parent e2b0fbfc06
commit ab609ab165
2 changed files with 33 additions and 1 deletions
+17 -1
View File
@@ -1,8 +1,24 @@
import { existsSync } from 'node:fs';
import { resolve } from 'node:path';
import { pathToFileURL } from 'node:url';
import { sourceFingerprint } from '../scripts/source-fingerprint.mjs';
const fingerprintForTree = async (root) => {
const modulePath = resolve(root, 'scripts/source-fingerprint.mjs');
if (!existsSync(modulePath)) return sourceFingerprint(root);
const module = await import(pathToFileURL(modulePath).href);
if (typeof module.sourceFingerprint !== 'function') {
throw new Error(`${modulePath} does not export sourceFingerprint`);
}
return module.sourceFingerprint(root);
};
/** Refuse measurements/screenshots made by a committed bundle from old source. */
export async function assertFreshDemoBundle(page, root = process.cwd()) {
const expected = sourceFingerprint(root);
// A comparative performance run may load an older tree whose fingerprint
// contract is intentionally different from the candidate's. Validate that
// tree with the implementation that built it, not with today's algorithm.
const expected = await fingerprintForTree(root);
const loaded = await page.evaluate(() => globalThis.__HOUSEPLAN_BUILD_FINGERPRINT__ ?? null);
if (loaded !== expected) {
throw new Error(
+16
View File
@@ -39,3 +39,19 @@ test('bundle freshness rejects a missing or stale fingerprint', async () => {
rmSync(root, { recursive: true, force: true });
}
});
test('bundle freshness uses the target tree fingerprint contract', async () => {
const root = fixtureRoot();
try {
mkdirSync(resolve(root, 'scripts'), { recursive: true });
writeFileSync(
resolve(root, 'scripts/source-fingerprint.mjs'),
"export const sourceFingerprint = () => 'legacy-tree-fingerprint';\n",
'utf8',
);
const page = { evaluate: async () => 'legacy-tree-fingerprint' };
assert.equal(await assertFreshDemoBundle(page, root), 'legacy-tree-fingerprint');
} finally {
rmSync(root, { recursive: true, force: true });
}
});