mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-21 04:12:08 +03:00
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:
@@ -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)
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
Reference in New Issue
Block a user