Skip to content

[Backport 8.x] Port Puppet::Util::Json to the json 3 API - #721

Merged
Sharpie merged 1 commit into
OpenVoxProject:8.xfrom
miharp:backport-706-8x
Oct 12, 2026
Merged

Sharpie merged 1 commit into
OpenVoxProject:8.xfrom
miharp:backport-706-8x

Conversation

@miharp

@miharp miharp commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Description

Backport of #655's follow-up #706 to 8.x. Fixes #720.

json 3 reached the FreeBSD ports tree on 2026-09-29 (devel/rubygem-json 3.0.2). The openvox-server8 port puts the system gem directory on JRuby's gem-path, so a routine pkg upgrade made the server load json 3.0.2 and every request with a JSON body failed with Could not intern from json: wrong number of arguments (given 2, expected 1) (#720). An agent running the 8.x gem on a system Ruby next to json 3 fails the same way (#654).

This cherry-picks the library commit from #706 (8530418) unchanged. It applies cleanly to 8.x. The second commit in #706, the gem-install smoke test job, is not carried: 8.x does not have the test_gem_build and test_install workflow jobs it extends, so it conflicts in tests.yaml and there is nothing for it to plug into. That is also why the backport bot could not do this one.

The backport bot label would have hit the same conflict, hence the manual PR.

Verification on 8.x under json 3.0.2

8.x CI will not exercise json 3 even with the Gemfile pin lifted to < 4, because rubocop ~> 1.86.1 depends on json ~> 2.3 (rubocop relaxed that to >= 2.3 in 1.90, which is what main is on). So I verified locally on this branch with a rubocop-free bundle so bundler resolved json 3.0.2:

  • Ruby 3.4.8, json 3.0.2, openvox 8.30.0 + this commit
  • Full unit suite (rake parallel:spec[8]): 25297 examples, 19 failures. The 19 are the same user, service and package provider specs that fail on stock 8.x (0d59f50) with json 2.21.2 on this macOS host, so none are from this change.
  • Smoke test of the paths [Bug]: Backport json 3 compatibility fix (8530418b) to 8.x #720 reports broken: puppet facts show, puppet parser dump --format json --pretty, puppet catalog compile --render-as json and puppet apply --catalog of that output all succeed.

With the stock 8.x bundle (json 2.21.2) the same suite is what CI runs here.

Assisted by Claude.

json 3.0.0 makes every option a keyword argument, raises on unknown
options, and removes several deprecated APIs. Puppet::Util::Json relied
on all three, so every agent run on a Ruby with json 3 installed failed
with "wrong number of arguments (given 2, expected 1)" as soon as it
deserialized anything (file metadata, catalogs, facts, module metadata).

Changes to lib:

* Util::Json.load passes parser options to JSON.parse as keywords.
* Util::Json.dump replaces the removed JSON::PRETTY_STATE_PROTOTYPE with
  the equivalent generator options and drops the obsolete :quirks_mode
  option that the network formats still pass. Both methods now dup the
  options hash instead of mutating the caller's.
* The epp and parser faces use JSON.pretty_generate instead of the
  removed JSON.pretty_unparse.
* Pal's JsonCatalogEncoder#encode_resource goes through Util::Json.dump.
  It passed :pretty straight to Hash#to_json, which json 2 silently
  ignored and json 3 rejects. As a side effect it now honours the pretty
  option like #encode already did.

Changes to spec, so the suite also passes with json 3:

* Specs for load options and dump behaviour.
* The schema matcher parses the JSON before handing it to json-schema,
  which as of 6.2.1 still calls JSON.parse with a positional hash.
* The loaders spec fixture produced metadata.json with a duplicate
  "dependencies" key, which json 3 rejects by default.
* Drop :create_additions from JSON.parse calls in the catalog spec; it
  was already the default and the option no longer exists.

The Gemfile pin added in OpenVoxProject#655 is lifted to json < 4 so CI resolves json 3
and exercises this port. Everything still works with the json 2.x that
ships with Ruby 3.2 through 4.0.

Fixes OpenVoxProject#654
Closes OpenVoxProject#664

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Michael Harp <mike@mikeharp.com>
(cherry picked from commit 8530418)
@miharp
miharp marked this pull request as ready for review October 11, 2026 11:08

@Sharpie Sharpie 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.

Looks good to me. Replaces long, long deprecated methods like pretty_unparse and pushes option handling into the existing Puppet::Util::Json module.

@Sharpie
Sharpie merged commit af67c41 into OpenVoxProject:8.x Oct 12, 2026
17 checks passed
@bastelfreak bastelfreak added the enhancement New feature or request label Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants