refactor: loadConfig 统一走 mergeConfig 路径
This commit is contained in:
@@ -25,12 +25,9 @@ export async function loadConfig(projectRoot: string): Promise<RuneConfig> {
|
|||||||
try {
|
try {
|
||||||
const content = await readFile(configPath, "utf-8");
|
const content = await readFile(configPath, "utf-8");
|
||||||
const userConfig = parseYaml(content) as Partial<RuneConfig> | null;
|
const userConfig = parseYaml(content) as Partial<RuneConfig> | null;
|
||||||
if (!userConfig?.stages) {
|
return mergeConfig(userConfig ?? {});
|
||||||
return structuredClone(defaultConfig);
|
|
||||||
}
|
|
||||||
return mergeConfig(userConfig);
|
|
||||||
} catch {
|
} catch {
|
||||||
return structuredClone(defaultConfig);
|
return mergeConfig({});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,6 +75,17 @@ describe("loadConfig", () => {
|
|||||||
expect(config.stages.plan!.documents[0].name).toBe("spec");
|
expect(config.stages.plan!.documents[0].name).toBe("spec");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("空配置 stages: {} 时返回完整默认配置", async () => {
|
||||||
|
const runeDir = join(TMP_DIR, ".rune");
|
||||||
|
await mkdir(runeDir, { recursive: true });
|
||||||
|
await writeFile(join(runeDir, "config.yaml"), "stages: {}");
|
||||||
|
const config = await loadConfig(TMP_DIR);
|
||||||
|
expect(config.stages.discuss).toBeDefined();
|
||||||
|
expect(config.stages.plan).toBeDefined();
|
||||||
|
expect(config.stages.build).toBeDefined();
|
||||||
|
expect(config.stages.archive).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
it("YAML 解析错误时返回默认配置", async () => {
|
it("YAML 解析错误时返回默认配置", async () => {
|
||||||
const runeDir = join(TMP_DIR, ".rune");
|
const runeDir = join(TMP_DIR, ".rune");
|
||||||
await mkdir(runeDir, { recursive: true });
|
await mkdir(runeDir, { recursive: true });
|
||||||
|
|||||||
Reference in New Issue
Block a user