Skip to content

Codegen-equivalence gate: prove generated Cedar decides like the spec#5

Merged
pyrex41 merged 2 commits into
mainfrom
feat/cedar-equivalence-gate
Jun 14, 2026
Merged

Codegen-equivalence gate: prove generated Cedar decides like the spec#5
pyrex41 merged 2 commits into
mainfrom
feat/cedar-equivalence-gate

Conversation

@pyrex41

@pyrex41 pyrex41 commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Supersedes #1. Same changes, rebased onto current main. The only conflict was in scripts/gates.sh: main added kernel-test gates 8 and 9 after #1 was cut, so the cedar equivalence check is now wired in as Gate 10 (not Gate 8). All of main's existing gates are kept intact. The four other files apply verbatim. Verification below re-run and reproduced on the rebased branch.


What

Adds a native, shen-derive-style codegen-equivalence gate to examples/shen-cedar-authz, plus a Prolog/functional differential check, wired into the backpressure gate suite.

Why

generate.rs renders Cedar from spec/authz.shen and strict-validates the shape of the result against the schema. It never checks that the generated PolicySet decides the same way as the spec it came from. Schema validation catches an ill-typed policy; it does not catch a closure bug, a rendering bug, or a hand-edit that quietly drops a permit. The only prior safeguard was the convention "never hand-edit the generated Cedar." This turns that convention into a red/green gate.

Changes

  • examples/shen-cedar-authz/examples/equiv.rs — loads spec/authz.shen into the served VM as the oracle (expand-all), renders the Cedar target, and asserts they agree on every request over a finite grid (one user per role × resources incl. an ungranted io). Exit 1 on any divergence; --inject-drift drops one permit to prove it catches drift. Generic over narrow Oracle/Target traits (ShenSpecOracle × CedarTarget); the seam is documented so a future SBCL oracle or shengen→Rust target can drop in.
  • examples/shen-cedar-authz/examples/reaches_equiv.rs — the same VM runs role reachability two ways: functional reaches (defun, ported from verify.rs) and a real defprolog prolog-reaches, both built from one edge table and differentially checked over all role pairs.
  • scripts/shen-cedar-equiv.sh + sb.toml + scripts/gates.sh — wired as Gate 10 (cedar-equiv).

Verification

All run locally, real exit codes:

cargo run -p shen-cedar-authz --example equiv                  → 12/12 agree, exit 0
cargo run -p shen-cedar-authz --example equiv -- --inject-drift → dana(Admin)·logs DIVERGENCE, exit 1
cargo run -p shen-cedar-authz --example reaches_equiv          → 49 pairs agree, exit 0
bash scripts/shen-cedar-equiv.sh                               → RESULT: PASS, exit 0
cargo fmt --all -- --check                                     → clean
cargo clippy -p shen-cedar-authz --all-targets -- -D warnings  → clean

Note: the new gate and fmt/clippy on the touched crate are verified; the full ./scripts/gates.sh (kernel tests etc.) was not re-run end-to-end in this change.

🤖 Generated with Claude Code

…spec

Re-applied onto current main. The cedar equivalence check is wired in as
Gate 10 (main added kernel-test gates 8/9 after the original PR was cut).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Cosmetic follow-up to the rebase: the cedar-equiv script header still said
'Gate 8' (it was renumbered to Gate 10 when this rebased onto a main that had
gained kernel-test gates 8/9), and gates.sh's header still said 'five gates'
(there are now 11: Gates 0-10). Comments only; no behavior change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@pyrex41 pyrex41 merged commit 8788119 into main Jun 14, 2026
2 checks passed
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.

1 participant