Generate Rego test skeleton
rego_generate_test_skeletonGenerate a Rego _test.rego skeleton from a policy by emitting one stub per production rule, inferring input. shape, and optionally building table-driven cases.
Instructions
Generate a *_test.rego skeleton from a policy. Parses the AST, finds each non-test rule, and emits one stub test per rule. Existing test_* and todo_test_* rules are skipped automatically -- only production rules get stubs, and a value rule whose head is computed gets a todo_test_ stub, which opa test reports as skipped until its expected value is filled in and it is renamed test_. The AST is walked to infer which input.* fields the policy accesses; the inferred shape is used as the placeholder with input as {...} in each stub, so the developer only needs to fill in realistic values rather than guess the structure. With tableStyle: true, each stub uses an every tc in cases { ... } loop so you can add multiple input/expected pairs without duplicating assertion code. The inferredInputShape field in the response shows the detected shape for reference.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| source | Yes | Rego source to generate tests for. | |
| tableStyle | No | Generate table-driven test stubs instead of single-case stubs. Each rule gets a `cases` array and an `every tc in cases { ... }` assertion loop. Pair with `rego_test varValues: true` to see which case failed. | |
| v0Compatible | No | Read the policy as Rego v0 (`--v0-compatible`). The stubs are still written with `import rego.v1`, which a v0 test run (`rego_test` with `v0Compatible`) accepts too. |