magi-code 0.96.1

Repository-aware CLI coding agent for terminal work
Documentation
use super::*;

#[test]
#[ignore = "diagnostic-only optimization measurement; run explicitly with --ignored --nocapture"]
fn optimization_harness_measures_large_replay_and_cache_material() {
    // Large count is fixture data for optimization measurement, not a runtime ceiling.
    let temp = TempDir::new().unwrap();
    let manager = crate::sessions::SessionManager::new(temp.path().join("sessions"));
    let session = manager.create().unwrap();
    let tool_pair_count = 1_500;
    for index in 0..tool_pair_count {
        session
            .append(&SessionEvent::new(
                "tool_call",
                session.id().to_string(),
                temp.path().to_path_buf(),
                json!({
                    "id": format!("call_{index}"),
                    "name": "read",
                    "arguments": {"path": format!("fixtures/{index}.txt")}
                }),
            ))
            .unwrap();
        session
            .append(&SessionEvent::new(
                "tool_result",
                session.id().to_string(),
                temp.path().to_path_buf(),
                json!({
                    "call_id": format!("call_{index}"),
                    "result": {
                        "tool_name": "read",
                        "success": true,
                        "content": format!("file contents {index}")
                    }
                }),
            ))
            .unwrap();
    }

    let replay_started = std::time::Instant::now();
    let replay = build_conversation_replay(Some(&session)).unwrap();
    let replay_elapsed = replay_started.elapsed();
    let material_started = std::time::Instant::now();
    let material = conversation_cache_material("p", "m", "sys", &replay.items);
    let material_elapsed = material_started.elapsed();

    println!(
        "optimization_harness context_replay tool_pairs={} items={} material_bytes={} replay_elapsed={replay_elapsed:?} material_elapsed={material_elapsed:?}",
        tool_pair_count,
        replay.items.len(),
        material.len()
    );
    assert_eq!(replay.items.len(), tool_pair_count * 2);
    assert!(material.contains(&format!("call_{}", tool_pair_count - 1)));
}