test: add regression coverage for null metadata with empty state objects - #224
Open
aws-kevinrickard wants to merge 1 commit into
Open
Conversation
kstribrnAmzn
previously approved these changes
Aug 18, 2026
aws-kevinrickard
force-pushed
the
tests/shadow-document-metadata-invariant
branch
from
August 18, 2026 23:46
cf4b265 to
8146331
Compare
aws-kevinrickard
dismissed
kstribrnAmzn’s stale review
August 18, 2026 23:46
The base branch was changed.
saranyailla
approved these changes
Aug 18, 2026
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.
Adds regression tests for the state/metadata consistency invariant that #213 fixes.
What this tests
After
ShadowDocument.update(patch), both sides of the document must satisfy: ifstate.{desired,reported}is non-null, thenmetadata.{desired,reported}is non-null. A desired-side violation of this invariant causesgetDelta()to throw NullPointerException inbuildMetadata(one frame deep).The root cause is
JsonUtil.isMissing()treating empty objects ({}) as missing, which leadsShadowStateMetadata.merge()to remove metadata keys while the corresponding state nodes remain. When that removal empties the metadata tree,nullIfEmptyconverts it tonull.Six cases cover the invariant from different angles. Case 5 exercises the same empty-object handling on the reported side, where it leaves the metadata tree inconsistent without surfacing as a crash — delta metadata is derived from the desired tree alone, so the reported-side violation is silent. Case 6 is the control (populated node, must pass everywhere).
Verification results
All assertions check the invariant (state non-null → metadata non-null) and safety (
getDelta()does not throw). No assertions on metadata contents.release_2.3.xv2.3.13release_2.3.x: 12 tests, 0 failures.v2.3.13: 12 tests, 5 failures — the invariant assertion fails for cases 1, 3, and 5 (metadata null while state is non-null), and thegetDelta()safety assertion additionally fails for cases 1 and 3 with the NPE fromShadowStateMetadata.buildMetadata. Case 5's violation is on the reported side, so it does not trigger the NPE.The failures on the pre-fix tag confirm the tests are meaningful: they detect the condition #213 addresses.
Notes
main, which carries the [Fix] Leave empty objects in metadata #213 fix as of fix: leave empty objects in metadata (cherry-pick #213 to main) #225. The tests also pass onrelease_2.3.x(where [Fix] Leave empty objects in metadata #213 originally landed) and fail on any branch without it.ShadowDocumentMetadataInvariantTest) rather than extendingShadowStateMetadataTest, because the latter differs between tags.getDelta()safety assertion is a separate parameterized test method so failures report independently from the invariant assertion.