Skip to content

Commit 2f21615

Browse files
committed
fix(core): treat non-zero shell exit at schedule creation as not yet
1 parent 86202ca commit 2f21615

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

‎packages/core/src/schedule.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,7 @@ const layer = Layer.effect(
642642
),
643643
)
644644
const shouldSeed =
645-
check.mode === "until" ||
646-
when.type === "every" ||
647-
(check.condition.type === "shell" && check.condition.changes === true)
645+
check.mode === "until" || (check.condition.type === "shell" && check.condition.changes === true)
648646
if (!shouldSeed) return { matched: false as const, state: null as Schema.Json, checks: 0 }
649647
const init = yield* ScheduleCheck.evaluate(session, check, null).pipe(
650648
instances.provide(session),
@@ -654,7 +652,8 @@ const layer = Layer.effect(
654652
),
655653
),
656654
)
657-
if (!init.ok) return yield* new InvalidError({ reason: init.error })
655+
// A target that is not up yet (e.g. curl exiting 7 while a server boots) is "not yet", not an invalid schedule.
656+
if (!init.ok) return { matched: false as const, state: null as Schema.Json, checks: 0 }
658657
if (check.mode === "until" && init.wake)
659658
return { matched: true as const, state: init.state, message: init.message }
660659
return { matched: false as const, state: init.state, checks: 1 }

‎packages/core/test/schedule.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -983,16 +983,20 @@ describe("Schedule", () => {
983983
}),
984984
)
985985

986-
it.effect("supports is and matches predicates", () =>
986+
it.effect("supports is and matches predicates, even when the command exits non-zero at creation", () =>
987987
Effect.gen(function* () {
988988
const schedules = yield* setup()
989-
shellState.stdout = "OPEN\n"
989+
// Service is still booting at creation (curl exits 7); creating an `until` with `is` still succeeds.
990+
shellState.exitCode = 7
991+
shellState.stdout = ""
990992
const exact = yield* schedules.create({
991993
sessionID,
992994
when: { type: "every", every: "20 seconds" },
993-
until: { type: "shell", run: "gh pr view 1", is: "MERGED" },
995+
until: { type: "shell", run: "curl -sf http://localhost:3000/status", is: "MERGED" },
994996
action: { type: "prompt", prompt: "Merged." },
995997
})
998+
shellState.exitCode = 0
999+
shellState.stdout = "OPEN\n"
9961000
const regex = yield* schedules.create({
9971001
sessionID,
9981002
when: { type: "every", every: "20 seconds" },

0 commit comments

Comments
 (0)