Skip to content

Commit 03c1d77

Browse files
authored
fix(claws): keep update JSON output parseable (#124130)
1 parent 393b454 commit 03c1d77

4 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎src/claws/package-update.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createHash } from "node:crypto";
22
import { coerceErrorMessage, stableStringify } from "@openclaw/normalization-core";
33
import { preflightPluginInstall } from "../plugins/plugin-install-preflight.js";
4+
import type { RuntimeEnv } from "../runtime.js";
45
import type { OpenClawStateDatabaseOptions } from "../state/openclaw-state-db.js";
56
import {
67
digestClawPackageRef,
@@ -51,6 +52,7 @@ export async function applyClawPackageUpdate(
5152
readRefs?: typeof readClawPackageRefs;
5253
replaceExpected?: typeof replaceClawPackageRefExpected;
5354
packageDeps?: PackageInstallerDeps;
55+
runtime?: RuntimeEnv;
5456
nowMs?: number;
5557
},
5658
): Promise<ClawPackageUpdateExecution> {

‎src/claws/update-apply.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { listAgentEntries } from "../agents/agent-scope.js";
44
import { transformConfigFileWithRetry } from "../config/config.js";
55
import type { AgentConfig } from "../config/types.agents.js";
66
import type { OpenClawConfig } from "../config/types.openclaw.js";
7+
import type { RuntimeEnv } from "../runtime.js";
78
import type { OpenClawStateDatabaseOptions } from "../state/openclaw-state-db.js";
89
import { clawTargetPackages } from "./application-provenance.js";
910
import {
@@ -99,6 +100,7 @@ export async function applyClawUpdatePlan(
99100
sourceMcpServers: Record<string, Record<string, unknown>>;
100101
consentPlanIntegrity: string | undefined;
101102
packagePreflight?: ClawAddPlanContext["packagePreflight"];
103+
runtime?: RuntimeEnv;
102104
commitConfig?: ConfigCommit;
103105
rebuildPlan?: typeof buildClawUpdatePlan;
104106
buildAddPlan?: typeof buildClawAddPlan;

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,15 @@ describe("claws cli", () => {
945945

946946
it("applies a supported update only after explicit consent", async () => {
947947
const { root } = await cliTestHelpers.writePackageFixture(tempDirs);
948+
const applyUpdate = mocks.applyClawUpdatePlan.getMockImplementation();
949+
if (!applyUpdate) {
950+
throw new Error("missing update fixture implementation");
951+
}
952+
mocks.applyClawUpdatePlan.mockImplementationOnce(async (...args) => {
953+
const options = args[2] as { runtime?: typeof mocks.runtime };
954+
(options.runtime ?? mocks.runtime).log("Installed plugin: demo");
955+
return await applyUpdate(...args);
956+
});
948957

949958
await runCli([
950959
"claws",
@@ -977,6 +986,7 @@ describe("claws cli", () => {
977986
}),
978987
}),
979988
);
989+
expect(mocks.logs).toHaveLength(1);
980990
expect(JSON.parse(mocks.logs[0] ?? "{}")).toMatchObject({
981991
schemaVersion: "openclaw.clawUpdateResult.v1",
982992
status: "complete",

‎src/cli/claws-update-cli.runtime.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ export async function runClawsUpdateCommand(
210210
sourceMcpServers: listedMcpServers.mcpServers,
211211
consentPlanIntegrity: opts.planIntegrity,
212212
packagePreflight: preflightClawPackage,
213+
runtime: opts.json ? { ...runtime, log: () => undefined } : runtime,
213214
cronGateway: {
214215
add: async (input) => await callGatewayFromCli("cron.add", {}, input),
215216
get: async (id) => await callGatewayFromCli("cron.get", {}, { id }),

0 commit comments

Comments
 (0)