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(); } });