test: stabilize sessions_send waits
This commit is contained in:
@@ -22,6 +22,20 @@ vi.mock("../config/config.js", async (importOriginal) => {
|
|||||||
|
|
||||||
import { createClawdbotTools } from "./clawdbot-tools.js";
|
import { createClawdbotTools } from "./clawdbot-tools.js";
|
||||||
|
|
||||||
|
const waitForCalls = async (
|
||||||
|
getCount: () => number,
|
||||||
|
count: number,
|
||||||
|
timeoutMs = 2000,
|
||||||
|
) => {
|
||||||
|
const start = Date.now();
|
||||||
|
while (getCount() < count) {
|
||||||
|
if (Date.now() - start > timeoutMs) {
|
||||||
|
throw new Error(`timed out waiting for ${count} calls`);
|
||||||
|
}
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
describe("sessions tools", () => {
|
describe("sessions tools", () => {
|
||||||
it("uses number (not integer) in tool schemas for Gemini compatibility", () => {
|
it("uses number (not integer) in tool schemas for Gemini compatibility", () => {
|
||||||
const tools = createClawdbotTools();
|
const tools = createClawdbotTools();
|
||||||
@@ -240,8 +254,18 @@ describe("sessions tools", () => {
|
|||||||
runId: "run-1",
|
runId: "run-1",
|
||||||
delivery: { status: "pending", mode: "announce" },
|
delivery: { status: "pending", mode: "announce" },
|
||||||
});
|
});
|
||||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
await waitForCalls(
|
||||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
() => calls.filter((call) => call.method === "agent").length,
|
||||||
|
4,
|
||||||
|
);
|
||||||
|
await waitForCalls(
|
||||||
|
() => calls.filter((call) => call.method === "agent.wait").length,
|
||||||
|
4,
|
||||||
|
);
|
||||||
|
await waitForCalls(
|
||||||
|
() => calls.filter((call) => call.method === "chat.history").length,
|
||||||
|
4,
|
||||||
|
);
|
||||||
|
|
||||||
const waitPromise = tool.execute("call6", {
|
const waitPromise = tool.execute("call6", {
|
||||||
sessionKey: "main",
|
sessionKey: "main",
|
||||||
@@ -255,8 +279,18 @@ describe("sessions tools", () => {
|
|||||||
delivery: { status: "pending", mode: "announce" },
|
delivery: { status: "pending", mode: "announce" },
|
||||||
});
|
});
|
||||||
expect(typeof (waited.details as { runId?: string }).runId).toBe("string");
|
expect(typeof (waited.details as { runId?: string }).runId).toBe("string");
|
||||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
await waitForCalls(
|
||||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
() => calls.filter((call) => call.method === "agent").length,
|
||||||
|
8,
|
||||||
|
);
|
||||||
|
await waitForCalls(
|
||||||
|
() => calls.filter((call) => call.method === "agent.wait").length,
|
||||||
|
8,
|
||||||
|
);
|
||||||
|
await waitForCalls(
|
||||||
|
() => calls.filter((call) => call.method === "chat.history").length,
|
||||||
|
8,
|
||||||
|
);
|
||||||
|
|
||||||
const agentCalls = calls.filter((call) => call.method === "agent");
|
const agentCalls = calls.filter((call) => call.method === "agent");
|
||||||
const waitCalls = calls.filter((call) => call.method === "agent.wait");
|
const waitCalls = calls.filter((call) => call.method === "agent.wait");
|
||||||
|
|||||||
Reference in New Issue
Block a user