Skip to content

Commit 69ac656

Browse files
Copilotnitrocode
andcommitted
fix: address 5 code quality issues in description feature
1. Fix compile error: declare stackDescription in processStackFile 2. Gofmt already applied by autofix.ci (no-op) 3. Fix vacuous test in TestDescribeStacksNoDescriptionField 4. Add TestDescribeStacksHelmfileComponentDescription for coverage 5. Add CLI golden snapshot for --sections description filter" Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com> Agent-Logs-Url: https://github.com/cloudposse/atmos/sessions/6d2569f8-5d96-49fa-89ae-bc60931eebd3
1 parent fcf3e3e commit 69ac656

File tree

8 files changed

+87
-6
lines changed

8 files changed

+87
-6
lines changed

internal/exec/describe_stacks_component_processor.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ func (p *describeStacksProcessor) processStackFile(stackFileName string, stackMa
9292
// not "imports", but keeping reads before mutations avoids implicit ordering assumptions.
9393
stackManifestName := getStackManifestName(stackMap)
9494

95+
// Extract stack-level description from the top-level "description" key.
96+
// ProcessStackConfig already promotes metadata.description to the top level of the result map.
97+
stackDescription, _ := stackMap[cfg.DescriptionSectionName].(string)
98+
9599
// Delete the stack-wide imports section (not needed in output).
96100
delete(stackMap, "imports")
97101

pkg/describe/describe_stacks_test.go

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,39 @@ func TestDescribeStacksComponentDescription(t *testing.T) {
473473
assert.Equal(t, "Top-level component for testing Atmos stack configuration.", description)
474474
}
475475

476+
// TestDescribeStacksHelmfileComponentDescription verifies that the description field on a
477+
// helmfile component is included in the describe stacks output.
478+
func TestDescribeStacksHelmfileComponentDescription(t *testing.T) {
479+
configAndStacksInfo := schema.ConfigAndStacksInfo{}
480+
481+
atmosConfig, err := cfg.InitCliConfig(configAndStacksInfo, true)
482+
assert.Nil(t, err)
483+
484+
stack := "tenant1-ue2-dev"
485+
components := []string{"echo-server"}
486+
componentTypes := []string{"helmfile"}
487+
488+
stacks, err := ExecuteDescribeStacks(atmosConfig, stack, components, componentTypes, nil, false, false)
489+
assert.Nil(t, err)
490+
assert.NotNil(t, stacks)
491+
492+
stackMap, ok := stacks[stack].(map[string]any)
493+
assert.True(t, ok, "stack entry should be a map")
494+
495+
componentsMap, ok := stackMap["components"].(map[string]any)
496+
assert.True(t, ok, "stack should have components section")
497+
498+
helmfileMap, ok := componentsMap["helmfile"].(map[string]any)
499+
assert.True(t, ok, "components should have helmfile section")
500+
501+
component, ok := helmfileMap["echo-server"].(map[string]any)
502+
assert.True(t, ok, "helmfile should have echo-server")
503+
504+
description, ok := component["description"].(string)
505+
assert.True(t, ok, "helmfile component should have description field")
506+
assert.Equal(t, "Echo server helmfile component for testing.", description)
507+
}
508+
476509
// TestDescribeStacksStackDescription verifies that the description field at the stack level
477510
// is included in the describe stacks output.
478511
func TestDescribeStacksStackDescription(t *testing.T) {
@@ -540,7 +573,7 @@ func TestDescribeStacksDescriptionSectionFilter(t *testing.T) {
540573
}
541574

542575
// TestDescribeStacksNoDescriptionField verifies that components without a description field
543-
// don't have the description field in the output when it's empty and includeEmpty is false.
576+
// don't have the description key in the output at all.
544577
func TestDescribeStacksNoDescriptionField(t *testing.T) {
545578
configAndStacksInfo := schema.ConfigAndStacksInfo{}
546579

@@ -570,9 +603,7 @@ func TestDescribeStacksNoDescriptionField(t *testing.T) {
570603
component, ok := terraformMap["test/test-component"].(map[string]any)
571604
assert.True(t, ok, "terraform should have test/test-component")
572605

573-
// test/test-component has no description field - it should not appear as a non-empty string.
574-
desc := component["description"]
575-
if descStr, ok := desc.(string); ok {
576-
assert.Empty(t, descStr, "description should be empty if not set in YAML")
577-
}
606+
// test/test-component has no metadata.description — the key must be absent entirely.
607+
_, exists := component["description"]
608+
assert.False(t, exists, "description key should be absent for component without metadata.description")
578609
}

tests/fixtures/scenarios/complete/stacks/catalog/helmfile/echo-server.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
components:
44
helmfile:
55
echo-server:
6+
metadata:
7+
description: "Echo server helmfile component for testing."
68
vars:
79
installed: true

tests/fixtures/scenarios/stack-manifest-name-pattern/stacks/catalog/base.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ components:
33
vpc:
44
metadata:
55
component: mock
6+
description: "VPC mock component for testing."
67
vars:
78
enabled: true

tests/fixtures/scenarios/stack-manifest-name-pattern/stacks/without-explicit-name.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
import:
33
- catalog/base
44

5+
metadata:
6+
description: "Development UW2 stack without explicit name."
7+
58
vars:
69
environment: dev
710
stage: uw2

tests/snapshots/TestCLICommands_describe_stacks_--sections_description.stderr.golden

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/snapshots/TestCLICommands_describe_stacks_--sections_description.stdout.golden

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/test-cases/component-path-resolution.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,3 +433,30 @@ tests:
433433
expect:
434434
diff: []
435435
exit_code: 0
436+
437+
- name: describe stacks --sections description
438+
enabled: true
439+
snapshot: true
440+
description: "Verify that --sections description returns only the description fields for stacks and components"
441+
workdir: "fixtures/scenarios/stack-manifest-name-pattern"
442+
command: "atmos"
443+
args:
444+
- "describe"
445+
- "stacks"
446+
- "--stack"
447+
- "dev-uw2"
448+
- "--sections"
449+
- "description"
450+
- "--format"
451+
- "json"
452+
expect:
453+
diff: []
454+
valid:
455+
- "json"
456+
stdout:
457+
- '"dev-uw2"'
458+
- '"description"'
459+
- '"Development UW2 stack without explicit name\."'
460+
- '"vpc"'
461+
- '"VPC mock component for testing\."'
462+
exit_code: 0

0 commit comments

Comments
 (0)