Files
rea/tests/boundary/cli/javascriptArtifactBomRanges.test.ts
T
Rudy Mizrahi Celekli 83defc054b fix(javascript): preserve original BOM source coordinates (#1093)
* test(javascript): reproduce BOM source range drift

Compare original UTF-8 source bytes and their retained digests with direct Babel and parse5 source-location oracles through actual directory and ASAR artifact reconstruction and both built public CLI analysis commands. Preserve no-BOM, structured-BOM and invalid UTF-8 controls. Tests only; production and workflows unchanged.

Signed-off-by: Rudy Celekli <rudy@gradiahq.com>

* fix(javascript): preserve original BOM source coordinates

Retain the initial UTF-8 BOM for JavaScript and HTML source text so graph ranges refer to the original digest-bound bytes. Preserve structured-text BOM handling and fatal UTF-8 decoding.

Signed-off-by: Rudy Celekli <rudy@gradiahq.com>

* style(javascript): format BOM decoder option

Apply the locked Oxfmt line wrapping to the approved decoder option; no behavior or test changes.

Signed-off-by: Rudy Celekli <rudy@gradiahq.com>

---------

Signed-off-by: Rudy Celekli <rudy@gradiahq.com>
2026-10-09 00:09:55 +08:00

46 lines
1.5 KiB
TypeScript

import { expect } from "vitest";
import { parseEvidence } from "../../../src/domain/evidence.js";
import { javascriptApplicationAnalysisResultSchema } from "../../../src/domain/javascript/javascriptApplicationAnalysis.js";
import {
bomSourceCases,
createBomArtifact,
expectBomSourceRange,
} from "../../fixtures/javascriptArtifactBom.js";
import { cliTest } from "../../support/cli/cliFixture.js";
for (const format of ["directory", "asar"] as const) {
for (const command of ["analyze-javascript-application", "analyze"]) {
cliTest(
`${command} preserves original BOM coordinates for ${format}`,
async ({ cli }) => {
const files = Object.fromEntries(
bomSourceCases.map((fixture) => [
fixture.path,
Buffer.from(`\uFEFF${fixture.source}`),
]),
);
const input = await createBomArtifact(format, {
...files,
"dep.js": "export const dependency = true;",
});
const output = await cli.run({ arguments: [command, input, "--json"] });
expect(output.exitCode).toBe(0);
const result = javascriptApplicationAnalysisResultSchema.parse(
parseEvidence(output.json).normalized_result,
);
expect(result.statistics).toMatchObject({
parse_failures: 0,
invalid_utf8_files: 0,
});
for (const fixture of bomSourceCases)
expectBomSourceRange(
result.graph,
fixture,
Buffer.from(`\uFEFF${fixture.source}`),
);
},
);
}
}