Skip to content

Commit 52c26d2

Browse files
committed
Keep flat cron duplicates rejectable
1 parent 0df932e commit 52c26d2

2 files changed

Lines changed: 56 additions & 8 deletions

File tree

‎src/agents/tools/cron-tool.test.ts‎

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,7 @@ describe("cron tool", () => {
11371137

11381138
it.each([
11391139
{
1140+
additionalProperty: "enabled ",
11401141
callId: "call-duplicate-padded-add",
11411142
input: {
11421143
action: "add",
@@ -1153,8 +1154,13 @@ describe("cron tool", () => {
11531154
},
11541155
},
11551156
label: "job",
1157+
verify: (params: Record<string, unknown>) => {
1158+
expect(params.enabled).toBe(false);
1159+
expect(params["enabled "]).toBe(true);
1160+
},
11561161
},
11571162
{
1163+
additionalProperty: "enabled ",
11581164
callId: "call-flat-duplicate-padded-add",
11591165
input: {
11601166
action: "add",
@@ -1169,22 +1175,60 @@ describe("cron tool", () => {
11691175
"enabled ": true,
11701176
},
11711177
label: "flat",
1178+
verify: (params: Record<string, unknown>) => {
1179+
expect(params.enabled).toBe(false);
1180+
expect(params["enabled "]).toBe(true);
1181+
},
1182+
},
1183+
{
1184+
additionalProperty: "cron ",
1185+
callId: "call-flat-duplicate-padded-cron-add",
1186+
input: {
1187+
action: "add",
1188+
name: "Holiday Check-in",
1189+
cron: "30 10,20 * * *",
1190+
"cron ": "*/5 * * * *",
1191+
sessionTarget: "isolated",
1192+
message: "Holiday check-in: how's everything going?",
1193+
},
1194+
label: "flat schedule shorthand",
1195+
verify: (params: Record<string, unknown>) => {
1196+
expect(params.schedule).toMatchObject({ expr: "30 10,20 * * *", kind: "cron" });
1197+
expect(params["cron "]).toBe("*/5 * * * *");
1198+
},
1199+
},
1200+
{
1201+
additionalProperty: "allowUnsafeExternalContent ",
1202+
callId: "call-flat-duplicate-padded-payload-add",
1203+
input: {
1204+
action: "add",
1205+
name: "Holiday Check-in",
1206+
schedule: { expr: "30 10,20 * * *", kind: "cron", tz: "Europe/Madrid" },
1207+
sessionTarget: "isolated",
1208+
message: "Holiday check-in: how's everything going?",
1209+
allowUnsafeExternalContent: false,
1210+
"allowUnsafeExternalContent ": true,
1211+
},
1212+
label: "flat payload shorthand",
1213+
verify: (params: Record<string, unknown>) => {
1214+
expect(params.payload).toMatchObject({ allowUnsafeExternalContent: false });
1215+
expect(params["allowUnsafeExternalContent "]).toBe(true);
1216+
},
11721217
},
11731218
])(
11741219
"preserves duplicate whitespace-padded cron add $label keys for strict validation",
1175-
async ({ callId, input }) => {
1220+
async ({ additionalProperty, callId, input, verify }) => {
11761221
const tool = createTestCronTool();
11771222
await tool.execute(callId, input);
11781223

11791224
const params = expectSingleGatewayCallMethod("cron.add") as Record<string, unknown>;
1180-
expect(params.enabled).toBe(false);
1181-
expect(params["enabled "]).toBe(true);
1225+
verify(params);
11821226
expect(Value.Check(CronAddParamsSchema, params)).toBe(false);
11831227
expect(Array.from(Value.Errors(CronAddParamsSchema, params))).toEqual(
11841228
expect.arrayContaining([
11851229
expect.objectContaining({
11861230
keyword: "additionalProperties",
1187-
params: { additionalProperties: ["enabled "] },
1231+
params: { additionalProperties: [additionalProperty] },
11881232
}),
11891233
]),
11901234
);

‎src/agents/tools/cron-tool.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -921,20 +921,24 @@ Use jobId canonical; id accepted compat. contextMessages (0-10) adds previous me
921921
// them inside `job`. When `params.job` is missing or empty, reconstruct
922922
// a synthetic job object from any recognised top-level job fields.
923923
// See: https://github.com/openclaw/openclaw/issues/11310
924+
let recoveredFlatJob = false;
924925
if (isMissingOrEmptyObject(params.job)) {
925926
const synthetic = recoverCronObjectFromFlatParams(params);
926927
// Only use the synthetic job if at least one meaningful field is present
927928
// (schedule, payload, message, or text are the minimum signals that the
928929
// LLM intended to create a job).
929930
if (synthetic.found && hasCronCreateSignal(synthetic.value)) {
930931
params.job = synthetic.value;
932+
recoveredFlatJob = true;
931933
}
932934
}
933935

934936
if (!params.job || typeof params.job !== "object") {
935937
throw new Error("job required");
936938
}
937-
const canonicalJob = canonicalizeCronToolObject(params.job as Record<string, unknown>);
939+
const canonicalJob = recoveredFlatJob
940+
? (params.job as Record<string, unknown>)
941+
: canonicalizeCronToolObject(params.job as Record<string, unknown>);
938942
assertNoCronCommandPayload(canonicalJob);
939943
assertCronDeliveryInputNonBlankFields(canonicalJob.delivery);
940944
const job =
@@ -1051,9 +1055,9 @@ Use jobId canonical; id accepted compat. contextMessages (0-10) adds previous me
10511055
if (!params.patch || typeof params.patch !== "object") {
10521056
throw new Error("patch required");
10531057
}
1054-
const canonicalPatch = canonicalizeCronToolObject(
1055-
params.patch as Record<string, unknown>,
1056-
);
1058+
const canonicalPatch = recoveredFlatPatch
1059+
? (params.patch as Record<string, unknown>)
1060+
: canonicalizeCronToolObject(params.patch as Record<string, unknown>);
10571061
assertNoCronCommandPayload(canonicalPatch);
10581062
assertCronDeliveryInputNonBlankFields(canonicalPatch.delivery);
10591063
const patch = normalizeCronJobPatch(canonicalPatch) ?? canonicalPatch;

0 commit comments

Comments
 (0)