fix(core): allow changes: false beside another shell check predicate

A shell check's wording counts is, matches and changes as alternatives, but
validation counted an explicit `changes: false` as one of them while the run
path treats it as unset. A check that opted out of change detection beside
another predicate was rejected as choosing two, with no way to say no.
Accept it and count only `changes: true`.
This commit is contained in:
Kit Langton
2026-11-06 17:16:07 -08:00
Unverified
parent d2b3ae09b2
commit d6d3b2469f
2 changed files with 22 additions and 1 deletions
+2 -1
View File
@@ -71,10 +71,11 @@ export function validate(condition: ScheduleSchema.Condition): Result.Result<voi
switch (condition.type) {
case "shell": {
if (condition.run.trim() === "") return Result.fail("A shell check needs a command")
// `changes: false` opts out, so only a true value is a predicate of its own.
const predicates = [
condition.is !== undefined,
condition.matches !== undefined,
condition.changes !== undefined,
condition.changes === true,
].filter(Boolean).length
if (predicates > 1) return Result.fail("Choose at most one of is, matches or changes")
if (condition.matches === undefined) return Result.succeed(undefined)
+20
View File
@@ -1229,6 +1229,26 @@ describe("Schedule", () => {
).toMatchObject({ _tag: "Schedule.InvalidError" })
}),
)
it.effect("counts only a changes predicate that is turned on", () =>
Effect.gen(function* () {
const schedules = yield* setup()
const create = (check: NonNullable<Parameters<typeof schedules.create>[0]["if"]>) =>
schedules.create({
sessionID,
when: { type: "every", every: "15 seconds" },
if: check,
action: { type: "prompt", prompt: "x" },
})
// `changes: false` opts out, so it does not compete with another predicate.
expect(yield* create({ type: "shell", run: "echo hi", is: "hi", changes: false })).toMatchObject({
if: { type: "shell", run: "echo hi", is: "hi", changes: false },
})
expect(
yield* Effect.flip(create({ type: "shell", run: "echo hi", is: "hi", changes: true })),
).toMatchObject({ reason: "Choose at most one of is, matches or changes" })
}),
)
})
describe("code checks", () => {