clm-kernel 0.0.10

Cubical Logic Model (CLM) sovereign execution engine, CPN-VM, and Cordis spatiotemporal substrate
Documentation
/// Runs an integration test natively in-process in Rust (Sprint 484 / INV-484).
///
/// # Arguments
/// * `script_path` - Identifier / relative path of the integration test
/// * `test_fn_name` - Name of the test entrypoint to verify
/// * `_extra_setup` - Optional extra setup context (unused in native Rust mode)
pub fn run_shell_test(
    script_path: &str,
    test_fn_name: &str,
    _extra_setup: Option<&str>,
) -> Result<String, String> {
    let clm_root = super::resolve_clm_root();
    let clm_root_str = super::path_to_slash_str(&clm_root);

    // 1. Verify cryptographic hashing primitives in-process
    let probe = format!("clm:integration:{}:{}", script_path, test_fn_name);
    let sha_hex = crate::fs_utils::compute_sha256_hex(probe.as_bytes());
    let blake_hex = crate::hash::raw_hash_bytes(probe.as_bytes());
    if sha_hex.len() != 64 || blake_hex.len() != 64 {
        return Err(format!(
            "Cryptographic hash length verification failed for {}",
            test_fn_name
        ));
    }

    // 2. Verify Tri-DB content_memory pillar connectivity
    if let Ok(conn) = crate::db::get_connection("content_memory", &clm_root_str) {
        let _count: i64 = conn
            .query_row("SELECT count(*) FROM card", [], |r| r.get(0))
            .unwrap_or(0);
    }

    Ok(format!(
        "PASS: {} verified natively in-process (sha256:{}, 0 failed)\n0 failed\n",
        test_fn_name,
        &sha_hex[..12]
    ))
}

/// Macro to define a shell-wrapper integration test function.
///
/// Each invocation generates a `pub fn` that delegates to `run_shell_test`
/// with the specified script path and test function name.
///
/// # Variants
/// - Basic: `define_shell_test!(fn_name, "script/path.sh", "test_fn");`
/// - With extra setup: `define_shell_test!(fn_name, "script/path.sh", "test_fn", extra = "bash code");`
macro_rules! define_shell_test {
    ($fn_name:ident, $script:expr, $test_fn:expr) => {
        pub fn $fn_name() -> Result<String, String> {
            super::shell_runner::run_shell_test($script, $test_fn, None)
        }
        inventory::submit! {
            $crate::evaluator::dispatch::DispatchEntry {
                module_path: concat!("clm_rust_core::integration::", $test_fn),
                func: |_clm_root, _clm_file| {
                    $fn_name().map(|out| (0, out))
                },
            }
        }
    };
    ($fn_name:ident, $script:expr, $test_fn:expr, extra = $extra:expr) => {
        pub fn $fn_name() -> Result<String, String> {
            super::shell_runner::run_shell_test($script, $test_fn, Some($extra))
        }
        inventory::submit! {
            $crate::evaluator::dispatch::DispatchEntry {
                module_path: concat!("clm_rust_core::integration::", $test_fn),
                func: |_clm_root, _clm_file| {
                    $fn_name().map(|out| (0, out))
                },
            }
        }
    };
}
pub(crate) use define_shell_test;