#1145: persist commit fields in MkCommits.create#1850
Merged
yegor256 merged 2 commits intojcabi:masterfrom May 5, 2026
Merged
Conversation
Adds two tests that call MkCommits.create(JsonObject) and then assert that input fields (sha, message) survive a round-trip through MkCommits.get(sha).json(). Both tests fail on master because MkCommits.create() does not apply any Directives to the storage XML and the commit node is missing when MkCommit.json() runs its XPath.
MkCommits.create(JsonObject) used to delegate straight to get(sha) without applying any Directives, so the commit node was never inserted into the mock storage XML. Any subsequent call to MkCommit.json() (or any other method that reads from the storage) raised NodeNotFoundException because the XPath /github/repos/repo/git/commits/commit[sha=...] selected nothing. The fix walks the input JsonObject and writes every key as an element under the new <commit> node, mirroring how MkBranches.create and MkReferences.create persist their inputs. Arrays are stored with the @array attribute that JsonNode already understands, so MkCommit.json() round-trips them as JsonArray. Nested objects (e.g. author) are stored as nested elements.
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.
Fixes #1145.
MkCommits.create(JsonObject)previously delegated straight toget(sha)without applying anyDirectives, so nothing was ever written to the mock storage XML. Any subsequent call that traverses the storage (MkCommit.json(), etc.) raisedNodeNotFoundExceptionbecause the XPath/github/repos/repo[@coords=...]/git/commits/commit[sha=...]selected zero nodes.The fix walks the input JSON and writes each key as an element under a new
<commit>node, mirroring howMkBranches.createandMkReferences.createpersist their inputs. Arrays are stored with the@arrayattribute thatJsonNodealready understands, and nested objects (author, etc.) are stored as nested elements.Reproduction
The first commit adds two failing tests to
MkCommitsTestthat callcommits.create(...)and then read the commit back viacommits.get(sha).json(). On master both fail withNodeNotFoundException. After the fix in the second commit, all three tests inMkCommitsTestpass and the fullmvn testsuite is green (715 tests, 6 skipped pre-existing).Test plan
mvn -B -ntp test -Dtest=MkCommitsTest— 3 / 3 greenmvn -B -ntp test— 715 tests, no failures or errorsquliceviolations introduced (verified viamvn -Pqulice; only the pre-existing PMD warnings oncreatesMkCommitremain)