Skip to main content
Glama

Run Rego tests across multiple roots

rego_test_multiroot

Runs OPA tests per root and aggregates results to avoid package conflicts when testing repositories with multiple independent namespaces. Supports explicit root lists or automatic leaf-root discovery.

Instructions

Run opa test once per root and aggregate results. Solves the package-conflict problem that occurs when opa test . is run on a repo with multiple independent package namespaces (OPA issue #4724). Two modes: explicit (supply root list with optional per-root include paths for shared libraries) and scan (auto-discover leaf test roots using the leaf rule -- a directory is a root only if it directly contains *_test.rego files and none of its eligible subdirectories do, preventing OPA's automatic recursion from double-running tests). Use sharedPaths in scan mode to add shared library directories to every root's invocation without including them in discovery. Coverage and threshold work per-root; overallCoveragePct is the mean across roots that have coverage data.

Tool call template

This tool declares no required parameters. Add optional parameters from the input schema as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {},
    "name": "rego_test_multiroot"
  }
}

Input Schema

NameRequiredDescriptionDefault
rootsNoExplicit list of test root directories. Use when roots are known upfront or when scan mode cannot determine the correct roots. Mutually exclusive with `scanDir`.
scanDirNoTop-level directory to scan for test roots. Uses the leaf rule: a directory is a root only if it directly contains `*_test.rego` files and none of its eligible subdirectories do. Mutually exclusive with `roots`.
verboseNoAdd the evaluation trace (`opa test -v`) to each failing or erroring test. Pass/fail for every test is reported without it. OPA traces passing tests too, which runs to megabytes, so those traces are dropped; over the response cap the rest go before any result does, and `tracesOmitted` counts them.
coverageNoAdd per-line coverage (`coverage`, `coveragePct`, and `overallCoveragePct` across roots) to the test results. Each root runs twice, once for the results and once for coverage. A root where a test fails or errors gets no coverage, and a `note` saying so: opa reports none for such a run.
maxDepthNoMaximum directory depth to scan. Default: 10. Only used with `scanDir`.
maxRootsNoMaximum number of test roots allowed. Returns INVALID_INPUT if scan finds more. Default: 50. Only used with `scanDir`.
thresholdNoMinimum coverage percentage required per root (0-100). A root whose tests pass below it gets `thresholdMet: false` and a COVERAGE_BELOW_THRESHOLD error. Implies `coverage`.
varValuesNoInclude local variable bindings in trace output (`--var-values`). Only useful with `verbose: true`.
runPatternNoRun only tests whose names match this regular expression (passed as `--run` to each root).
sharedPathsNoPaths added to every root's `opa test` invocation and excluded from auto-discovery. Use for shared library directories that all roots import from.
v0CompatibleNoRead the policy as Rego v0 (`--v0-compatible`), the syntax OPA used before 1.0: rules without `if`, partial sets as `deny[msg] { ... }`. Needed for a policy that has not been migrated, which OPA 1.x otherwise refuses to load. Where the tool also takes a query, the query is read as v0 too, with the future keywords imported so `in`, `every` and `some x in` still work in it.
ignorePatternsNoAdditional directory name patterns to skip during scan (e.g., ["vendor", "*.generated"]). Supports `*` wildcards. Only used with `scanDir`.
strictBuiltinErrorsNoReport a test as errored at its first built-in function error (`--strict-builtin-errors`, OPA 1.23 and later). Without it an erroring built-in, such as `to_number("ten")`, leaves its rule undefined, so a test that expects a deny can pass for that reason alone.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changedv0.12.0
    • addedInput schema / properties / strictBuiltinErrors
      Added value: +{
      +  "description": "Report a test as errored at its first built-in function error (`--strict-builtin-errors`, OPA 1.23 and later). Without it an erroring built-in, such as `to_number(\"ten\")`, leaves its rule undefined, so a test that expects a deny can pass for that reason alone.",
      +  "type": "boolean"
      +}
    • changedInput schema / properties / verbose / description
      Previous value: -"Emit per-test pass/fail details for each root."New value: +"Add the evaluation trace (`opa test -v`) to each failing or erroring test. Pass/fail for every test is reported without it. OPA traces passing tests too, which runs to megabytes, so those traces are dropped; over the response cap the rest go before any result does, and `tracesOmitted` counts them."
  2. Changed2 schema fields changedv0.9.1
    • changedInput schema / properties / coverage / description
      Previous value: -"Include per-line coverage data per root. Switches output to coverage-report mode: test record counts are not available, but `coverage`, `coveragePct`, and `overallCoveragePct` fields are populated."New value: +"Add per-line coverage (`coverage`, `coveragePct`, and `overallCoveragePct` across roots) to the test results. Each root runs twice, once for the results and once for coverage. A root where a test fails or errors gets no coverage, and a `note` saying so: opa reports none for such a run."
    • changedInput schema / properties / threshold / description
      Previous value: -"Minimum coverage percentage required per root (0-100). Roots below threshold have `thresholdMet: false` in their result. Implicitly enables coverage-report output mode."New value: +"Minimum coverage percentage required per root (0-100). A root whose tests pass below it gets `thresholdMet: false` and a COVERAGE_BELOW_THRESHOLD error. Implies `coverage`."
  3. Changed1 schema field changedv0.8.0
    • changedInput schema / properties / v0Compatible / description
      Previous value: -"Read the policy as Rego v0 (`--v0-compatible`), the syntax OPA used before 1.0: rules without `if`, partial sets as `deny[msg] { ... }`. Needed for a policy that has not been migrated, which OPA 1.x otherwise refuses to load."New value: +"Read the policy as Rego v0 (`--v0-compatible`), the syntax OPA used before 1.0: rules without `if`, partial sets as `deny[msg] { ... }`. Needed for a policy that has not been migrated, which OPA 1.x otherwise refuses to load. Where the tool also takes a query, the query is read as v0 too, with the future keywords imported so `in`, `every` and `some x in` still work in it."
  4. Changed1 schema field changedv0.7.0
    • addedInput schema / properties / v0Compatible
      Added value: +{
      +  "description": "Read the policy as Rego v0 (`--v0-compatible`), the syntax OPA used before 1.0: rules without `if`, partial sets as `deny[msg] { ... }`. Needed for a policy that has not been migrated, which OPA 1.x otherwise refuses to load.",
      +  "type": "boolean"
      +}
  5. Addedv0.1.17

TDQS

A4.5/5.0
Behavior5/5

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

Goes well beyond the sparse annotations (readOnlyHint=false, openWorldHint=true) by disclosing that coverage runs each root twice, that a failing root yields no coverage plus a `note`, that verbose traces are dropped past the response cap with `tracesOmitted` counting them, and that exceeding `maxRoots` returns INVALID_INPUT. These are exactly the execution traits an agent cannot infer from annotations or schema.

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 purpose and the two modes before detail; every sentence carries substantive information. It is dense and long-sentenced, but nothing is redundant filler.

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

Completeness4/5

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

For a 13-parameter tool with no output schema, the description covers mode selection, discovery rules, per-root coverage/threshold semantics, and aggregate fields like `overallCoveragePct`. Minor gaps remain, such as the overall response envelope for failures across roots, but the critical calling decisions are all supported.

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 the baseline is 3, but the description adds cross-parameter meaning the schema does not: `threshold` implies `coverage`, `maxDepth`/`maxRoots`/`ignorePatterns` only apply in scan mode, and `sharedPaths` is excluded from discovery rather than merely appended. That is genuine added semantics, not restatement.

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 resource (run `opa test` once per root and aggregate results) and frames the exact problem it solves: package-conflict from `opa test .` on repos with multiple independent namespaces. This clearly separates it from the single-invocation `rego_test` sibling without needing to name it.

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?

Distinguishes the two operating modes (`explicit` with a supplied root list, `scan` with the leaf rule) and explains when `sharedPaths` applies in scan mode. It never explicitly names `rego_test` or another sibling as the fallback for single-root runs, so the alternative selection is left to inference.

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