use std::env;
use std::fs;
pub fn run_integration_internal_dispatch_zerofs() -> Result<String, String> {
let (original_clm_root, test_dir) = super::setup_isolated_env("test_internal_dispatch_zerofs");
println!("======================================================");
println!(" Test Suite: Zero-FS Internal Rust Dispatch (100.2)");
println!("======================================================\n");
crate::utils::set_env_var("CLM_ZERO_FS", "true");
crate::utils::remove_env_var("ACTIVE_AGENT_DID");
crate::db::init_tridb(test_dir.to_str().unwrap()).unwrap();
println!(" ✅ init_tridb completed in-memory");
let test_clm_path = test_dir.join("test_split_internal.yaml");
let test_clm_content = r#"clm:
abstract_spec:
context: "Internal reference split verification"
goal: "Verify split operation is dispatched internally"
success_criteria: []
concrete_impl:
runtime: rust
operation: split
inputs:
- clm_file: "string"
outputs:
- split_output: "string"
process:
type: internal_reference
module: "clm_rust_core::baldwin::split"
balanced_exp:
expectation: "split completes"
"#;
fs::write(&test_clm_path, test_clm_content).unwrap();
println!("-- Invoking internal dispatch --");
let exit_code = crate::evaluator::try_internal_dispatch(
&test_dir,
test_clm_path.to_str().unwrap(),
None,
None, false, ).map_err(|e| format!("try_internal_dispatch failed: {}", e))?;
assert_eq!(exit_code, 0);
println!(" ✅ Internal dispatch executed successfully (exit_code=0)");
let identities_db_path = crate::db::get_db_path("agent_identities", test_dir.to_str().unwrap());
let conn_id = rusqlite::Connection::open(&identities_db_path).unwrap();
let active_did = env::var("ACTIVE_AGENT_DID").unwrap();
let root_card_exists: i64 = conn_id.query_row(
"SELECT count(*) FROM card WHERE hash = ?;",
[&active_did],
|row| row.get(0)
).unwrap_or(0);
assert_eq!(root_card_exists, 1);
println!(" ✅ Root agent DID card registered in agent_identities DB");
let log_db_path = crate::db::get_db_path("execution_log", test_dir.to_str().unwrap());
let conn_log = rusqlite::Connection::open(&log_db_path).unwrap();
let log_count: i64 = conn_log.query_row(
"SELECT count(*) FROM card;",
[],
|row| row.get(0)
).unwrap_or(0);
assert_eq!(log_count, 3); println!(" ✅ VCard Sandwich Post-Gate successfully registered execution card in log DB");
crate::utils::remove_env_var("CLM_ZERO_FS");
super::restore_env(&original_clm_root, &test_dir);
println!("\n======================================================");
print!(" Results: 5 passed, 0 failed (of 5)");
Ok("".to_string())
}