Skip to content

Commit e8ad80a

Browse files
committed
test: cover invalid talk config inputs
1 parent b4c8950 commit e8ad80a

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { beforeEach, describe, expect, it, vi } from "vitest";
2+
import { clearConfigCache, loadConfig } from "./config.js";
3+
import { withTempHomeConfig } from "./test-helpers.js";
4+
5+
describe("talk config validation fail-closed behavior", () => {
6+
beforeEach(() => {
7+
clearConfigCache();
8+
vi.restoreAllMocks();
9+
});
10+
11+
it.each([
12+
["boolean", true],
13+
["string", "1500"],
14+
["float", 1500.5],
15+
])("rejects %s talk.silenceTimeoutMs during config load", async (_label, value) => {
16+
await withTempHomeConfig(
17+
{
18+
agents: { list: [{ id: "main" }] },
19+
talk: {
20+
silenceTimeoutMs: value,
21+
},
22+
},
23+
async () => {
24+
const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => {});
25+
26+
let thrown: unknown;
27+
try {
28+
loadConfig();
29+
} catch (error) {
30+
thrown = error;
31+
}
32+
33+
expect(thrown).toBeInstanceOf(Error);
34+
expect((thrown as { code?: string } | undefined)?.code).toBe("INVALID_CONFIG");
35+
expect((thrown as Error).message).toMatch(/silenceTimeoutMs|talk/i);
36+
expect(consoleSpy).toHaveBeenCalled();
37+
},
38+
);
39+
});
40+
});

src/config/zod-schema.talk.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { describe, expect, it } from "vitest";
2+
import { OpenClawSchema } from "./zod-schema.js";
3+
4+
describe("OpenClawSchema talk validation", () => {
5+
it("accepts a positive integer talk.silenceTimeoutMs", () => {
6+
expect(() =>
7+
OpenClawSchema.parse({
8+
talk: {
9+
silenceTimeoutMs: 1500,
10+
},
11+
}),
12+
).not.toThrow();
13+
});
14+
15+
it.each([
16+
["boolean", true],
17+
["string", "1500"],
18+
["float", 1500.5],
19+
])("rejects %s talk.silenceTimeoutMs", (_label, value) => {
20+
expect(() =>
21+
OpenClawSchema.parse({
22+
talk: {
23+
silenceTimeoutMs: value,
24+
},
25+
}),
26+
).toThrow(/silenceTimeoutMs|number|integer/i);
27+
});
28+
});

0 commit comments

Comments
 (0)