home / skills / redisearch / redisearch / write-rust-tests

write-rust-tests skill

/.skills/write-rust-tests

This skill helps you write robust Rust tests for correctness of code, covering public APIs, edge cases, and error paths across crates.

npx playbooks add skill redisearch/redisearch --skill write-rust-tests

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
1.7 KB
---
name: write-rust-tests
description: Write Rust tests to verify correctness of Rust code.
---

# Write Rust Tests

Write new Rust tests for Rust code.

## Arguments
- `<path>`: Path to the Rust crate or file.
- `<path 1> <path 2>`: Multiple crate/file paths.

If a path doesn't include `src/`, assume it to be in the `src/redisearch_rs` directory. E.g. `numeric_range_tree` becomes `src/redisearch_rs/numeric_range_tree`.
If a path points to a directory, consider all Rust files in that directory.

## Guidelines

The generated tests must follow the guidelines outlined in [/rust-tests-guidelines](../rust-tests-guidelines/SKILL.md).

## What to test

Ensure that all public APIs are tested thoroughly, including edge cases, error conditions and branches.
Use [`/check-rust-coverage`](../check-rust-coverage/SKILL.md) to determine which lines are not covered by tests.

## Avoiding redundant tests

Before writing each test, explicitly identify which branch or code path it will cover that no existing test already covers. An uncovered line is not sufficient justification — ask *why* it is uncovered and whether it is reachable through an already-tested entry point.

Two tests are redundant if they exercise the same set of branches in the code under test. Differing only in input values that don't change control flow is not a distinct scenario.

Do not write standalone tests for:
- **Trivial trait delegations** — `Default`, `From`, or similar trait impls that are single-line delegations to an already-tested constructor, since they will be covered transitively.

After adding tests, double check that every new test covers at least one branch that no other test (existing or new) covers. Remove any that don't.

Overview

This skill writes Rust tests to verify correctness of Rust code in the project. It generates focused, non-redundant tests that exercise public APIs, edge cases, error conditions, and uncovered branches. Tests follow the project's testing guidelines and aim to increase meaningful coverage.

How this skill works

Provide one or more crate or file paths and the skill locates the corresponding Rust source (paths without src/ are assumed under src/redisearch_rs). If a path is a directory, it considers all Rust files inside. It inspects current tests and coverage reports to identify uncovered branches, then generates tests that cover distinct control flows without duplicating existing coverage.

When to use it

  • Add tests for new public functions, types, or methods to validate behavior and error handling.
  • Increase coverage on complex branches, edge conditions, or previously uncovered logic paths.
  • Validate interactions for indexing, full-text, vector search, or spatial features in the engine code.
  • Prevent regressions after refactors by adding tests that exercise tricky control flow.
  • Create tests for public API surface that other modules or bindings depend on.

Best practices

  • Target public APIs and ensure each new test covers at least one branch not covered by existing tests.
  • Before writing a test, explicitly state which branch or code path it will exercise and why that path is reachable.
  • Avoid redundant tests: do not add tests that only vary values without changing control flow.
  • Skip trivial single-line delegations (e.g., simple From/Default passthroughs) unless they exercise unique behavior.
  • Use the coverage checker to guide test selection, focusing on reachable, meaningful branches rather than raw line counts.

Example use cases

  • Generate tests for a numeric range tree to validate boundary conditions and error paths when ranges overlap or are invalid.
  • Add tests for inverted-index tokenization edge cases, including empty tokens and punctuation handling.
  • Create tests for spatial indexing routines to ensure correct behavior for points on the edge of bounding boxes.
  • Write tests for vector similarity queries to validate distance calculations, k-NN edge cases, and empty-result handling.
  • Cover aggregator functions and reduce paths that are only exercised under specific configuration flags.

FAQ

How do I specify a file path?

Pass either a full path or a module name; names without src/ are resolved under src/redisearch_rs. Directories include all Rust files inside.

What counts as a redundant test?

A test is redundant if it exercises the same set of branches as another test. Changing input values without altering control flow is not a distinct scenario.