Skip to content

Commit fc5ac11

Browse files
committed
test(msteams): cover occupied webhook port
Punchcard-Session: silver-willow-harbor-px
1 parent 9aa24e8 commit fc5ac11

1 file changed

Lines changed: 37 additions & 1 deletion

File tree

‎extensions/msteams/src/monitor.lifecycle.test.ts‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Msteams tests cover monitor.lifecycle plugin behavior.
2-
import type { Server } from "node:http";
2+
import { createServer, type Server } from "node:http";
33
import type { Request, Response } from "express";
44
import { afterEach, describe, expect, it, vi } from "vitest";
55
import type { OpenClawConfig, RuntimeEnv } from "../runtime-api.js";
@@ -292,6 +292,42 @@ describe("monitorMSTeamsProvider lifecycle", () => {
292292
}
293293
});
294294

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+
295331
it("rejects requests without Bearer token before SDK route", async () => {
296332
const abort = new AbortController();
297333
const task = monitorMSTeamsProvider({

0 commit comments

Comments
 (0)