mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
test: cover invalid talk config inputs
This commit is contained in:
40
src/config/config.talk-validation.test.ts
Normal file
40
src/config/config.talk-validation.test.ts
Normal 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();
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
28
src/config/zod-schema.talk.test.ts
Normal file
28
src/config/zod-schema.talk.test.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user