Skip to content

Commit 60b0442

Browse files
fix(clawsweeper): address review for clawsweeper-commit-openclaw-openclaw-4cba08df01ea (1)
1 parent b370935 commit 60b0442

2 files changed

Lines changed: 51 additions & 3 deletions

File tree

src/config/zod-schema.providers-whatsapp.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,32 @@ describe("WhatsApp prompt config Zod validation", () => {
108108
});
109109

110110
expect(result.success).toBe(true);
111+
if (result.success) {
112+
expect(Object.hasOwn(result.data, "exposeErrorText")).toBe(false);
113+
expect(Object.hasOwn(result.data.accounts?.work ?? {}, "exposeErrorText")).toBe(false);
114+
}
115+
});
116+
117+
it("keeps deprecated exposeErrorText out of generated config surfaces", () => {
118+
const schema = WhatsAppConfigSchema.toJSONSchema({
119+
target: "draft-07",
120+
unrepresentable: "any",
121+
}) as {
122+
properties?: {
123+
exposeErrorText?: unknown;
124+
accounts?: {
125+
additionalProperties?: {
126+
properties?: {
127+
exposeErrorText?: unknown;
128+
};
129+
};
130+
};
131+
};
132+
};
133+
134+
expect(schema.properties?.exposeErrorText).toBeUndefined();
135+
expect(schema.properties?.accounts?.additionalProperties?.properties?.exposeErrorText).toBe(
136+
undefined,
137+
);
111138
});
112139
});

src/config/zod-schema.providers-whatsapp.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ const WhatsAppAckReactionSchema = z
4848
.strict()
4949
.optional();
5050

51+
function stripDeprecatedWhatsAppNoopKeys(value: unknown): unknown {
52+
if (!value || typeof value !== "object" || Array.isArray(value)) {
53+
return value;
54+
}
55+
if (!Object.hasOwn(value, "exposeErrorText")) {
56+
return value;
57+
}
58+
const next = { ...(value as Record<string, unknown>) };
59+
delete next.exposeErrorText;
60+
return next;
61+
}
62+
5163
function buildWhatsAppCommonShape(params: { useDefaults: boolean }) {
5264
return {
5365
enabled: z.boolean().optional(),
@@ -57,7 +69,6 @@ function buildWhatsAppCommonShape(params: { useDefaults: boolean }) {
5769
sendReadReceipts: z.boolean().optional(),
5870
messagePrefix: z.string().optional(),
5971
responsePrefix: z.string().optional(),
60-
exposeErrorText: z.boolean().optional(),
6172
dmPolicy: params.useDefaults
6273
? DmPolicySchema.optional().default("pairing")
6374
: DmPolicySchema.optional(),
@@ -131,7 +142,7 @@ function enforceAllowlistDmPolicyAllowFrom(params: {
131142
});
132143
}
133144

134-
export const WhatsAppAccountSchema = z
145+
const WhatsAppAccountObjectSchema = z
135146
.object({
136147
...buildWhatsAppCommonShape({ useDefaults: false }),
137148
name: z.string().optional(),
@@ -142,7 +153,12 @@ export const WhatsAppAccountSchema = z
142153
})
143154
.strict();
144155

145-
export const WhatsAppConfigSchema = z
156+
export const WhatsAppAccountSchema = z.preprocess(
157+
stripDeprecatedWhatsAppNoopKeys,
158+
WhatsAppAccountObjectSchema,
159+
);
160+
161+
const WhatsAppConfigObjectSchema = z
146162
.object({
147163
...buildWhatsAppCommonShape({ useDefaults: true }),
148164
accounts: z.record(z.string(), WhatsAppAccountSchema.optional()).optional(),
@@ -207,3 +223,8 @@ export const WhatsAppConfigSchema = z
207223
});
208224
}
209225
});
226+
227+
export const WhatsAppConfigSchema = z.preprocess(
228+
stripDeprecatedWhatsAppNoopKeys,
229+
WhatsAppConfigObjectSchema,
230+
);

0 commit comments

Comments
 (0)