Skip to content

feat: RFC 6902 diffJSONS for the two-document case (#565) - #1080

Open
ilayfalach wants to merge 1 commit into
masterfrom
ISSUE565
Open

ilayfalach wants to merge 1 commit into
masterfrom
ISSUE565

Conversation

@ilayfalach

Copy link
Copy Markdown
Collaborator

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.ts is an independent 146-line TypeScript implementation, and nothing under ui/ calls the Python compareJSONS. The coordinated two-branch plan discussed in the issue is not needed.

What changed

hera.utils.diffJSONS(source, target) wraps jsonpatch.make_patch and returns the RFC 6902 patch that turns source into target — the standard @erasta proposed.

Both genuinely pairwise call sites are switched: workflow_compareToDisk and workflow_sync_to_db in hera/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, so res.empty became not res and the patch prints through pandas.DataFrame(res) — same familiar table, now with op/path/value columns.

jsonpatch was installed but only transitively (requirements.txt declared its dependency jsonpointer, 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:85
  • hermesWorkflowToolkit.py:863

There 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-physics changes the same two import lines from from ..utils to from hera.utils. This branch already uses the absolute form, so the only conflict is compareJSONS vs diffJSONS on those lines — take this branch's version.

🤖 Generated with Claude Code

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>
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