perf(test): statically import gateway reload deps

This commit is contained in:
Peter Steinberger
2026-02-13 23:52:16 +00:00
parent 1055e71c4b
commit 79bd82a35b
3 changed files with 13 additions and 14 deletions

View File

@@ -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({

View File

@@ -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)

View File

@@ -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<T = void>() {
let resolve!: (value: T | PromiseLike<T>) => 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({