Commit 4d59821
feat(workflow-audit): rules for caller-SHA-as-foreign-checkout-ref anti-pattern (#348)
## Summary
Two specific, sensitive checks in \`Hypatia.Rules.WorkflowAudit\`:
| Rule | When it fires | Severity |
|---|---|---|
| \`:workflow_sha_as_foreign_ref\` | \`actions/checkout\` uses \`ref:
\${{ github.workflow_sha }}\` against a \`repository:\` value that is
not \`\${{ github.repository }}\` | :critical |
| \`:reusable_caller_context_self_checkout\` | In a reusable workflow
(\`on: workflow_call\`), \`actions/checkout\` of a literal foreign repo
at \`ref:\` = any caller-context variable (\`github.ref\` / \`head_ref\`
/ \`sha\` / \`workflow_sha\`) | :critical |
## Why this rule pair
\`github.workflow_sha\` (and \`github.ref\`, \`head_ref\`, \`sha\`) all
resolve to the **caller repo's** value, never to the SHA of the reusable
workflow itself. Passing them as \`ref:\` to \`actions/checkout\` of a
*foreign* repository asks that repo for a SHA / branch that doesn't
exist — \`git fetch\` exits with code 128, three retries, then the step
(and downstream jobs) fail.
This is the exact bug shipped in \`hyperpolymath/standards#219\`'s
pre-fix \`governance-reusable.yml:155\`, which cascaded into governance
failures across hundreds of stuck PRs estate-wide on 2026-05-26 —
symptom \"governance / Language / package anti-pattern policy — Failing
after 40s\" on every PR.
## Design notes
### Sensitivity (catches the bug)
- Both rules use a YAML step-splitter (line-walker that respects indent)
instead of a multi-line regex, so they handle both \`actions/checkout\`
step shapes:
- \`- uses: actions/checkout@…\` (uses-first)
- \`- name: … / uses: actions/checkout@…\` (name-first)
- Verified against the verbatim pre-fix \`governance-reusable.yml\` body
— both rules fire.
### Specificity (low false-positive rate)
- Rule 1 does **not** fire when \`repository: \${{ github.repository
}}\` (the safe caller-self pattern shipped in many workflows).
- Rule 2 does **not** fire on non-reusable workflows (no
\`workflow_call:\`) or when \`ref:\` is pinned to a literal value
(\`main\`, \`v1.2.0\`, or an explicit SHA).
- Verified against the post-fix \`governance-reusable.yml\` (\`ref:
main\`) — both rules stay quiet.
### Why two rules, not one
- Rule 1 is the narrowest cut against the specific \`workflow_sha\`
mistake — high signal, zero false positives expected.
- Rule 2 is the broader anti-pattern: a reusable that puts ANY
caller-context ref against a foreign \`repository:\`. Catches the cousin
bugs (\`github.ref\` or \`github.sha\` used the same wrong way) that the
standards PR fix did not need to address but Hypatia should still warn
on.
## Test plan
- [x] \`mix test test/workflow_audit_test.exs\` — 12 new test cases (4 +
5 + 3) covering positive firing, negative firing, and the two checkout
step shapes.
- [x] Standalone smoke (10 assertions) covering both pre-fix and
post-fix \`governance-reusable.yml\` shapes — see PR body of
standards#219 for source.
- [ ] After merge: re-run Hypatia scan against
\`hyperpolymath/standards\` post-PR-219 and confirm neither rule fires
(it shouldn't — \`ref: main\` is the safe shape).
- [ ] Estate sweep: run Hypatia against the rest of
\`hyperpolymath/standards/.github/workflows/*-reusable.yml\` to confirm
no other reusables carry the same anti-pattern. (I scanned manually and
found only \`governance-reusable.yml\` — no false positives expected,
but worth confirming through the production scanner path.)
## Related
- \`hyperpolymath/standards#219\` — source-of-truth fix that unblocks
the stuck-PR cascade.
- The orthogonal CodeQL js-ts failure on \`.git-private-farm#24\` is a
GitHub Actions billing/spending-limit block — not a Hypatia-detectable
anti-pattern, just owner-action in Settings → Billing & plans.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent d966e6e commit 4d59821
2 files changed
Lines changed: 398 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
92 | 94 | | |
93 | 95 | | |
94 | 96 | | |
95 | 97 | | |
96 | 98 | | |
97 | | - | |
| 99 | + | |
| 100 | + | |
98 | 101 | | |
99 | 102 | | |
100 | 103 | | |
| |||
505 | 508 | | |
506 | 509 | | |
507 | 510 | | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
508 | 738 | | |
509 | 739 | | |
510 | 740 | | |
| |||
0 commit comments