fix(patch): keep package secrets when no kv operation applies - #467
fix(patch): keep package secrets when no kv operation applies#467sakurai-youhei wants to merge 1 commit into
Conversation
robinverduijn
left a comment
There was a problem hiding this comment.
I reviewed this and traced the fix through applySecretKVPatch. The diagnosis in the description is accurate: every operation branch (Remove, Add, Update, ReplaceKeys) reads from kv and overwrites out, so the initializer only takes effect when no branch fires. That is exactly the empty kv: {} and zero-match removeKeys cases from #466, where the old nil result was written over the package secrets. out := kv returns them unchanged, and it is safe: in the no-op path out, kv, and the caller's secrets.Data are the same slice, so the write-back is a real no-op, and the branch paths still pass kv explicitly so their behavior does not change.
I ran the package both ways to confirm the tests are load-bearing: both new cases fail against the pre-fix line and pass with it, and the full pkg/bundle/patch suite is green.
One pre-existing, out-of-scope note (not a blocker here): the operation branches do not compose. Each reads the original kv rather than the accumulated out, so a single kv block that sets more than one operation (for example add plus update, or a matching removeKeys plus add) keeps only the last-fired branch's result and discards the rest. This PR neither introduces nor worsens that, since it is independent of out's initial value. Might be worth a separate issue if multi-operation kv blocks are meant to be supported.
The fix looks correct to me.
Issue:
See #466
Cause:
applySecretKVPatchstarts with a nil result and only assigns it inside one of the four operation branches. Akvblock that triggers no operation — an empty block, orremoveKeyswhose pattern matches no key in the package — leaves the result nil, and the caller assigns that nil over the package's existing secrets.Fix:
Initialise the result with the incoming secret list, so a
kvblock that triggers no operation returns the package secrets unchanged.Verification:
Closes #466