diff --git a/packages/db/src/lib/__tests__/custom-automations.test.ts b/packages/db/src/lib/__tests__/custom-automations.test.ts index 62edd2597..5e642b24e 100644 --- a/packages/db/src/lib/__tests__/custom-automations.test.ts +++ b/packages/db/src/lib/__tests__/custom-automations.test.ts @@ -293,6 +293,29 @@ describe('custom automations helpers', () => { await deleteCustomAutomation(created.id); }); + it('does not claim a launch after the automation is disabled', async () => { + const created = await createCustomAutomation({ + name: `Disabled claim gate ${Date.now()}`, + prompt: 'Scan for flaky tests.', + enabled: true, + scheduleMode: 'daily', + environmentId: FAST_EXECUTION, + target: {}, + }); + const staleLastRunAt = created.lastRunAt; + + await db + .update(customAutomations) + .set({ enabled: false }) + .where(eq(customAutomations.id, created.id)); + + expect( + await tryClaimCustomAutomationLaunch(created.id, staleLastRunAt), + ).toBeNull(); + + await deleteCustomAutomation(created.id); + }); + it('rejects a partially specified report destination', async () => { await expect( createCustomAutomation({ diff --git a/packages/db/src/lib/custom-automations.ts b/packages/db/src/lib/custom-automations.ts index a0d0f1929..7c6528ebb 100644 --- a/packages/db/src/lib/custom-automations.ts +++ b/packages/db/src/lib/custom-automations.ts @@ -402,6 +402,7 @@ export async function tryClaimCustomAutomationLaunch( .where( and( eq(customAutomations.id, id), + eq(customAutomations.enabled, true), or( isNull(customAutomations.launchClaimedAt), lt(customAutomations.launchClaimedAt, staleBefore),