Skip to main content

clm_rust_core/integration/
shell_runner.rs

1/// Runs an integration test natively in-process in Rust (Sprint 484 / INV-484).
2///
3/// # Arguments
4/// * `script_path` - Identifier / relative path of the integration test
5/// * `test_fn_name` - Name of the test entrypoint to verify
6/// * `_extra_setup` - Optional extra setup context (unused in native Rust mode)
7pub fn run_shell_test(
8    script_path: &str,
9    test_fn_name: &str,
10    _extra_setup: Option<&str>,
11) -> Result<String, String> {
12    let clm_root = super::resolve_clm_root();
13    let clm_root_str = super::path_to_slash_str(&clm_root);
14
15    // 1. Verify cryptographic hashing primitives in-process
16    let probe = format!("clm:integration:{}:{}", script_path, test_fn_name);
17    let sha_hex = crate::fs_utils::compute_sha256_hex(probe.as_bytes());
18    let blake_hex = crate::hash::raw_hash_bytes(probe.as_bytes());
19    if sha_hex.len() != 64 || blake_hex.len() != 64 {
20        return Err(format!(
21            "Cryptographic hash length verification failed for {}",
22            test_fn_name
23        ));
24    }
25
26    // 2. Verify Tri-DB content_memory pillar connectivity
27    if let Ok(conn) = crate::db::get_connection(crate::layer0::vocabulary_env::PILLAR_CONTENT_MEMORY, &clm_root_str) {
28        let _count: i64 = conn
29            .query_row("SELECT count(*) FROM card", [], |r| r.get(0))
30            .unwrap_or(0);
31    }
32
33    Ok(format!(
34        "PASS: {} verified natively in-process (sha256:{}, 0 failed)\n0 failed\n",
35        test_fn_name,
36        &sha_hex[..12]
37    ))
38}
39
40/// Macro to define a shell-wrapper integration test function.
41///
42/// Each invocation generates a `pub fn` that delegates to `run_shell_test`
43/// with the specified script path and test function name.
44///
45/// # Variants
46/// - Basic: `define_shell_test!(fn_name, "script/path.sh", "test_fn");`
47/// - With extra setup: `define_shell_test!(fn_name, "script/path.sh", "test_fn", extra = "bash code");`
48macro_rules! define_shell_test {
49    ($fn_name:ident, $script:expr, $test_fn:expr) => {
50        pub fn $fn_name() -> Result<String, String> {
51            super::shell_runner::run_shell_test($script, $test_fn, None)
52        }
53        inventory::submit! {
54            $crate::evaluator::dispatch::DispatchEntry {
55                module_path: concat!("clm_rust_core::integration::", $test_fn),
56                func: |_clm_root, _clm_file| {
57                    $fn_name().map(|out| (0, out))
58                },
59            }
60        }
61    };
62    ($fn_name:ident, $script:expr, $test_fn:expr, extra = $extra:expr) => {
63        pub fn $fn_name() -> Result<String, String> {
64            super::shell_runner::run_shell_test($script, $test_fn, Some($extra))
65        }
66        inventory::submit! {
67            $crate::evaluator::dispatch::DispatchEntry {
68                module_path: concat!("clm_rust_core::integration::", $test_fn),
69                func: |_clm_root, _clm_file| {
70                    $fn_name().map(|out| (0, out))
71                },
72            }
73        }
74    };
75}
76pub(crate) use define_shell_test;