import { expect, spyOn, test } from "bun:test"; import { handleWorkflowCommand } from "./workflow/index.js"; import { parseArgs } from "../parser.js"; import * as services from "../../domains/platform/workflow/services.js"; test("production corp is blocked before any grant request or confirmation", async () => { const grant = spyOn(services, "grantWorkflowNodes").mockResolvedValue({ success: true, saved: ["code"], skipped: [], rawMessage: "ok", isTest: false, }); try { const runtime = { selectedCorp: { id: "prod-corp", name: "正式生产企业", env: "prod", credentials: { corpId: "prod-corp", accessToken: "token" }, }, jsonMode: false, } as any; const result = await handleWorkflowCommand( parseArgs(["workflow", "nodes", "grant", "code", "--yes"]), runtime ); expect(result.exitCode).toBe(1); expect(result.stderr).toContain("生产环境安全阻断"); expect(result.stderr).toContain("未提供 --force 逃生口"); expect(grant).not.toHaveBeenCalled(); } finally { grant.mockRestore(); } }); test("env-unmarked corp is conservatively treated as production", async () => { const grant = spyOn(services, "grantWorkflowNodes").mockResolvedValue({ success: true, saved: [], skipped: [], rawMessage: "ok", isTest: false, }); try { const result = await handleWorkflowCommand( parseArgs(["workflow", "nodes", "grant", "code", "--yes"]), { selectedCorp: { id: "corp", name: "浙江麦瑞克科技有限公司" }, jsonMode: true } as any ); expect(result.exitCode).toBe(1); expect(JSON.parse(result.stdout).code).toBe("PROD_GRANT_BLOCKED"); expect(grant).not.toHaveBeenCalled(); } finally { grant.mockRestore(); } });