From 63ac2e2ce09e778756a89f55e2dfc0d07031d047 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sat, 20 Jun 2026 21:36:01 +0200 Subject: [PATCH] fix(mac): reject build-and-run wrapper args --- scripts/build-and-run-mac.sh | 22 +++++++++++++++++++++- test/scripts/build-and-run-mac.test.ts | 24 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/scripts/build-and-run-mac.sh b/scripts/build-and-run-mac.sh index bf988f0dc18b..45ee622ed221 100755 --- a/scripts/build-and-run-mac.sh +++ b/scripts/build-and-run-mac.sh @@ -1,6 +1,26 @@ #!/usr/bin/env bash set -euo pipefail -cd "$(dirname "$0")/../apps/macos" + +ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)" +APP_DIR="$ROOT_DIR/apps/macos" + +usage() { + printf 'Usage: %s\n' "$(basename "$0")" + printf 'Build, stop, and relaunch the local debug OpenClaw macOS app.\n' +} + +for arg in "$@"; do + case "$arg" in + --help|-h) + usage + exit 0 + ;; + --) ;; + *) printf 'ERROR: Unknown build-and-run-mac option: %s\n' "$arg" >&2; exit 1 ;; + esac +done + +cd "$APP_DIR" BUILD_PATH=".build-local" PRODUCT="OpenClaw" diff --git a/test/scripts/build-and-run-mac.test.ts b/test/scripts/build-and-run-mac.test.ts index 40f64a40b344..e34d8ff44f37 100644 --- a/test/scripts/build-and-run-mac.test.ts +++ b/test/scripts/build-and-run-mac.test.ts @@ -108,9 +108,33 @@ afterEach(() => { }); describe("scripts/build-and-run-mac.sh", () => { + it("prints help before build or launch side effects", () => { + const result = spawnSync("bash", [scriptPath, "--help"], { + cwd: process.cwd(), + encoding: "utf8", + }); + + expect(result.status).toBe(0); + expect(result.stdout).toContain("Usage: build-and-run-mac.sh"); + expect(result.stdout).toContain("Build, stop, and relaunch"); + expect(result.stderr).toBe(""); + }); + + it("rejects unknown options before build or launch side effects", () => { + 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 build-and-run-mac option: --wat"); + }); + it("keeps launch logs isolated unless an explicit log path is provided", () => { const script = readFileSync(scriptPath, "utf8"); + expect(script).toContain('cd "$APP_DIR"'); expect(script).toContain( 'LOG_PATH="${OPENCLAW_MAC_RUN_LOG:-$(mktemp "${TMPDIR:-/tmp}/openclaw-${PRODUCT}.XXXXXX.log")}"', );