Skip to content

tests: sgd5_effects turns every truncated database into one usage error (BUILD-1627) - #7022

Open
kapitche wants to merge 1 commit into
ItsNotRexed:mainfrom
kapitche:pyitem-r1-sgd5-struct
Open

kapitche wants to merge 1 commit into
ItsNotRexed:mainfrom
kapitche:pyitem-r1-sgd5-struct

Conversation

@kapitche

Copy link
Copy Markdown
Contributor

Claimed as BUILD-1627: #6910 (comment)

What

tools/sgd5_effects.py is listed in the Up for grabs table as raising an uncaught struct.error on truncated database fields (lines 114-132, 145-174, 258-266). On current upstream/main (bd3f061ad) I could not reproduce that: every read goes through u32(), which raises ValueError("truncated SGD5 count") before struct is touched, and main() turns ValueError into a parser error. A random-byte and every-prefix fuzz of a synthetic database (28,192 runs) gave only ValueError.

So there is no code bug to fix here. This PR adds the regression test that was missing: it cuts a synthetic database at every byte offset and runs the CLI (main) with no query, --list-effects and --effect --technique; each run must either succeed or exit 2 with a usage error, never a struct.error or IndexError traceback. The existing test_bad_framing_and_truncation only cuts at two offsets.

Only tests/test_sgd5_effects.py changes. It does not overlap #5743 (which bounds reads against the database limit and guards program_identity).

Tests

  • Linux, Python 3.12.16: ~/src/Leonida/.venv/bin/python -I tests/test_sgd5_effects.py -> Ran 11 tests in 9.9s, OK (skipped=1) (the skip needs LEONIDA_GAME_DIR). Synthetic data only.

Negative control

Removing the if pos + 4 > len(data): raise ValueError("truncated SGD5 count") guard from u32() makes the new test fail with struct.error at many cut points (e.g. cut=10, 100, 101), for all three argument sets. The guard was then restored.

AI-assisted.

@LAKSHYA-cmd-tech LAKSHYA-cmd-tech left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review on Windows 11 x64, Python 3.12.

  • Adds comprehensive truncation fuzzing across every byte offset in tests/test_sgd5_effects.py (test_every_truncation_is_a_usage_error_not_a_traceback), verifying that truncation at any field boundary always exits 2 with a clean usage/parser error and never raises an unhandled struct.error or IndexError traceback.
  • python -I -m compileall -q tests/test_sgd5_effects.py (exit 0)
  • python -I tests/test_sgd5_effects.py (11/11 passed, 1 skipped)
  • python -I tools/sgd5_effects.py --help (exit 0)
  • python -I scripts/check_no_game_data.py (exit 0)
  • git diff --check clean (0).

LGTM. AI-assisted; synthetic test harnesses only, zero game data or GPU used.

@airp1ane

Copy link
Copy Markdown
Contributor

Tested f8c403f 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: test_sgd5_effects.py - all exit 0.

AI-assisted (Claude Code).

@ne1i

ne1i commented Nov 23, 2026

Copy link
Copy Markdown

Tested f8c403f3 on Linux, CPython 3.14, CPU only, synthetic inputs, merged onto main dde82f27: pass

  • python -I tests/test_sgd5_effects.py: Ran 11 tests, OK (skipped=1). Test-only change, so there is nothing to revert.
  • compileall and scripts/check_no_game_data.py on the changed files: clean.

Independent check (not the author). Run by an AI agent (DeepSeek V4.1 Flash) and re-run by the orchestrating session (Claude Code) before posting; claimed in #8047.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants