diff --git a/docs/progress_dashboard.md b/docs/progress_dashboard.md index 11b34e1c0..41ebf6967 100644 --- a/docs/progress_dashboard.md +++ b/docs/progress_dashboard.md @@ -59,4 +59,6 @@ panels count different things. The trend chart breaks a line where a metric's fo The page and the JSON carry counts, pass/fail, error classes and the project's own document text. The corpus panel stores per-stage numbers only: no shader name, carved file name or path into the game copy. One-line failure details -are kept with the home folder and drive paths reduced to their last component. +are kept with each absolute path replaced: a path inside the repository becomes its relative path, any other path +(work folder, home folder, temp folder) becomes ``, file name included, since a file name outside the +repository can be a carved shader's name. diff --git a/tests/test_progress_dashboard.py b/tests/test_progress_dashboard.py index f1f858a56..dfa5e8e9c 100644 --- a/tests/test_progress_dashboard.py +++ b/tests/test_progress_dashboard.py @@ -204,8 +204,30 @@ class Corpus(unittest.TestCase): ("compute", "implemented"): 1, ("compute", "failed"): 1}) m = next(m for m in col.metrics if m["id"] == "corpus.validated") self.assertEqual((m["numerator"], m["denominator"]), (2, 5)) - self.assertNotIn(SENTINEL, json.dumps({"c": col.components, "s": col.sources, "m": col.metrics})) - self.assertNotIn(tmp, json.dumps(col.sources)) + # everything the collector holds can reach the page (notes and panels included), so check all of it + held = json.dumps(vars(col), default=str) + self.assertNotIn(SENTINEL, held) + self.assertNotIn(tmp, held) + self.assertNotIn(json.dumps(tmp)[1:-1], held) + + +class Scrub(unittest.TestCase): + def test_paths_outside_the_repository_lose_their_file_name(self): + sep = os.sep + work = os.path.join(tempfile.gettempdir(), "work", "shaders", "dxbc", f"{SENTINEL}.fssm") + self.assertEqual(pd.scrub(f"FAIL: cannot read {work}"), "FAIL: cannot read ") + self.assertEqual(pd.scrub(f"see /home/someone/work/{SENTINEL}.fssm now"), "see now") + self.assertEqual(pd.scrub("in " + os.path.join(pd.HOME, "work", f"{SENTINEL}.fssm")), "in ") + self.assertEqual(pd.scrub(f"C:{sep}work{sep}{SENTINEL}_a.fssm, C:{sep}{SENTINEL}_b.fssm"), " ") + + def test_paths_inside_the_repository_become_relative(self): + line = "Error: " + os.path.join(ROOT, "tools", "text_tables.py") + " line 3" + self.assertEqual(pd.scrub(line), "Error: tools/text_tables.py line 3") + + def test_urls_and_relative_paths_stay(self): + self.assertEqual(pd.scrub("see https://github.com/ItsNotRexed/Leonida/issues/1"), + "see https://github.com/ItsNotRexed/Leonida/issues/1") + self.assertEqual(pd.scrub("tests/test_x.py failed"), "tests/test_x.py failed") class Outputs(unittest.TestCase): diff --git a/tools/progress_dashboard.py b/tools/progress_dashboard.py index bbb338853..882cdfdd3 100644 --- a/tools/progress_dashboard.py +++ b/tools/progress_dashboard.py @@ -100,14 +100,25 @@ HOME = os.path.expanduser("~") def scrub(text, limit=240): - """One line of tool output, with the user's home folder and drive paths reduced to their last component.""" + """One line of tool output with every absolute path replaced: a path inside the repository becomes its relative + path, any other path (the work folder, the home folder, a temp folder) becomes , file name included, since + a file name outside the repository can be a carved shader's name.""" if not text: return "" line = text.strip().splitlines()[-1] if text.strip() else "" + + def shown(m): + path = m.group(0) + if inside(path, ROOT): + rel = os.path.relpath(os.path.realpath(path), os.path.realpath(ROOT)).replace(os.sep, "/") + return "." if rel == "." else rel + return "" + + line = re.sub(r"(?i)\b[a-z]:[\\/][^\s'\"]*", shown, line) + line = re.sub(r"(? 3: line = line.replace(HOME, "~") - line = re.sub(r"(?i)\b[a-z]:[\\/](?:[^\s\\/:'\"]+[\\/])+([^\s\\/'\"]+)", r"/\1", line) - line = re.sub(r"(?/\1", line) + line = re.sub(r"~[\\/][^\s'\"]*", "", line) return line[:limit]