import { createHash } from "node:crypto"; import { mkdir, writeFile } from "node:fs/promises"; import { join } from "node:path"; import { expect, it } from "vitest"; import { reconstructJavaScriptArtifact } from "../../support/javascriptApplicationScope.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; it("preserves source digest, opening-tag range and decoded local base resolution", async () => { const root = await createTestTempDirectory("rea-html-entrypoint-evidence-"); const opening = '\n'; const html = `${prefix}${opening}`; await mkdir(join(root, "assets")); await Promise.all([ writeFile(join(root, "index.html"), html), writeFile( join(root, "assets", "actual.js"), "globalThis.ownedActual = true;", ), writeFile(join(root, "assets", "decoy.js"), "globalThis.decoy = true;"), ]); const result = await reconstructJavaScriptArtifact({ input_path: root }); const loads = result.graph.edges.filter( ({ relation, properties }) => relation === "loads" && properties.script_path !== undefined, ); expect(loads).toHaveLength(1); expect(loads[0]).toMatchObject({ properties: { script_path: "actual.js", base_href: "assets/", resolved_path: "assets/actual.js", }, evidence: { authority: "static-relationship-inference", artifact: { available: true, sha256: createHash("sha256").update(html).digest("hex"), }, location: { available: true, value: { kind: "source-range", source: "index.html", start: { line: 2, column: 0 }, end: { line: 2, column: opening.length }, }, }, }, }); }); it("preserves external and inline HTML script ranges across line endings", async () => { const root = await createTestTempDirectory("rea-html-coordinate-evidence-"); const opening = '"; const inlineOpening = "', '', "
", "", '', "