Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Agent Mode

testaruda’s agent mode (--agent flag on select) produces structured JSON designed for consumption by LLM coding agents and automated tooling. This document explains the output format and how to interpret each field.

Usage

testaruda select --agent [--base main] [--head HEAD] [--files <list>]

The --agent flag conflicts with --json and --pre-edit. Agent mode also implies --ordering deterministic to ensure stable output across runs (TIA-AGENT-007).

Output Format

Agent output is a single JSON object on stdout with the following top-level fields:

FieldTypeDescription
formatstringProtocol version identifier. Currently "testaruda-agent-v1".
summaryobjectSummary statistics (see below).
changed_unitsarrayContent units that changed in the code change set.
selectedarrayTests selected by the engine, with reason chains.
skippedarrayCandidate tests that were not selected, with exclusion reasons.
coverage_gapsarraySymbols with no covering test (coverage gaps).

Summary (summary)

FieldTypeDescription
changed_countintegerNumber of content units that changed.
selected_countintegerNumber of tests selected to run.
candidate_countintegerTests with direct stored dependencies on the changed units. Safety fallbacks can make this smaller than selected_count.
has_coverage_gapsbooleanWhether any coverage gaps were detected.

Changed Unit (changed_units[])

Each changed unit describes a file or symbol that the agent is proposing to modify.

FieldTypeDescription
idintegerInternal store identifier.
pathstringFile path relative to the project root.
symbolstring or nullSymbol name (function, class, etc.) if applicable.
kindstringContent kind (e.g., "source", "config", "test").
unresolvedbooleanTrue if the unit had no dependency data (cold-start or missing file).

Selected Test (selected[])

Each selected test includes a reason chain that explains why the engine chose it.

FieldTypeDescription
idintegerInternal store identifier.
node_idstring or nullAdapter-assigned human-readable test identifier (e.g., tests/test_model.py::test_model).
confidencenumberSelection confidence, 0.0–1.0.
distanceinteger or nullMinimum number of dependency hops from a changed unit.
always_runbooleanWhether this test is a safety fallback: confidence is 1.0 and no dependency distance is available.
quarantinedbooleanWhether the test runs for monitoring but is excluded from pass/fail trust calculations.
fallback_reasonstring or nullHuman-readable explanation for why the test is in always-run state. Present when always_run is true.
reason_chainarrayList of witness edges that form the selection reason.

Reason Edge (reason_chain[])

Each edge explains one step in the dependency chain.

FieldTypeDescription
content_unit_idintegerStore ID of the content unit that connects to this test.
originstringDependency origin: "static" (code import), "runtime" (execution trace), or "manual" (user-defined).
pathstring or nullFile path of the content unit (if resolved from store).

Skipped Test (skipped[])

Tests that were candidates (they import from changed units) but were not deemed affected.

FieldTypeDescription
idintegerInternal store identifier.
node_idstring or nullHuman-readable test identifier.
exclusion_reasonstringWhy the test was excluded (e.g., “no transitive path to changed units”).

Coverage Gap (coverage_gaps[])

Symbols that changed but no test covers them (TIA-AGENT-006).

FieldTypeDescription
symbolstringSymbol (function, class) that changed.
filestringFile path where the symbol is defined.
changed_unit_idintegerStore ID of the changed content unit.

Design Decisions

  1. Versioned format string — The format field allows future format changes without breaking existing consumers. Agents should check it and reject unknown versions.

  2. Reason chains — Each selected test carries a reason_chain that traces back to changed units. This enables agents to make targeted decisions: “test_user_model changed because it imports User from src/models.py which you modified”.

  3. Coverage gaps — Gaps alert the agent to untested changed code, so the agent can add tests or note the risk in its response.

  4. Skipped tests — When an agent modifies a widely-imported utility, the engine may exclude transitive dependents with zero distance. The exclusion_reason explains why.

Error Handling

If the store has not been initialized, the agent receives:

Error: Store has not been initialized. Run `testaruda init` first.

If the change set cannot be computed (e.g., invalid git ref), the agent receives a descriptive error on stderr and a non-zero exit code.

Pre-Edit Mode

The --pre-edit flag (TIA-AGENT-005) emits a simpler JSON format for proposed (not yet committed) changes:

testaruda select --pre-edit [--files <list>]

Output format: testaruda-pre-edit-v1 with changed_files and selected_tests arrays plus summary stats. Its contract is published in schemas/pre-edit-output-v1.json. The full agent-mode contract is published separately in schemas/agent-output.schema.json (see docs/research/schemas/).