use agentty::db::{DB_DIR, DB_FILE, Database};
use testty::assertion;
use testty::region::Region;
use crate::common;
use crate::common::{BuilderEnv, FeatureTest};
type E2eResult = Result<(), Box<dyn std::error::Error>>;
fn seed_review_ready_session(env: &BuilderEnv) -> Result<(), Box<dyn std::error::Error>> {
let canonical_workdir = env.workdir.canonicalize()?;
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()?;
runtime.block_on(async {
let db_path = env.agentty_root.join(DB_DIR).join(DB_FILE);
let database = Database::open(&db_path).await?;
let project_id = database
.upsert_project(&canonical_workdir.to_string_lossy(), Some("main"))
.await?;
database.touch_project_last_opened(project_id).await?;
database
.insert_session(
"review-shortcut-0001",
"gpt-5.4",
"main",
"Review",
project_id,
)
.await?;
database
.update_session_title(
"review-shortcut-0001",
"Refresh review request from session view",
)
.await?;
database
.update_session_diff_stats(12, 3, "review-shortcut-0001", "M")
.await
})?;
std::fs::create_dir_all(env.agentty_root.join("wt").join("review-s"))?;
Ok(())
}
#[test]
fn session_list_empty_state() -> E2eResult {
FeatureTest::new("session_empty")
.zola(
"Empty session state",
"A clean slate when no sessions exist yet.",
40,
)
.run(
|scenario| {
scenario
.compose(&common::wait_for_agentty_startup())
.viewing_pause_ms(2000)
.compose(&common::switch_to_tab("Sessions"))
.viewing_pause_ms(2000)
.capture_labeled("sessions_tab", "Sessions tab with no sessions")
},
|frame, _report| {
let full = Region::full(frame.cols(), frame.rows());
assertion::assert_text_in_region(frame, "No sessions", &full);
},
)?;
Ok(())
}
#[test]
fn session_creation_opens_prompt_mode() -> E2eResult {
FeatureTest::new("session_creation")
.with_git()
.zola(
"Session creation",
"Start a new agent session with a single keypress.",
30,
)
.run(
|scenario| {
scenario
.compose(&common::wait_for_agentty_startup())
.compose(&common::switch_to_tab("Sessions"))
.viewing_pause_ms(1500)
.press_key("a")
.wait_for_stable_frame(300, 5000)
.viewing_pause_ms(1500)
.capture_labeled("prompt_mode", "Prompt mode after pressing a")
},
|frame, _report| {
let full = Region::full(frame.cols(), frame.rows());
assertion::assert_text_in_region(frame, "Enter: submit", &full);
assertion::assert_text_in_region(frame, "Esc: cancel", &full);
},
)?;
Ok(())
}
#[test]
fn session_prompt_cancel_returns_to_empty_list() -> E2eResult {
FeatureTest::new("prompt_cancel")
.with_git()
.zola(
"Prompt cancel",
"Cancel prompt input with Esc to return to the session view.",
120,
)
.run(
|scenario| {
scenario
.compose(&common::wait_for_agentty_startup())
.compose(&common::switch_to_tab("Sessions"))
.viewing_pause_ms(2000)
.press_key("a")
.wait_for_stable_frame(300, 5000)
.viewing_pause_ms(2000)
.capture_labeled("prompt_open", "Prompt mode opened")
.press_key("Esc")
.wait_for_stable_frame(300, 5000)
.viewing_pause_ms(2000)
.capture_labeled("back_to_list", "Sessions list after cancel")
},
|frame, report| {
let prompt_frame = common::frame_from_capture(&report.captures[0]);
let prompt_full = Region::full(prompt_frame.cols(), prompt_frame.rows());
assertion::assert_text_in_region(&prompt_frame, "Esc: cancel", &prompt_full);
let full = Region::full(frame.cols(), frame.rows());
assertion::assert_text_in_region(frame, "No sessions", &full);
},
)?;
Ok(())
}
#[test]
fn session_open_and_return_to_list() -> E2eResult {
FeatureTest::new("session_open")
.with_git()
.zola(
"Session open and return",
"Open a session with Enter and return to the list with q.",
42,
)
.run(
|scenario| {
scenario
.compose(&common::wait_for_agentty_startup())
.compose(&common::switch_to_tab("Sessions"))
.compose(&common::create_session_and_return_to_list())
.viewing_pause_ms(1500)
.press_key("Enter")
.sleep(std::time::Duration::from_secs(2))
.viewing_pause_ms(2000)
.capture_labeled("session_view", "Session view after Enter")
.press_key("q")
.sleep(std::time::Duration::from_secs(1))
.viewing_pause_ms(2000)
.capture_labeled("back_to_list", "Sessions list after q")
},
|frame, report| {
let session_view_frame = common::frame_from_capture(&report.captures[0]);
let view_full = Region::full(session_view_frame.cols(), session_view_frame.rows());
assertion::assert_text_in_region(&session_view_frame, "q: back", &view_full);
let full = Region::full(frame.cols(), frame.rows());
assertion::assert_text_in_region(frame, "test", &full);
},
)?;
Ok(())
}
#[test]
fn review_request_publish_shortcut_opens_publish_popup() -> E2eResult {
FeatureTest::new("review_request_publish_shortcut")
.with_git()
.setup(seed_review_ready_session)
.zola(
"Review request publish shortcut",
"Open the review-request publish popup directly from session view with `p`.",
42,
)
.run(
|scenario| {
scenario
.compose(&common::wait_for_agentty_startup())
.compose(&common::switch_to_tab("Sessions"))
.press_key("Enter")
.sleep(std::time::Duration::from_secs(1))
.press_key("p")
.wait_for_stable_frame(300, 5000)
.viewing_pause_ms(1500)
.capture_labeled(
"review_request_publish_popup",
"Review-request publish popup after pressing p",
)
},
|frame, _report| {
let full = Region::full(frame.cols(), frame.rows());
assertion::assert_text_in_region(frame, "Publish Review Request", &full);
assertion::assert_text_in_region(frame, "Enter: publish review request", &full);
},
)?;
Ok(())
}
#[test]
fn session_list_jk_navigation() -> E2eResult {
FeatureTest::new("session_navigation")
.with_git()
.zola(
"Session list navigation",
"Navigate sessions with j/k keys to select and open different entries.",
44,
)
.run(
|scenario| {
scenario
.compose(&common::wait_for_agentty_startup())
.compose(&common::switch_to_tab("Sessions"))
.compose(&common::create_session_with_prompt_and_return_to_list(
"alpha",
))
.compose(&common::create_session_with_prompt_and_return_to_list(
"beta",
))
.viewing_pause_ms(2000)
.capture_labeled("two_sessions", "Two sessions in list")
.press_key("j")
.wait_for_stable_frame(300, 3000)
.press_key("Enter")
.sleep(std::time::Duration::from_secs(2))
.viewing_pause_ms(2000)
.capture_labeled("opened_after_j", "Session opened after pressing j")
.press_key("q")
.sleep(std::time::Duration::from_secs(1))
.press_key("k")
.wait_for_stable_frame(300, 3000)
.press_key("Enter")
.sleep(std::time::Duration::from_secs(2))
.viewing_pause_ms(2000)
.capture_labeled("opened_after_k", "Session opened after pressing k")
},
|_frame, report| {
assert_eq!(
report.captures.len(),
3,
"Expected 3 captures (list, opened_after_j, opened_after_k)"
);
let initial_frame = common::frame_from_capture(&report.captures[0]);
let initial_full = Region::full(initial_frame.cols(), initial_frame.rows());
let initial_text = initial_frame.text_in_region(&initial_full);
assert!(
initial_text.contains("alpha") && initial_text.contains("beta"),
"Expected both session prompts visible in list"
);
let session_after_down_navigation_frame =
common::frame_from_capture(&report.captures[1]);
let session_after_up_navigation_frame =
common::frame_from_capture(&report.captures[2]);
let down_navigation_full = Region::full(
session_after_down_navigation_frame.cols(),
session_after_down_navigation_frame.rows(),
);
let up_navigation_full = Region::full(
session_after_up_navigation_frame.cols(),
session_after_up_navigation_frame.rows(),
);
let down_navigation_text =
session_after_down_navigation_frame.text_in_region(&down_navigation_full);
let up_navigation_text =
session_after_up_navigation_frame.text_in_region(&up_navigation_full);
assert!(
down_navigation_text.contains("alpha") || down_navigation_text.contains("beta"),
"Session opened after j must contain alpha or beta"
);
assert!(
up_navigation_text.contains("alpha") || up_navigation_text.contains("beta"),
"Session opened after k must contain alpha or beta"
);
assert_ne!(
down_navigation_text.contains("alpha"),
up_navigation_text.contains("alpha"),
"j and k must open different sessions"
);
},
)?;
Ok(())
}
#[test]
fn prompt_typing_shows_text() -> E2eResult {
FeatureTest::new("prompt_typing")
.with_git()
.zola(
"Prompt typing",
"Type text into the prompt input and see it appear in real time.",
115,
)
.run(
|scenario| {
scenario
.compose(&common::wait_for_agentty_startup())
.compose(&common::switch_to_tab("Sessions"))
.viewing_pause_ms(2000)
.press_key("a")
.wait_for_stable_frame(300, 5000)
.viewing_pause_ms(1500)
.capture_labeled("empty_prompt", "Empty prompt input")
.write_text("hello world")
.wait_for_text("hello world", 3000)
.viewing_pause_ms(2500)
.capture_labeled("typed_text", "Prompt input with typed text")
},
|frame, _report| {
let full = Region::full(frame.cols(), frame.rows());
assertion::assert_text_in_region(frame, "hello world", &full);
},
)?;
Ok(())
}
#[test]
fn prompt_multiline_via_alt_enter() -> E2eResult {
FeatureTest::new("prompt_multiline")
.with_git()
.zola(
"Multiline prompt",
"Insert newlines with Alt+Enter to compose multiline prompts.",
125,
)
.run(
|scenario| {
scenario
.compose(&common::wait_for_agentty_startup())
.compose(&common::switch_to_tab("Sessions"))
.viewing_pause_ms(2000)
.press_key("a")
.wait_for_stable_frame(300, 5000)
.viewing_pause_ms(1500)
.write_text("first line")
.wait_for_text("first line", 3000)
.viewing_pause_ms(2000)
.capture_labeled("first_line", "First line typed")
.write_text("\x1b\r")
.wait_for_stable_frame(300, 3000)
.write_text("second line")
.wait_for_text("second line", 3000)
.viewing_pause_ms(2500)
.capture_labeled("multiline", "Multiline prompt with both lines")
},
|frame, _report| {
let full = Region::full(frame.cols(), frame.rows());
assertion::assert_text_in_region(frame, "first line", &full);
assertion::assert_text_in_region(frame, "second line", &full);
},
)?;
Ok(())
}