Files
hose-use/src/cli/mutation-boundaries.test.ts
T

46 lines
2.3 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import { handleAuthCommand } from "./commands/auth.js";
import { handleConfigCommand } from "./commands/config.js";
import { handleCorpsCommand } from "./commands/corps.js";
import { handleMessageCommand } from "./commands/message.js";
import { handleSkillCommand } from "./commands/skill.js";
import type { CliRuntime } from "./types.js";
const runtime: CliRuntime = {
corpContext: {
listCorps: () => [],
getCurrent: () => null,
switchCorp: () => true,
resolve: () => null,
} as any,
selectedCorp: {
id: "corp-test",
name: "测试企业",
corpId: "corp-test",
credentials: { accessToken: "token", corpId: "corp-test", staffId: "staff-test" },
} as any,
jsonMode: true,
};
describe("CLI mutation boundaries", () => {
test("auth login dry-run does not prompt or call the login API", async () => {
const result = await handleAuthCommand({ area: "auth", action: "login", args: [], options: { "dry-run": true }, raw: ["auth", "login", "--dry-run"] }, runtime);
expect(result.exitCode).toBe(0);
expect(JSON.parse(result.stdout).dryRun).toBe(true);
});
test("corps/config state changes share the dry-run protocol", async () => {
const corp = await handleCorpsCommand({ area: "corps", action: "switch", args: ["corp-next"], options: { "dry-run": true }, raw: ["corps", "switch", "corp-next", "--dry-run"] }, runtime);
const config = await handleConfigCommand({ area: "config", action: "mode", args: ["stateless"], options: { "dry-run": true }, raw: ["config", "mode", "stateless", "--dry-run"] }, runtime);
expect(JSON.parse(corp.stdout).operation).toContain("工作企业");
expect(JSON.parse(config.stdout).changes.stateful).toBe(false);
});
test("skill installation and message read never write during dry-run", async () => {
const skill = await handleSkillCommand({ area: "skill", action: "install", args: [], options: { "dry-run": true }, raw: ["skill", "install", "--dry-run"] }, runtime);
const message = await handleMessageCommand({ area: "message", action: "read", args: ["message-1"], options: { "dry-run": true }, raw: ["message", "read", "message-1", "--dry-run"] }, runtime);
expect(JSON.parse(skill.stdout).dryRun).toBe(true);
expect(JSON.parse(message.stdout).changes.read).toBe(true);
});
});