# How to Run Tests for a Specific OpenLogi Crate: A Complete Guide

> Learn how to run tests for a specific OpenLogi crate using the cargo test -p command. This guide shows you how to target individual crates efficiently.

- Repository: [Xuan Zhang/OpenLogi](https://github.com/AprilNEA/OpenLogi)
- Tags: how-to-guide
- Published: 2026-08-22

---

**To run tests for a specific OpenLogi crate, use the `cargo test -p <crate-name>` command from the workspace root, which limits execution to the selected package while leaving other crates untouched.**

OpenLogi is organized as a Cargo workspace containing multiple crates such as `openlogi-core`, `openlogi-agent`, and `openlogi-hid`. When contributing to this repository, you often need to verify changes in isolation without waiting for the entire workspace test suite to complete. The workspace configuration in [`Cargo.toml`](https://github.com/AprilNEA/OpenLogi/blob/main/Cargo.toml) defines these member crates, allowing you to target specific packages using Cargo's built-in flags.

## Understanding the OpenLogi Workspace Structure

OpenLogi follows a monorepo architecture where individual components live as separate crates under the `crates/` directory. Each directory name corresponds to the package name used in Cargo commands. According to the repository's guidance in [`AGENTS.md`](https://github.com/AprilNEA/OpenLogi/blob/main/AGENTS.md) (line 77), this structure enables **targeted testing** through the `-p` (package) flag, ensuring fast feedback loops during development.

## Running Tests for a Single Crate

### Basic Syntax

The fundamental command pattern follows Cargo's standard package selection syntax:

```bash
cargo test -p <crate-name>

```

This instructs Cargo to build and test only the specified package and its dependencies, ignoring other workspace members. For example, to test the core agent functionality, you would execute:

```bash
cargo test -p openlogi-agent-core

```

### Step-by-Step Instructions

1. **Open a terminal at the repository root** – All Cargo commands must be executed from the workspace root where the top-level [`Cargo.toml`](https://github.com/AprilNEA/OpenLogi/blob/main/Cargo.toml) resides.

2. **Identify the crate name** – Verify the exact package name by checking the `crates/` directory or the [`Cargo.toml`](https://github.com/AprilNEA/OpenLogi/blob/main/Cargo.toml) workspace member list.

3. **Run the tests** – Execute `cargo test -p <crate>` to launch all unit and integration tests within that crate.

4. **Optional filtering** – Append a test name pattern after the crate specification to run only matching tests (e.g., `cargo test -p openlogi-agent-core dpi`).

5. **Verify the result** – Cargo outputs a test summary specific to the selected crate, confirming that other crates remain untouched.

## Filtering Tests Within a Specific Crate

Beyond running all tests in a crate, you can target specific test functions or modules by adding a filter argument after the package name. As documented in the CI rules at [`.claude/rules/ci.md`](https://github.com/AprilNEA/OpenLogi/blob/main/.claude/rules/ci.md) (lines 93‑94), this pattern supports granular validation workflows.

Run tests matching a specific pattern:

```bash

# Run only tests containing "dpi" in the openlogi-agent-core crate

cargo test -p openlogi-agent-core dpi

```

Execute a specific test function using its full path:

```bash

# Run a single test function in openlogi-hid

cargo test -p openlogi-hid test_write_dpi

```

Run only integration tests for a specific crate:

```bash

# Verify wire-format tests for the IPC crate exclusively

cargo test -p openlogi-ipc --test wire_format

```

## CI and Automation Patterns

The repository's continuous integration configuration leverages these commands for efficient pipeline execution. The CI rules reference concrete examples such as:

```bash

# i18n end-to-end tests for the desktop UI

cargo test -p openlogi-desktop i18n

```

These patterns ensure that pull requests trigger only relevant test suites, reducing CI latency while maintaining coverage standards.

## Key Configuration Files

Several files define the testing workflow and crate organization:

- **[`AGENTS.md`](https://github.com/AprilNEA/OpenLogi/blob/main/AGENTS.md)** (line 77) – Outlines the generic `cargo test -p <crate>` pattern for agent development workflows.
- **[`.claude/rules/ci.md`](https://github.com/AprilNEA/OpenLogi/blob/main/.claude/rules/ci.md)** (lines 93‑94) – Contains concrete CI examples including integration test targeting with `--test` flags.
- **[`Cargo.toml`](https://github.com/AprilNEA/OpenLogi/blob/main/Cargo.toml)** – Defines the workspace members and dependencies, serving as the source of truth for available crate names.
- **[`docs/DEVELOPMENT.md`](https://github.com/AprilNEA/OpenLogi/blob/main/docs/DEVELOPMENT.md)** (lines 197‑199) – Explains the overall testing workflow including `cargo test --workspace` for full-suite validation when needed.

## Summary

- OpenLogi uses Cargo workspaces with crates located in the `crates/` directory.
- Use `cargo test -p <crate-name>` to execute tests for a single crate only.
- Append test name patterns after the crate specification to filter specific tests.
- Reference [`AGENTS.md`](https://github.com/AprilNEA/OpenLogi/blob/main/AGENTS.md) and [`.claude/rules/ci.md`](https://github.com/AprilNEA/OpenLogi/blob/main/.claude/rules/ci.md) for authoritative testing patterns.
- All commands must run from the repository root where the workspace [`Cargo.toml`](https://github.com/AprilNEA/OpenLogi/blob/main/Cargo.toml) resides.

## Frequently Asked Questions

### What is the difference between `cargo test` and `cargo test -p`?

Running `cargo test` without flags executes tests for the entire workspace, which can be time-consuming in large repositories like OpenLogi. The `-p` flag restricts the test run to a specific package, drastically reducing compilation and execution time when you are working on isolated changes.

### How do I find the exact crate name to use with the `-p` flag?

The crate name matches the directory name under `crates/` (e.g., `openlogi-agent-core`). You can also verify the exact package name by inspecting the `[workspace.members]` section in the root [`Cargo.toml`](https://github.com/AprilNEA/OpenLogi/blob/main/Cargo.toml), which lists all available crates in the repository.

### Can I run tests for multiple specific crates at once?

Yes, you can specify multiple `-p` flags in a single command: `cargo test -p openlogi-core -p openlogi-hid`. This approach tests only the listed crates while skipping other workspace members, providing a middle ground between single-crate and full-workspace testing.

### How do I run only integration tests for a specific crate?

Use the `--test` flag followed by the integration test name: `cargo test -p openlogi-ipc --test wire_format`. This command exclusively builds and runs the specified integration test file within the target crate, bypassing unit tests and other integration suites.