mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 09:08:38 +00:00
Puts a short plain-text block (25 lines at most) on the clipboard: the Leonida commit, Windows version, the card the newest d3d12 play log names, the play settings in effect and up to 10 scrubbed error lines of that log. The block builder and the scrub (home folder, hex runs, 0x values, hex-like names after shader stage words, program/shader/pipeline/pso/hash values, 200-character cut) are pure functions in tools/bug_report_info.py. The driver version and, mostly, the video memory are not in the runtime's log and read "not in the log". No game data, no paths. Claim: LAUNCHER-COPY-REPORT (#3312) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
234 lines
12 KiB
Python
234 lines
12 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):
|
|
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):
|
|
out = info.scrub_line(f"open {path} failed")
|
|
self.assertIn("%USERPROFILE%", out)
|
|
self.assertNotIn("bob", out)
|
|
self.assertNotIn("Dupont", out)
|
|
self.assertEqual(info.scrub_line(r"C:\Users\bob started"), "%USERPROFILE% started")
|
|
self.assertEqual(info.scrub_line("a home/ folder"), "a home/ folder")
|
|
|
|
def test_hex_runs(self):
|
|
out = info.scrub_line("fault at 00007FF6A1B2C3D4 and deadbeef and 1234567")
|
|
self.assertNotIn("7FF6", out)
|
|
self.assertNotIn("deadbeef", out)
|
|
self.assertIn("1234567", out) # 7 digits stay
|
|
self.assertEqual(info.scrub_line("t=10:00:00.123456789Z ok"), "t=10:00:00.123456789Z ok")
|
|
|
|
def test_hex_values(self):
|
|
out = info.scrub_line("status 0xC0000409 and 0x1f")
|
|
self.assertNotIn("0x", out)
|
|
self.assertNotIn("C0000409", out)
|
|
|
|
def test_stage_names(self):
|
|
for text in ("ps_1a2b3c", "vs 8F3A9C", "cs=beef", "GS:cafe", "ms-abcd12_main", "ds_deadbeef", "hs_0123", "as_f00d"):
|
|
with self.subTest(text=text):
|
|
out = info.scrub_line(f"compile {text} failed")
|
|
self.assertEqual(out.split()[1][:3].lower().rstrip("_:=-"), text[:2].lower())
|
|
self.assertIn("<name>", out)
|
|
for kept in ("as added", "ps_5_0", "cs of the box", "vs bad"):
|
|
with self.subTest(kept=kept):
|
|
self.assertEqual(info.scrub_line(f"x {kept} y"), f"x {kept} y")
|
|
|
|
def test_named_values(self):
|
|
for key in ("program", "shader", "pipeline", "pso", "hash", "shader_hash", "PSO"):
|
|
for value in ("secret_name", '"two words"', "'q v'", "12"):
|
|
with self.subTest(key=key, value=value):
|
|
out = info.scrub_line(f"error {key}={value}, next=1")
|
|
self.assertNotIn("secret", out)
|
|
self.assertNotIn("two", out)
|
|
self.assertNotIn("q v", out)
|
|
self.assertIn(f"{key}=<removed>", out)
|
|
self.assertIn("next=1", out)
|
|
self.assertIn("hash = <removed>", info.scrub_line("hash = abc"))
|
|
|
|
def test_cut_comes_after_the_scrub(self):
|
|
out = info.scrub_line("error " + "x" * 190 + " shader=" + "y" * 50)
|
|
self.assertLessEqual(len(out), info.MAX_LINE)
|
|
self.assertNotIn("y" * 5, out)
|
|
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", "<hex>"[:0] or "exit <hex>"])
|
|
|
|
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].replace("shader=<removed>", ""))
|
|
|
|
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 <hex>",
|
|
"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=<path>", 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)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|