fix: build 命令在 plan 未完成时给出友好提示而非未预期错误
This commit is contained in:
@@ -2,6 +2,7 @@ import { existsSync } from "node:fs";
|
|||||||
import { readFile } from "node:fs/promises";
|
import { readFile } from "node:fs/promises";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import type { RuneConfig } from "../types.ts";
|
import type { RuneConfig } from "../types.ts";
|
||||||
|
import { CommandError } from "../cli/errors.ts";
|
||||||
import { getChangeDir } from "./config.ts";
|
import { getChangeDir } from "./config.ts";
|
||||||
import { parseTasks } from "./task-parser.ts";
|
import { parseTasks } from "./task-parser.ts";
|
||||||
|
|
||||||
@@ -69,7 +70,11 @@ export async function assembleBuildPrompt(
|
|||||||
changeName: string,
|
changeName: string,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const build = config.stages.build;
|
const build = config.stages.build;
|
||||||
if (!build) throw new Error("build 阶段未配置");
|
if (!build) {
|
||||||
|
throw new CommandError("构建阶段未配置", {
|
||||||
|
hint: "请在 .rune/config.yaml 中配置 stages.build",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const changeDir = getChangeDir(projectRoot, changeName);
|
const changeDir = getChangeDir(projectRoot, changeName);
|
||||||
const taskPath = join(changeDir, "task.md");
|
const taskPath = join(changeDir, "task.md");
|
||||||
@@ -78,7 +83,9 @@ export async function assembleBuildPrompt(
|
|||||||
try {
|
try {
|
||||||
taskContent = await readFile(taskPath, "utf-8");
|
taskContent = await readFile(taskPath, "utf-8");
|
||||||
} catch {
|
} catch {
|
||||||
throw new Error(`task.md not found in ${changeDir}`);
|
throw new CommandError(`变更 "${changeName}" 尚未完成规划,task.md 不存在`, {
|
||||||
|
hint: `请先完成规划阶段:rune plan ${changeName} 生成所有规划文档`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const tasks = parseTasks(taskContent);
|
const tasks = parseTasks(taskContent);
|
||||||
|
|||||||
@@ -184,10 +184,15 @@ describe("assembleBuildPrompt", () => {
|
|||||||
expect(prompt).toContain("归档");
|
expect(prompt).toContain("归档");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("task.md 不存在时抛出错误", async () => {
|
it("task.md 不存在时抛出 CommandError 并附带提示", async () => {
|
||||||
await expect(
|
try {
|
||||||
assembleBuildPrompt(defaultConfig, TMP_DIR, "nonexistent"),
|
await assembleBuildPrompt(defaultConfig, TMP_DIR, "nonexistent");
|
||||||
).rejects.toThrow("task.md not found");
|
expect.unreachable();
|
||||||
|
} catch (e: any) {
|
||||||
|
expect(e.message).toContain("尚未完成规划");
|
||||||
|
expect(e.message).toContain("nonexistent");
|
||||||
|
expect(e.hint).toContain("rune plan");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user