fix(modeler): 发布收口——原始源基线不被首存重置+发布前持久化(预览==部署)+跨命名空间diff测试

I1+I2 联锁修(同一根因:预览/diff 的两侧要对齐"打开时原始源"与"实际部署内容"):
- I1:新增 baselineTargetRef,openSourceRef 只在首次打开某目标时捕获原始源;存量首存
  setParams(modelId) 触发的 reload 因归属已预置为新 modelId 而保留基线,不再被冲成「已存版」
  →「打开存量→改办理人→存→发布」的 diff 恢复非空。
- I2:handlePublishClick 在开确认弹窗前先 saveDraft(currentXml) 持久化编辑器态,使
  后端 deploy 读到的服务端草稿 == 预览 == diff 的 current 侧(草稿改未存直接发布不再预览≠部署)。

Minor:
- M1:diffSummary 比 content 前做全角【】↔半角{} normWidth 归一(含 RAW 兜底路径),防宽度变体误报。
- M2:completionBody 折叠全部空白后比较,防 bpmn-js 重排空白误报完成条件变更。
- M3:PublishConfirm 发布中 guardedClose 拦截遮罩/X 关闭。

I3 测试:diffSummary 跨命名空间(默认 ns 源 vs bpmn: 前缀当前)对齐命中/前缀不误报 + M1 宽度变体;
页面 I1 锁(存量 save→publish 后 diff 基线仍原始源→清单非空,已 red-check 证伪防呆)+ I2(发布前 saveDraft)。

diffSummary 16 + PublishConfirm 9 + 页面 22;全量 227 单测绿,tsc -b rc=0 + build 干净。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-02 14:39:52 +08:00
parent 406f053ec2
commit 0428a5c9d1
5 changed files with 138 additions and 12 deletions

View File

@@ -87,6 +87,11 @@ export function PublishConfirm({
}
}
// M3:发布进行中拦截关闭(遮罩点击 / X 按钮),避免中途关窗留下不确定态。
const guardedClose = () => {
if (!deploying) onClose();
};
const key = impact?.processKey || processKeyHint || '(未知)';
const cur = impact?.currentVersion ?? 0;
const versionText = !impactLoaded
@@ -100,7 +105,7 @@ export function PublishConfirm({
const foot = (
<>
<button className="btn" data-testid="publish-cancel-btn" onClick={onClose} disabled={deploying}>
<button className="btn" data-testid="publish-cancel-btn" onClick={guardedClose} disabled={deploying}>
取消
</button>
<button
@@ -115,7 +120,7 @@ export function PublishConfirm({
);
return (
<Dialog title="发布流程" width={520} onClose={onClose} foot={foot}>
<Dialog title="发布流程" width={520} onClose={guardedClose} foot={foot}>
<div data-testid="process-modeler-publish-confirm" style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
{/* 影响摘要 */}
<div style={{ display: 'flex', flexDirection: 'column', gap: 6, fontSize: 13 }}>

View File

@@ -1,6 +1,7 @@
import { describe, it, expect } from 'vitest';
import { SYNTHETIC_BPMN } from './moddle/fixtures/synthetic-full-surface.bpmn';
import { diffSummary } from './diffSummary';
import { buildCandidateExpression, type UserPropertyItem } from './candidateExpression';
// 节点级 diff(P2):以「总包合同交底」逐字对照的 synthetic fixture 为基线,
// 按 userTask id 对齐比较四类属性变化(办理人/指派/formKey/会签)。改动用**定点字符串替换**
@@ -127,3 +128,67 @@ describe('diffSummary — 节点级四类属性 diff', () => {
expect(diffSummary(SYNTHETIC_BPMN, '<<<')).toEqual([]);
});
});
// I3-①:跨命名空间对齐——源用默认命名空间(存量存储态),当前用 bpmn: 前缀(bpmn-js saveXML 输出)。
// diff 必须按命名空间 URI(而非字面前缀)对齐 userTask,否则「改存量→发布」全链的 diff 会漏。
describe('diffSummary — 跨命名空间(默认 ns vs bpmn: 前缀)对齐', () => {
const item = (type: string, content: string): UserPropertyItem => ({
type,
content,
isCandidate: true,
isSendMail: false,
isSendPhone: false,
isSendMessage: false,
});
// 办理人表达式属性值需把 " 转义成 &quot; 才能进 XML 属性。
const candAttr = (items: UserPropertyItem[]) =>
buildCandidateExpression(items, 'candidate').replace(/"/g, '&quot;');
// 默认命名空间(无前缀),activiti: 前缀属性——模拟存量源。
const defaultNs = (items: UserPropertyItem[]) =>
`<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" targetNamespace="x">
<process id="p1" name="流程" isExecutable="true">
<userTask id="t1" name="任务甲" activiti:candidateUsers="${candAttr(items)}"></userTask>
</process>
</definitions>`;
// bpmn: 前缀(BPMN 元素全部带前缀,namespaceURI 不变)——模拟 bpmn-js saveXML 输出。
const bpmnPrefixed = (items: UserPropertyItem[]) =>
`<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" targetNamespace="x">
<bpmn:process id="p1" name="流程" isExecutable="true">
<bpmn:userTask id="t1" name="任务甲" activiti:candidateUsers="${candAttr(items)}"></bpmn:userTask>
</bpmn:process>
</bpmn:definitions>`;
const ITEMS_A = [item('user', 'u1')];
const ITEMS_B = [item('depart', 'd1')];
it('前缀不同、语义相同 → 无变化(前缀本身不误报)', () => {
expect(diffSummary(defaultNs(ITEMS_A), bpmnPrefixed(ITEMS_A))).toEqual([]);
});
it('前缀不同、办理人改了 → 按 URI 对齐命中「办理人变更」', () => {
expect(diffSummary(defaultNs(ITEMS_A), bpmnPrefixed(ITEMS_B))).toEqual([
{ nodeName: '任务甲', changes: ['办理人变更'] },
]);
});
});
// M1:会签人员 content 的全角/半角宽度变体不应误报(parse 已 fullToHalf,diff 再兜一层 normWidth)。
describe('diffSummary — 人员 content 宽度变体不误报(M1)', () => {
it('collection content 仅全角【】↔半角{} 之差 → 无「会签人员变更」', () => {
// 两版仅 collection 人员 content 的括号宽度不同:${x}(半角)vs $【x】(全角),运行期等价。
const withHalf = SYNTHETIC_BPMN.replace(
'&quot;content&quot;:&quot;true,false,false,false,false,false,false,false,false,false,false&quot;',
'&quot;content&quot;:&quot;${x}&quot;',
);
const withFull = SYNTHETIC_BPMN.replace(
'&quot;content&quot;:&quot;true,false,false,false,false,false,false,false,false,false,false&quot;',
'&quot;content&quot;:&quot;$【x】&quot;',
);
expect(withHalf).not.toBe(withFull); // 两版确有字面差异
expect(diffSummary(withHalf, withFull)).toEqual([]);
});
});

View File

@@ -78,10 +78,15 @@ function miOf(el: Element): Element | null {
return list.length ? list[0] : null;
}
/** 多实例完成条件 body(规范化去空白),无则空串。 */
/** 多实例完成条件 body(折叠全部空白后比较,避免 bpmn-js 重排空白误报变更),无则空串。 */
function completionBody(mi: Element): string {
const list = mi.getElementsByTagNameNS(BPMN_NS, 'completionCondition');
return list.length ? (list[0].textContent ?? '').trim() : '';
return list.length ? (list[0].textContent ?? '').replace(/\s+/g, '') : '';
}
/** 全角【】↔半角{} 归一(与 codec parse 的 fullToHalf 同口径),防人员 content 宽度变体误报。 */
function normWidth(s: string): string {
return s.split('【').join('{').split('】').join('}');
}
/**
@@ -92,11 +97,11 @@ function completionBody(mi: Element): string {
function exprSig(raw: string | undefined): string {
if (!raw) return '';
const parsed = parseCandidateExpression(raw);
if (!parsed) return 'RAW:' + raw;
if (!parsed) return 'RAW:' + normWidth(raw);
return JSON.stringify(
parsed.items.map((i) => [
i.type,
i.content,
normWidth(i.content),
!!i.isCandidate,
!!i.isSendMail,
!!i.isSendPhone,