本仓 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,未来以本仓历史为主
135 lines
5.9 KiB
TypeScript
135 lines
5.9 KiB
TypeScript
/**
|
|
* workflow semantic lint tests.
|
|
*
|
|
* 8 场景:
|
|
* 1. 多结束节点且无合并 → 阻断
|
|
* 2. 无 start → 阻断
|
|
* 3. userTask 无 assignee 且无 potentialOwner → 阻断
|
|
* 4. 显式 ${deptManager} 解析为空 → 阻断并 diagnostics
|
|
* 5. userTask 无 assignee 但有 potentialOwner → ok=true
|
|
* 6. userTask camunda:assignee="12345678" (6+ 位数字) → ok=true
|
|
* 7. 空 XML → errors 含 'flowXml is empty'
|
|
* 8. 单 End + Gateway → 无 multiple-end (短路验证)
|
|
*
|
|
* 与 BPMN layout lint 分离: layout 自动修复不掩盖语义错误.
|
|
*/
|
|
import { describe, expect, it } from 'vitest'
|
|
import { semanticLint } from '../../src/commands/workflow/_semantic_lint.ts'
|
|
|
|
describe('workflow semantic lint', () => {
|
|
it('多结束无合并 → ok=false, errors 含 multiple-end', async () => {
|
|
const xml = `<?xml version="1.0"?>
|
|
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL">
|
|
<bpmn:process id="p1">
|
|
<bpmn:startEvent id="s1"/>
|
|
<bpmn:userTask id="t1"/>
|
|
<bpmn:endEvent id="e1"/>
|
|
<bpmn:endEvent id="e2"/>
|
|
</bpmn:process>
|
|
</bpmn:definitions>`
|
|
const r = await semanticLint(xml, { webapi: {} })
|
|
expect(r.ok).toBe(false)
|
|
expect(r.errors.some(e => /multiple-end/.test(e))).toBe(true)
|
|
})
|
|
|
|
it('无 start → ok=false', async () => {
|
|
const xml = `<?xml version="1.0"?>
|
|
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL">
|
|
<bpmn:process id="p1">
|
|
<bpmn:userTask id="t1"/>
|
|
<bpmn:endEvent id="e1"/>
|
|
</bpmn:process>
|
|
</bpmn:definitions>`
|
|
const r = await semanticLint(xml, { webapi: {} })
|
|
expect(r.ok).toBe(false)
|
|
})
|
|
|
|
it('userTask 无 assignee 且无 potentialOwner → ok=false', async () => {
|
|
const xml = `<?xml version="1.0"?>
|
|
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL">
|
|
<bpmn:process id="p1">
|
|
<bpmn:startEvent id="s1"/>
|
|
<bpmn:userTask id="t1"/>
|
|
<bpmn:endEvent id="e1"/>
|
|
</bpmn:process>
|
|
</bpmn:definitions>`
|
|
const r = await semanticLint(xml, { webapi: {} })
|
|
expect(r.ok).toBe(false)
|
|
expect(r.errors.some(e => /assignee|candidate/.test(e))).toBe(true)
|
|
})
|
|
|
|
it('assignee=${deptManager} 候选人为空 → 阻断并给 reason', async () => {
|
|
const xml = `<?xml version="1.0"?>
|
|
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL">
|
|
<bpmn:process id="p1">
|
|
<bpmn:startEvent id="s1"/>
|
|
<bpmn:userTask id="t1" assignee="\${deptManager}"/>
|
|
<bpmn:endEvent id="e1"/>
|
|
</bpmn:process>
|
|
</bpmn:definitions>`
|
|
const webapi = { getDeptManager: async () => [] as Array<{ id: string; name: string }> }
|
|
const r = await semanticLint(xml, { webapi })
|
|
expect(r.ok).toBe(false)
|
|
expect(r.diagnostics.some(d => /unresolved/.test(d.message))).toBe(true)
|
|
expect(r.diagnostics.some(d => /no users in dept/.test(d.message))).toBe(true)
|
|
})
|
|
|
|
// ─── critical fix 回归 (C1: potentialOwner array 访问模式) ─────────────
|
|
it('C1 回归: userTask 无 assignee + <bpmn:potentialOwner/> → ok=true', async () => {
|
|
// BPMN 标准 pattern: <bpmn:potentialOwner> 元素表达 "存在候选人 wrapper"
|
|
// (具体用户在 <bpmn:resourceAssignmentExpression> 里, 这里只看 potentialOwner 元素是否存在)
|
|
const xml = `<?xml version="1.0"?>
|
|
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL">
|
|
<bpmn:process id="p1">
|
|
<bpmn:startEvent id="s1"/>
|
|
<bpmn:userTask id="t1"><bpmn:potentialOwner id="po1"/></bpmn:userTask>
|
|
<bpmn:endEvent id="e1"/>
|
|
</bpmn:process>
|
|
</bpmn:definitions>`
|
|
const r = await semanticLint(xml, { webapi: {} })
|
|
expect(r.ok).toBe(true)
|
|
expect(r.errors).toEqual([])
|
|
})
|
|
|
|
// ─── critical fix 回归 (C2: namespaced assignee) ─────────────────────
|
|
it('C2 回归: userTask camunda:assignee="12345678" (6+ 位数字) → ok=true', async () => {
|
|
// JNPF/Camunda XML 风格: userTask 用命名空间前缀属性 camunda:assignee
|
|
// 修复后: 查 ut.assignee + $attrs.assignee + $attrs['camunda:assignee'] + $attrs['flowable:assignee']
|
|
// 6+ 位数字被 _approver_resolve 视为 JNPF userId 风格单候选人占位.
|
|
const xml = `<?xml version="1.0"?>
|
|
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL"
|
|
xmlns:camunda="http://camunda.org/schema/1.0/bpmn">
|
|
<bpmn:process id="p1">
|
|
<bpmn:startEvent id="s1"/>
|
|
<bpmn:userTask id="t1" camunda:assignee="12345678"/>
|
|
<bpmn:endEvent id="e1"/>
|
|
</bpmn:process>
|
|
</bpmn:definitions>`
|
|
const r = await semanticLint(xml, { webapi: {} })
|
|
expect(r.ok).toBe(true)
|
|
expect(r.errors).toEqual([])
|
|
})
|
|
|
|
// ─── 稳定性测试 ─────────────────────────────────────────────────────
|
|
it('稳定性: 空 XML → errors 含 "flowXml is empty"', async () => {
|
|
const r = await semanticLint('', { webapi: {} })
|
|
expect(r.ok).toBe(false)
|
|
expect(r.errors).toContain('flowXml is empty')
|
|
})
|
|
|
|
it('稳定性: 单 End + Gateway → ok=true (短路验证)', async () => {
|
|
// ends.length === 1 时 hasConvergingGateway 短路返回 true, 不会触发 multiple-end
|
|
const xml = `<?xml version="1.0"?>
|
|
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL">
|
|
<bpmn:process id="p1">
|
|
<bpmn:startEvent id="s1"/>
|
|
<bpmn:userTask id="t1"/>
|
|
<bpmn:exclusiveGateway id="g1"/>
|
|
<bpmn:userTask id="t2"/>
|
|
<bpmn:endEvent id="e1"/>
|
|
</bpmn:process>
|
|
</bpmn:definitions>`
|
|
const r = await semanticLint(xml, { webapi: {} })
|
|
expect(r.errors.some(e => /multiple-end/.test(e))).toBe(false)
|
|
})
|
|
}) |