Skip to main content
Glama

Generate Rego test skeleton

rego_generate_test_skeleton
Read-onlyIdempotent

Generate 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

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?

Annotations already declare readOnly/idempotent/non-destructive, yet the description goes well beyond them: it discloses stub-skipping semantics, the `todo_test_` -> `test_` rename workflow and how `opa test` reports it as skipped, AST-based `input.*` inference feeding the `with input as {...}` placeholder, and the response's `inferredInputShape` field. This is rich behavioral context an agent cannot get from structured fields.

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?

Front-loaded with the core purpose, then layers on skip behavior, input-shape inference, tableStyle, and the response field. It is dense but every sentence carries distinct information; slightly long but no obvious filler.

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 relevant return field (`inferredInputShape`) and explains the generated artifact's structure. For a read-only generator with three fully-described params, nothing an agent needs to call it correctly is missing.

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 real meaning: `tableStyle` is explained as an `every tc in cases { ... }` loop with a cross-reference to `rego_test varValues: true`, and `v0Compatible` semantics (stubs still emit `import rego.v1`) are clarified. It adds value beyond the schema's parameter list.

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 scopes it against sibling tools by describing what is generated (stub tests per non-test rule) versus run. An agent can distinguish it from rego_test/rego_test_multiroot without opening a schema.

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?

Clearly describes the generation context (skips existing `test_*`/`todo_test_*` rules, emits `todo_test_` for computed-head value rules) and explains when to use `tableStyle` (multiple input/expected pairs). It does not explicitly name alternative sibling tools or state exclusions, so it stops short of a 5.

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