mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 01:13:29 +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 { 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 () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user