fix: preserve imported operands and supported arities - #50
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
🟢 Approval recommended
Changes are consistent across the operator table, validator, UI operand handling, and are backed by targeted regression tests and demo examples.
Pull request overview
Fixes a builder/validator mismatch where imported shorthand operands (scalar, null, and nested operator objects) could be hidden and lost during edits, and updates arity validation to accept evaluator-supported forms (</<= with 3 operands; if without an else).
Changes:
- Preserve non-array operand shorthands by normalizing operand access/update paths in the recursive
Anyrenderer. - Expand operator arity contracts for
if,<, and<=, and align validator expectations with evaluator behavior. - Add regression tests for shorthand operand preservation and supported arities; add demo samples covering the imported shapes.
File summaries
| File | Description |
|---|---|
| packages/react-json-logic/src/components/any.tsx | Normalizes operand handling so scalar/nested shorthands render and survive add/remove/edit flows. |
| packages/react-json-logic/src/operators.ts | Updates fieldCount to allow if (min 2) and </<= (max 3). |
| packages/react-json-logic/tests/validator.test.ts | Adds regression cases ensuring validator accepts evaluator-supported arities and updates max-arity failure expectation. |
| packages/react-json-logic/tests/json-logic-builder.test.tsx | Adds regression coverage for preserving imported shorthand operands (including explicit null) and editing 3-operand ranges / if without else. |
| packages/react-json-logic/tests/edge-cases.test.tsx | Updates a nested-arity failure case to reflect the new < max arity. |
| apps/example/src/app.tsx | Adds sample rules demonstrating imported shorthand/nested operands, 3-operand ranges, and if without else. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
⚡ SLOPS ZAPPED: 1
Verdict: Non-blocking slop
Imported non-array operands and between-style < / <= arities match the evaluator. The if minimum is now 2 but the operator still seeds three slots, so Remove can drop below that minimum.
Findings
- 🧹 SMOLSLOP · P2 — if keeps a 3-slot template after min 2 — Remove's floor is bogus (
packages/react-json-logic/src/operators.ts:85)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 840aedbcb9
ℹ️ 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".
|
🎉 This PR is included in version 3.1.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Problem
Imported scalar and nested operands were hidden and could be discarded during editing. Validation rejected supported three-argument ranges and conditionals without an else.
The workflow used third-party runners in a public repository, including a release runner unsupported by npm trusted publishing.
Solution
Preserve defined shorthand operands through rendering and controlled updates, including explicit null. Allow three arguments for
</<=and two forif, retaining the existing UI defaults. Removal uses the actual operand count so a two-argument conditional cannot lose a required operand. Add regression coverage and import examples in the demo.Run verification and publication on GitHub-hosted
ubuntu-latestrunners under the public-repository policy. This also meets the npm trusted publishing runner requirement.Proof
The new regression suite failed 16 cases against the original source. Final
pnpm verifypasses 111 tests, coverage thresholds, library packaging and demo build. React Doctor reports no introduced issues againstorigin/main.Browser edits preserved these shapes:
{"-": [6]} {"!": [{"===": [1, 1]}]} {"<=": [18, {"var": "user.age"}, 20]} {"if": [true, "ok"]}Evaluation returned
-6,false,false, and"ok". The conditional has no Remove controls at two operands; adding a third and removing it by keyboard returns to two without allowing further removal.actionlintand offlinezizmorpassed for the workflow.Keyboard removal retained the first two range operands; the 375×812 view had no document overflow.