Skip to content

Report the real package version in the user agent (hscn/<version>) and release 1.5.1 - #65

Merged
JonoPrest merged 3 commits into
mainfrom
set-user-agent
Oct 30, 2026
Merged

JonoPrest merged 3 commits into
mainfrom
set-user-agent

Conversation

@JonoPrest

@JonoPrest JonoPrest commented Jun 8, 2026 •

Copy link
Copy Markdown
Collaborator

The client already tags requests with hscn/<version>, but the version came from CARGO_PKG_VERSION — and napi keeps the Cargo package version pinned at 0.0.0, so every request actually went out as hscn/0.0.0.

This makes build.rs read the version from package.json and inject it as NPM_PKG_VERSION, which the client now uses → hscn/<package-version> (e.g. hscn/1.5.1).

Release

Bumps to 1.5.1 (package.json, npm/* platform packages, and the version embedded in index.js), mirroring the 1.5.0 release in #67.

Why the release gets the right version

build.rs reads package.json directly, not via any build-time env var the pipeline may or may not set. The publish workflow (publish_to_npm.yaml) builds each platform with checkout → yarn install → yarn build, so the artifact is compiled from a checkout whose package.json holds the release version (kept in sync by napi version). package.json is parsed with serde_json (resolved via CARGO_MANIFEST_DIR), and there is deliberately no fallback: a missing or malformed version fails the build rather than silently shipping hscn/0.0.0.

Matches the Rust (hscr/) and Python (hscp/, separate PR) clients. Verified with cargo check (the env!("NPM_PKG_VERSION") would fail to compile if build.rs didn't set it; the version parses to 1.5.1; removing the field fails the build with a clear error).

Summary by CodeRabbit

  • Chores
    • Improved version consistency between the npm package and the Rust client.
    • The client’s default user-agent now reflects the npm package version.
    • Builds now validate the package version metadata and rerun when it changes.

@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: e0bb9576-be48-414f-a590-1d1e7172cd86
Commits

Reviewing files that changed from the base of the PR and between 2b490c5 and a097585.

Files selected for processing: 2
  • Cargo.toml
  • build.rs

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 4 reviews per hour.

Walkthrough

The build script reads the version from package.json and makes it available to Rust as NPM_PKG_VERSION. HypersyncClient::new uses that value in its default user-agent instead of the Cargo package version.

Changes: NPM Version Build Injection

Layer / File(s) Summary
Build-time npm version injection and client integration
Cargo.toml, build.rs, src/lib.rs
The build dependencies include serde_json. The build script reads and validates the package.json version, registers the file for rebuilds, and sets NPM_PKG_VERSION. The client constructor uses the injected version in its default user-agent.

Priority: Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: jasoons

Merge Risk: Minimal · up to a0975

No concrete merge-blocking risk is established; the version injection change is ready for normal checks.

Pre-merge checks: Passed 4
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly describes the main change: reporting the package version in the user agent. The release reference is also consistent with the stated objective.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Finishing Touches
📝 Generate docstrings
- [ ] Create stacked PR - [ ] Commit on current branch
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@build.rs`:
- Around line 12-25: The current manual line-based parsing in build.rs that
computes the local variable version is brittle; instead add serde_json = "1.0"
to [build-dependencies] in Cargo.toml and replace the manual
read/line/strip_prefix logic with a robust JSON parse using serde_json::from_str
to extract the "version" field (falling back to
env!("CARGO_PKG_VERSION").to_string() if parsing or key extraction fails).
Locate the code that defines version in build.rs (and the use of
env!("CARGO_PKG_VERSION")) and update it to read package.json, parse it with
serde_json::Value (or a small struct with a version field), and use that value
as the version.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1592ab44-7012-4a2c-8e38-443fa2e13429

📥 Commits

Reviewing files that changed from the base of the PR and between 8cf5b7d and 2b490c5.

📒 Files selected for processing (2)
  • build.rs
  • src/lib.rs

Comment thread build.rs Resolved
JonoPrest and others added 2 commits October 30, 2026 08:20
The user agent was hscn/{CARGO_PKG_VERSION}, but napi keeps the Cargo package
version at 0.0.0, so it always sent hscn/0.0.0. build.rs now reads the version
from package.json and injects it as NPM_PKG_VERSION, and the client uses that
(hscn/<package-version>).

build.rs reads package.json directly rather than relying on a build-env var, so
the published artifacts get the correct version: the publish workflow builds each
target with 'yarn build' from a checkout whose package.json holds the release
version. Falls back to CARGO_PKG_VERSION if package.json can't be read.
…is missing

Addresses review feedback: line-based parsing was brittle, and falling back to
CARGO_PKG_VERSION would silently reintroduce hscn/0.0.0. Resolve package.json via
CARGO_MANIFEST_DIR and emit rerun-if-changed before reading it (required because
napi_build's rerun-if-env-changed directives disable cargo's default rerun).
Bump package.json, the npm/* platform packages and the version embedded in
index.js, so the release reports hscn/1.5.1.
@JonoPrest JonoPrest changed the title Report the real package version in the user agent (hscn/<version>) Report the real package version in the user agent (hscn/<version>) and release 1.5.1 Oct 30, 2026
@JonoPrest
JonoPrest merged commit 122debd into main Oct 30, 2026
1 check passed
JonoPrest added a commit that referenced this pull request Oct 30, 2026
* Fix cargo fmt in src/lib.rs

* Add CI workflow for pull requests and main

Runs on every PR and push to main (there was no PR CI before; the only build
and tests ran inside the manual publish workflow):
- cargo fmt, clippy (-D warnings) and cargo test
- yarn build, then fail if the committed index.js / index.d.ts differ from
  what napi generates
- yarn test on node 20, 22 and 24
- a packaging smoke test that packs the main and platform packages as they
  are published, installs them into a fresh project and checks require,
  import and a TypeScript type-check against index.d.ts

* Add offline regression tests for past fixes

A loopback fake HyperSync server captures what the client sends, so query
conversion, headers and rate limiting can be tested without network access
or an API token. Covers:
- include/exclude selections not collapsing to empty filters (#52)
- transaction/trace 'type' field names (#22, #27, #43) and runtime enums (#30)
- authorization list filters (#37) and query validation errors
- hscn/<package version> user agent and bearer token (#44, #65)
- rate limit parsing and proactive sleep (#57)
- setLogLevel and RUST_LOG precedence (#62), in child processes
- index.js/index.d.ts export parity (#63) and version consistency (#47)
- decoder address independence (#10), checksumming (#18) and bad input
- preset queries
- Rust: response address checksumming (#18) and BigInt quantities (#20, #23)

* Type-check examples in CI and run them against HyperSync

scripts/check-examples.sh installs each example against the local build and
type-checks it. With --run it also runs each one with ENVIO_API_TOKEN: examples
that finish must exit 0 within RUN_SECONDS, streaming ones must still be
running cleanly at that point, and any ERROR logged by the client fails the
example (the client retries failed requests forever, so a bad token or broken
query would otherwise just look like a slow example).

The run job skips with a warning when the ENVIO_API_TOKEN secret isn't
available, e.g. on fork PRs.

* Widen rate limit window in proactive sleep test

Addresses review feedback: with a 1s reset window, a CI pause between the two
calls could let the window expire and fail the test spuriously.

* Run examples in parallel and stop streaming ones once data arrives

Streaming examples now pass as soon as they print their first real output
instead of running for a fixed 60s, every example runs concurrently, and
anything still running at RUN_TIMEOUT is reported as hung. Errors printed by
the examples themselves (e.g. height-stream catches its own) now also fail.

* Fix CallDecoder decoding and crashes on short input

Caught by the call_watch example once it ran in CI:
- hypersync_client::CallDecoder passes the calldata to abi_decode_input with
  its 4-byte selector still attached, so every argument came out shifted
  (addresses like 0x00000000c782..., huge amounts).
- It indexes data[0..4] without a length check, so a transaction with empty
  input (a plain ETH transfer) panicked; the binding's .unwrap() on the
  spawn_blocking JoinError then aborted the whole Node process.

The binding now keeps its own selector -> Function map and decodes with
alloy directly, stripping the selector. Input that isn't valid hex, is too
short, has an unknown selector or doesn't decode returns null, matching how
Decoder treats undecodable logs. The async variants reject instead of
aborting if the decode task ever panics. The existing checksum toggles are
now exported to JS, as they were meant to be.

* Address review findings on CI scripts

- check-examples: record each result in its own file instead of parsing the
  last log line (truncated output was glued onto the result, failing
  call_watch even though it passed); show the tail of the output, where
  failures are; run examples from scratch directories so parquet-out's data/
  isn't left in the checkout; keep ENVIO_API_TOKEN out of npm install / tsc;
  require call_watch to print a real decoded transfer.
- ci.yaml: only expose ENVIO_API_TOKEN to the step that runs the examples.
- smoke-test-package: the stray .node guard used '! ls', which set -e
  ignores, so it could never fail. Also add the optionalDependencies napi
  adds at publish time (using napi's own parseTriple) and install only the
  main package, so the platform binary has to resolve the way it does for
  users.
- package.test: each napi target has a matching npm/<platform> package.
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