Skip to main content
Glama

Generate Rego test skeleton

rego_generate_test_skeleton
Read-onlyIdempotent

Generates a *test.rego skeleton from a Rego policy: one todo_test stub per production rule, with the inferred input shape as a placeholder so you fill in values instead of guessing structure.

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 (a long one is written once, as todo_input), so the developer only needs to fill in realistic values rather than guess the structure. A rule written with a ref head is tested by the document it builds: users[name].role := ... gets a stub for users. 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.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "source": "<source>"
    },
    "name": "rego_generate_test_skeleton"
  }
}

Input 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, and the description adds substantial behavior on top: stubs are emitted as `todo_test_` rules that `opa test` reports as skipped and exits non-zero for, and it explains why (a placeholder input against a placeholder expectation would pass while testing nothing). It further discloses the hoisting of a long inferred shape into `todo_input`, ref-head handling, and the `inferredInputShape` response field.

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?

Purpose and mechanism are front-loaded, then details follow in a sensible order (skip logic, todo_test rationale, inferred input, ref heads, tableStyle). A few clauses restate the same idea — the placeholder-structure benefit is said twice ('only needs to fill in realistic values rather than guess the structure' after the earlier explanation) — but nothing is 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?

Despite having no output schema, the description names the one non-obvious response field (`inferredInputShape`) and fully describes the generated artifact, so an agent can call this correctly and explain results. Nothing material about this generator is left undocumented.

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% and the schema descriptions are already detailed, so the baseline is 3; the description earns extra credit by explaining what `tableStyle: true` actually produces (`every tc in cases` loop letting you add multiple input/expected pairs without duplicating assertions) and how `source` is consumed (AST walk to infer `input.*` shape). `v0Compatible` is left to the schema.

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?

The opening sentence states a specific verb and artifact: generate a `*_test.rego` skeleton from a policy, then immediately explains the mechanism (parse AST, one stub per non-test rule). This is unmistakably distinct from the `rego_test` sibling, which runs tests rather than generating them.

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?

It gives clear situational context: use it to scaffold tests for production rules, and existing `test_*`/`todo_test_*` rules are skipped so it is safe to re-run on a partially-tested policy. It also points at `rego_test varValues: true` as the companion for table-style stubs, though it never explicitly frames the generate-then-run workflow or states when a sibling like `rego_infer_input_schema` would be preferred.

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