Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ tree-sitter-powershell = "0.26.4"
tree-sitter-python = "0.25.0"
tree-sitter-typescript = "0.23.2"
unicode-ident = "1.0.24"
unicode-segmentation = "1.12.0"
unicode-width = "0.2.2"
uuid = { version = "1.24.0", features = ["serde", "v4"] }
vt100 = "0.16.2"
sysinfo = { version = "0.39.6", default-features = false, features = ["system"] }
walkdir = "2.5.0"
wait-timeout = "0.2.1"
Expand Down
1 change: 1 addition & 0 deletions crates/skit-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ predicates.workspace = true
portable-pty.workspace = true
syn.workspace = true
tempfile.workspace = true
vt100.workspace = true

[lints]
workspace = true
15 changes: 14 additions & 1 deletion crates/skit-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2724,8 +2724,21 @@ fn colour_is_welcome_for(
/// A stream that is not a terminal keeps the plain text, which is why every recorded output in
/// this repository is unchanged: those runs are redirected.
fn paint_for_output(text: &str, style: HumanStyle, width: Option<usize>) -> String {
paint_for_output_with_colour(text, style, width, colour_is_welcome())
}

/// The same formatter for a caller that already knows if colour is available.
///
/// Keeping this input explicit lets tests own the terminal capability without changing the
/// process environment that concurrent tests share.
fn paint_for_output_with_colour(
text: &str,
style: HumanStyle,
width: Option<usize>,
colour_is_welcome: bool,
) -> String {
let folded = fold_for_output(text, width);
if width.is_none() || style == HumanStyle::Plain || !colour_is_welcome() {
if width.is_none() || style == HumanStyle::Plain || !colour_is_welcome {
return folded;
}
format!("{}{folded}\x1b[0m", style.prefix())
Expand Down
12 changes: 8 additions & 4 deletions crates/skit-cli/src/cli/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12200,23 +12200,27 @@ fn a_printed_line_wears_its_sense_and_drops_it_where_it_cannot_show() {

// A terminal wears the sense; a redirected stream keeps the plain text.
assert_eq!(
super::paint_for_output("done", super::HumanStyle::Green, Some(40)),
super::paint_for_output_with_colour("done", super::HumanStyle::Green, Some(40), true,),
"\u{1b}[32mdone\u{1b}[0m"
);
assert_eq!(
super::paint_for_output("done", super::HumanStyle::Green, None),
super::paint_for_output_with_colour("done", super::HumanStyle::Green, None, true),
"done"
);
// A line that states a fact wears nothing, terminal or not.
assert_eq!(
super::paint_for_output("done", super::HumanStyle::Plain, Some(40)),
super::paint_for_output_with_colour("done", super::HumanStyle::Plain, Some(40), true,),
"done"
);
// The colour follows the fold, so a folded line wears one sequence around the whole answer.
assert_eq!(
super::paint_for_output("aaa bbb", super::HumanStyle::Red, Some(3)),
super::paint_for_output_with_colour("aaa bbb", super::HumanStyle::Red, Some(3), true,),
"\u{1b}[31maaa\nbbb\u{1b}[0m"
);
assert_eq!(
super::paint_for_output_with_colour("done", super::HumanStyle::Green, Some(40), false,),
"done"
);

// Rich drops every style for either answer, and keeps it otherwise.
assert!(super::colour_is_welcome_for(None, None));
Expand Down
20 changes: 14 additions & 6 deletions crates/skit-cli/tests/port_test_tui_responsive_manifest.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Completeness guard for Python `tests/test_tui_responsive.py` at `main@206f9ef`.
//!
//! Seventeen contracts have executable terminal-geometry equivalents. Two assert widget structures
//! that do not exist in the Ratatui frontend and stay architecture-closed rather than being
//! represented by a weaker test of a different widget.
//! Seventeen contracts have executable terminal-geometry equivalents. Three Rust-only contracts
//! cover frontend adapter invariants. Two Python contracts assert widget structures that do not
//! exist in the Ratatui frontend and stay architecture-closed rather than being represented by a
//! weaker test of a different widget.

use std::{collections::BTreeSet, fs, path::Path};

Expand Down Expand Up @@ -30,6 +31,12 @@ const EXECUTABLE: &[&str] = &[
"test_add_source_fields_stay_reachable_on_short_terminals",
];

const RUST_ADDITIVE: &[&str] = &[
"test_growing_across_height_tiers_never_shrinks_the_primary_viewport",
"test_footer_minimum_structure_is_monotonic_and_keeps_status_out_of_hits",
"test_root_hit_rectangles_stay_inside_every_boundary_viewport",
];

const ARCHITECTURE_CLOSED: &[(&str, &str)] = &[
(
"test_run_form_stacks_preset_row_and_choices_when_narrow",
Expand Down Expand Up @@ -75,8 +82,8 @@ fn every_executable_responsive_contract_has_exactly_one_rust_oracle() {
let names = test_names(&source);
assert_eq!(
names.len(),
EXECUTABLE.len(),
"responsive target added or lost a parity test: {names:#?}"
EXECUTABLE.len() + RUST_ADDITIVE.len(),
"responsive target added or lost a declared test: {names:#?}"
);
let actual = names.iter().cloned().collect::<BTreeSet<_>>();
assert_eq!(
Expand All @@ -86,9 +93,10 @@ fn every_executable_responsive_contract_has_exactly_one_rust_oracle() {
);
let expected = EXECUTABLE
.iter()
.chain(RUST_ADDITIVE)
.map(|name| (*name).to_owned())
.collect::<BTreeSet<_>>();
assert_eq!(actual, expected, "responsive executable mapping drifted");
assert_eq!(actual, expected, "responsive test inventory drifted");
}

#[test]
Expand Down
37 changes: 25 additions & 12 deletions crates/skit-cli/tests/support/pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@
//! then reports an end of input the child never sent.
//! 5. **The reader thread fills a channel and is never joined on end-of-input.** The drain is
//! detached; nothing downstream depends on it finishing.
//! 6. **Read the visible text, never the control stream.** A pseudo-console writes its own
//! sequences into the same stream as the child's output: Windows opens a session with a
//! cursor question, mode switches, and a window title carrying the whole binary path
//! (`\x1b]0;D:\a\...\skit.exe\x07`). An assertion that measures or matches raw bytes reads
//! that chrome as if the product had printed it. [`strip_terminal_control`] gives the text a
//! person sees (wave 4 fold owners). An assertion about colour cannot drop every sequence, so
//! [`visible_with_styles`] and [`styles_over`] read the same stream one layer up: the visible
//! lines, each with the styles the terminal painted over its own characters (round 5 colour
//! owner).
//! 6. **Use the correct view of terminal output.** A pseudo-console writes its own sequences into
//! the same stream as the child's output. Windows opens a session with a cursor question, mode
//! switches, and a window title that contains the binary path
//! (`\x1b]0;D:\a\...\skit.exe\x07`). [`strip_terminal_control`] gives a text history for a
//! line-oriented assertion. It does not apply cursor movement or erase commands. A full-screen
//! assertion must use [`final_terminal_screen`]. A color assertion uses
//! [`visible_with_styles`] and [`styles_over`] to read the styles over each history line.
//!
//! Two harness families share these rules. [`PtyChild`] is the full channel-driven harness.
//! The free functions ([`keystrokes`], [`settle_buffer`], [`wait_for_exit`]) serve the bespoke
Expand Down Expand Up @@ -296,6 +294,11 @@ impl PtyChild {
let _ = self.writer.flush();
}

/// Change the terminal window size while the child owns it.
pub(crate) fn resize(&mut self, size: PtySize) {
self.master.resize(size).unwrap();
}

/// Wait for `prompt`, then type `answer` (invariants 1 and 2 together).
pub(crate) fn send_after_prompt(&mut self, prompt: &str, answer: &[u8]) {
self.expect(prompt);
Expand Down Expand Up @@ -483,12 +486,12 @@ pub(crate) fn wait_for_exit(child: &mut Box<dyn portable_pty::Child + Send + Syn
}
}

/// The text a person sees, with the terminal's own sequences removed (invariant 6).
/// The terminal text history, with control sequences removed (invariant 6).
///
/// Drops CSI sequences (`ESC [` up to a final byte), OSC sequences (`ESC ]` up to `BEL` or
/// `ESC \`), any other single escape, and the carriage returns a terminal uses to return to the
/// left margin. What remains is the child's printable output, which an assertion can measure or
/// match.
/// left margin. What remains can include cells that a later frame replaced. Do not use it to
/// assert the final state of a full-screen interface.
pub(crate) fn strip_terminal_control(input: &str) -> String {
let bytes = input.as_bytes();
let mut output = Vec::with_capacity(bytes.len());
Expand Down Expand Up @@ -536,6 +539,16 @@ pub(crate) fn strip_terminal_control(input: &str) -> String {
String::from_utf8_lossy(&output).into_owned()
}

/// Replay terminal output and return only the current terminal grid.
///
/// This applies cursor movement, erase commands, and alternate-screen changes. Use it for a
/// full-screen assertion. [`strip_terminal_control`] is only a history view.
pub(crate) fn final_terminal_screen(input: &[u8], rows: u16, columns: u16) -> String {
let mut terminal = vt100::Parser::new(rows, columns, 0);
terminal.process(input);
terminal.screen().contents()
}

/// One line a terminal showed, with the styles it painted over that line's own characters.
#[derive(Debug)]
pub(crate) struct StyledLine {
Expand Down
Loading
Loading