magi-code 0.77.1

Repository-aware CLI coding agent for terminal work
Documentation
//! Bounded synthetic scroll profiles. Run `cargo test --quiet --lib
//! profile_scroll_ -- --ignored --nocapture --test-threads=1`.
//! Draw timings exclude queueing, pacing and physical display latency. `apply_ms`
//! includes scroll projection and, where specified, a synthetic streaming update.
use super::*;

const AREA: Rect = Rect::new(0, 0, 120, 36);
const FRAMES: usize = 18;

fn popup_state() -> (MissionControlState, ActivityId, ActivityId) {
    let mut state = seed_render_heavy_transcript_state(24);
    let batch = ActivityId::new("profile-batch");
    state.apply_activity_event(ActivityEvent::Started {
        id: batch.clone(),
        parent_id: None,
        kind: ActivityKind::SubagentBatch,
        status: ActivityStatus::Running,
        metadata: ActivityMetadata::new("profile agents"),
    });
    let tasks = [batch.child("selected"), batch.child("unrelated")];
    for task in &tasks {
        state.apply_activity_event(ActivityEvent::Started {
            id: task.clone(),
            parent_id: Some(batch.clone()),
            kind: ActivityKind::SubagentTask,
            status: ActivityStatus::Running,
            metadata: ActivityMetadata::new(task.as_str()),
        });
        // Separate timeline entries exercise deep history, not just one preview.
        for index in 0..80 {
            state.apply_activity_event(ActivityEvent::Started {
                id: task.child(format!("tool-{index}")),
                parent_id: Some(task.clone()),
                kind: ActivityKind::Tool,
                status: ActivityStatus::Success,
                metadata: ActivityMetadata::new(format!("inspect synthetic file {index}")),
            });
        }
    }
    assert!(state.open_subagent_viewer(batch, tasks[0].clone()));
    (state, tasks[0].clone(), tasks[1].clone())
}

fn popup_scroll_profile(name: &'static str, streaming_selected: Option<bool>) {
    let (state, selected, unrelated) = popup_state();
    let summary = run_render_scenario(name, AREA, FRAMES, state, |state, frame, area| {
        if let Some(selected_stream) = streaming_selected {
            let task = if selected_stream {
                &selected
            } else {
                &unrelated
            };
            state.apply_activity_event(ActivityEvent::Delta {
                id: task.child("tool-79"),
                preview: format!("streaming preview {frame}"),
            });
        }
        let timeline = crate::tui::render::subagent_viewer_timeline_area(area).unwrap();
        let width = timeline.width.saturating_sub(1).max(1);
        assert!(state.scroll_subagent_viewer_up(3, timeline.height, width));
    });
    assert_render_summaries(&[summary]);
}

#[test]
#[ignore = "diagnostic scroll profile; run explicitly with --ignored --nocapture"]
fn profile_scroll_popup_idle() {
    popup_scroll_profile("scroll_popup_idle", None);
}

#[test]
#[ignore = "diagnostic scroll profile; run explicitly with --ignored --nocapture"]
fn profile_scroll_popup_selected_streaming() {
    popup_scroll_profile("scroll_popup_selected_streaming", Some(true));
}

#[test]
#[ignore = "diagnostic scroll profile; run explicitly with --ignored --nocapture"]
fn profile_scroll_popup_unrelated_streaming() {
    popup_scroll_profile("scroll_popup_unrelated_streaming", Some(false));
}

fn transcript_scroll_profile(name: &'static str, mut state: MissionControlState, selection: bool) {
    if selection {
        use crate::tui::render::TuiPane;
        state.set_scroll_offset(&state.scroll_views.transcript, 300);
        let anchor = state
            .transcript_text_position_for_cell(0, 0, 24, 80)
            .unwrap();
        let current = state
            .transcript_text_position_for_cell(1, 10, 24, 80)
            .unwrap();
        state.start_selection(TuiPane::Transcript, anchor);
        assert!(state.update_selection(TuiPane::Transcript, current));
    }
    let summary = run_render_scenario(name, AREA, FRAMES, state, |state, frame, _| {
        state.set_scroll_offset(&state.scroll_views.transcript, 300 + frame * 3);
    });
    assert_render_summaries(&[summary]);
}

#[test]
#[ignore = "diagnostic scroll profile; run explicitly with --ignored --nocapture"]
fn profile_scroll_transcript_deep_history() {
    transcript_scroll_profile(
        "scroll_transcript_deep_history",
        seed_render_heavy_transcript_state(120),
        false,
    );
}

#[test]
#[ignore = "diagnostic scroll profile; run explicitly with --ignored --nocapture"]
fn profile_scroll_transcript_selection() {
    transcript_scroll_profile(
        "scroll_transcript_selection",
        seed_render_heavy_transcript_state(120),
        true,
    );
}

#[test]
#[ignore = "diagnostic scroll profile; run explicitly with --ignored --nocapture"]
fn profile_scroll_transcript_long_reply() {
    let mut state = seed_render_streaming_state();
    state.apply_output_event(&OutputEvent::AssistantComplete {
        text: RENDERING_TRANSCRIPT.repeat(40),
    });
    transcript_scroll_profile("scroll_transcript_long_reply", state, false);
}