Files
adolf/test/scripts/build-and-run-mac.test.ts
alvis bedb527145
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Vendor OpenClaw source as Adolf fork baseline
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11),
free to diverge. Tree copied sans upstream .git; upstream remote added for
future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19.
Preserves docs/ARCHITECTURE.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
2026-07-05 09:36:54 +00:00

185 lines
6.1 KiB
TypeScript
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Build And Run Mac tests cover build and run mac script behavior.
import { spawnSync } from "node:child_process";
import {
chmodSync,
existsSync,
mkdirSync,
mkdtempSync,
readFileSync,
rmSync,
writeFileSync,
} from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, describe, expect, it } from "vitest";
const scriptPath = "scripts/build-and-run-mac.sh";
const tempRoots: string[] = [];
function runStopExistingLocalApp(params: { fakeLsof?: string; fakePgrep: string }) {
const root = mkdtempSync(join(tmpdir(), "openclaw-build-run-mac-test-"));
tempRoots.push(root);
const binDir = join(root, "bin");
const killCallsPath = join(root, "kill-calls.txt");
const pgrepCallsPath = join(root, "pgrep-calls.txt");
mkdirSync(binDir);
for (const [name, body] of [
["pgrep", params.fakePgrep],
[
"lsof",
params.fakeLsof ??
[
"#!/usr/bin/env bash",
"pid=''",
"while [[ $# -gt 0 ]]; do",
' if [[ "$1" == "-p" ]]; then pid="$2"; shift 2; continue; fi',
" shift",
"done",
'printf "p%s\\n" "$pid"',
'printf "n/worktree/apps/macos\\n"',
"exit 0",
].join("\n"),
],
[
"sed",
[
"#!/usr/bin/env bash",
'if [[ "$1" == "-n" && "$2" == "s/^n//p" ]]; then',
" /usr/bin/sed -n 's/^n//p'",
"else",
' /usr/bin/sed "$@"',
"fi",
].join("\n"),
],
["head", ["#!/usr/bin/env bash", 'exec /usr/bin/head "$@"'].join("\n")],
["sleep", "#!/usr/bin/env bash\nexit 0\n"],
] as const) {
const toolPath = join(binDir, name);
writeFileSync(toolPath, body);
chmodSync(toolPath, 0o755);
}
const script = readFileSync(scriptPath, "utf8");
const stopFunction = script.slice(
script.indexOf("process_cwd_matches()"),
script.indexOf('printf "\\n▶ Building'),
);
const harnessPath = join(root, "stop-existing-local-app.sh");
writeFileSync(
harnessPath,
[
"#!/usr/bin/env bash",
"set -euo pipefail",
'BIN_ABS="/worktree/apps/macos/.build-local/debug/OpenClaw"',
'BIN=".build-local/debug/OpenClaw"',
'APP_CWD="/worktree/apps/macos"',
"kill() {",
' printf "%s\\n" "$*" >> "$OPENCLAW_TEST_KILL_CALLS"',
' touch "$OPENCLAW_TEST_KILLED_MARKER"',
" return 0",
"}",
stopFunction,
"stop_existing_local_app",
].join("\n"),
);
chmodSync(harnessPath, 0o755);
const result = spawnSync("bash", [harnessPath], {
encoding: "utf8",
env: {
...process.env,
OPENCLAW_TEST_KILLED_MARKER: join(root, "killed"),
OPENCLAW_TEST_KILL_CALLS: killCallsPath,
OPENCLAW_TEST_PGREP_CALLS: pgrepCallsPath,
OPENCLAW_TEST_PGREP_COUNT: join(root, "pgrep-count.txt"),
PATH: `${binDir}:${process.env.PATH ?? ""}`,
},
});
const killCalls = existsSync(killCallsPath) ? readFileSync(killCallsPath, "utf8") : "";
const pgrepCalls = existsSync(pgrepCallsPath) ? readFileSync(pgrepCallsPath, "utf8") : "";
return { killCalls, pgrepCalls, result };
}
afterEach(() => {
for (const root of tempRoots.splice(0)) {
rmSync(root, { force: true, recursive: true });
}
});
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")}"',
);
expect(script).toContain('nohup "$BIN_ABS" >"$LOG_PATH" 2>&1 &');
expect(script).toContain('printf "Started $PRODUCT (PID $PID). Logs: $LOG_PATH\\n"');
expect(script).not.toContain("/tmp/openclaw.log");
});
it("stops only the local debug app binary before relaunching", () => {
const script = readFileSync(scriptPath, "utf8");
const { killCalls, pgrepCalls, result } = runStopExistingLocalApp({
fakePgrep: [
"#!/usr/bin/env bash",
`printf '%s\\n' "$*" >> "$OPENCLAW_TEST_PGREP_CALLS"`,
'count="$(cat "$OPENCLAW_TEST_PGREP_COUNT" 2>/dev/null || echo 0)"',
'next="$((count + 1))"',
'printf "%s\\n" "$next" > "$OPENCLAW_TEST_PGREP_COUNT"',
'if [[ "$2" == "/worktree/apps/macos/.build-local/debug/OpenClaw" ]]; then exit 1; fi',
'if [[ "$2" == ".build-local/debug/OpenClaw" && "$count" == "1" ]]; then echo 321; exit 0; fi',
"exit 1",
].join("\n"),
});
expect(result.status).toBe(0);
expect(killCalls).toBe("321\n");
expect(pgrepCalls).toContain("-f /worktree/apps/macos/.build-local/debug/OpenClaw");
expect(pgrepCalls).toContain("-f .build-local/debug/OpenClaw");
expect(script).toContain('BIN_ABS="$(pwd)/$BIN"');
expect(script).toContain('pgrep -f "$BIN_ABS"');
expect(script).toContain('pgrep -f "$BIN"');
expect(script).toContain('kill "$pid"');
expect(script).not.toContain('killall -q "$PRODUCT"');
expect(script).not.toContain("pkill");
});
it("fails when the scoped local app process survives cleanup", () => {
const { result } = runStopExistingLocalApp({
fakePgrep: [
"#!/usr/bin/env bash",
'if [[ "$2" == ".build-local/debug/OpenClaw" ]]; then echo 321; exit 0; fi',
"exit 1",
].join("\n"),
});
expect(result.status).toBe(1);
});
});