|
1 | 1 | // Msteams tests cover monitor.lifecycle plugin behavior. |
2 | | -import type { Server } from "node:http"; |
| 2 | +import { createServer, type Server } from "node:http"; |
3 | 3 | import type { Request, Response } from "express"; |
4 | 4 | import { afterEach, describe, expect, it, vi } from "vitest"; |
5 | 5 | import type { OpenClawConfig, RuntimeEnv } from "../runtime-api.js"; |
@@ -292,6 +292,42 @@ describe("monitorMSTeamsProvider lifecycle", () => { |
292 | 292 | } |
293 | 293 | }); |
294 | 294 |
|
| 295 | + it("rejects startup when the webhook port is already in use", async () => { |
| 296 | + const blocker = createServer(); |
| 297 | + await new Promise<void>((resolve, reject) => { |
| 298 | + blocker.once("error", reject); |
| 299 | + blocker.listen(0, resolve); |
| 300 | + }); |
| 301 | + |
| 302 | + try { |
| 303 | + const address = blocker.address(); |
| 304 | + if (!address || typeof address === "string") { |
| 305 | + throw new Error("expected occupied TCP port"); |
| 306 | + } |
| 307 | + |
| 308 | + const stores = createStores(); |
| 309 | + const task = monitorMSTeamsProvider({ |
| 310 | + cfg: createConfig(address.port), |
| 311 | + runtime: createRuntime(), |
| 312 | + conversationStore: stores.conversationStore, |
| 313 | + pollStore: stores.pollStore, |
| 314 | + }); |
| 315 | + |
| 316 | + await expect(task).rejects.toMatchObject({ code: "EADDRINUSE" }); |
| 317 | + const ingress = getMSTeamsIngressMockState().instances[0]; |
| 318 | + if (!ingress) { |
| 319 | + throw new Error("expected Teams ingress"); |
| 320 | + } |
| 321 | + expect(ingress.start).toHaveBeenCalledTimes(1); |
| 322 | + expect(ingress.stop).toHaveBeenCalledTimes(1); |
| 323 | + expect(keepHttpServerTaskAliveMock).not.toHaveBeenCalled(); |
| 324 | + } finally { |
| 325 | + await new Promise<void>((resolve, reject) => { |
| 326 | + blocker.close((err) => (err ? reject(err) : resolve())); |
| 327 | + }); |
| 328 | + } |
| 329 | + }); |
| 330 | + |
295 | 331 | it("rejects requests without Bearer token before SDK route", async () => { |
296 | 332 | const abort = new AbortController(); |
297 | 333 | const task = monitorMSTeamsProvider({ |
|
0 commit comments