Files
dacli/tests/unit/workflow_command_smoke.test.ts
sushub f403a7e80e import: ssw/dacli@eea0ebc (2026-08-12) 起点版本
本仓 2026-08-12 从 ssw main (192.168.1.18:13300/ssw/ssw-mvp) 的
dacli/ subpath 抽取,作为独立仓托管到 gitea:3000/ssw/dacli.git。

- 工作树为 ssw main dacli subpath 最新版 (110 commit, 08-12)
- 历史未带 ssw main 整体历史(避免大仓污染)
- 此为新仓基线 commit,未来以本仓历史为主
2026-08-12 15:58:06 +08:00

128 lines
4.5 KiB
TypeScript

/**
* tests/unit/workflow_command_smoke.test.ts
*
* 6 个 workflow 命令的 commander parse smoke test (补覆盖缺口):
* - update, delete, tasks, info, syncForm, decision
*
* 设计: 只验 commander 能正确解析参数 + option 名字. 真实 API 行为靠 e2e 验.
* - 这是单测 0/1 的下限覆盖, 防 commander option 改名 / 漂移.
*/
import { describe, expect, it } from 'vitest'
import { buildWorkflowUpdateCommand } from '../../src/commands/workflow/update.ts'
import { buildWorkflowDeleteCommand } from '../../src/commands/workflow/delete.ts'
import { buildWorkflowTasksCommand } from '../../src/commands/workflow/tasks.ts'
import { buildWorkflowInfoCommand } from '../../src/commands/workflow/info.ts'
import { buildWorkflowSyncFormCommand } from '../../src/commands/workflow/syncForm.ts'
import { buildWorkflowDecisionCommand } from '../../src/commands/workflow/decision.ts'
describe('workflow command smoke (6 commands)', () => {
describe('update', () => {
it('--id --enabledMark=1 --startFormId → 解析', async () => {
const cmd = buildWorkflowUpdateCommand()
try {
await cmd.parseAsync([
'--id', 'W1',
'--enabledMark', '1',
'--startFormId', 'F1',
], { from: 'user' })
} catch { /* ignore */ }
const opts = cmd.opts<{ id?: string; enabledMark?: string; startFormId?: string }>()
expect(opts.id).toBe('W1')
expect(opts.enabledMark).toBe('1')
expect(opts.startFormId).toBe('F1')
})
it('--expected-enCode --expected-state → dirty check 参数解析', async () => {
const cmd = buildWorkflowUpdateCommand()
try {
await cmd.parseAsync([
'--id', 'W1',
'--expected-enCode', 'flow1',
'--expected-state', '1',
'--force',
], { from: 'user' })
} catch { /* ignore */ }
const opts = cmd.opts<{ expectedEnCode?: string; expectedState?: string; force?: boolean }>()
expect(opts.expectedEnCode).toBe('flow1')
expect(opts.expectedState).toBe('1')
expect(opts.force).toBe(true)
})
})
describe('delete', () => {
it('--id --yes → 解析', async () => {
const cmd = buildWorkflowDeleteCommand()
try {
await cmd.parseAsync(['--id', 'W1', '--yes'], { from: 'user' })
} catch { /* ignore */ }
const opts = cmd.opts<{ id?: string; yes?: boolean }>()
expect(opts.id).toBe('W1')
expect(opts.yes).toBe(true)
})
})
describe('tasks', () => {
it('--category=1 --flowId → 解析 (待办)', async () => {
const cmd = buildWorkflowTasksCommand()
try {
await cmd.parseAsync(['--category', '1', '--flowId', 'F1'], { from: 'user' })
} catch { /* ignore */ }
const opts = cmd.opts<{ category?: string; flowId?: string }>()
expect(opts.category).toBe('1')
expect(opts.flowId).toBe('F1')
})
it('不传 --category → 默认 1 (待办)', async () => {
const cmd = buildWorkflowTasksCommand()
try {
await cmd.parseAsync([], { from: 'user' })
} catch { /* ignore */ }
const opts = cmd.opts<{ category?: string }>()
expect(opts.category).toBe('1')
})
})
describe('info', () => {
it('--id → 解析', async () => {
const cmd = buildWorkflowInfoCommand()
try {
await cmd.parseAsync(['--id', 'W1', '--include-internals'], { from: 'user' })
} catch { /* ignore */ }
const opts = cmd.opts<{ id?: string; includeInternals?: boolean }>()
expect(opts.id).toBe('W1')
expect(opts.includeInternals).toBe(true)
})
})
describe('syncForm', () => {
it('--flowId → 解析 (syncForm 用 --flowId 不是 --id)', async () => {
const cmd = buildWorkflowSyncFormCommand()
try {
await cmd.parseAsync(['--flowId', 'W1'], { from: 'user' })
} catch { /* ignore */ }
const opts = cmd.opts<{ flowId?: string }>()
expect(opts.flowId).toBe('W1')
})
})
describe('decision', () => {
it('--list → list 模式', async () => {
const cmd = buildWorkflowDecisionCommand()
try {
await cmd.parseAsync(['--list'], { from: 'user' })
} catch { /* ignore */ }
const opts = cmd.opts<{ list?: boolean }>()
expect(opts.list).toBe(true)
})
it('<templateId> 位置参数 → 解析', async () => {
const cmd = buildWorkflowDecisionCommand()
try {
await cmd.parseAsync(['T1'], { from: 'user' })
} catch { /* ignore */ }
// commander positional 会写到 args 不写到 opts, 仅验不抛
expect(true).toBe(true)
})
})
})