Skip to content

test: add policy compiler round-trip tests (YAML -> Cedar -> evaluate) - #1595

Merged
lavkushry merged 1 commit into
mainfrom
test/1328-policy-compiler-roundtrip
Jun 27, 2026
Merged

test: add policy compiler round-trip tests (YAML -> Cedar -> evaluate)#1595
lavkushry merged 1 commit into
mainfrom
test/1328-policy-compiler-roundtrip

Conversation

@lavkushry

Copy link
Copy Markdown
Owner

Summary

  • Adds 36 evaluation-level tests in lib/policy/src/compiler.rs (mod round_trip) covering all 10 built-in policy templates / all 8 PolicySpec fields: each template is compiled YAML->Cedar, loaded into a real PolicyEngine, and evaluated against representative requests with an expected decision asserted — including forbid-overrides-permit and quarantine/require_approval annotation precedence cases.
  • production_baseline_compiled_matches_hand_written_equivalent additionally evaluates the same 6 requests against an independently hand-written equivalent Cedar policy and asserts identical decisions to the compiled output — the literal "compiled YAML == equivalent Cedar" comparison from the issue's acceptance criteria.
  • Adds upload_policy_bundle_evaluation_matches_standalone_cedar_load in src/src/routes/policy.rs: a signed policy bundle, once uploaded/verified/hot-reloaded, evaluates identically to loading that same Cedar text standalone (no signing pipeline involved) — closes the "signed bundle -> load -> evaluate -> same results" criterion. Tampered-bundle rejection was already covered by the existing upload_policy_bundle_rejects_tampered_bundle test.

Closes #1328

Test plan

  • Manually traced Cedar evaluation semantics (forbid-overrides-permit, annotation-escalation order-independence) against lib/policy/src/cedar.rs's actual authorize() implementation for every new assertion before writing it.
  • Brace/paren balance checked.
  • cargo test --workspace (cannot run locally — no Rust toolchain in this environment; relying on CI, per project convention).

Adds 36 evaluation-level tests in lib/policy/src/compiler.rs covering all
10 built-in policy templates / all 8 PolicySpec fields: each template is
compiled to Cedar, loaded into a real PolicyEngine, and evaluated against
representative requests with an expected decision asserted, including
forbid-overrides-permit and quarantine/require_approval annotation
precedence cases. production-baseline additionally evaluates the same
requests against an independently hand-written equivalent Cedar policy and
asserts identical decisions — the literal "compiled YAML == equivalent
Cedar" comparison from the issue.

Also adds one test in src/src/routes/policy.rs proving a signed policy
bundle, once uploaded/verified/hot-reloaded, evaluates identically to
loading that same Cedar text standalone (no signing pipeline involved).
Tampered-bundle rejection was already covered by an existing test.

Closes #1328
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@lavkushry, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 35 minutes and 22 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 31d6f68d-800f-4c16-a312-21e0118c4398

📥 Commits

Reviewing files that changed from the base of the PR and between 1ec6951 and eaf3848.

📒 Files selected for processing (2)
  • lib/policy/src/compiler.rs
  • src/src/routes/policy.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/1328-policy-compiler-roundtrip

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces comprehensive round-trip and integration tests for the Cedar policy compiler and engine, ensuring that compiled YAML templates and uploaded signed policy bundles evaluate correctly against a real PolicyEngine. The feedback suggests refactoring a test in compiler.rs to group parallel arrays into a single array of tuples, which improves safety and avoids potential out-of-bounds panics.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +525 to +550
let scenarios = [
request("github", "read", false, "trusted_internal_signed", "production", false), // unknown tool case driven by is_tool_known below
request("github", "merge", true, "trusted_internal_signed", "production", false),
request("github", "merge", true, "untrusted_external", "production", false),
request("github", "read", false, "trusted_internal_signed", "production", false),
request("github", "read", false, "trusted_internal_signed", "staging", false),
request("github", "read", false, "trusted_internal_signed", "production", false),
];
let is_tool_known = [false, true, true, true, true, true];
let is_mtls = [true, true, true, false, true, true];

for i in 0..scenarios.len() {
let compiled_decision =
decide(&compiled_engine, &scenarios[i], is_tool_known[i], is_mtls[i]).await;
let hand_written_decision = decide(
&hand_written_engine,
&scenarios[i],
is_tool_known[i],
is_mtls[i],
)
.await;
assert_eq!(
compiled_decision, hand_written_decision,
"scenario {i}: compiled YAML->Cedar and hand-written Cedar must agree"
);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using multiple parallel arrays (scenarios, is_tool_known, is_mtls) that must be kept in sync by index is error-prone and can easily lead to out-of-bounds panics if one array is updated without the others. Grouping the request and its associated parameters into a single tuple or struct array is much safer and more idiomatic.

            let scenarios = [
                (request("github", "read", false, "trusted_internal_signed", "production", false), false, true),
                (request("github", "merge", true, "trusted_internal_signed", "production", false), true, true),
                (request("github", "merge", true, "untrusted_external", "production", false), true, true),
                (request("github", "read", false, "trusted_internal_signed", "production", false), true, false),
                (request("github", "read", false, "trusted_internal_signed", "staging", false), true, true),
                (request("github", "read", false, "trusted_internal_signed", "production", false), true, true),
            ];

            for (i, (req, is_tool_known, is_mtls)) in scenarios.into_iter().enumerate() {
                let compiled_decision =
                    decide(&compiled_engine, &req, is_tool_known, is_mtls).await;
                let hand_written_decision = decide(
                    &hand_written_engine,
                    &req,
                    is_tool_known,
                    is_mtls,
                )
                .await;
                assert_eq!(
                    compiled_decision,
                    hand_written_decision,
                    "scenario {i}: compiled YAML->Cedar and hand-written Cedar must agree"
                );
            }

@lavkushry
lavkushry merged commit b1289b3 into main Jun 27, 2026
21 of 26 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.

[TEST] Add policy compiler round-trip test

1 participant