diff --git a/src/infra/bonjour.test.ts b/src/infra/bonjour.test.ts index d8f976fdc41ac..513250968c446 100644 --- a/src/infra/bonjour.test.ts +++ b/src/infra/bonjour.test.ts @@ -307,4 +307,29 @@ describe("gateway bonjour advertiser", () => { await started.stop(); }); + + it("disables Bonjour on win32 unless explicitly enabled", async () => { + enableAdvertiserUnitMode(); + vi.spyOn(process, "platform", "get").mockReturnValue("win32"); + + const started = await startGatewayBonjourAdvertiser({ + gatewayPort: 18789, + sshPort: 2222, + }); + expect(createService).not.toHaveBeenCalled(); + await started.stop(); + + createService.mockClear(); + process.env.OPENCLAW_ENABLE_BONJOUR_WINDOWS = "1"; + const destroy = vi.fn().mockResolvedValue(undefined); + const advertise = vi.fn().mockResolvedValue(undefined); + mockCiaoService({ advertise, destroy }); + + const enabled = await startGatewayBonjourAdvertiser({ + gatewayPort: 18789, + sshPort: 2222, + }); + expect(createService).toHaveBeenCalledTimes(1); + await enabled.stop(); + }); }); diff --git a/src/infra/bonjour.ts b/src/infra/bonjour.ts index 7d405741a0ecd..95b956b90b77f 100644 --- a/src/infra/bonjour.ts +++ b/src/infra/bonjour.ts @@ -29,6 +29,14 @@ function isDisabledByEnv() { if (isTruthyEnvValue(process.env.OPENCLAW_DISABLE_BONJOUR)) { return true; } + // On Windows, ciao's network probing can spawn visible cmd.exe helpers on some + // hosts. Keep Bonjour opt-in there to avoid periodic console-window flashing. + if ( + process.platform === "win32" && + !isTruthyEnvValue(process.env.OPENCLAW_ENABLE_BONJOUR_WINDOWS) + ) { + return true; + } if (process.env.NODE_ENV === "test") { return true; }