open-policy-agent / opa

Open Policy Agent (OPA) is an open source, general-purpose policy engine.
https://www.openpolicyagent.org
Apache License 2.0
9.3k stars 1.29k forks source link

trace+tester: Adding local var values to trace and test report #6815

Closed johanfylling closed 6 days ago

johanfylling commented 2 weeks ago

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: #2546

netlify[bot] commented 2 weeks ago

Deploy Preview for openpolicyagent ready!

Name Link
Latest commit 4ea05387f229fa593310fc9b82640d9b128cfba4
Latest deploy log https://app.netlify.com/sites/openpolicyagent/deploys/667a99d0d1b8ff000899632e
Deploy Preview https://deploy-preview-6815--openpolicyagent.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

johanfylling commented 2 weeks ago

The linter fails because it gets confused by some newer golang stuff: https://github.com/open-policy-agent/opa/pull/6817