test: integrate Hypothesis property-based testing for the backend#3403
Draft
gantoine wants to merge 2 commits into
Draft
test: integrate Hypothesis property-based testing for the backend#3403gantoine wants to merge 2 commits into
gantoine wants to merge 2 commits into
Conversation
Add Hypothesis to the test dependency group with CI/dev profiles, and introduce property-based tests for high-value pure functions: crc32_to_hex, filesystem and LaunchBox filename sanitization, LaunchBox metadata parsers, and ROM filename tag parsing. https://claude.ai/code/session_01GCTFmzuhvqNbSAfw3rGxmj
Extend Hypothesis coverage to the security-critical URL validator (globally-routable IPs allowed; private/loopback/link-local/multicast and internal TLDs always blocked; non-http schemes rejected; never leaks non-ValidationError exceptions) and to CHD v5 header SHA1 extraction (valid headers, version/signature/truncation rejection, robustness on arbitrary bytes). Adds light property coverage for username/email validators. https://claude.ai/code/session_01GCTFmzuhvqNbSAfw3rGxmj
Contributor
Contributor
Contributor
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified FilesNo covered modified files...
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduces Hypothesis property-based testing into the backend's existing pytest suite, plus a starter set of property tests for high-value pure functions.
Setup
hypothesis ~= 6.0to thetestoptional-dependency group (uv.lockupdated minimally — single package entry, no resolver churn).ci(200 examples) anddev(50 examples) profiles inbackend/tests/conftest.py, selected viaHYPOTHESIS_PROFILE(defaults todev);deadline=Noneto avoid flakiness on slow runners.HYPOTHESIS_PROFILE: ciin the pytest CI workflow..hypothesisexample database.Property tests added
crc32_to_hex— output is always 8 lowercase hex chars; 32-bit roundtrip.sanitize_filename(filesystem + LaunchBox variants) — no invalid chars, stripped, idempotent.parse_list,dedupe_words,parse_release_date.parse_tags(ROM filename tags) — never raises, deterministic, known region/language codes map to known names.validate_url_for_http_request(SSRF) — globally-routable IPs allowed; private/loopback/link-local/multicast (IPv4 + IPv6) and internal TLDs always blocked; non-http(s)schemes rejected; never leaks a non-ValidationErrorexception.extract_chd_hash(CHD v5) — valid headers return the embedded SHA1; version/signature/truncation rejected; robust on arbitrary bytes.Tests live alongside the existing mirrored test structure; no DB interaction.
Test plan
uv sync --extra testcd backend && uv run pytest -qpasses on the mariadb and postgresql CI matrix legsdevandciprofileshttps://claude.ai/code/session_01GCTFmzuhvqNbSAfw3rGxmj
Generated by Claude Code