test: faster test execution in codex-core (#2633)
this dramatically improves time to run `cargo test -p codex-core` (~25x speedup). before: ``` cargo test -p codex-core 35.96s user 68.63s system 19% cpu 8:49.80 total ``` after: ``` cargo test -p codex-core 5.51s user 8.16s system 63% cpu 21.407 total ``` both tests measured "hot", i.e. on a 2nd run with no filesystem changes, to exclude compile times. approach inspired by [Delete Cargo Integration Tests](https://matklad.github.io/2021/02/27/delete-cargo-integration-tests.html), we move all test cases in tests/ into a single suite in order to have a single binary, as there is significant overhead for each test binary executed, and because test execution is only parallelized with a single binary.
This commit is contained in:
77
codex-rs/tui/tests/suite/vt100_streaming_no_dup.rs
Normal file
77
codex-rs/tui/tests/suite/vt100_streaming_no_dup.rs
Normal file
@@ -0,0 +1,77 @@
|
||||
#![cfg(feature = "vt100-tests")]
|
||||
|
||||
use ratatui::backend::TestBackend;
|
||||
use ratatui::layout::Rect;
|
||||
use ratatui::text::Line;
|
||||
|
||||
fn term(viewport: Rect) -> codex_tui::custom_terminal::Terminal<TestBackend> {
|
||||
let backend = TestBackend::new(20, 6);
|
||||
let mut term = codex_tui::custom_terminal::Terminal::with_options(backend)
|
||||
.unwrap_or_else(|e| panic!("failed to construct terminal: {e}"));
|
||||
term.set_viewport_area(viewport);
|
||||
term
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stream_commit_trickle_no_duplication() {
|
||||
// Viewport is the last row (height=1 at y=5)
|
||||
let area = Rect::new(0, 5, 20, 1);
|
||||
let mut t = term(area);
|
||||
|
||||
// Step 1: commit first row
|
||||
let mut out1 = Vec::new();
|
||||
codex_tui::insert_history::insert_history_lines_to_writer(
|
||||
&mut t,
|
||||
&mut out1,
|
||||
vec![Line::from("one")],
|
||||
);
|
||||
|
||||
// Step 2: later commit next row
|
||||
let mut out2 = Vec::new();
|
||||
codex_tui::insert_history::insert_history_lines_to_writer(
|
||||
&mut t,
|
||||
&mut out2,
|
||||
vec![Line::from("two")],
|
||||
);
|
||||
|
||||
let combined = [out1, out2].concat();
|
||||
let s = String::from_utf8_lossy(&combined);
|
||||
assert_eq!(
|
||||
s.matches("one").count(),
|
||||
1,
|
||||
"history line duplicated: {s:?}"
|
||||
);
|
||||
assert_eq!(
|
||||
s.matches("two").count(),
|
||||
1,
|
||||
"history line duplicated: {s:?}"
|
||||
);
|
||||
assert!(
|
||||
!s.contains("three"),
|
||||
"live-only content leaked into history: {s:?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn live_ring_rows_not_inserted_into_history() {
|
||||
let area = Rect::new(0, 5, 20, 1);
|
||||
let mut t = term(area);
|
||||
|
||||
// Commit two rows to history.
|
||||
let mut buf = Vec::new();
|
||||
codex_tui::insert_history::insert_history_lines_to_writer(
|
||||
&mut t,
|
||||
&mut buf,
|
||||
vec![Line::from("one"), Line::from("two")],
|
||||
);
|
||||
|
||||
// The live ring might display tail+head rows like ["two", "three"],
|
||||
// but only committed rows should be present in the history ANSI stream.
|
||||
let s = String::from_utf8_lossy(&buf);
|
||||
assert!(s.contains("one"));
|
||||
assert!(s.contains("two"));
|
||||
assert!(
|
||||
!s.contains("three"),
|
||||
"uncommitted live-ring content should not be inserted into history: {s:?}"
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user