Files
hose-use/src/cli/commands/workflow-nodes-confirmation.test.ts
T
gitea 8375445bcb fix: 灰度节点开通加生产硬拦截并拆薄传输层
三处 P0:
- 生产企业零拦截:handleGrantNodes 用 isCorpProd 直接拒绝,无
  --force 逃生口,且拦截发生在 --yes 确认之前;补 2 条单测。
- dry-run 预览失真:payload 改由编排层显式构造,固定附带开关
  (recalculate-the-approval-flow / ui-notification / start) 提为
  GRANT_ATTACHED_OPTIONS,dry-run 与成功输出都会展示。刻意不改
  真实 payload 语义,避免破坏 Piper 历史接口契约。
- api.ts 越权:只留换票、POST、响应校验;业务码判定与
  saved/skipped 映射移到 catalog.ts 的 mapGrantResult。新增
  assertNoAuthFailure 复用 EASO 响应体系,401/403 统一转成
  AuthenticationError(CLI 退出码 11)。

P1:修 gray-nodes-catalog 同名「数据映射」(mapping/dmn) 静默覆盖,
normalizeGrayNodes 遇歧义抛 ValidationError;节点去重;删 node.ts
死常量;Piper 测试域名常量收敛到 core/http;修 filterKw 的
args[1] 越界;归一化逻辑收敛为一份;同步文档与测试名。

校验:bun test 1099 pass / 0 fail,bun run check、check:readme 通过。
本次不打 tag、不触发 Release;Skill 内嵌变更等 0.9.3 发版生效。
2026-11-05 16:46:48 +08:00

24 lines
1.7 KiB
TypeScript

import { expect, spyOn, test } from "bun:test";
import { parseArgs } from "../parser.js";
import { handleWorkflowCommand } from "./workflow/index.js";
import * as services from "../../domains/platform/workflow/services.js";
test("node grant previews without a Piper call and requires explicit confirmation", async () => {
const runtime = { selectedCorp: { id: "corp", isTest: true, 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();
const testPreview = await handleWorkflowCommand(parseArgs(["workflow", "nodes", "grant", "code", "--is-test", "--dry-run", "--yes"]), runtime);
expect(JSON.parse(testPreview.stdout).changes.isTest).toBe(true);
expect(grant).not.toHaveBeenCalled();
await handleWorkflowCommand(parseArgs(["workflow", "nodes", "grant", "code-js2", "--confirm"]), runtime);
expect(grant).toHaveBeenCalledTimes(1);
await handleWorkflowCommand(parseArgs(["workflow", "nodes", "grant", "code", "--is-test", "--yes"]), runtime);
expect(grant).toHaveBeenLastCalledWith(expect.anything(), expect.objectContaining({ nodes: ["code"], isTest: true }));
} finally { grant.mockRestore(); }
});