Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion infra-tools/internal/renderdiff/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,13 @@ func (e *Engine) buildPair(cd *ComponentDiff) error {
cd.BaseYAML = baseYAML
}

// If neither side has the directory, nothing to diff.
// If neither side produced output, check whether the directory exists.
// Empty-base overlays (resources: []) intentionally produce no output;
// treat them as a no-op instead of an error.
if cd.HeadYAML == nil && cd.BaseYAML == nil {
if e.head.DirExists(cd.Path) || e.base.DirExists(cd.Path) {
return nil
}
return fmt.Errorf("component %s does not exist on either ref", cd.Path)
}

Expand Down
24 changes: 24 additions & 0 deletions infra-tools/internal/renderdiff/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,30 @@ func TestEngine_NoEffectiveChange(t *testing.T) {
g.Expect(result.Diffs).To(BeEmpty()) // identical YAML → omitted
}

func TestEngine_EmptyBase_NewComponent(t *testing.T) {
g := NewWithT(t)

// Simulates an empty-base overlay (resources: []) that produces no output.
// The directory exists on HEAD but not on base, and BuildKustomization
// returns nil (empty kustomize output). This should be silently skipped.
head := &fakeBuilder{
exist: map[string]bool{"components/foo/staging/empty-base": true},
yamls: map[string][]byte{"components/foo/staging/empty-base": nil},
}
base := &fakeBuilder{
exist: map[string]bool{},
}

engine := NewEngine(head, base, 2)
affected := map[detector.Environment][]appset.ComponentPath{
detector.Staging: {{Path: "components/foo/staging/empty-base"}},
}

result, err := engine.Run(context.Background(), affected)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(result.Diffs).To(BeEmpty(), "empty-base with no output should be silently skipped")
}

func TestEngine_EmptyInput(t *testing.T) {
g := NewWithT(t)

Expand Down
Loading