Skip to content

Commit 7d6df6a

Browse files
wings1029claude
andcommitted
fix(agent-core): address review — hoist-safe mock and curly lint
- Use vi.hoisted pattern for spawnMock to fix ReferenceError in CI - Wrap one-line if guard in braces per repo curly rule Co-Authored-By: Claude <[email protected]>
1 parent 6d527ac commit 7d6df6a

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

packages/agent-core/src/harness/env/nodejs.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import { PassThrough } from "node:stream";
44
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
55
import { NodeExecutionEnv, resolveExecTimeoutMs } from "./nodejs.js";
66

7-
let spawnMock: ReturnType<typeof vi.fn>;
7+
const { spawnMock } = vi.hoisted(() => ({ spawnMock: vi.fn() }));
88

9-
vi.mock("node:child_process", () => {
10-
spawnMock = vi.fn();
11-
return { spawn: spawnMock };
12-
});
9+
vi.mock("node:child_process", () => ({
10+
spawn: spawnMock,
11+
}));
1312

1413
afterEach(() => {
1514
vi.clearAllMocks();

packages/agent-core/src/harness/env/nodejs.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,9 @@ export class NodeExecutionEnv implements ExecutionEnv {
375375
// child exits before all pipe data is consumed). Without listeners,
376376
// Node.js throws an uncaught exception that crashes the process.
377377
const onStreamError = (stream: "stdout" | "stderr", error: Error) => {
378-
if (settled) return;
378+
if (settled) {
379+
return;
380+
}
379381
onAbort();
380382
settle(
381383
err(new ExecutionError("spawn_error", `${stream} read error: ${error.message}`, error)),

0 commit comments

Comments
 (0)