🐛 fix(work): Work rules passes a pull request that has already merged or closed (#649)

Merged
AT
5d ago
+52-2

Slice: #659

Work rules no longer fails a pull request that has already merged or closed (#649).

Today: https://github.com/veda-hq/niyam/pull/598 (slice #590) merged at 2026-11-24T12:35:05Z. Its description was edited 7 seconds later, at 12:35:12Z (GraphQL userContentEdits), and that edited event started niyam / Work rules at 12:35:17Z: https://github.com/veda-hq/niyam/actions/runs/45394953619. It was not the closed event: checks.yml's work-rules job skips that action, and the run's niyam-merged job, which runs only on closed, was skipped. The merge had already closed #590, so the run refused with "#590 is closed, so this pull request is a fix". An edited event's payload carries the pull request as it is then: state: closed, merged: true.

Now: prWorkRules returns early when the event's pull request is closed, before any slice is read. It prints one line:

  • pr-work-rules: #N is merged; nothing to judge for a merged pull request;
  • pr-work-rules: #N is closed; nothing to judge for one closed without merging.

It decides on state === 'closed' alone, because a merged pull request is always closed. merged only picks the wording, so no mutant survives on a redundant ||. The check comes after the not-adopted, feature-off and personal-repository exits, which still win. An open pull request is judged exactly as before.

Tests (src/work.test.ts):

  • a merged pull request whose slice is closed passes with the merged line, and makes no /issues/ read;
  • a pull request closed without merging passes with the closed line, and makes no /issues/ read;
  • an open pull request (state: 'open') that names a closed slice and no State is still refused as a fix.

The README's Work rules section says a closed pull request is not judged.

Not changed: which events the workflow runs on.

Evidence

pnpm test
ℹ tests 2479
ℹ pass 2479
ℹ fail 0
ℹ all files            |  99.77 |    97.73 |   99.43 |
  ✔ passes a pull request already merged, its slice closed, reading no slice
  ✔ passes a pull request already closed, its slice closed, reading no slice
  ✔ judges an open pull request as before: a closed slice it names with no State is a fix still owed
  • pnpm typecheck and pnpm lint exit 0.
  • The pre-commit hook passed, and so did the pre-push hook, with niyam's agent check that slice #659 may be built.

🤖 Generated with Claude Code