merge: integrate review-06-node-index-resolution

This commit is contained in:
gitea committed 2026-10-20 23:02:07 +08:00
commit 29841a2374
4 files changed
+22 -5

No files matched your search

@@ -135,3 +135,5 @@ hose-use workflow eval-script --code="return a + b;" --input='{"a":1,"b":2}'
`eval-script` 使用内嵌 QuickJS/WASM 独立运行时,输入经过 JSON 复制,脚本无法访问宿主的 `process`、`Bun`、文件或网络。保留同步 JavaScript、日志和结构化执行结果;Promise 返回值明确报错。执行时间默认 3000ms,内存上限 32MiB,输入和结果各不超过 1MiB,日志最多 500 条及 64KiB。WASM 随 MCP bundle 和单文件二进制一起分发,不需要额外运行时文件。
灰度开通遵循统一写操作门禁:`--dry-run` 仅返回归一化节点清单且不调用网关;实际开通需要 `--yes/--confirm`。管理员密码用于额外授权,不能替代写操作确认。
节点定位约定: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) {