diff --git a/premerge/advisor/advisor_lib.py b/premerge/advisor/advisor_lib.py index 520496abc..7797850e5 100644 --- a/premerge/advisor/advisor_lib.py +++ b/premerge/advisor/advisor_lib.py @@ -2,6 +2,8 @@ import time import sqlite3 import logging +import re + import git_utils @@ -70,9 +72,17 @@ def setup_db(db_path: str) -> sqlite3.Connection: return connection +def _canonicalize_failures(failures: list[TestFailure]): + for failure in failures: + failure["message"] = re.sub( + r"\/home\/.*\/llvm-project", "llvm-project", failure["message"] + ) + + def upload_failures( failure_info: FailureUpload, db_connection: sqlite3.Connection, repository_path: str ): + _canonicalize_failures(failure_info["failures"]) failures = [] for failure in failure_info["failures"]: failures.append( @@ -181,6 +191,7 @@ def explain_failures( repository_path: str, db_connection: sqlite3.Connection, ) -> list[FailureExplanation]: + _canonicalize_failures(explanation_request["failures"]) explanations = [] for test_failure in explanation_request["failures"]: commit_index = git_utils.get_commit_index( diff --git a/premerge/advisor/advisor_lib_test.py b/premerge/advisor/advisor_lib_test.py index d2b9ede1c..db0b9c757 100644 --- a/premerge/advisor/advisor_lib_test.py +++ b/premerge/advisor/advisor_lib_test.py @@ -242,6 +242,23 @@ def test_explain_head_within_range(self): ], ) + # Test that we can explain test failures where the llvm-project root is + # located in a different path. + def test_explain_different_root_path(self): + self.assertListEqual( + self._get_explained_failures( + failure_message="/home/_w/llvm-project/test1/test1.ll failed", + prev_failure_failure_message="/home/gha/llvm-project/test1/test1.ll failed", + ), + [ + { + "name": "a.ll", + "explained": True, + "reason": "This test is already failing at the base commit.", + } + ], + ) + # Test that we do not explain away a failure at head if the only matching # failure information comes from a PR. def test_no_explain_different_source_type(self):