requirements.test-coverage.processes.progress.terminal
Requirements index · View definition
Requirement
Habeas coverage progress MUST be displayed when stderr is an interactive terminal and
TERMis notdumb.NO_COLORMUST disable color without disabling progress. When stderr is redirected orTERM=dumb, Habeas coverage progress MUST NOT emit animation or terminal control sequences.Temporary progress displays MUST be cleared when their stage ends, including empty work and early collection failures. Final diagnostics and the coverage artifact location MUST remain readable. Progress reporting MUST NOT change coverage results, retained profiles, or command exit status.
Rationale
I judge the tests adequate for requirements.test-coverage.processes.progress.terminal. I did not request implementation source. Each obligation maps to a marked test as follows.
Display policy (shown on an interactive stderr when TERM is not dumb; hidden otherwise)
src/execution_coverage/progress.rs#mod[tests]/fn[terminal_policy_and_hidden_progress_emit_no_display]checksenabled(terminal, term)for five cases:- terminal with
TERMunset gives true. - terminal with
xtermgives true. - terminal with
dumbgives false. - non-terminal with
TERMunset gives false. - non-terminal with
xtermgives false.
- terminal with
- The same test checks that a
Progresswith no target creates no bar. Itscompletedandstagecalls are no-ops. tests/execution_coverage.rs#fn[coverage_progress_on_a_pty_preserves_reports_and_plain_output_policy]runs the real binary on a PTY withTERM=xterm. It asserts that the “Preparing coverage” stages, “Converting coverage”, “1/1 attempts” and the elapsed timer all appear. It also asserts that escape sequences appear, so the display updates in place. Stdout is piped while stderr is the PTY, so the decision is tied to stderr.
NO_COLOR disables color but not progress
- The PTY run sets
NO_COLOR=1withxterm. It asserts the progress text is present and that there is no\x1b[3color sequence. - The unit test
stage_and_conversion_counts_are_visible_then_clearedalso asserts the rendered display contains no\x1b[.
Redirected stderr or TERM=dumb: no animation or control sequences
- The PTY run with
TERM=dumbasserts there is no “Converting coverage” and no\x1b[. - The run through the
coverage()helper has stderr redirected. It asserts there is no “Converting coverage” and no\x1b[.
Temporary displays cleared when the stage ends, including empty work and early failures
- In the unit test, dropping a preparation
Progressincreases the clear count. - In the unit test, conversion with
totalof 2 and withtotalof 0 (empty work) must each increase the clear count on drop. - The same test asserts the “n/total attempts” counts are visible while the stage runs.
- The PTY runs cover a success, a test failure (
deliberate_failure) and a missing profile (missing_profile, with 0 processes).assert_conversion_clearedrequires\x1b[2Kbetween the last “1/1 attempts” and “Coverage retained in”. - The preparation-failure case uses an unreadable
input.data. It asserts\x1b[2Kbetween the “recording inputs” stage and “Coverage preparation failed”. This is the early-collection-failure case.
Final diagnostics and artifact location stay readable
assert_conversion_clearedasserts that “Coverage retained in” is present and that no escape sequence follows it.- The preparation-failure case asserts there are no escape sequences after “Coverage preparation failed”.
- The
missing_profilecase asserts the “coverage: “ and “partial profiles and reports have been retained” diagnostics are present.
Progress does not change results, retained profiles or exit status
- Exit status is asserted per case: success for the xterm and dumb runs, and the expected failure or success for the
child_process,deliberate_failureandmissing_profilefilters. - Saved attempt records are checked for outcome, process count, and non-empty
linesandfunctions. - Line and function data from the PTY runs are compared with data from the non-PTY run.
Residual risk
- A terminal stdout with redirected stderr is not tested. The PTY test pipes stdout and puts only stderr on the terminal, so the stderr-based decision is exercised, and the redirected case is covered through the
coverage()helper. - This is an untested combination, not a named obligation, so I do not count it as a gap.
Inputs
Tests
Input 2: outline src/execution_coverage/progress.rs mod[tests]/fn[stage_and_conversion_counts_are_visible_then_cleared]
- File:
src/execution_coverage/progress.rs - Selector:
mod[tests]/fn[stage_and_conversion_counts_are_visible_then_cleared] - Kind:
fn src/execution_coverage/progress.rs:164–212
// {test}`requirements.test-coverage.processes.progress`
// {test}`requirements.test-coverage.processes.progress.preparation`
// {test}`requirements.test-coverage.processes.progress.terminal`
#[test]
fn stage_and_conversion_counts_are_visible_then_cleared() {
let terminal = RecordingTerm::default();
let target = || Some(ProgressDrawTarget::term_like(Box::new(terminal.clone())));
{
let preparation = Progress::with_target("Recording inputs", None, target());
assert!(terminal.text.lock().unwrap().contains("Recording inputs"));
preparation.stage("Capturing coverage maps");
assert!(
terminal
.text
.lock()
.unwrap()
.contains("Capturing coverage maps")
);
let before_drop = *terminal.clears.lock().unwrap();
drop(preparation);
assert!(*terminal.clears.lock().unwrap() > before_drop);
}
let cleared = *terminal.clears.lock().unwrap();
assert!(cleared > 0);
for total in [0, 2] {
let conversion = Progress::with_target("Converting coverage", Some(total), target());
let bar = conversion.bar.as_ref().unwrap();
assert_eq!(bar.position(), 0);
for expected in 1..=total {
conversion.completed();
bar.force_draw();
assert_eq!(bar.position(), expected as u64);
let text = terminal.text.lock().unwrap();
assert!(
text.contains(&format!("{expected}/{total} attempts")),
"{text}"
);
assert!(text.contains("[00:00:"));
assert!(!text.contains("\x1b["), "display must be monochrome");
}
let before_drop = *terminal.clears.lock().unwrap();
drop(conversion);
assert!(
*terminal.clears.lock().unwrap() > before_drop,
"completed and empty displays must both clear on drop"
);
}
assert!(*terminal.clears.lock().unwrap() > cleared);
}
Input 3: outline src/execution_coverage/progress.rs mod[tests]/fn[terminal_policy_and_hidden_progress_emit_no_display]
- File:
src/execution_coverage/progress.rs - Selector:
mod[tests]/fn[terminal_policy_and_hidden_progress_emit_no_display] - Kind:
fn src/execution_coverage/progress.rs:245–261
// {test}`requirements.test-coverage.processes.progress.terminal`
#[test]
fn terminal_policy_and_hidden_progress_emit_no_display() {
for (terminal, term, expected) in [
(true, None, true),
(true, Some("xterm"), true),
(true, Some("dumb"), false),
(false, None, false),
(false, Some("xterm"), false),
] {
assert_eq!(enabled(terminal, term.map(std::ffi::OsStr::new)), expected);
}
let hidden = Progress::with_target("Converting coverage", Some(1), None);
hidden.completed();
hidden.stage("No display");
assert!(hidden.bar.is_none());
}
Input 4: outline tests/execution_coverage.rs fn[coverage_progress_on_a_pty_preserves_reports_and_plain_output_policy]
- File:
tests/execution_coverage.rs - Selector:
fn[coverage_progress_on_a_pty_preserves_reports_and_plain_output_policy] - Kind:
fn tests/execution_coverage.rs:104–295
// {test}`requirements.test-coverage.processes.progress`
// {test}`requirements.test-coverage.processes.progress.preparation`
// {test}`requirements.test-coverage.processes.progress.terminal`
#[cfg(target_os = "linux")]
#[test]
fn coverage_progress_on_a_pty_preserves_reports_and_plain_output_policy() {
use std::io::Read;
use std::os::fd::FromRawFd;
#[link(name = "util")]
unsafe extern "C" {
fn openpty(
master: *mut std::ffi::c_int,
slave: *mut std::ffi::c_int,
name: *mut std::ffi::c_char,
termios: *const std::ffi::c_void,
winsize: *const std::ffi::c_void,
) -> std::ffi::c_int;
}
let temp = fixture();
let root = temp.path();
let source = fs::read_to_string(root.join("src/lib.rs")).unwrap();
fs::write(root.join("src/lib.rs"), format!("{source}\n#[test] fn deliberate_failure() {{ panic!(\"fixture failure\"); }}\nunsafe extern \"C\" {{ fn _exit(status: i32) -> !; }}\n#[test] fn missing_profile() {{ unsafe {{ _exit(0) }} }}\n")).unwrap();
let run_on_pty = |term: &str, filter: &str| {
let mut master = -1;
let mut slave = -1;
// The returned descriptors are owned by this test and transferred
// exactly once into File. Default terminal settings are sufficient.
assert_eq!(
unsafe {
openpty(
&mut master,
&mut slave,
std::ptr::null_mut(),
std::ptr::null(),
std::ptr::null(),
)
},
0
);
let mut master = unsafe { fs::File::from_raw_fd(master) };
let slave = unsafe { fs::File::from_raw_fd(slave) };
let reader = std::thread::spawn(move || {
let mut output = Vec::new();
if let Err(error) = master.read_to_end(&mut output) {
// Linux returns EIO when the last slave descriptor closes.
assert_eq!(error.raw_os_error(), Some(5));
}
output
});
let child = Command::new(env!("CARGO_BIN_EXE_habeas"))
.args(["coverage", "--", "-E", filter, "--color=never"])
.current_dir(root)
.env("CARGO_NET_OFFLINE", "true")
.env("TERM", term)
.env("NO_COLOR", "1")
.env_remove("CARGO_TARGET_DIR")
.env_remove("CARGO_BUILD_TARGET_DIR")
.env_remove("RUSTC_WORKSPACE_WRAPPER")
.env_remove("HABEAS_PREVIOUS_WORKSPACE_WRAPPER")
.env_remove("HABEAS_COVERAGE_RUN")
.env_remove("HABEAS_COVERAGE_FEATURE_LEDGER")
.stdin(std::process::Stdio::null())
.stdout(std::process::Stdio::piped())
.stderr(slave)
.spawn()
.unwrap();
let mut output = child.wait_with_output().unwrap();
output.stderr = reader.join().unwrap();
output
};
let assert_conversion_cleared = |text: &str| {
let count = text.rfind("1/1 attempts").unwrap();
let location = text.find("Coverage retained in ").unwrap();
assert!(text[count..location].contains("\x1b[2K"), "{text}");
assert!(
!text[location..].contains("\x1b["),
"final reports must remain plain and readable: {text}"
);
};
for term in ["xterm", "dumb"] {
let output = run_on_pty(term, "test(second)");
assert_success(&output);
let text = String::from_utf8_lossy(&output.stderr);
if term == "xterm" {
assert!(
text.contains("Preparing coverage: recording inputs"),
"{text}"
);
assert!(
text.contains("Preparing coverage: capturing maps"),
"{text}"
);
assert!(text.contains("Converting coverage"), "{text}");
assert!(text.contains("1/1 attempts"), "{text}");
assert!(text.contains("[00:"), "{text}");
assert!(
text.contains("\x1b["),
"PTY progress should update in place"
);
assert!(!text.contains("\x1b[3"), "NO_COLOR must suppress color");
assert_conversion_cleared(&text);
} else {
assert!(!text.contains("Converting coverage"), "{text}");
assert!(!text.contains("\x1b["), "{text}");
}
assert!(text.contains("Coverage retained in "), "{text}");
let saved = runs(root);
let records = attempts(&saved.last().unwrap().0);
assert_eq!(records.len(), 1);
assert_eq!(records[0]["outcome"], "success");
assert_eq!(records[0]["processes"].as_array().unwrap().len(), 1);
assert!(
!records[0]["processes"][0]["lines"]
.as_object()
.unwrap()
.is_empty()
);
}
let output = coverage(root, &["-E", "test(second)", "--color=never"]);
assert_success(&output);
let text = String::from_utf8_lossy(&output.stderr);
assert!(!text.contains("Converting coverage"), "{text}");
assert!(!text.contains("\x1b["), "{text}");
let saved = runs(root);
let first = attempts(&saved[0].0);
for (run, _) in &saved[1..] {
let records = attempts(run);
assert_eq!(
records[0]["processes"][0]["lines"],
first[0]["processes"][0]["lines"]
);
assert_eq!(
records[0]["processes"][0]["functions"],
first[0]["processes"][0]["functions"]
);
}
for (filter, succeeds, outcome, processes) in [
("test(child_process)", true, "success", 2),
("test(deliberate_failure)", false, "failed", 1),
("test(missing_profile)", false, "success", 0),
] {
let output = run_on_pty("xterm", filter);
assert_eq!(
output.status.success(),
succeeds,
"{}",
String::from_utf8_lossy(&output.stderr)
);
let text = String::from_utf8_lossy(&output.stderr);
assert_conversion_cleared(&text);
if processes == 0 {
assert!(text.contains("coverage: "), "{text}");
assert!(
text.contains("partial profiles and reports have been retained"),
"{text}"
);
}
let saved = runs(root);
let records = attempts(&saved.last().unwrap().0);
assert_eq!(records.len(), 1);
assert_eq!(records[0]["outcome"], outcome);
assert_eq!(records[0]["processes"].as_array().unwrap().len(), processes);
for process in records[0]["processes"].as_array().unwrap() {
assert!(!process["lines"].as_object().unwrap().is_empty());
assert!(process["functions"].is_array());
}
}
// An error during preparation must also clear the stage before the CLI
// prints its diagnostic, without manufacturing test attempts.
use std::os::unix::fs::PermissionsExt;
fs::write(
root.join("build.rs"),
"fn main() { println!(\"cargo::rerun-if-changed=input.data\"); }\n",
)
.unwrap();
let input = root.join("input.data");
fs::write(&input, "unreadable input").unwrap();
fs::set_permissions(&input, fs::Permissions::from_mode(0o000)).unwrap();
let output = run_on_pty("xterm", "test(second)");
fs::set_permissions(input, fs::Permissions::from_mode(0o600)).unwrap();
assert!(!output.status.success());
let text = String::from_utf8_lossy(&output.stderr);
let stage = text.rfind("Preparing coverage: recording inputs").unwrap();
let diagnostic = text.find("Coverage preparation failed").unwrap();
assert!(text[stage..diagnostic].contains("\x1b[2K"), "{text}");
assert!(!text[diagnostic..].contains("\x1b["), "{text}");
let saved = runs(root);
assert_eq!(saved.last().unwrap().1["outcome"], "failed");
assert!(attempts(&saved.last().unwrap().0).is_empty());
}
Other sources
Input 1: requirements selection requirements.test-coverage.processes.progress.terminal
requirements.test-coverage.processes.progress.terminal:md/requirements/test-coverage.md:83–93
:::{req} processes.progress.terminal
Habeas coverage progress MUST be displayed when stderr is an interactive
terminal and `TERM` is not `dumb`. `NO_COLOR` MUST disable color without
disabling progress. When stderr is redirected or `TERM=dumb`, Habeas coverage
progress MUST NOT emit animation or terminal control sequences.
Temporary progress displays MUST be cleared when their stage ends, including
empty work and early collection failures. Final diagnostics and the coverage
artifact location MUST remain readable. Progress reporting MUST NOT change
coverage results, retained profiles, or command exit status.
:::