Building 70 Projects ranging from beginner to advanced so anyone can β learn from, build upon, use as a reference, or even copy directly. Owned by my cybersecurity company π
Go aicertificationcloud-engineeringcybercybersecuritycybersecurity-analystcybersecurity-certificationcybersecurity-certificationscybersecurity-educationcybersecurity-jobscybersecurity-portfoliocybersecurity-projectscybersecurity-toolsgrchackinglearningpentestingproject-repositoryprojetcspython
feat(lisdex): B12 - a failing step reports what the tool diagnosed, not thirteen lines of "yes"
CarterPerez-dev877d7c8ed1c5
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/ladder.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/ladder.rsindex 090baddb..aa6fcfaa 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/ladder.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/ladder.rs@@ -20,6 +20,7 @@ pub const LOG_EXTENSION: &str = "log";const PREPASS_VARIANT_SUFFIX: &str = "-prepass";const LABEL_PREPASS: &str = "prepass";+const FAILURE_DIAGNOSIS_LINES: usize = 15;const LABEL_INSTRUMENTED: &str = "instrumented";const LABEL_CAPTURE: &str = "capture";const CONFIGURE_ONLY_LABEL: &str = "configure-only";@@ -254,7 +255,7 @@ fn execute("step {} failed ({:?}): {}",step.name,execution.code,- execution.tail(15)+ execution.diagnosis(FAILURE_DIAGNOSIS_LINES))};return Ok((outcomes, Some(reason)));diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/process.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/process.rsindex 1e88d005..edc9c557 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/process.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/process.rs@@ -146,6 +146,26 @@ impl Execution {let start = collected.len().saturating_sub(lines);collected[start..].join("\n")}++ // A tool writes progress to stdout and its verdict to stderr, so a window over the+ // combined capture is mostly chatter. Measured on a build that fails for a missing+ // dependency: of the fifteen lines reported, thirteen were `checking for stdio.h... yes`+ // and the two naming the cause were last. This reports what the tool actually+ // diagnosed. The whole capture is still written to the step's log either way, so+ // nothing is lost - only the failure LINE gets shorter and truer.+ #[must_use]+ pub fn diagnosis(&self, lines: usize) -> String {+ let collected: Vec<&str> = self+ .stderr+ .lines()+ .filter(|line| !line.trim().is_empty())+ .collect();+ if collected.is_empty() {+ return self.tail(lines);+ }+ let start = collected.len().saturating_sub(lines);+ collected[start..].join("\n")+ }}#[must_use]@@ -469,4 +489,47 @@ mod tests {let run = run(&spec, Duration::from_secs(10)).unwrap();assert_eq!(run.tail(2), "two\nthree");}++ #[test]+ fn a_diagnosis_reports_what_the_tool_wrote_to_stderr_not_its_progress() {+ let spec = CommandSpec::new("sh").args([+ "-c",+ "for i in 1 2 3 4 5 6 7 8 9; do echo \"checking for header $i... yes\"; done; \+ echo 'configure: error: liblzma is required' >&2; exit 1",+ ]);+ let run = run(&spec, Duration::from_secs(10)).unwrap();+ assert!(!run.success);+ assert_eq!(+ run.diagnosis(15),+ "configure: error: liblzma is required",+ "a window over the combined capture buries the cause under nine successful \+ probes, which is what a missing dependency looked like before"+ );+ assert!(+ run.tail(15).contains("checking for header 9"),+ "the whole capture is still there for the step log"+ );+ }++ #[test]+ fn a_tool_that_says_nothing_on_stderr_still_reports_its_output() {+ let spec = CommandSpec::new("sh").args(["-c", "printf 'only\\nstdout\\nhere\\n'; exit 1"]);+ let run = run(&spec, Duration::from_secs(10)).unwrap();+ assert_eq!(+ run.diagnosis(2),+ "stdout\nhere",+ "some tools report their failure on stdout, and reporting nothing at all would \+ be worse than reporting chatter"+ );+ }++ #[test]+ fn blank_stderr_lines_do_not_crowd_out_the_diagnosis() {+ let spec = CommandSpec::new("sh").args([+ "-c",+ "printf 'progress\\n'; printf '\\n\\n\\nld: cannot find -lz\\n' >&2; exit 1",+ ]);+ let run = run(&spec, Duration::from_secs(10)).unwrap();+ assert_eq!(run.diagnosis(2), "ld: cannot find -lz");+ }}