mirror of
https://github.com/morluto/rea.git
synced 2026-11-29 01:46:39 +00:00
* fix(javascript): refuse directories without JavaScript inputs and name directory-capable operations `analyze <dir>` routed every non-bundle directory to the static JavaScript lane, which reported an all-zero Electron summary as success for native build output. The JavaScript lane now owns that applicability decision from its complete inventory: when coverage is complete and no JavaScript, HTML, package.json, source map, or nested ASAR input exists, it returns a typed unsupported_target refusal naming inspect_desktop_application, audit_release_exposure, inspect_artifact, and open_binary. Incomplete coverage or unavailable files of unknown kind stay unknown and proceed. The directory_requires_file refusal no longer claims to come from open_binary when another operation (inspect, inspect-artifact) admitted the target, and it names the directory-capable operations instead of only the JavaScript lane. * fix(javascript): keep empty directories analyzable and report routing facts for non-JavaScript ones Owner decision on #14186: an empty directory is "nothing to analyze", not "unsupported". The JavaScript lane now classifies application-input presence once, in the domain owner of its file facts (javaScriptApplicationInputPresence): present, empty, absent, or unknown. - empty (complete traversal, no non-directory entries): analysis succeeds as before and the graph carries an explicit "No JavaScript inputs were found" limitation naming the next operations. - absent (complete traversal, entries but no JavaScript, HTML, package.json, source map, or nested ASAR): the typed unsupported_target refusal now carries bounded diagnostics from the inventory the lane already read: inventoried_entries, entries_by_format, json_files and native_addon_files. No paths are retained. - unknown (incomplete traversal or unavailable file of unknown kind) and present: unchanged analysis. Reverts the fixture edits that added package.json to empty directories.
283 lines
8.5 KiB
TypeScript
283 lines
8.5 KiB
TypeScript
import { mkdir, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
|
|
import { expect } from "vitest";
|
|
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { cliTest } from "../../support/cli/cliFixture.js";
|
|
import { buildGamecubeDol } from "../../../src/domain/gamecubeDol.fixture.js";
|
|
|
|
cliTest(
|
|
"validates GameCube format and architecture selections",
|
|
async ({ cli }) => {
|
|
const root = await createTestTempDirectory("rea-dol-cli-");
|
|
const path = join(root, "image.dol");
|
|
await writeFile(path, buildGamecubeDol());
|
|
const result = await cli.run({
|
|
arguments: [
|
|
"inspect",
|
|
path,
|
|
"--target-format",
|
|
"gamecube-dol",
|
|
"--architecture",
|
|
"arm64",
|
|
"--json",
|
|
],
|
|
environment: { HOME: root, XDG_CONFIG_HOME: root, XDG_CACHE_HOME: root },
|
|
});
|
|
expect(result.exitCode).toBe(1);
|
|
// open_binary's pairing rule refuses before the target is opened.
|
|
expect(result.json).toMatchObject({
|
|
code: "invalid_request",
|
|
details: {
|
|
operation: "binary_overview",
|
|
issues: [
|
|
expect.objectContaining({
|
|
path: ["architecture"],
|
|
message: expect.stringMatching(
|
|
/gamecube-dol.*architecture.*DOL header/iu,
|
|
),
|
|
}),
|
|
],
|
|
},
|
|
});
|
|
const invalid = await cli.run({
|
|
arguments: ["inspect", path, "--target-format", "gamecube", "--json"],
|
|
environment: { HOME: root, XDG_CONFIG_HOME: root, XDG_CACHE_HOME: root },
|
|
});
|
|
expect(invalid.exitCode).not.toBe(0);
|
|
expect(invalid.json).toMatchObject({
|
|
code: "VALIDATION_ERROR",
|
|
fieldErrors: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
code: "invalid_value",
|
|
path: "target-format",
|
|
}),
|
|
]),
|
|
});
|
|
},
|
|
);
|
|
|
|
cliTest(
|
|
"rejects a headerless image until architecture and entry are supplied",
|
|
async ({ cli }) => {
|
|
const root = await createTestTempDirectory("rea-raw-cli-");
|
|
const path = join(root, "ecu.bin");
|
|
await writeFile(path, Buffer.from("1eff2fe1", "hex"));
|
|
const before = await cli.run({
|
|
arguments: ["inspect", path, "--json"],
|
|
environment: {
|
|
HOME: root,
|
|
XDG_CONFIG_HOME: root,
|
|
XDG_CACHE_HOME: root,
|
|
},
|
|
});
|
|
expect(before.exitCode).not.toBe(0);
|
|
expect(JSON.stringify(before.json)).not.toContain("raw-binary");
|
|
const missing = await cli.run({
|
|
arguments: ["inspect", path, "--target-format", "raw-binary", "--json"],
|
|
environment: {
|
|
HOME: root,
|
|
XDG_CONFIG_HOME: root,
|
|
XDG_CACHE_HOME: root,
|
|
},
|
|
});
|
|
expect(missing.exitCode).toBe(1);
|
|
expect(missing.json).toMatchObject({
|
|
code: "invalid_request",
|
|
details: {
|
|
issues: [
|
|
expect.objectContaining({
|
|
path: ["architecture"],
|
|
message: expect.stringContaining("architecture"),
|
|
}),
|
|
],
|
|
},
|
|
});
|
|
},
|
|
);
|
|
|
|
cliTest(
|
|
"rejects a 6502 image crossing the 16-bit boundary before provider startup",
|
|
async ({ cli }) => {
|
|
const root = await createTestTempDirectory("rea-6502-cli-overflow-");
|
|
const path = join(root, "image.bin");
|
|
await writeFile(path, Buffer.from("a92a60", "hex"));
|
|
const result = await cli.run({
|
|
arguments: [
|
|
"inspect",
|
|
path,
|
|
"--target-format",
|
|
"raw-binary",
|
|
"--architecture",
|
|
"6502",
|
|
"--entry-point",
|
|
"0xffff",
|
|
"--provider",
|
|
"ghidra",
|
|
"--json",
|
|
],
|
|
environment: { HOME: root, XDG_CONFIG_HOME: root, XDG_CACHE_HOME: root },
|
|
});
|
|
expect(result.exitCode).toBe(1);
|
|
expect(result.json).toMatchObject({
|
|
code: "invalid_request",
|
|
details: {
|
|
reason: expect.stringContaining("6502 address width"),
|
|
related_parameters: ["format", "architecture", "entry_point"],
|
|
related_cli_flags: {
|
|
format: "--target-format",
|
|
architecture: "--architecture",
|
|
entry_point: "--entry-point",
|
|
},
|
|
},
|
|
});
|
|
},
|
|
);
|
|
|
|
cliTest.for([
|
|
["arm64", "c0035fd6", "0x8000001", "must be 4-byte aligned"],
|
|
["m68k", "4e75", "0x1001", "must be 2-byte aligned"],
|
|
] as const)(
|
|
"rejects an unaligned %s entry before provider startup",
|
|
async ([architecture, bytes, entryPoint, reason], { cli }) => {
|
|
const root = await createTestTempDirectory("rea-raw-cli-alignment-");
|
|
const path = join(root, "image.bin");
|
|
await writeFile(path, Buffer.from(bytes, "hex"));
|
|
const result = await cli.run({
|
|
arguments: [
|
|
"analyze",
|
|
path,
|
|
"--target-format",
|
|
"raw-binary",
|
|
"--architecture",
|
|
architecture,
|
|
"--entry-point",
|
|
entryPoint,
|
|
"--provider",
|
|
"ghidra",
|
|
"--json",
|
|
],
|
|
environment: { HOME: root, XDG_CONFIG_HOME: root, XDG_CACHE_HOME: root },
|
|
});
|
|
expect(result.exitCode).toBe(1);
|
|
expect(result.json).toMatchObject({
|
|
code: "invalid_request",
|
|
details: {
|
|
reason: expect.stringContaining(reason),
|
|
related_cli_flags: {
|
|
format: "--target-format",
|
|
architecture: "--architecture",
|
|
entry_point: "--entry-point",
|
|
},
|
|
},
|
|
});
|
|
},
|
|
);
|
|
|
|
cliTest(
|
|
"stops Hopper from claiming a caller-supplied raw-binary image",
|
|
async ({ cli }) => {
|
|
const root = await createTestTempDirectory("rea-raw-cli-hopper-");
|
|
const path = join(root, "ecu.bin");
|
|
await writeFile(path, Buffer.from("1eff2fe1", "hex"));
|
|
const result = await cli.run({
|
|
arguments: [
|
|
"inspect",
|
|
path,
|
|
"--target-format",
|
|
"raw-binary",
|
|
"--architecture",
|
|
"arm",
|
|
"--entry-point",
|
|
"0x8000000",
|
|
"--provider",
|
|
"hopper",
|
|
"--json",
|
|
],
|
|
environment: {
|
|
HOME: root,
|
|
XDG_CONFIG_HOME: root,
|
|
XDG_CACHE_HOME: root,
|
|
},
|
|
});
|
|
expect(result.exitCode).toBe(1);
|
|
expect(JSON.stringify(result.json)).toMatch(/Hopper|ghidra|Ghidra|hopper/i);
|
|
expect(JSON.stringify(result.json)).not.toMatch(
|
|
/unsupported binary format/i,
|
|
);
|
|
},
|
|
);
|
|
|
|
cliTest(
|
|
"renders related_cli_commands across registrars when target opening directs to another lane",
|
|
async ({ cli }) => {
|
|
const root = await createTestTempDirectory("rea-open-related-cli-");
|
|
const env = { HOME: root, XDG_CONFIG_HOME: root, XDG_CACHE_HOME: root };
|
|
|
|
const wasmPath = join(root, "module.wasm");
|
|
await writeFile(wasmPath, Buffer.from([0, 0x61, 0x73, 0x6d, 1, 0, 0, 0]));
|
|
const wasm = await cli.run({
|
|
arguments: ["inspect", wasmPath, "--json"],
|
|
environment: env,
|
|
});
|
|
expect(wasm.exitCode).toBe(1);
|
|
expect(wasm.json).toMatchObject({
|
|
code: "target_unavailable",
|
|
details: {
|
|
constraint: "wasm_requires_static_inspection",
|
|
related_operations: ["inspect_wasm_artifact"],
|
|
related_cli_commands: {
|
|
inspect_wasm_artifact: "rea inspect-wasm-artifact",
|
|
},
|
|
},
|
|
});
|
|
|
|
const plainDirectory = join(root, "plain-js-dir");
|
|
await mkdir(plainDirectory);
|
|
const directory = await cli.run({
|
|
arguments: ["inspect", plainDirectory, "--json"],
|
|
environment: env,
|
|
});
|
|
expect(directory.exitCode).toBe(1);
|
|
expect(directory.json).toMatchObject({
|
|
code: "target_unavailable",
|
|
details: {
|
|
constraint: "directory_requires_file",
|
|
related_operations: [
|
|
"inspect_desktop_application",
|
|
"audit_release_exposure",
|
|
"analyze_javascript_application",
|
|
],
|
|
related_cli_commands: {
|
|
inspect_desktop_application: "rea inspect-desktop-application",
|
|
audit_release_exposure: "rea audit-release-exposure",
|
|
analyze_javascript_application: "rea analyze-javascript-application",
|
|
},
|
|
},
|
|
});
|
|
|
|
const bundle = join(root, "Codeless.app", "Contents");
|
|
await mkdir(bundle, { recursive: true });
|
|
await writeFile(
|
|
join(bundle, "Info.plist"),
|
|
'<?xml version="1.0" encoding="UTF-8"?><plist version="1.0"><dict></dict></plist>',
|
|
);
|
|
const missingExec = await cli.run({
|
|
arguments: ["inspect", join(root, "Codeless.app"), "--json"],
|
|
environment: env,
|
|
});
|
|
expect(missingExec.exitCode).toBe(1);
|
|
expect(missingExec.json).toMatchObject({
|
|
code: "target_unavailable",
|
|
details: {
|
|
constraint: "bundle_executable_undeclared",
|
|
related_operations: ["inspect_plist"],
|
|
related_cli_commands: {
|
|
inspect_plist: "rea inspect-plist",
|
|
},
|
|
},
|
|
});
|
|
},
|
|
);
|