fix(PL-6895): remove edge case when merging mapping keys to preserve comments and tags#289
Conversation
📝 WalkthroughWalkthroughYAML mapping merges now select keys through a helper that preserves head comments, respects locked destination keys, handles nil nodes, and removes the obsolete ChangesYAML Mapping Key Merge
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/yml/merge.go`:
- Line 78: Update mergeKey in the mergeMap path to return immediately when
either key node is nil, before accessing or copying head comments. Preserve
normal comment propagation when both dst and src keys are present, preventing
nil dereferences for source-only or locked destination-only entries.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: d1b86148-60b5-4b6a-9597-0bd3f99b195d
📒 Files selected for processing (1)
internal/yml/merge.go
…comments and tags
11510ff to
db6dac1
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit db6dac1. Configure here.
| func mergeKey(dst, src *yaml.Node) *yaml.Node { | ||
| if IsLocked(dst) || IsLocal(dst) || src == nil { | ||
| return dst | ||
| } |
There was a problem hiding this comment.
Locked source keys overwrite destination
Medium Severity
mergeKey returns the source key whenever the destination key is unlocked, including when the source key is !lock. That disagrees with merge, which keeps the destination value when the source is locked. During promotion, an existing destination entry can become locked via the key tag while its value stays unchanged, so later merges stop updating it.
Reviewed by Cursor Bugbot for commit db6dac1. Configure here.
| if dst != nil { | ||
| // we want to preserve comments within destination files. | ||
| src.HeadComment = dst.HeadComment | ||
| } |
There was a problem hiding this comment.
Destination key comments partially dropped
Low Severity
mergeKey only copies HeadComment from the destination key onto the source key. Destination LineComment and FootComment are discarded whenever both keys exist and the destination key is not locked or local. The previous firstNonNil path kept the full destination key node, so those comments were preserved.
Reviewed by Cursor Bugbot for commit db6dac1. Configure here.


Note
Low Risk
Localized change to YAML merge key selection with no auth, security, or external API impact.
Overview
YAML map merges now pick mapping keys through a dedicated
mergeKeyhelper instead offirstNonNil, fixing edge cases when destination and source keys differ (comments, tags, or missing keys).When the destination key is locked or local, or the source key is absent, the merge keeps the destination key node. Otherwise it uses the source key but copies the destination key’s
HeadCommentonto it so inline comments on keys survive the merge.The unused
firstNonNilhelper is removed.Reviewed by Cursor Bugbot for commit db6dac1. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit