




























@@ -3,6 +3,24 @@ import { validateConfigObject } from "./validation.js";
33import { AgentDefaultsSchema } from "./zod-schema.agent-defaults.js";
44import { AgentEntrySchema } from "./zod-schema.agent-runtime.js";
556+type SchemaParseResult = {
7+success: boolean;
8+error?: { issues: Array<{ path: Array<string | number | symbol> }> };
9+};
10+11+function expectSchemaFailurePath(result: SchemaParseResult, expectedPathPrefix: string): void {
12+expect(result.success).toBe(false);
13+if (result.success || !result.error) {
14+throw new Error(`Expected schema validation to fail at ${expectedPathPrefix}.`);
15+}
16+const issuePaths = result.error.issues.map((issue) => issue.path.join("."));
17+expect(
18+issuePaths.some(
19+(path) => path === expectedPathPrefix || path.startsWith(`${expectedPathPrefix}.`),
20+),
21+).toBe(true);
22+}
23+624describe("agent defaults schema", () => {
725it("accepts subagent archiveAfterMinutes=0 to disable archiving", () => {
826expect(
@@ -37,14 +55,15 @@ describe("agent defaults schema", () => {
3755primary: "openrouter/openai/gpt-5.4-image-2",
3856timeoutMs: 180_000,
3957});
40-expect(() =>
41-AgentDefaultsSchema.parse({
58+expectSchemaFailurePath(
59+AgentDefaultsSchema.safeParse({
4260imageGenerationModel: {
4361primary: "openrouter/openai/gpt-5.4-image-2",
4462timeoutMs: 0,
4563},
4664}),
47-).toThrow();
65+"imageGenerationModel.timeoutMs",
66+);
4867});
49685069it("accepts mediaGenerationAutoProviderFallback", () => {
@@ -80,7 +99,10 @@ describe("agent defaults schema", () => {
8099});
8110082101it("rejects invalid contextInjection values", () => {
83-expect(() => AgentDefaultsSchema.parse({ contextInjection: "unknown" })).toThrow();
102+expectSchemaFailurePath(
103+AgentDefaultsSchema.safeParse({ contextInjection: "unknown" }),
104+"contextInjection",
105+);
84106});
8510786108it("accepts supported optional bootstrap filenames", () => {
@@ -96,10 +118,14 @@ describe("agent defaults schema", () => {
96118});
9711998120it("rejects unsupported optional bootstrap filenames", () => {
99-expect(() =>
100-AgentDefaultsSchema.parse({ skipOptionalBootstrapFiles: ["AGENTS.md"] }),
101-).toThrow();
102-expect(() => AgentDefaultsSchema.parse({ skipOptionalBootstrapFiles: ["SOUL.MD"] })).toThrow();
121+expectSchemaFailurePath(
122+AgentDefaultsSchema.safeParse({ skipOptionalBootstrapFiles: ["AGENTS.md"] }),
123+"skipOptionalBootstrapFiles",
124+);
125+expectSchemaFailurePath(
126+AgentDefaultsSchema.safeParse({ skipOptionalBootstrapFiles: ["SOUL.MD"] }),
127+"skipOptionalBootstrapFiles",
128+);
103129});
104130105131it("accepts embeddedPi.executionContract", () => {
@@ -196,8 +222,14 @@ describe("agent defaults schema", () => {
196222});
197223198224it("rejects zero heartbeat timeoutSeconds", () => {
199-expect(() => AgentDefaultsSchema.parse({ heartbeat: { timeoutSeconds: 0 } })).toThrow();
200-expect(() => AgentEntrySchema.parse({ id: "ops", heartbeat: { timeoutSeconds: 0 } })).toThrow();
225+expectSchemaFailurePath(
226+AgentDefaultsSchema.safeParse({ heartbeat: { timeoutSeconds: 0 } }),
227+"heartbeat.timeoutSeconds",
228+);
229+expectSchemaFailurePath(
230+AgentEntrySchema.safeParse({ id: "ops", heartbeat: { timeoutSeconds: 0 } }),
231+"heartbeat.timeoutSeconds",
232+);
201233});
202234203235it("preserves per-agent contextTokens through config validation", () => {
@@ -223,9 +255,18 @@ describe("agent defaults schema", () => {
223255});
224256225257it("rejects non-positive contextTokens on agent entries and defaults", () => {
226-expect(() => AgentEntrySchema.parse({ id: "ops", contextTokens: 0 })).toThrow();
227-expect(() => AgentEntrySchema.parse({ id: "ops", contextTokens: -1 })).toThrow();
228-expect(() => AgentEntrySchema.parse({ id: "ops", contextTokens: 1.5 })).toThrow();
229-expect(() => AgentDefaultsSchema.parse({ contextTokens: 0 })).toThrow();
258+expectSchemaFailurePath(
259+AgentEntrySchema.safeParse({ id: "ops", contextTokens: 0 }),
260+"contextTokens",
261+);
262+expectSchemaFailurePath(
263+AgentEntrySchema.safeParse({ id: "ops", contextTokens: -1 }),
264+"contextTokens",
265+);
266+expectSchemaFailurePath(
267+AgentEntrySchema.safeParse({ id: "ops", contextTokens: 1.5 }),
268+"contextTokens",
269+);
270+expectSchemaFailurePath(AgentDefaultsSchema.safeParse({ contextTokens: 0 }), "contextTokens");
230271});
231272});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。