


























@@ -133,7 +133,7 @@ describe("restartGatewayProcessWithFreshPid", () => {
133133expect(spawnMock).not.toHaveBeenCalled();
134134});
135135136-it("spawns detached child with current exec argv", () => {
136+it("uses in-process restart on unmanaged Unix so custom supervisors keep the tracked PID", () => {
137137delete process.env.OPENCLAW_NO_RESPAWN;
138138clearSupervisorHints();
139139setPlatform("linux");
@@ -143,16 +143,11 @@ describe("restartGatewayProcessWithFreshPid", () => {
143143144144const result = restartGatewayProcessWithFreshPid();
145145146-expect(result).toEqual({ mode: "spawned", pid: 4242 });
147-expect(spawnMock).toHaveBeenCalledWith(
148-process.execPath,
149-["--import", "tsx", "/repo/dist/index.js", "gateway", "run"],
150-{
151-detached: true,
152-env: process.env,
153-stdio: "inherit",
154-},
155-);
146+expect(result).toEqual({
147+mode: "disabled",
148+detail: "unmanaged: use in-process restart to keep custom supervisor PID tracking stable",
149+});
150+expect(spawnMock).not.toHaveBeenCalled();
156151});
157152158153it("returns supervised when OPENCLAW_LAUNCHD_LABEL is set (stock launchd plist)", () => {
@@ -186,12 +181,15 @@ describe("restartGatewayProcessWithFreshPid", () => {
186181setPlatform("linux");
187182process.env.OPENCLAW_SERVICE_MARKER = "openclaw";
188183process.env.OPENCLAW_SERVICE_KIND = "gateway";
189-spawnMock.mockReturnValue({ pid: 4242, unref: vi.fn() });
190184191185const result = restartGatewayProcessWithFreshPid();
192186193-expect(result).toEqual({ mode: "spawned", pid: 4242 });
187+expect(result).toEqual({
188+mode: "disabled",
189+detail: "unmanaged: use in-process restart to keep custom supervisor PID tracking stable",
190+});
194191expect(triggerOpenClawRestartMock).not.toHaveBeenCalled();
192+expect(spawnMock).not.toHaveBeenCalled();
195193});
196194197195it("returns disabled on Windows without Scheduled Task markers", () => {
@@ -235,7 +233,7 @@ describe("restartGatewayProcessWithFreshPid", () => {
235233expect(spawnMock).not.toHaveBeenCalled();
236234});
237235238-it("returns failed when spawn throws", () => {
236+it("does not attempt detached spawn on unmanaged Unix even if spawn would throw", () => {
239237delete process.env.OPENCLAW_NO_RESPAWN;
240238clearSupervisorHints();
241239setPlatform("linux");
@@ -244,8 +242,11 @@ describe("restartGatewayProcessWithFreshPid", () => {
244242throw new Error("spawn failed");
245243});
246244const result = restartGatewayProcessWithFreshPid();
247-expect(result.mode).toBe("failed");
248-expect(result.detail).toContain("spawn failed");
245+expect(result).toEqual({
246+mode: "disabled",
247+detail: "unmanaged: use in-process restart to keep custom supervisor PID tracking stable",
248+});
249+expect(spawnMock).not.toHaveBeenCalled();
249250});
250251});
251252@@ -286,4 +287,19 @@ describe("respawnGatewayProcessForUpdate", () => {
286287},
287288);
288289});
290+291+it("returns failed when update detached respawn throws", () => {
292+delete process.env.OPENCLAW_NO_RESPAWN;
293+clearSupervisorHints();
294+setPlatform("linux");
295+296+spawnMock.mockImplementation(() => {
297+throw new Error("spawn failed");
298+});
299+300+const result = respawnGatewayProcessForUpdate();
301+302+expect(result.mode).toBe("failed");
303+expect(result.detail).toContain("spawn failed");
304+});
289305});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。