Skip to content

fix(jq): handle serde_json arbitrary_precision numbers - #2965

Merged
chaliy merged 4 commits into
mainfrom
ordinary-newt
Nov 22, 2026
Merged

chaliy merged 4 commits into
mainfrom
ordinary-newt

Conversation

@chaliy

@chaliy chaliy commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Fixes jq misreading every non-integer number when any crate in the build enables serde_json/arbitrary_precision via feature unification. JqSeed::visit_map now detects the single-entry private-token map shape and returns JqJson::Number with the exact text.

Why

Closes #2964. Without this, decimals become one-key objects, breaking arithmetic (exit 5) and silently wrong comparisons (exit 0).

Before / After

With serde_json/arbitrary_precision on, before fix: round_trip_preserves_float_zero_decimal fails; echo '{"a": 1.5}' | jq '.a + 1' errors; map(select(. > 1)) returns objects. After fix: '{"a":1.5,"b":2}', '2.5', '[2.5,10]' as expected. Full lib suite passes in both builds (3507 tests with arbitrary_precision).

Risk

  • Low. Only adds a first-key check in jq visit_map; normal objects unchanged. One pre-existing test input adjusted from 2.50 to 2.5 to stay green in both builds (2.50 is preserved with the feature, normalized without).

Checklist

  • Tests added or updated
  • Backward compatibility considered

Show it working
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

With serde_json/arbitrary_precision enabled via feature unification,
non-integer numbers arrive as a single-entry map with the private key
$serde_json::private::Number instead of visit_f64. JqSeed::visit_map
now detects that shape and returns JqJson::Number with the exact text,
so jq input, --argjson, and streams keep working in either build.

Closes #2964
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit fac4a60 Commit Preview URL

Branch Preview URL
Nov 22 2026, 03:01 AM

@bashkit-pr-reviewer bashkit-pr-reviewer 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.

Correct, well-scoped fix for the feature-unification hazard in #2964. JqSeed is the only custom deserialize_any visitor in the jq path and all three entry points (parse_json_value, parse_json_stream, parse_json_stream_partial) go through it, so the single visit_map shape check covers main input, --argjson/--jsonargs, --slurpfile, and streams. The single-entry check with the multi-entry fall-through mirrors serde_json::Value's own AP behavior, and the feature-independent unit test plus the knowledge update match the repo's contribution rules. Two worth-considering items below, no blockers.

@bashkit-pr-reviewer

bashkit-pr-reviewer Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Review verdict (push fac4a60)

All findings resolved — no open items, no new review submitted. This push addresses the two remaining items exactly as suggested, and I verified each in the refreshed checkout.

What changed since the last review (c823ac8 → fac4a60)

  • CI coverage (resolves P1 jq-ap-build-ci-coverage): .github/workflows/ci.yml:429-433 adds a "Run jq tests with arbitrary_precision unified on" step — cargo test -p bashkit --lib --features jq,serde_json/arbitrary_precision -- builtins::jq:: — with a comment tying it to jq: decimal numbers are misread when serde_json's arbitrary_precision feature is on in the build #2964. The dep/feat syntax and jq feature name match existing steps in the same job (e.g. line 381), and the filter covers the whole jq unit-test subtree, so the pre-existing round_trip_preserves_float_zero_decimal now guards the probe on every run, not just manual ones.
  • Duplicate-collapse test (resolves P2 jq-token-duplicate-test-gap): token_led_object_with_second_key_stays_object gains a second half (now convert.rs:588-603) parsing a real {\"$tok\":\"1\",\"$tok\":\"2\"} literal and asserting a single entry with last-wins (String(\"2\")). Deterministic in both builds (quoted payloads stay String either way), and the doc comment's "(including duplicate-key collapse)" claim is now accurate. This directly pins the second-position dedupe fix.
  • tests.rs and knowledge/foundations/jq.md: unchanged; knowledge Verification section already describes all three tests accurately.

Findings status

  • ✅ Resolved: jq-token-object-duplicate-key, jq-token-object-fallthrough-test, jq-token-duplicate-test-gap, jq-ap-build-ci-coverage. Zero open findings.

Not reviewed / limits

  • Did not build or run tests (no cargo/network here); the new CI step's command was checked syntactically against neighboring steps, not executed. Full diff visible (truncated: false).

Address PR review: feed the second entry through the same last-wins
dedupe as the normal path and pin the two-entry fall-through with a
companion test.

@bashkit-pr-reviewer bashkit-pr-reviewer 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.

Re-reviewed the new push (92a5816). Both P2s from the prior review are addressed: the second entry in the token-led fall-through now goes through the same last-wins/first-position dedupe, and token_led_object_with_second_key_stays_object pins the must-stay-an-object branch. One minor follow-up below, no blockers.

Only interpret single-entry $serde_json::private::Number map as Number
when the build actually enabled arbitrary_precision (runtime OnceLock
via 2.50 round-trip). Real objects with that key stay Objects without
the feature; with it they match serde_json::Value parity.

Add single_entry_token_object_matches_build_mode to pin both modes.

@bashkit-pr-reviewer bashkit-pr-reviewer 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.

Re-reviewed push c823ac8. The runtime probe design is sound (it exercises the same deserialize_any path the fix relies on, so probe and parser cannot disagree by construction), all three entry points set handle_token, child() propagates it, and the knowledge doc matches the code. But this push makes automated dual-build coverage load-bearing, and it does not exist — one new finding below.

Comment thread knowledge/foundations/jq.md Resolved
Gate private-token number handling on runtime arbitrary_precision
detection so real single-entry objects stay Objects without the
feature. Extend fall-through test with duplicate-key collapse and add
CI leg running jq tests with serde_json/arbitrary_precision unified on.
@chaliy

chaliy commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Review follow-ups addressed in fac4a60: (1) fall-through test now includes a duplicate private-token case asserting last-wins collapse to a single entry; (2) CI leg added running jq tests with serde_json/arbitrary_precision unified on. Also gated token handling on runtime feature detection so real single-entry objects stay Objects without the feature.

@chaliy
chaliy merged commit d47e065 into main Nov 22, 2026
68 checks passed
@chaliy
chaliy deleted the ordinary-newt branch November 22, 2026 09:20
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.

jq: decimal numbers are misread when serde_json's arbitrary_precision feature is on in the build

1 participant