repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by bugabinga
pi/agent/extensions/prune/__tests__/format.test.ts
RawFile outline
- emptyData line 5
- format line 16
- renders spec section headers and prune_recall footer line 17
- caps transcript tail line 39
- renders recall note once line 52
- renders assistant text, tool without cmd, and errors line 59
- caps long file lists and omits token estimate when unavailable line 72
- formats small token estimates without k suffix line 81
import { describe, expect, it } from 'bun:test';
import { format } from '../src/format.ts';
import type { ExtractOutput } from '../src/types.ts';
function emptyData(): ExtractOutput {
return {
goals: [],
scopeChanges: [],
files: { modified: new Set(), created: new Set(), read: new Set() },
context: [],
preferences: [],
transcript: [],
};
}
describe('format', () => {
it('renders spec section headers and prune_recall footer', () => {
const data = emptyData();
data.goals.push('Fix the auth bug');
data.scopeChanges.push('also update token refresh logic');
data.files.modified.add('session.ts');
data.context.push('lint still failing');
data.preferences.push('Prefer TypeScript strict mode');
data.transcript.push({ role: 'user', text: 'Fix the auth bug', ref: '#1' });
const out = format(data, { sourceEntriesProcessed: 10, tailKept: 3, tokenEstimate: 18900 }).summary;
expect(out).toContain('[Session Goal]');
expect(out).toContain('- [Scope change]');
expect(out).toContain('[Files And Changes]');
expect(out).toContain('[Outstanding Context]');
expect(out).toContain('[User Preferences]');
expect(out).toContain('[user]\nFix the auth bug (#1)');
expect(out).toContain('prune: 10 source entries processed; tail kept 3 (~18.9k tok)');
expect(out).toContain('Use prune_recall');
expect(out).not.toContain('vcc_recall');
});
it('caps transcript tail', () => {
const data = emptyData();
for (let i = 1; i <= 5; i++) {
data.transcript.push({ role: 'user', text: `message ${i}`, ref: `#${i}` });
}
const out = format(data, { transcriptLimit: 2 }).summary;
expect(out).toContain('...(3 earlier lines omitted)');
expect(out).not.toContain('message 1 (#1)');
expect(out).toContain('message 4 (#4)');
expect(out).toContain('message 5 (#5)');
});
it('renders recall note once', () => {
const data = emptyData();
data.transcript.push({ role: 'user', text: 'hello', ref: '#1' });
const out = format(data).summary;
expect(out.match(/Use prune_recall/g)?.length).toBe(1);
});
it('renders assistant text, tool without cmd, and errors', () => {
const data = emptyData();
data.transcript.push(
{ role: 'assistant', text: 'Done', ref: '#2' },
{ role: 'assistant', text: '', tool: 'bash', ref: '#3' },
{ role: 'error', text: '[ERROR] bash', ref: '#4' },
);
const out = format(data).summary;
expect(out).toContain('[assistant]\nDone (#2)');
expect(out).toContain('* bash (#3)');
expect(out).toContain('[tool_error] [ERROR] bash (#4)');
});
it('caps long file lists and omits token estimate when unavailable', () => {
const data = emptyData();
for (let i = 0; i < 12; i++) data.files.modified.add(`file${i}.ts`);
const out = format(data, { sourceEntriesProcessed: 12, tailKept: 0 }).summary;
expect(out).toContain('(+2 more)');
expect(out).toContain('prune: 12 source entries processed; tail kept 0');
expect(out).not.toContain('tok)');
});
it('formats small token estimates without k suffix', () => {
const data = emptyData();
const out = format(data, { sourceEntriesProcessed: 1, tailKept: 0, tokenEstimate: 999 }).summary;
expect(out).toContain('(~999 tok)');
});
});