diff --git a/test/fixtures/sources/README.md b/test/fixtures/sources/README.md new file mode 100644 index 0000000..afd835b --- /dev/null +++ b/test/fixtures/sources/README.md @@ -0,0 +1,3 @@ +# Source fixtures + +This file is intentionally not a review target. diff --git a/test/fixtures/sources/example.go b/test/fixtures/sources/example.go new file mode 100644 index 0000000..38dd16d --- /dev/null +++ b/test/fixtures/sources/example.go @@ -0,0 +1,3 @@ +package main + +func main() {} diff --git a/test/fixtures/sources/example.py b/test/fixtures/sources/example.py new file mode 100644 index 0000000..e3010cc --- /dev/null +++ b/test/fixtures/sources/example.py @@ -0,0 +1,2 @@ +def greet(name: str) -> str: + return f"Hello, {name}" diff --git a/test/sources.test.mjs b/test/sources.test.mjs index 287ebe9..36689d4 100644 --- a/test/sources.test.mjs +++ b/test/sources.test.mjs @@ -2,6 +2,41 @@ import assert from 'node:assert/strict' import test from 'node:test' import { loadTargets } from '../dist/agents/code-review/sources.js' +test('local source directories normalize supported files and ignore Markdown', async () => { + const targets = await loadTargets({ kind: 'paths', paths: ['test/fixtures/sources'] }) + const byFile = new Map(targets.map((target) => [target.file, target])) + + assert.deepEqual([...byFile.keys()].sort(), [ + 'test/fixtures/sources/example.go', + 'test/fixtures/sources/example.py', + ]) + assert.equal(byFile.get('test/fixtures/sources/example.go')?.language, 'go') + assert.equal(byFile.get('test/fixtures/sources/example.py')?.language, 'py') + assert.equal(byFile.get('test/fixtures/sources/example.go')?.isChanged, false) + assert.equal(byFile.get('test/fixtures/sources/example.py')?.isChanged, false) + assert.equal( + byFile.get('test/fixtures/sources/example.go')?.fullContent, + 'package main\n\nfunc main() {}\n', + ) + assert.equal( + byFile.get('test/fixtures/sources/example.py')?.fullContent, + 'def greet(name: str) -> str:\n return f"Hello, {name}"\n', + ) +}) + +test('stdin source normalization derives Python language and marks the target changed', async () => { + const [target] = await loadTargets({ + kind: 'stdin', + filename: 'example.py', + content: 'print("hello")\n', + }) + + assert.equal(target?.language, 'py') + assert.equal(target?.isChanged, true) + assert.equal(target?.file, 'example.py') + assert.equal(target?.fullContent, 'print("hello")\n') +}) + test('GitHub PR ingestion fails when a reviewable file cannot be loaded', async () => { const originalFetch = globalThis.fetch globalThis.fetch = async (url) => {