Agent skill

RTK Filter TDD in Rust

by rtk-ai in rtk-ai/rtk

Enforces red-green-refactor for new RTK output filters in Rust, using real captured fixtures, snapshot tests with insta and token-savings assertions.

Apache-2.0Auto-check: notesTesting & QA

Install RTK Filter TDD in Rust

skills CLI
$ npx skills add rtk-ai/rtk --skill tdd-rust -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install rtk-ai/rtk tdd-rust --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/rtk-ai/rtk.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.claude/skills/tdd-rust .claude/skills/tdd-rust && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
tdd-rust
GitHub stars
83k
Token cost
~1.9k tokens
SKILL.md length
153 words
Files
1
Skills in repo
7
Repo updated
First seen
Licence
Apache-2.0

At a glance

Enforces red-green-refactor for new RTK output filters in Rust, using real captured fixtures, snapshot tests with insta and token-savings assertions.

  • Works in 6 steps: Real Fixture First → Write the Test (Red) → Minimum Implementation (Green) → …
  • Adding a new output filter to RTK
  • SKILL.md covers The Loop, Step 1: Real Fixture First, Step 2: Write the Test (Red) and Step 3: Minimum Implementation…, plus 7 more sections
  • Calls cargo, git and gh

What it does

The skill runs a strict TDD loop for RTK filter development. It starts from a real fixture, never synthetic data, captured from the actual command into tests/fixtures as a raw text file. Then it writes a failing test, implements the minimum code to pass, accepts a snapshot, wires the filter into main.rs and runs the quality gate of cargo fmt, cargo clippy and cargo test, with zero clippy warnings allowed.

Test patterns include arrange-act-assert, ANSI stripping, fallback behavior on unexpected input, and token savings at several sizes, where a large fixture must still reach at least 60% savings. The done checklist asks for a real fixture, a filter function returning a Result, an accepted insta snapshot, a savings test, and no panic on empty or malformed input.

When your agent uses it

  • Adding a new output filter to RTK
  • Writing snapshot tests for a filter with insta
  • Verifying that a filter meets the token savings target

Example prompts

  • “Add an RTK filter for docker ps output, test first with a real fixture.”
  • “Write the snapshot test for the new git status filter and accept it.”
  • “Check that the cargo test filter still saves at least 60% of tokens on a large fixture.”

Requirements

  • Rust with cargo and clippy
  • The insta snapshot tool
  • A checkout of the RTK repository
  • Pre-approved tools (allowed-tools): Read, Write, Edit, Bash

Workflow steps

6 steps, taken from the step headings in SKILL.md.

  1. Real Fixture First
  2. Write the Test (Red)
  3. Minimum Implementation (Green)
  4. Accept Snapshot
  5. Wire to main.rs (Integration)
  6. Quality Gate

What it can do on your machine

Read from SKILL.md and the folder at commit e0b2e85. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves these tools, so the agent can use them without asking each time:

    • Read
    • Write
    • Edit
    • Bash

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • cargo
    • git
    • gh

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use git and gh, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

RTK Filter TDD in Rust loads about 1.9k tokens when it runs. Until then it costs about 50 tokens; SKILL.md has 153 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~50
When it runs · the whole SKILL.md, loaded when a task matches
~1.9k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check: notes

The automated check noted patterns worth knowing about, such as sudo or a known installer.

  • NotePre-approves every shell command (allowed-tools: Bash)SKILL.md
    allowed-tools: Read, Write, Edit, Bash

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from rtk-ai/rtk at commit e0b2e85, republished under its Apache-2.0 licence (© rtk-ai). 153 words, ~1,885 tokens.

Download SKILL.mdSave it as .claude/skills/tdd-rust/SKILL.md (or your agent's skills folder).
name
tdd-rust
description
TDD workflow for RTK filter development. Red-Green-Refactor with Rust idioms. Real fixtures, token savings assertions, snapshot tests with insta. Auto-triggers on new filter implementation.
allowed-tools
Read, Write, Edit, Bash
triggers
new filter, implement filter, add command, write tests for, test coverage, fix failing test
effort
medium
tags
tdd, testing, rust, filters, snapshots, token-savings, rtk

RTK TDD Workflow

Enforce Red-Green-Refactor for all RTK filter development.

The Loop

1. RED   — Write failing test with real fixture
2. GREEN — Implement minimum code to pass
3. REFACTOR — Clean up, verify still passing
4. SAVINGS — Verify ≥60% token reduction
5. SNAPSHOT — Lock output format with insta

Step 1: Real Fixture First

Never write synthetic test data. Capture real command output:

bash
# Capture real output from the actual command
git log -20 > tests/fixtures/git_log_raw.txt
cargo test 2>&1 > tests/fixtures/cargo_test_raw.txt
cargo clippy 2>&1 > tests/fixtures/cargo_clippy_raw.txt
gh pr view 42 > tests/fixtures/gh_pr_view_raw.txt

# For commands with ANSI codes — capture as-is
script -q /dev/null cargo test 2>&1 > tests/fixtures/cargo_test_ansi_raw.txt

Fixture naming: tests/fixtures/<command>_raw.txt

Step 2: Write the Test (Red)

rust
#[cfg(test)]
mod tests {
    use super::*;
    use insta::assert_snapshot;

    fn count_tokens(s: &str) -> usize {
        s.split_whitespace().count()
    }

    // Test 1: Output format (snapshot)
    #[test]
    fn test_filter_output_format() {
        let input = include_str!("../tests/fixtures/mycmd_raw.txt");
        let output = filter_mycmd(input).expect("filter should not fail");
        assert_snapshot!(output);
    }

    // Test 2: Token savings ≥60%
    #[test]
    fn test_token_savings() {
        let input = include_str!("../tests/fixtures/mycmd_raw.txt");
        let output = filter_mycmd(input).expect("filter should not fail");

        let input_tokens = count_tokens(input);
        let output_tokens = count_tokens(&output);
        let savings = 100.0 * (1.0 - output_tokens as f64 / input_tokens as f64);

        assert!(
            savings >= 60.0,
            "Expected ≥60% token savings, got {:.1}% ({} → {} tokens)",
            savings, input_tokens, output_tokens
        );
    }

    // Test 3: Edge cases
    #[test]
    fn test_empty_input() {
        let result = filter_mycmd("");
        assert!(result.is_ok());
        // Empty input = empty output OR passthrough, never panic
    }

    #[test]
    fn test_malformed_input() {
        let result = filter_mycmd("not valid command output\nrandom text\n");
        // Must not panic — either filter best-effort or return input unchanged
        assert!(result.is_ok());
    }
}

Run: cargo test → should fail (function doesn't exist yet).

Step 3: Minimum Implementation (Green)

rust
// src/mycmd_cmd.rs

use anyhow::{Context, Result};
use regex::Regex;
use std::sync::LazyLock;

static ERROR_RE: LazyLock<Regex> =
    LazyLock::new(|| Regex::new(r"^error").unwrap());

pub fn filter_mycmd(input: &str) -> Result<String> {
    if input.is_empty() {
        return Ok(String::new());
    }

    let filtered: Vec<&str> = input.lines()
        .filter(|line| ERROR_RE.is_match(line))
        .collect();

    Ok(filtered.join("\n"))
}

Run: cargo test → green.

Step 4: Accept Snapshot

bash
# First run creates the snapshot
cargo test test_filter_output_format

# Review what was captured
cargo insta review
# Press 'a' to accept

# Snapshot saved to src/snapshots/mycmd_cmd__tests__test_filter_output_format.snap

Step 5: Wire to main.rs (Integration)

rust
// src/main.rs
mod mycmd_cmd;

#[derive(Subcommand)]
pub enum Commands {
    // ... existing commands ...
    Mycmd(MycmdArgs),
}

// In match:
Commands::Mycmd(args) => mycmd_cmd::run(args),
rust
// src/mycmd_cmd.rs — add run() function
pub fn run(args: MycmdArgs) -> Result<()> {
    let output = execute_command("mycmd", &args.to_vec())
        .context("Failed to execute mycmd")?;

    let filtered = filter_mycmd(&output.stdout)
        .unwrap_or_else(|e| {
            eprintln!("rtk: filter warning: {}", e);
            output.stdout.clone()
        });

    tracking::record("mycmd", &output.stdout, &filtered)?;
    print!("{}", filtered);

    if !output.status.success() {
        std::process::exit(output.status.code().unwrap_or(1));
    }
    Ok(())
}

Step 6: Quality Gate

bash
cargo fmt --all && cargo clippy --all-targets && cargo test

All 3 must pass. Zero clippy warnings.

Arrange-Act-Assert Pattern

rust
#[test]
fn test_filters_only_errors() {
    // Arrange
    let input = "info: starting build\nerror[E0001]: undefined\nwarning: unused\n";

    // Act
    let output = filter_mycmd(input).expect("should succeed");

    // Assert
    assert!(output.contains("error[E0001]"), "Should keep error lines");
    assert!(!output.contains("info:"), "Should drop info lines");
    assert!(!output.contains("warning:"), "Should drop warning lines");
}

RTK-Specific Test Patterns

Test ANSI stripping
rust
#[test]
fn test_strips_ansi_codes() {
    let input = "\x1b[32mSuccess\x1b[0m\n\x1b[31merror: failed\x1b[0m\n";
    let output = filter_mycmd(input).expect("should succeed");
    assert!(!output.contains("\x1b["), "ANSI codes should be stripped");
    assert!(output.contains("error: failed"), "Content should be preserved");
}
Test fallback behavior
rust
#[test]
fn test_filter_handles_unexpected_format() {
    // Give it something completely unexpected
    let input = "completely unexpected\x00binary\xff data";
    // Should not panic — returns Ok() with either empty or passthrough
    let result = filter_mycmd(input);
    assert!(result.is_ok(), "Filter must not panic on unexpected input");
}
Test savings at multiple sizes
rust
#[test]
fn test_savings_large_output() {
    // 1000-line fixture → must still hit ≥60%
    let large_input: String = (0..1000)
        .map(|i| format!("info: processing item {}\n", i))
        .collect();
    let output = filter_mycmd(&large_input).expect("should succeed");

    let savings = 100.0 * (1.0 - count_tokens(&output) as f64 / count_tokens(&large_input) as f64);
    assert!(savings >= 60.0, "Large output savings: {:.1}%", savings);
}

What "Done" Looks Like

Checklist before moving on:

  • tests/fixtures/<cmd>_raw.txt — real command output
  • filter_<cmd>() function returns Result<String>
  • Snapshot test passes and accepted via cargo insta review
  • Token savings test: ≥60% verified
  • Empty input test: no panic
  • Malformed input test: no panic
  • run() function with fallback pattern
  • Registered in main.rs Commands enum
  • cargo fmt --all && cargo clippy --all-targets && cargo test — all green

Never Do This

rust
// ❌ Synthetic fixture data
let input = "fake error: something went wrong";  // Not real cargo output

// ❌ Missing savings test
#[test]
fn test_filter() {
    let output = filter_mycmd(input);
    assert!(!output.is_empty());  // No savings verification
}

// ❌ unwrap() in production code
let filtered = filter_mycmd(input).unwrap();  // Panic in prod

// ❌ Regex inside the filter function
fn filter_mycmd(input: &str) -> Result<String> {
    let re = Regex::new(r"^error").unwrap();  // Recompiles every call
    ...
}

© rtk-ai, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .claude/skills/tdd-rust of rtk-ai/rtk.

Open the folder on GitHubat commit e0b2e85

Compare with similar skills

RTK Filter TDD in Rust next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

RTK Filter TDD in Rust compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
RTK Filter TDD in Rust this skillrtk-ai/rtk83k—~1.9kAutomated safety check: NotesApache-2.0
Jest Testing PatternsChrisWiles/claude-code-showcase6.1k7 repos~1.5kAutomated safety check: PassNone
Testingstatic-web-server/static-web-server2.4k—~1.5kAutomated safety check: PassApache-2.0
Rust Testingkurealnum/dotfiles2906 repos~2.9kAutomated safety check: PassNone
Agent-Core Python TestingopenJiuwen-ai/agent-core441—~2.3kAutomated safety check: PassApache-2.0
Godot Testing Patternsthedivergentai/GD-Agentic-Skills803—~2.9kAutomated safety check: PassLGPL-3.0

Similar skills

  • Jest Testing Patterns

    ChrisWiles/claude-code-showcase

    Jest patterns for React Native style tests: TDD discipline, mock factory functions, module and GraphQL hook mocking, custom render helpers and anti-patterns to avoid.

    6.1k GitHub starsUsed in 7 repos~1.5k tokens
    Testing & QAAuto-check passed
  • Testing

    static-web-server/static-web-server

    Write or review tests for the Static Web Server (SWS) project — unit tests, integration tests, test fixtures, and mocking strategies

    2.4k GitHub stars~1.5k tokensUpdated yesterday
    Testing & QAAuto-check passed
  • Rust Testing

    kurealnum/dotfiles

    Rust testing patterns including unit tests, integration tests, async testing, property-based testing, mocking, and coverage.

    290 GitHub starsUsed in 6 repos~2.9k tokens
    Testing & QAAuto-check passed
  • Agent-Core Python Testing

    openJiuwen-ai/agent-core

    Pytest patterns for the agent-core codebase: a red-green-refactor workflow, conftest fixtures, custom marks, monkeypatch and patch mocking, and async tests.

    441 GitHub stars~2.3k tokensUpdated 7 days ago
    Testing & QAAuto-check passed
  • Godot Testing Patterns

    thedivergentai/GD-Agentic-Skills

    Expert testing decision trees for GdUnit4: unit vs scene vs CI gates, headless runners, snapshots, and mock networks.

    803 GitHub stars~2.9k tokensUpdated 28 days ago
    Testing & QAAuto-check passed
  • MoAI TDD Workflow

    modu-ai/moai-adk

    Drives test-first development through the RED, GREEN, REFACTOR cycle, with a config switch that selects between TDD and a DDD workflow for existing code.

    1.2k GitHub stars~3.1k tokensUpdated today
    Testing & QAAuto-check passed

More from rtk-ai/rtk

  • Enforces red-green-refactor for Rust work, with idiomatic test patterns, a naming convention and a pre-commit gate of cargo fmt, clippy and test.

    83k GitHub stars~753 tokensUpdated today
    Auto-check: notes
  • Describes seven Rust design patterns for the RTK CLI filter modules, with when to use each, RTK examples, and notes on when a pattern is overkill.

    83k GitHub stars~1.9k tokensUpdated today
    Auto-check passed
  • Reviews RTK's Rust code for over-engineering and verbose patterns, applying idioms like iterator chains and early returns while protecting a specific list of constraints from being simplified away.

    83k GitHub stars~1.1k tokensUpdated today
    Auto-check passed
  • Audits open GitHub issues, categorizes them, flags duplicates and linked PRs in three phases, with optional deep analysis and comments posted only after validation.

    83k GitHub stars~3k tokensUpdated today
    Auto-check: notes
  • PR Triage

    rtk-ai/rtk

    Audits a repository's open pull requests, deep-reviews chosen ones and drafts review comments that are only posted after you approve them.

    83k GitHub stars~2.5k tokensUpdated today
    Auto-check: notes
  • Runs issue triage and PR triage in parallel, then cross-analyzes the results to flag duplicate coverage, security gaps, P0 issues with no PR, and PR conflicts.

    83k GitHub stars~1.6k tokensUpdated today
    Auto-check: notes

Works with

Questions about RTK Filter TDD in Rust

What does RTK Filter TDD in Rust do?

Enforces red-green-refactor for new RTK output filters in Rust, using real captured fixtures, snapshot tests with insta and token-savings assertions. The skill runs a strict TDD loop for RTK filter development. It starts from a real fixture, never synthetic data, captured from the actual command into tests/fixtures as a raw text file.

When should I use RTK Filter TDD in Rust?

RTK Filter TDD in Rust fits situations like: adding a new output filter to RTK; writing snapshot tests for a filter with insta; verifying that a filter meets the token savings target.

How do I install RTK Filter TDD in Rust in Claude Code?

Run `npx skills add rtk-ai/rtk --skill tdd-rust -a claude-code`. Or copy the skill folder (.claude/skills/tdd-rust in rtk-ai/rtk) into .claude/skills/tdd-rust in your project. Claude Code loads it when a task matches its description.

How do I install RTK Filter TDD in Rust in Codex?

Run `npx skills add rtk-ai/rtk --skill tdd-rust -a codex`. Or copy the skill folder (.claude/skills/tdd-rust in rtk-ai/rtk) into .agents/skills/tdd-rust in your project. Codex loads it when a task matches its description.

Can I use RTK Filter TDD in Rust in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add rtk-ai/rtk --skill tdd-rust -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/tdd-rust, .gemini/skills/tdd-rust, .github/skills/tdd-rust and .opencode/skills/tdd-rust in your project.

What does RTK Filter TDD in Rust need to run?

Going by SKILL.md and its folder, RTK Filter TDD in Rust needs the command-line tools its instructions call (cargo, git and gh). Our summary lists: Rust with cargo and clippy; The insta snapshot tool; A checkout of the RTK repository. Its frontmatter pre-approves these tools: Read, Write, Edit, Bash.

Does RTK Filter TDD in Rust access the network?

SKILL.md contains no URLs. Its commands use git and gh, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is RTK Filter TDD in Rust safe to install?

Our automated static check of SKILL.md found notes only (pre-approves every shell command (allowed-tools: bash)), nothing it rates as a warning. It is not a guarantee. Review the folder before installing.

What licence does RTK Filter TDD in Rust use?

RTK Filter TDD in Rust is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does RTK Filter TDD in Rust use?

About 1.9k tokens (SKILL.md is roughly 7.5k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to RTK Filter TDD in Rust?

Skills that share tags, products or a category with RTK Filter TDD in Rust: Jest Testing Patterns (ChrisWiles/claude-code-showcase, 6.1k stars), Testing (static-web-server/static-web-server, 2.4k stars), Rust Testing (kurealnum/dotfiles, 290 stars) and Agent-Core Python Testing (openJiuwen-ai/agent-core, 441 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains RTK Filter TDD in Rust?

rtk-ai (a GitHub organization) maintains it in rtk-ai/rtk, which has 82,568 GitHub stars. The repository holds 7 skills in this directory. The repository was last updated on October 7, 2026.

Source: rtk-ai/rtk on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.