Skip to content

Commit e52b56e

Browse files
committed
test(io): run exec test scripts from files for win32 compatibility
runCommand spawns through cmd.exe on Windows (shell: true for PATHEXT resolution), which mangles the quoting of node -e one-liners — the 'boom; exit 3' script never ran, so the process exited 0 and the rejection assertion failed. Write the scripts to temp files instead.
1 parent 82b644d commit e52b56e

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

src/io/exec.test.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1-
import { describe, expect, test } from "bun:test";
1+
import { afterAll, describe, expect, test } from "bun:test";
2+
import { mkdtemp, rm, writeFile } from "node:fs/promises";
3+
import { tmpdir } from "node:os";
4+
import { join } from "node:path";
25
import { CommandFailedError, MissingToolError, requireTool, runCommand, toolOnPath } from "./exec";
36

7+
// Scripts run from files rather than `node -e` one-liners: on win32 runCommand
8+
// spawns through cmd.exe (for PATHEXT resolution), which mangles quoted args.
9+
const scriptsDir = await mkdtemp(join(tmpdir(), "agentcore-exec-"));
10+
async function script(name: string, source: string): Promise<string> {
11+
const path = join(scriptsDir, name);
12+
await writeFile(path, source);
13+
return path;
14+
}
15+
16+
afterAll(() => rm(scriptsDir, { recursive: true, force: true }));
17+
418
describe("toolOnPath", () => {
519
test("finds a tool that exists", () => {
620
// node is guaranteed present: it's running this test suite's runtime deps.
@@ -28,8 +42,9 @@ describe("requireTool", () => {
2842

2943
describe("runCommand", () => {
3044
test("resolves on exit 0 and streams output to onOutput", async () => {
45+
const succeeding = await script("succeed.js", "console.log('hello')");
3146
const chunks: string[] = [];
32-
await runCommand(["node", "-e", "console.log('hello')"], {
47+
await runCommand(["node", succeeding], {
3348
cwd: process.cwd(),
3449
onOutput: (chunk) => chunks.push(chunk),
3550
});
@@ -38,8 +53,8 @@ describe("runCommand", () => {
3853
});
3954

4055
test("rejects with CommandFailedError carrying output and exit code", async () => {
41-
const command = ["node", "-e", "console.error('boom'); process.exit(3)"];
42-
const promise = runCommand(command, { cwd: process.cwd() });
56+
const failing = await script("fail.js", "console.error('boom'); process.exit(3)");
57+
const promise = runCommand(["node", failing], { cwd: process.cwd() });
4358

4459
await expect(promise).rejects.toBeInstanceOf(CommandFailedError);
4560
await expect(promise).rejects.toThrow(/exit code 3/);

0 commit comments

Comments
 (0)