Files
mandy/tests/test_missing_input_exit_codes.py
Kam471 d1490e359e BUILD-1046: missing inputs exit 2; image_query_probe help before oracle
Eleven tools treated a nonexistent input folder as a failed run (1). They now print one ERROR line and return 2, while real read failures keep exit 1. image_query_probe imports the hardware oracle only for a GPU run, so --help stays prompt. A table-driven subprocess test covers all eleven; existing expectations are updated.
2026-11-22 21:11:07 +00:00

65 lines
2.2 KiB
Python

"""BUILD-1046: a missing input path is a usage error (exit 2), not a failed run (exit 1).
Each tool is run with a nonexistent positional input. All of them build their inputs themselves in this test;
no game file or asset is used. `image_query_probe.py --help` is bounded so its argument parsing cannot grow the
hardware-oracle startup cost back in.
"""
import os
import subprocess
import sys
import unittest
HERE = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.dirname(HERE)
TOOLS = os.path.join(ROOT, "tools")
MISSING_INPUT_TOOLS = (
"analyze_4240_full",
"audio_config",
"bary_fallback_gs",
"content_definitions",
"cpu_ref",
"gamedata_maps",
"navmesh_index",
"pe_inspect",
"rtti_scan",
"shader_disasm",
"tile_probe",
)
# One process per tool; a hung import is a failure, not an infinite test.
TIMEOUT = 120
def run_tool(tool, *args, timeout=TIMEOUT):
return subprocess.run([sys.executable, "-I", os.path.join(TOOLS, tool + ".py"), *args],
capture_output=True, text=True, timeout=timeout, errors="replace")
class MissingInputExitCodeTests(unittest.TestCase):
def test_missing_input_is_exit_2_with_one_error_line(self):
missing = os.path.join(HERE, "no-such-input-for-build-1046")
self.assertFalse(os.path.exists(missing), "the fixture path must not exist")
for tool in MISSING_INPUT_TOOLS:
with self.subTest(tool=tool):
p = run_tool(tool, missing)
self.assertEqual(p.returncode, 2, p.stderr)
self.assertNotIn("Traceback", p.stderr)
lines = p.stderr.strip().splitlines()
self.assertEqual(len(lines), 1, p.stderr)
self.assertTrue(lines[0].strip())
self.assertTrue(lines[0].startswith("ERROR:"), p.stderr)
self.assertIn(missing, p.stderr)
class ImageQueryProbeHelpTests(unittest.TestCase):
def test_help_returns_promptly_without_the_hardware_oracle(self):
p = run_tool("image_query_probe", "--help", timeout=2)
self.assertEqual(p.returncode, 0, p.stderr)
self.assertIn("--self-test", p.stdout)
self.assertNotIn("Traceback", p.stderr)
if __name__ == "__main__":
unittest.main()