-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
trace+tester: Adding local var values to trace and test report #6815
trace+tester: Adding local var values to trace and test report #6815
Conversation
Local variable values in test report ------------------------------------ When enabled (`--var-values` flag), the failure report for tests will contain values for variables local to the failing expression. e.g.: ``` FAILURES -------------------------------------------------------------------------------- data.test.test_foo: FAIL (0ms) test.rego:8: x == y + z | | | | | 3 | y + z: 5 | y: 2 1 SUMMARY -------------------------------------------------------------------------------- test.rego: data.test.test_foo: FAIL (0ms) -------------------------------------------------------------------------------- FAIL: 1/1 ``` Local variable values in pretty trace ------------------------------------- When enabled on `eval` and `test` commands (`--var-values` flag), local variable values are added to pretty trace: ``` query:1 Enter data.test.p = _ {} query:1 | Eval data.test.p = _ {} query:1 | Index data.test.p (matched 1 rule, early exit) {} /test.rego:4 | Enter data.test.p {} /test.rego:5 | | Eval x = 1 {} /test.rego:6 | | Eval y = 2 {} /test.rego:7 | | Eval z = 3 {} /test.rego:8 | | Eval minus(z, y, __local3__) {y: 2, z: 3} /test.rego:8 | | Eval x = __local3__ {__local3__: 1, x: 1} /test.rego:4 | | Exit data.test.p early {} query:1 | Exit data.test.p = _ {_: true, data.test.p: true} query:1 Redo data.test.p = _ {_: true, data.test.p: true} query:1 | Redo data.test.p = _ {_: true, data.test.p: true} /test.rego:4 | Redo data.test.p {} /test.rego:8 | | Redo x = __local3__ {__local3__: 1, x: 1} /test.rego:8 | | Redo minus(z, y, __local3__) {__local3__: 1, y: 2, z: 3} /test.rego:7 | | Redo z = 3 {z: 3} /test.rego:6 | | Redo y = 2 {y: 2} /test.rego:5 | | Redo x = 1 {x: 1} ``` Fixing: open-policy-agent#2546 Signed-off-by: Johan Fylling <[email protected]>
✅ Deploy Preview for openpolicyagent ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Signed-off-by: Johan Fylling <[email protected]>
The linter fails because it gets confused by some newer golang stuff: #6817 |
…iler stage Signed-off-by: Johan Fylling <[email protected]>
Signed-off-by: Johan Fylling <[email protected]>
@@ -536,6 +540,7 @@ recommended as some updates might cause them to be dropped by OPA. | |||
testCommand.Flags().BoolVar(&testParams.benchmark, "bench", false, "benchmark the unit tests") | |||
testCommand.Flags().StringVarP(&testParams.runRegex, "run", "r", "", "run only test cases matching the regular expression.") | |||
testCommand.Flags().BoolVarP(&testParams.watch, "watch", "w", false, "watch command line files for changes") | |||
testCommand.Flags().BoolVar(&testParams.varValues, "var-values", false, "show local variable values in test output") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming suggestions appreciated 😄.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments after reading through the change, skimming over a few lines here and there 😎
ast/compile.go
Outdated
useTypeCheckAnnotations bool // whether to provide annotated information (schemas) to the type checker | ||
allowUndefinedFuncCalls bool // don't error on calls to unknown functions. | ||
evalMode CompilerEvalMode | ||
rewriteTestRulesToCaptureUnboundDynamics bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Dynamics" -- it's not a term that's common in ast or topdown, is it? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True 😄, I think that trickled up from the rewriteDynamics*()
naming convention we have in the compiler. Naming suggestions are welcome :). It's a bit too long for my liking too ..
return false | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it would be possible to add a few tests cases showing of the rewriting that's happening here? I'm afraid I don't understand it just from the code 😅 Maybe I just haven't found them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I'll add some of those 👍 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added some tests for this compiler stage. Hope they make things more clear.
| | | | ||
| | {"read": ["alice", "bob"], "write": ["jane"]} | ||
| "jane" | ||
["write"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏 This is going to be a tremendous help!
Signed-off-by: Johan Fylling <[email protected]>
Signed-off-by: Johan Fylling <[email protected]>
@@ -321,7 +321,7 @@ jobs: | |||
fail-fast: false | |||
matrix: | |||
os: [ubuntu-22.04, macos-14] | |||
version: ["1.20"] | |||
version: ["1.21"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0.20
isn't a supported Go version anyways. I think we simply forgot to bump this when we bumped the build version to 0.22
.
Signed-off-by: Johan Fylling <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tests and the rename! LGTM
Local variable values in test report
When enabled (
--var-values
flag), the failure report for tests will contain values for variables local to the failing expression. e.g.:Local variable values in pretty trace
When enabled on
eval
andtest
commands (--var-values
flag), local variable values are added to pretty trace:Fixing: #2546