
























@@ -10,6 +10,8 @@ import { resolveConfigPath, resolveStateDir } from "../config/paths.js";
1010import { createSuiteTempRootTracker } from "../test-helpers/temp-dir.js";
1111import { acquireGatewayLock, GatewayLockError, type GatewayLockOptions } from "./gateway-lock.js";
121213+type GatewayLock = NonNullable<Awaited<ReturnType<typeof acquireGatewayLock>>>;
14+1315const fixtureRootTracker = createSuiteTempRootTracker({ prefix: "openclaw-gateway-lock-" });
1416let fixtureRoot = "";
1517const realNow = Date.now.bind(Date);
@@ -47,6 +49,14 @@ async function acquireForTest(
4749});
4850}
495152+function expectGatewayLock(lock: Awaited<ReturnType<typeof acquireGatewayLock>>): GatewayLock {
53+expect(lock).toEqual(expect.objectContaining({ release: expect.any(Function) }));
54+if (lock === null) {
55+throw new Error("Expected gateway lock");
56+}
57+return lock;
58+}
59+5060function resolveLockPath(env: NodeJS.ProcessEnv) {
5161const stateDir = resolveStateDir(env);
5262const configPath = resolveConfigPath(env, stateDir);
@@ -175,17 +185,17 @@ describe("gateway lock", () => {
175185vi.useRealTimers();
176186const env = await makeEnv();
177187const lock = await acquireForTest(env, { timeoutMs: 50 });
178-expect(lock).not.toBeNull();
188+const acquiredLock = expectGatewayLock(lock);
179189180190const pending = acquireForTest(env, {
181191timeoutMs: 15,
182192readProcessCmdline: () => ["openclaw", "gateway", "run"],
183193});
184194await expect(pending).rejects.toBeInstanceOf(GatewayLockError);
185195186-await lock?.release();
196+await acquiredLock.release();
187197const lock2 = await acquireForTest(env);
188-await lock2?.release();
198+await expectGatewayLock(lock2).release();
189199});
190200191201it("treats recycled linux pid as stale when start time mismatches", async () => {
@@ -204,9 +214,9 @@ describe("gateway lock", () => {
204214pollIntervalMs: 5,
205215platform: "linux",
206216});
207-expect(lock).not.toBeNull();
217+const acquiredLock = expectGatewayLock(lock);
208218209-await lock?.release();
219+await acquiredLock.release();
210220spy.mockRestore();
211221});
212222@@ -259,8 +269,7 @@ describe("gateway lock", () => {
259269platform: "darwin",
260270port: 18789,
261271});
262-expect(lock).not.toBeNull();
263-await lock?.release();
272+await expectGatewayLock(lock).release();
264273connectSpy.mockRestore();
265274});
266275@@ -329,8 +338,7 @@ describe("gateway lock", () => {
329338port: 18789,
330339readProcessCmdline: () => ["chrome.exe", "--no-sandbox"],
331340});
332-expect(lock).not.toBeNull();
333-await lock?.release();
341+await expectGatewayLock(lock).release();
334342335343connectSpy.mockRestore();
336344});
@@ -394,8 +402,7 @@ describe("gateway lock", () => {
394402port: 18789,
395403readProcessCmdline: () => ["/Applications/Safari.app/Contents/MacOS/Safari"],
396404});
397-expect(lock).not.toBeNull();
398-await lock?.release();
405+await expectGatewayLock(lock).release();
399406400407connectSpy.mockRestore();
401408});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。