waechter 4 (dead code): functions of the decision modules with zero hits in an lcov report of the live line over the gate requests plus the suite fail (allow list docs/notizen/TOTCODE-AUSNAHMEN.md); coverage script waechter/abdeckung.sh

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Marc Mintel
2026-12-05 21:07:08 +01:00
co-authored by Claude Opus 5.5
parent f6f491eb26
commit 6c2ce56cd0
2 changed files with 73 additions and 0 deletions
@@ -104,6 +104,44 @@ fn ausnahmen(text: &str) -> Vec<(String, String)> {
.collect()
}
/// Waechter 4, toter Code: aus einem lcov-Bericht (FN/FNDA-Zeilen) die Funktionen der Entscheidungsmodule ohne Treffer. Der Bericht entsteht aus dem
/// Lauf der Live-Zeile ueber die Tor-Anfragen plus der Testsuite (entscheiden/motor/waechter/abdeckung.sh). Ausnahmen: docs/notizen/TOTCODE-AUSNAHMEN.md
/// (Datei | Funktion | Begruendung).
pub fn tote_funktionen(lcov: &str) -> Vec<(String, String)> {
let mut aus = Vec::new();
let mut datei = String::new();
let mut namen: BTreeMap<String, String> = BTreeMap::new();
let mut treffer: BTreeMap<String, u64> = BTreeMap::new();
let mut fertig = |datei: &str, namen: &mut BTreeMap<String, String>, treffer: &mut BTreeMap<String, u64>, aus: &mut Vec<(String, String)>| {
let kurz = datei.rsplit('/').next().unwrap_or(datei).to_string();
if ENTSCHEIDUNGS_MODULE.contains(&kurz.as_str()) {
for (roh, lesbar) in namen.iter() {
if treffer.get(roh).copied().unwrap_or(0) == 0 && !lesbar.contains("::spec::") && !lesbar.contains("{closure") {
aus.push((kurz.clone(), lesbar.clone()));
}
}
}
namen.clear();
treffer.clear();
};
for z in lcov.lines() {
if let Some(d) = z.strip_prefix("SF:") {
datei = d.to_string();
} else if let Some(f) = z.strip_prefix("FN:") {
if let Some((_, n)) = f.split_once(',') {
namen.insert(n.to_string(), n.to_string());
}
} else if let Some(f) = z.strip_prefix("FNDA:") {
if let Some((h, n)) = f.split_once(',') {
*treffer.entry(n.to_string()).or_default() += h.parse::<u64>().unwrap_or(0);
}
} else if z == "end_of_record" {
fertig(&datei, &mut namen, &mut treffer, &mut aus);
}
}
aus
}
#[cfg(test)]
mod spec {
use super::*;
@@ -115,6 +153,25 @@ mod spec {
assert_eq!(f, vec![(1, "0.8".to_string()), (3, "12".to_string()), (6, "0.25".to_string())]);
}
#[test]
fn tote_funktionen_aus_lcov() {
let l = "SF:/x/src/dienst.rs\nFN:10,_RNvf\nFN:20,_RNvg\nFNDA:3,_RNvf\nFNDA:0,_RNvg\nend_of_record\nSF:/x/src/main.rs\nFN:1,_RNvh\nFNDA:0,_RNvh\nend_of_record\n";
assert_eq!(tote_funktionen(l), vec![("dienst.rs".to_string(), "_RNvg".to_string())]);
}
/// Waechter 4 auf einem Abdeckungsbericht (WAECHTER_LCOV=<lcov.info>); rot, solange eine Entscheidungsfunktion nie laeuft und nicht begruendet ist.
#[test]
fn waechter_totcode() {
let Ok(p) = std::env::var("WAECHTER_LCOV") else { return };
let liste = std::fs::read_to_string(PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../docs/notizen/TOTCODE-AUSNAHMEN.md")).unwrap_or_default();
let tot: Vec<String> = tote_funktionen(&std::fs::read_to_string(p).unwrap())
.into_iter()
.filter(|(d, f)| !liste.lines().any(|z| z.contains(d.as_str()) && z.contains(f.as_str())))
.map(|(d, f)| format!("{d}: {f}"))
.collect();
assert!(tot.is_empty(), "Totcode-Waechter: {} Funktionen ohne Treffer\n{}", tot.len(), tot.join("\n"));
}
/// Der Waechter selbst: rot, solange ein Entscheidungsmodul freie Zahlen enthaelt, die nicht auf der Positivliste stehen.
#[test]
fn waechter_konstanten() {
+16
View File
@@ -0,0 +1,16 @@
#!/bin/sh
# Waechter 4: Abdeckung der Live-Zeile ueber die Tor-Anfragen plus Testsuite -> lcov.info; danach
# WAECHTER_LCOV=<lcov.info> cargo test --release waechter_totcode
# Aufruf: abdeckung.sh <ein.jsonl> <live-zeile.txt (K=V;K=V)> <daten-ordner> <aus-ordner>
# Laeuft lange (instrumentierter Motor, jede Anfrage mit Frist wie live); nur ohne anderen Lauf auf der Maschine.
set -e
EIN="$1"; ZEILE="$2"; D="$3"; AUS="$4"
mkdir -p "$AUS"
cd "$(dirname "$0")/.."
eval "$(cargo llvm-cov show-env --export-prefix)"
cargo llvm-cov clean --workspace
cargo build --release -j 4
env $(tr ';' ' ' < "$ZEILE") ./target/release/motor dienst sechs100 "$D" 2000-600-400 200 "$D/sechs100-v2.bin" genau "hu=$D/hu100-v1.bin,$D/hu200-v2.bin" < "$EIN" > "$AUS/antworten.jsonl"
cargo test --release -j 4 || true
cargo llvm-cov report --release --lcov --output-path "$AUS/lcov.info"
echo "lcov: $AUS/lcov.info"