fix: enforce strict config validation
This commit is contained in:
@@ -3,21 +3,18 @@ import path from "node:path";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { withTempHome } from "./test-helpers.js";
|
||||
|
||||
describe("config preservation on validation failure", () => {
|
||||
it("preserves unknown fields via passthrough", async () => {
|
||||
describe("config strict validation", () => {
|
||||
it("rejects unknown fields", async () => {
|
||||
vi.resetModules();
|
||||
const { validateConfigObject } = await import("./config.js");
|
||||
const res = validateConfigObject({
|
||||
agents: { list: [{ id: "pi" }] },
|
||||
customUnknownField: { nested: "value" },
|
||||
});
|
||||
expect(res.ok).toBe(true);
|
||||
expect((res as { config: Record<string, unknown> }).config.customUnknownField).toEqual({
|
||||
nested: "value",
|
||||
});
|
||||
expect(res.ok).toBe(false);
|
||||
});
|
||||
|
||||
it("preserves config data when validation fails", async () => {
|
||||
it("flags legacy config entries without auto-migrating", async () => {
|
||||
await withTempHome(async (home) => {
|
||||
const configDir = path.join(home, ".clawdbot");
|
||||
await fs.mkdir(configDir, { recursive: true });
|
||||
@@ -26,7 +23,6 @@ describe("config preservation on validation failure", () => {
|
||||
JSON.stringify({
|
||||
agents: { list: [{ id: "pi" }] },
|
||||
routing: { allowFrom: ["+15555550123"] },
|
||||
customData: { preserved: true },
|
||||
}),
|
||||
"utf-8",
|
||||
);
|
||||
@@ -35,12 +31,8 @@ describe("config preservation on validation failure", () => {
|
||||
const { readConfigFileSnapshot } = await import("./config.js");
|
||||
const snap = await readConfigFileSnapshot();
|
||||
|
||||
expect(snap.valid).toBe(true);
|
||||
expect(snap.legacyIssues).toHaveLength(0);
|
||||
expect((snap.config as Record<string, unknown>).customData).toEqual({
|
||||
preserved: true,
|
||||
});
|
||||
expect(snap.config.channels?.whatsapp?.allowFrom).toEqual(["+15555550123"]);
|
||||
expect(snap.valid).toBe(false);
|
||||
expect(snap.legacyIssues).not.toHaveLength(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user