mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 19:14:58 +00:00
fix: block invalid config startup
Co-authored-by: Muhammed Mukhthar CM <mukhtharcm@gmail.com>
This commit is contained in:
36
src/config/config.backup-rotation.test.ts
Normal file
36
src/config/config.backup-rotation.test.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import fs from "node:fs/promises";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { withTempHome } from "./test-helpers.js";
|
||||
import type { ClawdbotConfig } from "./types.js";
|
||||
|
||||
describe("config backup rotation", () => {
|
||||
it("keeps a 5-deep backup ring for config writes", async () => {
|
||||
await withTempHome(async () => {
|
||||
const { resolveConfigPath, writeConfigFile } = await import("./config.js");
|
||||
const configPath = resolveConfigPath();
|
||||
const buildConfig = (version: number): ClawdbotConfig =>
|
||||
({
|
||||
identity: { name: `v${version}` },
|
||||
}) as ClawdbotConfig;
|
||||
|
||||
for (let version = 0; version <= 6; version += 1) {
|
||||
await writeConfigFile(buildConfig(version));
|
||||
}
|
||||
|
||||
const readName = async (suffix = "") => {
|
||||
const raw = await fs.readFile(`${configPath}${suffix}`, "utf-8");
|
||||
return (JSON.parse(raw) as { identity?: { name?: string } }).identity?.name ?? null;
|
||||
};
|
||||
|
||||
await expect(readName()).resolves.toBe("v6");
|
||||
await expect(readName(".bak")).resolves.toBe("v5");
|
||||
await expect(readName(".bak.1")).resolves.toBe("v4");
|
||||
await expect(readName(".bak.2")).resolves.toBe("v3");
|
||||
await expect(readName(".bak.3")).resolves.toBe("v2");
|
||||
await expect(readName(".bak.4")).resolves.toBe("v1");
|
||||
await expect(fs.stat(`${configPath}.bak.5`)).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user