feat: Phase 1 robot mode + forgiving parser test suite #8

Open
opened 2026-04-24 03:04:54 +02:00 by root · 0 comments
Owner

Problem Statement

Phase 1 of the session-search spec (Robot Mode + Forgiving Parser) has shipping code in crates/terraphim_agent/src/robot/ and crates/terraphim_agent/src/forgiving/, but no dedicated test suite covers the new surfaces. Task 1.6 is unchecked. Without tests, typo correction, alias expansion, exit-code mapping, and JSON output shape can regress silently as later tasks land.

Current State

  • ForgivingParser in forgiving/parser.rs has inline unit tests for the bare parser but no integration tests that exercise the REPL dispatcher.
  • robot/output.rs, robot/exit_codes.rs, and robot/budget.rs have minimal or no assertions on JSON shape or exit-code mapping.
  • No golden-file / snapshot tests exist for --robot --format json output.
  • The repl_integration_tests harness in crates/terraphim_agent/tests/ does not cover robot mode.

Acceptance Criteria

  • Unit tests for ForgivingParser::parse: exact match, alias expansion, typo correction (edit distance 1 and 2), unknown command, suggestion list.
  • Unit tests for RobotFormatter: JSON schema, compact variant, description/body field presence, error payload shape.
  • Unit tests for ExitCode mapping: success (0), usage error (64), soft limit (2), internal error (70).
  • Integration test in tests/repl_robot_tests.rs that runs the REPL with --robot --format json against a fixture haystack and asserts the full envelope.
  • Snapshot test (via insta or plain include_str!) for representative JSON payloads: search hit, search miss, alias-expanded command, auto-corrected command.
  • All new tests pass under cargo test -p terraphim_agent --features repl-full.
  • cargo clippy -p terraphim_agent --features repl-full --tests -- -D warnings passes.
  • Coverage report (cargo llvm-cov -p terraphim_agent --features repl-full -- robot forgiving) shows ≥ 80 % line coverage for robot/ and forgiving/ modules.

Proposed Approach

  1. Create crates/terraphim_agent/src/forgiving/parser.rs test module additions covering the four ParseResult variants explicitly.
  2. Create crates/terraphim_agent/tests/repl_robot_tests.rs using a seeded in-memory haystack fixture; exercise ReplHandler end-to-end in robot mode.
  3. Add snapshot fixtures under crates/terraphim_agent/tests/fixtures/robot/ — one file per scenario.
  4. Add #[cfg(test)] helpers in robot/mod.rs for building minimal RobotResponse objects.
  5. Ensure the tests run cleanly offline — no network, no LLM calls.

Dependencies

Depends on #4 (ForgivingParser wiring) — integration tests need the dispatcher to actually route through the parser before they can verify auto-correction.

Verification

cargo test -p terraphim_agent --features repl-full robot
cargo test -p terraphim_agent --features repl-full forgiving
cargo test -p terraphim_agent --features repl-full --test repl_robot_tests
cargo clippy -p terraphim_agent --features repl-full --tests -- -D warnings
cargo llvm-cov -p terraphim_agent --features repl-full -- robot forgiving

Scope

~300 LOC of test code + ~6 snapshot fixtures. No production code touched. Single PR.

Upstream: Implements Task 1.6 of docs/specifications/terraphim-agent-session-search-tasks.md for terraphim/terraphim-ai.

## Problem Statement Phase 1 of the session-search spec (Robot Mode + Forgiving Parser) has shipping code in `crates/terraphim_agent/src/robot/` and `crates/terraphim_agent/src/forgiving/`, but no dedicated test suite covers the new surfaces. Task 1.6 is unchecked. Without tests, typo correction, alias expansion, exit-code mapping, and JSON output shape can regress silently as later tasks land. ## Current State - `ForgivingParser` in `forgiving/parser.rs` has inline unit tests for the bare parser but no integration tests that exercise the REPL dispatcher. - `robot/output.rs`, `robot/exit_codes.rs`, and `robot/budget.rs` have minimal or no assertions on JSON shape or exit-code mapping. - No golden-file / snapshot tests exist for `--robot --format json` output. - The `repl_integration_tests` harness in `crates/terraphim_agent/tests/` does not cover robot mode. ## Acceptance Criteria - [ ] Unit tests for `ForgivingParser::parse`: exact match, alias expansion, typo correction (edit distance 1 and 2), unknown command, suggestion list. - [ ] Unit tests for `RobotFormatter`: JSON schema, compact variant, description/body field presence, error payload shape. - [ ] Unit tests for `ExitCode` mapping: success (0), usage error (64), soft limit (2), internal error (70). - [ ] Integration test in `tests/repl_robot_tests.rs` that runs the REPL with `--robot --format json` against a fixture haystack and asserts the full envelope. - [ ] Snapshot test (via `insta` or plain `include_str!`) for representative JSON payloads: search hit, search miss, alias-expanded command, auto-corrected command. - [ ] All new tests pass under `cargo test -p terraphim_agent --features repl-full`. - [ ] `cargo clippy -p terraphim_agent --features repl-full --tests -- -D warnings` passes. - [ ] Coverage report (`cargo llvm-cov -p terraphim_agent --features repl-full -- robot forgiving`) shows ≥ 80 % line coverage for `robot/` and `forgiving/` modules. ## Proposed Approach 1. Create `crates/terraphim_agent/src/forgiving/parser.rs` test module additions covering the four `ParseResult` variants explicitly. 2. Create `crates/terraphim_agent/tests/repl_robot_tests.rs` using a seeded in-memory haystack fixture; exercise `ReplHandler` end-to-end in robot mode. 3. Add snapshot fixtures under `crates/terraphim_agent/tests/fixtures/robot/` — one file per scenario. 4. Add `#[cfg(test)]` helpers in `robot/mod.rs` for building minimal `RobotResponse` objects. 5. Ensure the tests run cleanly offline — no network, no LLM calls. ## Dependencies Depends on #4 (ForgivingParser wiring) — integration tests need the dispatcher to actually route through the parser before they can verify auto-correction. ## Verification ```bash cargo test -p terraphim_agent --features repl-full robot cargo test -p terraphim_agent --features repl-full forgiving cargo test -p terraphim_agent --features repl-full --test repl_robot_tests cargo clippy -p terraphim_agent --features repl-full --tests -- -D warnings cargo llvm-cov -p terraphim_agent --features repl-full -- robot forgiving ``` ## Scope ~300 LOC of test code + ~6 snapshot fixtures. No production code touched. Single PR. Upstream: Implements Task 1.6 of `docs/specifications/terraphim-agent-session-search-tasks.md` for terraphim/terraphim-ai.
root added a new dependency 2026-04-24 03:05:03 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Reference: terraphim/agent-tasks#8