69 lines
2.1 KiB
TypeScript
69 lines
2.1 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach } from "bun:test";
|
|
import { existsSync } from "node:fs";
|
|
import { mkdir, rm, readFile, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { runInit } from "../../src/commands/init.ts";
|
|
|
|
const TMP_DIR = join(import.meta.dir, "__tmp_init_test__");
|
|
|
|
beforeEach(async () => {
|
|
await mkdir(TMP_DIR, { recursive: true });
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await rm(TMP_DIR, { recursive: true, force: true });
|
|
});
|
|
|
|
describe("runInit", () => {
|
|
it("创建 .rune 目录和默认 config.yaml", async () => {
|
|
await runInit(TMP_DIR, ["opencode"]);
|
|
|
|
expect(existsSync(join(TMP_DIR, ".rune"))).toBe(true);
|
|
expect(existsSync(join(TMP_DIR, ".rune", "config.yaml"))).toBe(true);
|
|
|
|
const content = await readFile(
|
|
join(TMP_DIR, ".rune", "config.yaml"),
|
|
"utf-8",
|
|
);
|
|
expect(content).toContain("discuss");
|
|
expect(content).toContain("plan");
|
|
expect(content).toContain("build");
|
|
expect(content).toContain("archive");
|
|
});
|
|
|
|
it("创建 .rune/changes 和 .rune/archive 目录", async () => {
|
|
await runInit(TMP_DIR, ["opencode"]);
|
|
|
|
expect(existsSync(join(TMP_DIR, ".rune", "changes"))).toBe(true);
|
|
expect(existsSync(join(TMP_DIR, ".rune", "archive"))).toBe(true);
|
|
});
|
|
|
|
it("注入 OpenCode command 和 skill", async () => {
|
|
await runInit(TMP_DIR, ["opencode"]);
|
|
|
|
expect(existsSync(join(TMP_DIR, ".opencode", "commands", "discuss.md"))).toBe(true);
|
|
expect(existsSync(join(TMP_DIR, ".opencode", "skills", "rune-discuss.md"))).toBe(true);
|
|
});
|
|
|
|
it("重复 init 不覆盖 config.yaml", async () => {
|
|
await runInit(TMP_DIR, ["opencode"]);
|
|
await writeFile(
|
|
join(TMP_DIR, ".rune", "config.yaml"),
|
|
"自定义内容",
|
|
);
|
|
|
|
await runInit(TMP_DIR, ["opencode"]);
|
|
const content = await readFile(
|
|
join(TMP_DIR, ".rune", "config.yaml"),
|
|
"utf-8",
|
|
);
|
|
expect(content).toBe("自定义内容");
|
|
});
|
|
|
|
it("不支持的工具名抛出错误", async () => {
|
|
await expect(runInit(TMP_DIR, ["unknown-tool"])).rejects.toThrow(
|
|
"不支持的工具",
|
|
);
|
|
});
|
|
});
|