chore: clone config.env in genEnv to prevent shared-object mutation#2981
chore: clone config.env in genEnv to prevent shared-object mutation#2981joonas wants to merge 4 commits into
config.env in genEnv to prevent shared-object mutation#2981Conversation
config.env in genEnv to prevent shared-object mutationconfig.env in genEnv to prevent shared-object mutation
`genEnv` deleted `config.env["PEPR_WATCH_MODE"]` directly from the caller's `ModuleConfig` reference. Since the same config object is passed twice (once for the admission deployment and once for the watcher deployment) the first call permanently removed the key. Any code reading `config.env` after the first `genEnv` call would no longer see `PEPR_WATCH_MODE`. Shallow-clone `config.env` into a local `cfg` object and delete the key from the clone instead. This preserves the original config while still preventing a user-supplied `PEPR_WATCH_MODE` from overriding the programmatic value controlled by the `watchMode` parameter. Both regression tests assert `config.env` identity via snapshot comparison rather than checking `genEnv` return values. The `def` object always supplies `PEPR_WATCH_MODE` from the `watchMode` parameter, so output-based assertions pass even with the mutation bug present. Existing tests already cover output correctness for each mode. Signed-off-by: Joonas Bergius <joonas@defenseunicorns.com>
d9479f9 to
bcdf37e
Compare
Greptile SummaryThis PR fixes a shared-object mutation bug in
Confidence Score: 5/5Safe to merge — the change is a minimal, well-targeted clone-before-delete that eliminates an object mutation without touching any other logic. The fix is a single-line shallow clone that confines the PEPR_WATCH_MODE delete to a local copy of config.env. The logic for building the final env array is unchanged. Two new regression tests directly reproduce the two-call admission+watcher pattern that exposed the original bug, and existing tests continue to cover output correctness for every mode. No files require special attention. Important Files Changed
Reviews (2): Last reviewed commit: "Merge branch 'main' into fix/environment..." | Re-trigger Greptile |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2981 +/- ##
==========================================
+ Coverage 77.43% 77.57% +0.13%
==========================================
Files 93 93
Lines 2535 2582 +47
Branches 532 544 +12
==========================================
+ Hits 1963 2003 +40
- Misses 445 452 +7
Partials 127 127
🚀 New features to boost your workflow:
|
|
Moving to an upstream branch #3103 to fix CI secrets access. Cherry-picked with original authorship preserved. |
Description
genEnvdeletedconfig.env["PEPR_WATCH_MODE"]directly from the caller'sModuleConfigreference. Since the same config object is passed twice (once for the admission deployment and once for the watcher deployment) the first call permanently removed the key. Any code readingconfig.envafter the firstgenEnvcall would no longer seePEPR_WATCH_MODE.Shallow-clone
config.envinto a localcfgobject and delete the key from the clone instead. This preserves the original config while still preventing a user-suppliedPEPR_WATCH_MODEfrom overriding the programmatic value controlled by thewatchModeparameter.Both regression tests assert
config.envidentity via snapshot comparison rather than checkinggenEnvreturn values. Thedefobject always suppliesPEPR_WATCH_MODEfrom thewatchModeparameter, so output-based assertions pass even with the mutation bug present. Existing tests already cover output correctness for each mode.End to End Test:
(See Pepr Excellent Examples)
Type of change
Checklist before merging