From eafcac1593942a068d11538c3983a243cf67306a Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sat, 7 Feb 2026 17:39:16 +0900 Subject: [PATCH] fix: address cubic 4/5 review issues - Preserve encoding/callback args in stdout.write wrapper (json-output.ts) - Restore global console spy in afterEach (server-connection.test.ts) - Restore console.error spy in afterEach (on-complete-hook.test.ts) --- src/cli/run/json-output.ts | 6 +++--- src/cli/run/on-complete-hook.test.ts | 10 ++++++++-- src/cli/run/server-connection.test.ts | 6 ++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/cli/run/json-output.ts b/src/cli/run/json-output.ts index 8ec58314..a4b2e109 100644 --- a/src/cli/run/json-output.ts +++ b/src/cli/run/json-output.ts @@ -20,9 +20,9 @@ export function createJsonOutputManager( const originalWrite = stdout.write.bind(stdout) function redirectToStderr(): void { - stdout.write = function (chunk: string): boolean { - return stderr.write(chunk) - } + stdout.write = function (...args: Parameters): boolean { + return (stderr.write as Function).apply(stderr, args) + } as NodeJS.WriteStream["write"] } function restore(): void { diff --git a/src/cli/run/on-complete-hook.test.ts b/src/cli/run/on-complete-hook.test.ts index ec28f428..e050473d 100644 --- a/src/cli/run/on-complete-hook.test.ts +++ b/src/cli/run/on-complete-hook.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, spyOn, beforeEach } from "bun:test" +import { describe, it, expect, spyOn, beforeEach, afterEach } from "bun:test" import { executeOnCompleteHook } from "./on-complete-hook" describe("executeOnCompleteHook", () => { @@ -9,8 +9,14 @@ describe("executeOnCompleteHook", () => { } as unknown as ReturnType } + let consoleErrorSpy: ReturnType> + beforeEach(() => { - spyOn(console, "error").mockImplementation(() => {}) + consoleErrorSpy = spyOn(console, "error").mockImplementation(() => {}) + }) + + afterEach(() => { + consoleErrorSpy.mockRestore() }) it("executes command with correct env vars", async () => { diff --git a/src/cli/run/server-connection.test.ts b/src/cli/run/server-connection.test.ts index 5a4e8842..100154a0 100644 --- a/src/cli/run/server-connection.test.ts +++ b/src/cli/run/server-connection.test.ts @@ -1,5 +1,7 @@ import { describe, it, expect, mock, beforeEach, afterEach } from "bun:test" +const originalConsole = globalThis.console + const mockServerClose = mock(() => {}) const mockCreateOpencode = mock(() => Promise.resolve({ @@ -36,6 +38,10 @@ describe("createServerConnection", () => { globalThis.console = { ...console, log: mockConsoleLog } as typeof console }) + afterEach(() => { + globalThis.console = originalConsole + }) + it("attach mode returns client with no-op cleanup", async () => { // given const signal = new AbortController().signal