

















@@ -163,6 +163,36 @@ function runRestartArgParser(...args: string[]) {
163163return spawnSync("bash", [harnessPath, ...args], { encoding: "utf8" });
164164}
165165166+function runRestartLockHarness(lockDir: string) {
167+const root = mkdtempSync(join(tmpdir(), "openclaw-restart-mac-test-"));
168+tempRoots.push(root);
169+170+const script = readFileSync(restartScriptPath, "utf8");
171+const lockBlock = script.slice(
172+script.indexOf("cleanup()"),
173+script.indexOf("check_signing_keys()"),
174+);
175+const harnessPath = join(root, "lock-harness.sh");
176+writeFileSync(
177+harnessPath,
178+[
179+"#!/usr/bin/env bash",
180+"set -euo pipefail",
181+`LOCK_DIR=${shellQuote(lockDir)}`,
182+'LOCK_PID_FILE="${LOCK_DIR}/pid"',
183+"LOCK_HELD=0",
184+"WAIT_FOR_LOCK=0",
185+'log() { printf "%s\\n" "$*"; }',
186+lockBlock,
187+"trap cleanup EXIT",
188+"acquire_lock",
189+].join("\n"),
190+);
191+chmodSync(harnessPath, 0o755);
192+193+return spawnSync("bash", [harnessPath], { encoding: "utf8" });
194+}
195+166196afterEach(() => {
167197for (const root of tempRoots.splice(0)) {
168198rmSync(root, { force: true, recursive: true });
@@ -227,6 +257,35 @@ describe("scripts/restart-mac.sh", () => {
227257expect(script).not.toContain('LOG_PATH="${OPENCLAW_RESTART_LOG:-/tmp/openclaw-restart.log}"');
228258});
229259260+it("does not remove a live restart lock it did not acquire", () => {
261+const root = mkdtempSync(join(tmpdir(), "openclaw-restart-mac-test-"));
262+tempRoots.push(root);
263+const lockDir = join(root, "openclaw-restart-lock");
264+mkdirSync(lockDir);
265+writeFileSync(join(lockDir, "pid"), String(process.pid), "utf8");
266+267+const result = runRestartLockHarness(lockDir);
268+269+expect(result.status).toBe(0);
270+expect(result.stdout).toContain(`Another restart is running (pid ${process.pid}); re-run with --wait.`);
271+expect(result.stderr).toBe("");
272+expect(existsSync(lockDir)).toBe(true);
273+expect(readFileSync(join(lockDir, "pid"), "utf8")).toBe(String(process.pid));
274+});
275+276+it("removes the restart lock it acquired", () => {
277+const root = mkdtempSync(join(tmpdir(), "openclaw-restart-mac-test-"));
278+tempRoots.push(root);
279+const lockDir = join(root, "openclaw-restart-lock");
280+281+const result = runRestartLockHarness(lockDir);
282+283+expect(result.status).toBe(0);
284+expect(result.stdout).toBe("");
285+expect(result.stderr).toBe("");
286+expect(existsSync(lockDir)).toBe(false);
287+});
288+230289it("prefers the freshly packaged app unless an explicit app bundle is set", () => {
231290const script = readFileSync(restartScriptPath, "utf8");
232291const chooseBlock = script.slice(
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。