From f482408308b7c7c6da5c2309a34a53ae82e0d5ec Mon Sep 17 00:00:00 2001 From: IlyassRS Date: Tue, 24 Nov 2026 21:56:53 +0100 Subject: [PATCH 1/3] progress_dashboard: recover parse_lasttest after incomplete nested CTest logs --- tests/test_progress_dashboard.py | 87 ++++++++++++++++++++++++++++++++ tools/progress_dashboard.py | 64 +++++++++++++++++++---- 2 files changed, 142 insertions(+), 9 deletions(-) diff --git a/tests/test_progress_dashboard.py b/tests/test_progress_dashboard.py index b5a15e80ce..8965be9b55 100644 --- a/tests/test_progress_dashboard.py +++ b/tests/test_progress_dashboard.py @@ -142,6 +142,93 @@ def test_lasttest_ignores_a_nested_ctest_log(self) -> None: ) self.assertEqual(pd.parse_lasttest(log), [("outer", "fail", 0.23), ("next", "pass", 0.02)]) + def test_lasttest_recovers_when_nested_log_omits_end_testing(self) -> None: + # Mirrors the real CTest 3.31.10 fixture where outer `wrapper` (1/2, fails) prints an inner + # log containing `wrapper` (1/2, passes) and `child_2` (2/2, passes) with identical ordinal + # and timestamps, but without the inner `End testing:` trailer, followed by outer `later` (2/2). + sep = "-" * 58 + ts = "Nov 24 20:47 UTC" + inner_no_end = ( + f"Start testing: {ts}\n{sep}\n" + f"1/2 Testing: wrapper\n1/2 Test: wrapper\nOutput:\n{sep}\ninner ok\n\n" + f'Test time = 0.01 sec\n{sep}\nTest Passed.\n"wrapper" end time: {ts}\n' + f'"wrapper" time elapsed: 00:00:00\n{sep}\n\n' + f"2/2 Testing: child_2\n2/2 Test: child_2\nOutput:\n{sep}\nchild ok\n\n" + f'Test time = 0.01 sec\n{sep}\nTest Passed.\n"child_2" end time: {ts}\n' + f'"child_2" time elapsed: 00:00:00\n{sep}' + ) + log = ( + f"Start testing: {ts}\n{sep}\n" + f"1/2 Testing: wrapper\n1/2 Test: wrapper\nOutput:\n{sep}\n{inner_no_end}\n\n" + f'Test time = 0.25 sec\n{sep}\nTest Failed.\n"wrapper" end time: {ts}\n' + f'"wrapper" time elapsed: 00:00:00\n{sep}\n\n' + f"2/2 Testing: later\n2/2 Test: later\nOutput:\n{sep}\nok\n\n" + f'Test time = 0.02 sec\n{sep}\nTest Passed.\n"later" end time: {ts}\n' + f'"later" time elapsed: 00:00:00\n{sep}\n\nEnd testing: {ts}\n' + ) + self.assertEqual(pd.parse_lasttest(log), [("wrapper", "fail", 0.25), ("later", "pass", 0.02)]) + + def test_lasttest_recovers_from_empty_incomplete_nested_log(self) -> None: + sep = "-" * 58 + log = ( + f"Start testing: Nov 24 20:47 UTC\n{sep}\n" + f"1/1 Testing: wrapper\n1/1 Test: wrapper\nOutput:\n{sep}\n" + f"Start testing: Nov 24 20:47 UTC\n{sep}\n" + f"\nTest time = 10.00 sec\n{sep}\nTest Failed.\n" + ) + self.assertEqual(pd.parse_lasttest(log), [("wrapper", "fail", 10.0)]) + + def test_lasttest_handles_three_level_nested_log_missing_innermost_end_testing(self) -> None: + sep = "-" * 58 + ts = "Nov 24 20:47 UTC" + leaf = ( + f"Start testing: {ts}\n{sep}\n1/1 Test: leaf\nOutput:\n{sep}\nleaf\n\n" + f'Test time = 0.01 sec\n{sep}\nTest Passed.\n"leaf" end time: {ts}\n{sep}' + ) + mid = ( + f"Start testing: {ts}\n{sep}\n1/1 Test: mid\nOutput:\n{sep}\n{leaf}\n\n" + f'Test time = 0.05 sec\n{sep}\nTest Passed.\n"mid" end time: {ts}\n{sep}\n\nEnd testing: {ts}' + ) + log = ( + f"Start testing: {ts}\n{sep}\n1/2 Test: wrapper\nOutput:\n{sep}\n{mid}\n\n" + f'Test time = 0.30 sec\n{sep}\nTest Failed.\n"wrapper" end time: {ts}\n{sep}\n\n' + f"2/2 Test: later\nOutput:\n{sep}\nok\n\n" + f'Test time = 0.02 sec\n{sep}\nTest Passed.\n"later" end time: {ts}\n{sep}\n\nEnd testing: {ts}\n' + ) + self.assertEqual(pd.parse_lasttest(log), [("wrapper", "fail", 0.3), ("later", "pass", 0.02)]) + + def test_lasttest_recovers_when_inner_test_output_is_truncated_mid_stream(self) -> None: + sep = "-" * 58 + ts = "Nov 24 20:47 UTC" + inner_truncated = ( + f"Start testing: {ts}\n{sep}\n" + f"1/2 Test: wrapper\nOutput:\n{sep}\nok\n\n" + f'Test time = 0.01 sec\n{sep}\nTest Passed.\n"wrapper" end time: {ts}\n{sep}\n' + f"2/2 Test: child_2\nOutput:\n{sep}\npartial output before kill" + ) + log = ( + f"Start testing: {ts}\n{sep}\n" + f"1/2 Test: wrapper\nOutput:\n{sep}\n{inner_truncated}\n\n" + f'Test time = 0.40 sec\n{sep}\nTest Failed.\n"wrapper" end time: {ts}\n{sep}\n\n' + f"2/2 Test: later\nOutput:\n{sep}\nok\n\n" + f'Test time = 0.03 sec\n{sep}\nTest Passed.\n"later" end time: {ts}\n{sep}\n\nEnd testing: {ts}\n' + ) + self.assertEqual(pd.parse_lasttest(log), [("wrapper", "fail", 0.4), ("later", "pass", 0.03)]) + + def test_lasttest_ignores_spurious_end_testing_inside_nested_test_output(self) -> None: + sep = "-" * 58 + ts = "Nov 24 20:47 UTC" + inner = ( + f"Start testing: {ts}\n{sep}\n1/1 Test: inner\nOutput:\n{sep}\n" + f"End testing: spurious line in child output\n\n" + f'Test time = 0.01 sec\n{sep}\nTest Passed.\n"inner" end time: {ts}\n{sep}\nEnd testing: {ts}' + ) + log = ( + f"Start testing: {ts}\n{sep}\n1/1 Test: wrapper\nOutput:\n{sep}\n{inner}\n\n" + f'Test time = 0.15 sec\n{sep}\nTest Failed.\n"wrapper" end time: {ts}\n{sep}\nEnd testing: {ts}\n' + ) + self.assertEqual(pd.parse_lasttest(log), [("wrapper", "fail", 0.15)]) + def test_ci_selection_matches_the_workflow_rule(self): files = pd.ci_test_files() self.assertIn("tests/test_progress_dashboard.py", files) diff --git a/tools/progress_dashboard.py b/tools/progress_dashboard.py index 43d3fafdbb..99092372f0 100644 --- a/tools/progress_dashboard.py +++ b/tools/progress_dashboard.py @@ -400,24 +400,69 @@ def parse_junit(xml): return out +def _trailer_end_time_matches(lines: list[str], end_of_output_index: int, name: str) -> bool: + """True when the immediate CTest trailer after `` ends with `\"\" end time: `.""" + sep = "-" * 58 + separators = 0 + expected = f'"{name}" end time: ' + for line in lines[end_of_output_index + 1:]: + if line == sep: + separators += 1 + if separators >= 2: + return False + continue + if line.startswith('"') and '" end time: ' in line: + return line.startswith(expected) + if line == "" or line == "Output:" or line.startswith(("Start testing: ", "End testing: ")): + return False + if re.match(r"^\d+/\d+ Test: ", line): + return False + return False + + def parse_lasttest(text: str) -> list[tuple[str, str, float | None]]: """[(name, result, seconds)] from CTest's Testing/Temporary/LastTest.log.""" + sep = "-" * 58 + test_re = re.compile(r"^\d+/\d+ Test: (.+)$") out, name, secs = [], None, None captured = False - nested_runs = 0 + # Stack of [in_output, inner_test_name] for nested `Start testing:` runs inside captured output. + nested: list[list[object]] = [] lines = text.splitlines() for index, line in enumerate(lines): next_line = lines[index + 1] if index + 1 < len(lines) else "" if captured: - # CTest writes child output verbatim, so it can contain complete nested logs. - if line.startswith("Start testing: ") and next_line == "-" * 58: - nested_runs += 1 - elif nested_runs and line.startswith("End testing: "): - nested_runs -= 1 - elif not nested_runs and line == "" and next_line.startswith("Test time ="): - captured = False + # CTest writes child output verbatim, so it can contain complete or truncated nested logs. + if line.startswith("Start testing: ") and next_line == sep: + nested.append([False, None]) + elif nested and not nested[-1][0]: + m = test_re.match(line) + if m: + nested[-1][1] = m.group(1).strip() + elif line == "Output:" and next_line == sep: + nested[-1][0] = True + elif line.startswith("End testing: "): + nested.pop() + elif line == "" and next_line.startswith("Test time ="): + # No inner Output: block is open, so unwind any nested runs that omitted `End testing:`. + while nested and not nested[-1][0]: + nested.pop() + if not nested: + captured = False + else: + nested[-1][0] = False + elif line == "" and next_line.startswith("Test time ="): + if not nested: + captured = False + elif (len(nested) == 1 and nested[0][1] is not None and nested[0][1] != name + and _trailer_end_time_matches(lines, index, name)): + # Inner test output was truncated before its own ``; this trailer is the outer test's. + nested.clear() + captured = False + else: + nested[-1][0] = False continue - m = re.match(r"^\d+/\d+ Test: (.+)$", line) + m = test_re.match(line) if m: name, secs = m.group(1).strip(), None continue @@ -425,6 +470,7 @@ def parse_lasttest(text: str) -> list[tuple[str, str, float | None]]: continue if line == "Output:": captured = True + nested.clear() continue m = re.match(r"^Test time =\s*([\d.]+) sec", line) if m: From 8d2aa7bd803d0f8547f36697cc9c71b9a247075d Mon Sep 17 00:00:00 2001 From: IlyassRS Date: Tue, 24 Nov 2026 22:27:00 +0100 Subject: [PATCH 2/3] progress_dashboard: avoid O(n^2) suffix copy in _trailer_end_time_matches --- tools/progress_dashboard.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/progress_dashboard.py b/tools/progress_dashboard.py index 99092372f0..0e5d959070 100644 --- a/tools/progress_dashboard.py +++ b/tools/progress_dashboard.py @@ -400,12 +400,16 @@ def parse_junit(xml): return out +_CTEST_HEADER_RE = re.compile(r"^\d+/\d+ Test: (.+)$") + + def _trailer_end_time_matches(lines: list[str], end_of_output_index: int, name: str) -> bool: """True when the immediate CTest trailer after `` ends with `\"\" end time: `.""" sep = "-" * 58 separators = 0 expected = f'"{name}" end time: ' - for line in lines[end_of_output_index + 1:]: + for idx in range(end_of_output_index + 1, len(lines)): + line = lines[idx] if line == sep: separators += 1 if separators >= 2: @@ -415,7 +419,7 @@ def _trailer_end_time_matches(lines: list[str], end_of_output_index: int, name: return line.startswith(expected) if line == "" or line == "Output:" or line.startswith(("Start testing: ", "End testing: ")): return False - if re.match(r"^\d+/\d+ Test: ", line): + if _CTEST_HEADER_RE.match(line): return False return False @@ -423,7 +427,6 @@ def _trailer_end_time_matches(lines: list[str], end_of_output_index: int, name: def parse_lasttest(text: str) -> list[tuple[str, str, float | None]]: """[(name, result, seconds)] from CTest's Testing/Temporary/LastTest.log.""" sep = "-" * 58 - test_re = re.compile(r"^\d+/\d+ Test: (.+)$") out, name, secs = [], None, None captured = False # Stack of [in_output, inner_test_name] for nested `Start testing:` runs inside captured output. @@ -436,7 +439,7 @@ def parse_lasttest(text: str) -> list[tuple[str, str, float | None]]: if line.startswith("Start testing: ") and next_line == sep: nested.append([False, None]) elif nested and not nested[-1][0]: - m = test_re.match(line) + m = _CTEST_HEADER_RE.match(line) if m: nested[-1][1] = m.group(1).strip() elif line == "Output:" and next_line == sep: @@ -462,7 +465,7 @@ def parse_lasttest(text: str) -> list[tuple[str, str, float | None]]: else: nested[-1][0] = False continue - m = test_re.match(line) + m = _CTEST_HEADER_RE.match(line) if m: name, secs = m.group(1).strip(), None continue From c81b2daf57644e350f7d1084eceee1a64cc4db29 Mon Sep 17 00:00:00 2001 From: IlyassRS Date: Tue, 24 Nov 2026 22:46:21 +0100 Subject: [PATCH 3/3] progress_dashboard: unwind multi-level truncated nested CTest outputs by trailer name --- tests/test_progress_dashboard.py | 39 +++++++++++++++++++++ tools/progress_dashboard.py | 60 ++++++++++++++++++-------------- 2 files changed, 72 insertions(+), 27 deletions(-) diff --git a/tests/test_progress_dashboard.py b/tests/test_progress_dashboard.py index 8965be9b55..4b455b9096 100644 --- a/tests/test_progress_dashboard.py +++ b/tests/test_progress_dashboard.py @@ -215,6 +215,45 @@ def test_lasttest_recovers_when_inner_test_output_is_truncated_mid_stream(self) ) self.assertEqual(pd.parse_lasttest(log), [("wrapper", "fail", 0.4), ("later", "pass", 0.03)]) + def test_lasttest_recovers_when_multi_level_nested_output_is_truncated_mid_leaf(self) -> None: + sep = "-" * 58 + ts = "Nov 24 21:40 UTC" + middle_truncated_in_leaf = ( + f"Start testing: {ts}\n{sep}\n" + f"1/1 Test: middle\nOutput:\n{sep}\n" + f"Start testing: {ts}\n{sep}\n" + f"1/1 Test: leaf\nOutput:\n{sep}\n" + f"leaf payload" + ) + log = ( + f"Start testing: {ts}\n{sep}\n" + f"1/2 Test: wrapper\nOutput:\n{sep}\n{middle_truncated_in_leaf}\n\n" + f'Test time = 0.25 sec\n{sep}\nTest Failed.\n"wrapper" end time: {ts}\n{sep}\n\n' + f"2/2 Test: later\nOutput:\n{sep}\nok\n\n" + f'Test time = 0.04 sec\n{sep}\nTest Passed.\n"later" end time: {ts}\n{sep}\n\nEnd testing: {ts}\n' + ) + self.assertEqual(pd.parse_lasttest(log), [("wrapper", "fail", 0.25), ("later", "pass", 0.04)]) + + def test_lasttest_recovers_when_middle_finishes_after_truncated_leaf(self) -> None: + sep = "-" * 58 + ts = "Nov 24 21:40 UTC" + middle_with_truncated_leaf = ( + f"Start testing: {ts}\n{sep}\n" + f"1/1 Test: middle\nOutput:\n{sep}\n" + f"Start testing: {ts}\n{sep}\n" + f"1/1 Test: leaf\nOutput:\n{sep}\n" + f"leaf payload\n\n" + f'Test time = 0.10 sec\n{sep}\nTest Failed.\n"middle" end time: {ts}\n{sep}\nEnd testing: {ts}' + ) + log = ( + f"Start testing: {ts}\n{sep}\n" + f"1/2 Test: wrapper\nOutput:\n{sep}\n{middle_with_truncated_leaf}\n\n" + f'Test time = 0.35 sec\n{sep}\nTest Passed.\n"wrapper" end time: {ts}\n{sep}\n\n' + f"2/2 Test: later\nOutput:\n{sep}\nok\n\n" + f'Test time = 0.05 sec\n{sep}\nTest Passed.\n"later" end time: {ts}\n{sep}\n\nEnd testing: {ts}\n' + ) + self.assertEqual(pd.parse_lasttest(log), [("wrapper", "pass", 0.35), ("later", "pass", 0.05)]) + def test_lasttest_ignores_spurious_end_testing_inside_nested_test_output(self) -> None: sep = "-" * 58 ts = "Nov 24 20:47 UTC" diff --git a/tools/progress_dashboard.py b/tools/progress_dashboard.py index 0e5d959070..2f3219eb30 100644 --- a/tools/progress_dashboard.py +++ b/tools/progress_dashboard.py @@ -403,25 +403,26 @@ def parse_junit(xml): _CTEST_HEADER_RE = re.compile(r"^\d+/\d+ Test: (.+)$") -def _trailer_end_time_matches(lines: list[str], end_of_output_index: int, name: str) -> bool: - """True when the immediate CTest trailer after `` ends with `\"\" end time: `.""" +def _trailer_end_time_name(lines: list[str], end_of_output_index: int) -> str | None: + """Return `` from the immediate CTest trailer's `\"\" end time: ` line, or None.""" sep = "-" * 58 separators = 0 - expected = f'"{name}" end time: ' for idx in range(end_of_output_index + 1, len(lines)): line = lines[idx] if line == sep: separators += 1 if separators >= 2: - return False + return None continue - if line.startswith('"') and '" end time: ' in line: - return line.startswith(expected) + if line.startswith('"'): + marker = line.rfind('" end time: ') + if marker > 0: + return line[1:marker] if line == "" or line == "Output:" or line.startswith(("Start testing: ", "End testing: ")): - return False + return None if _CTEST_HEADER_RE.match(line): - return False - return False + return None + return None def parse_lasttest(text: str) -> list[tuple[str, str, float | None]]: @@ -438,6 +439,29 @@ def parse_lasttest(text: str) -> list[tuple[str, str, float | None]]: # CTest writes child output verbatim, so it can contain complete or truncated nested logs. if line.startswith("Start testing: ") and next_line == sep: nested.append([False, None]) + elif line == "" and next_line.startswith("Test time ="): + # Unwind any nested runs whose Output: block is already closed (or never opened) and omitted End testing:. + while nested and not nested[-1][0]: + nested.pop() + if not nested: + captured = False + else: + trailer_name = _trailer_end_time_name(lines, index) + matched_depth = None + if trailer_name is not None: + for depth in range(len(nested) - 1, -1, -1): + if nested[depth][1] == trailer_name: + matched_depth = depth + break + if matched_depth is not None: + del nested[matched_depth + 1:] + nested[matched_depth][0] = False + elif trailer_name is not None and trailer_name == name: + # All open nested Output: blocks were truncated before their own ``. + nested.clear() + captured = False + else: + nested[-1][0] = False elif nested and not nested[-1][0]: m = _CTEST_HEADER_RE.match(line) if m: @@ -446,24 +470,6 @@ def parse_lasttest(text: str) -> list[tuple[str, str, float | None]]: nested[-1][0] = True elif line.startswith("End testing: "): nested.pop() - elif line == "" and next_line.startswith("Test time ="): - # No inner Output: block is open, so unwind any nested runs that omitted `End testing:`. - while nested and not nested[-1][0]: - nested.pop() - if not nested: - captured = False - else: - nested[-1][0] = False - elif line == "" and next_line.startswith("Test time ="): - if not nested: - captured = False - elif (len(nested) == 1 and nested[0][1] is not None and nested[0][1] != name - and _trailer_end_time_matches(lines, index, name)): - # Inner test output was truncated before its own ``; this trailer is the outer test's. - nested.clear() - captured = False - else: - nested[-1][0] = False continue m = _CTEST_HEADER_RE.match(line) if m: