Skip to content

Commit 5748fa1

Browse files
committed
fix(cli): keep required status probes read-only
1 parent 1b237b1 commit 5748fa1

3 files changed

Lines changed: 77 additions & 1 deletion

File tree

‎src/cli/daemon-cli/probe.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ describe("probeGatewayStatus", () => {
322322
tlsFingerprint: "abc123",
323323
method: "status",
324324
timeoutMs: 5_000,
325+
sharedStateMode: "read-only",
325326
configPath: "/tmp/openclaw-daemon/openclaw.json",
326327
});
327328
});
@@ -368,6 +369,7 @@ describe("probeGatewayStatus", () => {
368369
config,
369370
method: "status",
370371
timeoutMs: 30_000,
372+
sharedStateMode: "read-only",
371373
});
372374
});
373375

@@ -413,6 +415,7 @@ describe("probeGatewayStatus", () => {
413415
tlsFingerprint: undefined,
414416
method: "status",
415417
timeoutMs: 5_000,
418+
sharedStateMode: "read-only",
416419
});
417420
});
418421

‎src/cli/daemon-cli/probe.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export async function probeGatewayStatus(opts: {
123123
...(allowRpcConfigCredentials && opts.config ? { config: opts.config } : {}),
124124
method: "status",
125125
timeoutMs: opts.timeoutMs,
126+
sharedStateMode: "read-only",
126127
...(opts.configPath ? { configPath: opts.configPath } : {}),
127128
});
128129
statusRuntimeVersion = readRuntimeVersionFromStatusPayload(statusPayload);

‎src/cli/gateway-backed-exit.process.test.ts‎

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ async function startGatewayStabilityRpcServer(
217217
ws,
218218
frame.id,
219219
buildMinimalGatewayHelloOkPayload({
220-
methods: ["diagnostics.stability"],
220+
methods: ["diagnostics.stability", "status"],
221221
auth: {
222222
role: "operator",
223223
scopes: ["operator.admin"],
@@ -233,6 +233,13 @@ async function startGatewayStabilityRpcServer(
233233
calls.push(frame.method);
234234
if (frame.method === "diagnostics.stability") {
235235
sendMinimalGatewayResponse(ws, frame.id, EMPTY_STABILITY_SNAPSHOT);
236+
return;
237+
}
238+
if (frame.method === "status") {
239+
sendMinimalGatewayResponse(ws, frame.id, {
240+
runtimeVersion: "2026.8.17-test",
241+
status: "ok",
242+
});
236243
}
237244
});
238245
});
@@ -615,6 +622,71 @@ describe("gateway-backed CLI process exit", () => {
615622
expect(await snapshotSharedStateArtifacts(stateDir)).toEqual(before);
616623
}, 30_000);
617624

625+
it.each([
626+
{ label: "absent", seeded: false },
627+
{ label: "seeded", seeded: true },
628+
])(
629+
"requires a reachable status RPC without changing $label shared state",
630+
async ({ label, seeded }) => {
631+
const root = tempDirs.make(`openclaw-gateway-status-${label}-`);
632+
const stateDir = path.join(root, "state");
633+
const configPath = path.join(stateDir, "openclaw.json");
634+
const token = "configured-token";
635+
const gateway = await startGatewayStabilityRpcServer(token, "issued-device-token");
636+
const stateEnv = {
637+
...process.env,
638+
HOME: root,
639+
OPENCLAW_HOME: root,
640+
OPENCLAW_STATE_DIR: stateDir,
641+
};
642+
await fs.mkdir(stateDir, { recursive: true });
643+
await fs.writeFile(
644+
configPath,
645+
JSON.stringify({ gateway: { mode: "remote", remote: { url: gateway.url, token } } }),
646+
);
647+
if (seeded) {
648+
const identity = loadOrCreateDeviceIdentity({ env: stateEnv });
649+
storeOriginDeviceToken({
650+
gatewayScope: gatewayOriginScope(gateway.url),
651+
deviceId: identity.deviceId,
652+
role: "operator",
653+
token,
654+
scopes: ["operator.admin"],
655+
env: stateEnv,
656+
});
657+
closeOpenClawStateDatabaseForTest();
658+
}
659+
const before = await snapshotSharedStateArtifacts(stateDir);
660+
expect(Object.keys(before).includes("openclaw.sqlite")).toBe(seeded);
661+
662+
const result = await runIsolatedGatewayCli({
663+
args: [
664+
"gateway",
665+
"status",
666+
"--url",
667+
gateway.url,
668+
"--token",
669+
token,
670+
"--require-rpc",
671+
"--json",
672+
"--timeout",
673+
"2000",
674+
],
675+
root,
676+
stateDir,
677+
configPath,
678+
});
679+
680+
expect(result, result.stderr).toMatchObject({ code: 0, signal: null, stderr: "" });
681+
expect(JSON.parse(result.stdout)).toMatchObject({
682+
rpc: { ok: true, kind: "read" },
683+
});
684+
expect(gateway.calls).toEqual(["status"]);
685+
expect(await snapshotSharedStateArtifacts(stateDir)).toEqual(before);
686+
},
687+
30_000,
688+
);
689+
618690
it.each([
619691
{ label: "absent", seeded: false },
620692
{ label: "seeded", seeded: true },

0 commit comments

Comments
 (0)