From 8ff0a20744728b9bf6dff2fa10578250eb3fc408 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sat, 6 Jun 2026 22:43:04 +0200 Subject: [PATCH] fix(docs): require sync provenance values --- scripts/docs-sync-publish.mjs | 22 ++++++++---- test/scripts/docs-sync-publish.test.ts | 46 ++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 test/scripts/docs-sync-publish.test.ts diff --git a/scripts/docs-sync-publish.mjs b/scripts/docs-sync-publish.mjs index e605c34c96c..070264927bf 100644 --- a/scripts/docs-sync-publish.mjs +++ b/scripts/docs-sync-publish.mjs @@ -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: diff --git a/test/scripts/docs-sync-publish.test.ts b/test/scripts/docs-sync-publish.test.ts new file mode 100644 index 00000000000..886f5c98b51 --- /dev/null +++ b/test/scripts/docs-sync-publish.test.ts @@ -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`, + ); + } + }); +});