Skip to content

refactor(artifacts): break the artifacts-firmware and artifacts-gpu import cycles - #11331

Merged
morluto merged 6 commits into
mainfrom
refactor/domain-binary-container
Nov 15, 2026
Merged

morluto merged 6 commits into
mainfrom
refactor/domain-binary-container

Conversation

@morluto

@morluto morluto commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Breaks the artifacts <-> firmware and artifacts <-> gpu mutual imports. BinaryContainer (failure types, BinaryReader, file-mapping helpers) moves from src/native/metadata/ to src/domain/binaryContainer.ts; the devicetree parser and its fixture move from src/firmware/devicetree/ to src/domain/firmware/; the raw LZ4 block decoder moves from src/gpu/ to src/artifacts/ and takes its output budget from the caller. Part of plan W9 (layer enforcement). Carries collapsed #11335.

Problem and expected behavior

Firmware and GPU providers read targets through src/artifacts/, but artifacts imported back:

  • The FIT reader (src/artifacts/fit/FitStructure.ts) parsed embedded devicetree blobs with src/firmware/devicetree/DevicetreeParser.ts. The parser imports only domain modules plus BinaryFormatFailure from src/native/metadata/BinaryContainer.ts, which itself imports only domain modules but sat under src/native/, making artifacts and firmware import native for a failure type and BinaryReader.
  • UnityFS decoding (src/artifacts/UnityFsStructures.ts) imported decodeLz4Block from src/gpu/. The decoder bounded every decode by GPU_OBJECT_BYTES (128 MiB) and threw through rejectGpu, so UnityFS inherited a GPU budget it never meant to use (its own checks cap blocks at 64 MiB before decoding).

Expected: the pure modules live in the domain layer beside the format declarations they implement (domain/firmware/devicetree.ts, domain/virtualFileMapping.ts); the shared LZ4 decoder lives in the shared reader unit and each caller states its budget; artifacts imports neither firmware nor gpu. Behaviour is unchanged.

Change and scope

  • Commit 1 (pure move): src/native/metadata/BinaryContainer.ts to src/domain/binaryContainer.ts with git mv, specifier rewrites in its importers, and the path in the raw-buffer-read architecture guard and docs/development/tool-design.md. BinaryContainer.test.ts stays in src/native/metadata/ because it also exercises readBinaryContainer.

  • Commit 2 (pure move): DevicetreeParser.ts, DevicetreeParser.test.ts and Devicetree.fixture.ts to src/domain/firmware/devicetreeParser.ts, devicetreeParser.test.ts and devicetree.fixture.ts, specifier rewrites, and the two per-guard baseline keys renamed (counts unchanged).

  • Collapsed refactor(artifacts): break the artifacts-gpu import cycle #11335, commit 1 (pure move): src/gpu/Lz4Block.ts and its test to src/artifacts/.

  • Collapsed refactor(artifacts): break the artifacts-gpu import cycle #11335, commit 2: decodeLz4Block(input, expected, maximumBytes, signal?). Malformed blocks throw BinaryFormatFailure("malformed", …) with unchanged messages (exactly what rejectGpu threw); an over-budget declaration throws BinaryResourceFailure naming the caller's budget. GPU payloads pass GPU_OBJECT_BYTES (unchanged); UnityFS passes its 64 MiB MAX_BLOCK_UNCOMPRESSED_BYTES, which its table and block checks already enforce.

  • Last commit: scripts/lib/module-layers.baseline.json drops artifacts <-> firmware and artifacts <-> gpu.

  • Collapsed refactor(artifacts): move the PE resource reader into src/artifacts/pe #11347 (pure move): the PE resource layout, parser and tree facts (with test and fixture) to src/artifacts/pe/, specifier rewrites, three raw-buffer-read baseline keys renamed and the path in docs/specs/artifacts/deno-standalone/plan.md. artifacts -> native is down to the two lipo imports of MachOSliceArtifactReader.

The pure-move commits will be listed in .git-blame-ignore-revs after merge. docs/verification/gpu-code-objects-2026-10-21.json keeps the old test path because it records a past run.

Not included: artifacts <-> javascript and the remaining artifacts <-> native imports (follow-ups; both need an injected port rather than a move) and catalogIdentity.ts <-> recordedCatalogDigests.ts (#11339).

Contribution scope: maintainer-approved W9 approach; no new capability.

Contract and boundary impact

  • Semantic owner and earliest changed stage: unchanged owners and APIs except decodeLz4Block, whose callers now own their budget. src/domain/ purity holds (the moved modules import only domain).
  • Contribution scope fit and linked maintainer decision: W9 layer enforcement.
  • CLI and MCP/tool-catalog contract: none.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none; failure classes and messages are unchanged.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): none.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

No target interaction changes.

Evidence and regression coverage

  • Tests added or updated: import paths; src/artifacts/Lz4Block.test.ts passes the budget explicitly and adds a refusal case (a declared length above the caller's budget reports BinaryResourceFailure with maximum_bytes equal to that budget). verify:module-boundaries (pure-layer rule) rejected moving BinaryContainer.test.ts because the test imports readBinaryContainer, so that test stays.
  • Base reproduction or other evidence: the production import graph (resolveModuleImports) has no artifacts -> firmware or artifacts -> gpu edge after the change (before: FitStructure.ts -> firmware/devicetree/DevicetreeParser.ts, UnityFsStructures.ts -> gpu/Lz4Block.ts); verify:module-boundaries reported both recorded cycles as gone.
  • User-visible CLI/MCP output (if applicable): none.
  • Remaining proof gaps: GPU, UnityFS and firmware boundary/acceptance suites were not run locally; only the focused tests below.

Validation performed

  • npm run check:fast (typecheck, lint, module boundaries, architecture guards) — passed after each commit.
  • npm run test:local -- src/native/metadata/BinaryContainer.test.ts src/artifacts/fit/FitStructure.test.ts src/gpu/Lz4Block.test.ts — 65 passed.
  • npm run test:local -- src/domain/firmware/devicetreeParser.test.ts src/artifacts/fit/FitStructure.test.ts src/artifacts/FitArtifactReader.test.ts — 97 passed.
  • npm run test:local -- src/artifacts/Lz4Block.test.ts src/gpu/GpuPayloadCodec.test.ts src/artifacts/UnityFsArtifactReader.test.ts — 36 passed.
  • npm run verify:module-boundaries — passed after the baseline edit.
  • npm run test:local -- src/artifacts/pe/PeResourceParser.test.ts src/artifacts/NodeSeaArtifactReader.test.ts src/artifacts/deno/DenoStandaloneArtifactReader.test.ts src/native/pe/PeResourcesProvider.test.ts (collapsed refactor(artifacts): move the PE resource reader into src/artifacts/pe #11347) — 203 passed.
  • Pre-push hook — passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none (internal module paths).
  • Real Hopper/Ghidra, browser, or OS coverage: none needed.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none; no behaviour change.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

BinaryContainer imports only domain modules and is shared by artifacts, firmware, gpu, go, il2cpp, python, rust and native. Living under src/native made artifacts and firmware import native for its failure types and BinaryReader. Pure move: git mv plus import specifier updates.
The FIT artifact reader in src/artifacts parses embedded devicetree blobs with the parser that lived under src/firmware, while firmware's providers import src/artifacts: the two units imported each other. The parser and its fixture are pure and now sit beside domain/firmware/devicetree.ts. Pure move: git mv plus import specifier and baseline key updates.
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-15T16:28:17.949431Z
We couldn’t complete this review. Comment @codex review to try again.
d07065c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@greptile-apps

greptile-apps Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Moves shared binary and device-tree code into the domain layer, and moves PE resource readers and LZ4 decoding into artifacts.

  • Binary readers and their shared failure types now live in the domain layer.
  • FIT readers and firmware providers now use the domain devicetree parser.
  • LZ4 callers now choose their own decoded-size limit.
  • PE resource parsing now lives with artifact readers.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  FIT["Artifacts: FIT reader"] --> DT["Domain: device-tree parser"]
  FW["Firmware provider"] --> DT
  DT --> BC["Domain: binary readers and failures"]
  PE["Artifacts: PE resource readers"] --> BC
  NP["Native PE providers"] --> PE
  U["UnityFS: 64 MiB budget"] --> LZ["Artifacts: shared LZ4 decoder"]
  G["GPU: 128 MiB budget"] --> LZ
  LZ --> BC
Loading

Reviews (4) · Last reviewed commit: "Merge branch 'main' into refactor/domain..." · Reviewed by Greptile

* refactor(artifacts): move the LZ4 block decoder into src/artifacts

Pure move: git mv plus import specifier updates. The next commit removes its GPU-specific budget.

* refactor(artifacts): take the LZ4 output budget from the caller

decodeLz4Block bounded every decode by the GPU object budget and threw through rejectGpu, so UnityFS decoding in src/artifacts imported src/gpu while gpu imports artifacts. Callers now pass their budget: GPU payloads keep GPU_OBJECT_BYTES; UnityFS passes its 64 MiB block bound, which its size checks already enforce before decoding. Malformed blocks still throw BinaryFormatFailure with the same messages.
@morluto morluto changed the title refactor(firmware): break the artifacts-firmware import cycle refactor(artifacts): break the artifacts-firmware and artifacts-gpu import cycles Nov 15, 2026
#11347)

refactor(artifacts): move the PE resource layout and parser into src/artifacts/pe

The Node SEA and Deno standalone readers in src/artifacts locate PE resources with the layout and parser that lived under src/native/pe, while those modules already read through src/artifacts (ArtifactReaderFailure, assertArtifactReadActive). Pure move: git mv plus import specifier, baseline key and spec path updates.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: evidence Evidence, artifacts, and reconstruction provider: gpu Analysis provider / engine: gpu

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant