Auto-Tests im Testfenster ausführen und als auto-lauf-Bericht speichern (#1037)

Schaltfläche „Auto-Tests ausführen“: führt die auto-Tests aus KLICKTESTS.md nacheinander im Hintergrund aus.
Ausgeführt werden nur cargo test <Filter> und python3 -m unittest tools/<datei>.py, ohne Shell und mit geprüften
Teilen; ein Lauf gilt nur als bestanden, wenn mindestens ein Test lief. Der Bericht hat die Art auto-lauf.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-02 11:52:41 +01:00
parent 5159119c5e
commit 188269375d
5 changed files with 871 additions and 5 deletions

View File

@ -252,6 +252,59 @@ pub fn write_report(
Ok(path)
}
/// Text eines Berichts der Art `auto-lauf`: je Test eine Zeile `- id: ✓ Notiz`; Gesamtergebnis ✓, wenn alle bestanden.
pub fn auto_report_text(
results: &[(String, bool, String)],
zeit: &str,
commit: &str,
hint: &str,
) -> String {
let all_ok = results.iter().all(|(_, ok, _)| *ok);
let mut out = format!(
"---\ntest: auto-lauf\nzeit: {zeit}\ncommit: {commit}\nart: auto-lauf\nergebnis: {}\n---\n",
if all_ok { "✓" } else { "✗" }
);
for (id, ok, note) in results {
let note = note.split_whitespace().collect::<Vec<_>>().join(" ");
out.push_str(&format!("- {id}: {}", if *ok { "✓" } else { "✗" }));
if !note.is_empty() {
out.push(' ');
out.push_str(&note);
}
out.push('\n');
}
let hint = hint.split_whitespace().collect::<Vec<_>>().join(" ");
if !hint.is_empty() {
out.push_str(&hint);
out.push('\n');
}
out
}
/// Schreibt einen `auto-lauf`-Bericht und überschreibt nie eine vorhandene Datei.
pub fn write_auto_report(
dir: &Path,
results: &[(String, bool, String)],
zeit: &str,
commit: &str,
hint: &str,
) -> Result<PathBuf, String> {
if results.is_empty() {
return Err("Kein Ergebnis zum Speichern.".into());
}
std::fs::create_dir_all(dir).map_err(|e| format!("{}: {e}", dir.display()))?;
let path = dir.join(report_file_name(zeit, "auto-lauf"));
if path.exists() {
return Err(format!(
"{} gibt es schon (gleiche Minute); eine Minute warten.",
path.display()
));
}
std::fs::write(&path, auto_report_text(results, zeit, commit, hint))
.map_err(|e| format!("{}: {e}", path.display()))?;
Ok(path)
}
/// Kurz-Hash des aktuellen Commits und ob der Arbeitsordner ungespeicherte Änderungen hat.
pub fn git_state(repo: &Path) -> (String, bool) {
let run = |args: &[&str]| {
@ -432,6 +485,52 @@ mod tests {
assert_eq!(next_open_manual(&p, &[], None, Some("gibt-es-nicht")), None);
}
#[test]
fn auto_report_has_one_line_per_test_and_round_trips() {
let results = vec![
(
"mikro2pegel.4".to_string(),
true,
"cargo test pitch:: – 12 Tests bestanden".to_string(),
),
(
"chart2score.4".to_string(),
false,
"fehlgeschlagen: a\nb".to_string(),
),
("x2y.1".to_string(), true, String::new()),
];
let text = auto_report_text(&results, "2026-11-02 10:00", "abc1234", "Hinweis: Probe");
assert!(text.ends_with("Hinweis: Probe\n"));
assert!(
text.contains("ergebnis: ✗\n---\n"),
"ein ✗ macht das Gesamtergebnis ✗"
);
assert!(
text.contains("- chart2score.4: ✗ fehlgeschlagen: a b\n"),
"Zeilenumbrüche in der Notiz werden Leerzeichen"
);
assert!(text.contains("- x2y.1: ✓\n"));
let runs = parse_report("2026-11-02_1000_auto-lauf.md", &text);
assert_eq!(runs.len(), 3);
assert_eq!(
(runs[1].id.as_str(), runs[1].ok, runs[1].note.as_str()),
("chart2score.4", false, "fehlgeschlagen: a b")
);
assert!(auto_report_text(&results[..1], "z", "c", "").contains("ergebnis: ✓"));
}
#[test]
fn auto_report_is_never_overwritten_and_needs_results() {
let d = tmp("autoreport");
let r = vec![("a2b.1".to_string(), true, String::new())];
assert!(write_auto_report(&d, &[], "2026-11-02 10:00", "abc", "").is_err());
assert!(write_auto_report(&d, &r, "2026-11-02 10:00", "abc", "").is_ok());
assert!(write_auto_report(&d, &r, "2026-11-02 10:00", "abc", "").is_err());
assert_eq!(load_runs(&d).len(), 1);
std::fs::remove_dir_all(&d).unwrap();
}
#[test]
fn report_has_checker_format() {
let t = parse_tests(SAMPLE)[0].tests[0].clone();
@ -507,6 +606,26 @@ mod tests {
"Fehler",
)
.unwrap();
// Auch ein Bericht der Art auto-lauf muss das Prüfskript bestehen.
write_auto_report(
&d.join("testberichte"),
&[
(
t.id.clone(),
true,
"cargo test x:: – 3 Tests bestanden".to_string(),
),
(
"unbekannt2test.9".to_string(),
false,
"fehlgeschlagen: x".to_string(),
),
],
"2026-11-02 09:32",
"abc1234",
"Hinweis: Probe",
)
.unwrap();
let out = std::process::Command::new("python3")
.arg(repo.join("tools/check-roadmap.py"))
.arg(&d)