fix(scripts): reject short flag values in release docs parsers

This commit is contained in:
Vincent Koc
2026-06-21 21:39:32 +02:00
parent 9adf3d92bd
commit 82f43f0a62
6 changed files with 36 additions and 9 deletions

View File

@@ -30,12 +30,19 @@ function runNode(args: string[], env: NodeJS.ProcessEnv = {}) {
const e = error as { stdout?: unknown; stderr?: unknown };
return {
ok: false,
stdout: Buffer.isBuffer(e.stdout) ? e.stdout.toString("utf8") : String(e.stdout ?? ""),
stderr: Buffer.isBuffer(e.stderr) ? e.stderr.toString("utf8") : String(e.stderr ?? ""),
stdout: formatProcessOutput(e.stdout),
stderr: formatProcessOutput(e.stderr),
};
}
}
function formatProcessOutput(value: unknown): string {
if (Buffer.isBuffer(value)) {
return value.toString("utf8");
}
return typeof value === "string" ? value : "";
}
function runGit(args: string[], cwd?: string, env: NodeJS.ProcessEnv = {}) {
execFileSync("git", args, {
cwd,
@@ -127,11 +134,17 @@ describe("scripts/android-release-signing.mjs", () => {
it.each([
["--mode"],
["--mode", "--manifest"],
["--mode", "-h"],
["--manifest"],
["--manifest", "-h"],
["--workspace", "--mode"],
["--workspace", "-h"],
["--materialized-dir", "--mode"],
["--materialized-dir", "-h"],
["--keystore", "--mode"],
["--keystore", "-h"],
["--properties", "--mode"],
["--properties", "-h"],
])("rejects missing values for %s before release signing work", (...args) => {
const result = runNode(args);

View File

@@ -20,11 +20,13 @@ describe("scripts/check-docs-mdx", () => {
expect(() => parseArgs(["--max-errors", "0"])).toThrow(
"--max-errors must be a positive integer",
);
expect(() => parseArgs(["--max-errors"])).toThrow("--max-errors must be a positive integer");
expect(() => parseArgs(["--max-errors"])).toThrow("--max-errors requires a value");
expect(() => parseArgs(["--max-errors", "-h"])).toThrow("--max-errors requires a value");
});
it("rejects missing JSON report output paths", () => {
expect(() => parseArgs(["--json-out"])).toThrow("--json-out requires a value");
expect(() => parseArgs(["--json-out", "-h"])).toThrow("--json-out requires a value");
expect(() => parseArgs(["--json-out", "--max-errors", "3"])).toThrow(
"--json-out requires a value",
);

View File

@@ -16,12 +16,19 @@ function runSigningResult(args: string[]): { ok: boolean; stdout: string; stderr
const e = error as { stdout?: unknown; stderr?: unknown };
return {
ok: false,
stdout: Buffer.isBuffer(e.stdout) ? e.stdout.toString("utf8") : String(e.stdout ?? ""),
stderr: Buffer.isBuffer(e.stderr) ? e.stderr.toString("utf8") : String(e.stderr ?? ""),
stdout: formatProcessOutput(e.stdout),
stderr: formatProcessOutput(e.stderr),
};
}
}
function formatProcessOutput(value: unknown): string {
if (Buffer.isBuffer(value)) {
return value.toString("utf8");
}
return typeof value === "string" ? value : "";
}
function runSigning(mode: string): string {
return execFileSync(process.execPath, [SCRIPT, "--mode", mode], {
encoding: "utf8",
@@ -33,7 +40,9 @@ describe("scripts/ios-release-signing.mjs", () => {
it.each([
["--mode"],
["--mode", "--manifest"],
["--mode", "-h"],
["--manifest"],
["--manifest", "-h"],
])("rejects missing values for %s before reading signing manifests", (...args) => {
const result = runSigningResult(args);