feat: RFC 6902 diffJSONS for the two-document case (#565) - #1080
Open
ilayfalach wants to merge 1 commit into
Open
ilayfalach wants to merge 1 commit into
ilayfalach wants to merge 1 commit into
Conversation
Adds `hera.utils.diffJSONS(source, target)`, a thin wrapper over `jsonpatch.make_patch` returning the JSON Patch that turns source into target, per the standard @erasta proposed in the issue. Scope is the pairwise case only. `compareJSONS` compares N documents and returns a table; JSON Patch is defined between exactly two, so it is not a drop-in replacement for the N-document callers (`machineLearningDeepLearning/toolkit.py:85`, `hermesWorkflowToolkit.py:863`) and those are untouched. What replaces the table for three or more documents is still open. Both genuinely pairwise call sites are switched — `workflow_compare` and `workflow_sync_to_db` in hera/simulations/CLI.py, each comparing one DB workflow against one file on disk. They only ever used the result for "is there a difference" and to print it, so `res.empty` becomes `not res` and the patch prints through `pandas.DataFrame(res)`, which keeps the familiar tabular output with op/path/value columns. `jsonpatch` was already installed but only transitively (requirements.txt declared its dependency `jsonpointer`, not jsonpatch itself); now declared. On the UI question raised in the issue thread: changing the Python side does not break the UI. `ui/client/src/utils/compareJsons.ts` is an independent TypeScript implementation and nothing in ui/ calls `compareJSONS`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #565. Partial by design — see the last section.
The UI is not at risk
The thread assumed this change would break the UI. It will not.
ui/client/src/utils/compareJsons.tsis an independent 146-line TypeScript implementation, and nothing underui/calls the PythoncompareJSONS. The coordinated two-branch plan discussed in the issue is not needed.What changed
hera.utils.diffJSONS(source, target)wrapsjsonpatch.make_patchand returns the RFC 6902 patch that turns source into target — the standard @erasta proposed.Both genuinely pairwise call sites are switched:
workflow_compareToDiskandworkflow_sync_to_dbinhera/simulations/CLI.py, each comparing one DB workflow against one file on disk. They only used the result for "is there a difference" and to print it, sores.emptybecamenot resand the patch prints throughpandas.DataFrame(res)— same familiar table, now withop/path/valuecolumns.jsonpatchwas installed but only transitively (requirements.txt declared its dependencyjsonpointer, not jsonpatch itself); now declared.Test
hera/tests/unit/test_diffJSONS.py— 6 tests, including that applying the patch to source actually yields target, and that argument order is source→target.What is still open
JSON Patch is defined between exactly two documents. Two callers compare N and get a table:
machineLearningDeepLearning/toolkit.py:85hermesWorkflowToolkit.py:863There is no single patch for N documents, so replacing those needs a decision — N−1 patches against a chosen base, a patch per pair, or keep the table for that case. Both left untouched. @lior-antonov happy to finish it once you pick.
Merge note:
tests/batch10-pure-physicschanges the same two import lines fromfrom ..utilstofrom hera.utils. This branch already uses the absolute form, so the only conflict iscompareJSONSvsdiffJSONSon those lines — take this branch's version.🤖 Generated with Claude Code