Repository navigation
find_hash_lookup: --window and --top below 1 are a usage error, not a misleading empty report - #7065
antoinecaputo wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
3 open issues
These tests invoke subprocesses without a timeout, which can lead to hung test runs if the tool… · New These tests invoke subprocesses without a timeout, which can lead to hung test runs if the tool… · New Thepositive_intdocstring describes a specific historical bug scenario rather than the… · New
What changed in this PR
This PR makes find_hash_lookup treat --window/--top values below 1 as CLI usage errors (exit code 2) instead of producing an empty/misleading report with exit code 0.
Changes:
- Add a shared argparse type (
positive_int) enforcing integer values>= 1for--windowand--top. - Add CLI tests ensuring below-1 values fail with a clear argparse error and valid explicit values still produce expected output.
| File | Description |
|---|---|
| tools/find_hash_lookup.py | Adds positive_int argparse type and applies it to --window/--top to reject values below 1. |
| tests/test_find_hash_lookup.py | Adds subprocess-based tests covering below-1 error behavior and a control case for valid explicit args. |
Review effort: Lite
| r = subprocess.run([sys.executable, "-I", TOOL, exe, flag, value], | ||
| capture_output=True, text=True) |
There was a problem hiding this comment.
The file's existing tests call subprocess.run the same way with no timeout (tests/test_find_hash_lookup.py:95, :103 — both pre-date this PR), and across the repo's 245 test files that spawn subprocesses only two pass a timeout. The new tests match that convention; the tool scans a hand-written <1 KB image and these invocations exit well under a second. Happy to add timeouts if the maintainer wants them file-wide.
| r = subprocess.run([sys.executable, "-I", TOOL, exe, "--window", "8", "--top", "2"], | ||
| capture_output=True, text=True) |
There was a problem hiding this comment.
Same as the other new test: the file and the repo run these CLI tests without timeouts (tests/test_find_hash_lookup.py:95, :103; two timeouts across the 245 test files that spawn subprocesses), and this control run exits in milliseconds on the synthetic image.
|
|
||
|
|
||
| def positive_int(text): | ||
| """--window 0 searched no bytes after a hash and --top 0 ranked nobody; the report blamed the window.""" |
There was a problem hiding this comment.
That historical phrasing is the house style for these argparse type functions — the docstring records what the bad value used to do, so the guard's reason survives out of context: anim_index.byte_count ("--limit: at least 1; 0 used to mean no limit and a negative value silently scanned less."), psin_index.count, fssm_header.non_negative ("a negative one would slice from the end (paths[:-1] drops the last blob)"). The new one copies that shape.
|
Tested 5b3a55c merged with main 8575d36 on Linux/Python 3.12.16: pass Merge was clean (tools/find_hash_lookup.py, tests/test_find_hash_lookup.py).
Diff read: |
… misleading empty report
5b3a55c to
fb264c1
Compare
|
Rebased onto main 042c5f3 (conflict with 115f3b2's new |
|
Tested fb264c1 on Windows 11, Python 3.15.2, NVIDIA RTX 4060 Ti (driver 621.24; CPU-only checks, no game files, no GPU/llvm-mc/MSVC used): pass. Ran the test files this PR adds or changes, from a clean checkout of the PR head: AI-assisted (Claude Code). |


--windowand--topwere plaintype=intused unchecked (code[at+4:at+4+window],ranked[:top]). With a synthetic PE whose.textholds one joaat constant followed by a directE8 rel32call, the default run reports the caller (0x1000 callers 1 led by player_story000_00, exit 0), but--top 0,--window 0and negative values each printno direct call follows any of the hashes: try a larger --windowand exit 0: the hash IS found, the empty slice just drops it and blames the window.The fix is the repo's established at-least-1 argparse type (the
anim_index.byte_count/psin_index.countshape,must be at least 1), shared by both flags the wayrestofworld_indexshares one type across--limit/--max-inflate. Help texts unchanged.Tests: two new cases in
tests/test_find_hash_lookup.pyreusing its PE builders — the four below-1 runs each exit 2 withargument <flag>: must be at least 1and never the misleading line; a control that explicit valid values still find the caller. Red on main (the four subtests fail there).The
--jsonreport-path PRs on this file (#5353, #4734, #5532) and the latin-1 hashing ones (#4753, #4882) are not touched.Tested:
python -I tests/test_find_hash_lookup.py(6 tests OK), compileall; macOS / CPython 3.14.7. CPU only; the PE is hand-written bytes; no game files.Claim: #6910 (comment)
AI-assisted.