Skip to content

Reset encoder anchor state between documents - #993

Open
peterolkhov wants to merge 1 commit into
goccy:masterfrom
peterolkhov:codex/reset-encoder-anchor-state
Open

peterolkhov wants to merge 1 commit into
goccy:masterfrom
peterolkhov:codex/reset-encoder-anchor-state

Conversation

@peterolkhov

Copy link
Copy Markdown

Before submitting your PR, please confirm the following.

  • Describe the purpose for which you created this PR.
  • Create test code that corresponds to the modification

Reusing an Encoder with the same anchored pointer can write aliases to the previous document instead of encoding the current value. For example, changing a shared settings object's timeout between two Encode calls loses that update, and the second document cannot be decoded independently.

Clear the document's anchor and alias bookkeeping in EncodeToNodeContext. This also covers repeated node conversions while preserving SmartAnchor's two passes. The tests cover updated snapshots, independent document decoding, custom anchor names, and SmartAnchor reuse when the next document stops sharing a value.

Tested locally: make test on Go 1.21.13 and 1.26.7, make lint with golangci-lint 2.1.2, make cover, go build ./..., the ycat build and run, and the playground wasm and page builds. These ran on macOS arm64; the page build used Node 24.13.0. The full hosted CI matrix and generated fuzzing were not run.

AI assistance was used to implement the fix and tests.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.72%. Comparing base (edee2f9) to head (d78cc99).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #993      +/-   ##
==========================================
+ Coverage   80.65%   80.72%   +0.06%     
==========================================
  Files          22       22              
  Lines        6845     6848       +3     
==========================================
+ Hits         5521     5528       +7     
+ Misses        905      903       -2     
+ Partials      419      417       -2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

2 participants