mirror of
https://github.com/modelstudioai/cli.git
synced 2026-09-14 19:49:23 +08:00
86 lines
2.4 KiB
TypeScript
86 lines
2.4 KiB
TypeScript
import { expect, test } from "vite-plus/test";
|
|
import { defineCommand } from "bailian-cli-core";
|
|
import { createTranslator } from "../src/i18n.ts";
|
|
import { CommandRegistry } from "../src/registry.ts";
|
|
|
|
test("translator resolves colocated text while preserving plain strings", () => {
|
|
const translator = createTranslator("zh-CN");
|
|
|
|
expect(translator.language).toBe("zh-CN");
|
|
expect(translator.localize("Already localized")).toBe("Already localized");
|
|
expect(
|
|
translator.localize({
|
|
"en-US": "Show help",
|
|
"zh-CN": "显示帮助信息",
|
|
}),
|
|
).toBe("显示帮助信息");
|
|
|
|
expect(
|
|
createTranslator("en-US").localize({
|
|
"en-US": "Show help",
|
|
"zh-CN": "显示帮助信息",
|
|
}),
|
|
).toBe("Show help");
|
|
});
|
|
|
|
test("registry renders runtime help copy with the selected language", async () => {
|
|
const translator = createTranslator("zh-CN");
|
|
const command = defineCommand({
|
|
description: {
|
|
"en-US": "Test command",
|
|
"zh-CN": "测试命令",
|
|
},
|
|
notes: [
|
|
{
|
|
"en-US": "Test note",
|
|
"zh-CN": "测试说明",
|
|
},
|
|
],
|
|
exampleArgs: [
|
|
{
|
|
"en-US": '--message "Hello"',
|
|
"zh-CN": '--message "你好"',
|
|
},
|
|
{
|
|
"en-US": "# Stream the response",
|
|
"zh-CN": "# 流式输出响应",
|
|
},
|
|
],
|
|
auth: "none",
|
|
risk: {
|
|
level: "high",
|
|
message: {
|
|
"en-US": "This operation is permanent.",
|
|
"zh-CN": "该操作无法撤销。",
|
|
},
|
|
},
|
|
run: async () => {},
|
|
});
|
|
const registry = new CommandRegistry({ test: command }, "bl", translator);
|
|
let output = "";
|
|
const stream = {
|
|
isTTY: false,
|
|
write(chunk: string) {
|
|
output += chunk;
|
|
return true;
|
|
},
|
|
} as NodeJS.WriteStream;
|
|
|
|
registry.printHelp([], stream);
|
|
|
|
expect(output).toContain("用法: bl <resource> <command> [flags]");
|
|
expect(output).toContain("测试命令");
|
|
expect(output).toContain("全局选项:");
|
|
expect(output).toContain("显示帮助信息");
|
|
expect(output).toContain("获取帮助:");
|
|
|
|
output = "";
|
|
registry.printHelp(["test"], stream);
|
|
expect(output).toContain("风险等级: 高风险");
|
|
expect(output).toContain("风险说明: 该操作无法撤销。");
|
|
expect(output).toContain("测试说明");
|
|
expect(output).toContain('bl test --message "你好"');
|
|
expect(output).toContain(" # 流式输出响应");
|
|
expect(output).not.toContain("bl test # 流式输出响应");
|
|
});
|