cli icon indicating copy to clipboard operation
cli copied to clipboard

Add merge.Override transform

Open kanterov opened this issue 1 year ago • 1 comments

Changes

Add merge.Override transform. It allows the override one dyn.Value with another, preserving source locations for parts of the sub-tree where nothing has changed. This is different from merging, where values are concatenated.

OverrideVisitor is visiting the changes during the override process and allows to control of what changes are allowed or update the effective value.

The primary use case is Python code updating bundle configuration.

During override, we update locations only for changed values. This allows us to keep track of locations where values were initially defined and used for error reporting. For instance, merging:

resources:               # location=left.yaml:0
  jobs:                  # location=left.yaml:1
    job_0:               # location=left.yaml:2
      name: "job_0"      # location=left.yaml:3

with

resources:               # location=right.yaml:0
  jobs:                  # location=right.yaml:1
    job_0:               # location=right.yaml:2
      name: "job_0"      # location=right.yaml:3
      description: job 0 # location=right.yaml:4
    job_1:               # location=right.yaml:5
      name: "job_1"      # location=right.yaml:5

produces

resources:               # location=left.yaml:0
  jobs:                  # location=left.yaml:1
    job_0:               # location=left.yaml:2
      name: "job_0"      # location=left.yaml:3
      description: job 0 # location=right.yaml:4
    job_1:               # location=right.yaml:5
      name: "job_1"      # location=right.yaml:5

Tests

Unit tests

kanterov avatar May 13 '24 08:05 kanterov

Codecov Report

Attention: Patch coverage is 75.26882% with 23 lines in your changes are missing coverage. Please review.

Project coverage is 55.10%. Comparing base (e22dd8a) to head (2ca1c25). Report is 106 commits behind head on main.

Files Patch % Lines
libs/dyn/merge/override.go 75.26% 13 Missing and 10 partials :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1428      +/-   ##
==========================================
+ Coverage   52.25%   55.10%   +2.84%     
==========================================
  Files         317      346      +29     
  Lines       18004    15785    -2219     
==========================================
- Hits         9408     8698     -710     
+ Misses       7903     6294    -1609     
- Partials      693      793     +100     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar May 13 '24 08:05 codecov-commenter

@pietern Thanks. I've updated the code, PR description, and title. Can you add it to the merge queue?

kanterov avatar May 17 '24 07:05 kanterov

Yes, everything looks good!

Looking at the code coverage, could you add/modify tests to make sure we cover the error cases as well? I think the table test can be modified to run twice for every example, one like it does now, and another one where the visitor returns an error to confirm it actually bubbles up to the caller.

pietern avatar May 17 '24 09:05 pietern