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

Open
github-bot wants to merge 1 commit from github-bot/gh-1866 into main AGit
Owner

@⁠kirigayakazima on GitHub · 2026-11-25 13:41 UTC · original
kirigayakazima:fix/compute-heap-layout-safety → main · +117 −11 · 2 files · 1 commits · open

Claimed in the coordination issue as: COMPUTE-HEAP-LAYOUT-BOM-FSPX-AND-DISPATCH-LOG-SAFETY (#1608)

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.
**@⁠kirigayakazima** on GitHub · 2026-11-25 13:41 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1866) `kirigayakazima:fix/compute-heap-layout-safety` → `main` · +117 −11 · 2 files · 1 commits · open Claimed in the coordination issue as: COMPUTE-HEAP-LAYOUT-BOM-FSPX-AND-DISPATCH-LOG-SAFETY (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:09:18 +00:00
Author
Owner

@⁠GeorgiyDemo on GitHub · 2026-11-25 14:05 UTC · original

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.

**@⁠GeorgiyDemo** on GitHub · 2026-11-25 14:05 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1866#issuecomment-7164747501) 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.
Author
Owner

@⁠DeadlyChirp on GitHub · 2026-11-25 15:32 UTC · original

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.)

**@⁠DeadlyChirp** on GitHub · 2026-11-25 15:32 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1866#issuecomment-7166994165) 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.)
github-bot force-pushed github-bot/gh-1866 from a51fba9217 to 4faebe249c 2026-11-27 12:04:14 +00:00 Compare
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1866/head:github-bot/gh-1866'
git switch 'github-bot/gh-1866'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1866'
git switch 'github-bot/gh-1866'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1866'
git switch 'github-bot/gh-1866'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1866'
git switch 'main'
git merge --squash 'github-bot/gh-1866'
git switch 'main'
git merge --ff-only 'github-bot/gh-1866'
git switch 'main'
git merge 'github-bot/gh-1866'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.