perf(test): replace send-keys session polling loop

This commit is contained in:
Peter Steinberger
2026-02-18 17:57:48 +00:00
parent cd8eb079e3
commit 6f273d5e2a

View File

@@ -1,5 +1,4 @@
import { afterEach, expect, test } from "vitest"; import { afterEach, expect, test } from "vitest";
import { sleep } from "../utils.js";
import { resetProcessRegistryForTests } from "./bash-process-registry.js"; import { resetProcessRegistryForTests } from "./bash-process-registry.js";
import { createExecTool } from "./bash-tools.exec.js"; import { createExecTool } from "./bash-tools.exec.js";
import { createProcessTool } from "./bash-tools.process.js"; import { createProcessTool } from "./bash-tools.process.js";
@@ -28,22 +27,27 @@ async function waitForSessionCompletion(params: {
sessionId: string; sessionId: string;
expectedText: string; expectedText: string;
}) { }) {
const deadline = Date.now() + (process.platform === "win32" ? 4000 : 2000); await expect
while (Date.now() < deadline) { .poll(
await sleep(50); async () => {
const poll = await params.processTool.execute("toolcall", { const poll = await params.processTool.execute("toolcall", {
action: "poll", action: "poll",
sessionId: params.sessionId, sessionId: params.sessionId,
}); });
const details = poll.details as { status?: string; aggregated?: string }; const details = poll.details as { status?: string; aggregated?: string };
if (details.status !== "running") { if (details.status === "running") {
expect(details.status).toBe("completed"); return false;
expect(details.aggregated ?? "").toContain(params.expectedText); }
return; expect(details.status).toBe("completed");
} expect(details.aggregated ?? "").toContain(params.expectedText);
} return true;
},
throw new Error(`PTY session did not exit after ${params.expectedText}`); {
timeout: process.platform === "win32" ? 4000 : 2000,
interval: 50,
},
)
.toBe(true);
} }
test("process send-keys encodes Enter for pty sessions", async () => { test("process send-keys encodes Enter for pty sessions", async () => {