From 51198ff49257ccb84d653dd492b719ccb36edb59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=AD=90=E9=BB=98?= <925456043@qq.com> Date: Sun, 19 Apr 2026 14:11:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=BC=80=E5=A7=8B?= =?UTF-8?q?=E8=A1=A8=E5=8D=95=E6=97=A7=E5=B7=A5=E4=BD=9C=E6=B5=81=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 避免旧开始节点缺失 user_input 时运行态强行注入系统问题字段 - 补充运行参数解析兼容测试并收口 M12 尾项 --- .../WorkflowRunningParameterResolver.java | 6 ++- .../WorkflowRunningParameterResolverTest.java | 44 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/easyflow-modules/easyflow-module-ai/src/main/java/tech/easyflow/ai/easyagentsflow/service/WorkflowRunningParameterResolver.java b/easyflow-modules/easyflow-module-ai/src/main/java/tech/easyflow/ai/easyagentsflow/service/WorkflowRunningParameterResolver.java index 5db7df1..9e04401 100644 --- a/easyflow-modules/easyflow-module-ai/src/main/java/tech/easyflow/ai/easyagentsflow/service/WorkflowRunningParameterResolver.java +++ b/easyflow-modules/easyflow-module-ai/src/main/java/tech/easyflow/ai/easyagentsflow/service/WorkflowRunningParameterResolver.java @@ -128,6 +128,10 @@ public class WorkflowRunningParameterResolver { JSONArray rawSchema = startNodeData == null ? null : startNodeData.getJSONArray("startFormSchema"); List> schema = new ArrayList<>(); Set seenKeys = new LinkedHashSet<>(); + boolean hasExplicitSchema = rawSchema != null; + boolean hasSystemParameter = parameters.stream().anyMatch(parameter -> + SYSTEM_START_PARAM_NAME.equals(trimToNull(parameter == null ? null : parameter.getName())) + ); if (rawSchema != null && !rawSchema.isEmpty()) { for (int i = 0; i < rawSchema.size(); i++) { JSONObject field = rawSchema.getJSONObject(i); @@ -163,7 +167,7 @@ public class WorkflowRunningParameterResolver { } } } - if (!seenKeys.contains(SYSTEM_START_PARAM_NAME)) { + if (!seenKeys.contains(SYSTEM_START_PARAM_NAME) && (hasExplicitSchema || hasSystemParameter)) { schema.add(0, normalizeStartFormField(new JSONObject(), null)); } return schema; diff --git a/easyflow-modules/easyflow-module-ai/src/test/java/tech/easyflow/ai/easyagentsflow/service/WorkflowRunningParameterResolverTest.java b/easyflow-modules/easyflow-module-ai/src/test/java/tech/easyflow/ai/easyagentsflow/service/WorkflowRunningParameterResolverTest.java index d2ba88e..9e4dee1 100644 --- a/easyflow-modules/easyflow-module-ai/src/test/java/tech/easyflow/ai/easyagentsflow/service/WorkflowRunningParameterResolverTest.java +++ b/easyflow-modules/easyflow-module-ai/src/test/java/tech/easyflow/ai/easyagentsflow/service/WorkflowRunningParameterResolverTest.java @@ -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 result = resolver.buildRunningParametersView(workflow); + Assert.assertNotNull(result); + List> fields = (List>) 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 fileValue(String fileName, String filePath, Long size) { Map value = new LinkedHashMap<>(); value.put("fileName", fileName);