Skip to content

test: check the Rego policies the docs tell people to copy - #433

Merged
AlexKantor87 merged 4 commits into
mainfrom
claude/check-rego-examples
Sep 29, 2026
Merged

AlexKantor87 merged 4 commits into
mainfrom
claude/check-rego-examples

Conversation

@AlexKantor87

@AlexKantor87 AlexKantor87 commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Readers copy the Rego blocks on this site. One that does not compile wastes their time. One that compiles but denies everything is worse, because it looks like it worked.

This PR fixes some of the problematic rego.

A reader copies these blocks. One that does not compile wastes their time.
One that compiles but denies everything is worse, because it looks like it
worked.

The test holds a block to that bar when it is presented as a whole file:
either it declares its own package, or its fence names a .rego file, as in
```rego pr-compliant.rego. Name the file whenever the page tells someone to
create it, and this holds the block to compiling from then on.

Blocks with neither are fragments showing one rule. They cannot compile
alone because their inputs are unbound, so there is nothing to check.

`default allow := false` on its own does not satisfy the allow check. A
policy can carry that line, have its real rule misspelled, compile, and
deny every input forever. That is the failure this exists to catch, so the
check wants a rule that can actually become true.

It found one. tutorials/linking_trails_across_branches.md had three faults
in nine lines: `package main`, which Kosli never reads because it queries
data.policy.allow; pre-1.0 syntax that no longer compiles; and
input.trail.compliance, where the field is input.trail.compliance_status.
Fixed here.

CI installs opa, pinned to v1.9.0 and checked against its published
sha256, matching how this workflow pins its actions. Without opa the
compile checks skip locally but fail outright when CI is set, so the suite
cannot go quietly green.

verified: pytest tests/ -> 58 passed. mint broken-links reports one break,
          in tutorials/working_with_controls.mdx, pre-existing on main.
mutation: misspell the allow rule but keep the default line -> "defines no
          allow rule that can be true". Drop the package from a named block
          -> "is shown as a file to create but declares no package". Rename
          the package -> "so Kosli never reads it". Break the syntax -> opa's
          rego_parse_error. Each fails by name. A fence carrying attributes
          rather than a filename stays a fragment.
search: counted every fenced block on the site, 881 of them. bash, shell,
        yaml and json were measured and left out: their failures are
        placeholders like <your-org>, CloudFormation !Ref and `...`
        ellipses, so a check there reports conventions, not defects.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@AlexKantor87
AlexKantor87 requested a review from a team as a code owner September 28, 2026 10:51
@mintlify

mintlify Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
kosli 🟢 Ready View Preview Sep 29, 2026, 9:19 AM

@claude

claude Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @AlexKantor87's task in 2m 28s —— View job


Follow-up review: 6378434..7a34e5f

  • Fetch previous review comments on PR test: check the Rego policies the docs tell people to copy #433
  • Diff 6378434..7a34e5f and map each prior Claude finding to changed lines
  • Check status of each previous finding
  • Review new commits' changed lines for bugs/security/regressions
  • Post inline comments for any new issues found
  • Post summary

Changed in this round: .github/workflows/pr-quality.yml (opa install method), tests/test_rego_examples.py (new guard test).

Previous findings:

  • compliance → compliance_status sweep (my earlier inline comment on tutorials/linking_trails_across_branches.md:55): resolved, but by commit 6378434 which is the before side of this diff — not touched by the two new commits (9c588e5, 7a34e5f). Confirmed both jq reads (:75, :263) now use .compliance_status.is_compliant. Nothing further to do here.
  • setup-opa action request (human review thread, not a prior Claude finding): addressed by 9c588e5 — the manual curl+checksum install is replaced with open-policy-agent/setup-opa@b2b258e... (# v2.4.0), version: 1.9.0, matching the version previously pinned and the SHA-pin style used elsewhere in this file. I couldn't reach network from this sandbox to independently verify the tag→SHA mapping, but the change is structurally sound and matches what was agreed in the thread.

New changes in this round — no bugs found:

  • 7a34e5f adds test_the_docs_still_contain_rego_policies, asserting POLICIES (now computed once via list(rego_policies()) and reused by both parametrized tests) is non-empty — a real gap closed: previously, if the fence regex silently stopped matching, both compile/contract tests would just collect zero cases and pass vacuously. Logic checks out; no vacuous-pass or double-generator-consumption issues.
  • 9c588e5's workflow edit is a straightforward, correctly-scoped substitution — no other steps affected.

Note on tooling: gh and outbound network calls required approval I couldn't grant in this run, so I relied on the review comments already provided in context rather than re-fetching via gh api, and I'm posting this status via the PR comment rather than gh pr comment (no new comment created, per this session's operating constraints). I also don't have a way to formally resolve the old inline review thread from here — it's confirmed fixed above, so it can be resolved manually.

No new inline comments needed this round.

Comment thread tutorials/linking_trails_across_branches.md
The Rego fix in the previous commit corrected input.trail.compliance to
compliance_status. The same wrong field is read twice more on the same
page, in the jq tab, and I did not look.

`kosli get trail --output json` has no compliance key. So jq printed null
and the next step ran with --compliant="null".

verified: extracted the documented get trail sample from
          client_reference/kosli_get_trail.md and ran both expressions
          against it. .compliance.is_compliant gives null,
          .compliance_status.is_compliant gives true.

A top-level is_compliant exists too, so .is_compliant would work. The
nested path matches the sentence above the block and the Rego block on the
same page.

search: grep -rnE "\.compliance\." over every md and mdx -> these two lines
        and nothing else. Same for jq reads of trail JSON.
no mutation: prose and shell, no test. pytest tests/ still 58 passed.

Raised by the review bot on #433.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Comment thread .github/workflows/pr-quality.yml
AlexKantor87 and others added 2 commits September 29, 2026 10:10
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
An empty parametrize list is 0 tests and exit 0, so the whole check
disappeared silently if the fence pattern stopped matching.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@AlexKantor87

Copy link
Copy Markdown
Contributor Author

Done - using the official action now, pinned to the v2.4.0 commit. Agreed on upstream, I won't open that from here.

Also in this push: my own test could pass while testing nothing. It runs over a list of Rego blocks found by a pattern; if the pattern stops matching, the list is empty, pytest runs 0 tests and exits 0. Added a check that the list isn't empty.

search: grep -rnE 'curl .*(-o|--output)' .github/workflows/
one other hand-rolled download, update-cli-docs.yml:70 (helm-docs .deb). Not in this PR, left alone.
mutation: run the test file with no docs under it -> test_the_docs_still_contain_rego_policies red (before: 2 skipped, exit 0)

@AlexKantor87
AlexKantor87 merged commit 424b66d into main Sep 29, 2026
6 checks passed
@AlexKantor87
AlexKantor87 deleted the claude/check-rego-examples branch September 29, 2026 09:55

This branch was successfully deployed

1 active deployment
staging — 7a34e5fa Deployed Sep 29, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants