dsh-progress-union 0.4.0 → 0.5.1
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 +157 -119
- package/LICENSE +21 -21
- package/README.md +201 -173
- package/anchor.js +39 -39
- package/client.js +2959 -2894
- package/cordis.patch.yml +4 -4
- package/docs/consumer-guide.md +210 -210
- package/docs/slot-models-comparison.md +23 -23
- package/docs/slot-trail-fanout.md +31 -31
- package/docs/spirit-reference.md +38 -38
- package/dsh.plugin.json +16 -16
- package/icon.svg +7 -7
- package/index.js +3621 -3106
- package/package.json +77 -77
- package/test/anchor.test.mjs +139 -139
- package/test/assistant.test.mjs +214 -214
- package/test/client.test.mjs +58 -54
- package/test/consumer.test.mjs +101 -101
- package/test/e2e.test.mjs +77 -77
- package/test/goal.test.mjs +110 -110
- package/test/harness.mjs +220 -216
- package/test/host.test.mjs +251 -184
- package/test/observer.test.mjs +170 -170
- package/test/plan.test.mjs +274 -0
- package/test/settings.test.mjs +81 -78
- package/test/stats.test.mjs +54 -54
- package/test/time.test.mjs +147 -147
- package/test/todo-sync.test.mjs +155 -155
package/test/settings.test.mjs
CHANGED
|
@@ -1,79 +1,82 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 设置面契约守卫(2026-11-26 事故回归)。
|
|
3
|
-
*
|
|
4
|
-
* 1) 设置页字段表单靠 **schema 叶子** 的 `.volatile()` 标记生成:整对象标 volatile
|
|
5
|
-
* 时一个字段都不渲染(客户端也就看不到任何可编辑项)。这里逐叶子断言标记存在。
|
|
6
|
-
* 2) 客户端必须把设置卡注册到 `settings.section` 槽,并通过宿主 `configForms`
|
|
7
|
-
* 句柄读写——否则「bundle 页 / 设置页」都没有配置入口。
|
|
8
|
-
*/
|
|
9
|
-
import assert from 'node:assert/strict'
|
|
10
|
-
import fs from 'node:fs'
|
|
11
|
-
import os from 'node:os'
|
|
12
|
-
import path from 'node:path'
|
|
13
|
-
import test from 'node:test'
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
'
|
|
37
|
-
'assistant.
|
|
38
|
-
'assistant.
|
|
39
|
-
'assistant.
|
|
40
|
-
'assistant.
|
|
41
|
-
'assistant.
|
|
42
|
-
'assistant.
|
|
43
|
-
'assistant.
|
|
44
|
-
'
|
|
45
|
-
'observer.
|
|
46
|
-
'observer.
|
|
47
|
-
'observer.
|
|
48
|
-
'observer.
|
|
49
|
-
'observer.
|
|
50
|
-
'
|
|
51
|
-
'
|
|
52
|
-
'todo.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
assert.
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
assert.
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
assert.match(src, /
|
|
75
|
-
assert.match(src, /
|
|
76
|
-
assert.match(src, /
|
|
77
|
-
assert.match(src, /
|
|
78
|
-
assert.match(src, /
|
|
1
|
+
/**
|
|
2
|
+
* 设置面契约守卫(2026-11-26 事故回归)。
|
|
3
|
+
*
|
|
4
|
+
* 1) 设置页字段表单靠 **schema 叶子** 的 `.volatile()` 标记生成:整对象标 volatile
|
|
5
|
+
* 时一个字段都不渲染(客户端也就看不到任何可编辑项)。这里逐叶子断言标记存在。
|
|
6
|
+
* 2) 客户端必须把设置卡注册到 `settings.section` 槽,并通过宿主 `configForms`
|
|
7
|
+
* 句柄读写——否则「bundle 页 / 设置页」都没有配置入口。
|
|
8
|
+
*/
|
|
9
|
+
import assert from 'node:assert/strict'
|
|
10
|
+
import fs from 'node:fs'
|
|
11
|
+
import os from 'node:os'
|
|
12
|
+
import path from 'node:path'
|
|
13
|
+
import test from 'node:test'
|
|
14
|
+
import { fileURLToPath } from 'node:url'
|
|
15
|
+
|
|
16
|
+
process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
|
|
17
|
+
const { Config } = await import('../index.js')
|
|
18
|
+
|
|
19
|
+
/** 递归收集点分键 → 是否带 volatile 标记。 */
|
|
20
|
+
function volatileLeaves(node, prefix = '', out = {}) {
|
|
21
|
+
const inner = node && (node.dict || node.inner)
|
|
22
|
+
if (!inner || typeof inner !== 'object') return out
|
|
23
|
+
for (const [key, child] of Object.entries(inner)) {
|
|
24
|
+
const dotted = prefix ? `${prefix}.${key}` : key
|
|
25
|
+
const meta = (child && child.meta) || {}
|
|
26
|
+
const nested = child && (child.dict || child.inner)
|
|
27
|
+
if (nested && typeof nested === 'object') volatileLeaves(child, dotted, out)
|
|
28
|
+
else out[dotted] = meta.volatile !== undefined
|
|
29
|
+
}
|
|
30
|
+
return out
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
test('Config:assistant / observer 的每个叶子都带 volatile(否则设置页不生成字段)', () => {
|
|
34
|
+
const leaves = volatileLeaves(Config)
|
|
35
|
+
const expected = [
|
|
36
|
+
'protocolHint',
|
|
37
|
+
'assistant.mode',
|
|
38
|
+
'assistant.provider',
|
|
39
|
+
'assistant.model',
|
|
40
|
+
'assistant.baseUrl',
|
|
41
|
+
'assistant.apiKey',
|
|
42
|
+
'assistant.authority',
|
|
43
|
+
'assistant.minIntervalMs',
|
|
44
|
+
'assistant.autoApply',
|
|
45
|
+
'observer.enabled',
|
|
46
|
+
'observer.maxIdleSteps',
|
|
47
|
+
'observer.maxIdleMs',
|
|
48
|
+
'observer.autoSyncCurrent',
|
|
49
|
+
'observer.autoSyncThrottleMs',
|
|
50
|
+
'observer.maxItems',
|
|
51
|
+
'todoSync',
|
|
52
|
+
'todo.maxReconcileIntervalMs',
|
|
53
|
+
'todo.mirrorThrottleMs',
|
|
54
|
+
]
|
|
55
|
+
for (const key of expected) {
|
|
56
|
+
assert.ok(key in leaves, `缺少配置键 ${key}`)
|
|
57
|
+
assert.equal(leaves[key], true, `${key} 必须是叶子级 .volatile()`)
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test('Config:外层对象不得自己标 volatile(嵌套 volatile 会被宿主拒绝)', () => {
|
|
62
|
+
for (const key of ['assistant', 'observer', 'todo']) {
|
|
63
|
+
const node = (Config.dict || Config.inner || {})[key]
|
|
64
|
+
assert.ok(node, `缺少 ${key} 节点`)
|
|
65
|
+
assert.equal((node.meta || {}).volatile, undefined, `${key} 这层不能标 volatile`)
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
test('客户端:设置卡双座位(settings.section + plugins.bundle.config)且走 configForms 句柄', () => {
|
|
70
|
+
// fileURLToPath:跨平台取文件路径。`new URL(...).pathname` 在 Linux 上会被
|
|
71
|
+
// `.replace(/^[/]/,'')` 误伤成相对路径(CI 上 ENOENT,本地 Windows 永不暴露)。
|
|
72
|
+
const file = fileURLToPath(new URL('../client.js', import.meta.url))
|
|
73
|
+
const src = fs.readFileSync(file, 'utf8')
|
|
74
|
+
assert.match(src, /registerSettingsSeat\('settings\.section'/, '必须注册 settings.section 槽')
|
|
75
|
+
assert.match(src, /id: 'dsh-progress-union'/, '分节 id 必须固定')
|
|
76
|
+
assert.match(src, /registerSettingsSeat\('plugins\.bundle\.config'/, 'bundle 详情页也要有配置卡(keyed by 包名)')
|
|
77
|
+
assert.match(src, /key: 'dsh-progress-union'/, 'bundle 座位 key 必须是包名')
|
|
78
|
+
assert.match(src, /configForms/, '必须经宿主 configForms 读写配置')
|
|
79
|
+
assert.match(src, /function ProgressUnionSettings\(/, '设置卡组件必须在')
|
|
80
|
+
assert.match(src, /scope\.subscribe/, '设置卡要订阅句柄快照')
|
|
81
|
+
assert.match(src, /function ensureUnionSettingsStyle\(/, '样式要注入 document.head,否则设置页里裸奔')
|
|
79
82
|
})
|
package/test/stats.test.mjs
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Should-Pass 验收:stats 学习链兼容——读鲸程(dsh-progress-task-bar)既有
|
|
3
|
-
* `$DSH_HOME/dsh-progress-stats.json` 样本:不迁移、不改路径、不损坏原样本,
|
|
4
|
-
* 新样本只在原数组尾部追加并按同一 schema 回写。
|
|
5
|
-
*/
|
|
6
|
-
import assert from 'node:assert/strict'
|
|
7
|
-
import fs from 'node:fs'
|
|
8
|
-
import os from 'node:os'
|
|
9
|
-
import path from 'node:path'
|
|
10
|
-
import test from 'node:test'
|
|
11
|
-
|
|
12
|
-
const HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-stats-'))
|
|
13
|
-
process.env.DSH_HOME = HOME
|
|
14
|
-
const STATS = path.join(HOME, 'dsh-progress-stats.json')
|
|
15
|
-
|
|
16
|
-
// 鲸程原样写出的文件:s=第几步,r=当时离任务结束还剩几秒。
|
|
17
|
-
const LEGACY = Array.from({ length: 25 }, (_, i) => ({ s: 1, r: 60 + i * 10 }))
|
|
18
|
-
fs.writeFileSync(STATS, JSON.stringify({ version: 1, updatedAt: 1000, samples: LEGACY }))
|
|
19
|
-
|
|
20
|
-
const { SESSION, createHarness, jsonReq, callRoute, withClock } = await import('./harness.mjs')
|
|
21
|
-
|
|
22
|
-
test('既有样本被读取成本机学习档,且新样本追加回写不损坏原样本', async () => {
|
|
23
|
-
const clock = withClock()
|
|
24
|
-
try {
|
|
25
|
-
const harness = createHarness()
|
|
26
|
-
await harness.run()
|
|
27
|
-
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
|
|
28
|
-
|
|
29
|
-
harness.emit('turn/start', {})
|
|
30
|
-
harness.emit('step/start', {})
|
|
31
|
-
clock.advance(30000)
|
|
32
|
-
|
|
33
|
-
// 25 条 s=1 样本 → bucket [1,2) 满 20 条,etaBasis 应从 'prior' 升到 'local'
|
|
34
|
-
const learned = harness.provided.get('progressAnchor').get(SESSION)
|
|
35
|
-
assert.equal(learned.time.etaBasis, 'local')
|
|
36
|
-
assert.equal(learned.time.etaP75Min, 4) // p75 = 240s
|
|
37
|
-
|
|
38
|
-
// 结束回合:产生一条真实样本 { s: 1, r: 30 }
|
|
39
|
-
harness.emit('turn/end', {})
|
|
40
|
-
|
|
41
|
-
const saved = JSON.parse(fs.readFileSync(STATS, 'utf8'))
|
|
42
|
-
assert.equal(saved.version, 1, 'schema version 保持 1(未迁移)')
|
|
43
|
-
assert.ok(saved.updatedAt > 1000, 'updatedAt 已刷新')
|
|
44
|
-
assert.deepEqual(saved.samples.slice(0, LEGACY.length), LEGACY, '既有 25 条原样保留')
|
|
45
|
-
assert.deepEqual(saved.samples.at(-1), { s: 1, r: 30 }, '新样本追加在尾部')
|
|
46
|
-
assert.equal(saved.samples.length, LEGACY.length + 1)
|
|
47
|
-
|
|
48
|
-
// 不迁移:DSH_HOME 里没有第二份 stats 文件
|
|
49
|
-
const extra = fs.readdirSync(HOME).filter((f) => /progress.*stats/.test(f) && f !== path.basename(STATS))
|
|
50
|
-
assert.deepEqual(extra, [], '没有生成迁移副本')
|
|
51
|
-
} finally {
|
|
52
|
-
clock.restore()
|
|
53
|
-
}
|
|
54
|
-
})
|
|
1
|
+
/**
|
|
2
|
+
* Should-Pass 验收:stats 学习链兼容——读鲸程(dsh-progress-task-bar)既有
|
|
3
|
+
* `$DSH_HOME/dsh-progress-stats.json` 样本:不迁移、不改路径、不损坏原样本,
|
|
4
|
+
* 新样本只在原数组尾部追加并按同一 schema 回写。
|
|
5
|
+
*/
|
|
6
|
+
import assert from 'node:assert/strict'
|
|
7
|
+
import fs from 'node:fs'
|
|
8
|
+
import os from 'node:os'
|
|
9
|
+
import path from 'node:path'
|
|
10
|
+
import test from 'node:test'
|
|
11
|
+
|
|
12
|
+
const HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-stats-'))
|
|
13
|
+
process.env.DSH_HOME = HOME
|
|
14
|
+
const STATS = path.join(HOME, 'dsh-progress-stats.json')
|
|
15
|
+
|
|
16
|
+
// 鲸程原样写出的文件:s=第几步,r=当时离任务结束还剩几秒。
|
|
17
|
+
const LEGACY = Array.from({ length: 25 }, (_, i) => ({ s: 1, r: 60 + i * 10 }))
|
|
18
|
+
fs.writeFileSync(STATS, JSON.stringify({ version: 1, updatedAt: 1000, samples: LEGACY }))
|
|
19
|
+
|
|
20
|
+
const { SESSION, createHarness, jsonReq, callRoute, withClock } = await import('./harness.mjs')
|
|
21
|
+
|
|
22
|
+
test('既有样本被读取成本机学习档,且新样本追加回写不损坏原样本', async () => {
|
|
23
|
+
const clock = withClock()
|
|
24
|
+
try {
|
|
25
|
+
const harness = createHarness()
|
|
26
|
+
await harness.run()
|
|
27
|
+
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
|
|
28
|
+
|
|
29
|
+
harness.emit('turn/start', {})
|
|
30
|
+
harness.emit('step/start', {})
|
|
31
|
+
clock.advance(30000)
|
|
32
|
+
|
|
33
|
+
// 25 条 s=1 样本 → bucket [1,2) 满 20 条,etaBasis 应从 'prior' 升到 'local'
|
|
34
|
+
const learned = harness.provided.get('progressAnchor').get(SESSION)
|
|
35
|
+
assert.equal(learned.time.etaBasis, 'local')
|
|
36
|
+
assert.equal(learned.time.etaP75Min, 4) // p75 = 240s
|
|
37
|
+
|
|
38
|
+
// 结束回合:产生一条真实样本 { s: 1, r: 30 }
|
|
39
|
+
harness.emit('turn/end', {})
|
|
40
|
+
|
|
41
|
+
const saved = JSON.parse(fs.readFileSync(STATS, 'utf8'))
|
|
42
|
+
assert.equal(saved.version, 1, 'schema version 保持 1(未迁移)')
|
|
43
|
+
assert.ok(saved.updatedAt > 1000, 'updatedAt 已刷新')
|
|
44
|
+
assert.deepEqual(saved.samples.slice(0, LEGACY.length), LEGACY, '既有 25 条原样保留')
|
|
45
|
+
assert.deepEqual(saved.samples.at(-1), { s: 1, r: 30 }, '新样本追加在尾部')
|
|
46
|
+
assert.equal(saved.samples.length, LEGACY.length + 1)
|
|
47
|
+
|
|
48
|
+
// 不迁移:DSH_HOME 里没有第二份 stats 文件
|
|
49
|
+
const extra = fs.readdirSync(HOME).filter((f) => /progress.*stats/.test(f) && f !== path.basename(STATS))
|
|
50
|
+
assert.deepEqual(extra, [], '没有生成迁移副本')
|
|
51
|
+
} finally {
|
|
52
|
+
clock.restore()
|
|
53
|
+
}
|
|
54
|
+
})
|
package/test/time.test.mjs
CHANGED
|
@@ -1,147 +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
|
-
})
|
|
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
|
+
})
|