From 1797bec7ef58bc14e7287e73d008878688e20384 Mon Sep 17 00:00:00 2001 From: Christopher Date: Wed, 29 Apr 2026 11:02:06 +1000 Subject: [PATCH] fix(cli): remove before_session hook color Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- packages/core/src/evaluation/hooks.ts | 5 +--- packages/core/test/evaluation/hooks.test.ts | 30 +++++++++++++++++++-- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/packages/core/src/evaluation/hooks.ts b/packages/core/src/evaluation/hooks.ts index 802f4ba9..d8a58cfc 100644 --- a/packages/core/src/evaluation/hooks.ts +++ b/packages/core/src/evaluation/hooks.ts @@ -27,9 +27,6 @@ import { spawnSync } from 'node:child_process'; -const ANSI_YELLOW = ''; -const ANSI_RESET = ''; - /** * Parse env var lines from hook stdout. * @@ -86,7 +83,7 @@ export function runBeforeSessionHook(command: string): void { const shell = isWindows ? 'cmd' : 'sh'; const shellFlag = isWindows ? '/c' : '-c'; - console.log(`${ANSI_YELLOW}Running before_session hook: ${command}${ANSI_RESET}`); + console.log(`Running before_session hook: ${command}`); const result = spawnSync(shell, [shellFlag, command], { encoding: 'utf8', diff --git a/packages/core/test/evaluation/hooks.test.ts b/packages/core/test/evaluation/hooks.test.ts index 802a4363..d082afc0 100644 --- a/packages/core/test/evaluation/hooks.test.ts +++ b/packages/core/test/evaluation/hooks.test.ts @@ -1,6 +1,6 @@ -import { describe, expect, it } from 'bun:test'; +import { describe, expect, it, spyOn } from 'bun:test'; -import { parseEnvOutput } from '../../src/evaluation/hooks.js'; +import { parseEnvOutput, runBeforeSessionHook } from '../../src/evaluation/hooks.js'; describe('parseEnvOutput', () => { it('parses dotenv KEY=value lines', () => { @@ -62,3 +62,29 @@ describe('parseEnvOutput', () => { expect(parseEnvOutput('MY_KEY_123=hello')).toEqual({ MY_KEY_123: 'hello' }); }); }); + +describe('runBeforeSessionHook', () => { + it('logs hook startup without ANSI color codes', () => { + const envKey = 'AGENTV_TEST_BEFORE_SESSION_HOOK_COLOR'; + const originalValue = process.env[envKey]; + const command = `bun -e "process.stdout.write('${envKey}=plain\\n')"`; + const logSpy = spyOn(console, 'log').mockImplementation(() => {}); + + delete process.env[envKey]; + + try { + runBeforeSessionHook(command); + + expect(logSpy.mock.calls[0]?.[0]).toBe(`Running before_session hook: ${command}`); + expect(process.env[envKey]).toBe('plain'); + } finally { + logSpy.mockRestore(); + + if (originalValue === undefined) { + delete process.env[envKey]; + } else { + process.env[envKey] = originalValue; + } + } + }); +});