Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions packages/core/src/evaluation/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@

import { spawnSync } from 'node:child_process';

const ANSI_YELLOW = '';
const ANSI_RESET = '';

/**
* Parse env var lines from hook stdout.
*
Expand Down Expand Up @@ -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',
Expand Down
30 changes: 28 additions & 2 deletions packages/core/test/evaluation/hooks.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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;
}
}
});
});
Loading