fix: 修复开始表单旧工作流兼容回退

- 避免旧开始节点缺失 user_input 时运行态强行注入系统问题字段

- 补充运行参数解析兼容测试并收口 M12 尾项
This commit is contained in:
2026-04-19 14:11:07 +08:00
parent 9feb889637
commit 51198ff492
2 changed files with 49 additions and 1 deletions

View File

@@ -106,6 +106,35 @@ public class WorkflowRunningParameterResolverTest {
Assert.assertEquals("file", fields.get(1).get("type"));
}
/**
* 旧工作流若不存在系统问题参数,运行态不应凭空注入 user_input。
*
* @throws Exception 反射注入失败
*/
@Test
public void testBuildRunningParametersViewShouldNotInjectUserInputForLegacyParametersWithoutSystemField() throws Exception {
WorkflowRunningParameterResolver resolver = newResolver();
JSONObject startData = data("开始");
startData.put("parameters", startParametersWithoutUserInput());
Workflow workflow = workflow(
workflowJson(
array(
node("s1", "startNode", null, startData),
node("e1", "endNode", null, data("结束"))
),
array(edge("e1", "s1", "e1"))
)
);
Map<String, Object> result = resolver.buildRunningParametersView(workflow);
Assert.assertNotNull(result);
List<Map<String, Object>> fields = (List<Map<String, Object>>) result.get("startFormSchema");
Assert.assertEquals(1, fields.size());
Assert.assertEquals("attachments", fields.get(0).get("key"));
Assert.assertEquals("file", fields.get(0).get("type"));
}
/**
* 文件参数运行值应统一归一化为数组并按 filePath 去重。
*
@@ -209,6 +238,21 @@ public class WorkflowRunningParameterResolverTest {
return parameters;
}
private static JSONArray startParametersWithoutUserInput() {
JSONArray parameters = new JSONArray();
JSONObject fileField = new JSONObject();
fileField.put("name", "attachments");
fileField.put("dataType", "File");
fileField.put("refType", "input");
fileField.put("required", false);
fileField.put("contentType", "file");
fileField.put("formType", "input");
fileField.put("formLabel", "附件");
parameters.add(fileField);
return parameters;
}
private static Map<String, Object> fileValue(String fileName, String filePath, Long size) {
Map<String, Object> value = new LinkedHashMap<>();
value.put("fileName", fileName);