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