Files
hyperframes/packages/inspector/tests/serviceFingerprint.test.ts
Xuanru Li 8af8e48ad9 fix(inspector): data-hf-id stamps alone do not make the live preview stale (#5870)
* fix(inspector): data-hf-id stamps alone do not make the live preview stale

The source fingerprint hashed html byte for byte, so stamping data-hf-id on disk
(Desktop does at project open and when a run ends) made every live query answer
stale_preview. The preview never reloads for an id-only write, because it already
served those ids, so the error lasted until some other edit. The fingerprint now
reads html without its data-hf-id attributes, the same rule Desktop's change
detection uses.

* fix(inspector): ignore HF IDs only for live previews
2026-10-19 21:19:33 +00:00

53 lines
1.9 KiB
TypeScript

import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { expect, it, vi } from "vitest";
import { Inspector } from "../src/service";
vi.mock("puppeteer-core", () => ({
default: {
launch: async () => ({
close: async () => {},
newPage: async () => {
let html = "";
return {
setViewport: async () => {},
goto: async (url: string) => {
html = await (await fetch(url)).text();
},
waitForFunction: async () => {},
evaluate: async () => {},
content: async () => html,
close: async () => {},
};
},
}),
},
}));
it("reloads the standalone page when an HF ID is stamped onto disk", async () => {
const project = mkdtempSync(join(tmpdir(), "inspect-stamp-"));
const path = join(project, "index.html");
const source =
'<!doctype html><html><head></head><body><main data-composition-id="root" data-duration="10" data-width="1920" data-height="1080"><div id="target">Title</div></main></body></html>';
writeFileSync(path, source);
const inspector = new Inspector(project, {
executablePath: "browser-stand-in",
instrument: false,
});
try {
const first = await inspector.withPage((page) => page.content());
expect(first).toContain('id="target"');
expect(first).not.toContain('data-hf-id="hf-t1"');
expect(await inspector.withPage((page) => page.content())).toBe(first);
expect(inspector.stats.pageLoads).toBe(1);
writeFileSync(path, source.replace('id="target"', 'id="target" data-hf-id="hf-t1"'));
const stamped = await inspector.withPage((page) => page.content());
expect(stamped).toContain('data-hf-id="hf-t1"');
expect(inspector.stats.pageLoads).toBe(2);
} finally {
await inspector.dispose();
rmSync(project, { recursive: true, force: true });
}
});