mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-22 06:08:13 +00:00
test: use vi wait helper in task registry
This commit is contained in:
@@ -105,7 +105,8 @@ function createChatFinalEvent(sessionKey: string): EventFrame {
|
||||
}
|
||||
|
||||
async function expectOversizedPromptRejected(params: { sessionId: string; text: string }) {
|
||||
const request = vi.fn(async () => ({ ok: true })) as GatewayClient["request"];
|
||||
const requestMock = vi.fn(async (_method: string) => ({ ok: true }));
|
||||
const request = requestMock as GatewayClient["request"];
|
||||
const sessionStore = createInMemorySessionStore();
|
||||
const agent = new AcpGatewayAgent(createAcpConnection(), createAcpGateway(request), {
|
||||
sessionStore,
|
||||
@@ -115,7 +116,7 @@ async function expectOversizedPromptRejected(params: { sessionId: string; text:
|
||||
await expect(agent.prompt(createPromptRequest(params.sessionId, params.text))).rejects.toThrow(
|
||||
/maximum allowed size/i,
|
||||
);
|
||||
expect(request.mock.calls.some(([method]) => method === "chat.send")).toBe(false);
|
||||
expect(requestMock.mock.calls.some(([method]) => method === "chat.send")).toBe(false);
|
||||
const session = sessionStore.getSession(params.sessionId);
|
||||
expect(session?.activeRunId).toBeNull();
|
||||
expect(session?.abortController).toBeNull();
|
||||
@@ -690,7 +691,7 @@ describe("acp setSessionConfigOption bridge behavior", () => {
|
||||
it("accepts forwarded timeout config options without failing OpenClaw ACP bridge turns", async () => {
|
||||
const sessionStore = createInMemorySessionStore();
|
||||
const connection = createAcpConnection();
|
||||
const request = vi.fn(async (method: string) => {
|
||||
const requestMock = vi.fn(async (method: string) => {
|
||||
if (method === "sessions.list") {
|
||||
return {
|
||||
ts: Date.now(),
|
||||
@@ -715,7 +716,8 @@ describe("acp setSessionConfigOption bridge behavior", () => {
|
||||
}
|
||||
expect(method).not.toBe("sessions.patch");
|
||||
return { ok: true };
|
||||
}) as GatewayClient["request"];
|
||||
});
|
||||
const request = requestMock as GatewayClient["request"];
|
||||
const agent = new AcpGatewayAgent(connection, createAcpGateway(request), {
|
||||
sessionStore,
|
||||
});
|
||||
@@ -727,7 +729,7 @@ describe("acp setSessionConfigOption bridge behavior", () => {
|
||||
);
|
||||
expect(Array.isArray(result.configOptions)).toBe(true);
|
||||
|
||||
expect(request.mock.calls.some(([method]) => method === "sessions.patch")).toBe(false);
|
||||
expect(requestMock.mock.calls.some(([method]) => method === "sessions.patch")).toBe(false);
|
||||
|
||||
sessionStore.clearAllSessionsForTest();
|
||||
});
|
||||
|
||||
@@ -233,7 +233,9 @@ describe("acp translator stop reason mapping", () => {
|
||||
const request = vi.fn(async (method: string, params?: Record<string, unknown>) => {
|
||||
if (method === "chat.send") {
|
||||
const runId = params?.idempotencyKey;
|
||||
expect(typeof runId).toBe("string");
|
||||
if (typeof runId !== "string") {
|
||||
throw new Error("expected chat.send idempotency key");
|
||||
}
|
||||
chatRunId = runId;
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -243,18 +243,7 @@ function createAcpSessionStoreEntry(params: {
|
||||
}
|
||||
|
||||
async function waitForAssertion(assertion: () => void, timeoutMs = 2_000, stepMs = 5) {
|
||||
const startedAt = Date.now();
|
||||
for (;;) {
|
||||
try {
|
||||
assertion();
|
||||
return;
|
||||
} catch (error) {
|
||||
if (Date.now() - startedAt >= timeoutMs) {
|
||||
throw error;
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, stepMs));
|
||||
}
|
||||
}
|
||||
await vi.waitFor(assertion, { timeout: timeoutMs, interval: stepMs });
|
||||
}
|
||||
|
||||
async function flushAsyncWork(times = 4) {
|
||||
|
||||
Reference in New Issue
Block a user