From dfe914499467ed2c1a49d79456d777fb2ffbb1c8 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 15 Oct 2026 12:36:29 +0000 Subject: [PATCH] scripts: match cargo's colored lines in a failed stage's summary CI sets CARGO_TERM_COLOR=always, so cargo writes its own lines with terminal colors, and the summary that #107 added did not match cargo's "error: test failed, to rerun pass ..." line: #108's Integration failure printed the failed test and its panic but not the target to re-run. Colors are now removed before a line is matched. Co-Authored-By: Claude Opus 5.5 (1M context) --- scripts/tests/test_upstream.py | 10 ++++++++++ scripts/validate-upstream.py | 7 +++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/scripts/tests/test_upstream.py b/scripts/tests/test_upstream.py index e44a758..94c212c 100644 --- a/scripts/tests/test_upstream.py +++ b/scripts/tests/test_upstream.py @@ -283,6 +283,16 @@ def test_failure_lines_are_names_counts_and_locations_only(self): log.write_text('\n'.join(output + named + named) + '\n') self.assertEqual(validation.failure_lines(log), named) + def test_cargo_lines_match_without_their_colors(self): + with tempfile.TemporaryDirectory() as tmp: + log = Path(tmp) / 'stage.log' + log.write_text('\x1b[1m\x1b[91merror\x1b[0m: test failed, to rerun pass `-p codespace-server --lib`\n' + '\x1b[1m\x1b[91merror\x1b[0m: could not compile `codespace-server` (lib test) due to 1 previous error\n' + '\x1b[1m\x1b[32m Running\x1b[0m unittests src/lib.rs\n') + self.assertEqual(validation.failure_lines(log), [ + 'error: test failed, to rerun pass `-p codespace-server --lib`', + 'error: could not compile `codespace-server` (lib test) due to 1 previous error']) + def test_an_unreadable_log_or_many_failures_keep_the_summary_short(self): with tempfile.TemporaryDirectory() as tmp, contextlib.redirect_stdout(io.StringIO()) as printed: log = Path(tmp) / 'unit-pty.log' diff --git a/scripts/validate-upstream.py b/scripts/validate-upstream.py index 66c8149..8174da0 100644 --- a/scripts/validate-upstream.py +++ b/scripts/validate-upstream.py @@ -192,12 +192,15 @@ def execute(commands, env, log): r'FAILED \([\w ]+=\d+(?:, [\w ]+=\d+)*\)'])) # Enough for one test binary's failures; the log keeps the rest. FAILURES_SHOWN = 40 +# The terminal colors of cargo's own lines, which CI asks for with CARGO_TERM_COLOR. +COLOR = re.compile(r'\x1b\[[0-9;]*m') def failure_lines(path): - """The lines of a stage's log that FAILURE_LINE matches, each once, in order.""" + """The lines of a stage's log that FAILURE_LINE matches without their colors, each once, in + order.""" with path.open(encoding='utf-8', errors='replace') as log: - lines = (line.strip() for line in log) + lines = (COLOR.sub('', line).strip() for line in log) return list(dict.fromkeys(line for line in lines if FAILURE_LINE.fullmatch(line)))