Skip to content

Commit 7a1d5a8

Browse files
steipeteampagent
andauthored
test(cli): replace redundant ACP process cases (#122229)
Co-authored-by: Amp <[email protected]>
1 parent 73ae583 commit 7a1d5a8

2 files changed

Lines changed: 41 additions & 50 deletions

File tree

‎src/cli/acp-cli-exit.process.test.ts‎

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
// Process regression coverage for ACP help commands returning without loading runtime transports.
2-
import {
3-
execFile,
4-
spawn,
5-
spawnSync,
6-
type ChildProcessWithoutNullStreams,
7-
} from "node:child_process";
1+
// Process regression coverage for ACP bridge disconnect and startup-handshake exit paths.
2+
import { spawn, spawnSync, type ChildProcessWithoutNullStreams } from "node:child_process";
83
import { createServer } from "node:http";
94
import path from "node:path";
10-
import { promisify, stripVTControlCharacters } from "node:util";
5+
import { stripVTControlCharacters } from "node:util";
116
import { describe, expect, it } from "vitest";
127
import { type RawData, WebSocketServer } from "ws";
138
import {
@@ -16,7 +11,6 @@ import {
1611
} from "../state/openclaw-state-db.js";
1712
import { createOpenClawTestState } from "../test-utils/openclaw-test-state.js";
1813

19-
const execFileAsync = promisify(execFile);
2014
const CHILD_PROCESS_TIMEOUT_MS = 30_000;
2115

2216
const INITIALIZE_FRAME = {
@@ -126,46 +120,7 @@ function rawDataToText(data: RawData): string {
126120
}
127121

128122
describe("ACP CLI process exit", () => {
129-
it.each([
130-
{ args: ["acp", "--help"], usage: "Usage: openclaw acp [options] [command]" },
131-
{ args: ["acp", "client", "--help"], usage: "Usage: openclaw acp client [options]" },
132-
])(
133-
"exits promptly after $args",
134-
async ({ args, usage }) => {
135-
const state = await createPreparedAcpProcessState();
136-
try {
137-
const result = await execFileAsync(
138-
process.execPath,
139-
["--import", "tsx", "src/entry.ts", ...args],
140-
{
141-
cwd: path.resolve("."),
142-
encoding: "utf8",
143-
env: {
144-
...createAcpProcessEnv(state.env),
145-
NODE_OPTIONS: process.platform === "darwin" ? "--use-system-ca" : undefined,
146-
NODE_USE_SYSTEM_CA: undefined,
147-
},
148-
killSignal: "SIGKILL",
149-
timeout: CHILD_PROCESS_TIMEOUT_MS,
150-
},
151-
);
152-
153-
expect(withoutSqliteTransactionWarnings(result.stderr)).toBe("");
154-
expect(result.stdout).toContain(usage);
155-
} finally {
156-
await state.cleanup();
157-
}
158-
},
159-
CHILD_PROCESS_TIMEOUT_MS + 5_000,
160-
);
161-
162-
it.each([
163-
{ name: "empty stdin", input: "" },
164-
{
165-
name: "an initialize frame",
166-
input: `${JSON.stringify(INITIALIZE_FRAME)}\n`,
167-
},
168-
])("exits when the bridge starts with $name and the client disconnects", async ({ input }) => {
123+
it("exits when the client disconnects after sending an initialize frame", async () => {
169124
const state = await createPreparedAcpProcessState();
170125
try {
171126
const result = spawnSync(
@@ -175,7 +130,7 @@ describe("ACP CLI process exit", () => {
175130
cwd: path.resolve("."),
176131
encoding: "utf8",
177132
env: createAcpProcessEnv(state.env),
178-
input,
133+
input: `${JSON.stringify(INITIALIZE_FRAME)}\n`,
179134
killSignal: "SIGKILL",
180135
timeout: CHILD_PROCESS_TIMEOUT_MS,
181136
},

‎src/cli/help-exit.process.test.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,42 @@ describe("CLI help process exit", () => {
278278
expect(stdout).toContain(`Usage: openclaw ${usageCommand} [options] [command]`);
279279
},
280280
);
281+
282+
it.concurrent.each([
283+
{ args: ["acp", "--help"], usage: "Usage: openclaw acp [options] [command]" },
284+
{ args: ["acp", "client", "--help"], usage: "Usage: openclaw acp client [options]" },
285+
])("renders in-process ACP help for $args", async ({ args, usage }) => {
286+
let stdout = "";
287+
let stderr = "";
288+
let actionStarted = false;
289+
const program = new Command()
290+
.name("openclaw")
291+
.exitOverride()
292+
.configureOutput({
293+
writeOut: (value) => {
294+
stdout += value;
295+
},
296+
writeErr: (value) => {
297+
stderr += value;
298+
},
299+
});
300+
program.hook("preAction", () => {
301+
actionStarted = true;
302+
});
303+
const argv = ["node", "openclaw", ...args];
304+
305+
const registered = await registerSubCliByName(program, "acp", argv);
306+
const parseResult = await program
307+
.parseAsync(argv.slice(2), { from: "user" })
308+
.catch((cause: unknown) => cause);
309+
310+
expect(registered).toBe(true);
311+
expect(parseResult).toBeInstanceOf(CommanderError);
312+
expect(parseResult).toMatchObject({ code: "commander.helpDisplayed", exitCode: 0 });
313+
expect(stderr).toBe("");
314+
expect(stdout.split(/\r?\n/u).find((line) => line.startsWith("Usage:"))).toBe(usage);
315+
expect(actionStarted).toBe(false);
316+
});
281317
});
282318

283319
describe("JSON console style process output", () => {

0 commit comments

Comments
 (0)