Skip to main content

Overview

RTK provides token-optimized test runners for multiple ecosystems. All test commands achieve 90%+ token savings by showing only failures while preserving:
  • Exit codes for CI/CD
  • Failure details (stack traces, assertions)
  • Test counts and duration
  • Full output via tee recovery

Supported Test Runners

Cargo

rtk cargo test - Rust tests via cargo

Vitest

rtk vitest - JavaScript/TypeScript via Vitest

Pytest

rtk pytest - Python tests via pytest

Go

rtk go test - Go tests with NDJSON streaming

rtk test (Generic)

Generic test runner wrapper that filters any test command.

Usage

Examples

Features

  • Failures only: Skips passing tests
  • Stack traces: Preserves failure details
  • Counts: Shows passed/failed/skipped
  • Tee recovery: Full output saved to file

Implementation

From src/runner.rs:run_test():
  • Executes command via shell
  • Parses stdout/stderr for test results
  • Filters out passing tests
  • Preserves exit codes

rtk cargo test

Rust test runner via cargo.

Usage

Options

  • --lib: Test library only
  • --bins: Test binaries
  • --tests: Test integration tests
  • --doc: Test documentation
  • --all-features: Enable all features
  • --no-fail-fast: Don’t stop on first failure

Examples

Token Savings

rtk vitest

JavaScript/TypeScript test runner via Vitest.

Usage

Commands

  • run: Run tests once (default)
  • watch: Watch mode (passthrough)
  • dev: Dev mode (passthrough)

Examples

Features

  • JSON parsing: Parses --reporter=json output
  • ANSI stripping: Removes color codes
  • Package manager detection: Auto-detects pnpm/npm/yarn
  • Tee recovery: Saves full output on failure

Implementation

From src/vitest_cmd.rs:VitestParser:
  • Forces --reporter=json for structured output
  • Parses JSON line-by-line (handles pnpm prefixes)
  • Extracts failures with stack traces
  • Falls back to regex if JSON parsing fails

rtk pytest

Python test runner via pytest.

Usage

Options

  • -v: Verbose (passthrough)
  • -k <pattern>: Run tests matching pattern
  • -x: Stop on first failure
  • --tb=short: Short traceback (default)

Examples

Features

  • State machine parser: Parses text output (no JSON needed)
  • Auto-flags: Forces --tb=short -q for compact output
  • Import errors: Preserves stderr for import failures
  • Tee recovery: Saves full output on failure

Implementation

From src/pytest_cmd.rs:filter_pytest_output():
  • State machine: Header → TestProgress → Failures → Summary
  • Extracts failure sections with traceback
  • Filters out passing tests (. dots)
  • Preserves exit codes

rtk go test

Go test runner with NDJSON streaming.

Usage

Flags

  • -v: Verbose (passthrough)
  • -run <regexp>: Run tests matching pattern
  • -short: Run short tests only
  • -timeout <duration>: Test timeout

Examples

Features

  • NDJSON parsing: Parses -json output line-by-line
  • Streaming: Handles interleaved package events
  • Build errors: Captures build failures separately
  • Tee recovery: Saves full output on failure

Implementation

From src/go_cmd.rs:filter_go_test_json():
  • Forces -json flag for structured output
  • Parses GoTestEvent NDJSON structs
  • Groups by package (handles multiple packages)
  • Tracks pass/fail/skip counts per package
  • Preserves exit codes

Tee Output Recovery

All test commands use tee recovery to save full output on failure.

How It Works

  1. Test runs and produces output
  2. RTK filters to failures only
  3. If exit code != 0, saves raw output to ~/.local/share/rtk/tee/
  4. Prints hint: [full output: ~/.../1707753600_cargo_test.log]
  5. LLM reads file instead of re-running test

Configuration

From ~/.config/rtk/config.toml:

Environment Overrides

CI/CD Integration

All test commands preserve exit codes:
Tests fail the CI pipeline if any test fails (exit code preserved).

Token Savings Summary

Next Steps

JavaScript

Modern JS/TS stack tools

Python

Python development tools