Skip to content

Conversation

@fatelei
Copy link

@fatelei fatelei commented Dec 2, 2025

cargo test -r --test opa -- v1/rendertemplate
Compiling regorus v0.2.5 (/Users/fatelei/github/regorus)
Finished release profile [optimized + debuginfo] target(s) in 1.75s
Running tests/opa.rs (target/release/deps/opa-f3ff12037003e175)
OPA TESTSUITE: target/opa/branch/v0.68.0/test/cases/testdata
0: rendertemplate/simple PASSED
1: rendertemplate/simpleint PASSED
2: rendertemplate/complex PASSED
3: rendertemplate/missingkey PASSED

OPA TESTSUITE STATUS
FOLDER PASS FAIL
v1/rendertemplate : 4 0

TOTAL

cargo test -r --test opa -- rendertemplate
Finished release profile [optimized + debuginfo] target(s) in 0.20s
Running tests/opa.rs (target/release/deps/opa-f3ff12037003e175)
OPA TESTSUITE: target/opa/branch/v0.68.0/test/cases/testdata

OPA TESTSUITE STATUS
FOLDER PASS FAIL

Error: no matching tests found.
error: test failed, to rerun pass --test opa

Caused by:
process didn't exit successfully: /Users/fatelei/github/regorus/target/release/deps/opa-f3ff12037003e175 rendertemplate (exit status: 1)

@fatelei
Copy link
Author

fatelei commented Dec 2, 2025

@microsoft-github-policy-service agree

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for the strings.render_template builtin function to the Regorus OPA interpreter, enabling Go-style template rendering with variable interpolation, conditional blocks (if), and iteration constructs (range). The implementation also includes two minor fixes: correcting pattern matching in the interpreter's default rule handling and making lifetime annotations explicit in the time compatibility module.

  • Added strings.render_template builtin function with support for Go template syntax including variable interpolation, conditional rendering, and iteration over arrays/sets/objects
  • Fixed pattern matching in interpreter.rs to properly use .as_ref() for comparing optional default rule indices
  • Made lifetime annotations explicit in builtins/time/compat.rs for better code clarity

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
src/builtins/strings.rs Adds the complete strings.render_template implementation with helper functions for expression evaluation, block parsing, and template rendering
src/interpreter.rs Fixes pattern matching for default rule index comparison to use .as_ref()
src/builtins/time/compat.rs Changes implicit lifetime '_ to explicit 'a in impl block

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@anakrish
Copy link
Collaborator

anakrish commented Dec 2, 2025

@fatelei Thanks for the contribution. CoPilot has provided very good feedback above.

@fatelei
Copy link
Author

fatelei commented Dec 3, 2025

@fatelei Thanks for the contribution. CoPilot has provided very good feedback above.

ok

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@anakrish
Copy link
Collaborator

Hey @fatelei,
Thanks for the contribution. Given that templating is a language in itself, it would be good to add test cases here: https://github.com/microsoft/regorus/tree/main/tests/interpreter/cases/builtins/strings

covering all the interesting cases.

@anakrish
Copy link
Collaborator

@fatelei, It is not exactly clear to me what the template language semantics are. Is this the spec: https://pkg.go.dev/text/template

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