Repository navigation
feat(artifacts): inspect NES 2.0 container headers and regions - #10674
Conversation
Problem: the iNES lane refused every header whose byte 7 bits 2-3 select NES 2.0, so NES 2.0 cartridges could not be inventoried, extracted or reconstructed even though their file layout extends classic iNES. Fix: the single iNES-family header parser now reads NES 2.0 alongside classic iNES. It reports the 12-bit mapper, submapper, 12-bit and exponent-multiplier PRG/CHR sizes, declared PRG/CHR RAM and NVRAM sizes, CPU/PPU timing, console type with Vs. System and extended console codes, miscellaneous ROM count and default expansion device in a "nes-2.0" header variant; classic headers keep their exact serialization. Regions add one prg.bin/chr.bin for exponent sizes and misc-rom.bin for the bytes after CHR-ROM when miscellaneous ROMs are declared. Oversized declarations (with exact totals, including exponent sizes beyond safe integers), nonzero unused header bits, empty PRG-ROM and declared but absent miscellaneous ROM bytes are refused through the existing format error. Nested byte classification now admits NES 2.0 through the same parser. The reader limitation, tool description, guide and skill reference now state that UNIF remains unsupported and that RAM, timing and console values are declarations. Validation: new synthetic NES 2.0 unit cases fail on the base (15 of 24) and pass after the change; focused boundary and acceptance iNES suites (75 tests) pass, including NES 2.0 inventory, extraction, reconstruction and compiled CLI inspection; npm run check:fast passes. Refs morluto#2072
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
[Medium impact] The PR extends a bounded artifact-inspection and extraction workflow for NES cartridge files. Satisfy the shared-reader and feature-documentation requirements before merging. FindingsFix with agent prompt### Issue 1
src/domain/inesContainer.ts:28-30
The new `headerByte` wrapper still reads fields with `Buffer.readUInt8`. The parser guide requires bounded fields to use `BinaryReader`. Existing length checks protect these calls today, but moving raw reads into a helper does not satisfy that requirement. Use `BinaryReader.u8` as the shared owner of checked header reads. This repository requirement must be satisfied before merging.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
### Issue 2
docs/ines-containers.md:27-36
NES 2.0 support adds new header fields, size rules and region behavior, but no matching feature specification, plan or tasks are tracked under `docs/specs`. The documentation guide requires those three records for a feature and distinguishes them from a usage guide. Add the feature records and link this guide to them so the intended behavior and acceptance checks have a clear home. This repository requirement must be satisfied before merging.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryAdds NES 2.0 header inspection and preserves declared ROM regions, original offsets and reconstruction facts.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Selected file] --> B[Read signature and header]
B --> C{Header variant}
C --> D[Classic iNES declarations]
C --> E[NES 2.0 declarations]
D --> F[Check combined extent]
E --> F
F -->|Does not fit| G[Typed parse failure]
F -->|Fits| H[Build ordered file regions]
H --> I[Hash regions and retain source offsets]
I --> J[Verify order, byte count and whole-file digest]
J --> K[Inspection Evidence or extraction]
Reviews (12) · Last reviewed commit: "Merge main into nes2-header" · Reviewed by Greptile |
Review follow-up for NES 2.0 headers. The exponent-multiplier case stopped at parseInesLayout, and the extraction test used counted ROM units, so prg.bin and chr.bin from an exponent-sized area never went through the reader or extraction. A boundary case now builds a NES 2.0 file with a 2^10 * 3 byte PRG-ROM area beside one counted 8 KiB CHR-ROM unit. It checks the header omits the PRG unit count, the source offsets of prg.bin and chr/000.bin, the verified reconstruction order, and that the extracted regions match the original bytes exactly. Tests: tests/boundary/filesystem/inesArtifact.test.ts passes (38).
The NES 2.0 declaration added a sixth raw Buffer read to inesContainer.ts. On current main the architecture guard allows five there, so the merged tree failed Static checks. iNES and NES 2.0 declarations and the format probe now read header bytes through one headerByte helper. The file has one raw read, and its counted baseline drops from 5 to 1 through --shrink-baselines. Tests: inesContainer domain tests (24) and the NES boundary and acceptance tests (76) pass. architecture-guards, format:check and check:ci:fast pass on the branch merged with main.
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
Main now recognizes artifact formats through one registry, which already admits NES 2.0 through parseInesLayout; the old classifier chain is dropped in favour of it.
Review follow-up: the NES 2.0 declaration added plain-string failures. The iNES-family parser now returns Result<_, ParseFailure> with its kind and where it was found: - malformed: a missing signature, a dirty legacy header, an empty PRG-ROM area, reserved NES 2.0 bits or an invalid file extent; - truncated: a short header, a short payload, or declared miscellaneous ROM with no bytes; - unsupported: UNIF or another header variant, with undecoded content. The detail text is unchanged. The format registry refuses with the detail, and the iNES reader and root classifier translate the failure at their boundary into the existing format ArtifactReaderFailure, with the ParseFailureError as its cause. Tests: the refusal table now asserts each failure's kind and format as well as its detail. iNES domain and recognition tests, NES boundary and acceptance tests (76), architecture-guards, format:check and check:ci:fast pass on the branch merged with main.
Main imports the artifact reader helpers from src/resources, gives inspect_artifact explicit tool effects, and keeps each counted guard's baseline in its own file. The merge keeps the branch's ParseFailureError imports and its NES 2.0 contract wording, and lowers the raw-buffer-read baseline for inesContainer.ts from 5 to 1, as the branch did.
# Conflicts: # scripts/verify/baselines/raw-buffer-read.json # src/artifacts/InesArtifactReader.ts
| /** The one reader of header bytes; callers index inside the admitted prefix. */ | ||
| const headerByte = (prefix: Buffer, index: number): number => | ||
| prefix.readUInt8(index); |
There was a problem hiding this comment.
Header reads bypass required reader
The new headerByte wrapper still reads fields with Buffer.readUInt8. The parser guide requires bounded fields to use BinaryReader. Existing length checks protect these calls today, but moving raw reads into a helper does not satisfy that requirement. Use BinaryReader.u8 as the shared owner of checked header reads. This repository requirement must be satisfied before merging.
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/inesContainer.ts
Line: 28-30
Comment:
**Header reads bypass required reader**
The new `headerByte` wrapper still reads fields with `Buffer.readUInt8`. The parser guide requires bounded fields to use `BinaryReader`. Existing length checks protect these calls today, but moving raw reads into a helper does not satisfy that requirement. Use `BinaryReader.u8` as the shared owner of checked header reads. This repository requirement must be satisfied before merging.
**Context Used:** AGENTS.md ([source](https://github.com/morluto/rea/blob/main/AGENTS.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| - NES 2.0 headers add `prg_rom_bytes`/`chr_rom_bytes`, the 12-bit mapper and | ||
| `submapper`, `console_type`, `cpu_ppu_timing`, declared PRG-RAM, | ||
| PRG-NVRAM, CHR-RAM and CHR-NVRAM byte sizes (`0` when none is declared), | ||
| `misc_rom_count` and `default_expansion_device`. Vs. System headers add | ||
| `vs_ppu_type` and `vs_hardware_type`; extended console headers add | ||
| `extended_console_type`. These codes are reported as numbers. When the | ||
| exponent-multiplier form declares a ROM size, its unit count is omitted | ||
| rather than reported as zero. `nametable_layout_flags` preserves byte 6's | ||
| `arrangement_bit` (bit 0) and `alternative_layout_bit` (bit 3) as header | ||
| flags. Their effective behavior can depend on the mapper. |
There was a problem hiding this comment.
Required feature records are missing
NES 2.0 support adds new header fields, size rules and region behavior, but no matching feature specification, plan or tasks are tracked under docs/specs. The documentation guide requires those three records for a feature and distinguishes them from a usage guide. Add the feature records and link this guide to them so the intended behavior and acceptance checks have a clear home. This repository requirement must be satisfied before merging.
Context Used: Documentation (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: docs/ines-containers.md
Line: 27-36
Comment:
**Required feature records are missing**
NES 2.0 support adds new header fields, size rules and region behavior, but no matching feature specification, plan or tasks are tracked under `docs/specs`. The documentation guide requires those three records for a feature and distinguishes them from a usage guide. Add the feature records and link this guide to them so the intended behavior and acceptance checks have a clear home. This repository requirement must be satisfied before merging.
**Context Used:** Documentation ([source](https://github.com/morluto/rea/blob/main/docs))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Refs #2072.
The iNES reader added in #2816 refused NES 2.0 headers. This change parses the NES 2.0 variant and inventories the declared trainer, PRG-ROM, CHR-ROM, and remaining regions. The region scan and reconstruction keep original bytes and source offsets.
Validation
0x40expansion-device case and raw nametable flag assertions failed on the original contributor head and passed after the repair.Author readiness
Human owner: @Davmunrey
Before merge
type(scope): outcome.Maintainer update
Refreshed against main and resolved the raw-read baseline conflict. The feature source and tests retain the contributor revision. The focused parser, artifact recognition, filesystem, and cancellation suites passed all 131 cases on the refreshed head. The architecture guard passed. The previous contributor head passed hosted CI. Fresh hosted checks are pending.