> ## Documentation Index
> Fetch the complete documentation index at: https://docs.memorose.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# 测试

> 如何运行测试，以及理解当前 Memorose 的测试结构。

# 测试

## 运行测试

运行完整 Rust 测试套件：

```bash theme={null}
cargo test
```

或者运行单个 crate：

```bash theme={null}
cargo test -p memorose-core
cargo test -p memorose-server
cargo test -p memorose-gateway
cargo test -p memorose-common
```

按名称运行单个测试：

```bash theme={null}
cargo test -p memorose-core test_ingest_and_retrieve
```

## 测试组织

### 单元测试

大多数单元测试通过 `#[cfg(test)]` 和被测模块放在一起。

常见入口：

* `crates/memorose-core/src/engine/tests.rs`
* `graph/`、`llm/`、`raft/`、`worker.rs` 以及 dashboard handlers 里的模块内 `#[cfg(test)]`

### 集成测试

当前集成测试位于：

* `crates/memorose-core/tests/integration.rs`

这些测试覆盖端到端的 ingest 和 retrieve 流程。

## 常见模式

### 异步测试

I/O 较重的测试通常使用 `#[tokio::test]`。

### 临时目录

需要隔离存储状态的测试通常会把引擎指向临时目录，而不是复用仓库目录。

### 模拟外部 HTTP 调用

涉及 HTTP 的测试会使用 `wiremock`，例如：

* `crates/memorose-server/src/shard_manager.rs`
* `crates/memorose-core/src/llm/openai_tests.rs`
* `crates/memorose-core/src/llm/gemini_tests.rs`

### LLM 相关测试

当前 `AppConfig` 没有一个会被运行时 loader 消费的 `[development].use_mock_llm` 开关。实际测试里通常是在 Rust 测试代码内部显式构造 mock client。

## 编写新测试

* 单元测试尽量贴近被测代码。
* 跨模块集成测试放到 `crates/memorose-core/tests/`。
* 使用描述性名称，例如 `test_hybrid_search_with_agent_filter`。
* 优先用临时目录，避免共享磁盘状态。
* 除非你是在刻意验证 provider 集成，否则避免真实外部调用。

## Dashboard 检查

当前 dashboard 可用的脚本是：

```bash theme={null}
cd dashboard
pnpm lint
pnpm build
```

如果你需要本地交互验证：

```bash theme={null}
pnpm dev
```
