fix: 防止开始节点重名参数被删除

- 校验开始节点参数名并保留冲突输入

- 在字段归一化前拦截重名并补充回归测试
This commit is contained in:
2026-07-30 16:23:34 +08:00
parent 5dbb46ef8f
commit 9959f95b94
3 changed files with 128 additions and 3 deletions

View File

@@ -13,6 +13,7 @@ import {
createInitialWorkflowData,
ensureStartNodeParameters,
FIELD_BINDING_META_KEY,
isStartFormFieldKeyAvailable,
normalizeStartNodeData,
normalizeWorkflowStartNodes,
renameStartFieldReferencesInNodes,
@@ -148,6 +149,47 @@ describe('workflow node fields', () => {
expect(nextParameter?.id).toBe(previousParameter?.id);
});
it('keeps start fields unchanged when renaming to an existing key', () => {
const initial = createInitialWorkflowData();
const withTopic = appendStartFormField(
initial.nodes[0]?.data as Record<string, any>,
{
key: 'topic',
label: '主题',
type: 'text',
},
);
const withDetails = appendStartFormField(withTopic, {
key: 'details',
label: '详情',
type: 'textarea',
});
const previousFields = withDetails.startFormSchema;
const previousParameters = withDetails.parameters;
expect(
isStartFormFieldKeyAvailable(withDetails, 'details', 'summary'),
).toBe(true);
expect(
isStartFormFieldKeyAvailable(withDetails, 'details', 'topic'),
).toBe(false);
expect(
isStartFormFieldKeyAvailable(withDetails, 'details', 'user_input'),
).toBe(false);
const duplicatedCustomKey = updateStartFormField(withDetails, 'details', {
key: 'topic',
});
const duplicatedSystemKey = updateStartFormField(withDetails, 'details', {
key: 'user_input',
});
expect(duplicatedCustomKey.startFormSchema).toEqual(previousFields);
expect(duplicatedCustomKey.parameters).toEqual(previousParameters);
expect(duplicatedSystemKey.startFormSchema).toEqual(previousFields);
expect(duplicatedSystemKey.parameters).toEqual(previousParameters);
});
it('renames downstream token and managed references when start field key changes', () => {
const initialStartData = appendStartFormField(
createInitialWorkflowData().nodes[0]?.data as Record<string, any>,