Skip to content

test: integrate Hypothesis property-based testing for the backend#3403

Draft
gantoine wants to merge 2 commits into
masterfrom
claude/exciting-heisenberg-61PF9
Draft

test: integrate Hypothesis property-based testing for the backend#3403
gantoine wants to merge 2 commits into
masterfrom
claude/exciting-heisenberg-61PF9

Conversation

@gantoine

Copy link
Copy Markdown
Member

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

  • Add hypothesis ~= 6.0 to the test optional-dependency group (uv.lock updated minimally — single package entry, no resolver churn).
  • Register ci (200 examples) and dev (50 examples) profiles in backend/tests/conftest.py, selected via HYPOTHESIS_PROFILE (defaults to dev); deadline=None to avoid flakiness on slow runners.
  • Set HYPOTHESIS_PROFILE: ci in the pytest CI workflow.
  • Ignore the local .hypothesis example 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.
  • LaunchBox parsersparse_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-ValidationError exception.
  • extract_chd_hash (CHD v5) — valid headers return the embedded SHA1; version/signature/truncation rejected; robust on arbitrary bytes.
  • Light bonus coverage for the username/email validators.

Tests live alongside the existing mirrored test structure; no DB interaction.

Test plan

  • uv sync --extra test
  • cd backend && uv run pytest -q passes on the mariadb and postgresql CI matrix legs
  • New property tests pass under both dev and ci profiles

Note: verified locally — all new property tests pass under the 200-example ci profile. The pre-existing test_extract_chd_hash_permission_error fails only when the suite runs as root (root bypasses chmod(0o000)); it is unrelated to this change and passes under a normal user / CI.

https://claude.ai/code/session_01GCTFmzuhvqNbSAfw3rGxmj


Generated by Claude Code

claude added 2 commits May 21, 2026 16:40
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
@github-actions

Copy link
Copy Markdown
Contributor

Test Results (postgresql)

    1 files  ± 0      1 suites  ±0   4m 59s ⏱️ +52s
1 404 tests +33  1 404 ✅ +33  0 💤 ±0  0 ❌ ±0 
1 406 runs  +33  1 406 ✅ +33  0 💤 ±0  0 ❌ ±0 

Results for commit 4f3d75a. ± Comparison against base commit 76d8af6.

@github-actions

Copy link
Copy Markdown
Contributor

Test Results (mariadb)

    1 files  ± 0      1 suites  ±0   4m 56s ⏱️ +28s
1 404 tests +33  1 404 ✅ +33  0 💤 ±0  0 ❌ ±0 
1 406 runs  +33  1 406 ✅ +33  0 💤 ±0  0 ❌ ±0 

Results for commit 4f3d75a. ± Comparison against base commit 76d8af6.

@github-actions

Copy link
Copy Markdown
Contributor

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
16456 11515 70% 0% 🟢

New Files

No new covered files...

Modified Files

No covered modified files...

updated for commit: 4f3d75a by action🐍

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.

2 participants