-
Notifications
You must be signed in to change notification settings - Fork 16.5k
Expand file tree
/
Copy pathtaskAnchorReminder.test.ts
More file actions
129 lines (116 loc) · 4.32 KB
/
Copy pathtaskAnchorReminder.test.ts
File metadata and controls
129 lines (116 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import { describe, expect, test } from 'bun:test'
import type { Task } from '../../../utils/tasks.js'
import {
buildTaskAnchorReminder,
buildUnfinishedTaskNotice,
isAnchorlessNudge,
} from '../taskAnchorReminder.js'
function task(partial: Partial<Task> & Pick<Task, 'id' | 'status'>): Task {
return {
subject: `Task ${partial.id}`,
description: '',
blocks: [],
blockedBy: [],
...partial,
}
}
describe('isAnchorlessNudge', () => {
test('matches short Chinese keep-going nudges', () => {
expect(isAnchorlessNudge('继续执行后续的工作')).toBe(true)
expect(isAnchorlessNudge('继续完成当前任务')).toBe(true)
expect(isAnchorlessNudge('自动执行后续的所有流程')).toBe(true)
expect(isAnchorlessNudge('接着做')).toBe(true)
})
test('matches short English keep-going nudges', () => {
expect(isAnchorlessNudge('continue')).toBe(true)
expect(isAnchorlessNudge('keep going')).toBe(true)
expect(isAnchorlessNudge('go on please')).toBe(true)
})
test('does not match empty or whitespace', () => {
expect(isAnchorlessNudge('')).toBe(false)
expect(isAnchorlessNudge(' ')).toBe(false)
})
test('does not match long messages that merely contain a nudge word', () => {
expect(
isAnchorlessNudge(
'继续用状态机方案重构 REPL 的输入处理模块,并补齐对应的单元测试',
),
).toBe(false)
})
test('does not match substantive requests without nudge words', () => {
expect(isAnchorlessNudge('给我看下 query.ts 的结构')).toBe(false)
expect(isAnchorlessNudge('fix the login bug')).toBe(false)
})
})
describe('buildTaskAnchorReminder', () => {
test('returns null when there are no unfinished tasks', () => {
expect(buildTaskAnchorReminder([])).toBeNull()
expect(
buildTaskAnchorReminder([
task({ id: '1', status: 'completed' }),
task({ id: '2', status: 'completed' }),
]),
).toBeNull()
})
test('lists only unfinished tasks, in_progress before pending', () => {
const reminder = buildTaskAnchorReminder([
task({ id: '1', status: 'completed', subject: 'done' }),
task({ id: '2', status: 'pending', subject: 'second' }),
task({ id: '3', status: 'in_progress', subject: 'third' }),
])
expect(reminder).not.toBeNull()
const body = reminder!
expect(body).toContain('2 unfinished task(s)')
// in_progress (#3) must appear before pending (#2)
expect(body.indexOf('#3 [in_progress]')).toBeLessThan(
body.indexOf('#2 [pending]'),
)
expect(body).not.toContain('#1')
expect(body).toContain('<system-reminder>')
expect(body).toContain('</system-reminder>')
})
test('orders same-status tasks by numeric id', () => {
const reminder = buildTaskAnchorReminder([
task({ id: '10', status: 'pending', subject: 'ten' }),
task({ id: '2', status: 'pending', subject: 'two' }),
])!
expect(reminder.indexOf('#2 ')).toBeLessThan(reminder.indexOf('#10 '))
})
test('caps the list and reports overflow', () => {
const many: Task[] = Array.from({ length: 25 }, (_, i) =>
task({ id: String(i + 1), status: 'pending' }),
)
const reminder = buildTaskAnchorReminder(many)!
expect(reminder).toContain('25 unfinished task(s)')
expect(reminder).toContain('…and 5 more')
})
})
describe('buildUnfinishedTaskNotice', () => {
test('returns null when no task is in_progress', () => {
expect(buildUnfinishedTaskNotice([])).toBeNull()
expect(
buildUnfinishedTaskNotice([
task({ id: '1', status: 'pending' }),
task({ id: '2', status: 'completed' }),
]),
).toBeNull()
})
test('surfaces in_progress task names and pending count', () => {
const notice = buildUnfinishedTaskNotice([
task({ id: '1', status: 'in_progress', subject: '写模块' }),
task({ id: '2', status: 'pending' }),
task({ id: '3', status: 'pending' }),
task({ id: '4', status: 'completed' }),
])!
expect(notice).toContain('#1 写模块')
expect(notice).toContain('2 个待办')
})
test('collapses overflow when more than three in_progress tasks', () => {
const notice = buildUnfinishedTaskNotice(
Array.from({ length: 5 }, (_, i) =>
task({ id: String(i + 1), status: 'in_progress' }),
),
)!
expect(notice).toContain('等 5 个')
})
})