Skip to content

Commit 4903f54

Browse files
claude-code-bestglm-5.2
andcommitted
chore(workflow): 工作流相关代码中文文案全部英文化
源码(src/workflow/ + packages/workflow-engine/src/)的中文注释、 用户可见错误消息、字符串字面量;测试文件的标题与注释;同步 6 条 硬编码断言到英文化后的错误消息。 Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
1 parent 490714d commit 4903f54

71 files changed

Lines changed: 1091 additions & 1077 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/workflow-engine/src/__tests__/WorkflowTool.test.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function mockPorts(
4848
return { ports, events, runStatus }
4949
}
5050

51-
test('call 返回 launch 消息并在后台完成', async () => {
51+
test('call returns launch message and completes in background', async () => {
5252
const dir = await mkdtemp(join(tmpdir(), 'wf-tool-'))
5353
try {
5454
const { ports, runStatus } = mockPorts(
@@ -74,7 +74,7 @@ test('call 返回 launch 消息并在后台完成', async () => {
7474
}
7575
})
7676

77-
test('inline script 持久化到 run 目录,返回真实 scriptPath', async () => {
77+
test('inline script persists to run directory, returns real scriptPath', async () => {
7878
const dir = await mkdtemp(join(tmpdir(), 'wf-tool-'))
7979
try {
8080
const { ports } = mockPorts(
@@ -102,7 +102,7 @@ test('inline script 持久化到 run 目录,返回真实 scriptPath', async ()
102102
}
103103
})
104104

105-
test('缺少 script/name/scriptPath → 返回错误(不进后台)', async () => {
105+
test('missing script/name/scriptPath → returns error (does not enter background)', async () => {
106106
const dir = await mkdtemp(join(tmpdir(), 'wf-tool-'))
107107
try {
108108
const { ports, runStatus } = mockPorts(dir, new Map())
@@ -115,7 +115,7 @@ test('缺少 script/name/scriptPath → 返回错误(不进后台)', async (
115115
}
116116
})
117117

118-
test('脚本语法错 → 返回校验错误(不进后台)', async () => {
118+
test('script syntax error → returns validation error (does not enter background)', async () => {
119119
const dir = await mkdtemp(join(tmpdir(), 'wf-tool-'))
120120
try {
121121
const { ports, runStatus } = mockPorts(dir, new Map())
@@ -126,14 +126,14 @@ test('脚本语法错 → 返回校验错误(不进后台)', async () => {
126126
undefined,
127127
undefined,
128128
)
129-
expect(res.data.output).toMatch(/|Error/)
129+
expect(res.data.output).toMatch(/validation failed|Error/i)
130130
expect(runStatus.size).toBe(0)
131131
} finally {
132132
await rm(dir, { recursive: true, force: true })
133133
}
134134
})
135135

136-
test('name 解析到 .claude/workflows/<name>.ts', async () => {
136+
test('name resolves to .claude/workflows/<name>.ts', async () => {
137137
const dir = await mkdtemp(join(tmpdir(), 'wf-tool-'))
138138
try {
139139
await mkdir(join(dir, '.claude', 'workflows'), { recursive: true })
@@ -180,7 +180,7 @@ test('renderToolUseMessage / mapToolResultToToolResultBlockParam', () => {
180180
expect(block.content[0]!.text).toBe('hi')
181181
})
182182

183-
test('scriptPath 解析到文件内容并后台执行', async () => {
183+
test('scriptPath resolves to file content and runs in background', async () => {
184184
const dir = await mkdtemp(join(tmpdir(), 'wf-tool-'))
185185
try {
186186
const scriptFile = join(dir, 'external.ts')
@@ -209,7 +209,7 @@ test('scriptPath 解析到文件内容并后台执行', async () => {
209209
}
210210
})
211211

212-
test('脚本运行时失败 → onFinish 路由到 fail', async () => {
212+
test('script runtime failure → onFinish routes to fail', async () => {
213213
const dir = await mkdtemp(join(tmpdir(), 'wf-tool-'))
214214
try {
215215
const { ports, runStatus } = mockPorts(dir, new Map())
@@ -229,7 +229,7 @@ test('脚本运行时失败 → onFinish 路由到 fail', async () => {
229229
}
230230
})
231231

232-
test('元数据方法:description/prompt/renderToolUseMessage', async () => {
232+
test('metadata methods: description/prompt/renderToolUseMessage', async () => {
233233
const { ports } = mockPorts('/tmp', new Map())
234234
const tool = createWorkflowTool(ports)
235235
expect(tool.isEnabled()).toBe(true)
@@ -242,7 +242,7 @@ test('元数据方法:description/prompt/renderToolUseMessage', async () => {
242242
)
243243
})
244244

245-
test('prompt 包含默认并发 3 + AskUserQuestion 指引', async () => {
245+
test('prompt includes default concurrency 3 + AskUserQuestion guidance', async () => {
246246
const { ports } = mockPorts('/tmp', new Map())
247247
const tool = createWorkflowTool(ports)
248248
const p = await tool.prompt()
@@ -251,7 +251,7 @@ test('prompt 包含默认并发 3 + AskUserQuestion 指引', async () => {
251251
expect(p).toMatch(/AskUserQuestion/i)
252252
})
253253

254-
test('name 不存在 → 返回错误(不进后台)', async () => {
254+
test('name does not exist → returns error (does not enter background)', async () => {
255255
const dir = await mkdtemp(join(tmpdir(), 'wf-tool-'))
256256
try {
257257
await mkdir(join(dir, '.claude', 'workflows'), { recursive: true })
@@ -270,7 +270,7 @@ test('name 不存在 → 返回错误(不进后台)', async () => {
270270
}
271271
})
272272

273-
test('workflow 被 abort → onFinish 路由 kill', async () => {
273+
test('workflow aborted → onFinish routes to kill', async () => {
274274
const dir = await mkdtemp(join(tmpdir(), 'wf-tool-'))
275275
try {
276276
const runStatus = new Map<string, string>()
@@ -321,7 +321,7 @@ test('workflow 被 abort → onFinish 路由 kill', async () => {
321321
}
322322
})
323323

324-
test('args JSON 字符串化的对象时防御性 parse(向后兼容旧 z.string() 契约)', async () => {
324+
test('args defensively parses when a JSON-stringified object (backward compatible with old z.string() contract)', async () => {
325325
const dir = await mkdtemp(join(tmpdir(), 'wf-tool-'))
326326
try {
327327
const capturedPrompts: unknown[] = []
@@ -360,7 +360,7 @@ test('args 为 JSON 字符串化的对象时防御性 parse(向后兼容旧 z.
360360
await tool.call(
361361
{
362362
script: `return agent(args.commit)`,
363-
// 模拟旧契约下模型发送的字符串化 JSON
363+
// simulate stringified JSON sent by model under old contract
364364
args: '{"commit":"abc123"}',
365365
},
366366
undefined,
@@ -370,15 +370,15 @@ test('args 为 JSON 字符串化的对象时防御性 parse(向后兼容旧 z.
370370
await new Promise(r => {
371371
setTimeout(r, 50)
372372
})
373-
// args 未归一化:args.commit === undefinedstring 上无 commit 属性)
374-
// args 归一化:args.commit === 'abc123'
373+
// if args not normalized: args.commit === undefined (string has no commit property)
374+
// if args normalized: args.commit === 'abc123'
375375
expect(capturedPrompts).toContain('abc123')
376376
} finally {
377377
await rm(dir, { recursive: true, force: true })
378378
}
379379
})
380380

381-
test('args 为非合法 JSON 字符串时保持原值不抛', async () => {
381+
test('args keeps original value for non-legal JSON string without throwing', async () => {
382382
const dir = await mkdtemp(join(tmpdir(), 'wf-tool-'))
383383
try {
384384
const capturedPrompts: unknown[] = []
@@ -416,7 +416,7 @@ test('args 为非合法 JSON 字符串时保持原值不抛', async () => {
416416
const tool = createWorkflowTool(ports)
417417
await tool.call(
418418
{
419-
// 脚本把 args 当字符串用:agent(args) → agent('hello')
419+
// script uses args as a string: agent(args) → agent('hello')
420420
script: `return agent(args)`,
421421
args: 'hello',
422422
},
@@ -427,22 +427,22 @@ test('args 为非合法 JSON 字符串时保持原值不抛', async () => {
427427
await new Promise(r => {
428428
setTimeout(r, 50)
429429
})
430-
// 'hello' 不是合法 JSON,应保持为字符串
430+
// 'hello' is not valid JSON, should be kept as a string
431431
expect(capturedPrompts).toContain('hello')
432432
} finally {
433433
await rm(dir, { recursive: true, force: true })
434434
}
435435
})
436436

437-
test('scriptPath 越界(resolve 后在 cwd 之外)→ 拒绝并报错(防任意文件读)', async () => {
437+
test('scriptPath out of bounds (resolved outside cwd) → rejected with error (prevents arbitrary file read)', async () => {
438438
const dir = await mkdtemp(join(tmpdir(), 'wf-tool-'))
439439
try {
440440
const subDir = join(dir, 'sub')
441441
await mkdir(subDir, { recursive: true })
442-
// subDir 之外(dir 内)放置一个脚本
442+
// place a script outside subDir (inside dir)
443443
const outsideScript = join(dir, 'outside.ts')
444444
await writeFile(outsideScript, `return agent('x')`)
445-
// host.cwd = subDirscriptPath 是 subDir 外的绝对路径
445+
// host.cwd = subDir, scriptPath is an absolute path outside subDir
446446
const { ports, runStatus } = mockPorts(subDir, new Map())
447447
const tool = createWorkflowTool(ports)
448448
const res = await tool.call(
@@ -452,22 +452,22 @@ test('scriptPath 越界(resolve 后在 cwd 之外)→ 拒绝并报错(防
452452
undefined,
453453
)
454454
expect(res.data.output).toMatch(/^Error:/)
455-
expect(res.data.output).toMatch(/||outside|contain/i)
455+
expect(res.data.output).toMatch(/out of bounds|outside|not within/i)
456456
expect(runStatus.size).toBe(0)
457457
} finally {
458458
await rm(dir, { recursive: true, force: true })
459459
}
460460
})
461461

462-
test('name ".." 路径段 → 拒绝(防路径遍历逃出 workflowDir', async () => {
462+
test('name contains ".." path segment → rejected (prevents path traversal escaping workflowDir)', async () => {
463463
const outer = await mkdtemp(join(tmpdir(), 'wf-outer-'))
464464
try {
465-
// 在 outer 根下放置 evil.ts(在 .claude/workflows 之外)
465+
// place evil.ts at outer root (outside .claude/workflows)
466466
await writeFile(join(outer, 'evil.ts'), `return agent('x')`)
467467
await mkdir(join(outer, '.claude', 'workflows'), { recursive: true })
468468
const { ports, runStatus } = mockPorts(outer, new Map())
469469
const tool = createWorkflowTool(ports)
470-
// name = '../../evil' → join 后逃离 workflows 目录到 outer/evil.ts
470+
// name = '../../evil' → after join escapes the workflows directory to outer/evil.ts
471471
const res = await tool.call(
472472
{ name: '../../evil' },
473473
undefined,
@@ -481,7 +481,7 @@ test('name 含 ".." 路径段 → 拒绝(防路径遍历逃出 workflowDir)'
481481
}
482482
})
483483

484-
test('name 含路径分隔符或为绝对路径 → 拒绝', async () => {
484+
test('name contains path separators or is absolute → rejected', async () => {
485485
const dir = await mkdtemp(join(tmpdir(), 'wf-tool-'))
486486
try {
487487
await mkdir(join(dir, '.claude', 'workflows'), { recursive: true })
@@ -501,7 +501,7 @@ test('name 含路径分隔符或为绝对路径 → 拒绝', async () => {
501501
}
502502
})
503503

504-
test('returnValue 为对象 → completeformatValue JSON 分支)', async () => {
504+
test('returnValue is an object → complete (formatValue takes JSON branch)', async () => {
505505
const dir = await mkdtemp(join(tmpdir(), 'wf-tool-'))
506506
try {
507507
const { ports, runStatus } = mockPorts(

packages/workflow-engine/src/__tests__/agentAdapter.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const CTX = {
3636
agentId: 1,
3737
}
3838

39-
test('resolve 默认走 default adapterrun 返回结果', async () => {
39+
test('resolve goes to default adapter, run returns result', async () => {
4040
const reg = new AgentAdapterRegistry()
4141
.register(makeAdapter('a'))
4242
.register(makeAdapter('b'))
@@ -46,7 +46,7 @@ test('resolve 默认走 default adapter,run 返回结果', async () => {
4646
expect(r.kind).toBe('ok')
4747
})
4848

49-
test('route agentType 命中优先于 default', () => {
49+
test('route agentType hit takes priority over default', () => {
5050
const reg = new AgentAdapterRegistry()
5151
.register(makeAdapter('default'))
5252
.register(makeAdapter('research'))
@@ -56,18 +56,18 @@ test('route agentType 命中优先于 default', () => {
5656
expect(reg.resolve(P({ agentType: 'other' })).id).toBe('default')
5757
})
5858

59-
test('route model 前缀匹配', () => {
59+
test('route model prefix match', () => {
6060
const reg = new AgentAdapterRegistry()
6161
.register(makeAdapter('cheap'))
6262
.register(makeAdapter('strong'))
6363
.route({ kind: 'model', pattern: 'claude-opus', adapter: 'strong' })
6464
.default('cheap')
6565
expect(reg.resolve(P({ model: 'claude-opus-4' })).id).toBe('strong')
6666
expect(reg.resolve(P({ model: 'claude-sonnet-4' })).id).toBe('cheap')
67-
expect(reg.resolve(P()).id).toBe('cheap') // model → default
67+
expect(reg.resolve(P()).id).toBe('cheap') // no model → default
6868
})
6969

70-
test('route custom 谓词', () => {
70+
test('route custom predicate', () => {
7171
const reg = new AgentAdapterRegistry()
7272
.register(makeAdapter('main'))
7373
.register(makeAdapter('special'))
@@ -81,7 +81,7 @@ test('route custom 谓词', () => {
8181
expect(reg.resolve(P({ prompt: 'normal' })).id).toBe('main')
8282
})
8383

84-
test('规则按顺序匹配(先命中先用)', () => {
84+
test('rules match in order (first hit wins)', () => {
8585
const reg = new AgentAdapterRegistry()
8686
.register(makeAdapter('a'))
8787
.register(makeAdapter('b'))
@@ -90,20 +90,20 @@ test('规则按顺序匹配(先命中先用)', () => {
9090
expect(reg.resolve(P({ agentType: 'x' })).id).toBe('a')
9191
})
9292

93-
test('规则命中的 adapter 未注册 → 跳过该规则继续匹配', () => {
93+
test('rule-matched adapter not registered → skip that rule and continue matching', () => {
9494
const reg = new AgentAdapterRegistry()
9595
.register(makeAdapter('real'))
9696
.route({ kind: 'agentType', agentType: 'x', adapter: 'ghost' })
9797
.route({ kind: 'agentType', agentType: 'x', adapter: 'real' })
9898
expect(reg.resolve(P({ agentType: 'x' })).id).toBe('real')
9999
})
100100

101-
test('无匹配且无 default → AdapterNotFoundError', () => {
101+
test('no match and no default → AdapterNotFoundError', () => {
102102
const reg = new AgentAdapterRegistry().register(makeAdapter('a'))
103103
expect(() => reg.resolve(P())).toThrow(AdapterNotFoundError)
104104
})
105105

106-
test('default 指向未注册的 adapter → 仍抛(不静默回退)', () => {
106+
test('default points to an unregistered adapter → still throws (no silent fallback)', () => {
107107
const reg = new AgentAdapterRegistry()
108108
.register(makeAdapter('a'))
109109
.default('missing')
@@ -118,7 +118,7 @@ test('has / get', () => {
118118
expect(reg.get('b')).toBeUndefined()
119119
})
120120

121-
test('initializeAll / disposeAll 触发 lifecycle(跳过未实现)', async () => {
121+
test('initializeAll / disposeAll triggers lifecycle (skips unimplemented)', async () => {
122122
const events: string[] = []
123123
const withLifecycle: AgentAdapter = {
124124
id: 'a',
@@ -133,7 +133,7 @@ test('initializeAll / disposeAll 触发 lifecycle(跳过未实现)', async (
133133
events.push('dispose-a')
134134
},
135135
}
136-
const noLifecycle = makeAdapter('b') // initialize/dispose
136+
const noLifecycle = makeAdapter('b') // no initialize/dispose
137137
const reg = new AgentAdapterRegistry()
138138
.register(withLifecycle)
139139
.register(noLifecycle)
@@ -142,7 +142,7 @@ test('initializeAll / disposeAll 触发 lifecycle(跳过未实现)', async (
142142
expect(events).toEqual(['init-a', 'dispose-a'])
143143
})
144144

145-
test('capabilities 声明可读', () => {
145+
test('capabilities declaration is readable', () => {
146146
const adapter: AgentAdapter = {
147147
id: 'a',
148148
capabilities: { structuredOutput: true, tools: true, stream: false },

packages/workflow-engine/src/__tests__/agentId.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function build(results: Map<string, AgentRunResult>) {
4646
return { ctx, events, hooks: makeHooks(ctx, async () => null) }
4747
}
4848

49-
test('并发 agent 各自拿到唯一 agentIdstarted/done 配对', async () => {
49+
test('concurrent agents each get a unique agentId, started/done are paired', async () => {
5050
const ok = (out: string): AgentRunResult => ({
5151
kind: 'ok',
5252
output: out,
@@ -71,7 +71,7 @@ test('并发 agent 各自拿到唯一 agentId,started/done 配对', async () =
7171
expect(ctx.resources.agentIdSeq.value).toBe(2)
7272
})
7373

74-
test('agentId 单调递增', async () => {
74+
test('agentId increases monotonically', async () => {
7575
const ok = (out: string): AgentRunResult => ({
7676
kind: 'ok',
7777
output: out,

packages/workflow-engine/src/__tests__/budget.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect, test } from 'bun:test'
22
import { Budget, BudgetExhaustedError } from '../engine/budget.js'
33

4-
test('total=null 时无限制', () => {
4+
test('total=null means unlimited', () => {
55
const b = new Budget(null)
66
expect(b.total).toBeNull()
77
expect(b.remaining()).toBe(Infinity)
@@ -10,7 +10,7 @@ test('total=null 时无限制', () => {
1010
expect(() => b.assertCanSpend()).not.toThrow()
1111
})
1212

13-
test('累加并触顶抛错', () => {
13+
test('accumulates and throws when cap exceeded', () => {
1414
const b = new Budget(100)
1515
expect(b.remaining()).toBe(100)
1616
b.addOutputTokens(40)
@@ -22,7 +22,7 @@ test('累加并触顶抛错', () => {
2222
expect(() => b.assertCanSpend()).toThrow(BudgetExhaustedError)
2323
})
2424

25-
test('addOutputTokens 负值忽略', () => {
25+
test('addOutputTokens ignores negative values', () => {
2626
const b = new Budget(100)
2727
b.addOutputTokens(-50)
2828
expect(b.spent()).toBe(0)

0 commit comments

Comments
 (0)