Skip to main content
Glama

Generate Rego test skeleton

rego_generate_test_skeleton
Read-onlyIdempotent

Generate *_test.rego stub tests from a Rego policy, inferring input shape and skipping existing tests. Each production rule gets a todo_test_ stub to fill in.

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. Every stub is a todo_test_ rule, which opa test reports as skipped (and exits non-zero for) until a realistic input and the expected value are filled in and it is renamed test_: a placeholder input against a placeholder expectation would otherwise pass while testing nothing. 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

TableJSON Schema
NameRequiredDescriptionDefault
sourceYesRego source to generate tests for.
tableStyleNoGenerate 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.
v0CompatibleNoRead 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.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv0.8.0
    • addedInput schema / properties / v0Compatible
      Added value: +{
      +  "description": "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.",
      +  "type": "boolean"
      +}
  2. Addedv0.1.13
  3. Removedv0.1.5
  4. Addedv0.1.2
  5. Removedv0.1.1
  6. First observedv0.1.0

TDQS

A4.6/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Goes well beyond the readOnly/idempotent annotations by explaining that generated stubs are todo_test_ rules that opa test reports as skipped and fails on, and why placeholder values are intentionally not passing. It also discloses that the AST walk infers input.* shape used as the placeholder with-input, and that inferredInputShape is returned.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Core purpose is front-loaded and every sentence carries functional information, but the prose is dense and around six sentences long. It is efficient rather than padded, though not maximally tight.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

No output schema exists, yet the description names the returned inferredInputShape field, explains the skip/fail semantics, and covers both parameter modes. For a code-generation tool with annotations covering the safety profile, this is complete enough to invoke correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% so baseline is 3, but the description adds meaning beyond the schema: it explains the every tc in cases loop semantics for tableStyle and the v0Compatible nuance that stubs use import rego.v1 which a v0 run still accepts. This enriches parameter understanding rather than restating it.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and artifact ('generate a *_test.rego skeleton from a policy') and immediately delineates behavior: parses AST, one stub per non-test rule, skips existing test_*/todo_test_* rules. This clearly separates it from siblings like rego_test (which runs tests) and rego_parse_ast.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description conveys a clear workflow context: generate skeletons, fill in realistic input/expected, then rename todo_test_ to test_. It explains what is skipped automatically. However it does not explicitly state when to reach for this over related tools such as rego_infer_input_schema or conftest_test.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.