Skip to content

Commit 3c9437a

Browse files
fix: configs that used the previously documented WhatsApp exposeErrorText key now fail valida... (#74667)
* fix: configs that used the previously documented WhatsApp exposeErrorText key now fail valida... * fix(clawsweeper): address review for clawsweeper-commit-openclaw-openclaw-4cba08df01ea (1) --------- Co-authored-by: openclaw-clawsweeper[bot] <280122609+openclaw-clawsweeper[bot]@users.noreply.github.com>
1 parent 1ff1fbe commit 3c9437a

2 files changed

Lines changed: 64 additions & 2 deletions

File tree

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,44 @@ describe("WhatsApp prompt config Zod validation", () => {
9696
expect(result.data.direct?.["+15557654321"]?.systemPrompt).toBe("Keep responses concise");
9797
}
9898
});
99+
100+
it("accepts deprecated exposeErrorText as a no-op compatibility key", () => {
101+
const result = WhatsAppConfigSchema.safeParse({
102+
exposeErrorText: false,
103+
accounts: {
104+
work: {
105+
exposeErrorText: true,
106+
},
107+
},
108+
});
109+
110+
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+
);
138+
});
99139
});

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

Lines changed: 24 additions & 2 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(),
@@ -130,7 +142,7 @@ function enforceAllowlistDmPolicyAllowFrom(params: {
130142
});
131143
}
132144

133-
export const WhatsAppAccountSchema = z
145+
const WhatsAppAccountObjectSchema = z
134146
.object({
135147
...buildWhatsAppCommonShape({ useDefaults: false }),
136148
name: z.string().optional(),
@@ -141,7 +153,12 @@ export const WhatsAppAccountSchema = z
141153
})
142154
.strict();
143155

144-
export const WhatsAppConfigSchema = z
156+
export const WhatsAppAccountSchema = z.preprocess(
157+
stripDeprecatedWhatsAppNoopKeys,
158+
WhatsAppAccountObjectSchema,
159+
);
160+
161+
const WhatsAppConfigObjectSchema = z
145162
.object({
146163
...buildWhatsAppCommonShape({ useDefaults: true }),
147164
accounts: z.record(z.string(), WhatsAppAccountSchema.optional()).optional(),
@@ -206,3 +223,8 @@ export const WhatsAppConfigSchema = z
206223
});
207224
}
208225
});
226+
227+
export const WhatsAppConfigSchema = z.preprocess(
228+
stripDeprecatedWhatsAppNoopKeys,
229+
WhatsAppConfigObjectSchema,
230+
);

0 commit comments

Comments
 (0)