Files
reverse-engineering-anything/tests/boundary/cli/argumentGuidance.test.ts
T
Wenyu Chiou 3142f7b0dd fix(adb): align CLI selector schemas with canonical inputs (#7722)
* fix(adb): align CLI selector schemas with canonical inputs

Reuse canonical selector constraints for ADB CLI admission and cover schema, parser, and inert provider boundaries. Independent source review approved tree bc722f8d1b1f8d014be29533e6845c6f897d5918; full contribution checks remain pending.

* test(adb): expect CLI serial validation refusal

Independent review approved staged diff 35418e6994339af838b490be51278fd41b9f8e3e. Focused serial refusal test, lint, and formatting passed with existing dependencies.

* test(adb): assert CLI selector validation stage

Independent review approved staged diff a1164a8dcf1df1f0d60323d7a53a69ee2bfdffeb. Focused dispatch tests, targeted lint and formatting passed using existing dependencies.

* fix(adb): retain safe selector validation constraints

Independent review: review_ci_delta APPROVE for diff 18748a3b4b112dc96b95f7c1099bd479e1d1587b. Focused tests, typecheck and targeted lint passed; the aggregate check remains limited by a matching baseline Knip finding.
2026-10-29 07:44:43 +08:00

93 lines
2.6 KiB
TypeScript

import { expect, it } from "vitest";
import { createCli } from "../../../src/cli.js";
import { MAX_SELECTED_LOCALES } from "../../../src/domain/apktool/apktoolResourceAnalysis.js";
import { serveCli } from "./cliServeHarness.js";
it.each([
["analyze"],
["decompile"],
["setup", "--no-client"],
["search", "/caller/selected", "needle", "--kind", "unrecognized"],
])(
"keeps correction fields and concise guidance for invalid CLI arguments: %j",
async (...argv) => {
const cli = createCli({});
let text = "";
let exit = 0;
await cli.serve([...argv, "--json"], {
stdout: (chunk) => {
text += chunk;
},
exit: (code) => {
exit = code;
},
env: {},
});
expect(exit).toBe(1);
const result = JSON.parse(text);
expect(result).toMatchObject({
code: "VALIDATION_ERROR",
message:
"REA could not read the command arguments. Check the named argument and its expected type, then try again.",
fieldErrors: expect.any(Array),
});
expect(text).not.toContain("Details:");
for (const field of result.fieldErrors) {
expect(field).not.toHaveProperty("maximum");
}
if (argv[0] === "search")
expect(result.fieldErrors).toEqual(
expect.arrayContaining([
expect.objectContaining({
path: "kind",
code: "invalid_value",
missing: false,
message: expect.stringContaining('"strings"|"procedures"'),
}),
]),
);
else if (argv[0] === "setup")
expect(result.fieldErrors).toEqual(
expect.arrayContaining([
expect.objectContaining({
path: "client",
missing: false,
expected: "array",
}),
]),
);
else
expect(result.fieldErrors).toEqual(
expect.arrayContaining([
expect.objectContaining({
path: "path",
missing: true,
expected: "string",
}),
]),
);
},
);
it("leaves non-ADB over-limit argument errors unchanged", async () => {
const result = await serveCli([
"decode-android-resources",
"/nonexistent/app.apk",
...Array.from({ length: MAX_SELECTED_LOCALES + 1 }, () => [
"--locales",
"de",
]).flat(),
"--json",
]);
expect(result.exitCode).toBe(1);
const output = JSON.parse(result.stdout);
expect(output).toMatchObject({
code: "VALIDATION_ERROR",
fieldErrors: [
expect.objectContaining({ path: "locales", code: "too_big" }),
],
});
expect(output.fieldErrors[0]).not.toHaveProperty("maximum");
});