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:
@@ -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 }}>
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
// 办理人表达式属性值需把 " 转义成 " 才能进 XML 属性。
|
||||
const candAttr = (items: UserPropertyItem[]) =>
|
||||
buildCandidateExpression(items, 'candidate').replace(/"/g, '"');
|
||||
|
||||
// 默认命名空间(无前缀),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(
|
||||
'"content":"true,false,false,false,false,false,false,false,false,false,false"',
|
||||
'"content":"${x}"',
|
||||
);
|
||||
const withFull = SYNTHETIC_BPMN.replace(
|
||||
'"content":"true,false,false,false,false,false,false,false,false,false,false"',
|
||||
'"content":"$【x】"',
|
||||
);
|
||||
expect(withHalf).not.toBe(withFull); // 两版确有字面差异
|
||||
expect(diffSummary(withHalf, withFull)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -326,12 +326,14 @@ describe('ProcessModelerPage', () => {
|
||||
expect(mDeploy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('发布:打开草稿(有 modelId)→点发布→开同人确认弹窗并按 modelId 拉 impact', async () => {
|
||||
it('发布:打开草稿(有 modelId)→点发布→先持久化(I2)→开同人确认弹窗并按 modelId 拉 impact', async () => {
|
||||
renderPage('/process-modeler?modelId=MD-7');
|
||||
await waitFor(() => expect(importXMLMock).toHaveBeenCalled());
|
||||
await waitFor(() => expect(publishBtn()).not.toBeDisabled());
|
||||
fireEvent.click(publishBtn());
|
||||
await waitFor(() => expect(saveXMLMock).toHaveBeenCalled());
|
||||
// I2:发布前先 saveDraft(当前 xml) 持久化,使部署内容==预览==diff current 侧。
|
||||
await waitFor(() => expect(mSaveDraft).toHaveBeenCalledWith('MD-7', { bpmnXml: '<edited/>' }));
|
||||
await waitFor(() => expect(screen.getByTestId('process-modeler-publish-confirm')).toBeInTheDocument());
|
||||
await waitFor(() => expect(mImpact).toHaveBeenCalledWith('MD-7'));
|
||||
// 确认发布 → deployModel(MD-7) → 成功后弹窗关闭
|
||||
@@ -341,4 +343,31 @@ describe('ProcessModelerPage', () => {
|
||||
expect(screen.queryByTestId('process-modeler-publish-confirm')).not.toBeInTheDocument(),
|
||||
);
|
||||
});
|
||||
|
||||
// I1 锁:存量按 key 打开→改→首存(reload)→发布,diff 基线必须仍是**原始源**(非「已存版」),故 diff 非空。
|
||||
it('I1:存量 save→publish 后 diff 基线仍是原始源→变更清单非空', async () => {
|
||||
// 原始源(办理人 type=position) vs 首存后 reload/当前编辑器态(办理人 type=user)。
|
||||
const EDITED = SYNTHETIC_BPMN.replace(
|
||||
'"type":"position"',
|
||||
'"type":"user"',
|
||||
);
|
||||
mSourceByKey.mockResolvedValue({ found: true, bpmnXml: SYNTHETIC_BPMN, idMap: { '总包合同交底': 'Proc_zbht' } });
|
||||
// 首存后 setParams(modelId=NEW-1) 触发 reload:getModel 返回已存(编辑)版,模拟服务端草稿态。
|
||||
mGetModel.mockResolvedValue({ found: true, bpmnXml: EDITED, metaInfo: JSON.stringify({ eip4IdMap: {} }), key: '总包合同交底' });
|
||||
// 当前编辑器 saveXML 返回编辑版(与已存版一致)。
|
||||
saveXMLMock.mockResolvedValue({ xml: EDITED });
|
||||
|
||||
renderPage('/process-modeler?procKey=' + encodeURIComponent('总包合同交底'));
|
||||
await waitFor(() => expect(importXMLMock).toHaveBeenCalledWith(SYNTHETIC_BPMN)); // 初次载原始源
|
||||
await waitFor(() => expect(saveBtn()).not.toBeDisabled());
|
||||
fireEvent.click(saveBtn()); // 首存 → createDraft NEW-1 → 回填 ?modelId= → reload
|
||||
await waitFor(() => expect(mCreateDraft).toHaveBeenCalled());
|
||||
await waitFor(() => expect(mGetModel).toHaveBeenCalledWith('NEW-1'));
|
||||
await waitFor(() => expect(publishBtn()).not.toBeDisabled());
|
||||
fireEvent.click(publishBtn());
|
||||
await waitFor(() => expect(screen.getByTestId('process-modeler-publish-confirm')).toBeInTheDocument());
|
||||
// 基线保留为原始源 → diff(原始, 编辑) 非空、含「办理人变更」;未修复则基线=编辑版 → diff 空。
|
||||
expect(screen.queryByTestId('publish-diff-empty')).not.toBeInTheDocument();
|
||||
expect(screen.getByTestId('publish-diff-list')).toHaveTextContent('办理人变更');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -78,8 +78,12 @@ export function ProcessModelerPage() {
|
||||
const modelIdRef = useRef<string>('');
|
||||
// 当前载入流程的 key(存量 procDefKey / 草稿 key)——新建草稿的 name/key 源。
|
||||
const loadedKeyRef = useRef<string>('');
|
||||
// 打开时的源 XML(发布影响摘要的 diff 基线:openSource vs 当前 saveXML)。
|
||||
// 打开时的**原始**源 XML(发布影响摘要的 diff 基线:openSource vs 当前 saveXML)。
|
||||
const openSourceRef = useRef<string>('');
|
||||
// 基线归属标识:openSourceRef 对应哪个打开目标。存量首存会 setParams(modelId) 触发载入 effect
|
||||
// 重跑(procKey→modelId),若每次重设基线,则「打开存量→改→存→发布」的 diff(已存版,已存版) 恒空
|
||||
// (I1)。故首存前把归属预置为新 modelId,effect 见归属未变即**保留原始基线不重置**。
|
||||
const baselineTargetRef = useRef<string>('');
|
||||
|
||||
const [loadState, setLoadState] = useState<LoadState>('idle');
|
||||
const [loadError, setLoadError] = useState('');
|
||||
@@ -174,7 +178,17 @@ export function ProcessModelerPage() {
|
||||
}
|
||||
idMapRef.current = src.idMap ?? {};
|
||||
loadedKeyRef.current = src.key ?? '';
|
||||
openSourceRef.current = src.bpmnXml; // diff 基线(此处 bpmnXml 已由上方 found 守卫保证非空)
|
||||
// diff 基线:仅在**首次打开某目标**时捕获原始源;同目标重跑(含首存后 procKey→modelId
|
||||
// 的 reload,归属已由 handleSaveDraft 预置成新 modelId)则保留,防 I1 基线被冲成「已存版」。
|
||||
const openTargetKey = modelIdParam
|
||||
? 'model:' + modelIdParam
|
||||
: procDefId
|
||||
? 'pd:' + procDefId
|
||||
: 'pk:' + procKey;
|
||||
if (baselineTargetRef.current !== openTargetKey) {
|
||||
openSourceRef.current = src.bpmnXml; // 此处 bpmnXml 已由上方 found 守卫保证非空
|
||||
baselineTargetRef.current = openTargetKey;
|
||||
}
|
||||
// 草稿路:记住 modelId(后续保存走 PUT);存量路:清空(首次保存新建草稿)。
|
||||
modelIdRef.current = modelIdParam || '';
|
||||
await modeler.importXML(src.bpmnXml);
|
||||
@@ -226,6 +240,8 @@ export function ProcessModelerPage() {
|
||||
modelId = await draftFromProcDef(procDefId);
|
||||
await saveDraft(modelId, { bpmnXml: xml });
|
||||
modelIdRef.current = modelId;
|
||||
// I1:预置基线归属为新 modelId,使随后的 reload 保留原始源基线(不被冲成「已存版」)。
|
||||
baselineTargetRef.current = 'model:' + modelId;
|
||||
// I-2:首存回填 ?modelId=,令刷新幂等(不再重复建草稿)、二次保存恒走 PUT。
|
||||
setParams({ modelId }, { replace: true });
|
||||
} else {
|
||||
@@ -239,6 +255,8 @@ export function ProcessModelerPage() {
|
||||
});
|
||||
modelId = await createDraft({ name: key, key, bpmnXml: xml, metaInfo });
|
||||
modelIdRef.current = modelId;
|
||||
// I1:同上,reload 保留原始源基线。
|
||||
baselineTargetRef.current = 'model:' + modelId;
|
||||
setParams({ modelId }, { replace: true });
|
||||
}
|
||||
toast('已保存草稿', 'ok');
|
||||
@@ -249,19 +267,23 @@ export function ProcessModelerPage() {
|
||||
}
|
||||
}
|
||||
|
||||
// 发布:需先有草稿(modelId)——未存则提示先存;已存则取当前 saveXML 开同人确认弹窗。
|
||||
// 发布:需先有草稿(modelId)——未存则提示先存;已存则先把当前编辑器态持久化进草稿,再开确认弹窗。
|
||||
// I2:后端 deploy 从服务端草稿取源部署,故发布前必须 saveDraft(currentXml),使
|
||||
// 部署内容 == 预览内容 == diff 的 current 侧(否则「打开草稿→改未存→直接发布」预览≠部署)。
|
||||
async function handlePublishClick() {
|
||||
const modeler = modelerRef.current;
|
||||
if (!modeler || saving) return;
|
||||
if (!modelIdRef.current) {
|
||||
const modelId = modelIdRef.current;
|
||||
if (!modelId) {
|
||||
toast('请先保存草稿,再发布', 'warn');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const { xml } = await modeler.saveXML({ format: true });
|
||||
await saveDraft(modelId, { bpmnXml: xml }); // 持久化当前态,保证部署==预览
|
||||
setPublish({ xml });
|
||||
} catch {
|
||||
toast('读取流程内容失败', 'err');
|
||||
toast('发布前保存失败,请重试', 'err');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user