Skip to content

test: add regression coverage for null metadata with empty state objects - #224

Open
aws-kevinrickard wants to merge 1 commit into
aws-greengrass:mainfrom
aws-kevinrickard:tests/shadow-document-metadata-invariant
Open

test: add regression coverage for null metadata with empty state objects#224
aws-kevinrickard wants to merge 1 commit into
aws-greengrass:mainfrom
aws-kevinrickard:tests/shadow-document-metadata-invariant

Conversation

@aws-kevinrickard

@aws-kevinrickard aws-kevinrickard commented Aug 18, 2026

Copy link
Copy Markdown
Member

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: if state.{desired,reported} is non-null, then metadata.{desired,reported} is non-null. A desired-side violation of this invariant causes getDelta() to throw NullPointerException in buildMetadata (one frame deep).

The root cause is JsonUtil.isMissing() treating empty objects ({}) as missing, which leads ShadowStateMetadata.merge() to remove metadata keys while the corresponding state nodes remain. When that removal empties the metadata tree, nullIfEmpty converts it to null.

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.

Case Description release_2.3.x v2.3.13
1 empty object as only desired node
2 empty object beside a populated sibling
3 all children of a node removed by a null patch
4 empty object nested two levels down
5 empty object on the reported side
6 populated desired node (control)

release_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 the getDelta() safety assertion additionally fails for cases 1 and 3 with the NPE from ShadowStateMetadata.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

kstribrnAmzn
kstribrnAmzn previously approved these changes Aug 18, 2026
@aws-kevinrickard
aws-kevinrickard force-pushed the tests/shadow-document-metadata-invariant branch from cf4b265 to 8146331 Compare August 18, 2026 23:46
@aws-kevinrickard
aws-kevinrickard changed the base branch from release_2.3.x to main August 18, 2026 23:46
@aws-kevinrickard
aws-kevinrickard dismissed kstribrnAmzn’s stale review August 18, 2026 23:46

The base branch was changed.

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.

3 participants