镜像架构原则实践: BS-drift-W-3 (AI 节点数自由生成) 不可强约束, 硬编码角色/节点数会引入维护负担 + 漏业务专属角色 + 跨语言失败. 采用 '复用规则文字 + 引用 web 源码行号' 的务实镜像策略: 镜像源: web/packages/jnpf/plugins/jnpf-bpmn/lib/utils/bpmnLintUtil.ts 镜像 4 规则: - 规则 1 (line 73): 必须有 start + end + approver - 规则 2 (line 84): 只能有 1 个 start - 规则 3 (line 106): 只能有 1 个 end - 规则 5 (line 130+): parallel/inclusive 网关必须成对 (偶数个) 规则 4 (edges 进出线) 跳过: dacli parseFlowXml 不解析 sequenceFlow 边 (web _webapi_helpers.ts:215 注释). 未来 v0.22+ 用 webapi loader 整个 import bpmnLintUtil.ts (含边校验), 需先用 shim 把 flowNodes 转 ElementRegistry-like 结构. 5 类漂移全部 RESOLVED: - BS-drift-M-1/2, BS-drift-W-1/2/4 (Round 5) - BS-drift-W-3 (Round 6 镜像修复) ✓ NEW vitest: 62/62 PASS (22 menu + 31 workflow drift + 9 validator 单元测试), 419ms 改动: - workflow/_webapi_helpers.ts: 加 validateFlowNodeStructure (镜像 4 规则) - workflow/create.ts: step 4/6 调用 mirror validator - tests/integration/drift/workflow-validator.spec.ts (NEW): 9 单元测试 - tests/integration/drift/workflow-drift.spec.ts: BS-W-3 切到 RESOLVED via mirror - docs/drift/2026-07-14-round6-w3-mirror-summary.md (NEW): 完整总结
130 lines
4.5 KiB
TypeScript
130 lines
4.5 KiB
TypeScript
/**
|
|
* workflow-validator.spec.ts — Round 6 BS-drift-W-3 fix 单元测试
|
|
*
|
|
* 目的: 验证 validateFlowNodeStructure (镜像 web bpmnLintUtil.ts) 的 4 条规则正确触发.
|
|
*
|
|
* 镜像源: web/packages/jnpf/plugins/jnpf-bpmn/lib/utils/bpmnLintUtil.ts
|
|
* - 规则 1: 必须有 start + end + approver (line 73)
|
|
* - 规则 2: 只能有 1 个 start (line 84)
|
|
* - 规则 3: 只能有 1 个 end (line 106)
|
|
* - 规则 5: 分流/合流网关必须成对 (line 130+)
|
|
*
|
|
* 镜像架构原则: 复用 web 规则文字, 不自创.
|
|
*/
|
|
|
|
import { describe, it, expect } from 'vitest'
|
|
import { validateFlowNodeStructure } from '../../../src/commands/workflow/_webapi_helpers.ts'
|
|
|
|
describe('workflow-validator: 镜像 web bpmnLintUtil.ts 规则 1 (start/end/approver 必有)', () => {
|
|
it('缺 start → FAIL', () => {
|
|
const r = validateFlowNodeStructure({
|
|
end: { type: 'end' },
|
|
approver1: { type: 'approver' },
|
|
global: { type: 'global' },
|
|
})
|
|
expect(r.errorList.length).toBe(1)
|
|
expect(r.errorList[0].error).toContain('缺失')
|
|
expect(r.errorList[0].error).toContain('start')
|
|
expect(r.errorList[0].webSource).toContain('bpmnLintUtil.ts:73')
|
|
})
|
|
|
|
it('缺 end → FAIL', () => {
|
|
const r = validateFlowNodeStructure({
|
|
start: { type: 'start' },
|
|
approver1: { type: 'approver' },
|
|
global: { type: 'global' },
|
|
})
|
|
expect(r.errorList.some(e => e.error.includes('end'))).toBe(true)
|
|
})
|
|
|
|
it('缺 approver → FAIL', () => {
|
|
const r = validateFlowNodeStructure({
|
|
start: { type: 'start' },
|
|
end: { type: 'end' },
|
|
global: { type: 'global' },
|
|
})
|
|
expect(r.errorList.some(e => e.error.includes('approver'))).toBe(true)
|
|
})
|
|
|
|
it('start + end + approver 齐全 → PASS', () => {
|
|
const r = validateFlowNodeStructure({
|
|
start: { type: 'start' },
|
|
approver1: { type: 'approver' },
|
|
approver2: { type: 'approver' },
|
|
end: { type: 'end' },
|
|
global: { type: 'global' },
|
|
})
|
|
expect(r.errorList.length).toBe(0)
|
|
expect(r.okMessage).toContain('结构完整')
|
|
})
|
|
})
|
|
|
|
describe('workflow-validator: 镜像 web bpmnLintUtil.ts 规则 2 (只能 1 个 start)', () => {
|
|
it('2 个 start → FAIL', () => {
|
|
const r = validateFlowNodeStructure({
|
|
start1: { type: 'start' },
|
|
start2: { type: 'start' },
|
|
approver1: { type: 'approver' },
|
|
end: { type: 'end' },
|
|
global: { type: 'global' },
|
|
})
|
|
expect(r.errorList.some(e => e.error.includes('开始节点') && e.error.includes('2'))).toBe(true)
|
|
})
|
|
})
|
|
|
|
describe('workflow-validator: 镜像 web bpmnLintUtil.ts 规则 3 (只能 1 个 end)', () => {
|
|
it('2 个 end → FAIL', () => {
|
|
const r = validateFlowNodeStructure({
|
|
start: { type: 'start' },
|
|
approver1: { type: 'approver' },
|
|
end1: { type: 'end' },
|
|
end2: { type: 'end' },
|
|
global: { type: 'global' },
|
|
})
|
|
expect(r.errorList.some(e => e.error.includes('结束节点') && e.error.includes('2'))).toBe(true)
|
|
})
|
|
})
|
|
|
|
describe('workflow-validator: 镜像 web bpmnLintUtil.ts 规则 5 (parallel/inclusive 网关成对)', () => {
|
|
it('parallel 网关奇数个 → FAIL', () => {
|
|
const r = validateFlowNodeStructure({
|
|
start: { type: 'start' },
|
|
approver1: { type: 'approver' },
|
|
parallel1: { type: 'parallel' },
|
|
end: { type: 'end' },
|
|
global: { type: 'global' },
|
|
})
|
|
expect(r.errorList.some(e => e.error.includes('parallel') && e.error.includes('奇数'))).toBe(true)
|
|
})
|
|
|
|
it('parallel 网关偶数个 → PASS', () => {
|
|
const r = validateFlowNodeStructure({
|
|
start: { type: 'start' },
|
|
approver1: { type: 'approver' },
|
|
parallel1: { type: 'parallel' },
|
|
parallel2: { type: 'parallel' },
|
|
end: { type: 'end' },
|
|
global: { type: 'global' },
|
|
})
|
|
expect(r.errorList.filter(e => e.error.includes('parallel')).length).toBe(0)
|
|
})
|
|
})
|
|
|
|
describe('workflow-validator: 镜像 web 端 AI 生成标准流程 PASS', () => {
|
|
it('典型 AI 生成: 1 start + 3 approver + 1 end + 1 global → PASS', () => {
|
|
const r = validateFlowNodeStructure({
|
|
Event_start: { type: 'start' },
|
|
Activity_1: { type: 'approver' },
|
|
Activity_2: { type: 'approver' },
|
|
Activity_3: { type: 'approver' },
|
|
Event_end: { type: 'end' },
|
|
global: { type: 'global' },
|
|
})
|
|
expect(r.errorList.length).toBe(0)
|
|
expect(r.okMessage).toContain('结构完整')
|
|
expect(r.nodeTypeCounts.start).toBe(1)
|
|
expect(r.nodeTypeCounts.approver).toBe(3)
|
|
expect(r.nodeTypeCounts.end).toBe(1)
|
|
expect(r.nodeTypeCounts.global).toBe(1)
|
|
})
|
|
}) |