mirror of
https://github.com/morluto/rea
synced 2026-10-26 06:16:17 -04:00
d93fbda390
Bundle ordinary CLI and output entries to reduce Windows module filesystem resolution while preserving source URLs, lazy loading and worker resources. Keep release identity in its shared owning module. Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
140 lines
4.2 KiB
TypeScript
140 lines
4.2 KiB
TypeScript
import { writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
|
|
import { expect } from "vitest";
|
|
import { z } from "zod";
|
|
|
|
import { javascriptApplicationAnalysisResultSchema } from "../../../src/domain/javascript/javascriptApplicationAnalysis.js";
|
|
import { analyzeJavaScriptApplication } from "../../support/javascriptApplicationScope.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { cliTest } from "../../support/cli/cliFixture.js";
|
|
|
|
const filter = "evidence_id,normalized_result.graph.nodes[0,1].node_id";
|
|
|
|
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 normalized = javascriptApplicationAnalysisResultSchema.parse(
|
|
direct.value.normalized_result,
|
|
);
|
|
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
|
|
? {
|
|
evidence_id: direct.value.evidence_id,
|
|
normalized_result: {
|
|
graph: {
|
|
nodes: normalized.graph.nodes
|
|
.slice(0, 1)
|
|
.map(({ node_id }) => ({ node_id })),
|
|
},
|
|
},
|
|
}
|
|
: direct.value,
|
|
);
|
|
if (scenario.filtered)
|
|
expect(normalized.graph.nodes.length).toBeGreaterThan(0);
|
|
},
|
|
);
|
|
}
|
|
|
|
cliTest(
|
|
"preserves a complete empty filtered JSON document",
|
|
async ({ cli }) => {
|
|
const root = await createTestTempDirectory("rea-js-json-empty-filter-");
|
|
await writeFile(join(root, "main.js"), "export const value = 1;\n");
|
|
const output = await cli.run({
|
|
arguments: [
|
|
"analyze-javascript-application",
|
|
root,
|
|
"--json",
|
|
"--filter-output",
|
|
"absent.field",
|
|
],
|
|
});
|
|
expect(output.exitCode).toBe(0);
|
|
expect(output.json).toEqual({});
|
|
},
|
|
);
|
|
|
|
cliTest(
|
|
"preserves a typed failed analysis in the JSON result",
|
|
async ({ cli }) => {
|
|
const root = await createTestTempDirectory("rea-js-json-failure-");
|
|
const output = await cli.run({
|
|
arguments: [
|
|
"analyze-javascript-application",
|
|
join(root, "absent"),
|
|
"--json",
|
|
],
|
|
});
|
|
expect(output.json).toMatchObject({
|
|
code: "invalid_request",
|
|
details: { issues: [{ path: ["input_path"], reason: "invalid_value" }] },
|
|
});
|
|
},
|
|
);
|
|
|
|
cliTest(
|
|
"preserves JSON omission for inherited filter methods",
|
|
async ({ cli }) => {
|
|
const root = await createTestTempDirectory("rea-js-json-inherited-filter-");
|
|
await writeFile(join(root, "main.js"), "export const value = 1;\n");
|
|
const output = await cli.run({
|
|
arguments: [
|
|
"analyze-javascript-application",
|
|
root,
|
|
"--json",
|
|
"--filter-output",
|
|
"toString",
|
|
],
|
|
});
|
|
expect(output.exitCode).toBe(0);
|
|
expect(output.json).toEqual({});
|
|
},
|
|
);
|