From 79bd82a35ba192fd87eb562aea2e592543d32bb6 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 13 Feb 2026 23:52:16 +0000 Subject: [PATCH] perf(test): statically import gateway reload deps --- src/gateway/server-reload.config-during-reply.test.ts | 5 ++--- src/gateway/server-reload.integration.test.ts | 11 ++++++----- src/gateway/server-reload.real-scenario.test.ts | 11 +++++------ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/gateway/server-reload.config-during-reply.test.ts b/src/gateway/server-reload.config-during-reply.test.ts index c0a7265090..3d8be89749 100644 --- a/src/gateway/server-reload.config-during-reply.test.ts +++ b/src/gateway/server-reload.config-during-reply.test.ts @@ -7,6 +7,8 @@ import { clearAllDispatchers, getTotalPendingReplies, } from "../auto-reply/reply/dispatcher-registry.js"; +import { createReplyDispatcher } from "../auto-reply/reply/reply-dispatcher.js"; +import { getTotalQueueSize } from "../process/command-queue.js"; // Helper to flush all pending microtasks async function flushMicrotasks() { @@ -28,9 +30,6 @@ describe("gateway config reload during reply", () => { }); it("should defer restart until reply dispatcher completes", async () => { - const { createReplyDispatcher } = await import("../auto-reply/reply/reply-dispatcher.js"); - const { getTotalQueueSize } = await import("../process/command-queue.js"); - // Create a dispatcher (simulating message handling) let deliveredReplies: string[] = []; const dispatcher = createReplyDispatcher({ diff --git a/src/gateway/server-reload.integration.test.ts b/src/gateway/server-reload.integration.test.ts index 698b1041fd..9d788ad494 100644 --- a/src/gateway/server-reload.integration.test.ts +++ b/src/gateway/server-reload.integration.test.ts @@ -4,6 +4,12 @@ * and ensures they get a reply before the gateway restarts. */ import { describe, expect, it, vi, beforeEach, afterEach } from "vitest"; +import { + clearAllDispatchers, + getTotalPendingReplies, +} from "../auto-reply/reply/dispatcher-registry.js"; +import { createReplyDispatcher } from "../auto-reply/reply/reply-dispatcher.js"; +import { getTotalQueueSize } from "../process/command-queue.js"; describe("gateway restart deferral integration", () => { beforeEach(() => { @@ -14,15 +20,10 @@ describe("gateway restart deferral integration", () => { vi.restoreAllMocks(); // Wait for any pending microtasks (from markComplete()) to complete await Promise.resolve(); - const { clearAllDispatchers } = await import("../auto-reply/reply/dispatcher-registry.js"); clearAllDispatchers(); }); it("should defer restart until dispatcher completes with reply", async () => { - const { createReplyDispatcher } = await import("../auto-reply/reply/reply-dispatcher.js"); - const { getTotalPendingReplies } = await import("../auto-reply/reply/dispatcher-registry.js"); - const { getTotalQueueSize } = await import("../process/command-queue.js"); - const events: string[] = []; // T=0: Message received — dispatcher created (pending=1 reservation) diff --git a/src/gateway/server-reload.real-scenario.test.ts b/src/gateway/server-reload.real-scenario.test.ts index dc10891ff7..f26f660dc7 100644 --- a/src/gateway/server-reload.real-scenario.test.ts +++ b/src/gateway/server-reload.real-scenario.test.ts @@ -3,6 +3,11 @@ * This test MUST fail if "imsg rpc not running" would occur in production. */ import { describe, expect, it, vi, beforeEach, afterEach } from "vitest"; +import { + clearAllDispatchers, + getTotalPendingReplies, +} from "../auto-reply/reply/dispatcher-registry.js"; +import { createReplyDispatcher } from "../auto-reply/reply/reply-dispatcher.js"; function createDeferred() { let resolve!: (value: T | PromiseLike) => void; @@ -26,14 +31,10 @@ describe("real scenario: config change during message processing", () => { vi.restoreAllMocks(); // Wait for any pending microtasks (from markComplete()) to complete await Promise.resolve(); - const { clearAllDispatchers } = await import("../auto-reply/reply/dispatcher-registry.js"); clearAllDispatchers(); }); it("should NOT restart gateway while reply delivery is in flight", async () => { - const { createReplyDispatcher } = await import("../auto-reply/reply/reply-dispatcher.js"); - const { getTotalPendingReplies } = await import("../auto-reply/reply/dispatcher-registry.js"); - let rpcConnected = true; const deliveredReplies: string[] = []; const deliveryStarted = createDeferred(); @@ -95,8 +96,6 @@ describe("real scenario: config change during message processing", () => { }); it("should keep pending > 0 until reply is actually enqueued", async () => { - const { createReplyDispatcher } = await import("../auto-reply/reply/reply-dispatcher.js"); - const { getTotalPendingReplies } = await import("../auto-reply/reply/dispatcher-registry.js"); const allowDelivery = createDeferred(); const dispatcher = createReplyDispatcher({