From 8a23867246d98474f28799a292a92640e5e0f8b4 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Thu, 26 Nov 2026 23:23:11 +0000 Subject: [PATCH] fix: give each `eb-junit` case a unique name A recorded name can hold a character that the report format forbids, and `eb-junit` drops it while escaping. The escaped name could then match a generated ` #N` suffix on another line, because `disambiguate` counted only the recorded name. Two cases came out as `cpu/A.eb #2`, and GitLab keeps only the first case with a given name. Keep numbering until the escaped name is free. --- changelog.d/+junit-case-name.bugfix.md | 3 +++ src/bin/eb-junit.rs | 32 +++++++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 changelog.d/+junit-case-name.bugfix.md diff --git a/changelog.d/+junit-case-name.bugfix.md b/changelog.d/+junit-case-name.bugfix.md new file mode 100644 index 0000000..86a319c --- /dev/null +++ b/changelog.d/+junit-case-name.bugfix.md @@ -0,0 +1,3 @@ +`eb-junit` now gives every case a unique name. A case whose name lost +a character during escaping could share a name with another case, +and GitLab then showed only one of them. diff --git a/src/bin/eb-junit.rs b/src/bin/eb-junit.rs index 55fd1e2..65ee167 100644 --- a/src/bin/eb-junit.rs +++ b/src/bin/eb-junit.rs @@ -5,7 +5,7 @@ use eb_pipeline::{exit, run, util}; use serde_json::{Map, Number, Value}; -use std::collections::BTreeMap; +use std::collections::{BTreeMap, BTreeSet}; use std::ffi::OsString; use std::path::{Path, PathBuf}; use std::process::ExitCode; @@ -639,16 +639,16 @@ fn write_case(out: &mut String, class: &str, case: &Case) { } fn disambiguate(names: &[String]) -> Vec { - let mut seen = BTreeMap::::new(); + let mut used = BTreeSet::new(); let mut out = Vec::with_capacity(names.len()); for name in names { - let n = seen.entry(escape_attr(name)).or_insert(0); - *n += 1; - if *n == 1 { - out.push(name.clone()); - } else { - out.push(format!("{name} #{n}")); + let mut n = 1usize; + let mut candidate = name.clone(); + while !used.insert(escape_attr(&candidate)) { + n += 1; + candidate = format!("{name} #{n}"); } + out.push(candidate); } out } @@ -855,6 +855,22 @@ mod tests { assert!(xml.contains("name=\"cpu/Ok-1.0.eb #2\"")); } + #[test] + fn a_numbered_suffix_does_not_reuse_another_xml_safe_name() { + let text = concat!( + r#"{"schema_version":1,"kind":"result","site":"example","target":"cpu","#, + r#""build_type":"production","run_id":"n","exit_code":1,"lines":["#, + r#"{"easyconfig":"A.eb","unit":"all","phase":"build","status":"failed"},"#, + r#"{"easyconfig":"A.eb","unit":"all","phase":"build","status":"failed"},"#, + "{\"easyconfig\":\"A\\u0001.eb #2\",\"unit\":\"all\",\"phase\":\"build\",\"status\":\"failed\"}", + "]}" + ); + let xml = render(text).unwrap(); + assert_eq!(xml.matches("name=\"cpu/A.eb\"").count(), 1, "{xml}"); + assert_eq!(xml.matches("name=\"cpu/A.eb #2\"").count(), 1, "{xml}"); + assert_eq!(xml.matches("name=\"cpu/A.eb #2 #2\"").count(), 1, "{xml}"); + } + #[test] fn a_run_that_stops_before_a_line_fails_is_one_exit_case() { let text = r#"{