diff --git a/AGENTS.md b/AGENTS.md index 4256a3c75..4ca7d7e8b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -250,6 +250,15 @@ wait This does not apply to lightweight LLM-only targets (azure, openai, gemini, openrouter) which can run with higher concurrency. +### Writing Tests + +Tests should be lean and focused on what matters. Follow these principles: + +- **Only test new or changed behavior.** Don't write tests for existing behavior that's already covered by the 1600+ core tests. If you fix a bug, test the fix and its edge cases — not the surrounding module. +- **One test per distinct behavior.** Don't write separate tests for trivially different inputs that exercise the same code path. +- **No tests for obvious code.** If a function returns `undefined` for missing input and that's a one-line null check, you don't need a test for it unless it's a regression risk. +- **Regression tests > comprehensive tests.** A test that would have caught the bug is worth more than five tests that exercise happy paths. + ### Verifying Evaluator Changes Unit tests alone are insufficient for evaluator changes. After implementing or modifying evaluators: diff --git a/packages/core/src/evaluation/formatting/segment-formatter.ts b/packages/core/src/evaluation/formatting/segment-formatter.ts index 8596a947f..666ac857a 100644 --- a/packages/core/src/evaluation/formatting/segment-formatter.ts +++ b/packages/core/src/evaluation/formatting/segment-formatter.ts @@ -54,9 +54,13 @@ export function formatSegment( return undefined; } - // Agent mode: return file reference only + // Agent mode: return file reference with absolute path so agents can locate + // the file regardless of their working directory. resolvedPath is set by + // message-processor.ts during file resolution; fall back to the display + // path when it is absent (e.g. in unit tests with synthetic segments). if (mode === 'agent') { - return ``; + const absolutePath = asString(segment.resolvedPath) ?? filePath; + return ``; } // LM mode: return embedded content with XML tags diff --git a/packages/core/test/evaluation/formatting/segment-formatter.test.ts b/packages/core/test/evaluation/formatting/segment-formatter.test.ts new file mode 100644 index 000000000..d44642b02 --- /dev/null +++ b/packages/core/test/evaluation/formatting/segment-formatter.test.ts @@ -0,0 +1,20 @@ +import { describe, expect, it } from 'bun:test'; + +import { formatSegment } from '../../../src/evaluation/formatting/segment-formatter.js'; + +describe('formatSegment agent mode file paths', () => { + it('uses resolvedPath (absolute) when available', () => { + const segment = { + type: 'file', + path: 'snippets/data.csv', + text: 'content', + resolvedPath: '/abs/path/to/snippets/data.csv', + }; + expect(formatSegment(segment, 'agent')).toBe(''); + }); + + it('falls back to display path when resolvedPath is absent', () => { + const segment = { type: 'file', path: 'snippets/data.csv', text: 'content' }; + expect(formatSegment(segment, 'agent')).toBe(''); + }); +});