Files
mandy/tests/test_bug_report_info.py
MoonEyes 63baede940 bug report info: the settings lines go through an allowlist too (review 2)
Variable values showed lists of the title's program hashes (LEONIDA_PAIRED_FOR and the like), program names and
URLs. A value is now shown as it is only when it is a number, true/false or a short word; a list shows its count
(<44 entries>), anything else <set>. Windows, the card, the profile, the upscaler and frame generation go word by
word through an allowlist (short words, numbers, model numbers such as A770, the (R)/(TM) marks); the resolution
must look like 1080 or 2560x1080. Tests cover the reviewer's probes and that real card names stay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 12:04:24 +01:00

282 lines
14 KiB
Python

"""tools/bug_report_info.py: the bug report block, its log parsing and its scrub (synthetic text only, no game data).
python -I tests/test_bug_report_info.py -v
"""
import os
from pathlib import Path
import sys
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "tools"))
import bug_report_info as info # noqa: E402
import leonida_launcher as launcher # noqa: E402
CARD_LOG = ('2026-12-03T10:00:00.123456Z INFO leonida_gpu::indirect: the card was asked whether it runs an indirect '
'dispatch card="NVIDIA GeForce RTX 4070", runs=true, ms=1.5\n')
ADAPTER_LOG = ("2026-12-03T10:00:00.1Z WARN leonida_gpu::host: host device on the card LEONIDA_ADAPTER names "
"adapter=AMD Radeon RX 7800 XT index=1 memory_mb=16368\n")
def build(head=None, tail=None, **changes):
arguments = dict(version="abc1234 2026-12-03", system="Windows 11 (10.0.26300)", console="series-x",
args=["-Dlss", "quality", "-FrameGen", "3"], variables={"LEONIDA_FG_LIMIT_FPS": "60"},
log_head=head, log_tail=tail)
arguments.update(changes)
return info.build_report(**arguments)
class ScrubTests(unittest.TestCase):
"""scrub_line keeps only words that cannot carry anything of the game or the user (an allowlist)."""
def assert_gone(self, line, *leaks):
out = info.scrub_line(line)
for leak in leaks:
self.assertNotIn(leak, out, msg=out)
return out
def test_home_folder(self):
for path in (r"C:\Users\Jean Dupont\AppData\x", "c:/users/bob/x", r"\\?\D:\Users\bob\x", "/home/bob/x",
"/Users/bob/x"):
with self.subTest(path=path):
self.assert_gone(f"open {path} failed", "bob", "Dupont", "AppData")
self.assertEqual(info.scrub_line(r"C:\Users\bob started"), "%USERPROFILE% started")
def test_runtime_program_names(self):
# pipeline/host.rs logs `?names` of the title's programs when a pipeline is refused.
out = self.assert_gone('2026-12-03T10:00:00.1Z WARN leonida_gpu::pipeline::host: host pipeline refused '
'error=E_INVALIDARG shaders=[1a2b3c4d, 5e6f7a8b] names=["PS_WaterDeep", "VS_Ocean"]',
"WaterDeep", "Ocean", "1a2b", "5e6f", "E_INVALIDARG")
self.assertIn("leonida_gpu::pipeline::host:", out)
self.assertIn("host pipeline refused", out)
def test_paths_and_file_names(self):
for line in (r"ERROR leonida_gpu::capture: wrote path=D:\Captures\jsmith\frame.png",
r"open \\server\share\jsmith\x.log failed", r"read D:\Games\jsmith\GTA6\game.exe",
"load 'common:/data/levels/gta6/vice.rpf' cs_terrain_blend.fssm hud_minimap_icon_042",
"file:///C:/x/jsmith/y", r"thread main panicked at C:\Users\jsmith\src\x.rs:10:5:"):
with self.subTest(line=line):
self.assert_gone(line, "jsmith", "vice", "terrain", "minimap", "Captures", "frame.png", "GTA6")
def test_names_hashes_and_addresses(self):
for word in ("ps_1a2b3c", "cs=beef", "GS:cafe", "deadbeef", "1a2b3c4", "0x7FF6A1B2C3D4", "0x8fffffff",
"0x1f", "QmFzZTY0TmFtZQ==", "PS_WaterDeep"):
with self.subTest(word=word):
self.assert_gone(f"error near {word} here", word)
self.assert_gone("error 'quoted name' and \"two words\" here", "quoted", "two")
def test_field_values(self):
out = info.scrub_line("error program=secret shader=12 frames=3 ok=true pso=abc hr=0x887A0005")
self.assertNotIn("secret", out)
self.assertNotIn("abc", out)
for kept in ("frames=3", "ok=true", "shader=12", "hr=0x887A0005", "program=<removed>"):
self.assertIn(kept, out)
def test_status_codes_numbers_and_words_stay(self):
self.assertEqual(info.scrub_line("device removed (reason 0x887A0006), 3 frames, 12.5 ms"),
"device removed (reason 0x887A0006), 3 frames, 12.5 ms")
self.assertEqual(info.scrub_line("exit 0xC0000409"), "exit 0xC0000409")
self.assertEqual(info.scrub_line("t 10:00:00.123456789 ok"), "t 10:00:00.123456789 ok")
def test_removed_words_in_a_row_become_one(self):
self.assertEqual(info.scrub_line("x a_1 b_2 c_3 y"), "x <removed> y")
def test_cut_comes_after_the_scrub(self):
self.assertLessEqual(len(info.scrub_line("error " + "word " * 100)), info.MAX_LINE)
self.assertEqual(len(info.scrub_line("g" * 500)), info.MAX_LINE)
def test_ansi_and_control(self):
self.assertEqual(info.scrub_line("\x1b[31mERROR\x1b[0m boom\x07\r\n"), "ERROR boom")
class LogTests(unittest.TestCase):
def test_error_lines_match_and_cap(self):
text = "\n".join(["INFO fine", "ERROR a", "WARN device lost", "INFO device removed here", "panicked at x",
"an exception", "exit 0xC0000005", "INFO 0 errors", "INFO ok"])
self.assertEqual(info.error_lines(text), ["ERROR a", "WARN device lost", "INFO device removed here",
"panicked at x", "an exception", "exit 0xC0000005"])
def test_ten_line_cap_keeps_the_newest(self):
text = "\n".join(f"ERROR number {i}" for i in range(30))
lines = info.error_lines(text)
self.assertEqual(len(lines), 10)
self.assertEqual(lines[0], "ERROR number 20")
self.assertEqual(lines[-1], "ERROR number 29")
def test_repeated_lines_once(self):
text = "ERROR a\n" + "ERROR device removed\n" * 50 + "ERROR b\n"
self.assertEqual(info.error_lines(text), ["ERROR a", "ERROR device removed", "ERROR b"])
def test_lines_are_scrubbed(self):
out = info.error_lines(r"ERROR C:\Users\bob\x shader=abc ps_1a2b3c 0xDEAD deadbeef01")
self.assertEqual(len(out), 1)
for leaked in ("bob", "abc", "1a2b3c", "DEAD", "deadbeef"):
self.assertNotIn(leaked, out[0])
def test_card(self):
self.assertEqual(info.gpu_from_log("noise\n" + CARD_LOG)["name"], "NVIDIA GeForce RTX 4070")
self.assertIsNone(info.gpu_from_log(CARD_LOG)["memory_mb"])
self.assertEqual(info.gpu_from_log("\x1b[2m" + CARD_LOG)["name"], "NVIDIA GeForce RTX 4070")
def test_adapter_line_has_memory(self):
gpu = info.gpu_from_log(CARD_LOG + ADAPTER_LOG)
self.assertEqual((gpu["name"], gpu["memory_mb"]), ("AMD Radeon RX 7800 XT", 16368))
quoted = info.gpu_from_log('LEONIDA_ADAPTER adapter="X Y" index=0 memory_mb=8000')
self.assertEqual((quoted["name"], quoted["memory_mb"]), ("X Y", 8000))
def test_software_adapter(self):
self.assertEqual(info.gpu_from_log("host device on the software adapter (WARP)")["name"],
"software adapter (WARP)")
def test_no_card(self):
self.assertEqual(info.gpu_from_log("INFO nothing"), {"name": None, "memory_mb": None, "driver": None})
def test_newest_log_and_ends(self):
with tempfile.TemporaryDirectory() as tmp:
self.assertIsNone(info.newest_play_log(tmp))
self.assertIsNone(info.newest_play_log(os.path.join(tmp, "missing")))
for name, stamp in (("play-1.log", 100), ("play-2.log", 300), ("other.log", 900), ("play-3.log", 200)):
path = os.path.join(tmp, name)
Path(path).write_text("x", encoding="utf-8", newline="\n")
os.utime(path, (stamp, stamp))
self.assertEqual(os.path.basename(info.newest_play_log(tmp)), "play-2.log")
big = os.path.join(tmp, "play-9.log")
Path(big).write_bytes(b"HEAD" + b"." * 100 + b"TAIL")
os.utime(big, (999, 999))
head, tail = info.read_log_ends(big, head=4, tail=4)
self.assertEqual((head, tail), ("HEAD", "TAIL"))
self.assertEqual(info.read_log_ends(os.path.join(tmp, "none.log")), ("", ""))
class ReportTests(unittest.TestCase):
def test_full_block(self):
text = build(CARD_LOG + ADAPTER_LOG, "ERROR device removed 0x887A0006\nERROR second")
lines = text.splitlines()
self.assertEqual(lines[0], "Leonida bug report info")
for expected in ("Version: abc1234 2026-12-03", "Windows: Windows 11 (10.0.26300)",
"GPU: AMD Radeon RX 7800 XT", "Driver: not in the log", "Video memory: 16368 MB",
"Console profile: series-x", "Resolution: default", "Upscaler: DLSS quality",
"Frame generation: DLSS 3x", "Options: -Dlss quality -FrameGen 3",
"Variables: LEONIDA_FG_LIMIT_FPS=60"):
self.assertIn(expected, lines)
self.assertEqual(lines[-3:], ["Last errors of the newest play log:", "ERROR device removed 0x887A0006",
"ERROR second"])
self.assertTrue(text.endswith("\n") and "\r" not in text)
def test_missing_fields_say_so(self):
lines = build("INFO nothing", "INFO nothing").splitlines()
self.assertIn("GPU: not in the log", lines)
self.assertIn("Driver: not in the log", lines)
self.assertIn("Video memory: not in the log", lines)
self.assertEqual(lines[-1], "Last errors of the newest play log: none")
def test_missing_log(self):
text = build(None, None, args=["-NoDlss", "-NoFrameGen", "-Resolution", "1440"], variables={})
lines = text.splitlines()
self.assertIn("GPU: not in the log", lines)
self.assertIn("Resolution: 1440", lines)
self.assertIn("Upscaler: off", lines)
self.assertIn("Frame generation: off", lines)
self.assertIn("Variables: (none)", lines)
self.assertTrue(lines[-1].startswith("Last errors: no play log found"))
def test_line_cap(self):
text = build("", "\n".join(f"ERROR line {i}" for i in range(40)))
lines = text.splitlines()
self.assertLessEqual(len(lines), info.MAX_LINES)
self.assertEqual(sum(1 for line in lines if line.startswith("ERROR")), 10)
many = build("", "\n".join(f"ERROR e{i}" for i in range(40)), variables={f"LEONIDA_V{i}": "1" for i in range(90)})
self.assertLessEqual(len(many.splitlines()), info.MAX_LINES)
self.assertTrue(all(len(line) <= info.MAX_LINE + 40 for line in many.splitlines()))
def test_paths_in_variables_are_not_shown(self):
text = build(variables={"LEONIDA_CACHE_DIR": r"C:\Users\bob\cache", "LEONIDA_X": "/home/bob/x", "LEONIDA_Y": "2"})
self.assertNotIn("bob", text)
self.assertIn("LEONIDA_CACHE_DIR=<set>", text)
self.assertIn("LEONIDA_Y=2", text)
def test_commit_hash_stays(self):
self.assertIn("Version: bfd03e7f3 2026-12-03", build(version="bfd03e7f3 2026-12-03"))
def test_fsr_frame_generation(self):
self.assertEqual(info.describe_options(["-FsrFrameGen"])["frame_gen"], "FSR 3")
self.assertEqual(info.describe_options([])["upscaler"], "DLSS (auto)")
def test_no_user_name_anywhere(self):
text = build(CARD_LOG, r"ERROR C:\Users\bob\x failed", version=r"abc C:\Users\bob", system=r"Win /home/bob")
self.assertNotIn("bob", text)
class LauncherTests(unittest.TestCase):
def test_bug_report_text_reads_the_newest_log(self):
settings = dict(launcher.DEFAULTS, game_dir="D:/Games/GTA", resolution="1080", series_s=True, fg_limit="60")
with tempfile.TemporaryDirectory() as tmp:
repo = os.path.join(tmp, "repo")
os.makedirs(repo)
logs = os.path.join(tmp, "logs")
os.makedirs(logs)
Path(logs, "play-a.log").write_text(CARD_LOG + "ERROR boom shader=zzz\n", encoding="utf-8", newline="\n")
text = launcher.bug_report_text(settings, repo=repo, logs=logs, windows=True, system="Windows 11 (x)")
self.assertNotIn(tmp, text)
lines = text.splitlines()
self.assertIn("Version: zip copy", lines)
self.assertIn("GPU: NVIDIA GeForce RTX 4070", lines)
self.assertIn("Console profile: series-s", lines)
self.assertIn("Resolution: 1080", lines)
self.assertIn("Variables: LEONIDA_FG_LIMIT_FPS=60", lines)
self.assertEqual(lines[-1], "ERROR boom shader=<removed>")
self.assertNotIn("Games", text)
def test_bug_report_text_without_a_log(self):
with tempfile.TemporaryDirectory() as tmp:
text = launcher.bug_report_text(dict(launcher.DEFAULTS), repo=tmp, logs=os.path.join(tmp, "none"),
windows=True, system="Windows 11 (x)")
self.assertIn("no play log found", text)
self.assertIn("GPU: not in the log", text)
class SettingsLeakTests(unittest.TestCase):
def test_program_lists_show_only_their_count(self):
text = build(CARD_LOG, "", variables={"LEONIDA_PAIRED_FOR": ",".join(["0123456789abcdef"] * 44),
"LEONIDA_X": "PS_WaterDeep", "LEONIDA_URL": "http://x/y",
"LEONIDA_FG_LIMIT_FPS": "60", "LEONIDA_ON": "true"})
self.assertNotIn("0123456789abcdef", text)
self.assertNotIn("WaterDeep", text)
self.assertNotIn("http", text)
self.assertIn("LEONIDA_PAIRED_FOR=<44 entries>", text)
self.assertIn("LEONIDA_X=<set>", text)
self.assertIn("LEONIDA_FG_LIMIT_FPS=60", text)
self.assertIn("LEONIDA_ON=true", text)
def test_names_the_launcher_knows_go_through_the_allowlist(self):
log = 'INFO x: card="NVIDIA RTX D:\\jsmith\\x PS_y"\n'
text = build(log, "", console="series-s PS_x", args=["-Resolution", "PS_x", "-Dlss", "jsmith\\a"],
system=r"Windows 11 \\srv\jsmith")
for leak in ("PS_", "srv", "D:\\", "jsmith\\"):
self.assertNotIn(leak, text)
self.assertIn("Resolution: <set>", text)
def test_real_names_stay(self):
text = build('INFO x: card="Intel(R) Arc(TM) A770 Graphics"\n', "")
self.assertIn("GPU: Intel(R) Arc(TM) A770 Graphics", text)
self.assertIn("GPU: AMD Radeon RX 7800 XT", build('INFO y: card="AMD Radeon RX 7800 XT"\n', ""))
self.assertIn("Windows: Windows 11 (10.0.26300)", text)
self.assertIn("Console profile: series-x", text)
class StatusCodes(unittest.TestCase):
def test_windows_status_codes_are_kept_and_addresses_are_not(self):
out = info.scrub_line("exception 0xC0000409 at 0x7FF6A1B2C3D4, hr 0x887A0005, then 0x80070057; ptr 0x1234ABCD")
self.assertIn("0xC0000409", out)
self.assertIn("0x887A0005", out)
self.assertIn("0x80070057", out)
self.assertNotIn("7FF6A1B2C3D4", out)
self.assertNotIn("1234ABCD", out)
if __name__ == "__main__":
unittest.main()