mirror of
https://github.com/morluto/rea.git
synced 2026-11-29 18:06:46 +00:00
* fix(cli)!: accept only the documented kebab-case option spelling REA's argv parser kept incur's second spelling of every option: the camelCase schema key (`--maxRows`) bound like the documented `--max-rows`, although help, completion and manifests list only the kebab-case form. That hidden alias let wrong spellings survive in the guides. The parser now binds only the documented flag. A schema key spelling, including its `--no-` negation, fails as a typed `flag_spelling` failure rendered as PARSE_ERROR that names the documented flag: "Unknown flag: --maxRows. Did you mean --max-rows?". Completion no longer resolves camelCase option names. The sensitive-value scan still treats `--sensitiveValue` as a declaration so its value stays redacted from the refusal. Guides, the inspect-api-contract option description and tests now use the kebab-case flags. BREAKING CHANGE: camelCase option spellings such as `--maxRows` or `--dryRun` are refused; use the kebab-case flag that `--help` lists. * test(cli): exercise invalid dry-run values with the documented flag spelling The invalid dry-run cases in strictPositionals and cliSetup appended --dryRun=false as a later valid override. The parser now refuses that schema key spelling before it validates the dry-run value, so each case failed on flag spelling and never checked that a later override cannot hide an earlier invalid value. The override is now --dry-run=false, and each case asserts the dry-run failure message, so a spelling refusal can no longer satisfy it. The --dryRun=abc case in cliSetup's malformed-value list is removed: it was the --dry-run=abc case under a spelling the parser now refuses before reading the value, and argvParser.test.ts owns that refusal. * test(cli): keep one public case for the flag spelling refusal cliOptionAliases repeated argvParser's three token shapes (bare, inline value, negation) through the full CLI. The parser test owns those shapes and asserts the structured flag_spelling failure with its flag and documented spelling; the CLI keeps one case for the documented PARSE_ERROR projection, whose message is part of the CLI contract. The camel-case sensitive-value case also dropped its trailing --no-<literal> token: the spelling refusal stops parsing before it, so the token no longer exercised anything.
114 lines
3.4 KiB
TypeScript
114 lines
3.4 KiB
TypeScript
import { execFile } from "node:child_process";
|
|
import { promisify } from "node:util";
|
|
|
|
import { expect, it } from "vitest";
|
|
|
|
import { createStrippedAsarAddon } from "../../fixtures/strippedAsarAddon.js";
|
|
|
|
const execute = promisify(execFile);
|
|
const run = async (arguments_: readonly string[]): Promise<unknown> => {
|
|
const { stdout } = await execute(
|
|
process.execPath,
|
|
["scripts/rea.mjs", ...arguments_, "--json"],
|
|
{ cwd: process.cwd(), maxBuffer: 16 * 1024 * 1024 },
|
|
);
|
|
return JSON.parse(stdout);
|
|
};
|
|
|
|
const runFailure = async (arguments_: readonly string[]): Promise<unknown> => {
|
|
try {
|
|
await run(arguments_);
|
|
} catch (cause: unknown) {
|
|
if (typeof cause !== "object" || cause === null || !("stdout" in cause))
|
|
throw cause;
|
|
const stdout = cause.stdout;
|
|
if (typeof stdout !== "string") throw cause;
|
|
return JSON.parse(stdout);
|
|
}
|
|
throw new Error("Expected the CLI command to fail");
|
|
};
|
|
|
|
it.each(["analyze-javascript-application", "analyze"])(
|
|
"%s carries the integrity policy into shared JavaScript analysis",
|
|
async (command) => {
|
|
const { archive, addon } = await createStrippedAsarAddon();
|
|
const result = await run([
|
|
command,
|
|
archive,
|
|
"--integrity-policy",
|
|
"record-and-continue",
|
|
]);
|
|
expect(result).toMatchObject({
|
|
operation: "analyze_javascript_application",
|
|
parameters: { integrity_policy: "record-and-continue" },
|
|
normalized_result: {
|
|
integrity_contradictions: [
|
|
{ logical_path: addon, trust: "observed-untrusted" },
|
|
],
|
|
graph: { coverage: { status: "partial" } },
|
|
},
|
|
});
|
|
},
|
|
);
|
|
|
|
it("rejects the JavaScript integrity policy on binary-only inspection", async () => {
|
|
await expect(
|
|
run([
|
|
"inspect",
|
|
"unused.asar",
|
|
"--integrity-policy",
|
|
"record-and-continue",
|
|
]),
|
|
).rejects.toMatchObject({
|
|
code: 1,
|
|
stdout: expect.stringContaining("Unknown flag: --integrity-policy"),
|
|
});
|
|
});
|
|
|
|
it.each(["fail", "record-and-continue"] as const)(
|
|
"rejects the explicitly selected %s integrity policy on a binary analyze target",
|
|
async (policy) => {
|
|
const failure = await runFailure([
|
|
"analyze",
|
|
"unused.bin",
|
|
"--integrity-policy",
|
|
policy,
|
|
]);
|
|
expect(failure).toMatchObject({
|
|
code: "invalid_request",
|
|
details: {
|
|
issues: [
|
|
{
|
|
path: ["integrityPolicy"],
|
|
reason: "invalid_value",
|
|
message: expect.stringMatching(
|
|
/--integrity-policy.*static JavaScript ASAR\/directory.*native program target.*does not take it/u,
|
|
),
|
|
},
|
|
],
|
|
},
|
|
});
|
|
},
|
|
);
|
|
|
|
it("still routes a binary analyze target without an integrity policy", async () => {
|
|
await expect(run(["analyze", "unused.bin"])).rejects.toMatchObject({
|
|
code: 1,
|
|
stdout: expect.stringContaining("target does not exist"),
|
|
});
|
|
});
|
|
|
|
it("advertises the optional integrity policy without an undefined union", async () => {
|
|
const schema = (await run(["analyze", "--schema"])) as {
|
|
options?: { properties?: { integrityPolicy?: unknown } };
|
|
};
|
|
const policy = schema.options?.properties?.integrityPolicy;
|
|
expect(policy).toMatchObject({
|
|
type: "string",
|
|
enum: ["fail", "record-and-continue"],
|
|
default: "fail",
|
|
description: "Behavior when declared application integrity does not match",
|
|
});
|
|
expect(JSON.stringify(policy)).not.toContain("undefined");
|
|
});
|