test(javascript): cover the inline-HTML unavailable scope through the public CLI

The analyzer already reports valid HTML containing inline <script> bodies
through an explicit "parse-html-inline-scripts" unavailable scope, so an
application whose endpoints, storage, or imports live in inline scripts is
surfaced as not-analyzed rather than silently empty. That contract was asserted
only at the filesystem boundary (javascriptHtmlEntrypoints.test.ts); the public
CLI acceptance surface had no scenario proving it survives transport.

Add one acceptance case to the existing unavailable-HTML CLI suite. No source change.
This commit is contained in:
Davi Lopes Rosa de Oliveira authored and Ysopwnable committed 2026-11-21 22:29:41 +01:00
1 parent de44e5e273
commit 3eae4de89f
1 file changed
+121
@@ -1,3 +1,4 @@
import { createHash } from "node:crypto";
import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect } from "vitest";
@@ -159,3 +160,123 @@ cliTest(
]);
},
);
cliTest(
"reports an unavailable inline-scripts scope through the CLI while external scripts survive",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-inline-html-cli-");
const inlineUrl = "https://example.test/inline-only";
const inlineKey = "inline-only-key";
const moduleBody = 'import "./main.js";';
const htmlBytes = Buffer.from(
[
"<!doctype html><html><head>",
'<script src="main.js"></script>',
"<script>",
`fetch("${inlineUrl}"); localStorage.setItem("${inlineKey}", "value");`,
"</script>",
`<script type="module">${moduleBody}</script>`,
'<script type="application/json">{"value":42}</script>',
"</head></html>",
].join("\n"),
);
await writeFile(
join(root, "package.json"),
'{"name":"inline-html-scope","main":"main.js"}',
);
await writeFile(
join(root, "main.js"),
'fetch("https://example.test/external");',
);
await writeFile(join(root, "index.html"), htmlBytes);
const response = await cli.run({
arguments: [
"analyze-javascript-application",
root,
...["package.json", "main.js", "index.html"].flatMap((path) => [
"--source-path",
path,
]),
"--format",
"json",
],
});
expect(response.exitCode, response.stderr).toBe(0);
const result = javascriptApplicationAnalysisResultSchema.parse(
parseEvidence(response.json).normalized_result,
);
const scopes = result.graph.nodes
.filter(({ kind }) => kind === "unknown")
.flatMap(({ observations }) => observations)
.filter(
({ properties }) =>
properties.operation === "parse-html-inline-scripts" &&
properties.path === "index.html",
);
expect(scopes).toHaveLength(1);
expect(scopes[0]).toMatchObject({
properties: {
operation: "parse-html-inline-scripts",
path: "index.html",
inline_script_count: 2,
inline_scripts: [
{
script_type: "classic",
location: {
start: { line: 3, column: 8 },
end: { line: 5, column: 0 },
},
},
{
script_type: "module",
location: {
start: { line: 6, column: 22 },
end: { line: 6, column: 22 + moduleBody.length },
},
},
],
},
evidence: {
state: "unavailable",
confidence: "unknown",
artifact: {
sha256: createHash("sha256").update(htmlBytes).digest("hex"),
},
coverage: { status: "partial" },
},
});
expect(result.graph.coverage).toMatchObject({
status: "partial",
truncated: false,
});
expect(result.graph.limitations).toContain(
"index.html has 2 inline JavaScript bodies starting at lines 3, 6 that were not analyzed; endpoints, storage, imports and other facts in them are absent from the evidence.",
);
expect(
result.graph.edges.some(
({ relation, properties }) =>
relation === "loads" && properties.resolved_path === "main.js",
),
).toBe(true);
expect(
result.graph.nodes
.filter(({ kind }) => kind === "endpoint")
.flatMap(({ observations }) => observations)
.map(({ properties }) => properties.value),
).toContain("https://example.test/external");
expect(
result.graph.nodes.some(
({ kind, observations }) =>
kind === "endpoint" &&
observations.some(({ properties }) => properties.value === inlineUrl),
),
).toBe(false);
expect(
result.graph.nodes.some(
({ kind, observations }) =>
kind === "storage" &&
observations.some(({ properties }) => properties.name === inlineKey),
),
).toBe(false);
},
);