Files
hose-use/src/cli/commands/config.test.ts
T
gitea 1cd8901f7a feat(cli): add corps search command and intuitive aliases
- Implement hose-use corps search <keyword> with case-insensitive fuzzy matching across id, name, corpId, staffId, staffName, and accountId
- Format terminal table output with matched cell brackets, hit labels, active corp markers, and friendly no-match fallback
- Support --json structured output conforming to CliResult specification
- Add intuitive aliases for frequently guessed commands: auth list -> auth accounts, corps find -> corps search, config show -> config paths
- Enhance CorpSummary and CorpContext with corpId, staffName, and getAllCorps
- Add comprehensive unit tests in corps.test.ts, auth.test.ts, and config.test.ts
2026-09-09 14:42:58 +08:00

88 lines
2.3 KiB
TypeScript

import { describe, it, expect } from "bun:test";
import { handleConfigCommand } from "./config.js";
import type { CliRuntime } from "../types.js";
describe("cli/commands/config > aliases and path mapping", () => {
const dummyRuntime: CliRuntime = {
corpContext: {
listCorps: () => [],
getCurrent: () => null,
switchCorp: () => false,
resolve: () => null,
} as any,
selectedCorp: null,
jsonMode: false,
};
it("maps config show to config paths diagnosis", async () => {
const res = await handleConfigCommand(
{
area: "config",
action: "show",
args: [],
options: {},
raw: ["config", "show"],
},
dummyRuntime
);
expect(res.exitCode).toBe(0);
expect(res.stdout).toContain("配置路径诊断 (Config Paths)");
expect(res.stdout).toContain("当前生效配置文件");
expect(res.stdout).toContain("运行模式 (Mode)");
});
it("supports config paths directly", async () => {
const res = await handleConfigCommand(
{
area: "config",
action: "paths",
args: [],
options: {},
raw: ["config", "paths"],
},
dummyRuntime
);
expect(res.exitCode).toBe(0);
expect(res.stdout).toContain("配置路径诊断 (Config Paths)");
});
it("supports config show --json structured output", async () => {
const jsonRuntime = { ...dummyRuntime, jsonMode: true };
const res = await handleConfigCommand(
{
area: "config",
action: "show",
args: [],
options: { json: true },
raw: ["config", "show", "--json"],
},
jsonRuntime
);
expect(res.exitCode).toBe(0);
const data = JSON.parse(res.stdout);
expect(data).toHaveProperty("configFile");
expect(data).toHaveProperty("writableDir");
expect(data).toHaveProperty("mode");
});
it("supports config get for inspecting global stateful configuration", async () => {
const res = await handleConfigCommand(
{
area: "config",
action: "get",
args: [],
options: {},
raw: ["config", "get"],
},
dummyRuntime
);
expect(res.exitCode).toBe(0);
expect(res.stdout).toContain("全局运行配置");
expect(res.stdout).toContain("运行模式 (Mode)");
});
});