tdd7 复盘第三批: - src/commands/workflow/approve.ts: 重构为 buildApprovalCommand(hooks?), 暴露 handle/audit 双 hook, --auto-handle 选项自动顺序 handle → audit (tdd7 debug §2.2 修复点 ⑥: 真实审批必须先 handle 才能提交) 不传 --auto-handle 时保留原行为 (向后兼容) - tests/unit/approve_auto_handle.test.ts: 2 用例 (含/不含 --auto-handle) - scripts/quality-gate.sh: 增 [6/6] workflow runtime ladder 步骤, 跨 app 跑 ssw-loop 关卡 W, advisory 不阻断 commit 总测试 86 文件 / 643 用例 全部通过, tsc --noEmit 0 错误
56 lines
2.1 KiB
TypeScript
56 lines
2.1 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest'
|
|
import { buildApprovalCommand, type ApprovalHooks } from '../../src/commands/workflow/approve.ts'
|
|
|
|
// 单测里 stub 不存在 token 的 JnpfClient.fromToken, 让 commander parseAsync 跑完
|
|
vi.mock('../../src/core/client.ts', () => ({
|
|
JnpfClient: {
|
|
fromToken: async () => ({
|
|
appCode: 'testspace',
|
|
postJson: async () => ({ code: 200, msg: 'ok', data: { id: 'mock' } }),
|
|
get: async () => ({ code: 200, msg: 'ok', data: {} }),
|
|
}),
|
|
},
|
|
}))
|
|
|
|
interface CallLog {
|
|
method: 'handle' | 'audit'
|
|
args: Record<string, unknown>
|
|
}
|
|
|
|
function makeHooks(): { hooks: ApprovalHooks; calls: CallLog[] } {
|
|
const calls: CallLog[] = []
|
|
const hooks: ApprovalHooks = {
|
|
handle: async (args) => {
|
|
calls.push({ method: 'handle', args })
|
|
},
|
|
audit: async (args) => {
|
|
calls.push({ method: 'audit', args })
|
|
},
|
|
}
|
|
return { hooks, calls }
|
|
}
|
|
|
|
describe('workflow approve auto-handle', () => {
|
|
it('runs the registered handle before audit when --auto-handle is set', async () => {
|
|
const { hooks, calls } = makeHooks()
|
|
const command = buildApprovalCommand(hooks)
|
|
const options = command.options.map(option => option.long)
|
|
expect(options).toEqual(expect.arrayContaining(['--operatorId', '--status', '--opinion', '--auto-handle', '--json', '--verbose']))
|
|
|
|
await command.parseAsync(['--operatorId', '852462625554956293', '--status', '0', '--opinion', '同意', '--auto-handle'], { from: 'user' })
|
|
|
|
expect(calls.map(call => call.method)).toEqual(['handle', 'audit'])
|
|
expect(calls[0].args).toMatchObject({ operatorId: '852462625554956293' })
|
|
expect(calls[1].args).toMatchObject({ operatorId: '852462625554956293', status: 0, opinion: '同意' })
|
|
})
|
|
|
|
it('skips handle when --no-auto-handle is passed (default behaviour)', async () => {
|
|
const { hooks, calls } = makeHooks()
|
|
const command = buildApprovalCommand(hooks)
|
|
|
|
await command.parseAsync(['--operatorId', '852462625554956293', '--status', '0'], { from: 'user' })
|
|
|
|
expect(calls.map(call => call.method)).toEqual(['audit'])
|
|
})
|
|
})
|