|
| 1 | +import { expect, mock, test } from 'claude-code/testing' |
| 2 | +import type { On } from 'claude-code' |
| 3 | + |
| 4 | +const PROGRESS = 'mcp__savvy-progress__progress' |
| 5 | +const start = { cwd: '/repo', surface: 'terminal', isInteractive: true } as const |
| 6 | + |
| 7 | +// Stands in for the engine beneath the plugin and keeps the list of open panes. |
| 8 | +const engine = (on: On) => { |
| 9 | + const panes: { id: string; title?: string }[] = [] |
| 10 | + mock.clock(on) |
| 11 | + on('session.start', ($, e) => ({ cwd: e.cwd })) |
| 12 | + on('command.run', () => ({})) |
| 13 | + on('env.get', () => ({ value: undefined })) |
| 14 | + on('settings.read', () => ({ value: {} })) |
| 15 | + on('tool.register', () => ({ value: undefined })) |
| 16 | + on('command.register', () => ({ value: undefined })) |
| 17 | + on('session.usage', () => ({ value: { rateLimits: [] } })) |
| 18 | + on('ui.panes', () => ({ value: panes })) |
| 19 | + on('ui.open', ($, e) => { |
| 20 | + panes.push({ id: e.id, title: e.title }) |
| 21 | + return { value: { isPlaced: true } } |
| 22 | + }) |
| 23 | + on('ui.close', ($, e) => { |
| 24 | + panes.splice(0, panes.length, ...panes.filter(p => p.id !== e.id)) |
| 25 | + return { value: undefined } |
| 26 | + }) |
| 27 | + return panes |
| 28 | +} |
| 29 | + |
| 30 | +test('the progress tool labels the flow by phase and count', async ($, on) => { |
| 31 | + engine(on) |
| 32 | + await $.session.start(start) |
| 33 | + expect(String((await $.tool.call({ tool: PROGRESS, title: 'Add login' })).result)).toBe('ok: Plan') |
| 34 | + expect(String((await $.tool.call({ tool: PROGRESS, total: 4, done: 1, phase: 'delegate' })).result)).toBe('ok: Tasks 1/4') |
| 35 | + expect(String((await $.tool.call({ tool: PROGRESS, done: 3, phase: 'review' })).result)).toBe('ok: Review 3/4') |
| 36 | + expect(String((await $.tool.call({ tool: PROGRESS, finished: true })).result)).toBe('ok: Done') |
| 37 | +}) |
| 38 | + |
| 39 | +test('a new title starts a clean flow and done never exceeds total', async ($, on) => { |
| 40 | + engine(on) |
| 41 | + await $.session.start(start) |
| 42 | + await $.tool.call({ tool: PROGRESS, title: 'First', total: 5, done: 5, phase: 'delegate' }) |
| 43 | + expect(String((await $.tool.call({ tool: PROGRESS, title: 'Second', phase: 'delegate' })).result)).toBe('ok: Tasks 0 running') |
| 44 | + expect(String((await $.tool.call({ tool: PROGRESS, total: 2, done: 9 })).result)).toBe('ok: Tasks 2/2') |
| 45 | +}) |
| 46 | + |
| 47 | +test('/agents-info opens the panel and closes it again', async ($, on) => { |
| 48 | + const panes = engine(on) |
| 49 | + await $.session.start(start) |
| 50 | + expect((await $.command.run({ command: 'agents-info' })).text).toBe('Agents panel opened.') |
| 51 | + expect(panes.map(p => p.id)).toEqual(['savvy-agents']) |
| 52 | + expect((await $.command.run({ command: 'agents-info' })).text).toBe('Agents panel closed.') |
| 53 | + expect(panes.length).toBe(0) |
| 54 | +}) |
0 commit comments