























@@ -4,6 +4,7 @@ import path from "node:path";
44import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
55import type { StaleOpenClawUpdateLaunchdJob } from "../../daemon/launchd.js";
66import { createMockGatewayService } from "../../daemon/service.test-helpers.js";
7+import type { PortConnections } from "../../infra/ports.js";
78import type { GatewayRestartHandoff } from "../../infra/restart-handoff.js";
89import { captureEnv } from "../../test-utils/env.js";
910import { VERSION } from "../../version.js";
@@ -38,6 +39,12 @@ const inspectPortUsage = vi.fn(async (port: number) => ({
3839listeners: [],
3940hints: [],
4041}));
42+const inspectPortConnections = vi.fn<(port: number) => Promise<PortConnections>>(
43+async (port: number) => ({
44+ port,
45+connections: [],
46+}),
47+);
4148const readLastGatewayErrorLine = vi.fn(async (_env?: NodeJS.ProcessEnv) => null);
4249const readGatewayRestartHandoffSync = vi.fn<
4350(_env?: NodeJS.ProcessEnv) => GatewayRestartHandoff | null
@@ -166,6 +173,7 @@ vi.mock("../../gateway/net.js", () => ({
166173}));
167174168175vi.mock("../../infra/ports.js", () => ({
176+inspectPortConnections: (port: number) => inspectPortConnections(port),
169177inspectPortUsage: (port: number) => inspectPortUsage(port),
170178formatPortDiagnostics: () => [],
171179}));
@@ -222,6 +230,7 @@ describe("gatherDaemonStatus", () => {
222230findStaleOpenClawUpdateLaunchdJobs.mockResolvedValue([]);
223231loadGatewayTlsRuntime.mockClear();
224232inspectGatewayRestart.mockClear();
233+inspectPortConnections.mockClear();
225234readGatewayRestartHandoffSync.mockClear();
226235readConfigFileSnapshotCalls.mockClear();
227236loadConfigCalls.mockClear();
@@ -484,6 +493,59 @@ describe("gatherDaemonStatus", () => {
484493485494expect(readGatewayRestartHandoffSync).not.toHaveBeenCalled();
486495expect(findStaleOpenClawUpdateLaunchdJobs).not.toHaveBeenCalled();
496+expect(inspectPortConnections).not.toHaveBeenCalled();
497+});
498+499+it("surfaces established gateway connections during deep status", async () => {
500+inspectPortConnections.mockResolvedValueOnce({
501+port: 19001,
502+connections: [
503+{
504+pid: 4242,
505+ppid: 1,
506+command: "node",
507+commandLine: "node /tmp/newer-openclaw/dist/index.js logs --follow",
508+address: "TCP 127.0.0.1:50123->127.0.0.1:19001 (ESTABLISHED)",
509+direction: "client",
510+},
511+],
512+});
513+514+const status = await gatherDaemonStatus({
515+rpc: {},
516+probe: false,
517+deep: true,
518+});
519+520+expect(inspectPortConnections).toHaveBeenCalledWith(19001);
521+expect(status.connections?.established).toEqual([
522+{
523+pid: 4242,
524+ppid: 1,
525+command: "node",
526+commandLine: "node /tmp/newer-openclaw/dist/index.js logs --follow",
527+address: "TCP 127.0.0.1:50123->127.0.0.1:19001 (ESTABLISHED)",
528+direction: "client",
529+},
530+]);
531+});
532+533+it("skips established gateway connection scans for remote gateway status", async () => {
534+daemonLoadedConfig = {
535+gateway: {
536+mode: "remote",
537+remote: { url: "wss://gateway.example" },
538+},
539+};
540+541+const status = await gatherDaemonStatus({
542+rpc: {},
543+probe: false,
544+deep: true,
545+});
546+547+expect(inspectPortConnections).not.toHaveBeenCalled();
548+expect(status.connections).toBeUndefined();
487549});
488550489551it("uses the fast config path for plain same-file status reads", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。