|
| 1 | +import fs from "node:fs"; |
1 | 2 | import os from "node:os"; |
2 | 3 | import { afterEach, describe, expect, it, vi } from "vitest"; |
3 | 4 | |
@@ -207,6 +208,38 @@ describe("gateway bonjour advertiser", () => {
|
207 | 208 | await expect(started.stop()).resolves.toBeUndefined(); |
208 | 209 | }); |
209 | 210 | |
| 211 | +it("auto-disables Bonjour in detected containers", async () => { |
| 212 | +enableAdvertiserUnitMode(); |
| 213 | +vi.spyOn(fs, "existsSync").mockImplementation((filePath) => String(filePath) === "/.dockerenv"); |
| 214 | + |
| 215 | +const started = await startAdvertiser({ |
| 216 | +gatewayPort: 18789, |
| 217 | +sshPort: 2222, |
| 218 | +}); |
| 219 | + |
| 220 | +expect(createService).not.toHaveBeenCalled(); |
| 221 | +await expect(started.stop()).resolves.toBeUndefined(); |
| 222 | +}); |
| 223 | + |
| 224 | +it("honors explicit Bonjour opt-in inside detected containers", async () => { |
| 225 | +enableAdvertiserUnitMode(); |
| 226 | +process.env.OPENCLAW_DISABLE_BONJOUR = "0"; |
| 227 | +vi.spyOn(fs, "existsSync").mockImplementation((filePath) => String(filePath) === "/.dockerenv"); |
| 228 | + |
| 229 | +const destroy = vi.fn().mockResolvedValue(undefined); |
| 230 | +const advertise = vi.fn().mockResolvedValue(undefined); |
| 231 | +mockCiaoService({ advertise, destroy }); |
| 232 | + |
| 233 | +const started = await startAdvertiser({ |
| 234 | +gatewayPort: 18789, |
| 235 | +sshPort: 2222, |
| 236 | +}); |
| 237 | + |
| 238 | +expect(createService).toHaveBeenCalledTimes(1); |
| 239 | + |
| 240 | +await started.stop(); |
| 241 | +}); |
| 242 | + |
210 | 243 | it("attaches conflict listeners for services", async () => { |
211 | 244 | enableAdvertiserUnitMode(); |
212 | 245 | |
|