fix(workflow): distinguish hierarchical node selectors from global indices
This commit is contained in:
1 parent
fac81b08e8
commit
f46e0e7b0a
4 files changed
+22
-5
No files matched your search
@@ -128,3 +128,5 @@ hose-use workflow eval-script --code="return a + b;" --input='{"a":1,"b":2}'
|
||||
- 借助 Kimi 网桥(`kimi-webbridge`)建立真实微前端会话,自动探测并解析不同应用类型下的非费用类表单元数据;
|
||||
- 提取出动态列、关联实体 ID 与系统字段字典,在 CLI 层面提供对非费用类业务对象的只读探针与结构化校验能力。
|
||||
|
||||
|
||||
节点定位约定:CLI 的字符串编号(如 `3`、`2.1`)始终对应列表展示的层级编号;SDK 传入数字 `3` 时表示深度优先遍历的第 3 个节点。节点名称仍可直接用于定位,两个编号体系不再在一次查找中竞争。
|
||||
@@ -0,0 +1,16 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { findWorkflowTask } from "./locator.js";
|
||||
import { editWorkflowTask, removeWorkflowTask } from "./mutations.js";
|
||||
const workflow = { tasks: [{ name: "trigger", type: "webhook" }, { name: "branch", type: "condition", tasks: [{ name: "child", type: "http" }] }, { name: "third", type: "http" }] } as any;
|
||||
test("string indices select displayed hierarchy while SDK numbers select traversal order", () => {
|
||||
expect(findWorkflowTask(workflow, "3")?.task.name).toBe("third");
|
||||
expect(findWorkflowTask(workflow, "2.1")?.task.name).toBe("child");
|
||||
expect(findWorkflowTask(workflow, 3)?.task.name).toBe("child");
|
||||
expect(findWorkflowTask(workflow, "child")?.hierarchicalIndex).toBe("2.1");
|
||||
const edited = editWorkflowTask(workflow, "3", { label: "changed" });
|
||||
expect(edited.workflow.tasks[2].label).toBe("changed");
|
||||
expect(edited.workflow.tasks[1].tasks![0].label).toBeUndefined();
|
||||
const removed = removeWorkflowTask(workflow, "3");
|
||||
expect(removed.removedTask.name).toBe("third");
|
||||
expect(removed.workflow.tasks[1].tasks![0].name).toBe("child");
|
||||
});
|
||||
@@ -2,7 +2,7 @@ import type { WorkflowTask } from "../../types.js";
|
||||
import type { LocatedWorkflowTask } from "./types.js";
|
||||
|
||||
/**
|
||||
* 在任务树中按节点名称、层级编号 (如 "2.1") 或全局序号定位目标任务
|
||||
* 在任务树中按字符串节点名称、字符串层级编号 (如 "2.1") 或数字全局序号定位目标任务
|
||||
*/
|
||||
export function findWorkflowTask(
|
||||
tasksOrWorkflow: WorkflowTask[] | { tasks?: WorkflowTask[] },
|
||||
@@ -13,7 +13,7 @@ export function findWorkflowTask(
|
||||
: tasksOrWorkflow?.tasks || [];
|
||||
const targetStr = String(target).trim();
|
||||
const targetNum = Number(targetStr);
|
||||
const isNumeric = !Number.isNaN(targetNum) && Number.isInteger(targetNum) && targetNum > 0;
|
||||
const isNumeric = typeof target === "number" && Number.isInteger(targetNum) && targetNum > 0;
|
||||
|
||||
let globalCounter = 0;
|
||||
|
||||
@@ -30,8 +30,7 @@ export function findWorkflowTask(
|
||||
const path = basePath ? `${basePath}.${i}` : `tasks.${i}`;
|
||||
|
||||
const matched =
|
||||
task.name === targetStr ||
|
||||
hierarchicalIndex === targetStr ||
|
||||
(typeof target === "string" && (task.name === targetStr || hierarchicalIndex === targetStr)) ||
|
||||
(isNumeric && globalCounter === targetNum);
|
||||
|
||||
if (matched) {
|
||||
|
||||
Reference in new issue
Block a user