test: cover invalid talk config inputs

This commit is contained in:
Peter Steinberger
2026-03-08 14:53:03 +00:00
parent b4c8950417
commit e8ad80afc7
2 changed files with 68 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { clearConfigCache, loadConfig } from "./config.js";
import { withTempHomeConfig } from "./test-helpers.js";
describe("talk config validation fail-closed behavior", () => {
beforeEach(() => {
clearConfigCache();
vi.restoreAllMocks();
});
it.each([
["boolean", true],
["string", "1500"],
["float", 1500.5],
])("rejects %s talk.silenceTimeoutMs during config load", async (_label, value) => {
await withTempHomeConfig(
{
agents: { list: [{ id: "main" }] },
talk: {
silenceTimeoutMs: value,
},
},
async () => {
const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => {});
let thrown: unknown;
try {
loadConfig();
} catch (error) {
thrown = error;
}
expect(thrown).toBeInstanceOf(Error);
expect((thrown as { code?: string } | undefined)?.code).toBe("INVALID_CONFIG");
expect((thrown as Error).message).toMatch(/silenceTimeoutMs|talk/i);
expect(consoleSpy).toHaveBeenCalled();
},
);
});
});

View File

@@ -0,0 +1,28 @@
import { describe, expect, it } from "vitest";
import { OpenClawSchema } from "./zod-schema.js";
describe("OpenClawSchema talk validation", () => {
it("accepts a positive integer talk.silenceTimeoutMs", () => {
expect(() =>
OpenClawSchema.parse({
talk: {
silenceTimeoutMs: 1500,
},
}),
).not.toThrow();
});
it.each([
["boolean", true],
["string", "1500"],
["float", 1500.5],
])("rejects %s talk.silenceTimeoutMs", (_label, value) => {
expect(() =>
OpenClawSchema.parse({
talk: {
silenceTimeoutMs: value,
},
}),
).toThrow(/silenceTimeoutMs|number|integer/i);
});
});