fix(workflow): require confirmation and honor dry-run for node grants

This commit is contained in:
gitea committed 2026-10-20 17:50:45 +08:00
1 parent fac81b08e8
commit 0e6090a92c
5 files changed
+242 -214

No files matched your search

@@ -0,0 +1,18 @@
import { expect, spyOn, test } from "bun:test";
import { parseArgs } from "../parser.js";
import { handleWorkflowCommand } from "./workflow/index.js";
import * as services from "../../domains/platform/services.js";
test("node grant previews without a gateway call and requires explicit confirmation", async () => {
const runtime = { selectedCorp: { id: "corp", credentials: { corpId: "corp" } }, jsonMode: true } as any;
const grant = spyOn(services, "grantWorkflowNodes").mockResolvedValue({ success: true, saved: ["code-js2"], skipped: [], rawMessage: "ok" });
try {
await expect(handleWorkflowCommand(parseArgs(["workflow", "nodes", "grant", "code-js2"]), runtime)).rejects.toThrow("--yes");
const result = await handleWorkflowCommand(parseArgs(["workflow", "nodes", "grant", "JS节点(新)", "--dry-run", "--yes"]), runtime);
expect(JSON.parse(result.stdout).dryRun).toBe(true);
expect(JSON.parse(result.stdout).changes.nodes).toEqual(["code-js2"]);
expect(grant).not.toHaveBeenCalled();
await handleWorkflowCommand(parseArgs(["workflow", "nodes", "grant", "code-js2", "--confirm"]), runtime);
expect(grant).toHaveBeenCalledTimes(1);
} finally { grant.mockRestore(); }
});
+2 -2
View File
@@ -147,7 +147,7 @@ describe("CLI - workflow nodes 字典探针与灰度开通测试", () => {
area: "workflow",
action: "nodes",
args: ["grant", "code-js2"],
options: {},
options: { yes: true },
raw: ["workflow", "nodes", "grant", "code-js2"],
},
mockRuntime
@@ -180,7 +180,7 @@ describe("CLI - workflow nodes 字典探针与灰度开通测试", () => {
area: "workflow",
action: "nodes",
args: ["grant", "JS节点(新)"],
options: {},
options: { yes: true },
raw: ["workflow", "nodes", "grant", "JS节点(新)"],
},
mockRuntime
+8
View File
@@ -587,6 +587,14 @@ async function handleGrantNodes(
};
}
requireMutationConfirmation(parsed, runtime, "开通企业工作流灰度节点", "hose-use workflow nodes grant <type...> --yes");
if (isDryRun(parsed, runtime)) {
return mutationPreview(parsed, runtime, "开通企业工作流灰度节点", corp.corpId || corp.credentials.corpId || corp.id, {
nodes: targetNodes.map(node => findGrayNode(node)?.type || node.trim()),
adminPasswordRequired: Boolean(process.env.HOSE_ADMIN_PASSWORD),
});
}
const password = stringOption(parsed.options, ["password", "pwd", "admin-key"]);
const result = await grantWorkflowNodes(corp, {
@@ -19,7 +19,7 @@ hose-use workflow create [--name=<名称>] [--trigger=webhook|clock|datalink|flo
hose-use workflow copy <pipelineId> [--name=<名称>] [--platform-id=<应用ID>] [--dry-run|--yes]
hose-use workflow delete <pipelineId> [--dry-run|--yes]
hose-use workflow nodes [list] [--all]
hose-use workflow nodes grant <type...> [--password=<pwd>]
hose-use workflow nodes grant <type...> [--password=<pwd>] [--dry-run|--yes]
hose-use workflow node list <pipelineId>
hose-use workflow node get <pipelineId> <节点name或#序号>
hose-use workflow node add <pipelineId> --type=code-js2 --label="清洗" --code="..." [--after=<节点>] [--parent=<容器>] [--dry-run|--yes]
@@ -128,3 +128,5 @@ hose-use workflow eval-script --code="return a + b;" --input='{"a":1,"b":2}'
- 借助 Kimi 网桥(`kimi-webbridge`)建立真实微前端会话,自动探测并解析不同应用类型下的非费用类表单元数据;
- 提取出动态列、关联实体 ID 与系统字段字典,在 CLI 层面提供对非费用类业务对象的只读探针与结构化校验能力。
灰度开通遵循统一写操作门禁:`--dry-run` 仅返回归一化节点清单且不调用网关;实际开通需要 `--yes/--confirm`。管理员密码用于额外授权,不能替代写操作确认。