2026-10-20 17:25:19 +08:00
|
|
|
import { describe, expect } from "vitest";
|
2026-10-16 03:13:06 +08:00
|
|
|
|
2026-10-20 17:25:19 +08:00
|
|
|
import { cliTest, type CliResult } from "../../support/cli/cliFixture.js";
|
2026-10-16 03:13:06 +08:00
|
|
|
|
|
|
|
|
const SESSION_ID = "27d3e3f1-f1e5-49ae-91ec-95af1f343a5a";
|
|
|
|
|
const NON_INTEGER_TEXT = [
|
|
|
|
|
"",
|
|
|
|
|
" ",
|
|
|
|
|
"\t",
|
|
|
|
|
"1\n",
|
|
|
|
|
"0x1",
|
|
|
|
|
"0b1",
|
|
|
|
|
"1e0",
|
|
|
|
|
"+1",
|
|
|
|
|
"1.0",
|
|
|
|
|
"9007199254740992",
|
|
|
|
|
];
|
|
|
|
|
const NON_INTEGER_OPTION_TEXT = [...NON_INTEGER_TEXT, "-0"];
|
|
|
|
|
|
2026-10-20 17:25:19 +08:00
|
|
|
const expectCliValidationError = (result: CliResult, field: string): void => {
|
2026-10-16 03:13:06 +08:00
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(JSON.parse(result.stdout)).toMatchObject({
|
|
|
|
|
code: "VALIDATION_ERROR",
|
|
|
|
|
fieldErrors: expect.arrayContaining([
|
|
|
|
|
expect.objectContaining({ path: expect.stringContaining(field) }),
|
|
|
|
|
]),
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
describe("CLI integer arguments", () => {
|
2026-10-20 17:25:19 +08:00
|
|
|
cliTest.for(NON_INTEGER_TEXT)(
|
2026-10-16 03:13:06 +08:00
|
|
|
"rejects %j as a Cutter expected generation",
|
2026-10-20 17:25:19 +08:00
|
|
|
async (value, { cli }) => {
|
|
|
|
|
const result = await cli.run({
|
|
|
|
|
arguments: ["cutter-command", SESSION_ID, value, "pdi", "--json"],
|
|
|
|
|
});
|
2026-10-16 03:13:06 +08:00
|
|
|
|
|
|
|
|
expectCliValidationError(result, "expectedGeneration");
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
2026-10-20 17:25:19 +08:00
|
|
|
cliTest.for(NON_INTEGER_TEXT)(
|
2026-10-16 03:13:06 +08:00
|
|
|
"rejects %j as a web module script index",
|
2026-10-20 17:25:19 +08:00
|
|
|
async (value, { cli }) => {
|
|
|
|
|
const result = await cli.run({
|
|
|
|
|
arguments: [
|
|
|
|
|
"trace-web-module-imports",
|
|
|
|
|
"/nonexistent/manifest.json",
|
|
|
|
|
value,
|
|
|
|
|
"--json",
|
|
|
|
|
],
|
|
|
|
|
});
|
2026-10-16 03:13:06 +08:00
|
|
|
|
|
|
|
|
expectCliValidationError(result, "scriptIndex");
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
2026-10-20 17:25:19 +08:00
|
|
|
cliTest.for(NON_INTEGER_OPTION_TEXT)(
|
2026-10-16 03:13:06 +08:00
|
|
|
"rejects %j in a repeated web capture record selector",
|
2026-10-20 17:25:19 +08:00
|
|
|
async (value, { cli }) => {
|
|
|
|
|
const result = await cli.run({
|
|
|
|
|
arguments: [
|
|
|
|
|
"inspect-web-network-capture",
|
|
|
|
|
"/nonexistent/capture.qlog",
|
|
|
|
|
"qlog",
|
|
|
|
|
"--record",
|
|
|
|
|
"0",
|
|
|
|
|
"--record",
|
|
|
|
|
value,
|
|
|
|
|
"--json",
|
|
|
|
|
],
|
|
|
|
|
});
|
2026-10-16 03:13:06 +08:00
|
|
|
|
|
|
|
|
expectCliValidationError(result, "record");
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
2026-10-20 17:25:19 +08:00
|
|
|
cliTest(
|
|
|
|
|
"keeps the one-based source line lower bound at the CLI boundary",
|
|
|
|
|
async ({ cli }) => {
|
|
|
|
|
const result = await cli.run({
|
|
|
|
|
arguments: [
|
|
|
|
|
"trace-web-source-location",
|
|
|
|
|
"/nonexistent/manifest.json",
|
|
|
|
|
"0",
|
|
|
|
|
"/nonexistent/app.js.map",
|
|
|
|
|
"https://example.test/app.js.map",
|
|
|
|
|
"0",
|
|
|
|
|
"0",
|
|
|
|
|
"--json",
|
|
|
|
|
],
|
|
|
|
|
});
|
2026-10-16 03:13:06 +08:00
|
|
|
|
2026-10-20 17:25:19 +08:00
|
|
|
expectCliValidationError(result, "line");
|
|
|
|
|
},
|
|
|
|
|
);
|
2026-10-16 03:13:06 +08:00
|
|
|
});
|