diff --git a/scripts/notarize-mac-artifact.sh b/scripts/notarize-mac-artifact.sh index abaae84e627..bc19d221640 100755 --- a/scripts/notarize-mac-artifact.sh +++ b/scripts/notarize-mac-artifact.sh @@ -12,11 +12,42 @@ set -euo pipefail # NOTARYTOOL_KEY_ID API key ID # NOTARYTOOL_ISSUER API issuer ID -ARTIFACT="${1:-}" +ARTIFACT="" STAPLE_APP_PATH="${STAPLE_APP_PATH:-}" +usage() { + cat <<'HELP' +Usage: scripts/notarize-mac-artifact.sh + +Env: + STAPLE_APP_PATH=dist/OpenClaw.app + NOTARYTOOL_PROFILE= + NOTARYTOOL_KEY= + NOTARYTOOL_KEY_ID= + NOTARYTOOL_ISSUER= +HELP +} + +if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then + usage + exit 0 +fi +if [[ "${1:-}" == "--" ]]; then + shift +fi +if [[ "$#" -gt 0 ]]; then + case "$1" in + -*) echo "Error: unknown notarization option: $1" >&2; exit 1 ;; + *) ARTIFACT="$1"; shift ;; + esac +fi +if [[ "$#" -gt 0 ]]; then + echo "Error: unexpected notarization argument: $1" >&2 + exit 1 +fi + if [[ -z "$ARTIFACT" ]]; then - echo "Usage: $0 " >&2 + usage >&2 exit 1 fi if [[ ! -e "$ARTIFACT" ]]; then diff --git a/test/scripts/notarize-mac-artifact.test.ts b/test/scripts/notarize-mac-artifact.test.ts index ffb0a039e96..b7c0e4815e4 100644 --- a/test/scripts/notarize-mac-artifact.test.ts +++ b/test/scripts/notarize-mac-artifact.test.ts @@ -21,6 +21,44 @@ afterEach(() => { }); describe("notarize-mac-artifact input validation", () => { + it("prints help without checking artifact or notary tools", () => { + const result = spawnSync("bash", [scriptPath, "--help"], { + cwd: process.cwd(), + encoding: "utf8", + }); + + expect(result.status).toBe(0); + expect(result.stdout).toContain("Usage: scripts/notarize-mac-artifact.sh "); + expect(result.stdout).toContain("NOTARYTOOL_PROFILE"); + expect(result.stderr).toBe(""); + }); + + it("rejects unknown options before artifact validation", () => { + const result = spawnSync("bash", [scriptPath, "--wat"], { + cwd: process.cwd(), + encoding: "utf8", + }); + + expect(result.status).toBe(1); + expect(result.stdout).toBe(""); + expect(result.stderr.trim()).toBe("Error: unknown notarization option: --wat"); + }); + + it("rejects extra artifact arguments before notarization", () => { + const tempRoot = makeTempDir("openclaw-notary-extra-"); + const artifact = path.join(tempRoot, "OpenClaw.zip"); + writeFileSync(artifact, "placeholder", "utf8"); + + const result = spawnSync("bash", [scriptPath, artifact, "extra"], { + cwd: process.cwd(), + encoding: "utf8", + }); + + expect(result.status).toBe(1); + expect(result.stdout).toBe(""); + expect(result.stderr.trim()).toBe("Error: unexpected notarization argument: extra"); + }); + it("fails before notarization when an explicit staple app path is missing", () => { const tempRoot = makeTempDir("openclaw-notary-staple-"); const artifact = path.join(tempRoot, "OpenClaw.zip");