Skip to content

Commit 135f082

Browse files
committed
fix(mac): read launchd port from service env
1 parent 4529711 commit 135f082

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

src/daemon/launchd.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,22 @@ describe("launchd install", () => {
691691
expect(output).toContain("Stopped LaunchAgent");
692692
});
693693

694+
it("resolves the stop postcondition port from the stored LaunchAgent environment", async () => {
695+
const env = createDefaultLaunchdEnv();
696+
await installLaunchAgent({
697+
env,
698+
stdout: new PassThrough(),
699+
programArguments: defaultProgramArguments,
700+
environment: { OPENCLAW_GATEWAY_PORT: "19006" },
701+
});
702+
state.launchctlCalls.length = 0;
703+
704+
await stopLaunchAgent({ env, stdout: new PassThrough() });
705+
706+
expect(cleanStaleGatewayProcessesSync).toHaveBeenCalledWith(19006);
707+
expect(inspectPortUsage).toHaveBeenCalledWith(19006);
708+
});
709+
694710
it("fails stop when the verified gateway port remains busy after cleanup", async () => {
695711
const env = {
696712
...createDefaultLaunchdEnv(),
@@ -961,6 +977,25 @@ describe("launchd install", () => {
961977
expect(cleanStaleGatewayProcessesSync).toHaveBeenCalledWith(19001);
962978
});
963979

980+
it("uses the stored LaunchAgent environment port for restart stale cleanup", async () => {
981+
const env = createDefaultLaunchdEnv();
982+
await installLaunchAgent({
983+
env,
984+
stdout: new PassThrough(),
985+
programArguments: defaultProgramArguments,
986+
environment: { OPENCLAW_GATEWAY_PORT: "19007" },
987+
});
988+
state.launchctlCalls.length = 0;
989+
990+
await restartLaunchAgent({
991+
env,
992+
stdout: new PassThrough(),
993+
});
994+
995+
expect(cleanStaleGatewayProcessesSync).toHaveBeenCalledWith(19007);
996+
expect(inspectPortUsage).toHaveBeenCalledWith(19007);
997+
});
998+
964999
it("fails restart before kickstart when the configured gateway port remains busy", async () => {
9651000
const env = {
9661001
...createDefaultLaunchdEnv(),

src/daemon/launchd.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@ async function resolveLaunchAgentGatewayPort(env: GatewayServiceEnv): Promise<nu
254254
if (fromArgs !== null) {
255255
return fromArgs;
256256
}
257+
const fromServiceEnv = parseStrictPositiveInteger(
258+
command?.environment?.OPENCLAW_GATEWAY_PORT ?? "",
259+
);
260+
if (fromServiceEnv !== undefined) {
261+
return fromServiceEnv;
262+
}
257263
const fromEnv = parseStrictPositiveInteger(env.OPENCLAW_GATEWAY_PORT ?? "");
258264
return fromEnv ?? null;
259265
}

0 commit comments

Comments
 (0)