Skip to content

Commit 976161e

Browse files
IWhatsskillsteipete
authored andcommitted
fix(update): return failure when dirty checkout blocks update
1 parent b7f0df0 commit 976161e

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

‎src/cli/update-cli.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6140,7 +6140,7 @@ describe("update-cli", () => {
61406140
"Commit, stash, or discard the local changes, then rerun `openclaw update`.",
61416141
);
61426142
expect(serviceStop).not.toHaveBeenCalled();
6143-
expect(defaultRuntime.exit).toHaveBeenCalledWith(0);
6143+
expect(defaultRuntime.exit).toHaveBeenCalledWith(1);
61446144
});
61456145
it.each([
61466146
{

‎src/cli/update-cli/update-command-post-update.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,45 @@ async function finishFailedUpdate(result: UpdateRunResult): Promise<void> {
4444
} as unknown as FinishUpdateParams);
4545
}
4646

47+
async function finishSkippedUpdate(reason: string): Promise<void> {
48+
await finishUpdate({
49+
result: {
50+
status: "skipped",
51+
mode: reason === "dirty" ? "git" : "unknown",
52+
reason,
53+
steps: [],
54+
durationMs: 1,
55+
},
56+
opts: {},
57+
showProgress: false,
58+
controlPlaneUpdateSentinelMeta: undefined,
59+
} as unknown as FinishUpdateParams);
60+
}
61+
62+
describe("skipped update exit status", () => {
63+
beforeEach(() => {
64+
vi.clearAllMocks();
65+
vi.spyOn(defaultRuntime, "exit").mockImplementation(() => undefined as never);
66+
vi.spyOn(defaultRuntime, "error").mockImplementation(() => undefined);
67+
vi.spyOn(defaultRuntime, "log").mockImplementation(() => undefined);
68+
});
69+
70+
it("exits nonzero when local changes block a Git update", async () => {
71+
await finishSkippedUpdate("dirty");
72+
73+
expect(defaultRuntime.error).toHaveBeenCalledWith(
74+
expect.stringContaining("Update blocked: local files are edited"),
75+
);
76+
expect(defaultRuntime.exit).toHaveBeenCalledWith(1);
77+
});
78+
79+
it("keeps a non-Git install skip successful", async () => {
80+
await finishSkippedUpdate("not-git-install");
81+
82+
expect(defaultRuntime.exit).toHaveBeenCalledWith(0);
83+
});
84+
});
85+
4786
describe("failed Git update recovery restart", () => {
4887
beforeEach(() => {
4988
vi.clearAllMocks();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export async function finishUpdate(params: {
169169
),
170170
);
171171
}
172-
defaultRuntime.exit(0);
172+
defaultRuntime.exit(params.result.reason === "dirty" ? 1 : 0);
173173
return;
174174
}
175175

0 commit comments

Comments
 (0)