Skip to content

Commit 40c2d27

Browse files
authored
fix(config): allow historyLimit: 0 in GroupChatSchema (#65359)
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 fd2e326 commit 40c2d27

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
@@ -594,7 +594,7 @@ export const MentionPatternsPolicySchema = z
594594
export const GroupChatSchema = z
595595
.object({
596596
mentionPatterns: z.array(z.string()).optional(),
597-
historyLimit: z.number().int().positive().optional(),
597+
historyLimit: z.number().int().min(0).optional(),
598598
unmentionedInbound: AmbientGroupInboundSchema.optional(),
599599
visibleReplies: VisibleRepliesSchema.optional(),
600600
})

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

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

698+
it("accepts messages.groupChat.historyLimit: 0 through config.patch", async () => {
699+
const { createConfigIO, resetConfigRuntimeState } = await import("../config/config.js");
700+
const configPath = createConfigIO().configPath;
701+
let previousConfig: string | null = null;
702+
try {
703+
try {
704+
previousConfig = await fs.readFile(configPath, "utf-8");
705+
} catch (error) {
706+
if ((error as { code?: string }).code !== "ENOENT") {
707+
throw error;
708+
}
709+
}
710+
await fs.mkdir(path.dirname(configPath), { recursive: true });
711+
await fs.writeFile(
712+
configPath,
713+
`${JSON.stringify({ messages: { groupChat: { historyLimit: 1 } } }, null, 2)}\n`,
714+
"utf-8",
715+
);
716+
resetConfigRuntimeState();
717+
718+
const current = await rpcReq<{ hash?: string }>(requireWs(), "config.get", {});
719+
expect(current.ok).toBe(true);
720+
expect(typeof current.payload?.hash).toBe("string");
721+
722+
const res = await rpcReq<{
723+
config?: { messages?: { groupChat?: { historyLimit?: number } } };
724+
}>(requireWs(), "config.patch", {
725+
raw: JSON.stringify({ messages: { groupChat: { historyLimit: 0 } } }),
726+
baseHash: current.payload?.hash,
727+
});
728+
729+
expect(res.error).toBeUndefined();
730+
expect(res.ok).toBe(true);
731+
expect(res.payload?.config?.messages?.groupChat?.historyLimit).toBe(0);
732+
} finally {
733+
if (previousConfig === null) {
734+
await fs.rm(configPath, { force: true });
735+
} else {
736+
await fs.writeFile(configPath, previousConfig, "utf-8");
737+
}
738+
resetConfigRuntimeState();
739+
}
740+
});
741+
698742
it("rejects config.patch when raw is null", async () => {
699743
const res = await rpcReq<{ ok?: boolean }>(requireWs(), "config.patch", {
700744
raw: "null",

0 commit comments

Comments
 (0)