Skip to content

Commit 400b3e0

Browse files
committed
fix: stop unknown-root git services
1 parent 535b1f5 commit 400b3e0

2 files changed

Lines changed: 36 additions & 7 deletions

File tree

src/cli/update-cli.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2877,6 +2877,34 @@ describe("update-cli", () => {
28772877
expect(updateCall?.beforeGitMutation).toEqual(expect.any(Function));
28782878
});
28792879

2880+
it("stops a running managed git gateway when wrapper commands hide the service root", async () => {
2881+
const wrapperPath = path.join(
2882+
createCaseDir("openclaw-update-wrapper-service"),
2883+
"gateway-wrapper",
2884+
);
2885+
serviceReadCommand.mockResolvedValue({
2886+
programArguments: [wrapperPath, "gateway", "run"],
2887+
environment: {
2888+
OPENCLAW_SERVICE_MARKER: "openclaw",
2889+
OPENCLAW_SERVICE_KIND: "gateway",
2890+
},
2891+
});
2892+
serviceLoaded.mockResolvedValue(true);
2893+
serviceReadRuntime.mockResolvedValue({
2894+
status: "running",
2895+
pid: 4242,
2896+
state: "running",
2897+
});
2898+
mockGitUpdateAfterMutation();
2899+
2900+
await updateCommand({ yes: true });
2901+
2902+
expect(serviceStop).toHaveBeenCalledTimes(1);
2903+
expect(runGatewayUpdate).toHaveBeenCalledTimes(1);
2904+
expect(prepareRestartScript).toHaveBeenCalled();
2905+
expect(runDaemonRestart).not.toHaveBeenCalled();
2906+
});
2907+
28802908
it("fails managed git restart when the gateway responds but the service stays stopped", async () => {
28812909
const serviceEntrypoint = path.join(process.cwd(), "dist", "index.js");
28822910
serviceReadCommand.mockResolvedValue({

src/cli/update-cli/update-command.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,8 @@ async function maybeStopManagedServiceBeforeMutableUpdate(params: {
926926

927927
if (
928928
params.updateInstallKind === "git" &&
929-
!(await gatewayServiceCommandUsesRoot({ root: params.root, command: serviceState.command }))
929+
(await gatewayServiceCommandUsesRoot({ root: params.root, command: serviceState.command })) ===
930+
false
930931
) {
931932
if (!params.jsonMode) {
932933
defaultRuntime.log(
@@ -1459,10 +1460,10 @@ async function gatewayServiceCommandUsesRoot(params: {
14591460
root: string | undefined;
14601461
env?: NodeJS.ProcessEnv;
14611462
command?: GatewayServiceCommandConfig | null;
1462-
}): Promise<boolean> {
1463+
}): Promise<boolean | null> {
14631464
const expectedRoot = normalizeOptionalString(params.root);
14641465
if (!expectedRoot) {
1465-
return false;
1466+
return null;
14661467
}
14671468
const command =
14681469
params.command === undefined
@@ -1473,7 +1474,7 @@ async function gatewayServiceCommandUsesRoot(params: {
14731474
const layout = await summarizeGatewayServiceLayout(command);
14741475
const serviceRoot = layout?.packageRoot;
14751476
if (!serviceRoot) {
1476-
return false;
1477+
return null;
14771478
}
14781479
const [expectedRootReal, serviceRootReal] = await Promise.all([
14791480
tryRealpathOrResolve(expectedRoot),
@@ -2242,10 +2243,10 @@ async function maybeRestartService(params: {
22422243
});
22432244
if (
22442245
updatedInstallRestartNeedsServiceRootProof &&
2245-
!(await gatewayServiceCommandUsesRoot({
2246+
(await gatewayServiceCommandUsesRoot({
22462247
root: params.result.root,
22472248
env: params.serviceEnv,
2248-
}))
2249+
})) !== true
22492250
) {
22502251
if (!params.opts.json) {
22512252
defaultRuntime.log(
@@ -3820,7 +3821,7 @@ async function updateCommandInternal(opts: UpdateCommandOptions): Promise<void>
38203821
serviceState.installed &&
38213822
serviceState.loaded &&
38223823
preManagedServiceStop?.stopped !== true &&
3823-
serviceMatchesUpdateRoot !== true;
3824+
serviceMatchesUpdateRoot === false;
38243825
if (
38253826
shouldPrepareUpdatedInstallRestart({
38263827
updateMode: resultWithPostUpdate.mode,

0 commit comments

Comments
 (0)