
























@@ -369,10 +369,52 @@ describe("logs cli", () => {
369369370370expect(readConfiguredLogTail).not.toHaveBeenCalled();
371371expect(stderrWrites.join("")).toContain("gateway disconnected");
372+expect(stderrWrites.join("")).toContain("gateway reconnected");
372373expect(stdoutWrites.join("")).toContain("line from remote");
373374expect(exitSpy).toHaveBeenCalledWith(1);
374375});
375376377+it("emits notice JSON records for retry and reconnect in --follow --json mode", async () => {
378+callGatewayFromCli
379+.mockRejectedValueOnce(
380+new GatewayTransportError({
381+kind: "closed",
382+code: 1006,
383+reason: "abnormal closure",
384+connectionDetails: {
385+url: "ws://remote.example.com:18789",
386+urlSource: "cli",
387+message: "",
388+},
389+message: "gateway closed (1006 abnormal closure): abnormal closure",
390+}),
391+)
392+.mockResolvedValueOnce({
393+file: "/tmp/openclaw.log",
394+cursor: 10,
395+lines: [],
396+});
397+398+const stderrWrites = captureStderrWrites();
399+const stdoutWrites = captureStdoutWrites();
400+const exitSpy = vi.spyOn(process, "exit").mockImplementation(() => undefined as never);
401+402+await runLogsCli(["logs", "--follow", "--json", "--url", "ws://remote.example.com:18789"]);
403+404+const stderr = stderrWrites.join("");
405+const noticeRecords = stderr
406+.split("\n")
407+.filter((line) => line.length > 0)
408+.map((line) => JSON.parse(line) as { type: string; message?: string });
409+const messages = noticeRecords
410+.filter((record) => record.type === "notice")
411+.map((record) => record.message ?? "");
412+expect(messages.some((message) => message.includes("gateway disconnected"))).toBe(true);
413+expect(messages.some((message) => message.includes("gateway reconnected"))).toBe(true);
414+expect(stdoutWrites.join("")).toContain('"type":"meta"');
415+expect(exitSpy).toHaveBeenCalledWith(1);
416+});
417+376418it("exits immediately on pairing-required close errors in --follow mode with explicit URL", async () => {
377419callGatewayFromCli.mockRejectedValueOnce(
378420new GatewayTransportError({
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。