diff options
| author | Leonardo Guimaraes <leozinhoszg@gmail.com> | 2026-11-22 16:52:03 -0300 |
|---|---|---|
| committer | Leonardo Guimaraes <leozinhoszg@gmail.com> | 2026-11-22 16:52:03 -0300 |
| commit | b4a2e05585634214d99b61ba602d1f1c57bb0fc3 (patch) | |
| tree | 740be96169e5a7387325dd491bca1f5ee0ccf8b9 | |
| parent | 8915df896e10c0cef994ce390a490fbc57f21d23 (diff) | |
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.
| -rw-r--r-- | docs/progress_dashboard.md | 4 | ||||
| -rw-r--r-- | tests/test_progress_dashboard.py | 26 | ||||
| -rw-r--r-- | tools/progress_dashboard.py | 17 |
3 files changed, 41 insertions, 6 deletions
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 | |||
| 59 | 59 | ||
| 60 | The page and the JSON carry counts, pass/fail, error classes and the project's own document text. The corpus panel | 60 | The page and the JSON carry counts, pass/fail, error classes and the project's own document text. The corpus panel |
| 61 | stores per-stage numbers only: no shader name, carved file name or path into the game copy. One-line failure details | 61 | stores per-stage numbers only: no shader name, carved file name or path into the game copy. One-line failure details |
| 62 | are kept with the home folder and drive paths reduced to their last component. | 62 | are kept with each absolute path replaced: a path inside the repository becomes its relative path, any other path |
| 63 | (work folder, home folder, temp folder) becomes `<path>`, file name included, since a file name outside the | ||
| 64 | 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): | |||
| 204 | ("compute", "implemented"): 1, ("compute", "failed"): 1}) | 204 | ("compute", "implemented"): 1, ("compute", "failed"): 1}) |
| 205 | m = next(m for m in col.metrics if m["id"] == "corpus.validated") | 205 | m = next(m for m in col.metrics if m["id"] == "corpus.validated") |
| 206 | self.assertEqual((m["numerator"], m["denominator"]), (2, 5)) | 206 | self.assertEqual((m["numerator"], m["denominator"]), (2, 5)) |
| 207 | self.assertNotIn(SENTINEL, json.dumps({"c": col.components, "s": col.sources, "m": col.metrics})) | 207 | # everything the collector holds can reach the page (notes and panels included), so check all of it |
| 208 | self.assertNotIn(tmp, json.dumps(col.sources)) | 208 | held = json.dumps(vars(col), default=str) |
| 209 | self.assertNotIn(SENTINEL, held) | ||
| 210 | self.assertNotIn(tmp, held) | ||
| 211 | self.assertNotIn(json.dumps(tmp)[1:-1], held) | ||
| 212 | |||
| 213 | |||
| 214 | class Scrub(unittest.TestCase): | ||
| 215 | def test_paths_outside_the_repository_lose_their_file_name(self): | ||
| 216 | sep = os.sep | ||
| 217 | work = os.path.join(tempfile.gettempdir(), "work", "shaders", "dxbc", f"{SENTINEL}.fssm") | ||
| 218 | self.assertEqual(pd.scrub(f"FAIL: cannot read {work}"), "FAIL: cannot read <path>") | ||
| 219 | self.assertEqual(pd.scrub(f"see /home/someone/work/{SENTINEL}.fssm now"), "see <path> now") | ||
| 220 | self.assertEqual(pd.scrub("in " + os.path.join(pd.HOME, "work", f"{SENTINEL}.fssm")), "in <path>") | ||
| 221 | self.assertEqual(pd.scrub(f"C:{sep}work{sep}{SENTINEL}_a.fssm, C:{sep}{SENTINEL}_b.fssm"), "<path> <path>") | ||
| 222 | |||
| 223 | def test_paths_inside_the_repository_become_relative(self): | ||
| 224 | line = "Error: " + os.path.join(ROOT, "tools", "text_tables.py") + " line 3" | ||
| 225 | self.assertEqual(pd.scrub(line), "Error: tools/text_tables.py line 3") | ||
| 226 | |||
| 227 | def test_urls_and_relative_paths_stay(self): | ||
| 228 | self.assertEqual(pd.scrub("see https://github.com/ItsNotRexed/Leonida/issues/1"), | ||
| 229 | "see https://github.com/ItsNotRexed/Leonida/issues/1") | ||
| 230 | self.assertEqual(pd.scrub("tests/test_x.py failed"), "tests/test_x.py failed") | ||
| 209 | 231 | ||
| 210 | 232 | ||
| 211 | class Outputs(unittest.TestCase): | 233 | 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("~") | |||
| 100 | 100 | ||
| 101 | 101 | ||
| 102 | def scrub(text, limit=240): | 102 | def scrub(text, limit=240): |
| 103 | """One line of tool output, with the user's home folder and drive paths reduced to their last component.""" | 103 | """One line of tool output with every absolute path replaced: a path inside the repository becomes its relative |
| 104 | path, any other path (the work folder, the home folder, a temp folder) becomes <path>, file name included, since | ||
| 105 | a file name outside the repository can be a carved shader's name.""" | ||
| 104 | if not text: | 106 | if not text: |
| 105 | return "" | 107 | return "" |
| 106 | line = text.strip().splitlines()[-1] if text.strip() else "" | 108 | line = text.strip().splitlines()[-1] if text.strip() else "" |
| 109 | |||
| 110 | def shown(m): | ||
| 111 | path = m.group(0) | ||
| 112 | if inside(path, ROOT): | ||
| 113 | rel = os.path.relpath(os.path.realpath(path), os.path.realpath(ROOT)).replace(os.sep, "/") | ||
| 114 | return "." if rel == "." else rel | ||
| 115 | return "<path>" | ||
| 116 | |||
| 117 | line = re.sub(r"(?i)\b[a-z]:[\\/][^\s'\"]*", shown, line) | ||
| 118 | line = re.sub(r"(?<![\w.:/~])/[^\s/'\"][^\s'\"]*", shown, line) | ||
| 107 | if HOME and len(HOME) > 3: | 119 | if HOME and len(HOME) > 3: |
| 108 | line = line.replace(HOME, "~") | 120 | line = line.replace(HOME, "~") |
| 109 | line = re.sub(r"(?i)\b[a-z]:[\\/](?:[^\s\\/:'\"]+[\\/])+([^\s\\/'\"]+)", r"<path>/\1", line) | 121 | line = re.sub(r"~[\\/][^\s'\"]*", "<path>", line) |
| 110 | line = re.sub(r"(?<![\w.])/(?:[^\s/'\"]+/)+([^\s/'\"]+)", r"<path>/\1", line) | ||
| 111 | return line[:limit] | 122 | return line[:limit] |
| 112 | 123 | ||
| 113 | 124 | ||