mirror of https://github.com/openclaw/openclaw.git
test: annotate chat abort helper exports (#45346)
This commit is contained in:
parent
1f85c9af68
commit
987c254eea
|
|
@ -1,5 +1,6 @@
|
||||||
import { vi } from "vitest";
|
import { vi } from "vitest";
|
||||||
import type { GatewayRequestHandler } from "./types.js";
|
import type { Mock } from "vitest";
|
||||||
|
import type { GatewayRequestHandler, RespondFn } from "./types.js";
|
||||||
|
|
||||||
export function createActiveRun(
|
export function createActiveRun(
|
||||||
sessionKey: string,
|
sessionKey: string,
|
||||||
|
|
@ -20,7 +21,23 @@ export function createActiveRun(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createChatAbortContext(overrides: Record<string, unknown> = {}) {
|
export type ChatAbortTestContext = Record<string, unknown> & {
|
||||||
|
chatAbortControllers: Map<string, ReturnType<typeof createActiveRun>>;
|
||||||
|
chatRunBuffers: Map<string, string>;
|
||||||
|
chatDeltaSentAt: Map<string, number>;
|
||||||
|
chatAbortedRuns: Map<string, number>;
|
||||||
|
removeChatRun: (...args: unknown[]) => { sessionKey: string; clientRunId: string } | undefined;
|
||||||
|
agentRunSeq: Map<string, number>;
|
||||||
|
broadcast: (...args: unknown[]) => void;
|
||||||
|
nodeSendToSession: (...args: unknown[]) => void;
|
||||||
|
logGateway: { warn: (...args: unknown[]) => void };
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ChatAbortRespondMock = Mock<RespondFn>;
|
||||||
|
|
||||||
|
export function createChatAbortContext(
|
||||||
|
overrides: Record<string, unknown> = {},
|
||||||
|
): ChatAbortTestContext {
|
||||||
return {
|
return {
|
||||||
chatAbortControllers: new Map(),
|
chatAbortControllers: new Map(),
|
||||||
chatRunBuffers: new Map(),
|
chatRunBuffers: new Map(),
|
||||||
|
|
@ -39,7 +56,7 @@ export function createChatAbortContext(overrides: Record<string, unknown> = {})
|
||||||
|
|
||||||
export async function invokeChatAbortHandler(params: {
|
export async function invokeChatAbortHandler(params: {
|
||||||
handler: GatewayRequestHandler;
|
handler: GatewayRequestHandler;
|
||||||
context: ReturnType<typeof createChatAbortContext>;
|
context: ChatAbortTestContext;
|
||||||
request: { sessionKey: string; runId?: string };
|
request: { sessionKey: string; runId?: string };
|
||||||
client?: {
|
client?: {
|
||||||
connId?: string;
|
connId?: string;
|
||||||
|
|
@ -48,8 +65,8 @@ export async function invokeChatAbortHandler(params: {
|
||||||
scopes?: string[];
|
scopes?: string[];
|
||||||
};
|
};
|
||||||
} | null;
|
} | null;
|
||||||
respond?: ReturnType<typeof vi.fn>;
|
respond?: ChatAbortRespondMock;
|
||||||
}) {
|
}): Promise<ChatAbortRespondMock> {
|
||||||
const respond = params.respond ?? vi.fn();
|
const respond = params.respond ?? vi.fn();
|
||||||
await params.handler({
|
await params.handler({
|
||||||
params: params.request,
|
params: params.request,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue