diff --git a/packages/ui/src/features/loops/components/LoopTriggerEditor.tsx b/packages/ui/src/features/loops/components/LoopTriggerEditor.tsx index 1731d7f6be..eb900993d2 100644 --- a/packages/ui/src/features/loops/components/LoopTriggerEditor.tsx +++ b/packages/ui/src/features/loops/components/LoopTriggerEditor.tsx @@ -18,12 +18,12 @@ import { type RecurringFrequency, } from "../loopCron"; import { + defaultLoopScheduleTrigger, emptyLoopApiTriggerConfig, emptyLoopGithubTriggerConfig, emptyLoopScheduleTriggerConfig, isTriggerDraftValid, type LoopTriggerDraft, - nextDraftTriggerKey, } from "../loopFormTypes"; import { LoopRepositoryPicker } from "./LoopRepositoryPicker"; @@ -97,15 +97,7 @@ export function LoopTriggerEditor({ }; const addTrigger = () => { - onChange([ - ...triggers, - { - key: nextDraftTriggerKey(), - type: "schedule", - enabled: true, - config: emptyLoopScheduleTriggerConfig(), - }, - ]); + onChange([...triggers, defaultLoopScheduleTrigger()]); }; return ( diff --git a/packages/ui/src/features/loops/loopFormTypes.test.ts b/packages/ui/src/features/loops/loopFormTypes.test.ts index 55af79af62..8df75b6dd5 100644 --- a/packages/ui/src/features/loops/loopFormTypes.test.ts +++ b/packages/ui/src/features/loops/loopFormTypes.test.ts @@ -98,7 +98,7 @@ describe("isTriggerDraftValid", () => { describe("isLoopFormValid", () => { it("accepts a named form with instructions and no triggers", () => { - expect(isLoopFormValid(validFormValues())).toBe(true); + expect(isLoopFormValid({ ...validFormValues(), triggers: [] })).toBe(true); }); it.each([ @@ -128,6 +128,19 @@ describe("isLoopFormValid", () => { }); }); +describe("emptyLoopFormValues", () => { + it("starts new loops with an enabled weekly schedule trigger", () => { + expect(emptyLoopFormValues().triggers).toEqual([ + { + key: expect.any(String), + type: "schedule", + enabled: true, + config: { cron_expression: "0 9 * * 1", timezone: "UTC" }, + }, + ]); + }); +}); + describe("normalizeLoopFormValues", () => { it("forces team visibility when a context target is set", () => { const values = { diff --git a/packages/ui/src/features/loops/loopFormTypes.ts b/packages/ui/src/features/loops/loopFormTypes.ts index b298b93841..e7fbee6ca0 100644 --- a/packages/ui/src/features/loops/loopFormTypes.ts +++ b/packages/ui/src/features/loops/loopFormTypes.ts @@ -45,7 +45,7 @@ export interface LoopFormValues { } export function emptyLoopScheduleTriggerConfig(): LoopSchemas.LoopScheduleTriggerConfig { - return { cron_expression: "0 9 * * *", timezone: "UTC" }; + return { cron_expression: "0 9 * * 1", timezone: "UTC" }; } export function emptyLoopGithubTriggerConfig(): LoopSchemas.LoopGithubTriggerConfig { @@ -98,6 +98,15 @@ export function nextDraftTriggerKey(): string { return `draft-trigger-${draftKeySeq}`; } +export function defaultLoopScheduleTrigger(): LoopTriggerDraft { + return { + key: nextDraftTriggerKey(), + type: "schedule", + enabled: true, + config: emptyLoopScheduleTriggerConfig(), + }; +} + export function emptyLoopFormValues(): LoopFormValues { return { name: "", @@ -108,7 +117,7 @@ export function emptyLoopFormValues(): LoopFormValues { model: "", reasoningEffort: null, repositories: [], - triggers: [], + triggers: [defaultLoopScheduleTrigger()], behaviors: defaultLoopBehaviors(), notifications: defaultLoopNotifications(), contextTarget: null,