Skip to content

feat: validate num_modules/byte_count for esm-chunked candidates - #343

Merged
bash0816 merged 11 commits into
mainfrom
automation/claude-code-2.1.248-offset-validation
Aug 30, 2026
Merged

feat: validate num_modules/byte_count for esm-chunked candidates#343
bash0816 merged 11 commits into
mainfrom
automation/claude-code-2.1.248-offset-validation

Conversation

@bash0816

Copy link
Copy Markdown
Owner

Summary

Add runtime validation of num_modules and byte_count from the discoverModuleGraph result against audited values in validateEsmChunkedOffsets(). This detects potential binary corruption or version mismatches early in the native package validation flow.

The new checks:

  • Verify audited.num_modules matches graph.numModules if defined
  • Verify audited.byte_count matches graph.byteCount if defined

Both checks throw descriptive errors with expected vs. actual values on mismatch.

Test plan

  • Syntax check: node --check prepare-native.js passes
  • Implementation follows G2 design review guidance exactly
  • Property names verified against bunfs-extract.js source

bash0816 and others added 11 commits August 29, 2026 07:15
Add runtime validation of num_modules and byte_count from the
discoverModuleGraph result against audited values to detect potential
binary corruption or version mismatches early in the native package
validation flow.

Co-Authored-By: Claude Haiku 4.5 <[email protected]>
- Extract validateEsmChunkedOffsets, validateLegacyCjsOffsets, validateOffsets, and verifyTarball to native-validators.js
- Parameterize version argument to enable testability
- Add native-validators.test.js with 3 test cases covering normal and error cases
- All existing tests (bunfs-extract.test.js: 11 tests) continue to pass

Co-Authored-By: Claude Sonnet 5 <[email protected]>
- Consolidate 3 separate integration tests into 1 unified test to avoid
  register() hook accumulation issues
- Test validates: normal /$bunfs/root/ resolution, path traversal rejection,
  and missing module errors
- Add bunfs-esm-loader.test.js and native-validators.test.js to CI

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…sign

- Add analyzeCycleHoists and discoverCycleHoists functions to audit cycle-breaking patterns
- Modify discoverOffsets to load cycle_hoists data from binary analysis
- Implement data-driven hoisting in bunfs-esm-loader.mjs to support multiple cycles
- Add __bunfsAssertHoistedProps helper to detect evaluation-order regressions
- Update cycle_hoists field in both config JSON files for versions 2.1.245 and 2.1.248
- Add comprehensive test coverage for cycle hoisting logic
- Integrate cycle_hoists into termux-run-claude-native.sh register() calls

This change moves from a hardcoded single-cycle fix (O9/chunk-y0jj307t.js) to a generic,
data-driven design that can handle arbitrary module graph cycles, improving maintainability
and reducing brittleness for future versions.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ks() to fix hang on cycle_hoists

Changes:
- Convert resolve() and load() functions from async to sync
- Add caller origin gate (fromChunk) to restrict child_process/vm/ws redirects
- Replace module.register() with module.registerHooks() for synchronous in-process hooks
- Update Node.js version requirement to >=22.15.0 <23.0.0 || >=23.5.0
- Add Node.js version check in bin/claude
- Improve load() format detection (ESM vs CommonJS)

Co-Authored-By: Claude Sonnet 5 <[email protected]>
The prior commit (66f26b6) added a regex-based commonjs/module format
detector to load() to work around a failing integration test. Verified
against a real 2.1.248 extraction (1768 chunk files) that PROCESS_OWNED_DIR
never contains genuine CommonJS files (0 use module.exports without
import/export syntax) - the failure was caused by the test's synthetic
foo.js fixture using module.exports, not a real production case. Reverted
load() to always return format: 'module' and fixed the fixture to use ESM
syntax instead.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…locker)

The second esmChunkedMain() bootstrap path (used when CLAUDE_TERMUX_STDIN=inherit,
i.e. TUI/interactive sessions) still destructured `register` from node:module while
calling the undefined `registerHooks(...)`, causing a ReferenceError not reachable
via the default -p smoke test path. Found by G3 review (terra). Fixed the
destructure to match the first path and verified both paths (-p default and
CLAUDE_TERMUX_STDIN=inherit) succeed on 2.1.248 and 2.1.245.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@bash0816
bash0816 merged commit ed4be9f into main Aug 30, 2026
3 checks passed
@bash0816
bash0816 deleted the automation/claude-code-2.1.248-offset-validation branch August 30, 2026 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant