mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 16:18:26 +00:00
perf(test): replace send-keys session polling loop
This commit is contained in:
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user