fix(docs): require sync provenance values

This commit is contained in:
Vincent Koc
2026-06-06 22:43:04 +02:00
parent bdc317f4a6
commit 8ff0a20744
2 changed files with 61 additions and 7 deletions

View File

@@ -170,7 +170,15 @@ const GENERATED_LOCALES = [
},
];
function parseArgs(argv) {
function readOptionValue(argv, index, optionName) {
const value = argv[index + 1];
if (value === undefined || value === "" || value.startsWith("--")) {
throw new Error(`${optionName} requires a value`);
}
return value;
}
export function parseArgs(argv) {
const args = {
target: "",
sourceRepo: "",
@@ -185,27 +193,27 @@ function parseArgs(argv) {
const part = argv[index];
switch (part) {
case "--target":
args.target = argv[index + 1] ?? "";
args.target = readOptionValue(argv, index, part);
index += 1;
break;
case "--source-repo":
args.sourceRepo = argv[index + 1] ?? "";
args.sourceRepo = readOptionValue(argv, index, part);
index += 1;
break;
case "--source-sha":
args.sourceSha = argv[index + 1] ?? "";
args.sourceSha = readOptionValue(argv, index, part);
index += 1;
break;
case "--clawhub-repo":
args.clawhubRepo = argv[index + 1] ?? "";
args.clawhubRepo = readOptionValue(argv, index, part);
index += 1;
break;
case "--clawhub-source-repo":
args.clawhubSourceRepo = argv[index + 1] ?? "";
args.clawhubSourceRepo = readOptionValue(argv, index, part);
index += 1;
break;
case "--clawhub-source-sha":
args.clawhubSourceSha = argv[index + 1] ?? "";
args.clawhubSourceSha = readOptionValue(argv, index, part);
index += 1;
break;
default:

View File

@@ -0,0 +1,46 @@
import { describe, expect, it } from "vitest";
import { parseArgs } from "../../scripts/docs-sync-publish.mjs";
describe("docs-sync-publish", () => {
it("parses docs sync provenance args", () => {
expect(
parseArgs([
"--target",
"generated-docs",
"--source-repo",
"openclaw/openclaw",
"--source-sha",
"abc123",
"--clawhub-repo",
"../clawhub",
"--clawhub-source-repo",
"openclaw/clawhub",
"--clawhub-source-sha",
"def456",
]),
).toMatchObject({
clawhubRepo: "../clawhub",
clawhubSourceRepo: "openclaw/clawhub",
clawhubSourceSha: "def456",
sourceRepo: "openclaw/openclaw",
sourceSha: "abc123",
target: "generated-docs",
});
});
it("rejects missing docs sync option values", () => {
for (const flag of [
"--target",
"--source-repo",
"--source-sha",
"--clawhub-repo",
"--clawhub-source-repo",
"--clawhub-source-sha",
]) {
expect(() => parseArgs([flag])).toThrow(`${flag} requires a value`);
expect(() => parseArgs([flag, "--target", "generated-docs"])).toThrow(
`${flag} requires a value`,
);
}
});
});