
The demo uses a duplicate-refund bug. Perch flags the unguarded function and passes after the fix. The requirement stays in perch.yaml, so you can check a later agent edit against the same rule. Full command output.
Add the requirement
After setting up Perch, save this as refund.py in your Git repository:
def refund(order, payment):
payment.refund(order.total)
order.status = "refunded"
return order
Add the behavior you need as a rule:
$ perch rules add refund-once --where refund.py --each method --ensure "Refunded orders cannot be refunded again."
Added refund-once.
The rule is saved in perch.yaml. Check the function:
$ perch check refund.py::refund --rules refund-once
refund.py:1 refund
1 check, 1 broken.
Confidence Rule Description
80% refund-once Refunded orders cannot be refunded again.
This is output from the September 20 demo. The check exited 3, indicating a finding.
Add the guard
Return before calling the payment provider when the order is already refunded:
def refund(order, payment):
if order.status == "refunded":
return order
payment.refund(order.total)
order.status = "refunded"
return order
Run the same command against the edited file:
$ perch check refund.py::refund --rules refund-once
refund.py:1 refund
1 check, nothing to report.
That run exited 0. perch check reads the file on disk, so the fix does not need to be committed first. Fresh model checks can return different scores.
Check the payment behavior
Add a regression test that calls refund twice with the same order and counts payment-provider calls. Also test provider failure: a failed refund must not leave the order marked refunded.
This guard handles sequential calls. Concurrent requests and a crash after payment succeeds need provider idempotency and durable state; test those at the payment boundary.
Run the rule in CI
Commit the rule with the code. With origin/main fetched, check the branch’s changes:
perch scan --since origin/main --filter type=lint
Have your coding agent run the focused check after edits too. Agent setup adds Perch instructions to supported coding assistants.