dsh-progress-union 0.6.3 → 0.7.0-rc.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 +387 -373
- package/LICENSE +21 -21
- package/README.md +286 -286
- package/anchor.js +39 -39
- package/client.js +2993 -2993
- package/cordis.patch.yml +4 -4
- 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 +1 -1
- package/icon.svg +7 -7
- package/index.js +4993 -4568
- package/package.json +93 -79
- package/test/anchor.test.mjs +139 -139
- package/test/assistant.test.mjs +214 -214
- package/test/client.test.mjs +190 -190
- package/test/download-classify.test.mjs +199 -0
- package/test/e2e.test.mjs +77 -77
- package/test/goal-drive.test.mjs +17 -17
- package/test/harness.mjs +249 -249
- package/test/host.test.mjs +251 -251
- package/test/observer.test.mjs +170 -170
- package/test/parse-progress.test.mjs +78 -0
- package/test/settings.test.mjs +81 -81
- package/test/star-panel.test.mjs +181 -181
- package/test/time.test.mjs +147 -147
- package/test/todo-sync.test.mjs +155 -155
package/test/client.test.mjs
CHANGED
|
@@ -1,190 +1,190 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Phase 4 验收:client 契约守卫。
|
|
3
|
-
* 1) 客户端文件不得残留 board 旧命名空间/旧 API 调用(fork 改造回归);
|
|
4
|
-
* 2) 客户端消费的两条路由形状(snapshot / status)由宿主实测钉住。
|
|
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
|
-
import { fileURLToPath } from 'node:url'
|
|
13
|
-
|
|
14
|
-
process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
|
|
15
|
-
const { SESSION, createHarness, jsonReq, callRoute } = await import('./harness.mjs')
|
|
16
|
-
|
|
17
|
-
// 必须用 fileURLToPath:`new URL(...).pathname` 在 Windows 得到 `/E:/...`(需去前导斜杠),
|
|
18
|
-
// 但 Linux 的 `/` 是根目录,`.replace(/^[/]/,'')` 会把它变成相对路径 → CI 上 ENOENT。
|
|
19
|
-
const clientFile = fileURLToPath(new URL('../client.js', import.meta.url))
|
|
20
|
-
const packageFile = fileURLToPath(new URL('../package.json', import.meta.url))
|
|
21
|
-
|
|
22
|
-
test('client.js 命名空间已切到 union,无 progress-board API 残留', () => {
|
|
23
|
-
const src = fs.readFileSync(clientFile, 'utf8')
|
|
24
|
-
assert.match(src, /id: 'dsh-progress-union'/)
|
|
25
|
-
assert.match(src, /const API = '\/progress-union'/)
|
|
26
|
-
assert.match(src, /STATUS_API = '\/dsh-progress\/status'/)
|
|
27
|
-
assert.doesNotMatch(src, /fetch\(`\/progress-board/, '不得残留旧 API 前缀的直接调用')
|
|
28
|
-
assert.match(src, /useUnionTiming/, '迷你条时间面钩子必须在')
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
test('迷你条暂停/继续按钮接线齐全(渲染 + 请求 + 状态门控)', () => {
|
|
32
|
-
const src = fs.readFileSync(clientFile, 'utf8')
|
|
33
|
-
// 渲染:两个按钮都在 dock actions 区
|
|
34
|
-
assert.match(src, /className: 'pb-dock-btn pb-dock-goal pb-dock-goal-pause'/, '暂停按钮必须在')
|
|
35
|
-
assert.match(src, /className: 'pb-dock-btn pb-dock-goal pb-dock-goal-resume'/, '继续按钮必须在')
|
|
36
|
-
// 请求面:走 /progress-union/goal 控制路由
|
|
37
|
-
assert.match(src, /fetch\(`\$\{API\}\/goal`/, '必须调用目标控制路由')
|
|
38
|
-
assert.match(src, /action: 'pause'|onGoalControl\('pause'\)/, '暂停必须接线')
|
|
39
|
-
assert.match(src, /onGoalControl\('resume'\)/, '继续必须接线')
|
|
40
|
-
// 门控:只有目标 active 才给暂停,只有 paused/blocked 才给继续
|
|
41
|
-
assert.match(src, /goalActive = goalPhase === 'active'/, '暂停按钮必须按 phase 门控')
|
|
42
|
-
assert.match(src, /goalStopped = goalPhase === 'paused' \|\| goalPhase === 'blocked'/, '继续按钮必须按 phase 门控')
|
|
43
|
-
// 按钮样式必须真的存在(否则是裸浏览器按钮):背景=主色实心,前景=宿主 on-color 令牌。
|
|
44
|
-
assert.match(src, /\.pb-dock-goal-resume \{[^}]*background: var\(--dsw-alias-brand-primary\)/, '继续按钮需要有主色实心样式')
|
|
45
|
-
assert.match(src, /\.pb-dock-goal-resume \{[^}]*color: var\(--dsw-alias-label-on-color/, '继续按钮前景必须用 on-color 令牌')
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
test('主色实心按钮的前景色不得用 bg-base(玻璃皮肤会把它设成 transparent)', () => {
|
|
49
|
-
const src = fs.readFileSync(clientFile, 'utf8')
|
|
50
|
-
// 事故:maid-atelier 皮肤在 body 上把 --dsw-alias-bg-base 设为 transparent,
|
|
51
|
-
// 拿它当 color 会让「继续」渲染成透明字 → 看着像一块纯色块盖住了按钮。
|
|
52
|
-
assert.doesNotMatch(src, /color:\s*var\(--dsw-alias-bg-base/, '--dsw-alias-bg-base 是页面底色语义,不能当前景色')
|
|
53
|
-
assert.match(src, /\.pb-btn-primary \{[^}]*color: var\(--dsw-alias-label-on-color/, '主按钮前景必须用 on-color 令牌')
|
|
54
|
-
// 选择态底板同样不能用 bg-base(透明后选中段会"消失")。
|
|
55
|
-
assert.doesNotMatch(src, /\[data-on="true"\] \{[^}]*background: var\(--dsw-alias-bg-base/, '分段控件选中态不得用 bg-base 做底板')
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
test('目标文案区分「板目标」与宿主 goal,完成态不报时间面', () => {
|
|
59
|
-
const src = fs.readFileSync(clientFile, 'utf8')
|
|
60
|
-
// 官方 GoalBar 与 /progress-goal 是两套状态机,并排在同一 input dock:文案必须能分辨。
|
|
61
|
-
assert.match(src, /goalPaused: '板目标已暂停'/, 'zh 文案需带「板目标」前缀')
|
|
62
|
-
assert.match(src, /goalPaused: 'Board goal paused'/, 'en 文案需带 Board goal 前缀')
|
|
63
|
-
assert.match(src, /独立于宿主的 \/goal/, '悬停提示需说明与宿主 /goal 的关系')
|
|
64
|
-
assert.match(src, /const allDone = summary\.total > 0 && summary\.done === summary\.total/, '完成态需跳过时间面')
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
test('W1: 头部入口注册仍在,且带渲染兜底与分面隔离', () => {
|
|
68
|
-
// 仓内文件是 CRLF:多行断言前先归一,否则 \n 永远匹配不到 \r\n。
|
|
69
|
-
const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
|
|
70
|
-
// 入口本体:槽位 + id + 顺序(5 = 排在宿主自带入口之后、其余插件之前,窄窗口不会被裁掉)
|
|
71
|
-
assert.match(src, /name: 'conversation\.session\.header\.utilities'/, '头部工具区槽位注册必须在')
|
|
72
|
-
assert.match(src, /id: 'progress-union-header'/, '头部入口 id 必须在')
|
|
73
|
-
assert.match(src, /order: 5,/, '头部入口顺序必须提前到 5')
|
|
74
|
-
// 渲染兜底:组件抛错只让这一枚消失,不拖垮整排 utilities
|
|
75
|
-
assert.match(src, /class HeaderEntryBoundary extends React\.Component/, '头部入口必须有错误边界')
|
|
76
|
-
assert.match(src, /getDerivedStateFromError/, '错误边界必须真的降级渲染')
|
|
77
|
-
assert.match(src, /function ProgressHeaderButton\(props\) \{\n return h\(HeaderEntryBoundary/, '导出组件必须包在错误边界里')
|
|
78
|
-
// 分面隔离:任一入口注册失败不得中止 apply(否则图标/迷你条/右栏页签一起消失)
|
|
79
|
-
assert.match(src, /const safeEffect = \(label, register\) =>/, '必须有分面隔离助手')
|
|
80
|
-
const safeCalls = src.match(/^\s+safeEffect\($/gm) || []
|
|
81
|
-
assert.equal(safeCalls.length, 6, '六个入口面(设置×2 / 右栏类型 / 右栏面板 / 头部 / 迷你条)都必须经 safeEffect 注册')
|
|
82
|
-
const bare = src.match(/ctx\.effect\(\s*\n\s*\(\) =>\s*\n\s*ctx\.(slots|sidebarRightTabs)/g) || []
|
|
83
|
-
assert.equal(bare.length, 0, '不得残留裸 ctx.effect 入口注册')
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
test('W2: better-sidebar 页签是独立入口,内容仍是自有板子', () => {
|
|
87
|
-
const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
|
|
88
|
-
assert.match(src, /const BS_TAB_ID = 'dsh-progress-union:board'/, 'better-sidebar 页签 id 必须在')
|
|
89
|
-
assert.doesNotMatch(src, /const BS_TAB_ID = 'progress-union'|const BS_TAB_ID = 'dsh-progress-union'\n/, '页签 id 不得与原生 kind 混用')
|
|
90
|
-
// 服务可能晚于 apply 就绪 → 必须 deferred inject,不能一次性 ctx.get
|
|
91
|
-
assert.match(src, /ctx\.inject\(\['betterSidebar'\], \(bs\) => \{/, '必须用 deferred inject 等待 betterSidebar')
|
|
92
|
-
assert.match(src, /typeof service\.registerTab !== 'function'/, '调用前必须探测 registerTab')
|
|
93
|
-
// 描述符字段齐全
|
|
94
|
-
assert.match(src, /id: BS_TAB_ID,/)
|
|
95
|
-
assert.match(src, /title: \(\) => t\('nav'\),/)
|
|
96
|
-
assert.match(src, /description: \(\) => t\('bsDesc'\),/)
|
|
97
|
-
assert.match(src, /icon: \(size\) => h\(ProgressNavIcon, \{ size: size \|\| 16 \}\)/)
|
|
98
|
-
assert.match(src, /order: 120,/)
|
|
99
|
-
assert.match(src, /single: true,/)
|
|
100
|
-
// 内容是自有板子,且拿到当前会话
|
|
101
|
-
assert.match(src, /h\(ProgressSidePanel, \{/, '页签正文必须是自有 ProgressSidePanel')
|
|
102
|
-
assert.match(src, /sessionId: tabProps && tabProps\.scope \? tabProps\.scope\.sessionId : undefined/)
|
|
103
|
-
// 不传 collapse / toggleFullscreen,避免 better-sidebar 里出现死按钮
|
|
104
|
-
const block = src.slice(src.indexOf("ctx.inject(['betterSidebar']"), src.indexOf("'progress-union: better-sidebar tab'"))
|
|
105
|
-
assert.doesNotMatch(block, /collapse:/, '不得向 better-sidebar 页签传 collapse')
|
|
106
|
-
assert.doesNotMatch(block, /toggleFullscreen:/, '不得向 better-sidebar 页签传 toggleFullscreen')
|
|
107
|
-
// 明确不复用 better-sidebar 的「任务管理」
|
|
108
|
-
assert.doesNotMatch(block, /task.?manage|subagent|后台命令/iu, '不得复用 better-sidebar 的任务管理视图')
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
test('W2: better-sidebar 只是软依赖(未装者必须照常加载)', () => {
|
|
112
|
-
const pkg = JSON.parse(fs.readFileSync(packageFile, 'utf8'))
|
|
113
|
-
const declared = pkg.dsh?.client?.inject ?? []
|
|
114
|
-
assert.equal(declared.includes('dsh-better-sidebar'), false, 'dsh.client.inject 不得声明 dsh-better-sidebar')
|
|
115
|
-
assert.equal('dsh-better-sidebar' in (pkg.dependencies ?? {}), false, 'dependencies 不得声明 dsh-better-sidebar')
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
test('S2: bsDesc 在 zh/en 两个字典里都存在', () => {
|
|
119
|
-
const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
|
|
120
|
-
assert.match(src, /bsDesc: '任务串联的进度板(不是 better-sidebar 的「任务管理」)'/, 'zh 文案必须在')
|
|
121
|
-
assert.match(src, /bsDesc: 'Linked-task progress board \(not better-sidebar task manager\)'/, 'en 文案必须在')
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
test('宿主 snapshot/status 两路由的客户端消费形状', async () => {
|
|
125
|
-
const harness = createHarness()
|
|
126
|
-
await harness.run()
|
|
127
|
-
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
|
|
128
|
-
await harness.toolMap.get('progress_update').definition.execute(
|
|
129
|
-
{ changes: [{ title: '渲染截图', status: 'doing', current: '渲染第 7/24 张' }, { title: '合成音轨' }] },
|
|
130
|
-
{ agent: harness.agent },
|
|
131
|
-
)
|
|
132
|
-
harness.emit('turn/start', {})
|
|
133
|
-
harness.emit('step/start', {})
|
|
134
|
-
|
|
135
|
-
const snap = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
|
|
136
|
-
assert.equal(snap.ok, true)
|
|
137
|
-
assert.equal(snap.enabled, true)
|
|
138
|
-
assert.deepEqual(snap.items.map((i) => i.title), ['渲染截图', '合成音轨'])
|
|
139
|
-
assert.equal(typeof snap.summary.percent, 'number')
|
|
140
|
-
assert.equal('pendingUserChanges' in snap, true)
|
|
141
|
-
|
|
142
|
-
const status = (await callRoute(harness, '/dsh-progress/status', { method: 'GET', url: '/dsh-progress/status', headers: {} })).json()
|
|
143
|
-
assert.equal(status.ok, true)
|
|
144
|
-
assert.equal(status.config.pollMs, 1000)
|
|
145
|
-
assert.ok(status.task, 'status.task 必须存在(迷你条数据源)')
|
|
146
|
-
assert.equal(String(status.task.id), String(SESSION))
|
|
147
|
-
// 板开:阶段直接取板 items,不再走关键词猜测
|
|
148
|
-
assert.deepEqual(status.task.stages, ['渲染截图', '合成音轨'])
|
|
149
|
-
assert.equal(status.task.boardDriven, true)
|
|
150
|
-
assert.equal(status.task.current, 0)
|
|
151
|
-
assert.ok(Array.isArray(status.tasks))
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
test('W3: 板只住在右侧边栏——不再注册主区完整面板', () => {
|
|
155
|
-
// 事故:主区面板没有收拢入口,点进去就回不到会话(进去出不来)。
|
|
156
|
-
const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
|
|
157
|
-
assert.match(src, /const openPanel = \(\) => ctx\.sidebarRight\.openTab\(RIGHT_TAB_KIND\)/, '头部/迷你条入口必须打开右栏页签')
|
|
158
|
-
assert.match(src, /inject: \(\) => \(\{ openPanel, togglePanel \}\)/, '头部入口注入的必须是右栏开关(可见则收起,不可见则打开)')
|
|
159
|
-
assert.doesNotMatch(src, /ctx\.slots\.inject\('main'/, '不得再注册主区完整面板')
|
|
160
|
-
assert.doesNotMatch(src, /layout\.selectPanel/, '不得再切主区面板')
|
|
161
|
-
assert.doesNotMatch(src, /function ProgressPanel\(/, '完整面板组件应已移除')
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
test('W4: 侧栏顶部不再画自带的 全面展开/收起/完整面板 按钮(交给右栏 chrome)', () => {
|
|
165
|
-
// 事故:三个按钮都在,但 toggleFullscreen / collapse 在右栏页签里根本没注入(better-sidebar 里更没处传),
|
|
166
|
-
// 点了没反应才是常态。右栏自身的 chrome 已经有全屏与关闭,不再重复造。
|
|
167
|
-
const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
|
|
168
|
-
assert.doesNotMatch(src, /props\.toggleFullscreen/, '不得再渲染自带的全屏按钮')
|
|
169
|
-
assert.doesNotMatch(src, /props\.collapse/, '不得再渲染自带的收起按钮')
|
|
170
|
-
assert.doesNotMatch(src, /t\('sideFull'\)|t\('sideHalf'\)|t\('sideCollapse'\)/, '三个死按钮的文案不得残留')
|
|
171
|
-
assert.doesNotMatch(src, /toggleFullscreen/, '注入面不得再传全屏切换')
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
test('0.6.2:面板来源行只在 snapshot.restoredFrom 存在时渲染', () => {
|
|
175
|
-
const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
|
|
176
|
-
assert.match(src, /\.pb-side-restore \{/, '来源行样式缺失')
|
|
177
|
-
assert.match(src, /sideRestore: '已从归档 v\{seq\} · rev \{revision\} 恢复,共 \{n\} 项'/, 'zh 文案缺失')
|
|
178
|
-
assert.match(src, /sideRestore: 'Restored from archive/, 'en 文案缺失')
|
|
179
|
-
assert.match(src, /snapshot\?\.restoredFrom\s*\n?\s*\? h\(/, '渲染必须由 restoredFrom 门控')
|
|
180
|
-
assert.match(src, /replace\('\{seq\}', String\(snapshot\.restoredFrom\.seq\)\)/, 'seq 未注入')
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
test('0.6.3:提示卡与用量条间距成体系,且不再出现负 margin', () => {
|
|
184
|
-
const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
|
|
185
|
-
assert.doesNotMatch(src, /margin:\s*-4px/, '不得再有负上边距(用量条顶进提示卡的根因)')
|
|
186
|
-
assert.match(src, /\.pb-llm \{[^}]*margin: 10px 0 12px/, '.pb-llm 下边距必须 12px')
|
|
187
|
-
assert.doesNotMatch(src, /\.pb-llm \{[^}]*margin: 10px 0 0[;}]/, '旧的 0 下边距必须消失')
|
|
188
|
-
assert.match(src, /\.pb-side > \.pb-usage \{[^}]*margin: 0 0 12px/, '用量条上边距必须归零')
|
|
189
|
-
assert.match(src, /\.pb-side > \.pb-llm \+ \.pb-side-error \{ margin-top: 12px; \}/, '同类块相邻补 12px')
|
|
190
|
-
})
|
|
1
|
+
/**
|
|
2
|
+
* Phase 4 验收:client 契约守卫。
|
|
3
|
+
* 1) 客户端文件不得残留 board 旧命名空间/旧 API 调用(fork 改造回归);
|
|
4
|
+
* 2) 客户端消费的两条路由形状(snapshot / status)由宿主实测钉住。
|
|
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
|
+
import { fileURLToPath } from 'node:url'
|
|
13
|
+
|
|
14
|
+
process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
|
|
15
|
+
const { SESSION, createHarness, jsonReq, callRoute } = await import('./harness.mjs')
|
|
16
|
+
|
|
17
|
+
// 必须用 fileURLToPath:`new URL(...).pathname` 在 Windows 得到 `/E:/...`(需去前导斜杠),
|
|
18
|
+
// 但 Linux 的 `/` 是根目录,`.replace(/^[/]/,'')` 会把它变成相对路径 → CI 上 ENOENT。
|
|
19
|
+
const clientFile = fileURLToPath(new URL('../client.js', import.meta.url))
|
|
20
|
+
const packageFile = fileURLToPath(new URL('../package.json', import.meta.url))
|
|
21
|
+
|
|
22
|
+
test('client.js 命名空间已切到 union,无 progress-board API 残留', () => {
|
|
23
|
+
const src = fs.readFileSync(clientFile, 'utf8')
|
|
24
|
+
assert.match(src, /id: 'dsh-progress-union'/)
|
|
25
|
+
assert.match(src, /const API = '\/progress-union'/)
|
|
26
|
+
assert.match(src, /STATUS_API = '\/dsh-progress\/status'/)
|
|
27
|
+
assert.doesNotMatch(src, /fetch\(`\/progress-board/, '不得残留旧 API 前缀的直接调用')
|
|
28
|
+
assert.match(src, /useUnionTiming/, '迷你条时间面钩子必须在')
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test('迷你条暂停/继续按钮接线齐全(渲染 + 请求 + 状态门控)', () => {
|
|
32
|
+
const src = fs.readFileSync(clientFile, 'utf8')
|
|
33
|
+
// 渲染:两个按钮都在 dock actions 区
|
|
34
|
+
assert.match(src, /className: 'pb-dock-btn pb-dock-goal pb-dock-goal-pause'/, '暂停按钮必须在')
|
|
35
|
+
assert.match(src, /className: 'pb-dock-btn pb-dock-goal pb-dock-goal-resume'/, '继续按钮必须在')
|
|
36
|
+
// 请求面:走 /progress-union/goal 控制路由
|
|
37
|
+
assert.match(src, /fetch\(`\$\{API\}\/goal`/, '必须调用目标控制路由')
|
|
38
|
+
assert.match(src, /action: 'pause'|onGoalControl\('pause'\)/, '暂停必须接线')
|
|
39
|
+
assert.match(src, /onGoalControl\('resume'\)/, '继续必须接线')
|
|
40
|
+
// 门控:只有目标 active 才给暂停,只有 paused/blocked 才给继续
|
|
41
|
+
assert.match(src, /goalActive = goalPhase === 'active'/, '暂停按钮必须按 phase 门控')
|
|
42
|
+
assert.match(src, /goalStopped = goalPhase === 'paused' \|\| goalPhase === 'blocked'/, '继续按钮必须按 phase 门控')
|
|
43
|
+
// 按钮样式必须真的存在(否则是裸浏览器按钮):背景=主色实心,前景=宿主 on-color 令牌。
|
|
44
|
+
assert.match(src, /\.pb-dock-goal-resume \{[^}]*background: var\(--dsw-alias-brand-primary\)/, '继续按钮需要有主色实心样式')
|
|
45
|
+
assert.match(src, /\.pb-dock-goal-resume \{[^}]*color: var\(--dsw-alias-label-on-color/, '继续按钮前景必须用 on-color 令牌')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('主色实心按钮的前景色不得用 bg-base(玻璃皮肤会把它设成 transparent)', () => {
|
|
49
|
+
const src = fs.readFileSync(clientFile, 'utf8')
|
|
50
|
+
// 事故:maid-atelier 皮肤在 body 上把 --dsw-alias-bg-base 设为 transparent,
|
|
51
|
+
// 拿它当 color 会让「继续」渲染成透明字 → 看着像一块纯色块盖住了按钮。
|
|
52
|
+
assert.doesNotMatch(src, /color:\s*var\(--dsw-alias-bg-base/, '--dsw-alias-bg-base 是页面底色语义,不能当前景色')
|
|
53
|
+
assert.match(src, /\.pb-btn-primary \{[^}]*color: var\(--dsw-alias-label-on-color/, '主按钮前景必须用 on-color 令牌')
|
|
54
|
+
// 选择态底板同样不能用 bg-base(透明后选中段会"消失")。
|
|
55
|
+
assert.doesNotMatch(src, /\[data-on="true"\] \{[^}]*background: var\(--dsw-alias-bg-base/, '分段控件选中态不得用 bg-base 做底板')
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test('目标文案区分「板目标」与宿主 goal,完成态不报时间面', () => {
|
|
59
|
+
const src = fs.readFileSync(clientFile, 'utf8')
|
|
60
|
+
// 官方 GoalBar 与 /progress-goal 是两套状态机,并排在同一 input dock:文案必须能分辨。
|
|
61
|
+
assert.match(src, /goalPaused: '板目标已暂停'/, 'zh 文案需带「板目标」前缀')
|
|
62
|
+
assert.match(src, /goalPaused: 'Board goal paused'/, 'en 文案需带 Board goal 前缀')
|
|
63
|
+
assert.match(src, /独立于宿主的 \/goal/, '悬停提示需说明与宿主 /goal 的关系')
|
|
64
|
+
assert.match(src, /const allDone = summary\.total > 0 && summary\.done === summary\.total/, '完成态需跳过时间面')
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test('W1: 头部入口注册仍在,且带渲染兜底与分面隔离', () => {
|
|
68
|
+
// 仓内文件是 CRLF:多行断言前先归一,否则 \n 永远匹配不到 \r\n。
|
|
69
|
+
const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
|
|
70
|
+
// 入口本体:槽位 + id + 顺序(5 = 排在宿主自带入口之后、其余插件之前,窄窗口不会被裁掉)
|
|
71
|
+
assert.match(src, /name: 'conversation\.session\.header\.utilities'/, '头部工具区槽位注册必须在')
|
|
72
|
+
assert.match(src, /id: 'progress-union-header'/, '头部入口 id 必须在')
|
|
73
|
+
assert.match(src, /order: 5,/, '头部入口顺序必须提前到 5')
|
|
74
|
+
// 渲染兜底:组件抛错只让这一枚消失,不拖垮整排 utilities
|
|
75
|
+
assert.match(src, /class HeaderEntryBoundary extends React\.Component/, '头部入口必须有错误边界')
|
|
76
|
+
assert.match(src, /getDerivedStateFromError/, '错误边界必须真的降级渲染')
|
|
77
|
+
assert.match(src, /function ProgressHeaderButton\(props\) \{\n return h\(HeaderEntryBoundary/, '导出组件必须包在错误边界里')
|
|
78
|
+
// 分面隔离:任一入口注册失败不得中止 apply(否则图标/迷你条/右栏页签一起消失)
|
|
79
|
+
assert.match(src, /const safeEffect = \(label, register\) =>/, '必须有分面隔离助手')
|
|
80
|
+
const safeCalls = src.match(/^\s+safeEffect\($/gm) || []
|
|
81
|
+
assert.equal(safeCalls.length, 6, '六个入口面(设置×2 / 右栏类型 / 右栏面板 / 头部 / 迷你条)都必须经 safeEffect 注册')
|
|
82
|
+
const bare = src.match(/ctx\.effect\(\s*\n\s*\(\) =>\s*\n\s*ctx\.(slots|sidebarRightTabs)/g) || []
|
|
83
|
+
assert.equal(bare.length, 0, '不得残留裸 ctx.effect 入口注册')
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('W2: better-sidebar 页签是独立入口,内容仍是自有板子', () => {
|
|
87
|
+
const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
|
|
88
|
+
assert.match(src, /const BS_TAB_ID = 'dsh-progress-union:board'/, 'better-sidebar 页签 id 必须在')
|
|
89
|
+
assert.doesNotMatch(src, /const BS_TAB_ID = 'progress-union'|const BS_TAB_ID = 'dsh-progress-union'\n/, '页签 id 不得与原生 kind 混用')
|
|
90
|
+
// 服务可能晚于 apply 就绪 → 必须 deferred inject,不能一次性 ctx.get
|
|
91
|
+
assert.match(src, /ctx\.inject\(\['betterSidebar'\], \(bs\) => \{/, '必须用 deferred inject 等待 betterSidebar')
|
|
92
|
+
assert.match(src, /typeof service\.registerTab !== 'function'/, '调用前必须探测 registerTab')
|
|
93
|
+
// 描述符字段齐全
|
|
94
|
+
assert.match(src, /id: BS_TAB_ID,/)
|
|
95
|
+
assert.match(src, /title: \(\) => t\('nav'\),/)
|
|
96
|
+
assert.match(src, /description: \(\) => t\('bsDesc'\),/)
|
|
97
|
+
assert.match(src, /icon: \(size\) => h\(ProgressNavIcon, \{ size: size \|\| 16 \}\)/)
|
|
98
|
+
assert.match(src, /order: 120,/)
|
|
99
|
+
assert.match(src, /single: true,/)
|
|
100
|
+
// 内容是自有板子,且拿到当前会话
|
|
101
|
+
assert.match(src, /h\(ProgressSidePanel, \{/, '页签正文必须是自有 ProgressSidePanel')
|
|
102
|
+
assert.match(src, /sessionId: tabProps && tabProps\.scope \? tabProps\.scope\.sessionId : undefined/)
|
|
103
|
+
// 不传 collapse / toggleFullscreen,避免 better-sidebar 里出现死按钮
|
|
104
|
+
const block = src.slice(src.indexOf("ctx.inject(['betterSidebar']"), src.indexOf("'progress-union: better-sidebar tab'"))
|
|
105
|
+
assert.doesNotMatch(block, /collapse:/, '不得向 better-sidebar 页签传 collapse')
|
|
106
|
+
assert.doesNotMatch(block, /toggleFullscreen:/, '不得向 better-sidebar 页签传 toggleFullscreen')
|
|
107
|
+
// 明确不复用 better-sidebar 的「任务管理」
|
|
108
|
+
assert.doesNotMatch(block, /task.?manage|subagent|后台命令/iu, '不得复用 better-sidebar 的任务管理视图')
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
test('W2: better-sidebar 只是软依赖(未装者必须照常加载)', () => {
|
|
112
|
+
const pkg = JSON.parse(fs.readFileSync(packageFile, 'utf8'))
|
|
113
|
+
const declared = pkg.dsh?.client?.inject ?? []
|
|
114
|
+
assert.equal(declared.includes('dsh-better-sidebar'), false, 'dsh.client.inject 不得声明 dsh-better-sidebar')
|
|
115
|
+
assert.equal('dsh-better-sidebar' in (pkg.dependencies ?? {}), false, 'dependencies 不得声明 dsh-better-sidebar')
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
test('S2: bsDesc 在 zh/en 两个字典里都存在', () => {
|
|
119
|
+
const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
|
|
120
|
+
assert.match(src, /bsDesc: '任务串联的进度板(不是 better-sidebar 的「任务管理」)'/, 'zh 文案必须在')
|
|
121
|
+
assert.match(src, /bsDesc: 'Linked-task progress board \(not better-sidebar task manager\)'/, 'en 文案必须在')
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
test('宿主 snapshot/status 两路由的客户端消费形状', async () => {
|
|
125
|
+
const harness = createHarness()
|
|
126
|
+
await harness.run()
|
|
127
|
+
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
|
|
128
|
+
await harness.toolMap.get('progress_update').definition.execute(
|
|
129
|
+
{ changes: [{ title: '渲染截图', status: 'doing', current: '渲染第 7/24 张' }, { title: '合成音轨' }] },
|
|
130
|
+
{ agent: harness.agent },
|
|
131
|
+
)
|
|
132
|
+
harness.emit('turn/start', {})
|
|
133
|
+
harness.emit('step/start', {})
|
|
134
|
+
|
|
135
|
+
const snap = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
|
|
136
|
+
assert.equal(snap.ok, true)
|
|
137
|
+
assert.equal(snap.enabled, true)
|
|
138
|
+
assert.deepEqual(snap.items.map((i) => i.title), ['渲染截图', '合成音轨'])
|
|
139
|
+
assert.equal(typeof snap.summary.percent, 'number')
|
|
140
|
+
assert.equal('pendingUserChanges' in snap, true)
|
|
141
|
+
|
|
142
|
+
const status = (await callRoute(harness, '/dsh-progress/status', { method: 'GET', url: '/dsh-progress/status', headers: {} })).json()
|
|
143
|
+
assert.equal(status.ok, true)
|
|
144
|
+
assert.equal(status.config.pollMs, 1000)
|
|
145
|
+
assert.ok(status.task, 'status.task 必须存在(迷你条数据源)')
|
|
146
|
+
assert.equal(String(status.task.id), String(SESSION))
|
|
147
|
+
// 板开:阶段直接取板 items,不再走关键词猜测
|
|
148
|
+
assert.deepEqual(status.task.stages, ['渲染截图', '合成音轨'])
|
|
149
|
+
assert.equal(status.task.boardDriven, true)
|
|
150
|
+
assert.equal(status.task.current, 0)
|
|
151
|
+
assert.ok(Array.isArray(status.tasks))
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
test('W3: 板只住在右侧边栏——不再注册主区完整面板', () => {
|
|
155
|
+
// 事故:主区面板没有收拢入口,点进去就回不到会话(进去出不来)。
|
|
156
|
+
const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
|
|
157
|
+
assert.match(src, /const openPanel = \(\) => ctx\.sidebarRight\.openTab\(RIGHT_TAB_KIND\)/, '头部/迷你条入口必须打开右栏页签')
|
|
158
|
+
assert.match(src, /inject: \(\) => \(\{ openPanel, togglePanel \}\)/, '头部入口注入的必须是右栏开关(可见则收起,不可见则打开)')
|
|
159
|
+
assert.doesNotMatch(src, /ctx\.slots\.inject\('main'/, '不得再注册主区完整面板')
|
|
160
|
+
assert.doesNotMatch(src, /layout\.selectPanel/, '不得再切主区面板')
|
|
161
|
+
assert.doesNotMatch(src, /function ProgressPanel\(/, '完整面板组件应已移除')
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
test('W4: 侧栏顶部不再画自带的 全面展开/收起/完整面板 按钮(交给右栏 chrome)', () => {
|
|
165
|
+
// 事故:三个按钮都在,但 toggleFullscreen / collapse 在右栏页签里根本没注入(better-sidebar 里更没处传),
|
|
166
|
+
// 点了没反应才是常态。右栏自身的 chrome 已经有全屏与关闭,不再重复造。
|
|
167
|
+
const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
|
|
168
|
+
assert.doesNotMatch(src, /props\.toggleFullscreen/, '不得再渲染自带的全屏按钮')
|
|
169
|
+
assert.doesNotMatch(src, /props\.collapse/, '不得再渲染自带的收起按钮')
|
|
170
|
+
assert.doesNotMatch(src, /t\('sideFull'\)|t\('sideHalf'\)|t\('sideCollapse'\)/, '三个死按钮的文案不得残留')
|
|
171
|
+
assert.doesNotMatch(src, /toggleFullscreen/, '注入面不得再传全屏切换')
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
test('0.6.2:面板来源行只在 snapshot.restoredFrom 存在时渲染', () => {
|
|
175
|
+
const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
|
|
176
|
+
assert.match(src, /\.pb-side-restore \{/, '来源行样式缺失')
|
|
177
|
+
assert.match(src, /sideRestore: '已从归档 v\{seq\} · rev \{revision\} 恢复,共 \{n\} 项'/, 'zh 文案缺失')
|
|
178
|
+
assert.match(src, /sideRestore: 'Restored from archive/, 'en 文案缺失')
|
|
179
|
+
assert.match(src, /snapshot\?\.restoredFrom\s*\n?\s*\? h\(/, '渲染必须由 restoredFrom 门控')
|
|
180
|
+
assert.match(src, /replace\('\{seq\}', String\(snapshot\.restoredFrom\.seq\)\)/, 'seq 未注入')
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
test('0.6.3:提示卡与用量条间距成体系,且不再出现负 margin', () => {
|
|
184
|
+
const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
|
|
185
|
+
assert.doesNotMatch(src, /margin:\s*-4px/, '不得再有负上边距(用量条顶进提示卡的根因)')
|
|
186
|
+
assert.match(src, /\.pb-llm \{[^}]*margin: 10px 0 12px/, '.pb-llm 下边距必须 12px')
|
|
187
|
+
assert.doesNotMatch(src, /\.pb-llm \{[^}]*margin: 10px 0 0[;}]/, '旧的 0 下边距必须消失')
|
|
188
|
+
assert.match(src, /\.pb-side > \.pb-usage \{[^}]*margin: 0 0 12px/, '用量条上边距必须归零')
|
|
189
|
+
assert.match(src, /\.pb-side > \.pb-llm \+ \.pb-side-error \{ margin-top: 12px; \}/, '同类块相邻补 12px')
|
|
190
|
+
})
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v0.7.0 R1 验收:下载识别(classifyDownload)与板项标记(isDownloadItem)。
|
|
3
|
+
* 口径与 spec 一致:**软感知** —— 词表命中才记,猜不出返回 null;
|
|
4
|
+
* 绝不把 npm test / git status / pip list 这类无网络拉取的动作误判成下载。
|
|
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
|
+
process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-dl-test-'))
|
|
13
|
+
const { SESSION, createHarness, jsonReq, callRoute } = await import('./harness.mjs')
|
|
14
|
+
const { classifyDownload, isDownloadItem, unwrapAct } = await import('../index.js')
|
|
15
|
+
|
|
16
|
+
const sh = (command) => ['bash', JSON.stringify({ command })]
|
|
17
|
+
|
|
18
|
+
test('classifyDownload:安装类命中并取到包名', () => {
|
|
19
|
+
assert.deepEqual(classifyDownload(...sh('npm install lodash'))?.kind, 'install')
|
|
20
|
+
assert.equal(classifyDownload(...sh('npm install lodash')).target, 'lodash')
|
|
21
|
+
assert.equal(classifyDownload(...sh('pnpm add -D vite')).target, 'vite')
|
|
22
|
+
assert.equal(classifyDownload(...sh('yarn add react')).kind, 'install')
|
|
23
|
+
assert.equal(classifyDownload(...sh('pip install requests')).target, 'requests')
|
|
24
|
+
assert.equal(classifyDownload(...sh('uv pip install httpx')).kind, 'install')
|
|
25
|
+
assert.equal(classifyDownload(...sh('brew install ripgrep')).target, 'ripgrep')
|
|
26
|
+
assert.equal(classifyDownload(...sh('cargo add serde')).target, 'serde')
|
|
27
|
+
assert.equal(classifyDownload(...sh('npx create-vite app')).target, 'create-vite')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('classifyDownload:clone / pull / 单一下载器', () => {
|
|
31
|
+
const clone = classifyDownload(...sh('git clone https://github.com/acme/widget.git'))
|
|
32
|
+
assert.equal(clone.kind, 'clone')
|
|
33
|
+
assert.equal(clone.target, 'widget.git')
|
|
34
|
+
assert.equal(classifyDownload(...sh('git pull')).kind, 'clone')
|
|
35
|
+
const pull = classifyDownload(...sh('docker pull nginx:latest'))
|
|
36
|
+
assert.equal(pull.kind, 'pull')
|
|
37
|
+
assert.equal(pull.target, 'nginx:latest')
|
|
38
|
+
assert.equal(classifyDownload(...sh('wget https://host/big.zip')).target, 'big.zip')
|
|
39
|
+
assert.equal(classifyDownload(...sh('curl -O https://mirror/x.tar.gz')).target, 'x.tar.gz')
|
|
40
|
+
assert.equal(classifyDownload(...sh('curl -L https://api.dev/pkg.tgz -o pkg.tgz')).target, 'pkg.tgz')
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
test('classifyDownload:不误判(无网络拉取的动作一律 null)', () => {
|
|
44
|
+
for (const cmd of [
|
|
45
|
+
'npm test', 'npm run dev', 'npm ls', 'npm view foo', 'npm ci --dry-run',
|
|
46
|
+
'git status', 'git log --oneline -5', 'git diff', 'ls -la', 'echo hi',
|
|
47
|
+
'pip list', 'pip show requests', 'pip freeze', 'conda info', 'brew list',
|
|
48
|
+
'cargo build', 'cargo test', 'dotnet test', 'node build.mjs', 'python train.py',
|
|
49
|
+
'grep -rn todo src', 'cat package.json',
|
|
50
|
+
]) {
|
|
51
|
+
assert.equal(classifyDownload(...sh(cmd)), null, `不得把「${cmd}」当下载`)
|
|
52
|
+
}
|
|
53
|
+
assert.equal(classifyDownload('todo_write', JSON.stringify({ todos: [] })), null)
|
|
54
|
+
assert.equal(classifyDownload('read', JSON.stringify({ file_path: 'a.md' })), null)
|
|
55
|
+
assert.equal(classifyDownload('bash', JSON.stringify({})), null)
|
|
56
|
+
assert.equal(classifyDownload(undefined, undefined), null)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
test('classifyDownload:后台线索(工具名 / & / nohup / --detach / detached 参数)', () => {
|
|
60
|
+
assert.equal(classifyDownload(...sh('npm install heavy-dep &')).background, true)
|
|
61
|
+
assert.equal(classifyDownload(...sh('nohup pip install torch > log.txt 2>&1 &')).background, true)
|
|
62
|
+
assert.equal(classifyDownload(...sh('docker pull big/image --detach')).background, true)
|
|
63
|
+
assert.equal(classifyDownload('exec_background', JSON.stringify({ command: 'wget https://h/f.bin' })).background, true)
|
|
64
|
+
assert.equal(classifyDownload('bash', JSON.stringify({ command: 'wget https://h/f.bin', detached: true })).background, true)
|
|
65
|
+
// 前台的 & 只在该段真是命令时才生效:`a && b` 不得判成后台
|
|
66
|
+
assert.equal(classifyDownload(...sh('npm ci && npm test')).background, false)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
test('classifyDownload + unwrapAct:act 包装透传到内层工具', () => {
|
|
70
|
+
const wrapped = ['act', JSON.stringify({ tool: 'bash', input: { command: 'npm i left-pad' } })]
|
|
71
|
+
const hit = classifyDownload(...wrapped)
|
|
72
|
+
assert.equal(hit?.kind, 'install')
|
|
73
|
+
assert.equal(hit.target, 'left-pad')
|
|
74
|
+
assert.deepEqual(unwrapAct('act', JSON.stringify({ tool: 'read', input: { file_path: 'x' } })), {
|
|
75
|
+
name: 'read', argsRaw: JSON.stringify({ file_path: 'x' }),
|
|
76
|
+
})
|
|
77
|
+
// 非 act 工具原样返回,不做二次展开
|
|
78
|
+
assert.deepEqual(unwrapAct('bash', '{"command":"ls"}'), { name: 'bash', argsRaw: '{"command":"ls"}' })
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
test('classifyDownload:非 shell 通道的下载工具名', () => {
|
|
82
|
+
const hit = classifyDownload('download_file', JSON.stringify({ url: 'https://cdn/a.iso' }))
|
|
83
|
+
assert.equal(hit.kind, 'download')
|
|
84
|
+
assert.equal(hit.target, 'a.iso')
|
|
85
|
+
assert.equal(classifyDownload('download', JSON.stringify({})), null, '拿不到目标就不记')
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
test('isDownloadItem:分组词与标题动词命中', () => {
|
|
89
|
+
assert.equal(isDownloadItem({ group: 'download', title: '拉模型' }), true)
|
|
90
|
+
assert.equal(isDownloadItem({ group: 'deps-install', title: '装依赖' }), true)
|
|
91
|
+
assert.equal(isDownloadItem({ title: 'git clone 主仓' }), true)
|
|
92
|
+
assert.equal(isDownloadItem({ title: 'Install python deps' }), true)
|
|
93
|
+
assert.equal(isDownloadItem({ title: '渲染截图' }), false)
|
|
94
|
+
assert.equal(isDownloadItem({ group: 'release', title: '发包到 npm' }), false)
|
|
95
|
+
assert.equal(isDownloadItem(null), false)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
// —— 接线面:recordTool 命中 → 观察块出 ⬇ 行 + 快照 download 字段 ——
|
|
99
|
+
|
|
100
|
+
async function booted() {
|
|
101
|
+
const harness = createHarness()
|
|
102
|
+
await harness.run()
|
|
103
|
+
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
|
|
104
|
+
await harness.toolMap.get('progress_update').definition.execute(
|
|
105
|
+
{ changes: [{ title: '拉取素材', status: 'doing' }, { title: '合成音轨', status: 'todo' }] },
|
|
106
|
+
{ agent: harness.agent },
|
|
107
|
+
)
|
|
108
|
+
return harness
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function observerText(harness) {
|
|
112
|
+
return harness.contexts.get('progress-union-observer')()
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async function snapshot(harness) {
|
|
116
|
+
const res = await callRoute(harness, '/progress-union/snapshot', {
|
|
117
|
+
method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {},
|
|
118
|
+
})
|
|
119
|
+
return res.json()
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
test('观察块:下载中出现一行,板无下载项时追催办子句', async () => {
|
|
123
|
+
const harness = await booted()
|
|
124
|
+
// 板上的 doing 项是「拉取素材」→ 标题不含下载动词,仍算没挂上:催办子句应出现
|
|
125
|
+
harness.emit('tool/call', { name: 'bash', callId: 'c1', arguments: JSON.stringify({ command: 'wget https://cdn/x.zip' }) })
|
|
126
|
+
const text = observerText(harness)
|
|
127
|
+
assert.match(text, /⬇ 下载中:x\.zip/, text)
|
|
128
|
+
assert.match(text, /板上没有对应的 doing 下载项/, text)
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
test('观察块:板上有 doing 下载项时不催办', async () => {
|
|
132
|
+
const harness = await booted()
|
|
133
|
+
await harness.toolMap.get('progress_update').definition.execute(
|
|
134
|
+
{ changes: [{ title: 'wget 拉取素材包', status: 'doing' }] },
|
|
135
|
+
{ agent: harness.agent },
|
|
136
|
+
)
|
|
137
|
+
harness.emit('tool/call', { name: 'bash', callId: 'c1', arguments: JSON.stringify({ command: 'wget https://cdn/x.zip' }) })
|
|
138
|
+
const text = observerText(harness)
|
|
139
|
+
assert.match(text, /⬇ 下载中:x\.zip/, text)
|
|
140
|
+
assert.doesNotMatch(text, /板上没有对应的 doing 下载项/, text)
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
test('观察块:download.enabled=false 时整行消失(逐字退回 0.6.x)', async () => {
|
|
144
|
+
const harness = createHarness({ config: { download: { enabled: false } } })
|
|
145
|
+
await harness.run()
|
|
146
|
+
await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
|
|
147
|
+
harness.emit('tool/call', { name: 'bash', callId: 'c1', arguments: JSON.stringify({ command: 'wget https://cdn/x.zip' }) })
|
|
148
|
+
const text = observerText(harness)
|
|
149
|
+
assert.doesNotMatch(text, /⬇/, 'download.enabled=false 必须逐字退回 0.6.x 观察块')
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
test('快照 download:elapsed 档(只有动作记录时 percent 为 null,不假扮进度)', async () => {
|
|
153
|
+
const harness = await booted()
|
|
154
|
+
harness.emit('tool/call', { name: 'bash', callId: 'c9', arguments: JSON.stringify({ command: 'git clone https://github.com/a/b.git' }) })
|
|
155
|
+
const dl = (await snapshot(harness)).download
|
|
156
|
+
assert.equal(dl.active, true)
|
|
157
|
+
assert.equal(dl.basis, 'elapsed')
|
|
158
|
+
assert.equal(dl.kind, 'clone')
|
|
159
|
+
assert.equal(dl.target, 'b.git')
|
|
160
|
+
assert.equal(dl.percent, null)
|
|
161
|
+
assert.equal(dl.background, false)
|
|
162
|
+
assert.deepEqual(Object.keys(dl).sort(), ['active', 'basis', 'bytes', 'elapsedSec', 'kind', 'percent', 'target', 'background'].sort())
|
|
163
|
+
assert.ok(Object.keys(dl).length <= 8, 'download 键数必须 ≤8')
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
test('快照 download:stdout 档优先于板项(tool/result 带真值)', async () => {
|
|
167
|
+
const harness = await booted()
|
|
168
|
+
harness.emit('tool/call', { name: 'bash', callId: 'c2', arguments: JSON.stringify({ command: 'wget https://cdn/x.zip' }) })
|
|
169
|
+
harness.emit('tool/result', {
|
|
170
|
+
callId: 'c2',
|
|
171
|
+
message: { toolCallId: 'c2', toolName: 'bash', content: [{ type: 'text', text: 'x.zip 45% [====> ] 12.3MB/27.8MB 4.1MB/s' }] },
|
|
172
|
+
})
|
|
173
|
+
const dl = (await snapshot(harness)).download
|
|
174
|
+
assert.equal(dl.basis, 'stdout')
|
|
175
|
+
assert.equal(dl.percent, 45)
|
|
176
|
+
assert.equal(dl.bytes, '12.3MB/27.8MB')
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
test('快照 download:无下载时是稳定的非激活对象(前端可无条件读)', async () => {
|
|
180
|
+
const harness = await booted()
|
|
181
|
+
const dl = (await snapshot(harness)).download
|
|
182
|
+
assert.deepEqual(dl, { active: false, basis: '', kind: '', target: '', percent: null, bytes: '', background: false, elapsedSec: 0 })
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
test('快照 items 追加 isDownload(老字段不动)', async () => {
|
|
186
|
+
const harness = await booted()
|
|
187
|
+
await harness.toolMap.get('progress_update').definition.execute(
|
|
188
|
+
{ changes: [{ title: 'npm install 依赖', status: 'todo', group: 'deps' }] },
|
|
189
|
+
{ agent: harness.agent },
|
|
190
|
+
)
|
|
191
|
+
const snap = await snapshot(harness)
|
|
192
|
+
const byTitle = new Map(snap.items.map((i) => [i.title, i]))
|
|
193
|
+
assert.equal(byTitle.get('npm install 依赖').isDownload, true)
|
|
194
|
+
assert.equal(byTitle.get('拉取素材').isDownload, false, '中文标题不靠语义猜,只认词表')
|
|
195
|
+
assert.ok(Object.keys(byTitle.get('拉取素材')).includes('isDownload'), '只追加字段')
|
|
196
|
+
for (const key of ['id', 'title', 'status', 'percent', 'current', 'next', 'approach', 'note', 'group', 'order', 'updatedAt', 'updatedBy']) {
|
|
197
|
+
assert.ok(Object.keys(snap.items[0]).includes(key), `老字段 ${key} 不得丢`)
|
|
198
|
+
}
|
|
199
|
+
})
|