|
| 1 | +import { describe, expect, test } from 'bun:test' |
| 2 | +import type { Task } from '../../../utils/tasks.js' |
| 3 | +import { |
| 4 | + buildContinuationPrompt, |
| 5 | + buildUnfinishedTaskNotice, |
| 6 | +} from '../taskAnchorReminder.js' |
| 7 | + |
| 8 | +function task(partial: Partial<Task> & Pick<Task, 'id' | 'status'>): Task { |
| 9 | + return { |
| 10 | + subject: `Task ${partial.id}`, |
| 11 | + description: '', |
| 12 | + blocks: [], |
| 13 | + blockedBy: [], |
| 14 | + ...partial, |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +describe('buildContinuationPrompt', () => { |
| 19 | + test('returns null when there are no unfinished tasks', () => { |
| 20 | + expect(buildContinuationPrompt([])).toBeNull() |
| 21 | + expect( |
| 22 | + buildContinuationPrompt([ |
| 23 | + task({ id: '1', status: 'completed' }), |
| 24 | + task({ id: '2', status: 'completed' }), |
| 25 | + ]), |
| 26 | + ).toBeNull() |
| 27 | + }) |
| 28 | + |
| 29 | + test('picks the in_progress task over pending ones', () => { |
| 30 | + const prompt = buildContinuationPrompt([ |
| 31 | + task({ id: '1', status: 'pending', subject: 'first' }), |
| 32 | + task({ id: '2', status: 'in_progress', subject: 'second' }), |
| 33 | + ]) |
| 34 | + expect(prompt).toBe('按计划继续 Task #2 second') |
| 35 | + }) |
| 36 | + |
| 37 | + test('among same status picks the lowest numeric id', () => { |
| 38 | + const prompt = buildContinuationPrompt([ |
| 39 | + task({ id: '10', status: 'pending', subject: 'ten' }), |
| 40 | + task({ id: '2', status: 'pending', subject: 'two' }), |
| 41 | + ]) |
| 42 | + expect(prompt).toBe('按计划继续 Task #2 two') |
| 43 | + }) |
| 44 | + |
| 45 | + test('ignores completed tasks when picking', () => { |
| 46 | + const prompt = buildContinuationPrompt([ |
| 47 | + task({ id: '1', status: 'completed', subject: 'done' }), |
| 48 | + task({ id: '3', status: 'pending', subject: 'todo' }), |
| 49 | + ]) |
| 50 | + expect(prompt).toBe('按计划继续 Task #3 todo') |
| 51 | + }) |
| 52 | +}) |
| 53 | + |
| 54 | +describe('buildUnfinishedTaskNotice', () => { |
| 55 | + test('returns null when no task is in_progress', () => { |
| 56 | + expect(buildUnfinishedTaskNotice([])).toBeNull() |
| 57 | + expect( |
| 58 | + buildUnfinishedTaskNotice([ |
| 59 | + task({ id: '1', status: 'pending' }), |
| 60 | + task({ id: '2', status: 'completed' }), |
| 61 | + ]), |
| 62 | + ).toBeNull() |
| 63 | + }) |
| 64 | + |
| 65 | + test('surfaces in_progress task names and pending count', () => { |
| 66 | + const notice = buildUnfinishedTaskNotice([ |
| 67 | + task({ id: '1', status: 'in_progress', subject: '写模块' }), |
| 68 | + task({ id: '2', status: 'pending' }), |
| 69 | + task({ id: '3', status: 'pending' }), |
| 70 | + task({ id: '4', status: 'completed' }), |
| 71 | + ])! |
| 72 | + expect(notice).toContain('#1 写模块') |
| 73 | + expect(notice).toContain('2 个待办') |
| 74 | + }) |
| 75 | + |
| 76 | + test('collapses overflow when more than three in_progress tasks', () => { |
| 77 | + const notice = buildUnfinishedTaskNotice( |
| 78 | + Array.from({ length: 5 }, (_, i) => |
| 79 | + task({ id: String(i + 1), status: 'in_progress' }), |
| 80 | + ), |
| 81 | + )! |
| 82 | + expect(notice).toContain('等 5 个') |
| 83 | + }) |
| 84 | + |
| 85 | + test('guides the user to press Tab instead of promising bare Enter', () => { |
| 86 | + const notice = buildUnfinishedTaskNotice([ |
| 87 | + task({ id: '1', status: 'in_progress', subject: '写模块' }), |
| 88 | + ])! |
| 89 | + expect(notice).toContain('按 Tab') |
| 90 | + expect(notice).not.toContain('可直接回车继续') |
| 91 | + }) |
| 92 | +}) |
0 commit comments