openclaw/src/config/config.preservation-on-validation-failure.test.ts

39 lines
1.2 KiB
TypeScript
Raw Normal View History

2026-01-14 01:08:15 +00:00
import fs from "node:fs/promises";
import path from "node:path";
import { describe, expect, it, vi } from "vitest";
import { withTempHome } from "./test-helpers.js";
2026-01-19 03:38:51 +00:00
describe("config strict validation", () => {
it("rejects unknown fields", async () => {
2026-01-14 01:08:15 +00:00
vi.resetModules();
const { validateConfigObject } = await import("./config.js");
const res = validateConfigObject({
agents: { list: [{ id: "pi" }] },
customUnknownField: { nested: "value" },
});
2026-01-19 03:38:51 +00:00
expect(res.ok).toBe(false);
2026-01-14 01:08:15 +00:00
});
2026-01-19 03:38:51 +00:00
it("flags legacy config entries without auto-migrating", async () => {
2026-01-14 01:08:15 +00:00
await withTempHome(async (home) => {
const configDir = path.join(home, ".clawdbot");
await fs.mkdir(configDir, { recursive: true });
await fs.writeFile(
path.join(configDir, "clawdbot.json"),
JSON.stringify({
agents: { list: [{ id: "pi" }] },
routing: { allowFrom: ["+15555550123"] },
}),
"utf-8",
);
vi.resetModules();
const { readConfigFileSnapshot } = await import("./config.js");
const snap = await readConfigFileSnapshot();
2026-01-19 03:38:51 +00:00
expect(snap.valid).toBe(false);
expect(snap.legacyIssues).not.toHaveLength(0);
2026-01-14 01:08:15 +00:00
});
});
});