feat: 新增 validateConfig 校验 depend 引用、自依赖和循环依赖

This commit is contained in:
2026-06-09 10:40:07 +08:00
parent 566a9d7255
commit 0d2b117680
2 changed files with 136 additions and 3 deletions

View File

@@ -1,7 +1,9 @@
import { describe, it, expect, beforeEach, afterEach } from "bun:test";
import { mkdir, writeFile, rm } from "node:fs/promises";
import { join } from "node:path";
import { loadConfig, findProjectRoot, getRuneDir } from "../../src/core/config.ts";
import { loadConfig, findProjectRoot, getRuneDir, validateConfig } from "../../src/core/config.ts";
import { ConfigError } from "../../src/cli/errors.ts";
import type { RuneConfig } from "../../src/types.ts";
const TMP_DIR = join(import.meta.dir, "__tmp_config_test__");
@@ -103,3 +105,77 @@ describe("getRuneDir", () => {
expect(getRuneDir("/project")).toBe(join("/project", ".rune"));
});
});
describe("validateConfig", () => {
it("正常配置不抛错", () => {
const config: RuneConfig = {
stages: {
plan: {
documents: [
{ name: "design", prompt: "生成设计" },
{ name: "task", prompt: "生成任务", depend: ["design"] },
],
},
},
};
expect(() => validateConfig(config)).not.toThrow();
});
it("depend 引用不存在的文档时报错", () => {
const config: RuneConfig = {
stages: {
plan: {
documents: [
{ name: "task", prompt: "生成任务", depend: ["nonexistent"] },
],
},
},
};
expect(() => validateConfig(config)).toThrow(ConfigError);
});
it("自依赖报错", () => {
const config: RuneConfig = {
stages: {
plan: {
documents: [
{ name: "design", prompt: "生成设计", depend: ["design"] },
],
},
},
};
expect(() => validateConfig(config)).toThrow(ConfigError);
});
it("循环依赖报错", () => {
const config: RuneConfig = {
stages: {
plan: {
documents: [
{ name: "a", prompt: "a", depend: ["b"] },
{ name: "b", prompt: "b", depend: ["a"] },
],
},
},
};
expect(() => validateConfig(config)).toThrow(ConfigError);
});
it("无 plan 阶段时不报错", () => {
const config: RuneConfig = { stages: {} };
expect(() => validateConfig(config)).not.toThrow();
});
it("depend 为空数组时不报错", () => {
const config: RuneConfig = {
stages: {
plan: {
documents: [
{ name: "design", prompt: "生成设计", depend: [] },
],
},
},
};
expect(() => validateConfig(config)).not.toThrow();
});
});