refactor: 修复代码审查发现的问题

- Bug修复: formatChangeStatus 使用实际配置而非 defaultConfig
- 统一 assembler 中所有错误抛出为 CommandError
- 提取 writeIfChanged 到 adapters/utils.ts,消除 claude-code/opencode 重复代码
- 导出 SUPPORTED_TOOLS,cli.ts update 命令复用同一工具注册表
- 提取 mapError/mapCacError 函数,支持单元测试
- 补充 claude-code 适配器测试(10 个用例)
- 补充 validateChangeName、formatChangeStatus、suggestNextStep、mapError 单元测试(18 个用例)
- 共新增 3 个测试文件,测试从 96 增至 133,全部通过
This commit is contained in:
2026-06-09 12:57:28 +08:00
parent 7b258f4d90
commit bfa0f29dd5
10 changed files with 459 additions and 60 deletions

View File

@@ -1,7 +1,8 @@
import { existsSync } from "node:fs";
import { mkdir, writeFile, readFile } from "node:fs/promises";
import { mkdir, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { STAGES } from "../types.ts";
import { writeIfChanged } from "./utils.ts";
const COMMANDS_DIR = ".claude/commands";
@@ -50,21 +51,9 @@ export async function updateClaudeCode(projectRoot: string): Promise<void> {
? "\n如果用户没有指定变更名称请向用户确认。"
: "";
const newContent = `执行以下命令,将输出作为当前阶段的工作指引:\n\`\`\`bash\n${cmd}\n\`\`\`${nameHint}\n`;
await writeIfChangedClaude(commandPath, newContent);
await writeIfChanged(commandPath, newContent);
}
const statusPath = join(projectRoot, COMMANDS_DIR, "rune-status.md");
await writeIfChangedClaude(statusPath, `执行以下命令查看变更状态:\n\`\`\`bash\nrune status\n\`\`\`\n`);
}
async function writeIfChangedClaude(filePath: string, newContent: string): Promise<void> {
try {
const existing = await readFile(filePath, "utf-8");
if (existing === newContent) {
return;
}
} catch {
// 文件不存在,创建
}
await writeFile(filePath, newContent);
await writeIfChanged(statusPath, `执行以下命令查看变更状态:\n\`\`\`bash\nrune status\n\`\`\`\n`);
}