dsh-progress-union 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +77 -0
- package/README.md +25 -13
- package/client.js +14 -189
- package/dsh.plugin.json +1 -1
- package/index.js +51 -25
- package/package.json +9 -4
- package/test/anchor.test.mjs +139 -0
- package/test/assistant.test.mjs +215 -0
- package/test/client.test.mjs +54 -0
- package/test/e2e.test.mjs +77 -0
- package/test/goal.test.mjs +110 -0
- package/test/harness.mjs +210 -0
- package/test/host.test.mjs +184 -0
- package/test/observer.test.mjs +171 -0
- package/test/stats.test.mjs +54 -0
- package/test/time.test.mjs +147 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 2 验收:时间引擎(事件层 + ETA 三档回落 + 协议收敛 + cooldown/stale)。
|
|
3
|
+
*/
|
|
4
|
+
import assert from 'node:assert/strict'
|
|
5
|
+
import fs from 'node:fs'
|
|
6
|
+
import os from 'node:os'
|
|
7
|
+
import path from 'node:path'
|
|
8
|
+
import test from 'node:test'
|
|
9
|
+
|
|
10
|
+
process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
|
|
11
|
+
const { SESSION, createHarness, jsonReq, callRoute, withClock } = await import('./harness.mjs')
|
|
12
|
+
|
|
13
|
+
async function booted() {
|
|
14
|
+
const harness = createHarness()
|
|
15
|
+
await harness.run()
|
|
16
|
+
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
|
|
17
|
+
return harness
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function execUpdate(harness, args) {
|
|
21
|
+
const tool = harness.toolMap.get('progress_update')
|
|
22
|
+
return tool.definition.execute(args, { agent: harness.agent })
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function anchorOf(harness, atMs) {
|
|
26
|
+
return harness.provided.get('progressAnchor').get(SESSION, atMs)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
test('turn/start + step/start 驱动 steps/elapsed;无板无 todo 走 prior', async () => {
|
|
30
|
+
const harness = createHarness()
|
|
31
|
+
await harness.run()
|
|
32
|
+
harness.emit('turn/start', {})
|
|
33
|
+
for (let i = 0; i < 4; i++) harness.emit('step/start', {})
|
|
34
|
+
const started = anchorOf(harness).time.startedAt
|
|
35
|
+
assert.ok(started > 0)
|
|
36
|
+
const at = started + 60_000
|
|
37
|
+
const anchor = anchorOf(harness, at)
|
|
38
|
+
assert.equal(anchor.time.steps, 4)
|
|
39
|
+
assert.equal(anchor.time.elapsedSec, 60)
|
|
40
|
+
assert.equal(anchor.time.etaBasis, 'prior') // 临时 DSH_HOME 无学习样本
|
|
41
|
+
assert.equal(anchor.time.todoTotal, 0)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
test('board 档最优先:阶段取板、blocked 不计剩余', async () => {
|
|
45
|
+
const harness = await booted()
|
|
46
|
+
const added = await execUpdate(harness, {
|
|
47
|
+
changes: [
|
|
48
|
+
{ title: '甲', status: 'done' },
|
|
49
|
+
{ title: '乙', status: 'blocked', note: '等人确认' },
|
|
50
|
+
{ title: '丙', status: 'todo' },
|
|
51
|
+
],
|
|
52
|
+
})
|
|
53
|
+
harness.emit('turn/start', {})
|
|
54
|
+
const started = anchorOf(harness).time.startedAt
|
|
55
|
+
const at = started + 60_000 // elapsed 60s, done=1 → perItemSec=60, left=1(丙) → p50=60
|
|
56
|
+
const anchor = anchorOf(harness, at)
|
|
57
|
+
assert.equal(anchor.time.etaBasis, 'board')
|
|
58
|
+
assert.equal(anchor.time.elapsedSec, 60)
|
|
59
|
+
// p50=60 → remain=max(5,60-36)/60=0.4min → etaMin=max(0,round(.4))=0
|
|
60
|
+
assert.equal(anchor.time.etaMin, 0)
|
|
61
|
+
// inFlight 含 blocked(等人不是等时间,但要出现在锚点)
|
|
62
|
+
assert.deepEqual(anchor.board.inFlight.map((i) => i.status), ['blocked'])
|
|
63
|
+
assert.equal(anchor.board.summary.total, 3)
|
|
64
|
+
assert.equal(anchor.board.summary.done, 1)
|
|
65
|
+
void added
|
|
66
|
+
|
|
67
|
+
// /dsh-progress/status:板开时阶段直接取 items 标题(不再关键词猜测)
|
|
68
|
+
const res = await callRoute(harness, '/dsh-progress/status', { method: 'GET', url: '/dsh-progress/status', headers: {} })
|
|
69
|
+
const task = res.json().task
|
|
70
|
+
assert.deepEqual(task.stages, ['甲', '乙', '丙'])
|
|
71
|
+
assert.equal(task.boardDriven, true)
|
|
72
|
+
assert.equal(task.autoStage, false)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('todo 档:板关闭时用官方 todo 完成度', async () => {
|
|
76
|
+
const harness = createHarness()
|
|
77
|
+
await harness.run()
|
|
78
|
+
harness.emit('turn/start', {})
|
|
79
|
+
harness.emit('todo/write', { todos: [{ content: 'a', status: 'completed' }, { content: 'b', status: 'completed' }, { content: 'c', status: 'pending' }, { content: 'd', status: 'pending' }] })
|
|
80
|
+
const started = anchorOf(harness).time.startedAt
|
|
81
|
+
const at = started + 120_000 // perItemSec=60, left=2 → p50=120
|
|
82
|
+
const anchor = anchorOf(harness, at)
|
|
83
|
+
assert.equal(anchor.time.etaBasis, 'todo')
|
|
84
|
+
assert.equal(anchor.time.todoDone, 2)
|
|
85
|
+
assert.equal(anchor.time.todoTotal, 4)
|
|
86
|
+
// p50=120, elapsed=120 → max(5,120-72)=48s → etaMin=1
|
|
87
|
+
assert.equal(anchor.time.etaMin, 1)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('kickoff 冷却:全完成后一回合只推一次', async () => {
|
|
91
|
+
const harness = await booted()
|
|
92
|
+
await execUpdate(harness, { changes: [{ title: '唯一任务', status: 'done' }] })
|
|
93
|
+
const kickoff = harness.contexts.get('progress-union-kickoff')
|
|
94
|
+
const first = kickoff()
|
|
95
|
+
assert.match(first, /已全部完成/)
|
|
96
|
+
assert.equal(kickoff(), '', '60s 冷却内不得重复推')
|
|
97
|
+
void harness
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
test('stale:板开 13 分钟未更新 → anchor.time.staleMin ≥ 11', async () => {
|
|
101
|
+
const harness = await booted()
|
|
102
|
+
await execUpdate(harness, { changes: [{ title: '任务', status: 'doing', current: '在做' }] })
|
|
103
|
+
const base = Date.now()
|
|
104
|
+
const anchor = anchorOf(harness, base + 13 * 60 * 1000)
|
|
105
|
+
assert.equal(anchor.time.staleMin, 13)
|
|
106
|
+
assert.equal(anchor.board.inFlight[0].status, 'doing')
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
test('单协议收敛:板开不注入文件上报协议,板关注入且 kind=plugin:dsh-progress-union', async () => {
|
|
110
|
+
const clock = withClock()
|
|
111
|
+
try {
|
|
112
|
+
// 板开
|
|
113
|
+
const on = await booted()
|
|
114
|
+
const preStep = on.agentHooks.find((h) => h.type === 'agent/pre-step')
|
|
115
|
+
assert.ok(preStep, 'agent/created 应装 pre-step 钩子')
|
|
116
|
+
const freshUser = { source: { kind: 'user' } }
|
|
117
|
+
const decision = { kind: 'enter', messages: [freshUser] }
|
|
118
|
+
const out = await preStep.handler({ messages: [freshUser] }, async () => decision)
|
|
119
|
+
assert.equal(out.messages.length, 1, '板开时不得追加协议消息')
|
|
120
|
+
|
|
121
|
+
// 板关(全新 harness 不启用)
|
|
122
|
+
const off = createHarness()
|
|
123
|
+
await off.run()
|
|
124
|
+
const preStepOff = off.agentHooks.find((h) => h.type === 'agent/pre-step')
|
|
125
|
+
const decisionOff = { kind: 'enter', messages: [{ source: { kind: 'user' } }] }
|
|
126
|
+
const outOff = await preStepOff.handler({ messages: [{ source: { kind: 'user' } }] }, async () => decisionOff)
|
|
127
|
+
assert.equal(outOff.messages.length, 2)
|
|
128
|
+
const injected = outOff.messages[1]
|
|
129
|
+
assert.equal(injected.source.kind, 'plugin:dsh-progress-union')
|
|
130
|
+
assert.match(injected.content[0].text, /dsh-progress/)
|
|
131
|
+
} finally {
|
|
132
|
+
clock.restore()
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
test('turn/end 收任务并学样本;结束后锚点时间层归零但不丢 steps', async () => {
|
|
137
|
+
const harness = createHarness()
|
|
138
|
+
await harness.run()
|
|
139
|
+
harness.emit('turn/start', {})
|
|
140
|
+
harness.emit('step/start', {})
|
|
141
|
+
harness.emit('step/start', {})
|
|
142
|
+
harness.emit('turn/end', {})
|
|
143
|
+
const anchor = anchorOf(harness, Date.now() + 3600_000)
|
|
144
|
+
assert.equal(anchor.time.startedAt, 0, '任务已结束不应再给进行中锚')
|
|
145
|
+
assert.equal(anchor.time.etaBasis, 'none')
|
|
146
|
+
assert.equal(anchor.time.elapsedSec, 0)
|
|
147
|
+
})
|