-
-
Save evankanderson/eaf0d86fe6ccee3e16aea521849c6d7f to your computer and use it in GitHub Desktop.
Minder rule test format experiment -- Starlark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Minder Rule Test — Starlark Format Experiment | |
| # Rule: branch_protection_allow_force_pushes | |
| # Format: Starlark (using go.starlark.net embedding) | |
| # | |
| # The test runner would embed a Starlark interpreter and expose: | |
| # - run_rule(rule_name, mocks, profile) → EvalResult | |
| # - EvalResult.status → "pass" | "fail" | "error" | |
| # - EvalResult.violations → list of violation messages | |
| # ── Shared setup ────────────────────────────────────────────────────────────── | |
| ENTITY = { | |
| "owner": "acme-corp", | |
| "repo": "widgets", | |
| "branch": "main", | |
| } | |
| # ── Git ingest rule ─────────────────────────────────────────────────────────── | |
| # Rule: actions_check_pinned_tags | |
| # Git ingest rules get file contents instead of HTTP mocks. | |
| # Starlark handles this naturally with a "files" dict. | |
| cases = { | |
| "pinned": { | |
| "ref": "b4ffde65f46336ab88eb53be808477a3936bae11", | |
| "expect": "pass", | |
| }, | |
| "unpinned" { | |
| "ref": "v4", | |
| "expect": "fail", | |
| "checker": lambda(result): assert len(result.violations) == 1 and "unpinned" in result.violations[0].msg, | |
| } | |
| } | |
| def testcase(case): | |
| fs = txtar(load("check_pinned.txtar")) | |
| fs = {k: v.format(ref=case.ref) for k, v in fs.items()} | |
| result = run_rule( | |
| rule = "actions_check_pinned_tags", | |
| entity = ENTITY, | |
| files = fs, | |
| ) | |
| assert result.status == case.expect | |
| if checker in case: | |
| case.checker(result) | |
| [testcase(v) for k, v in cases] | |
| def test_no_workflows(): | |
| result = run_rule( | |
| rule = "actions_check_pinned_tags", | |
| entity = ENTITY, | |
| files = {}, # empty repo | |
| ) | |
| assert result.status == "pass" | |
| test_no_workflows() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- .github/workflows/action.yml --- | |
| # This is a sample workflow, defanged by being in a .txtar file | |
| name: CI | |
| on: [push] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@{ref} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment