mirror of
https://github.com/morluto/rea.git
synced 2026-11-29 01:46:39 +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.
285 lines
8.1 KiB
TypeScript
285 lines
8.1 KiB
TypeScript
import { describe, expect } from "vitest";
|
|
|
|
import { cliTest, type CliResult } from "../../support/cli/cliFixture.js";
|
|
|
|
const LITERAL = "SYNTHETIC_CAPTURE_LITERAL_83A4";
|
|
const CAPTURE = ["inspect-web-network-capture", "/nonexistent/capture.har"];
|
|
const DECLARED = [...CAPTURE, "har", "--sensitive-value", LITERAL];
|
|
|
|
const expectExcluded = (
|
|
result: CliResult,
|
|
literals: readonly string[] = [LITERAL],
|
|
): void => {
|
|
expect(result.exitCode).toBe(1);
|
|
for (const literal of literals) {
|
|
expect(result.stdout).not.toContain(literal);
|
|
expect(result.stderr).not.toContain(literal);
|
|
}
|
|
};
|
|
|
|
describe("CLI --sensitive-value parser diagnostics", () => {
|
|
cliTest.for([
|
|
{
|
|
name: "negated unknown flag",
|
|
arguments: [...DECLARED, `--no-unknown-option=${LITERAL}`],
|
|
message: "Unknown flag: --no-unknown-option=[REDACTED]",
|
|
},
|
|
{
|
|
name: "unknown flag name",
|
|
arguments: [...DECLARED, `--${LITERAL}`],
|
|
message: "Unknown flag: --[REDACTED]",
|
|
},
|
|
{
|
|
name: "declaration after the rejected token",
|
|
arguments: [
|
|
...CAPTURE,
|
|
"har",
|
|
`--no-${LITERAL}`,
|
|
`--sensitive-value=${LITERAL}`,
|
|
],
|
|
message: "Unknown flag: --no-[REDACTED]",
|
|
},
|
|
{
|
|
name: "camel-case declaration",
|
|
arguments: [...CAPTURE, "har", `--sensitiveValue=${LITERAL}`],
|
|
// The parser refuses the schema key spelling; its value stays redacted.
|
|
message:
|
|
"Unknown flag: --sensitiveValue. Did you mean --sensitive-value?",
|
|
failure: { code: "PARSE_ERROR", retryable: false },
|
|
},
|
|
{
|
|
// Incur removes builtin output flags before reading the declared value.
|
|
name: "builtin flag before the declared value",
|
|
arguments: [
|
|
...CAPTURE,
|
|
"har",
|
|
"--sensitive-value",
|
|
"--json",
|
|
LITERAL,
|
|
`--no-${LITERAL}`,
|
|
],
|
|
message: "Unknown flag: --no-[REDACTED]",
|
|
},
|
|
])(
|
|
"excludes declarations from a JSON $name rejection",
|
|
async (
|
|
{ arguments: arguments_, message, failure = { code: "UNKNOWN" } },
|
|
{ cli },
|
|
) => {
|
|
const result = await cli.run({ arguments: [...arguments_, "--json"] });
|
|
|
|
expectExcluded(result);
|
|
expect(JSON.parse(result.stdout)).toEqual({ ...failure, message });
|
|
},
|
|
);
|
|
|
|
cliTest(
|
|
"redacts fixed parser text but keeps JSON keys and codes",
|
|
async ({ cli }) => {
|
|
const result = await cli.run({
|
|
arguments: [
|
|
...CAPTURE,
|
|
"har",
|
|
...["flag", "code", "UNKNOWN"].flatMap((literal) => [
|
|
"--sensitive-value",
|
|
literal,
|
|
]),
|
|
"--no-x",
|
|
"--json",
|
|
],
|
|
});
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
expect(JSON.parse(result.stdout)).toEqual({
|
|
code: "UNKNOWN",
|
|
message: "Unknown [REDACTED]: --no-x",
|
|
});
|
|
},
|
|
);
|
|
|
|
cliTest(
|
|
"excludes declarations from validation text while keeping field errors",
|
|
async ({ cli }) => {
|
|
const result = await cli.run({
|
|
arguments: [
|
|
...CAPTURE,
|
|
"bogus",
|
|
"--sensitive-value",
|
|
"mitmproxy",
|
|
"--json",
|
|
],
|
|
});
|
|
|
|
expectExcluded(result, ["mitmproxy"]);
|
|
expect(JSON.parse(result.stdout)).toMatchObject({
|
|
code: "VALIDATION_ERROR",
|
|
message: expect.stringMatching(/arguments.*expected type/iu),
|
|
fieldErrors: [
|
|
expect.objectContaining({ code: "invalid_value", path: "format" }),
|
|
],
|
|
});
|
|
},
|
|
);
|
|
|
|
cliTest(
|
|
"retains undeclared tokens and declared values that the parser accepts",
|
|
async ({ cli }) => {
|
|
const undeclared = await cli.run({
|
|
arguments: [...CAPTURE, "har", `--no-${LITERAL}`, "--json"],
|
|
});
|
|
expect(undeclared.exitCode).toBe(1);
|
|
expect(JSON.parse(undeclared.stdout)).toEqual({
|
|
code: "UNKNOWN",
|
|
message: `Unknown flag: --no-${LITERAL}`,
|
|
});
|
|
|
|
// An accepted output value is honored, so the service failure is JSON.
|
|
const accepted = await cli.run({
|
|
arguments: [
|
|
...CAPTURE,
|
|
"har",
|
|
"--sensitive-value",
|
|
"json",
|
|
"--format",
|
|
"json",
|
|
],
|
|
});
|
|
expect(accepted.exitCode).toBe(1);
|
|
expect(JSON.parse(accepted.stdout)).toMatchObject({
|
|
code: "invalid_request",
|
|
});
|
|
},
|
|
);
|
|
});
|
|
|
|
describe("CLI --sensitive-value output-value diagnostics", () => {
|
|
cliTest.for([
|
|
{
|
|
name: "a spaced --format value",
|
|
arguments: [...DECLARED, "--format", LITERAL],
|
|
message: 'Invalid format: "[REDACTED]"',
|
|
},
|
|
{
|
|
name: "an equals-form --format value",
|
|
arguments: [...DECLARED, `--format=${LITERAL}`],
|
|
message: 'Invalid format: "[REDACTED]"',
|
|
},
|
|
{
|
|
name: "a --token-limit value",
|
|
arguments: [...DECLARED, "--token-limit", LITERAL],
|
|
message: 'Invalid value for --token-limit: "[REDACTED]"',
|
|
},
|
|
{
|
|
name: "a partially declared --token-offset value",
|
|
arguments: [...DECLARED, "--token-offset", `1${LITERAL}`],
|
|
message: 'Invalid value for --token-offset: "1[REDACTED]"',
|
|
},
|
|
])(
|
|
"keeps rejecting $name without the declaration",
|
|
async ({ arguments: arguments_, message }, { cli }) => {
|
|
const result = await cli.run({ arguments: arguments_ });
|
|
|
|
expectExcluded(result);
|
|
expect(JSON.parse(result.stdout)).toMatchObject({
|
|
ok: false,
|
|
error: {
|
|
code: "INVALID_OUTPUT_VALUE",
|
|
message: expect.stringContaining(message),
|
|
},
|
|
});
|
|
},
|
|
);
|
|
|
|
cliTest(
|
|
"rejects an output value that would be accepted once declarations are removed",
|
|
async ({ cli }) => {
|
|
const declared = ["X", "[REDACTED]", "…"];
|
|
const result = await cli.run({
|
|
arguments: [
|
|
...CAPTURE,
|
|
"har",
|
|
...declared.flatMap((literal) => ["--sensitive-value", literal]),
|
|
"--token-limit",
|
|
"12X",
|
|
],
|
|
});
|
|
|
|
expectExcluded(result, declared);
|
|
expect(result.stdout).toContain("Invalid value for --token-limit:");
|
|
},
|
|
);
|
|
|
|
cliTest.for([
|
|
{
|
|
name: "flag-name and value",
|
|
declared: ["token"],
|
|
arguments: ["--token-limit", "token"],
|
|
message: 'Invalid value for --[REDACTED]-limit: "[REDACTED]"',
|
|
},
|
|
{
|
|
name: "overlapping",
|
|
declared: ["tok", "token"],
|
|
arguments: ["--token-offset", "token1"],
|
|
message: 'Invalid value for --[REDACTED]-offset: "[REDACTED]1"',
|
|
},
|
|
{
|
|
name: "fixed-text",
|
|
declared: ["Invalid", "Expected"],
|
|
arguments: ["--format", "bogus"],
|
|
message:
|
|
'[REDACTED] format: "bogus". [REDACTED] one of: toon, json, yaml, md, jsonl',
|
|
},
|
|
{
|
|
// Codes and keys identify the contract, not caller text.
|
|
name: "code and key",
|
|
declared: ["UNKNOWN", "code", "message"],
|
|
arguments: ["--format", "bogus"],
|
|
message:
|
|
'Invalid format: "bogus". Expected one of: toon, json, yaml, md, jsonl',
|
|
},
|
|
])(
|
|
"redacts the whole rejected output message for $name declarations",
|
|
async ({ declared, arguments: arguments_, message }, { cli }) => {
|
|
const result = await cli.run({
|
|
arguments: [
|
|
...CAPTURE,
|
|
"har",
|
|
...declared.flatMap((literal) => ["--sensitive-value", literal]),
|
|
...arguments_,
|
|
],
|
|
});
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
expect(JSON.parse(result.stdout)).toMatchObject({
|
|
ok: false,
|
|
error: {
|
|
code: "INVALID_OUTPUT_VALUE",
|
|
message: expect.stringContaining(message),
|
|
},
|
|
});
|
|
},
|
|
);
|
|
|
|
cliTest.for([
|
|
["--format", "bogus"],
|
|
["--token-limit=x"],
|
|
["--token-offset", " "],
|
|
])(
|
|
"renders the same structured %s rejection with an unrelated declaration",
|
|
async (arguments_, { cli }) => {
|
|
const command = [...CAPTURE, "har", ...arguments_];
|
|
const incur = await cli.run({ arguments: command });
|
|
const declared = await cli.run({
|
|
arguments: [...command, "--sensitive-value", "unused"],
|
|
});
|
|
|
|
expect(incur.exitCode).toBe(1);
|
|
expect(declared).toMatchObject({
|
|
exitCode: incur.exitCode,
|
|
stdout: incur.stdout,
|
|
stderr: incur.stderr,
|
|
});
|
|
},
|
|
);
|
|
});
|