veh_spawn_intensities: handle empty tables, count MudMin>0, guard carve overwrites/paths, and write JSON atomically (VEH-SPAWN-INTENSITIES-AGG-AND-IO) #1580

Merged
IlyassRS3 merged 1 commit from upstream-pr/1580 into main 2026-11-28 10:54:34 +00:00
IlyassRS3 commented 2026-11-25 04:59:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T04:59:45Z.


Item ID: VEH-SPAWN-INTENSITIES-AGG-AND-IO (new item; coordination issue #14 is at GitHub's 2,500-comment cap with no open successor at PR time — confirmed 0 open PRs touch tools/veh_spawn_intensities.py)

Summary

  • Handle empty VehSpawnIntensities tables in aggregate(): max(len(sig) for sig in signatures) previously crashed with ValueError: max() iterable argument is empty; using default=0 returns a valid zero-entry aggregate.
  • Count MudMin > 0 as well as MudMax > 0 in bands_with_mud: matches the documented rule (MudMin/MudMax above zero) instead of checking only MudMax.
  • Guard carve directory inputs and validate --json before scanning:
    • When input is a carve directory, guard <input>/index.json and .bin/.bk2 streams (including hardlink/case aliases via same_report_path) so --json can never overwrite carve inputs.
    • Reject empty/whitespace --json paths (previously "" was silently ignored and " " created a literal " " file) and existing directories before reading or printing stdout.
  • Write --json atomically before printing stdout and catch RecursionError: stage via NamedTemporaryFile + file_mode.published_mode + replace_retry.replace with allow_nan=False, cleaning up temp files on failure so existing reports are never truncated and failed runs emit no misleading stdout JSON.

Testing

  • AI-assisted: yes
  • GPUs tested: none (CPU/Python stdlib tool; no GPU, no game files)
  • python3 -W error -I tests/test_veh_spawn_intensities.py -v: 12/12 passed
  • python3 -W error -I tests/test_text_write_line_endings.py -v: 3/3 passed
  • python3 -I scripts/check_no_game_data.py tools/veh_spawn_intensities.py tests/test_veh_spawn_intensities.py: passed
  • python3 -m compileall -q make_game.py tools tests: passed
  • Mutation check against unpatched main:tools/veh_spawn_intensities.py: all 3 new tests fail (FAILED (failures=4, errors=2)).
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5485465090 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1580). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T04:59:45Z. --- Item ID: `VEH-SPAWN-INTENSITIES-AGG-AND-IO` (new item; coordination issue #14 is at GitHub's 2,500-comment cap with no open successor at PR time — confirmed 0 open PRs touch `tools/veh_spawn_intensities.py`) ## Summary - **Handle empty `VehSpawnIntensities` tables in `aggregate()`**: `max(len(sig) for sig in signatures)` previously crashed with `ValueError: max() iterable argument is empty`; using `default=0` returns a valid zero-entry aggregate. - **Count `MudMin > 0` as well as `MudMax > 0` in `bands_with_mud`**: matches the documented rule (`MudMin`/`MudMax` above zero) instead of checking only `MudMax`. - **Guard carve directory inputs and validate `--json` before scanning**: - When `input` is a carve directory, guard `<input>/index.json` and `.bin`/`.bk2` streams (including hardlink/case aliases via `same_report_path`) so `--json` can never overwrite carve inputs. - Reject empty/whitespace `--json` paths (previously `""` was silently ignored and `" "` created a literal `" "` file) and existing directories before reading or printing stdout. - **Write `--json` atomically before printing stdout and catch `RecursionError`**: stage via `NamedTemporaryFile` + `file_mode.published_mode` + `replace_retry.replace` with `allow_nan=False`, cleaning up temp files on failure so existing reports are never truncated and failed runs emit no misleading stdout JSON. ## Testing - AI-assisted: yes - GPUs tested: none (CPU/Python stdlib tool; no GPU, no game files) - `python3 -W error -I tests/test_veh_spawn_intensities.py -v`: **12/12 passed** - `python3 -W error -I tests/test_text_write_line_endings.py -v`: **3/3 passed** - `python3 -I scripts/check_no_game_data.py tools/veh_spawn_intensities.py tests/test_veh_spawn_intensities.py`: passed - `python3 -m compileall -q make_game.py tools tests`: passed - Mutation check against unpatched `main:tools/veh_spawn_intensities.py`: all 3 new tests fail (`FAILED (failures=4, errors=2)`).
copilot-pull-request-reviewer[bot] commented 2026-11-25 05:00:02 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T05:00:02Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6052088302 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1580#pullrequestreview-6052088302). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T05:00:02Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
MoonEyes commented 2026-11-28 10:54:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T10:54:31Z.


Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18).
Targeted batch of 19 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238199921 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1580#issuecomment-7238199921). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T10:54:31Z. --- Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18). Targeted batch of 19 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1580
No description provided.