dsh-progress-union 0.9.0 → 0.9.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 +628 -628
- package/LICENSE +21 -21
- package/README.md +395 -395
- package/anchor.js +39 -39
- package/client.js +3828 -3828
- 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 +6165 -6119
- package/package.json +16 -6
- package/test/anchor.test.mjs +139 -139
- package/test/assistant.test.mjs +214 -214
- package/test/client.test.mjs +479 -479
- package/test/download-classify.test.mjs +284 -284
- 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/major-change-notice.test.mjs +174 -174
- package/test/observer.test.mjs +170 -170
- package/test/ops.test.mjs +638 -638
- package/test/parse-progress.test.mjs +78 -78
- package/test/restore-hydrate.test.mjs +185 -185
- package/test/settings.test.mjs +253 -253
- 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/tool-gloss.test.mjs +137 -137
|
@@ -1,284 +1,284 @@
|
|
|
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
|
-
})
|
|
200
|
-
|
|
201
|
-
// ── Windows 宿主实测形状(v0.7.3)───────────────────────────────────
|
|
202
|
-
// 真机回灌:DSH 0.2.2 沙箱的 Bash 工具实落 pwsh,命令名带 .exe / 路径前缀,
|
|
203
|
-
// 只认 POSIX 首词时 `curl.exe -L -o …` 整条漏识别(子条根本不出现)。
|
|
204
|
-
|
|
205
|
-
test('classifyDownload:Windows 形态的 .exe / 绝对路径首词照样识别', () => {
|
|
206
|
-
const a = classifyDownload(...sh('New-Item -ItemType Directory -Force -Path dl072; curl.exe -L -o dl072/node.tar.gz https://nodejs.org/dist/v22.12.0/node-v22.12.0.tar.gz'))
|
|
207
|
-
assert.equal(a?.kind, 'download', '复合命令里带 curl.exe 的那一段必须被抓到')
|
|
208
|
-
assert.equal(a.target, 'node.tar.gz')
|
|
209
|
-
assert.equal(classifyDownload(...sh('C:\\Windows\\System32\\curl.exe -O https://example.com/a.bin')).kind, 'download')
|
|
210
|
-
assert.equal(classifyDownload(...sh('/mingw64/bin/git.exe clone https://github.com/a/b')).kind, 'clone')
|
|
211
|
-
assert.equal(classifyDownload(...sh('WGET.EXE -q https://example.com/x')).kind, 'download')
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
test('classifyDownload:pwsh/cmd 包层的引号体不再漏识别', () => {
|
|
215
|
-
assert.equal(classifyDownload(...sh('pwsh -Command "curl.exe -L -o out.bin https://example.com/out.bin"')).kind, 'download')
|
|
216
|
-
assert.equal(classifyDownload(...sh('powershell -Command "Invoke-WebRequest -Uri https://example.com/f.zip -OutFile f.zip"')).kind, 'download')
|
|
217
|
-
assert.equal(classifyDownload(...sh('cmd /c "wget -qO- https://example.com/y"')).kind, 'download')
|
|
218
|
-
assert.equal(classifyDownload(...sh('sh -c \'npm install left-pad\'')).kind, 'install')
|
|
219
|
-
})
|
|
220
|
-
|
|
221
|
-
test('classifyDownload:PowerShell 自有下载 cmdlet 入表', () => {
|
|
222
|
-
assert.equal(classifyDownload(...sh('Invoke-WebRequest -Uri https://example.com/big.iso -OutFile big.iso')).kind, 'download')
|
|
223
|
-
assert.equal(classifyDownload(...sh('iwr https://example.com/a -OutFile a.txt')).target, 'a', 'URL 在前时目标取 URL 末段')
|
|
224
|
-
assert.equal(classifyDownload(...sh('iwr -Uri https://example.com/big.iso -OutFile big.iso')).target, 'big.iso', '-OutFile 显式给目标时用文件名')
|
|
225
|
-
assert.equal(classifyDownload(...sh('Start-BitsTransfer -Source https://example.com/b -Destination b.bin')).kind, 'download')
|
|
226
|
-
})
|
|
227
|
-
|
|
228
|
-
test('classifyDownload:Windows 形状不得误判(无拉取语义的 pwsh 命令仍返回 null)', () => {
|
|
229
|
-
for (const cmd of [
|
|
230
|
-
'pwsh -Command "Get-Process | Select-Object -First 5"',
|
|
231
|
-
'curl.exe -s -X POST https://example.com/api -d \'{}\'',
|
|
232
|
-
'Invoke-WebRequest -Uri https://example.com/page',
|
|
233
|
-
'git.exe status --short',
|
|
234
|
-
'New-Item -ItemType Directory out',
|
|
235
|
-
]) {
|
|
236
|
-
const r = classifyDownload(...sh(cmd))
|
|
237
|
-
if (cmd === 'curl.exe -s -X POST https://example.com/api -d \'{}\'' || cmd === 'Invoke-WebRequest -Uri https://example.com/page') {
|
|
238
|
-
// 拉取器就是单一动词,这两条允许命中(与 POSIX 口径一致),但不许是 install 型误判。
|
|
239
|
-
assert.ok(!r || r.kind !== 'install', cmd)
|
|
240
|
-
continue
|
|
241
|
-
}
|
|
242
|
-
assert.equal(r, null, `不该误判成下载:${cmd}`)
|
|
243
|
-
}
|
|
244
|
-
})
|
|
245
|
-
|
|
246
|
-
test('glossCommand:Windows 命令名给人话而不是退回 Bash×n', async () => {
|
|
247
|
-
const { glossCommand } = await import('../index.js')
|
|
248
|
-
assert.match(glossCommand('curl.exe -L -o a.bin https://x/a.bin'), /发 HTTP 请求|下载/)
|
|
249
|
-
assert.match(glossCommand('Invoke-WebRequest -Uri https://x -OutFile y'), /下载文件/)
|
|
250
|
-
assert.match(glossCommand('git.exe clone https://github.com/a/b'), /克隆|拉取/)
|
|
251
|
-
})
|
|
252
|
-
|
|
253
|
-
// ── v0.7.4:工具名本身是解释器(宿主实测报成 `pwsh` 而不是 `Bash`)──
|
|
254
|
-
// 0.7.3 只修了命令词表,但 isShell 这道门在上一行就把整条判成非 shell,
|
|
255
|
-
// 所以下面这些形状在 0.7.3 上依旧全漏——这两个用例就是那次的真机回灌。
|
|
256
|
-
test('classifyDownload:工具名为 pwsh/powershell 时不再被 isShell 门拦下', () => {
|
|
257
|
-
const pwsh = (command) => ['pwsh', JSON.stringify({ command })]
|
|
258
|
-
const real = 'New-Item -ItemType Directory -Force -Path dl073 | Out-Null; curl.exe -L -o dl073/echarts.tgz http://registry.npmmirror.com/echarts/-/echarts-5.5.0.tgz'
|
|
259
|
-
const hit = classifyDownload(...pwsh(real))
|
|
260
|
-
assert.equal(hit?.kind, 'download', 'pwsh 工具名 + 分号后的 curl.exe 必须命中')
|
|
261
|
-
assert.equal(hit.target, 'echarts.tgz')
|
|
262
|
-
|
|
263
|
-
assert.equal(classifyDownload(...pwsh('wget https://example.com/a.bin')).kind, 'download')
|
|
264
|
-
const p2 = ['powershell', JSON.stringify({ command: 'Invoke-WebRequest -Uri https://example.com/files/big.iso -OutFile big.iso' })]
|
|
265
|
-
assert.equal(classifyDownload(...p2).target, 'big.iso')
|
|
266
|
-
const p3 = ['C:\\Program Files\\PowerShell\\7\\pwsh.exe', JSON.stringify({ command: 'git.exe clone https://github.com/a/b' })]
|
|
267
|
-
assert.equal(classifyDownload(...p3).kind, 'clone')
|
|
268
|
-
assert.equal(classifyDownload(...pwsh('npm install lodash')).kind, 'install')
|
|
269
|
-
})
|
|
270
|
-
|
|
271
|
-
test('classifyDownload:解释器名不得把非 shell 工具变成 shell', () => {
|
|
272
|
-
// read/search 这类工具名不在词表里,带了 command 字段也不许当下载通道。
|
|
273
|
-
assert.equal(classifyDownload('read_file', JSON.stringify({ command: 'curl -O https://x/a.bin' })), null)
|
|
274
|
-
assert.equal(classifyDownload('mcp__tools__fetch', JSON.stringify({ command: 'wget https://x/a.bin' })), null)
|
|
275
|
-
// 解释器名但拿不出命令文本 → 仍然 null,不臆造。
|
|
276
|
-
assert.equal(classifyDownload('pwsh', JSON.stringify({})), null)
|
|
277
|
-
})
|
|
278
|
-
|
|
279
|
-
test('describeToolStep:pwsh 工具名走 shell 分支而不是退回空串', async () => {
|
|
280
|
-
const { describeToolStep } = await import('../index.js')
|
|
281
|
-
const step = describeToolStep('pwsh', JSON.stringify({ command: 'New-Item -ItemType Directory -Force -Path d1 | Out-Null; curl.exe -L -o a.bin http://x/a.bin' }), 46)
|
|
282
|
-
assert.ok(step, 'pwsh 形态必须有人话')
|
|
283
|
-
assert.match(step, /建目录或文件|发 HTTP 请求|下载/)
|
|
284
|
-
})
|
|
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
|
+
})
|
|
200
|
+
|
|
201
|
+
// ── Windows 宿主实测形状(v0.7.3)───────────────────────────────────
|
|
202
|
+
// 真机回灌:DSH 0.2.2 沙箱的 Bash 工具实落 pwsh,命令名带 .exe / 路径前缀,
|
|
203
|
+
// 只认 POSIX 首词时 `curl.exe -L -o …` 整条漏识别(子条根本不出现)。
|
|
204
|
+
|
|
205
|
+
test('classifyDownload:Windows 形态的 .exe / 绝对路径首词照样识别', () => {
|
|
206
|
+
const a = classifyDownload(...sh('New-Item -ItemType Directory -Force -Path dl072; curl.exe -L -o dl072/node.tar.gz https://nodejs.org/dist/v22.12.0/node-v22.12.0.tar.gz'))
|
|
207
|
+
assert.equal(a?.kind, 'download', '复合命令里带 curl.exe 的那一段必须被抓到')
|
|
208
|
+
assert.equal(a.target, 'node.tar.gz')
|
|
209
|
+
assert.equal(classifyDownload(...sh('C:\\Windows\\System32\\curl.exe -O https://example.com/a.bin')).kind, 'download')
|
|
210
|
+
assert.equal(classifyDownload(...sh('/mingw64/bin/git.exe clone https://github.com/a/b')).kind, 'clone')
|
|
211
|
+
assert.equal(classifyDownload(...sh('WGET.EXE -q https://example.com/x')).kind, 'download')
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
test('classifyDownload:pwsh/cmd 包层的引号体不再漏识别', () => {
|
|
215
|
+
assert.equal(classifyDownload(...sh('pwsh -Command "curl.exe -L -o out.bin https://example.com/out.bin"')).kind, 'download')
|
|
216
|
+
assert.equal(classifyDownload(...sh('powershell -Command "Invoke-WebRequest -Uri https://example.com/f.zip -OutFile f.zip"')).kind, 'download')
|
|
217
|
+
assert.equal(classifyDownload(...sh('cmd /c "wget -qO- https://example.com/y"')).kind, 'download')
|
|
218
|
+
assert.equal(classifyDownload(...sh('sh -c \'npm install left-pad\'')).kind, 'install')
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
test('classifyDownload:PowerShell 自有下载 cmdlet 入表', () => {
|
|
222
|
+
assert.equal(classifyDownload(...sh('Invoke-WebRequest -Uri https://example.com/big.iso -OutFile big.iso')).kind, 'download')
|
|
223
|
+
assert.equal(classifyDownload(...sh('iwr https://example.com/a -OutFile a.txt')).target, 'a', 'URL 在前时目标取 URL 末段')
|
|
224
|
+
assert.equal(classifyDownload(...sh('iwr -Uri https://example.com/big.iso -OutFile big.iso')).target, 'big.iso', '-OutFile 显式给目标时用文件名')
|
|
225
|
+
assert.equal(classifyDownload(...sh('Start-BitsTransfer -Source https://example.com/b -Destination b.bin')).kind, 'download')
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
test('classifyDownload:Windows 形状不得误判(无拉取语义的 pwsh 命令仍返回 null)', () => {
|
|
229
|
+
for (const cmd of [
|
|
230
|
+
'pwsh -Command "Get-Process | Select-Object -First 5"',
|
|
231
|
+
'curl.exe -s -X POST https://example.com/api -d \'{}\'',
|
|
232
|
+
'Invoke-WebRequest -Uri https://example.com/page',
|
|
233
|
+
'git.exe status --short',
|
|
234
|
+
'New-Item -ItemType Directory out',
|
|
235
|
+
]) {
|
|
236
|
+
const r = classifyDownload(...sh(cmd))
|
|
237
|
+
if (cmd === 'curl.exe -s -X POST https://example.com/api -d \'{}\'' || cmd === 'Invoke-WebRequest -Uri https://example.com/page') {
|
|
238
|
+
// 拉取器就是单一动词,这两条允许命中(与 POSIX 口径一致),但不许是 install 型误判。
|
|
239
|
+
assert.ok(!r || r.kind !== 'install', cmd)
|
|
240
|
+
continue
|
|
241
|
+
}
|
|
242
|
+
assert.equal(r, null, `不该误判成下载:${cmd}`)
|
|
243
|
+
}
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
test('glossCommand:Windows 命令名给人话而不是退回 Bash×n', async () => {
|
|
247
|
+
const { glossCommand } = await import('../index.js')
|
|
248
|
+
assert.match(glossCommand('curl.exe -L -o a.bin https://x/a.bin'), /发 HTTP 请求|下载/)
|
|
249
|
+
assert.match(glossCommand('Invoke-WebRequest -Uri https://x -OutFile y'), /下载文件/)
|
|
250
|
+
assert.match(glossCommand('git.exe clone https://github.com/a/b'), /克隆|拉取/)
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
// ── v0.7.4:工具名本身是解释器(宿主实测报成 `pwsh` 而不是 `Bash`)──
|
|
254
|
+
// 0.7.3 只修了命令词表,但 isShell 这道门在上一行就把整条判成非 shell,
|
|
255
|
+
// 所以下面这些形状在 0.7.3 上依旧全漏——这两个用例就是那次的真机回灌。
|
|
256
|
+
test('classifyDownload:工具名为 pwsh/powershell 时不再被 isShell 门拦下', () => {
|
|
257
|
+
const pwsh = (command) => ['pwsh', JSON.stringify({ command })]
|
|
258
|
+
const real = 'New-Item -ItemType Directory -Force -Path dl073 | Out-Null; curl.exe -L -o dl073/echarts.tgz http://registry.npmmirror.com/echarts/-/echarts-5.5.0.tgz'
|
|
259
|
+
const hit = classifyDownload(...pwsh(real))
|
|
260
|
+
assert.equal(hit?.kind, 'download', 'pwsh 工具名 + 分号后的 curl.exe 必须命中')
|
|
261
|
+
assert.equal(hit.target, 'echarts.tgz')
|
|
262
|
+
|
|
263
|
+
assert.equal(classifyDownload(...pwsh('wget https://example.com/a.bin')).kind, 'download')
|
|
264
|
+
const p2 = ['powershell', JSON.stringify({ command: 'Invoke-WebRequest -Uri https://example.com/files/big.iso -OutFile big.iso' })]
|
|
265
|
+
assert.equal(classifyDownload(...p2).target, 'big.iso')
|
|
266
|
+
const p3 = ['C:\\Program Files\\PowerShell\\7\\pwsh.exe', JSON.stringify({ command: 'git.exe clone https://github.com/a/b' })]
|
|
267
|
+
assert.equal(classifyDownload(...p3).kind, 'clone')
|
|
268
|
+
assert.equal(classifyDownload(...pwsh('npm install lodash')).kind, 'install')
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
test('classifyDownload:解释器名不得把非 shell 工具变成 shell', () => {
|
|
272
|
+
// read/search 这类工具名不在词表里,带了 command 字段也不许当下载通道。
|
|
273
|
+
assert.equal(classifyDownload('read_file', JSON.stringify({ command: 'curl -O https://x/a.bin' })), null)
|
|
274
|
+
assert.equal(classifyDownload('mcp__tools__fetch', JSON.stringify({ command: 'wget https://x/a.bin' })), null)
|
|
275
|
+
// 解释器名但拿不出命令文本 → 仍然 null,不臆造。
|
|
276
|
+
assert.equal(classifyDownload('pwsh', JSON.stringify({})), null)
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
test('describeToolStep:pwsh 工具名走 shell 分支而不是退回空串', async () => {
|
|
280
|
+
const { describeToolStep } = await import('../index.js')
|
|
281
|
+
const step = describeToolStep('pwsh', JSON.stringify({ command: 'New-Item -ItemType Directory -Force -Path d1 | Out-Null; curl.exe -L -o a.bin http://x/a.bin' }), 46)
|
|
282
|
+
assert.ok(step, 'pwsh 形态必须有人话')
|
|
283
|
+
assert.match(step, /建目录或文件|发 HTTP 请求|下载/)
|
|
284
|
+
})
|