mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 04:47:03 -06:00
test(gateway): share runtime state fixture
This commit is contained in:
@@ -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,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user