Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xranx OpenContext Core Unit Tests

From Leeroopedia
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

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);
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment