import { describe, expect, test } from "bun:test";
import { MAX_RUNS, normalizePath, parseSarif } from "./sarif";
function run(name: string, results: unknown[] = []) {
return { tool: { driver: { name } }, results };
}
describe("parseSarif (INT-A11/INT-A31)", () => {
test("caps the number of runs and flags truncation", () => {
const runs = Array.from({ length: MAX_RUNS + 5 }, (_, index) => run(`tool-${index}`));
const parsed = parseSarif({ version: "2.1.0", runs });
expect(parsed.tools).toHaveLength(MAX_RUNS);
expect(parsed.truncated).toBe(true);
});
test("bounds rule names, line numbers and paths", () => {
const parsed = parseSarif({
version: "2.1.0",
runs: [
{
tool: { driver: { name: "x", rules: [{ id: "r1", name: "n".repeat(500) }] } },
results: [
{
ruleId: "r1",
message: { text: "m" },
locations: [
{
physicalLocation: {
artifactLocation: { uri: "file:///C:/repo/../src/./a.ts" },
region: { startLine: -5, endLine: 10 ** 12 },
},
},
],
},
],
},
],
});
const [result] = parsed.results;
expect(result.ruleName).toHaveLength(200);