@@ -3,8 +3,9 @@ import os from "node:os";
33import path from "node:path" ;
44import { afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
55import type { StaleOpenClawUpdateLaunchdJob } from "../../daemon/launchd.js" ;
6+ import type { GatewayServiceRuntime } from "../../daemon/service-runtime.js" ;
67import { createMockGatewayService } from "../../daemon/service.test-helpers.js" ;
7- import type { PortConnections } from "../../infra/ports.js" ;
8+ import type { PortConnections , PortUsage } from "../../infra/ports.js" ;
89import type { GatewayRestartHandoff } from "../../infra/restart-handoff.js" ;
910import { captureEnv } from "../../test-utils/env.js" ;
1011import { VERSION } from "../../version.js" ;
@@ -34,7 +35,7 @@ const findExtraGatewayServices = vi.fn(async (_env?: unknown, _opts?: unknown) =
3435const findStaleOpenClawUpdateLaunchdJobs = vi . fn <
3536 ( env ?: NodeJS . ProcessEnv ) => Promise < StaleOpenClawUpdateLaunchdJob [ ] >
3637> ( async ( ) => [ ] ) ;
37- const inspectPortUsage = vi . fn ( async ( port : number ) => ( {
38+ const inspectPortUsage = vi . fn < ( port : number ) => Promise < PortUsage > > ( async ( port : number ) => ( {
3839 port,
3940 status : "free" as const ,
4041 listeners : [ ] ,
@@ -52,7 +53,9 @@ const readGatewayRestartHandoffSync = vi.fn<
5253> ( ( ) => null ) ;
5354const auditGatewayServiceConfig = vi . fn ( async ( _opts ?: unknown ) => undefined ) ;
5455const serviceIsLoaded = vi . fn ( async ( _opts ?: unknown ) => true ) ;
55- const serviceReadRuntime = vi . fn ( async ( _env ?: NodeJS . ProcessEnv ) => ( { status : "running" } ) ) ;
56+ const serviceReadRuntime = vi . fn < ( _env ?: NodeJS . ProcessEnv ) => Promise < GatewayServiceRuntime > > (
57+ async ( _env ?: NodeJS . ProcessEnv ) => ( { status : "running" } ) ,
58+ ) ;
5659const inspectGatewayRestart = vi . fn < ( opts ?: unknown ) => Promise < GatewayRestartSnapshot > > (
5760 async ( _opts ?: unknown ) => ( {
5861 runtime : { status : "running" , pid : 1234 } ,
@@ -453,6 +456,32 @@ describe("gatherDaemonStatus", () => {
453456 expect ( ( status . service . runtime as { detail ?: string } ) . detail ) . toBe ( "19001" ) ;
454457 } ) ;
455458
459+ it ( "suppresses busy-port hints when all listeners belong to the running gateway pid" , async ( ) => {
460+ serviceReadRuntime . mockResolvedValueOnce ( { status : "running" , pid : 73614 } ) ;
461+ inspectPortUsage . mockResolvedValueOnce ( {
462+ port : 19001 ,
463+ status : "busy" ,
464+ listeners : [
465+ { pid : 73614 , command : "node" , address : "127.0.0.1:19001" } ,
466+ { pid : 73614 , command : "node" , address : "[::1]:19001" } ,
467+ ] ,
468+ hints : [
469+ "Another process is listening on this port." ,
470+ "Multiple listeners detected; ensure only one gateway/tunnel per port unless intentionally running isolated profiles." ,
471+ ] ,
472+ } ) ;
473+
474+ const status = await gatherDaemonStatus ( {
475+ rpc : { } ,
476+ probe : false ,
477+ deep : false ,
478+ } ) ;
479+
480+ expect ( status . port ?. status ) . toBe ( "busy" ) ;
481+ expect ( status . port ?. listeners ) . toHaveLength ( 2 ) ;
482+ expect ( status . port ?. hints ) . toEqual ( [ ] ) ;
483+ } ) ;
484+
456485 it ( "surfaces recent service restart handoffs only during deep status" , async ( ) => {
457486 readGatewayRestartHandoffSync . mockReturnValueOnce ( {
458487 kind : "gateway-supervisor-restart-handoff" ,
0 commit comments