mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 16:02:32 +00:00
- Gracefully fall back to file-name summaries when staged diffs exceed node/ssh execution maxBuffer limits, preventing generation failures. - Split oversized diffs by file and allocate budget via water-filling, ensuring single huge files do not starve smaller human changes. - Clip truncated diff sections on line boundaries to avoid half-lines.
65 lines
2.1 KiB
TypeScript
65 lines
2.1 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { buildCommitMessagePrompt, splitGeneratedCommitMessage } from './commit-message-generation'
|
|
|
|
describe('buildCommitMessagePrompt', () => {
|
|
it('builds a prompt from staged context instead of asking the agent to inspect git', () => {
|
|
const prompt = buildCommitMessagePrompt(
|
|
{
|
|
branch: 'feature/commit-drafts',
|
|
stagedSummary: 'M\tsrc/main/ipc/filesystem.ts',
|
|
stagedPatch: 'diff --git a/src/main/ipc/filesystem.ts b/src/main/ipc/filesystem.ts\n+hello'
|
|
},
|
|
''
|
|
)
|
|
|
|
expect(prompt).toContain('Branch: feature/commit-drafts')
|
|
expect(prompt).toContain('Staged files:\nM\tsrc/main/ipc/filesystem.ts')
|
|
expect(prompt).toContain('Staged patch:\n```diff')
|
|
expect(prompt).toContain('+hello')
|
|
expect(prompt).toContain('Use only the staged changes below as context.')
|
|
expect(prompt).not.toContain('Additional user prompt:')
|
|
})
|
|
|
|
it('keeps a custom prompt in a separate bounded section', () => {
|
|
const prompt = buildCommitMessagePrompt(
|
|
{
|
|
branch: null,
|
|
stagedSummary: 'A\tREADME.md',
|
|
stagedPatch: '+docs'
|
|
},
|
|
'Use Conventional Commits.'
|
|
)
|
|
|
|
expect(prompt).toContain('Branch: (detached)')
|
|
expect(prompt).toContain('Additional user prompt:\nUse Conventional Commits.')
|
|
})
|
|
|
|
it('notes when the diff was omitted so the agent relies on the file list', () => {
|
|
const prompt = buildCommitMessagePrompt(
|
|
{
|
|
branch: 'feature/big-diff',
|
|
stagedSummary: 'A\thuge.jsonl',
|
|
stagedPatch: ''
|
|
},
|
|
''
|
|
)
|
|
|
|
expect(prompt).toContain('Staged files:\nA\thuge.jsonl')
|
|
expect(prompt).toContain('diff omitted — too large to read')
|
|
})
|
|
})
|
|
|
|
describe('splitGeneratedCommitMessage', () => {
|
|
it('normalizes subject and preserves body text', () => {
|
|
const result = splitGeneratedCommitMessage(
|
|
'Fix source control generation.\n\n- Move planning into main'
|
|
)
|
|
|
|
expect(result).toEqual({
|
|
subject: 'Fix source control generation',
|
|
body: '- Move planning into main',
|
|
message: 'Fix source control generation\n\n- Move planning into main'
|
|
})
|
|
})
|
|
})
|