progress_dashboard: no file name from outside the repository on the page

scrub() kept the last component of every absolute path, so a failing test line
naming a carved shader in the work folder showed the shader's name. A path
inside the repository now becomes its relative path and any other path becomes
<path>, file name included; URLs and relative paths are left alone.

The corpus test checked components, sources and metrics only, so a name added
to notes (which the page prints) passed. It now checks everything the
collector holds. Both cases were found by JRamos1993 in review; each new check
fails when the old behaviour is put back.
This commit is contained in:
Leonardo Guimaraes
2026-11-22 16:52:03 -03:00
parent 8915df896e
commit b4a2e05585
3 changed files with 41 additions and 6 deletions

View File

@ -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 `<path>`, file name included, since a file name outside the
repository can be a carved shader's name.

View File

@ -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 <path>")
self.assertEqual(pd.scrub(f"see /home/someone/work/{SENTINEL}.fssm now"), "see <path> now")
self.assertEqual(pd.scrub("in " + os.path.join(pd.HOME, "work", f"{SENTINEL}.fssm")), "in <path>")
self.assertEqual(pd.scrub(f"C:{sep}work{sep}{SENTINEL}_a.fssm, C:{sep}{SENTINEL}_b.fssm"), "<path> <path>")
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):

View File

@ -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 <path>, 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 "<path>"
line = re.sub(r"(?i)\b[a-z]:[\\/][^\s'\"]*", shown, line)
line = re.sub(r"(?<![\w.:/~])/[^\s/'\"][^\s'\"]*", shown, line)
if HOME and len(HOME) > 3:
line = line.replace(HOME, "~")
line = re.sub(r"(?i)\b[a-z]:[\\/](?:[^\s\\/:'\"]+[\\/])+([^\s\\/'\"]+)", r"<path>/\1", line)
line = re.sub(r"(?<![\w.])/(?:[^\s/'\"]+/)+([^\s/'\"]+)", r"<path>/\1", line)
line = re.sub(r"~[\\/][^\s'\"]*", "<path>", line)
return line[:limit]