@@ -35,6 +35,7 @@ const findSystemGatewayServices = vi.hoisted(() =>
3535) ;
3636const buildGatewayRuntimeHints = vi . hoisted ( ( ) => vi . fn ( ( ) : string [ ] => [ ] ) ) ;
3737const formatGatewayRuntimeSummary = vi . hoisted ( ( ) => vi . fn ( ( ) : string | null => null ) ) ;
38+ const isDefaultInstallIdentity = vi . hoisted ( ( ) => vi . fn ( ( ) => true ) ) ;
3839
3940vi . mock ( "../config/config.js" , async ( ) => {
4041 const actual = await vi . importActual < typeof import ( "../config/config.js" ) > ( "../config/config.js" ) ;
@@ -44,6 +45,11 @@ vi.mock("../config/config.js", async () => {
4445 } ;
4546} ) ;
4647
48+ vi . mock ( "../config/paths.js" , async ( ) => {
49+ const actual = await vi . importActual < typeof import ( "../config/paths.js" ) > ( "../config/paths.js" ) ;
50+ return { ...actual , isDefaultInstallIdentity } ;
51+ } ) ;
52+
4753vi . mock ( "../daemon/constants.js" , ( ) => ( {
4854 resolveGatewayLaunchAgentLabel : vi . fn ( ( ) => "ai.openclaw.gateway" ) ,
4955 resolveNodeLaunchAgentLabel : vi . fn ( ( ) => "ai.openclaw.node" ) ,
@@ -161,6 +167,7 @@ describe("maybeRepairGatewayDaemon", () => {
161167 service . readRuntime . mockResolvedValue ( { status : "running" } ) ;
162168 service . readCommand . mockResolvedValue ( null ) ;
163169 service . restart . mockResolvedValue ( { outcome : "completed" } ) ;
170+ isDefaultInstallIdentity . mockReturnValue ( true ) ;
164171 readGatewayRestartHandoffSync . mockReturnValue ( null ) ;
165172 findSystemGatewayServices . mockResolvedValue ( [ ] ) ;
166173 inspectPortUsage . mockResolvedValue ( {
@@ -287,6 +294,41 @@ describe("maybeRepairGatewayDaemon", () => {
287294 await runScheduledGatewayRepairAndExpectVerificationSkipped ( "Restart gateway service now?" ) ;
288295 } ) ;
289296
297+ it ( "skips every service-manager seam for a non-default install identity" , async ( ) => {
298+ await withEnvAsync (
299+ {
300+ OPENCLAW_STATE_DIR : "/tmp/openclaw-copied-state" ,
301+ OPENCLAW_CONFIG_PATH : "/tmp/openclaw-copied-state/openclaw.json" ,
302+ } ,
303+ async ( ) => {
304+ isDefaultInstallIdentity . mockReturnValue ( false ) ;
305+ await runNonInteractiveRepair ( ) ;
306+ } ,
307+ ) ;
308+
309+ expect ( service . isLoaded ) . not . toHaveBeenCalled ( ) ;
310+ expect ( service . readRuntime ) . not . toHaveBeenCalled ( ) ;
311+ expect ( service . readCommand ) . not . toHaveBeenCalled ( ) ;
312+ expect ( service . install ) . not . toHaveBeenCalled ( ) ;
313+ expect ( service . restart ) . not . toHaveBeenCalled ( ) ;
314+ expect ( launchd . repairLaunchAgentBootstrap ) . not . toHaveBeenCalled ( ) ;
315+ expect ( findSystemGatewayServices ) . not . toHaveBeenCalled ( ) ;
316+ expect ( note ) . toHaveBeenCalledWith (
317+ "service management skipped: non-default state dir or config path" ,
318+ "Gateway" ,
319+ ) ;
320+ } ) ;
321+
322+ it ( "still inspects the managed service for the default install identity" , async ( ) => {
323+ await withEnvAsync (
324+ { OPENCLAW_STATE_DIR : undefined , OPENCLAW_CONFIG_PATH : undefined } ,
325+ runNonInteractiveRepair ,
326+ ) ;
327+
328+ expect ( service . isLoaded ) . toHaveBeenCalledTimes ( 1 ) ;
329+ expect ( service . readRuntime ) . toHaveBeenCalledTimes ( 1 ) ;
330+ } ) ;
331+
290332 it ( "reports recent restart handoffs during deep doctor" , async ( ) => {
291333 vi . useFakeTimers ( ) ;
292334 vi . setSystemTime ( 40_000 ) ;
0 commit comments