Skip to content

Reject container insertions that would create a cycle - #1184

Merged
tgregg merged 2 commits into
amazon-ion:masterfrom
davidreic2:white-bounty/container-invariants
Dec 3, 2026
Merged

tgregg merged 2 commits into
amazon-ion:masterfrom
davidreic2:white-bounty/container-invariants

Conversation

@davidreic2

Copy link
Copy Markdown
Contributor

Closes #6.

The shared child validator now rejects inserting a container into itself or one of its descendants. A child that already has a parent is rejected by the existing ownership check, so the only detached ancestor to check is the root. Scalars and empty candidate containers need no ancestor walk.

The regression tests cover self-insertion into a list and replacing an existing sequence element or struct field with an ancestor. They also check that the original entries survive rejection and that reparenting succeeds after a valid detach.

./gradlew :test passed. Both new tests ran in the streaming and incremental streaming configurations.

Contributed by David Reichhardt (samambai), with OpenAI Codex assistance on the implementation, validation and PR text.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov

codecov Bot commented Dec 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.39%. Comparing base (3c1b6b1) to head (ce65c23).
⚠️ Report is 174 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1184      +/-   ##
============================================
+ Coverage     67.23%   68.39%   +1.16%     
- Complexity     5484     5760     +276     
============================================
  Files           159      160       +1     
  Lines         23025    23521     +496     
  Branches       4126     4245     +119     
============================================
+ Hits          15481    16088     +607     
+ Misses         6262     6133     -129     
- Partials       1282     1300      +18     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tgregg tgregg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

@tgregg
tgregg merged commit 5d9750d into amazon-ion:master Dec 3, 2026
30 of 37 checks passed
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.

Container add-methods should check for cycle creation

2 participants