Skip to content

Replace indent-fragile marketplace version regex with real JSON parser - #157

Merged
danielraffel merged 1 commit into
mainfrom
fix/marketplace-regex-indent
Apr 14, 2026
Merged

Replace indent-fragile marketplace version regex with real JSON parser#157
danielraffel merged 1 commit into
mainfrom
fix/marketplace-regex-indent

Conversation

@danielraffel

Copy link
Copy Markdown
Collaborator

Why

Codex P2 on #152 flagged that `read_marketplace_plugin_entry_version` anchored on exactly `^ "version"` (six leading spaces). Any reformatting of `.claude-plugin/marketplace.json` — tab reformat, 2/4-space flip, minification — would silently skip the check and let drift back in.

What

Switched both `read_json_version_field()` and `read_marketplace_plugin_entry_version()` in `tools/cli/cmd_version.cpp` to use the in-repo `tools/cli/json_parser.hpp` (same parser the package subsystem uses). The check now walks the actual JSON object tree:

  • top-level `.version` for `plugin.json` and `marketplace.json`
  • `plugins[0].version` for the per-plugin entry inside marketplace's catalog

Indentation/formatting can't re-introduce drift.

Bonus: fresh drift found

While verifying locally, the new parser caught real drift already on main: `marketplace.json` `plugins[0].version` was at 0.4.0 while `plugin.json` is at 0.5.0. One of the intermediate PRs bumped `plugin.json` without updating the nested plugin entry — exactly the class of drift this PR hardens against. Bumped to 0.5.0 in the same commit since the check now (correctly) refuses to pass without it.

Test plan

  • Local build succeeds.
  • `pulp version check` reports both marketplace fields matching plugin.json.
  • CI: version-skill-check + build matrix.

Codex P2 on #152 flagged that my previous marketplace.json check
anchored on exactly '^      "version"' (six spaces), which would
silently stop working if the file's indentation ever changed (tab
reformat, 2/4-space flip, minification, etc.).

Switched both read_json_version_field() and
read_marketplace_plugin_entry_version() to use the in-repo
tools/cli/json_parser.hpp that the package subsystem already ships.
Now the check walks the actual JSON object tree:
  - top-level .version         for plugin.json and marketplace.json
  - plugins[0].version         for marketplace.json per-plugin entry

Indentation/formatting can't re-introduce drift.

While verifying locally, the new parser caught real drift already on
main: marketplace.json plugins[0].version was at 0.4.0 while
plugin.json is at 0.5.0. Bumped plugins[0].version to 0.5.0 in the
same commit since the check now (correctly) refuses to pass without
it. That's a fresh drift introduced by one of the intermediate PRs
that bumped plugin.json without updating the nested plugin entry —
exactly the class of drift this PR is hardening against.

Skill-Update: skip skill=cli-maintenance reason="Internal swap from regex to JSON parser; the cli-maintenance SKILL.md's 'pulp version check' section already documents the multi-version-field gotcha at the policy level — what check lives there. Implementation detail update only."

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c57e7f572b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/cli/cmd_version.cpp
Comment on lines +178 to +180
pulp::cli::pkg::JsonParser parser{content};
parser.skip_ws();
auto root = parser.parse_value();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Guard JSON parse to avoid hanging on malformed manifests

Switching to JsonParser here introduces a hang path that the old regex did not have: if plugin.json or marketplace.json is temporarily malformed (for example, a trailing comma while editing), parse_value() can enter a non-advancing loop in parse_object/parse_array and never return, so pulp version check stalls instead of reporting a clear error. Because this check runs in version-gate workflows, a simple syntax mistake can block CI/hooks rather than failing fast; wrap parsing with an error/timeout-safe path (or fall back to a non-blocking parse failure).

Useful? React with 👍 / 👎.

@danielraffel
danielraffel merged commit 1e39aef into main Apr 14, 2026
6 checks passed
@danielraffel
danielraffel deleted the fix/marketplace-regex-indent branch April 14, 2026 09:25
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