@@ -619,6 +619,37 @@ describe("createWebhookHandler", () => {
|
619 | 619 | expectBotReplySentTo("123"); |
620 | 620 | }); |
621 | 621 | |
| 622 | +it("awaits deliver directly with no local hardcoded timeout wrapper", async () => { |
| 623 | +// Previously this webhook handler wrapped deliver with a hardcoded 120s |
| 624 | +// Promise.race that overrode the configurable agents.defaults.timeoutSeconds |
| 625 | +// from core. That wrapper created a setTimeout(_, 120000) on every deliver |
| 626 | +// call. We spy on setTimeout to prove no such call exists in the current code. |
| 627 | +const setTimeoutSpy = vi.spyOn(global, "setTimeout"); |
| 628 | +try { |
| 629 | +const deliver = vi.fn().mockResolvedValue("late reply"); |
| 630 | +const handler = createWebhookHandler({ |
| 631 | +account: makeAccount({ accountId: "no-hardcoded-timeout-" + Date.now() }), |
| 632 | + deliver, |
| 633 | + log, |
| 634 | +}); |
| 635 | + |
| 636 | +const res = makeRes(); |
| 637 | +const req = makeReq("POST", validBody); |
| 638 | +await handler(req, res); |
| 639 | + |
| 640 | +expect(res.status).toBe(204); |
| 641 | + |
| 642 | +// Collect all setTimeout delays used during this handler run |
| 643 | +const delays = setTimeoutSpy.mock.calls.map((call) => call[1]); |
| 644 | +// Every delay should be well under 120s — the old hardcoded wrapper would |
| 645 | +// have produced exactly one call with delay === 120000. |
| 646 | +const longDelays = delays.filter((d) => typeof d === "number" && d >= 120_000); |
| 647 | +expect(longDelays).toEqual([]); |
| 648 | +} finally { |
| 649 | +setTimeoutSpy.mockRestore(); |
| 650 | +} |
| 651 | +}); |
| 652 | + |
622 | 653 | it("sanitizes input before delivery", async () => { |
623 | 654 | const deliver = vi.fn().mockResolvedValue(null); |
624 | 655 | const handler = createWebhookHandler({ |
|