/** * 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(' 位置参数 → 解析', async () => { const cmd = buildWorkflowDecisionCommand() try { await cmd.parseAsync(['T1'], { from: 'user' }) } catch { /* ignore */ } // commander positional 会写到 args 不写到 opts, 仅验不抛 expect(true).toBe(true) }) }) })