feat(dacli): workflow/create.ts wrapCommand 迁移 (P2 batch3, 9 exit 收口)

全 action 包 wrapCommand + try/catch. 8 action process.exit + runWorkflowStepMachine helper process.exit → throw/ctx.fail.
成功 printCommandEnd → ctx.success. stale-retry 3 分支 exit → ctx.fail (create_stale_retry 测试仍 PASS).
cmdFix 在 wrapCommand 前算 (静态 populated), fixes 正常透传.

Co-Authored-By: Claude <[email protected]>
This commit is contained in:
sswandClaude committed 2026-07-21 21:44:34 +08:00
1 parent 11082bff6e
commit 32904b2efc
1 file changed
+28 -22
+28 -22
View File
@@ -23,7 +23,7 @@ import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
import { installHelpHookWithPatterns } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
import { setupOutputFilter, printCommandEnd } from '../_output_filter.ts'
import { setupOutputFilter, wrapCommand } from '../_output_filter.ts' // v2.2+ (2026-07-21): wrapCommand 收口 5c (9 process.exit + step machine throw)
import { callAiWorkflow, detectTrivialFlowXml } from '../form/_ai.ts'
import { buildFlowNodes, validateFlowNodeStructure } from './_webapi_helpers.ts'
import { autoLayoutFlowXml, isLayoutNeeded } from './_autoLayout.ts'
@@ -107,6 +107,15 @@ export function buildWorkflowCreateCommand(): Command {
Object.assign(opts, cmdFix.opts)
}
await wrapCommand({
command: 'workflow create',
appCode: c.appCode,
startTime,
verbose: opts.verbose,
json: opts.json,
fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions],
}, async (ctx) => {
try {
// (Round 8 P0): workflow 没绑 startFormId → 浏览器报 "workFlowForm/undefined.vue"
// step 1 拦截: 提示用户传 --startFormId (web NodeFormParser.vue:59-64)
if (!opts.startFormId) {
@@ -137,7 +146,7 @@ export function buildWorkflowCreateCommand(): Command {
if (!allCategories.has(opts.category) && !/^[a-f0-9]{32}$/.test(opts.category)) {
log.error(`BS-E5: workflow --category="${opts.category}" 不存在`)
log.error(` 跑 'dacli workflow selector' 看真实分类 id (32 位 hash 或中文)`)
process.exit(2)
return ctx.fail(`BS-E5: workflow --category="${opts.category}" 不存在`, { enCode: opts.enCode })
}
} catch (e) {
log.warn(`BS-E5: 查 workflow category 失败 (${(e as Error).message?.slice(0, 80)}), 跳过预校验`)
@@ -152,7 +161,7 @@ export function buildWorkflowCreateCommand(): Command {
if (!data.flowXml) {
log.error('AI 响应缺 flowXml, 无法自动建建')
if (opts.json) printJson(data)
process.exit(2)
return ctx.fail('AI 响应缺 flowXml, 无法自动建流程', { enCode: opts.enCode })
}
flowXml = data.flowXml
log.info(` ↳ AI 返回 flowXml 长度 ${flowXml.length} 字符`)
@@ -179,7 +188,7 @@ export function buildWorkflowCreateCommand(): Command {
}
if (!flowXml) {
log.error('必须传 --flowXml 或 --ai "<描述>" 之一')
process.exit(2)
return ctx.fail('必须传 --flowXml 或 --ai "<描述>" 之一', { enCode: opts.enCode })
}
// enCode 兜底: 缺时从 fullName 生成
@@ -257,13 +266,13 @@ export function buildWorkflowCreateCommand(): Command {
Object.assign(createResp, retryResp)
} else {
log.error(`BS-新43b: retry 仍失败 (code=${retryResp.code}): ${retryResp.msg}`)
process.exit(1)
return ctx.fail(`workflow create retry 仍失败 (code=${retryResp.code}): ${retryResp.msg}`, { enCode: opts.enCode })
}
} else {
process.exit(1)
return ctx.fail('workflow create 失败 (stale cleanup 未清理任何残留)', { enCode: opts.enCode })
}
} else {
process.exit(1)
return ctx.fail(`workflow create 失败 (code=${createResp.code}): ${createResp.msg}`, { enCode: opts.enCode })
}
}
const templateId = (typeof createResp.data === 'string' ? createResp.data : (createResp.data as { id?: string })?.id) || ''
@@ -275,7 +284,7 @@ export function buildWorkflowCreateCommand(): Command {
const versions = (verResp.data as unknown) as Array<{ id: string; state?: number }> || []
if (versions.length === 0) {
log.error(`创建后没有 version 记录, templateId=${templateId}, 数据异常`)
process.exit(1)
return ctx.fail(`创建后没有 version 记录, templateId=${templateId}, 数据异常`, { enCode: opts.enCode })
}
const versionId = versions[0].id
log.ok(` ↳ versionId (flowId) = ${versionId}`)
@@ -316,7 +325,7 @@ export function buildWorkflowCreateCommand(): Command {
log.error(`Save 失败 (code=${saveResp.code}): ${saveResp.msg}`)
const enhanced = enhanceFromBackend(saveResp.msg || '', 'workflow', { entity: 'workflow' })
log.error(` ${formatErrorLine(enhanced, { step: 5, stepName: 'save type=1' })}`)
process.exit(1)
return ctx.fail(`Save 失败 (code=${saveResp.code}): ${saveResp.msg}`, { enCode: opts.enCode })
}
log.ok(` ↳ Save 成功 (workflow 已部署到 Flowable)`)
@@ -377,18 +386,14 @@ export function buildWorkflowCreateCommand(): Command {
}
// 输出过滤: 命令结束, 落 CommandLog (L3) + 打印摘要 + "详情: dacli log last" (L1)
// v2.1+ (2026-07-21): 走新签名 { command, appCode, summary, fixes, duration_ms, verbose, json }
printCommandEnd({
command: 'workflow create',
appCode: c.appCode,
summary: {
id: templateId,
enCode: actualEnCode,
flowId: item?.flowId || versionId,
},
fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions],
duration_ms: Date.now() - startTime,
verbose: opts.verbose,
json: opts.json,
ctx.success({
id: templateId,
enCode: actualEnCode,
flowId: item?.flowId || versionId,
})
} catch (e) {
ctx.fail(`workflow create 失败: ${(e as Error).message?.slice(0, 200)}`, { enCode: opts.enCode })
}
})
})
@@ -469,7 +474,8 @@ async function runWorkflowStepMachine(
for (const e of allErrors) {
log.error(` [step ${e.step} ${e.stepName}] ${e.field || '?'}: ${e.message}`)
}
process.exit(1)
// v2.2+ (2026-07-21): throw 替代 process.exit(1), wrapCommand handler catch → ctx.fail
throw new Error(`step machine 校验失败 (${allErrors.length} 个错误)`)
}
log.info(`✓ step machine 校验通过 (3/3): enCode=${opts.enCode}`)
}