tools/compute_heap_layout_census: validate fspx user_sgprs, strip BOM logs, extract testable main #1866

Merged
kirigayakazima merged 1 commit from upstream-pr/1866 into main 2026-11-28 20:16:20 +00:00
kirigayakazima commented 2026-11-25 13:41:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-25T13:41:19Z.


Claimed in the coordination issue as: COMPUTE-HEAP-LAYOUT-BOM-FSPX-AND-DISPATCH-LOG-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7164101436)

What and why

  • Open dispatch logs with encoding="utf-8-sig", errors="replace" in captured_layouts() (tools/compute_heap_layout_census.py) so UTF-8 BOM headers do not corrupt line 1.
  • Replace launch.exists() + unchecked json.loads(launch.read_bytes()) in program_loads() with launch.is_file(), explicit utf-8-sig decoding, path-attributed ValueError diagnostics for invalid UTF-8 / JSON / RecursionError / non-object roots, and strict type(raw_user) is int and raw_user >= 0 checking for user_sgprs (rejecting bool, str, and negative integers).
  • Extract main(argv=None) -> int catching (OSError, ValueError, KeyError, TypeError, RecursionError) to print ERROR: <exc> to stderr and return 2, with sys.stdout.reconfigure(errors="replace") under __main__.
  • Expand tests/test_compute_heap_layout_census.py with tests for BOM fspx/<name>.json fallback, directory at launch path, invalid UTF-8/JSON/type/range inputs, and BOM dispatch logs through main().

Tested

  • Patched: python -I tests/test_compute_heap_layout_census.py -v -> Ran 5 tests in 0.102s (OK).
  • Baseline check (upstream/main 5e95fa2f with updated test file copied into detached worktree): Ran 5 tests in 0.106s (FAILED (failures=3, errors=4)).
  • Repo gates: python -I tests/test_ci_registration.py (Ran 16 tests in 4.618s, OK), python -I tests/test_text_write_line_endings.py (Ran 3 tests in 12.681s, OK), python -I scripts/check_no_game_data.py (exit 0), python -I -m compileall -q (exit 0), git diff --check (exit 0).

GPUs tested: n/a (synthetic containers, listings, dispatch logs, and CLI error validation)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5492463556 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1866). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-25T13:41:19Z. --- Claimed in the coordination issue as: COMPUTE-HEAP-LAYOUT-BOM-FSPX-AND-DISPATCH-LOG-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7164101436) ### What and why - Open dispatch logs with `encoding="utf-8-sig", errors="replace"` in `captured_layouts()` (`tools/compute_heap_layout_census.py`) so UTF-8 BOM headers do not corrupt line 1. - Replace `launch.exists()` + unchecked `json.loads(launch.read_bytes())` in `program_loads()` with `launch.is_file()`, explicit `utf-8-sig` decoding, path-attributed `ValueError` diagnostics for invalid UTF-8 / JSON / `RecursionError` / non-object roots, and strict `type(raw_user) is int and raw_user >= 0` checking for `user_sgprs` (rejecting `bool`, `str`, and negative integers). - Extract `main(argv=None) -> int` catching `(OSError, ValueError, KeyError, TypeError, RecursionError)` to print `ERROR: <exc>` to `stderr` and return `2`, with `sys.stdout.reconfigure(errors="replace")` under `__main__`. - Expand `tests/test_compute_heap_layout_census.py` with tests for BOM `fspx/<name>.json` fallback, directory at launch path, invalid UTF-8/JSON/type/range inputs, and BOM dispatch logs through `main()`. ### Tested - Patched: `python -I tests/test_compute_heap_layout_census.py -v` -> `Ran 5 tests in 0.102s` (`OK`). - Baseline check (`upstream/main` `5e95fa2f` with updated test file copied into detached worktree): `Ran 5 tests in 0.106s` (`FAILED (failures=3, errors=4)`). - Repo gates: `python -I tests/test_ci_registration.py` (`Ran 16 tests in 4.618s`, `OK`), `python -I tests/test_text_write_line_endings.py` (`Ran 3 tests in 12.681s`, `OK`), `python -I scripts/check_no_game_data.py` (exit 0), `python -I -m compileall -q` (exit 0), `git diff --check` (exit 0). GPUs tested: n/a (synthetic containers, listings, dispatch logs, and CLI error validation) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
GeorgiyDemo commented 2026-11-25 14:05:41 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by GeorgiyDemo on 2026-11-25T14:05:41Z.


Tested a51fba921 on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main 71a769d7d (Python census tool; no GPU):

  • pytest 9.2.0 on tests/test_compute_heap_layout_census.py: 5 passed, 5 subtests passed at this head.
  • The same file on main: 7 failed, 3 passed — the BOM-tolerant dispatch-log reading, launch.exists()/json.loads checks and the FSPX user-SGPR validation are new.
  • Not run: real dispatch logs; the tests build the inputs synthetically.

AI-assisted; synthetic fixtures only, no game data.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7164747501 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1866#issuecomment-7164747501). Originally posted by [GeorgiyDemo](https://github.com/GeorgiyDemo) on 2026-11-25T14:05:41Z. --- Tested `a51fba921` on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against `main` `71a769d7d` (Python census tool; no GPU): - pytest 9.2.0 on `tests/test_compute_heap_layout_census.py`: **5 passed, 5 subtests passed** at this head. - The same file on `main`: **7 failed**, 3 passed — the BOM-tolerant dispatch-log reading, `launch.exists()`/`json.loads` checks and the FSPX user-SGPR validation are new. - Not run: real dispatch logs; the tests build the inputs synthetically. AI-assisted; synthetic fixtures only, no game data.
DeadlyChirp commented 2026-11-25 15:32:10 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DeadlyChirp on 2026-11-25T15:32:10Z.


Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main.

python -m pytest -q tests/test_compute_heap_layout_census.py:

  • PR: 5 passed, 5 subtests passed. main: 2 passed. The new tests pass on Windows.

(AI-assisted test run; output checked by hand.)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7166994165 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1866#issuecomment-7166994165). Originally posted by [DeadlyChirp](https://github.com/DeadlyChirp) on 2026-11-25T15:32:10Z. --- Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. `python -m pytest -q tests/test_compute_heap_layout_census.py`: - PR: 5 passed, 5 subtests passed. main: 2 passed. The new tests pass on Windows. (AI-assisted test run; output checked by hand.)
MoonEyes commented 2026-11-28 20:16:17 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T20:16:17Z.


Red/green: On main test_compute_heap_layout_census.py has 3 failures and 4 errors (BOM logs and invalid fspx user_sgprs not handled, no testable main), and with the PR all 5 tests pass on Windows 11 at OreoFR's (RTX 4070).
Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7245162736 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1866#issuecomment-7245162736). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T20:16:17Z. --- Red/green: On main test_compute_heap_layout_census.py has 3 failures and 4 errors (BOM logs and invalid fspx user_sgprs not handled, no testable main), and with the PR all 5 tests pass on Windows 11 at OreoFR's (RTX 4070). Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.
OreoFR commented 2026-11-28 21:55:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:55:24Z.


Verified by OreoFR

  • Base: main 3408969a7 + PR head 4faebe249
  • Test: python -I tests/test_compute_heap_layout_census.py
  • Red on main: 3 FAIL + 4 ERROR: partly a missing symbol (compute_heap_layout_census.main, which the PR extracts), the rest the missing validation (TypeError int/str, PermissionError on a folder)
  • Green with the PR: 5 OK
  • Verdict: READY
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246370537 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1866#issuecomment-7246370537). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T21:55:24Z. --- **Verified by OreoFR** - Base: main `3408969a7` + PR head `4faebe249` - Test: `python -I tests/test_compute_heap_layout_census.py` - Red on main: 3 FAIL + 4 ERROR: partly a missing symbol (compute_heap_layout_census.main, which the PR extracts), the rest the missing validation (TypeError int/str, PermissionError on a folder) - Green with the PR: 5 OK - Verdict: READY - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 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!1866
No description provided.