Skip to content

test: property-based fuzz testing for js->zig->js roundtrip - #41

Open
nazarhussain wants to merge 17 commits into
nh/bigint-exact-conversionsfrom
nh/fuzz-testing
Open

nazarhussain wants to merge 17 commits into
nh/bigint-exact-conversionsfrom
nh/fuzz-testing

Conversation

@nazarhussain

@nazarhussain nazarhussain commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

Adds a property-based fuzz harness for zapi Number, BigInt and Uint8Array converters (vitest + fast-check, driven through a dedicated test_fuzz_numeric.node addon). The harness surfaced several latent bugs and an API sharp edge.

Stacked on #83. The library fixes and API changes the harness found (exact-by-default toI64/toU64/toI128, the *LowBits variants, BigInt.fromWords, the getValueBigintWords sign fix and the Number doc comments) now live in #83. This PR contains only the fuzz tests, the build wiring and CI. Merge #83 first.

Changes

  • tests/fuzz/: round-trip fuzz targets and fast-check properties for Number, BigInt and Uint8Array, with oracle tests and a seeds workflow (see tests/fuzz/README.md).
  • tests/build.zig.zon / tests/build.zig: a separate Zig package for the fuzz addon, mirroring examples/ and consuming zapi via --fork=... It installs to the root zig-out/.
  • package.json: build:zig now runs build:zig:examples and build:zig:tests; adds test:fuzz:round_trip and the fast-check dev dependency.
  • CI: a test-fuzz job.

🤖 Generated with Claude Code

Comment thread .github/workflows/ci.yml
- name: Test
run: pnpm test:js

test-fuzz:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems a little strange to fuzz in CI

@wemeetagain wemeetagain left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the API changes and additional comments are good

@matthewkeil matthewkeil moved this from Awaiting Author to Review Requested in Lodestar Team Coordination Sep 10, 2026
@nazarhussain
nazarhussain force-pushed the nh/fuzz-testing branch 2 times, most recently from 4b09223 to e3384ed Compare October 19, 2026 10:11
@nazarhussain
nazarhussain changed the base branch from main to nh/bigint-exact-conversions October 19, 2026 10:11
nazarhussain and others added 16 commits October 19, 2026 12:31
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Round-trips JS BigInt → i128 → JS BigInt via toI128 and fromWords.
Property test covers the i128 boundary plus out-of-range truncation via
BigInt.asIntN(128, ·). Oracle test adds deterministic boundary cases for
zero, I128_MIN/MAX (exact), just-out-of-range ±1, and oversized values
whose low 128 bits are all zero (expected result: 0n).
The seeds-workflow doc claimed NaN/Infinity could be persisted via a
{"__special": ...} encoding, but no corresponding reviver exists in
fuzz.test.ts — following the README literally would silently corrupt
test input. NaN/Infinity are already in edgeNumbers and exercised every
run, so persisting them adds nothing. Trim the README to match reality.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Review Requested

Development

Successfully merging this pull request may close these issues.

3 participants