rbf0_encode: write back a short-count element with text or child content (carry of #2386) #3096

Merged
leonida/mandy
MoonEyes merged 3 commits from carry/2386 into main 2026-12-02 20:47:34 +00:00

Pull request successfully merged and closed

MoonEyes commented 2026-12-02 10:31:45 +00:00

Claimed in the coordination issue as: RBF0-ENCODE-SHORT-COUNT-CONTENT (original author's item ID, claimed at https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7198218440)

What and why

Carry of #2386 (syfyra), unchanged since 2026-11-26 (head 4f1ca189); branch = main (80910637f) + the author's head (commit kept, merged without conflicts) + my commit.

The author's change: tools/rbf0_encode.py refused every element flagged attribute_order_violation as "an attribute after content", including a short-count element whose content is text or a child element, although its bytes write back exactly (docs/rbf0.md 9.6). The encoder now refuses on the flag only when an attribute record's offset follows the first content record's, or when the records carry no offsets to tell.

Review defect fixed (reviewers imShangLi, aegish-zagi and the CHANGES_REQUESTED review from aslan2142): the new code read .get("offset") of every attribute and content record before the shape checks. On current main, a malformed attributes or content (None, [123], ["bad"]) raised TypeError or AttributeError instead of EncodeError("value"), which failed 4 subtests of test_bool_recorded_lengths_and_malformed_element_children. My commit moves the shape checks ahead of the offset lists and adds a regression subtest (a flagged element with each of the four malformed shapes must refuse with value).

Tested

Windows 11, Python 3.14, no GPU, no game files, on main 80910637f plus this branch:

  • python -I tests/test_rbf0_encode.py: 41 tests, OK.
  • python -I tests/test_rbf0_tree.py: 38 tests, OK (1 skipped).
  • Before my commit, the merged tree failed python -I tests/test_rbf0_encode.py with 41 tests, errors=4, as the reviewers reported.
  • Red: with tools/rbf0_encode.py restored to main's version and this branch's tests kept, python -I tests/test_rbf0_encode.py runs 41 tests, FAILED (failures=4, errors=2), all six in subtests of test_fewer_attribute_records_than_the_count: 2 errors for the text and child short-count cases, 4 failures for the flagged malformed-record cases. The file was restored afterwards.
  • python -I scripts/check_no_game_data.py tools/rbf0_encode.py tests/test_rbf0_encode.py: clean.

Not run: the full suite, CI.

GPUs tested: n/a (unit tests only)

AI-assisted: yes. Models: Claude Opus 5.5 in Claude Code (carry, conflict resolution, fixes, tests); separate read-only reviewer agent: Claude Opus 5.5.

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. (n/a: no translator change)

Supersedes #2386 once merged; the original stays open until a maintainer decides.

🤖 Generated with Claude Code

Claimed in the coordination issue as: RBF0-ENCODE-SHORT-COUNT-CONTENT (original author's item ID, claimed at https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7198218440) ### What and why Carry of #2386 (syfyra), unchanged since 2026-11-26 (head `4f1ca189`); branch = main (`80910637f`) + the author's head (commit kept, merged without conflicts) + my commit. The author's change: `tools/rbf0_encode.py` refused every element flagged `attribute_order_violation` as "an attribute after content", including a short-count element whose content is text or a child element, although its bytes write back exactly (`docs/rbf0.md` 9.6). The encoder now refuses on the flag only when an attribute record's offset follows the first content record's, or when the records carry no offsets to tell. Review defect fixed (reviewers `imShangLi`, `aegish-zagi` and the CHANGES_REQUESTED review from `aslan2142`): the new code read `.get("offset")` of every attribute and content record before the shape checks. On current main, a malformed `attributes` or `content` (`None`, `[123]`, `["bad"]`) raised `TypeError` or `AttributeError` instead of `EncodeError("value")`, which failed 4 subtests of `test_bool_recorded_lengths_and_malformed_element_children`. My commit moves the shape checks ahead of the offset lists and adds a regression subtest (a flagged element with each of the four malformed shapes must refuse with `value`). ### Tested Windows 11, Python 3.14, no GPU, no game files, on main `80910637f` plus this branch: - `python -I tests/test_rbf0_encode.py`: 41 tests, OK. - `python -I tests/test_rbf0_tree.py`: 38 tests, OK (1 skipped). - Before my commit, the merged tree failed `python -I tests/test_rbf0_encode.py` with 41 tests, errors=4, as the reviewers reported. - Red: with `tools/rbf0_encode.py` restored to main's version and this branch's tests kept, `python -I tests/test_rbf0_encode.py` runs 41 tests, FAILED (failures=4, errors=2), all six in subtests of `test_fewer_attribute_records_than_the_count`: 2 errors for the text and child short-count cases, 4 failures for the flagged malformed-record cases. The file was restored afterwards. - `python -I scripts/check_no_game_data.py tools/rbf0_encode.py tests/test_rbf0_encode.py`: clean. Not run: the full suite, CI. GPUs tested: n/a (unit tests only) AI-assisted: yes. Models: Claude Opus 5.5 in Claude Code (carry, conflict resolution, fixes, tests); separate read-only reviewer agent: Claude Opus 5.5. ### 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. (n/a: no translator change) Supersedes #2386 once merged; the original stays open until a maintainer decides. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
OreoFR commented 2026-12-02 12:19:01 +00:00

Verified by OreoFR (oreofr-agent, AI-assisted; third-party red/green). Head b56408e2d79ac1e048c0f53f7d06e80dcf450ecf merged into main f6dd2242e02b5f579d245f1c19dd5150d42e00a1 with no conflicts. Windows 11, Python 3.12, CPU only.

  • Green: tests/test_rbf0_encode.py OK; tests/test_rbf0_tree.py OK (skipped=1).
  • Red, with main's tools/rbf0_encode.py restored and this PR's tests kept: test_rbf0_encode.py FAILED (failures=4, errors=2), matching the description; test_rbf0_tree.py unchanged, OK.
    Safe to merge: it merges cleanly, CI is green, and it touches only a tool and its test. Not merged by me.
**Verified by OreoFR** (oreofr-agent, AI-assisted; third-party red/green). Head `b56408e2d79ac1e048c0f53f7d06e80dcf450ecf` merged into main `f6dd2242e02b5f579d245f1c19dd5150d42e00a1` with no conflicts. Windows 11, Python 3.12, CPU only. - Green: `tests/test_rbf0_encode.py` OK; `tests/test_rbf0_tree.py` OK (skipped=1). - Red, with main's `tools/rbf0_encode.py` restored and this PR's tests kept: `test_rbf0_encode.py` FAILED (failures=4, errors=2), matching the description; `test_rbf0_tree.py` unchanged, OK. Safe to merge: it merges cleanly, CI is green, and it touches only a tool and its test. Not merged by me.
Kal0s-design commented 2026-12-02 12:56:05 +00:00

Ran natively on Windows 11, Python 3.13, head b56408e2d merged into current main (23a51c494), no conflicts.

py -3.13 -I tests/test_rbf0_encode.py: OK. Red/green is already shown twice above, so I tried to find an element the narrower check now lets through but does not write back exactly.

Sweep with throwaway streams built by the test file's Stream helper: root element with a declared attribute count of 0..3, followed by every sequence of 0..4 records drawn from {int, bool, string, text, empty child, child with one attribute}, in both the wide and the narrow form. That is 12,440 elements. Each one goes rbf0_tree.parse_resource -> rbf0_encode.encode and the output is compared with the input bytes.

result this PR main
written back byte-exact, not flagged 5,852 5,852
written back byte-exact, flagged attribute_order_violation 1,404 0
refused order 5,184 6,588
written back but bytes differ 0 0
any other exception 0 0

So the 1,404 shapes the PR now accepts all round-trip exactly, and nothing encodes to different bytes. To check that the 5,184 still refused really need refusing, I dropped the flag from each of them and encoded again: 1,188 then come out with different bytes and 3,996 are refused as descriptor. None of them would have written back exactly, so the new check does not refuse anything it could have kept, at least in this space.

Not checked: nesting deeper than one child, more than 4 records per element, real resources (no game files used).

GPUs tested: n/a (CPU-only tests).

AI-assisted: yes (Claude Code).

Ran natively on Windows 11, Python 3.13, head `b56408e2d` merged into current `main` (`23a51c494`), no conflicts. `py -3.13 -I tests/test_rbf0_encode.py`: OK. Red/green is already shown twice above, so I tried to find an element the narrower check now lets through but does not write back exactly. Sweep with throwaway streams built by the test file's `Stream` helper: root element with a declared attribute count of 0..3, followed by every sequence of 0..4 records drawn from {int, bool, string, text, empty child, child with one attribute}, in both the wide and the narrow form. That is 12,440 elements. Each one goes `rbf0_tree.parse_resource` -> `rbf0_encode.encode` and the output is compared with the input bytes. | result | this PR | main | |---|---|---| | written back byte-exact, not flagged | 5,852 | 5,852 | | written back byte-exact, flagged `attribute_order_violation` | 1,404 | 0 | | refused `order` | 5,184 | 6,588 | | written back but bytes differ | 0 | 0 | | any other exception | 0 | 0 | So the 1,404 shapes the PR now accepts all round-trip exactly, and nothing encodes to different bytes. To check that the 5,184 still refused really need refusing, I dropped the flag from each of them and encoded again: 1,188 then come out with different bytes and 3,996 are refused as `descriptor`. None of them would have written back exactly, so the new check does not refuse anything it could have kept, at least in this space. Not checked: nesting deeper than one child, more than 4 records per element, real resources (no game files used). GPUs tested: n/a (CPU-only tests). AI-assisted: yes (Claude Code).
aegish-zagi commented 2026-12-02 14:37:55 +00:00

Verification — VERIFY-3096

PR #3096 — rbf0_encode: write back a short-count element with text or child content (carry of #2386)
Head b56408e2d79ac1e048c0f53f7d06e80dcf450ecf; MERGEABLE against current main (acc350745)
Tests run The PR's tests/test_rbf0_encode.py run standalone in a scratch worktree: (a) PR test file against plain main code, (b) PR test file against the PR head
Red on main FAILED (failures=4, errors=2) of 41 tests on main code
Green on PR All 41 tests pass with the PR head (OK); the 35 tests that passed on main still pass — no regressions
Diff audit tools/rbf0_encode.py + its test only: the short-count element write-back now carries text/child content instead of dropping it. One topic, claim in place (carry of #2386), no game data
Verdict PASS — red on main, green on the PR
Platform Linux, Python 3.12.3, no GPU (Profile Z)

AI-assisted: yes (Muse Wonder, Muse by Meta)

Verification — VERIFY-3096 | | | |---|---| | PR | #3096 — rbf0_encode: write back a short-count element with text or child content (carry of #2386) | | Head | b56408e2d79ac1e048c0f53f7d06e80dcf450ecf; MERGEABLE against current main (acc350745) | | Tests run | The PR's `tests/test_rbf0_encode.py` run standalone in a scratch worktree: (a) PR test file against plain main code, (b) PR test file against the PR head | | Red on main | **FAILED (failures=4, errors=2)** of 41 tests on main code | | Green on PR | All 41 tests pass with the PR head (OK); the 35 tests that passed on main still pass — no regressions | | Diff audit | tools/rbf0_encode.py + its test only: the short-count element write-back now carries text/child content instead of dropping it. One topic, claim in place (carry of #2386), no game data | | Verdict | **PASS** — red on main, green on the PR | | Platform | Linux, Python 3.12.3, no GPU (Profile Z) | AI-assisted: yes (Muse Wonder, Muse by Meta)
MoonEyes commented 2026-12-02 20:36:02 +00:00

Merging. Head b56408e2d merges cleanly with main b41763227 and does not force a rebase of #2566. Carry of #2386, CI green on this head Merged by MoonEyes.

AI-assisted (Claude Code).

Merging. Head `b56408e2d` merges cleanly with `main` `b41763227` and does not force a rebase of #2566. Carry of #2386, CI green on this head Merged by MoonEyes. AI-assisted (Claude Code).
Sign in to join this conversation.
No description provided.