Skip to content

Commit 4aca1ba

Browse files
maxreithzhanxingxin1998
authored andcommitted
fix(config): allow historyLimit: 0 in GroupChatSchema
GroupChatSchema used .positive() which rejects 0, while all other historyLimit schemas use .min(0). This caused a silent config reload failure when setting messages.groupChat.historyLimit to 0. Change .positive() to .min(0) and add test coverage. Fixes #65305
1 parent b388475 commit 4aca1ba

3 files changed

Lines changed: 64 additions & 1 deletion

File tree

‎src/config/zod-schema.core.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { describe, expect, it } from "vitest";
2+
import { GroupChatSchema } from "./zod-schema.core.js";
3+
4+
describe("GroupChatSchema", () => {
5+
it("accepts historyLimit: 0", () => {
6+
const result = GroupChatSchema.unwrap().safeParse({ historyLimit: 0 });
7+
expect(result.success).toBe(true);
8+
});
9+
10+
it("accepts a positive historyLimit", () => {
11+
const result = GroupChatSchema.unwrap().safeParse({ historyLimit: 50 });
12+
expect(result.success).toBe(true);
13+
});
14+
15+
it("rejects a negative historyLimit", () => {
16+
const result = GroupChatSchema.unwrap().safeParse({ historyLimit: -1 });
17+
expect(result.success).toBe(false);
18+
});
19+
});

‎src/config/zod-schema.core.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ export const MentionPatternsPolicySchema = z
586586
export const GroupChatSchema = z
587587
.object({
588588
mentionPatterns: z.array(z.string()).optional(),
589-
historyLimit: z.number().int().positive().optional(),
589+
historyLimit: z.number().int().min(0).optional(),
590590
unmentionedInbound: AmbientGroupInboundSchema.optional(),
591591
visibleReplies: VisibleRepliesSchema.optional(),
592592
})

‎src/gateway/server.config-patch.test.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,50 @@ describe("gateway config methods", () => {
448448
expect(after.payload?.hash).toBe(current.payload?.hash);
449449
});
450450

451+
it("accepts messages.groupChat.historyLimit: 0 through config.patch", async () => {
452+
const { createConfigIO, resetConfigRuntimeState } = await import("../config/config.js");
453+
const configPath = createConfigIO().configPath;
454+
let previousConfig: string | null = null;
455+
try {
456+
try {
457+
previousConfig = await fs.readFile(configPath, "utf-8");
458+
} catch (error) {
459+
if ((error as { code?: string }).code !== "ENOENT") {
460+
throw error;
461+
}
462+
}
463+
await fs.mkdir(path.dirname(configPath), { recursive: true });
464+
await fs.writeFile(
465+
configPath,
466+
`${JSON.stringify({ messages: { groupChat: { historyLimit: 1 } } }, null, 2)}\n`,
467+
"utf-8",
468+
);
469+
resetConfigRuntimeState();
470+
471+
const current = await rpcReq<{ hash?: string }>(requireWs(), "config.get", {});
472+
expect(current.ok).toBe(true);
473+
expect(typeof current.payload?.hash).toBe("string");
474+
475+
const res = await rpcReq<{
476+
config?: { messages?: { groupChat?: { historyLimit?: number } } };
477+
}>(requireWs(), "config.patch", {
478+
raw: JSON.stringify({ messages: { groupChat: { historyLimit: 0 } } }),
479+
baseHash: current.payload?.hash,
480+
});
481+
482+
expect(res.error).toBeUndefined();
483+
expect(res.ok).toBe(true);
484+
expect(res.payload?.config?.messages?.groupChat?.historyLimit).toBe(0);
485+
} finally {
486+
if (previousConfig === null) {
487+
await fs.rm(configPath, { force: true });
488+
} else {
489+
await fs.writeFile(configPath, previousConfig, "utf-8");
490+
}
491+
resetConfigRuntimeState();
492+
}
493+
});
494+
451495
it("rejects config.patch when raw is null", async () => {
452496
const res = await rpcReq<{ ok?: boolean }>(requireWs(), "config.patch", {
453497
raw: "null",

0 commit comments

Comments
 (0)