


























@@ -3,10 +3,12 @@ import type { GatewayProbeResult } from "../../gateway/probe.js";
33import type { RuntimeEnv } from "../../runtime.js";
44import type { GatewayStatusProbedTarget } from "./probe-run.js";
556-const writeRuntimeJson = vi.fn();
6+const mocks = vi.hoisted(() => ({
7+writeRuntimeJson: vi.fn(),
8+}));
79810vi.mock("../../runtime.js", () => ({
9-writeRuntimeJson: (...args: unknown[]) => writeRuntimeJson(...args),
11+writeRuntimeJson: (...args: unknown[]) => mocks.writeRuntimeJson(...args),
1012}));
11131214vi.mock("../../terminal/theme.js", async () => {
@@ -18,7 +20,8 @@ vi.mock("../../terminal/theme.js", async () => {
1820};
1921});
202221-const { writeGatewayStatusJson, writeGatewayStatusText } = await import("./output.js");
23+const { buildGatewayStatusWarnings, writeGatewayStatusJson, writeGatewayStatusText } =
24+await import("./output.js");
22252326function createRuntimeCapture(): RuntimeEnv {
2427return {
@@ -77,7 +80,35 @@ function createTarget(id: string, probe: GatewayProbeResult): GatewayStatusProbe
77807881describe("gateway status output", () => {
7982beforeEach(() => {
80-writeRuntimeJson.mockReset();
83+mocks.writeRuntimeJson.mockReset();
84+});
85+86+it("warns with diagnostic next steps when no probes or Bonjour discovery find a gateway", () => {
87+const warnings = buildGatewayStatusWarnings({
88+probed: [
89+createTarget(
90+"localLoopback",
91+createProbe("unknown", {
92+ok: false,
93+connectLatencyMs: null,
94+error: "connection refused",
95+}),
96+),
97+],
98+sshTarget: null,
99+sshTunnelStarted: false,
100+sshTunnelError: null,
101+discoveryCount: 0,
102+});
103+104+expect(warnings).toContainEqual(
105+expect.objectContaining({
106+code: "no_gateway_reachable",
107+message: expect.stringContaining("openclaw gateway status --deep --require-rpc"),
108+targetIds: ["localLoopback"],
109+}),
110+);
111+expect(warnings.at(0)?.message).toContain("lsof -nP -iTCP:<port>");
81112});
8211383114it("derives summary capability from reachable probes only in json output", () => {
@@ -114,7 +145,7 @@ describe("gateway status output", () => {
114145primaryTargetId: "reachable-read",
115146});
116147117-expect(writeRuntimeJson).toHaveBeenCalledWith(
148+expect(mocks.writeRuntimeJson).toHaveBeenCalledWith(
118149runtime,
119150expect.objectContaining({
120151ok: true,
@@ -188,7 +219,7 @@ describe("gateway status output", () => {
188219primaryTargetId: "detail-timeout",
189220});
190221191-expect(writeRuntimeJson).toHaveBeenCalledWith(
222+expect(mocks.writeRuntimeJson).toHaveBeenCalledWith(
192223runtime,
193224expect.objectContaining({
194225ok: true,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。