test: prune redundant cases and promote configuration lifecycle coverage

This commit is contained in:
morluto
2026-10-09 02:58:03 +08:00
parent bef234d6ce
commit 5945915f91
18 changed files with 237 additions and 417 deletions
@@ -11,54 +11,61 @@ import { cliTest } from "../../support/cli/cliFixture.js";
const filter = "evidence_id,normalized_result.graph.nodes[0:1].node_id";
for (const command of ["analyze-javascript-application", "analyze"]) {
for (const format of ["json", "jsonl"]) {
for (const fullOutput of [false, true]) {
for (const filtered of [false, true]) {
cliTest(
`${command} preserves ${format}, full output ${String(fullOutput)}, filtering ${String(filtered)}`,
async ({ cli }) => {
const root = await createTestTempDirectory("rea-js-json-output-");
await writeFile(join(root, "main.js"), "fetch('');\n");
const direct = await analyzeJavaScriptApplication({
input_path: root,
});
if (!direct.ok) throw direct.error;
const output = await cli.run({
arguments: [
command,
root,
"--format",
format,
...(fullOutput ? ["--full-output"] : []),
...(filtered ? ["--filter-output", filter] : []),
],
});
expect(output.exitCode).toBe(0);
let data: unknown = output.json;
if (fullOutput) {
const envelope = z
.object({
ok: z.literal(true),
data: z.unknown(),
meta: z.object({
command: z.literal(command),
duration: z.string().regex(/^\d+ms$/u),
}),
})
.parse(output.json);
data = envelope.data;
}
expect(data).toEqual(
filtered
? Filter.apply(direct.value, Filter.parse(filter))
: direct.value,
);
},
);
for (const scenario of [
{
command: "analyze-javascript-application",
format: "json",
fullOutput: false,
filtered: true,
},
{
command: "analyze-javascript-application",
format: "jsonl",
fullOutput: true,
filtered: true,
},
{ command: "analyze", format: "json", fullOutput: true, filtered: false },
{ command: "analyze", format: "jsonl", fullOutput: false, filtered: false },
] as const) {
cliTest(
`${scenario.command} preserves representative ${scenario.format} output`,
async ({ cli }) => {
const root = await createTestTempDirectory("rea-js-json-output-");
await writeFile(join(root, "main.js"), "fetch('');\n");
const direct = await analyzeJavaScriptApplication({ input_path: root });
if (!direct.ok) throw direct.error;
const output = await cli.run({
arguments: [
scenario.command,
root,
"--format",
scenario.format,
...(scenario.fullOutput ? ["--full-output"] : []),
...(scenario.filtered ? ["--filter-output", filter] : []),
],
});
expect(output.exitCode).toBe(0);
let data: unknown = output.json;
if (scenario.fullOutput) {
const envelope = z
.object({
ok: z.literal(true),
data: z.unknown(),
meta: z.object({
command: z.literal(scenario.command),
duration: z.string().regex(/^\d+ms$/u),
}),
})
.parse(output.json);
data = envelope.data;
}
}
}
expect(data).toEqual(
scenario.filtered
? Filter.apply(direct.value, Filter.parse(filter))
: direct.value,
);
},
);
}
cliTest(