跳到正文
cccskills
免费在 GitHub 公开

rtk-tdd

Guide Rust development through test-driven development: write a failing test, implement enough code to pass, then refactor. Includes practical test patterns and final checks for formatting, static analysis, and test results.

中文简介正在准备中。当前显示英语简介。

原文查看原文说明

Enforces TDD (Red-Green-Refactor) for Rust development. Auto-triggers on implementation, testing, refactoring, and bug fixing tasks. Provides Rust-idiomatic testing patterns with anyhow/thiserror, cfg(test), and Arrange-Act-Assert workflow.

查看安装方法

适用场景

  • Adding Rust features with tests first
  • Reproducing bugs with failing tests before fixing them
  • Testing invalid inputs and error paths
  • Checking formatting, static analysis, and tests before committing

包含的文件(2)

  • SKILL.md2.9 KB
  • references/testing-patterns.md3.5 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Rust TDD Workflow

Three Laws of TDD

  1. Do NOT write production code without a failing test
  2. Write only enough test to fail (including compilation failure)
  3. Write only enough production code to pass the failing test

Cycle: RED (test fails) -> GREEN (minimum to pass) -> REFACTOR (cleanup, cargo test)

Red-Green-Refactor Steps

1. Write test in #[cfg(test)] mod tests of the SAME file
2. cargo test MODULE::tests::test_name  -- must FAIL (red)
3. Implement the minimum in the function
4. cargo test MODULE::tests::test_name  -- must PASS (green)
5. Refactor if needed, re-run cargo test (still green)
6. cargo fmt && cargo clippy --all-targets && cargo test  (final gate)

Never skip step 2. If the test passes immediately, it tests nothing.

Idiomatic Rust Test Patterns

PatternUsageWhen
Arrange-Act-AssertBase structure for every testAlways
assert_eq! / assert!Direct comparison / booleansDeterministic values
assert!(result.is_err())Error path testingInvalid inputs
Result<()> return typeTests with ? operatorFallible functions
#[should_panic]Expected panicInvariants, preconditions
tempfile::NamedTempFileFile/I/O testsFilesystem-dependent code

Patterns by Code Type

Code TypeTest PatternExample
Pure function (str -> str)Input literal -> assert outputassert_eq!(truncate("hello", 3), "...")
Parsing/filteringRaw string -> filter -> contains/not-containsassert!(filter(raw).contains("expected"))
Validation/securityBoundary inputs -> assert boolassert!(!is_valid("../etc/passwd"))
Error handlingBad input -> is_err()assert!(parse("garbage").is_err())
Struct/enum roundtripConstruct -> serialize -> deserialize -> eqassert_eq!(from_str(to_str(x)), x)

Naming Convention

test_{function}_{scenario}
test_{function}_{input_type}

Examples: test_truncate_edge_case, test_parse_invalid_input, test_filter_empty_string

When NOT to Use Pure TDD

  • Functions calling Command::new() -> test the parser, not the execution
  • std::process::exit() -> refactor to Result first, then test the Result
  • Direct I/O (SQLite, network) -> use tempfile/mock or test the pure logic separately
  • Main/CLI wiring -> covered by integration/smoke tests

Pre-Commit Gate

cargo fmt --all --check
cargo clippy --all-targets
cargo test

All 3 must pass. No exceptions. No #[allow(...)] without documented justification.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Simplify Rust code in RTK by replacing verbose loops, unnecessary copies, and excessive abstractions with common Rust patterns. Preserve behavior and project requirements, including error context, fallback handling, exit codes, and existing test modules.

中文简介正在准备中。当前显示英语简介。

  • Simplifying verbose loops and string construction
  • Removing unnecessary string copies
  • Reducing nested conditional and error handling code
rtk-ai/rtk8.4万2026年10月17日 更新

Choose Rust design patterns for RTK modules that process command output. Use concrete examples to structure configuration, prevent type mixups, manage parser states, and select abstractions suited to the task without adding unnecessary architectural complexity.

中文简介正在准备中。当前显示英语简介。

  • Planning the structure of a new command output filter
  • Preventing mixups between values with the same underlying type
  • Organizing configuration with many optional fields
rtk-ai/rtk8.4万2026年10月17日 更新

Organize open GitHub issues by category, risk, linked pull requests, duplicate candidates, and inactivity. Optionally analyze selected issues in depth, draft responses, and apply approved comments, labels, or closures to keep the backlog actionable.

中文简介正在准备中。当前显示英语简介。

  • Sorting a growing backlog of open issues
  • Checking whether suspected duplicate issues are truly duplicates
  • Prioritizing security risks and breaking changes
rtk-ai/rtk8.4万2026年10月17日 更新

pr-triage

免费

Sort open GitHub pull requests by change size, automated check results, conflicts, and inactivity. Review selected changes in detail, draft constructive feedback, and post comments after the user approves them.

中文简介正在准备中。当前显示英语简介。

  • Prioritizing a backlog of open pull requests
  • Finding overlapping changes and failing checks
  • Reviewing selected pull requests in detail
rtk-ai/rtk8.4万2026年10月17日 更新

Review GitHub issues and pull requests together to find duplicate work, security findings without fixes, and critical bugs without linked changes. Produce action tables and a dated report to support backlog reviews and sprint planning.

中文简介正在准备中。当前显示英语简介。

  • Reviewing issues and pull requests before a sprint
  • Finding pull requests that duplicate the same work
  • Identifying security findings without proposed fixes
rtk-ai/rtk8.4万2026年10月17日 更新

tdd-rust

免费

Develop Rust filters for RTK through tests written before implementation. Use real command output as test inputs, check output snapshots and unexpected inputs, verify a minimum reduction target, and complete formatting, linting, and test checks before finishing.

中文简介正在准备中。当前显示英语简介。

  • Adding a new RTK command filter
  • Checking filtered output against saved snapshots
  • Testing empty, malformed, or ANSI-colored input
rtk-ai/rtk8.4万2026年10月17日 更新

查看 rtk-ai 的全部技能

报告此技能的问题