fix(modeler): activiti.json 修 Modeler.saveXML 大写元素名(断部署)+真Modeler序列化回归测试
CRITICAL:bpmn-js Modeler.saveXML 把被 activiti.json `extends` 的 bpmn 类型序列化成
PascalCase 元素名(<Process>/<UserTask>/<StartEvent>…),未扩展的 <sequenceFlow>/<endEvent>
仍小写。Flowable 大小写敏感 → <Process> 不被识别为流程,ProcessValidator 报
flowable-process-definition-not-executable,部署完全失败。
根因:moddle 把「被扩展类型」的合并描述符 $pkg 设为**最后一个 trait 的包**(moddle
index.esm.js:577)。activiti 包缺 `xml.tagAlias:"lowerCase"`,故 moddle-xml 写元素名时不做
首字母小写 → PascalCase。且 tagAlias 是**双向**的(也驱动 fromXML 解析),要求自定义元素类型名
用 activiti/camunda 惯例的 PascalCase,否则解析 <activiti:taskListener> 找不到类型而丢弃。
修法(对齐 activiti/camunda-bpmn-moddle 标准):
- activiti.json + flowable.json 加 `"xml": { "tagAlias": "lowerCase" }`;
- 自定义元素类型名改 PascalCase:taskListener→TaskListener / executionListener→ExecutionListener
/ field→Field / formProperty→FormProperty / value→Value / in→In / out→Out(属性 type 引用同步)。
XML 元素名仍小写(tagAlias),故 fixture 与「toContain('activiti:taskListener')」类 XML 断言不变。
- Eip4Panel.tsx:moddle.create/$type 用 'activiti:TaskListener';测试 fake 类型名同步。
为何旧测试没抓到:T1.1/T1.2 只断言 activiti 扩展属性/元素多重集,从不断言基础 BPMN 元素名大小写;
fromXML→toXML 与 create 都走同一 moddle-xml Writer 且都产 PascalCase(本 commit 实证)。
新增 serialization.test.ts(4 例,RED→GREEN):以 BpmnModdle(= Modeler.saveXML 的 moddle 层,
jsdom 跑不动 diagram-js SVG)驱动 fromXML→toXML 与 create→toXML,断言基础元素名全小写、无 PascalCase、
isExecutable 保留、扩展元素/属性不丢;flowable 隔离同验。
serialization 4 + fidelity 12 + Eip4Panel 37;全量 231 单测绿,tsc -b rc=0 + build 干净。
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
95
src/modeler/moddle/serialization.test.ts
Normal file
95
src/modeler/moddle/serialization.test.ts
Normal file
@@ -0,0 +1,95 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import BpmnModdle from 'bpmn-moddle';
|
||||
import activiti from './activiti.json';
|
||||
import flowable from './flowable.json';
|
||||
import { SYNTHETIC_BPMN } from './fixtures/synthetic-full-surface.bpmn';
|
||||
|
||||
// 元素名大小写回归(CRITICAL:断部署)。
|
||||
//
|
||||
// 根因:moddle 把「被扩展类型」的合并描述符 $pkg 设为**最后一个 trait 的包**
|
||||
// (moddle index.esm.js:577)。activiti.json 用 `extends` 给 bpmn:Process/UserTask/StartEvent…
|
||||
// 加属性 → 这些基础类型的 $pkg 变成 activiti 包;moddle-xml 序列化时按 $pkg 的
|
||||
// `xml.tagAlias` 决定元素名首字母是否小写。bpmn 包有 `tagAlias:"lowerCase"`(Process→process),
|
||||
// activiti 包若无此声明 → 写出 PascalCase `<Process>/<UserTask>/<StartEvent>`。
|
||||
// **Flowable 大小写敏感**:`<Process>` 不被识别为流程 → 部署时 ProcessValidator 报
|
||||
// flowable-process-definition-not-executable(看到 0 个可执行流程),部署完全失败。
|
||||
//
|
||||
// 为何 T1.1/T1.2 没抓到:它们只断言 activiti 扩展属性/元素多重集,**从不断言基础 BPMN 元素名的
|
||||
// 大小写**;且 fromXML→toXML 与 create 都走同一 moddle-xml Writer,均产 PascalCase(本文件实证)。
|
||||
//
|
||||
// 为何用 BpmnModdle 而非真 Modeler:bpmn-js Modeler 依赖 diagram-js 的 SVG 布局(getBBox 等),
|
||||
// jsdom 跑不动;而 Modeler.saveXML 在 moddle 层就是 `moddle.toXML(定义树)`,diagram-js 从不改元素名。
|
||||
// 故 `new BpmnModdle({activiti})` 的 fromXML→toXML / create→toXML 忠实复现 saveXML 的元素命名路径。
|
||||
|
||||
const BASE_TYPES: Array<[create: string, lower: string, pascal: string]> = [
|
||||
['bpmn:Process', 'process', 'Process'],
|
||||
['bpmn:UserTask', 'userTask', 'UserTask'],
|
||||
['bpmn:StartEvent', 'startEvent', 'StartEvent'],
|
||||
['bpmn:ScriptTask', 'scriptTask', 'ScriptTask'],
|
||||
['bpmn:EndEvent', 'endEvent', 'EndEvent'],
|
||||
['bpmn:SequenceFlow', 'sequenceFlow', 'SequenceFlow'],
|
||||
['bpmn:BoundaryEvent', 'boundaryEvent', 'BoundaryEvent'],
|
||||
];
|
||||
|
||||
/** 元素名正则(可选 bpmn: 前缀 + 精确 token + 分隔符),大小写敏感。 */
|
||||
const openTag = (name: string) => new RegExp('<(bpmn:)?' + name + '[\\s/>]');
|
||||
|
||||
describe('moddle 序列化——基础 BPMN 元素名小写(断部署回归)', () => {
|
||||
it('打开存量再导出(fromXML→toXML):基础元素名全小写,无 PascalCase(Flowable 可识别)', async () => {
|
||||
const moddle = new BpmnModdle({ activiti });
|
||||
const { rootElement } = await moddle.fromXML(SYNTHETIC_BPMN);
|
||||
const { xml } = await moddle.toXML(rootElement, { format: true });
|
||||
for (const [, lower, pascal] of BASE_TYPES) {
|
||||
expect(xml, `应含小写 <${lower}>`).toMatch(openTag(lower));
|
||||
expect(xml, `不应含 PascalCase <${pascal}>(Flowable 大小写敏感)`).not.toMatch(openTag(pascal));
|
||||
}
|
||||
});
|
||||
|
||||
it('isExecutable 症状:process 元素小写且保留 isExecutable="true"', async () => {
|
||||
const moddle = new BpmnModdle({ activiti });
|
||||
const { rootElement } = await moddle.fromXML(SYNTHETIC_BPMN);
|
||||
const { xml } = await moddle.toXML(rootElement, { format: true });
|
||||
// 真正的 bug 是 <Process> 不被识别("isExecutable 丢失"只是症状)——断言 process 小写即可。
|
||||
expect(xml).toMatch(/<(bpmn:)?process[\s][^>]*isExecutable="true"/);
|
||||
expect(xml).not.toMatch(openTag('Process'));
|
||||
});
|
||||
|
||||
it('新建元素(create→toXML):新建流程各基础节点名也全小写', async () => {
|
||||
const moddle = new BpmnModdle({ activiti });
|
||||
const defs = moddle.create('bpmn:Definitions', { targetNamespace: 'http://x' });
|
||||
const proc = moddle.create('bpmn:Process', { id: 'p1', isExecutable: true });
|
||||
const start = moddle.create('bpmn:StartEvent', { id: 's1' });
|
||||
const ut = moddle.create('bpmn:UserTask', {
|
||||
id: 't1',
|
||||
'activiti:candidateUsers': 'X',
|
||||
'activiti:formKey': 'K',
|
||||
});
|
||||
const flow = moddle.create('bpmn:SequenceFlow', { id: 'f1', sourceRef: start, targetRef: ut });
|
||||
const end = moddle.create('bpmn:EndEvent', { id: 'e1' });
|
||||
proc.flowElements = [start, ut, flow, end];
|
||||
defs.rootElements = [proc];
|
||||
const { xml } = await moddle.toXML(defs, { format: true });
|
||||
for (const [, lower, pascal] of BASE_TYPES.filter(([, l]) => l !== 'scriptTask' && l !== 'boundaryEvent')) {
|
||||
expect(xml, `应含小写 <${lower}>`).toMatch(openTag(lower));
|
||||
expect(xml, `不应含 PascalCase <${pascal}>`).not.toMatch(openTag(pascal));
|
||||
}
|
||||
// 扩展属性 / 自定义元素不受影响
|
||||
expect(xml).toContain('activiti:candidateUsers="X"');
|
||||
expect(xml).toContain('activiti:formKey="K"');
|
||||
});
|
||||
|
||||
it('flowable 描述符隔离同样小写(虽不进 Modeler,防同类潜伏 bug)', async () => {
|
||||
const moddle = new BpmnModdle({ flowable });
|
||||
const defs = moddle.create('bpmn:Definitions', { targetNamespace: 'http://x' });
|
||||
const proc = moddle.create('bpmn:Process', { id: 'p1', isExecutable: true });
|
||||
const ut = moddle.create('bpmn:UserTask', { id: 't1', 'flowable:assignee': 'u1' });
|
||||
proc.flowElements = [ut];
|
||||
defs.rootElements = [proc];
|
||||
const { xml } = await moddle.toXML(defs, { format: true });
|
||||
expect(xml).toMatch(openTag('process'));
|
||||
expect(xml).toMatch(openTag('userTask'));
|
||||
expect(xml).not.toMatch(openTag('Process'));
|
||||
expect(xml).not.toMatch(openTag('UserTask'));
|
||||
expect(xml).toContain('flowable:assignee="u1"');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user