Open History to see the last commit
1import { test } from 'node:test';
2import assert from 'node:assert/strict';
3import { createProgressReporter, publicProgressText } from '../src/progress.ts';
4
5test('only public assistant text accompanying work is eligible for progress', () => {
6 assert.equal(publicProgressText({ role: 'assistant', content: [{ type: 'thinking', text: 'private reasoning' }, { type: 'text', text: 'I’m adding touch controls.' }, { type: 'toolCall', name: 'edit', arguments: { source: 'secret' } }] }), 'I’m adding touch controls.');
7 for (const content of [[{ type: 'thinking', text: 'private' }], [{ type: 'text', text: 'Ready.' }], [{ type: 'text', text: 'Which color?' }, { type: 'toolCall', name: 'ask_user' }], [{ type: 'text', text: '```code```' }, { type: 'toolCall', name: 'write' }]]) assert.equal(publicProgressText({ role: 'assistant', content }), null);
8});
9
10test('progress preserves order, deduplicates activity, bounds noise, and stops after lost ownership', async () => {
11 const updates: Array<{ eventId: string; content: string; stage: string }> = [];
12 const reporter = createProgressReporter(async input => { updates.push(input); }, () => assert.fail('Unexpected invalidation'));
13 reporter.report('Thinking about your app.', 'thinking'); reporter.tool('read'); reporter.tool('read'); reporter.tool('edit'); reporter.tool('build_candidate');
14 await reporter.flush();
15 assert.equal(updates.length, 4); assert.equal(reporter.phase, 'Checking the app');
16 assert.equal(new Set(updates.map(update => update.eventId)).size, 4);
17 for (let index = 0; index < 40; index++) reporter.report(`Step ${index}`);
18 await reporter.flush(); assert.equal(updates.length, 24);
19 reporter.close(); reporter.report('Too late'); await reporter.flush(); assert.equal(updates.length, 24);
20 let invalidated = 0, requests = 0;
21 const stale = createProgressReporter(async () => { requests++; throw Object.assign(new Error('Stopped'), { status: 409 }); }, () => { invalidated++; });
22 stale.report('One'); stale.report('Two'); await stale.flush();
23 assert.equal(invalidated, 1); assert.equal(requests, 1);
24});