diff --git a/src/commands/_anti_patterns.ts b/src/commands/_anti_patterns.ts index ff823da..ea61b1a 100644 --- a/src/commands/_anti_patterns.ts +++ b/src/commands/_anti_patterns.ts @@ -150,6 +150,15 @@ export const ANTI_PATTERNS: Record = { source: 'jxcj M2 2026-07-23 实战 → decisions/0017-form-smartprops-unification', crossRefs: ['decisions/0017-form-smartprops-unification', 'BS-新132', 'BS-新133'], }, + { + id: 'AP-fu-5', + severity: 'P1', + wrong: 'form update --fields 只传 dictType (enCode 字符串), 不传 dictionaryType (数字 typeId), 当 enCode 字符串相似时 smartProps 启发式可能错配', + right: 'select 字段 + dict 是设计核心 (e.g. 状态机/类型枚举) 时, form update --fields **必显式传 `dictionaryType` 数字 typeId** (e.g. `852592707829235781`), 不依赖 smartProps 自动补. 同时传 dictType (enCode 字符串, 前端显示) + dictionaryType (数字 typeId, 后端存储). 命中场景: enCode 字符串相似 (e.g. jxcjauditstate vs jxcjenrollstatus), smartProps 启发式按字段名前缀匹配错选', + rationale: 'BS-新142: 字典 smartProps typeId 错配 (enCode 字符串相似时). 实测: jxcjenrollrecord.f_audit_state 期望 jxcjenrollstatus, smartProps 错配 jxcjauditstate. applyHeuristicDictType 多候选警告已升级 BS-新141 → BS-新142 ERROR', + source: 'jxcj M1 2026-07-30 阶段 4.2 mod2 实战 → decisions/0019-form-update-dictionarytype-explicit', + crossRefs: ['decisions/0019-form-update-dictionarytype-explicit', 'BS-新142', 'BS-新141', 'decisions/0017-form-smartprops-unification'], + }, ], 'form info': [ { @@ -219,6 +228,22 @@ export const ANTI_PATTERNS: Record = { rationale: 'AI 默认生 trivial 3-node BPMN, 不实用', source: 'archive/drift-rounds-2026-07/2026-07-15-round12-fix-batch2.md §F3', }, + { + id: 'AP-wc-3', severity: 'P1', + wrong: '--ai 描述里含 "${initiator}" "${reviewer}" "${admin}" 等变量, semanticLint 阻断 unresolved', + right: '--ai 描述**显式禁止** AI 用变量, 推荐模板: "业务描述 + 审批人用 admin fixed user (或 admin + 张三 userId=1,2), 不要用变量 initiator/reviewer/admin". 或传 --flowXml 跳过 AI. 命中: ${initiator} 是 web 保留字, ${reviewer}/${admin} 是未定义变量, semanticLint 全部阻断', + rationale: 'BS-新143: workflow --ai 变量引用 unresolved. jxcj M1 阶段 4.3 实战: 3 个 userTask assignee 都 unresolved, semanticLint 兜底仍失败. 修复路径: --ai 描述加约束 + semanticLint 后端兜底', + source: 'jxcj M1 2026-07-30 阶段 4.3 实战 → decisions/0020-workflow-ai-variables', + crossRefs: ['decisions/0020-workflow-ai-variables', 'BS-新143'], + }, + { + id: 'AP-wc-4', severity: 'P1', + wrong: 'workflow create throw 后 (semanticLint 失败 / AI 缺 flowXml / 其他异常), template 残留 DB (enabledMark=0, flowId=null) 阻塞 SU001 重试, 用户必须手动 dacli workflow delete --id= --yes', + right: 'v0.23+ workflow create catch 块自动调 workflow delete --yes 清理 templateId (除非 --keep-on-fail). 修复前: semanticLint 失败 → 残留 → retry 报 SU001; 修复后: catch 自动清理, retry 立即可用', + rationale: 'BS-新145: workflow create 任何 throw 后 template 残留 DB 阻塞 SU001 重试. jxcj M1 阶段 4.3 实战: 第一次 create 失败 (semanticLint ${initiator}), 第二次 create 报 SU001 enCode 已存在, 必须手动 cleanup', + source: 'jxcj M1 2026-07-30 阶段 4.3 实战 → decisions/0021-workflow-create-auto-rollback', + crossRefs: ['decisions/0021-workflow-create-auto-rollback', 'BS-新145', 'decisions/0006-workflow-create-startformid'], + }, ], 'dm create': [ { diff --git a/src/commands/test/browser.ts b/src/commands/test/browser.ts index b97caf1..acbaf3c 100644 --- a/src/commands/test/browser.ts +++ b/src/commands/test/browser.ts @@ -70,6 +70,8 @@ interface MenuItem { fullName: string enCode: string urlAddress: string + // propertyJson.moduleId = 关联 form id (web 端 menu 创建时写入, BS-新131 hash 后缀的对照) + propertyJson?: { moduleId?: string; [k: string]: any } children?: MenuItem[] } @@ -85,22 +87,32 @@ async function fetchMenuList(c: JnpfClient, opts: { isBackend?: 0 | 1 } = {}): P return data?.menuList || [] } -function findMenuUrl(items: MenuItem[], enCode: string): string | null { +function findMenuUrl(items: MenuItem[], formId: string, enCode?: string): string | null { for (const m of items) { - if (m.enCode === enCode || m.enCode?.startsWith(enCode)) return m.urlAddress + // 优先 moduleId 精确匹配 (跨 BS-新131 hash 后缀必然歧义, BS-新144 修复) + if (m.propertyJson?.moduleId && m.propertyJson.moduleId === formId) return m.urlAddress + // 兜底 1: 精确 enCode 匹配 (无 hash 时) + if (enCode && m.enCode === enCode) return m.urlAddress + // 兜底 2: urlAddress 包含 enCode (向前兼容旧 menu 无 propertyJson) + if (enCode && m.urlAddress && m.urlAddress.includes(enCode)) return m.urlAddress if (m.children) { - const r = findMenuUrl(m.children, enCode) + const r = findMenuUrl(m.children, formId, enCode) if (r) return r } } return null } -function findMenuItem(items: MenuItem[], enCode: string): MenuItem | null { +function findMenuItem(items: MenuItem[], formId: string, enCode?: string): MenuItem | null { for (const m of items) { - if (m.enCode === enCode || m.enCode?.startsWith(enCode)) return m + // 优先 moduleId 精确匹配 (BS-新144 修复) + if (m.propertyJson?.moduleId && m.propertyJson.moduleId === formId) return m + // 兜底 1: 精确 enCode 匹配 + if (enCode && m.enCode === enCode) return m + // 兜底 2: urlAddress 包含 enCode + if (enCode && m.urlAddress && m.urlAddress.includes(enCode)) return m if (m.children) { - const f = findMenuItem(m.children, enCode) + const f = findMenuItem(m.children, formId, enCode) if (f) return f } } @@ -573,8 +585,10 @@ async function runFormBrowserTest(opts: { } // 2. 解析真实 URL (含 8a3aa suffix) + 找对应 menu item (含 suffix enCode) - const realUrl = findMenuUrl(menuList, schema.enCode) - const menuItem = findMenuItem(menuList, schema.enCode) + // BS-新144 (2026-07-30 jxcj M1): 用 propertyJson.moduleId 精确匹配, + // 修复 startsWith 前缀碰撞 (e.g. jxcjteammember04a58.startsWith('jxcjteam') === true) + const realUrl = findMenuUrl(menuList, formId, schema.enCode) + const menuItem = findMenuItem(menuList, formId, schema.enCode) const menuEnCode = menuItem?.enCode if (!realUrl) { return { diff --git a/src/commands/workflow/create.ts b/src/commands/workflow/create.ts index 34a5ab1..cee137d 100644 --- a/src/commands/workflow/create.ts +++ b/src/commands/workflow/create.ts @@ -90,7 +90,7 @@ export function buildWorkflowCreateCommand(): Command { .option('--showType ', '显示位置 (0=全局 1=流程 2=菜单, 默认 0)', '0') .option('--startFormId ', '绑定的 formId (绑到 start 节点 formId, 镜像 web 选表单步骤). 强烈推荐传 — 不传浏览器端会报 workFlowForm/undefined.vue 404 (web 端 BS-新27 实战踩坑, 2026-07-29)') .option('--layoutThreshold ', 'isLayoutNeeded 重叠阈值 (0-1, 默认 0.8 = 80% 触发 autoLayout)', '0.8') - .option('--ai ', 'AI 创建流程 — 自然语言描述, 走 web 端 getAiInfo 拿 flowXml') + .option('--ai ', 'AI 创建流程 — 自然语言描述, 走 web 端 getAiInfo 拿 flowXml. ⚠️ BS-新143 (2026-07-30 jxcj M1): --ai 描述里若含 "${initiator}" "${reviewer}" "${admin}" 等变量, semanticLint 会阻断 unresolved (保留字/未定义变量). 推荐 --ai 描述显式说"审批人用 admin fixed user, 不要用变量 initiator"') .option('--auto-authorize', '创建后自动给当前角色授权', false) .option('--force-lint', '跳过 semanticLint 阻断 (AI 生成的 BPMN 可能有 assignee/candidate 问题, 用户确认风险后强制 save; 后端 Flowable 部署可能失败, 2026-07-29)', false) .option('--keep-on-fail', 'Save 失败时保留残留 template (不自动回滚). 调试用, 默认 false 自动调用 workflow delete 清理', false) @@ -124,6 +124,9 @@ export function buildWorkflowCreateCommand(): Command { fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions], }, async (ctx) => { try { + // BS-新145 (2026-07-30 jxcj M1): 提前声明 templateId, 让 catch 块能 cleanup 残留 + let templateId = '' + // (Round 8 P0): workflow 没绑 startFormId → 浏览器报 "workFlowForm/undefined.vue" // step 1 拦截: 提示用户传 --startFormId (web NodeFormParser.vue:59-64) if (!opts.startFormId) { @@ -381,7 +384,8 @@ export function buildWorkflowCreateCommand(): Command { 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) || '' + const templateIdResp = (typeof createResp.data === 'string' ? createResp.data : (createResp.data as { id?: string })?.id) || '' + templateId = templateIdResp // BS-新145: 让外层 catch 可访问 log.ok(` ↳ templateId = ${templateId}`) // ========== 4. getVersionList 拿 versionId ========== @@ -602,6 +606,23 @@ export function buildWorkflowCreateCommand(): Command { flowId: item?.flowId || versionId, }) } catch (e) { + // BS-新145 (2026-07-30 jxcj M1): 任何 throw 后自动清理 templateId 残留 + // 修复前: semanticLint 失败 → template 留在 DB (enabledMark=0, flowId=null) → 重试报 SU001 enCode 已存在 + // 修复后: 自动调 workflow delete 兜底, 用户重试不需要手动 cleanup + if (templateId && !opts.keepOnFail) { + log.warn(`BS-新145: catch 自动清理 template ${templateId} (${(e as Error).message?.slice(0, 80)})`) + try { + const { spawnSync } = await import('node:child_process') + const cliEntry = process.argv[1] || 'src/cli.ts' + const r = spawnSync('npx', ['tsx', cliEntry, 'workflow', 'delete', '--id', templateId, '--yes'], { + stdio: 'pipe', timeout: 10000, + }) + if (r.status === 0) log.ok(` ✓ BS-新145 已清理 template ${templateId}`) + else log.warn(` BS-新145 清理失败: ${r.stderr?.toString().slice(0, 200) || r.stdout?.toString().slice(0, 200)}`) + } catch (cleanupErr) { + log.warn(` BS-新145 清理异常: ${(cleanupErr as Error).message?.slice(0, 100)}`) + } + } ctx.fail(`workflow create 失败: ${(e as Error).message?.slice(0, 200)}`, { enCode: opts.enCode }) } })