[Minor Feature] Regression tests that trigger each bug from #258–#278 #287

Closed
opened 2026-03-08 03:20:27 +00:00 by john · 1 comment
Owner

Context

The debug build system (ASan, UBSan, Valgrind, pydebug) is working correctly — when given targeted trigger code, ASan immediately catches the gridstate overflow (#258). However, the existing test suite of 243 tests exercises only normal operation paths and produces zero sanitizer findings.

The 22 bugs from the 7DRL 2026 post-mortem each require specific input sequences to trigger. Without dedicated regression tests, the sanitizer builds provide a false sense of security.

Proposal

Create tests/regression/issue_NNN_*.py for each open bug that:

  1. Constructs the specific trigger condition (e.g., entity transfer between differently-sized grids)
  2. Under normal builds: passes (the bug is latent)
  3. Under ASan/pydebug: produces a clear diagnostic (the bug is detected)
  4. After the fix: passes under all builds (regression prevented)

Bug families and their triggers:

Gridstate overflow (#258–#263, #276, #278):

  • Create entity on small grid, force gridstate init, transfer to big grid via each code path (append/extend/insert/setitem/slice), call update_visibility()

Dangling pointers (#264–#265, #270–#272, #277):

  • Get GridPointState/GridPoint Python reference, mutate underlying vector, access the reference

Refcount leaks (#267, #275):

  • Access scene.children in a loop, check sys.gettotalrefcount() growth under pydebug

Iterator invalidation (#273):

  • Call entity.die() during for e in grid.entities iteration

Missing cleanup (#274):

  • Transfer entity between grids, verify spatial hash state

Value

Each test is both a regression guard and a sanitizer calibration check — if ASan doesn't flag the gridstate test, the build is misconfigured.

  • #258–#278 (the bugs to reproduce)
  • #279 (memory safety audit meta-issue)
## Context The debug build system (ASan, UBSan, Valgrind, pydebug) is working correctly — when given targeted trigger code, ASan immediately catches the gridstate overflow (#258). However, the existing test suite of 243 tests exercises only normal operation paths and produces **zero sanitizer findings**. The 22 bugs from the 7DRL 2026 post-mortem each require specific input sequences to trigger. Without dedicated regression tests, the sanitizer builds provide a false sense of security. ## Proposal Create `tests/regression/issue_NNN_*.py` for each open bug that: 1. Constructs the specific trigger condition (e.g., entity transfer between differently-sized grids) 2. Under normal builds: passes (the bug is latent) 3. Under ASan/pydebug: produces a clear diagnostic (the bug is detected) 4. After the fix: passes under all builds (regression prevented) ### Bug families and their triggers: **Gridstate overflow (#258–#263, #276, #278):** - Create entity on small grid, force gridstate init, transfer to big grid via each code path (append/extend/insert/setitem/slice), call `update_visibility()` **Dangling pointers (#264–#265, #270–#272, #277):** - Get `GridPointState`/`GridPoint` Python reference, mutate underlying vector, access the reference **Refcount leaks (#267, #275):** - Access `scene.children` in a loop, check `sys.gettotalrefcount()` growth under pydebug **Iterator invalidation (#273):** - Call `entity.die()` during `for e in grid.entities` iteration **Missing cleanup (#274):** - Transfer entity between grids, verify spatial hash state ## Value Each test is both a **regression guard** and a **sanitizer calibration check** — if ASan doesn't flag the gridstate test, the build is misconfigured. ## Related - #258–#278 (the bugs to reproduce) - #279 (memory safety audit meta-issue)
Author
Owner

Regression test coverage update (2026-04-10)

All 5 bug families from the memory safety audit now have regression tests:

Bug Family Issues Test File Status
Gridstate overflow #258-#263, #276, #278 issue_258_gridstate_resize_test.py All transfer paths tested (set_grid, append, extend, insert, setitem, slice)
Dangling GridPoint #264 issue_264_gridpoint_dangle_test.py Covered
Dangling GridPointState #265 issue_265_gridpointstate_dangle_test.py NEW
Dangling parent_grid #270-#272, #277 issue_270_277_parent_grid_dangle_test.py Covered
Refcount leaks #267, #275 issue_267_275_refcount_test.py NEW (full check requires pydebug build)
Iterator invalidation #273 issue_273_die_during_iteration_test.py Covered
Missing cleanup #274 issue_274_set_grid_spatial_hash_test.py Covered
Entity lifecycle #266 issue_266_entity_lifecycle_test.py, issue_266_subclass_identity_test.py Covered

Remaining gap: the refcount leak tests (#267, #275) use a weak proxy (gc.collect + loop completion) in release builds. Full sys.gettotalrefcount() validation requires a pydebug build, which depends on #285 (CI pipeline) being set up.

## Regression test coverage update (2026-04-10) All 5 bug families from the memory safety audit now have regression tests: | Bug Family | Issues | Test File | Status | |---|---|---|---| | Gridstate overflow | #258-#263, #276, #278 | `issue_258_gridstate_resize_test.py` | All transfer paths tested (set_grid, append, extend, insert, setitem, slice) | | Dangling GridPoint | #264 | `issue_264_gridpoint_dangle_test.py` | Covered | | Dangling GridPointState | #265 | `issue_265_gridpointstate_dangle_test.py` | **NEW** | | Dangling parent_grid | #270-#272, #277 | `issue_270_277_parent_grid_dangle_test.py` | Covered | | Refcount leaks | #267, #275 | `issue_267_275_refcount_test.py` | **NEW** (full check requires pydebug build) | | Iterator invalidation | #273 | `issue_273_die_during_iteration_test.py` | Covered | | Missing cleanup | #274 | `issue_274_set_grid_spatial_hash_test.py` | Covered | | Entity lifecycle | #266 | `issue_266_entity_lifecycle_test.py`, `issue_266_subclass_identity_test.py` | Covered | Remaining gap: the refcount leak tests (#267, #275) use a weak proxy (gc.collect + loop completion) in release builds. Full `sys.gettotalrefcount()` validation requires a pydebug build, which depends on #285 (CI pipeline) being set up.
john closed this issue 2026-04-10 06:58:06 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
john/McRogueFace#287
No description provided.