Implementation:0xranx OpenContext Core Unit Tests
| Knowledge Sources | |
|---|---|
| Domains | Testing, Rust_Core |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
Unit test suite for the opencontext-core Rust crate, covering context initialization, folder operations, document CRUD, and manifest generation using tempdir fixtures.
Description
The tests.rs file in crates/opencontext-core/src/ contains comprehensive unit tests organized into modules: context_tests (initialization, idempotency, env_info), folder_tests (create, list, rename, move, remove), doc_tests (create, list, get by path/stable_id, move, description), and manifest_tests. Each test uses tempfile::TempDir to create isolated test environments with the EnvOverrides pattern for deterministic paths.
Usage
Run with cargo test in the crates/opencontext-core directory.
Code Reference
Source Location
- Repository: 0xranx_OpenContext
- File: crates/opencontext-core/src/tests.rs
- Lines: 1-732
Signature
#[cfg(test)]
mod context_tests { ... }
#[cfg(test)]
mod folder_tests { ... }
#[cfg(test)]
mod doc_tests { ... }
#[cfg(test)]
mod manifest_tests { ... }
fn create_test_context() -> (OpenContext, TempDir)
Import
// Tests are compiled with #[cfg(test)] and run via:
// cargo test --package opencontext-core
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| TempDir | tempfile::TempDir | Yes | Isolated temp directory per test |
| EnvOverrides | struct | Yes | Override paths for test isolation |
Outputs
| Name | Type | Description |
|---|---|---|
| Test results | cargo output | Pass/fail per test function |
Usage Examples
Running Tests
cd crates/opencontext-core
cargo test
cargo test -- --test-threads=1 # sequential if needed
Test Pattern
#[test]
fn test_initialize_creates_directories() {
let (ctx, temp_dir) = create_test_context();
let info = ctx.env_info();
assert!(info.contexts_root.exists(), "Contexts directory should exist");
assert!(info.db_path.exists(), "Database file should exist");
drop(temp_dir);
}