test(gateway): share runtime state fixture

This commit is contained in:
Vincent Koc
2026-06-02 10:54:56 +02:00
parent af9bad9fe7
commit afbf895af0
3 changed files with 31 additions and 40 deletions
+2 -19
View File
@@ -10,7 +10,7 @@ import {
resolveActivePluginHttpRouteRegistry,
setActivePluginRegistry,
} from "../plugins/runtime.js";
import { createGatewayRuntimeState } from "./server-runtime-state.js";
import { createGatewayRuntimeStateForTest } from "./test-helpers.server-runtime-state.js";
function createRegistryWithRoute(path: string) {
const registry = createEmptyPluginRegistry();
@@ -38,24 +38,7 @@ describe("createGatewayRuntimeState", () => {
const fallbackRegistry = createRegistryWithRoute("/fallback");
setActivePluginRegistry(startupRegistry);
const runtimeState = await createGatewayRuntimeState({
cfg: {},
bindHost: "127.0.0.1",
port: 0,
controlUiEnabled: false,
controlUiBasePath: "/",
openAiChatCompletionsEnabled: false,
openResponsesEnabled: false,
resolvedAuth: {} as never,
getResolvedAuth: () => ({}) as never,
hooksConfig: () => null,
getHookClientIpConfig: () => ({}) as never,
pluginRegistry: startupRegistry,
deps: {} as never,
log: { info: () => {}, warn: () => {} },
logHooks: { info: () => {}, warn: () => {}, error: () => {}, debug: () => {} } as never,
logPlugins: { info: () => {}, warn: () => {}, error: () => {}, debug: () => {} } as never,
});
const runtimeState = await createGatewayRuntimeStateForTest(startupRegistry);
pinActivePluginHttpRouteRegistry(loadedRegistry);
pinActivePluginChannelRegistry(loadedRegistry);
@@ -1,8 +1,7 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { WebSocket } from "ws";
import { createEmptyPluginRegistry } from "../plugins/registry.js";
import { createGatewayRuntimeState } from "./server-runtime-state.js";
import { getFreePort, installGatewayTestHooks, startGatewayServer } from "./test-helpers.js";
import { createGatewayRuntimeStateForTest } from "./test-helpers.server-runtime-state.js";
type StartGatewayServer = typeof import("./test-helpers.js").startGatewayServer;
type GatewayServerForTest = Awaited<ReturnType<StartGatewayServer>>;
@@ -52,25 +51,7 @@ afterEach(() => {
describe("gateway startup websocket readiness", () => {
it("attaches websocket upgrade handlers before exposing the listen step", async () => {
const registry = createEmptyPluginRegistry();
const runtimeState = await createGatewayRuntimeState({
cfg: {},
bindHost: "127.0.0.1",
port: 0,
controlUiEnabled: false,
controlUiBasePath: "/",
openAiChatCompletionsEnabled: false,
openResponsesEnabled: false,
resolvedAuth: {} as never,
getResolvedAuth: () => ({}) as never,
hooksConfig: () => null,
getHookClientIpConfig: () => ({}) as never,
pluginRegistry: registry,
deps: {} as never,
log: { info: () => {}, warn: () => {} },
logHooks: { info: () => {}, warn: () => {}, error: () => {}, debug: () => {} } as never,
logPlugins: { info: () => {}, warn: () => {}, error: () => {}, debug: () => {} } as never,
});
const runtimeState = await createGatewayRuntimeStateForTest();
try {
expect(runtimeState.httpBindHosts).toEqual([]);
expect(runtimeState.httpServer.listenerCount("upgrade")).toBeGreaterThan(0);
@@ -0,0 +1,27 @@
import { createEmptyPluginRegistry } from "../plugins/registry.js";
import { createGatewayRuntimeState } from "./server-runtime-state.js";
type GatewayRuntimeStateParams = Parameters<typeof createGatewayRuntimeState>[0];
export async function createGatewayRuntimeStateForTest(
pluginRegistry: GatewayRuntimeStateParams["pluginRegistry"] = createEmptyPluginRegistry(),
) {
return await createGatewayRuntimeState({
cfg: {},
bindHost: "127.0.0.1",
port: 0,
controlUiEnabled: false,
controlUiBasePath: "/",
openAiChatCompletionsEnabled: false,
openResponsesEnabled: false,
resolvedAuth: {} as never,
getResolvedAuth: () => ({}) as never,
hooksConfig: () => null,
getHookClientIpConfig: () => ({}) as never,
pluginRegistry,
deps: {} as never,
log: { info: () => {}, warn: () => {} },
logHooks: { info: () => {}, warn: () => {}, error: () => {}, debug: () => {} } as never,
logPlugins: { info: () => {}, warn: () => {}, error: () => {}, debug: () => {} } as never,
});
}