





















@@ -23,21 +23,6 @@ function currentNodeEvalCommand(source: string): string {
2323return process.platform === "win32" ? `& ${node} -e ${script}` : `${node} -e ${script}`;
2424}
252526-async function runPtyCommand(command: string) {
27-const handle = await runExecProcess({
28- command,
29-workdir: process.cwd(),
30-env: currentEnv(),
31-usePty: true,
32-warnings: [],
33-maxOutput: 20_000,
34-pendingMaxOutput: 20_000,
35-notifyOnExit: false,
36-timeoutSec: 5,
37-});
38-return await handle.promise;
39-}
40-4126async function startPtySession(command: string) {
4227const processTool = createProcessTool();
4328const run = await runExecProcess({
@@ -58,8 +43,11 @@ async function startPtySession(command: string) {
5843async function waitForSessionCompletion(params: {
5944processTool: ReturnType<typeof createProcessTool>;
6045sessionId: string;
61-expectedText: string;
46+expectedText: string | string[];
6247}) {
48+const expectedTexts = Array.isArray(params.expectedText)
49+ ? params.expectedText
50+ : [params.expectedText];
6351await expect
6452.poll(
6553async () => {
@@ -72,7 +60,9 @@ async function waitForSessionCompletion(params: {
7260return false;
7361}
7462expect(details.status).toBe("completed");
75-expect(details.aggregated ?? "").toContain(params.expectedText);
63+for (const expectedText of expectedTexts) {
64+expect(details.aggregated ?? "").toContain(expectedText);
65+}
7666return true;
7767},
7868{
@@ -83,20 +73,22 @@ async function waitForSessionCompletion(params: {
8373.toBe(true);
8474}
857586-test("exec supports pty output and OPENCLAW_SHELL", async () => {
87-const result = await runPtyCommand(
88-currentNodeEvalCommand('process.stdout.write(`ok:${process.env.OPENCLAW_SHELL || ""}`)'),
89-);
90-91-expect(result.status).toBe("completed");
92-expect(result.aggregated).toContain("ok");
93-expect(result.aggregated).toContain("exec");
94-});
95-96-test("process send-keys and submit send Enter for pty sessions", async () => {
76+test("exec supports pty output, OPENCLAW_SHELL, send-keys, and submit", async () => {
9777const { processTool, sessionId } = await startPtySession(
9878currentNodeEvalCommand(
99-"const dataEvent=String.fromCharCode(100,97,116,97);const submitted=String.fromCharCode(115,117,98,109,105,116,116,101,100);let first=false;process.stdin.on(dataEvent,d=>{process.stdout.write(d);if(d.includes(10)||d.includes(13)){if(first){process.stdout.write(submitted);process.exit(0);}first=true;}});",
79+[
80+"process.stdout.write(`ok:${process.env.OPENCLAW_SHELL || ''}`);",
81+"const dataEvent=String.fromCharCode(100,97,116,97);",
82+"const submitted=String.fromCharCode(115,117,98,109,105,116,116,101,100);",
83+"let first=false;",
84+"process.stdin.on(dataEvent,d=>{",
85+"process.stdout.write(d);",
86+"if(d.includes(10)||d.includes(13)){",
87+"if(first){process.stdout.write(submitted);process.exit(0);}",
88+"first=true;",
89+"}",
90+"});",
91+].join(""),
10092),
10193);
10294@@ -111,5 +103,9 @@ test("process send-keys and submit send Enter for pty sessions", async () => {
111103 sessionId,
112104});
113105114-await waitForSessionCompletion({ processTool, sessionId, expectedText: "submitted" });
106+await waitForSessionCompletion({
107+ processTool,
108+ sessionId,
109+expectedText: ["submitted", "ok", "exec"],
110+});
115111});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。