- 新增 src/cli/production.ts:--allow-prod 为唯一生产覆盖参数, --allow-production / --force 仅作兼容别名;JSON 阻断统一为 PROD_OVERRIDE_REQUIRED,并携带 nextAction 与 details.operation - workflow test 与 workflow nodes grant 统一提示文案、错误结构与 nextAction 生成;workflow test 的 JSON 阻断不再返回空 stdout - 预览 --dry-run 始终放行,实际执行才要求覆盖参数;nodes grant 参数校验前置,缺少节点类型时不再先报生产阻断 - 两个命令的成功结果统一携带 productionOverride / productionWarning - corps tag 将企业从 prod 降级为 test/demo 时输出显著警告 - 同步 CLI 帮助、CLI/workflow README 与 Skill;补充对应单测 Co-Authored-By: Claude <noreply@anthropic.com>
219 lines
6.5 KiB
TypeScript
219 lines
6.5 KiB
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import { handleCorpsCommand } from "./corps/index.js";
|
|
import { handleContextCommand } from "./context.js";
|
|
import { CorpContext } from "../../core/config/manager.js";
|
|
import type { CorpConfig } from "../../core/config/types.js";
|
|
import type { CliRuntime } from "../types.js";
|
|
|
|
const sampleCorps: CorpConfig[] = [
|
|
{
|
|
id: "corp_prod",
|
|
name: "新转转集团",
|
|
env: "prod",
|
|
isTest: false,
|
|
baseUrl: "https://app.ekuaibao.com",
|
|
source: "manual",
|
|
credentials: { corpId: "corp_prod", staffId: "staff_1", accessToken: "t1" },
|
|
},
|
|
{
|
|
id: "corp_test",
|
|
name: "HAB对公测试环境",
|
|
env: "test",
|
|
isTest: true,
|
|
baseUrl: "https://app.ekuaibao.com",
|
|
source: "manual",
|
|
credentials: { corpId: "corp_test", staffId: "staff_2", accessToken: "t2" },
|
|
},
|
|
{
|
|
id: "corp_demo",
|
|
name: "营销中心演示企业",
|
|
env: "demo",
|
|
isTest: true,
|
|
baseUrl: "https://app.ekuaibao.com",
|
|
source: "manual",
|
|
credentials: { corpId: "corp_demo", staffId: "staff_3", accessToken: "t3" },
|
|
},
|
|
];
|
|
|
|
function createMockRuntime(corps: CorpConfig[] = sampleCorps): CliRuntime {
|
|
const context = new CorpContext(corps, { stateful: true, defaultCorpId: "corp_prod" });
|
|
return {
|
|
corpContext: context,
|
|
selectedCorp: context.getCurrent()!,
|
|
jsonMode: false,
|
|
outputOptions: {},
|
|
};
|
|
}
|
|
|
|
describe("CLI - corps environment attributes & filtering", () => {
|
|
it("corps list displays environment column with emoji labels", async () => {
|
|
const runtime = createMockRuntime();
|
|
const res = await handleCorpsCommand(
|
|
{
|
|
area: "corps",
|
|
action: "list",
|
|
args: [],
|
|
options: {},
|
|
raw: ["corps", "list"],
|
|
},
|
|
runtime
|
|
);
|
|
|
|
expect(res.exitCode).toBe(0);
|
|
expect(res.stdout).toContain("环境");
|
|
expect(res.stdout).toContain("🏭 正式");
|
|
expect(res.stdout).toContain("🧪 测试");
|
|
expect(res.stdout).toContain("🎪 演示");
|
|
expect(res.stdout).toContain("共 3 家企业 (🏭 正式 1 家, 🧪 测试 1 家, 🎪 演示 1 家)");
|
|
});
|
|
|
|
it("corps list --test filters only test and demo enterprises", async () => {
|
|
const runtime = createMockRuntime();
|
|
const res = await handleCorpsCommand(
|
|
{
|
|
area: "corps",
|
|
action: "list",
|
|
args: [],
|
|
options: { test: true },
|
|
raw: ["corps", "list", "--test"],
|
|
},
|
|
runtime
|
|
);
|
|
|
|
expect(res.exitCode).toBe(0);
|
|
expect(res.stdout).toContain("HAB对公测试环境");
|
|
expect(res.stdout).toContain("营销中心演示企业");
|
|
expect(res.stdout).not.toContain("新转转集团");
|
|
expect(res.stdout).toContain("已筛选显示 2 家");
|
|
});
|
|
|
|
it("corps list --prod filters only production enterprises", async () => {
|
|
const runtime = createMockRuntime();
|
|
const res = await handleCorpsCommand(
|
|
{
|
|
area: "corps",
|
|
action: "list",
|
|
args: [],
|
|
options: { prod: true },
|
|
raw: ["corps", "list", "--prod"],
|
|
},
|
|
runtime
|
|
);
|
|
|
|
expect(res.exitCode).toBe(0);
|
|
expect(res.stdout).toContain("新转转集团");
|
|
expect(res.stdout).not.toContain("HAB对公测试环境");
|
|
expect(res.stdout).not.toContain("营销中心演示企业");
|
|
expect(res.stdout).toContain("已筛选显示 1 家");
|
|
});
|
|
|
|
it("corps list --env=demo filters precisely demo enterprises", async () => {
|
|
const runtime = createMockRuntime();
|
|
const res = await handleCorpsCommand(
|
|
{
|
|
area: "corps",
|
|
action: "list",
|
|
args: [],
|
|
options: { env: "demo" },
|
|
raw: ["corps", "list", "--env=demo"],
|
|
},
|
|
runtime
|
|
);
|
|
|
|
expect(res.exitCode).toBe(0);
|
|
expect(res.stdout).toContain("营销中心演示企业");
|
|
expect(res.stdout).not.toContain("新转转集团");
|
|
expect(res.stdout).not.toContain("HAB对公测试环境");
|
|
});
|
|
|
|
it("corps tag requires mutation confirmation unless confirmed or dry-run", async () => {
|
|
const runtime = createMockRuntime();
|
|
await expect(
|
|
handleCorpsCommand(
|
|
{
|
|
area: "corps",
|
|
action: "tag",
|
|
args: ["corp_prod"],
|
|
options: { test: true },
|
|
raw: ["corps", "tag", "corp_prod", "--test"],
|
|
},
|
|
runtime
|
|
)
|
|
).rejects.toThrow("拒绝执行设置企业环境属性");
|
|
});
|
|
|
|
it("corps tag previews change under --dry-run", async () => {
|
|
const runtime = createMockRuntime();
|
|
const res = await handleCorpsCommand(
|
|
{
|
|
area: "corps",
|
|
action: "tag",
|
|
args: ["corp_prod"],
|
|
options: { test: true, "dry-run": true },
|
|
raw: ["corps", "tag", "corp_prod", "--test", "--dry-run"],
|
|
},
|
|
runtime
|
|
);
|
|
|
|
expect(res.exitCode).toBe(0);
|
|
expect(res.stdout).toContain("[DRY-RUN]");
|
|
expect(res.stdout).toContain("设置企业环境属性");
|
|
expect(res.stdout).toContain("newEnv: test");
|
|
expect(res.stdout).toContain("将不再触发生产环境确认");
|
|
});
|
|
|
|
it("corps tag dry-run from production to demo includes the same downgrade warning", async () => {
|
|
const runtime = createMockRuntime();
|
|
const res = await handleCorpsCommand(
|
|
{
|
|
area: "corps",
|
|
action: "tag",
|
|
args: ["corp_prod"],
|
|
options: { demo: true, "dry-run": true },
|
|
raw: ["corps", "tag", "corp_prod", "--demo", "--dry-run"],
|
|
},
|
|
runtime
|
|
);
|
|
|
|
expect(res.exitCode).toBe(0);
|
|
expect(res.stdout).toContain("将不再触发生产环境确认");
|
|
expect(res.stdout).toContain("newEnv: demo");
|
|
});
|
|
|
|
it("corps current displays environment attribute label", async () => {
|
|
const runtime = createMockRuntime();
|
|
const res = await handleCorpsCommand(
|
|
{
|
|
area: "corps",
|
|
action: "current",
|
|
args: [],
|
|
options: {},
|
|
raw: ["corps", "current"],
|
|
},
|
|
runtime
|
|
);
|
|
|
|
expect(res.exitCode).toBe(0);
|
|
expect(res.stdout).toContain("环境属性");
|
|
expect(res.stdout).toContain("🏭 正式");
|
|
});
|
|
|
|
it("context command reports environment counts and current corp env tag", async () => {
|
|
const runtime = createMockRuntime();
|
|
const res = await handleContextCommand(
|
|
{
|
|
area: "context",
|
|
action: "",
|
|
args: [],
|
|
options: {},
|
|
raw: ["context"],
|
|
},
|
|
runtime
|
|
);
|
|
|
|
expect(res.exitCode).toBe(0);
|
|
expect(res.stdout).toContain("新转转集团 (corp_prod) [🏭 正式]");
|
|
expect(res.stdout).toContain("🏭 正式: 1 家, 🧪 测试: 1 家, 🎪 演示: 1 家");
|
|
});
|
|
});
|