Skip to content

Fix component menu to filter abstract and disabled components#1977

Merged
aknysh merged 7 commits intomainfrom
osterman/fix-menu-option-issue
Jan 17, 2026
Merged

Fix component menu to filter abstract and disabled components#1977
aknysh merged 7 commits intomainfrom
osterman/fix-menu-option-issue

Conversation

@osterman
Copy link
Copy Markdown
Member

@osterman osterman commented Jan 16, 2026

what

  • Interactive component selection menu now filters out abstract components (metadata.type: abstract)
  • Disabled components (metadata.enabled: false) are hidden from interactive prompts and tab completion
  • Stack-scoped filtering: only components in the specified stack appear when --stack is provided
  • Added helper functions isComponentDeployable() and filterDeployableComponents() to centralize filtering logic
  • Updated PromptForComponent() signature to accept stack parameter for stack-aware filtering

why

Previously, users would see all components from all stacks in the interactive menu, including abstract base components that serve as templates. This was confusing because abstract components cannot be deployed. The fix ensures only deployable, valid components appear in interactive prompts and shell completion, improving user experience and preventing errors.

references

Fixes component selection menu to correctly filter out non-deployable components.

Summary by CodeRabbit

  • New Features

    • Interactive component prompts and tab completion now filter by the specified stack and show only deployable components (excludes abstract/disabled)
  • Improvements

    • Prompt flow now asks for and validates the stack earlier, enabling stack-scoped component filtering and faster validation when a stack is supplied
  • Documentation

    • Added a blog post documenting component selection filtering behavior
  • Tests

    • Expanded tests covering deployability filtering, prompting, completions, and related utilities

✏️ Tip: You can customize this high-level summary in your review settings.

…us and shell completion

When running 'atmos terraform plan -s stack-name' without specifying a component, the
interactive "Choose a component" menu now correctly filters out:
- Abstract components (metadata.type: abstract) that cannot be deployed
- Disabled components (metadata.enabled: false) that cannot be deployed
- Components not in the specified stack when --stack is provided

This filtering also applies to shell tab completion. Added helper functions
isComponentDeployable() and filterDeployableComponents() to centralize the filtering
logic. Updated PromptForComponent() to accept a stack parameter for stack-scoped
filtering. All callers updated to pass the stack parameter.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@osterman osterman requested a review from a team as a code owner January 16, 2026 16:24
@github-actions github-actions bot added the size/m Medium size PR label Jan 16, 2026
@osterman osterman added the patch A minor, backward compatible change label Jan 16, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 16, 2026

Dependency Review

✅ No vulnerabilities or license issues found.

Scanned Files

  • go.mod

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 16, 2026

Codecov Report

❌ Patch coverage is 98.37398% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.91%. Comparing base (af850e8) to head (667e69c).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/terraform/shared/prompt.go 98.11% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1977      +/-   ##
==========================================
+ Coverage   74.73%   74.91%   +0.17%     
==========================================
  Files         777      777              
  Lines       71213    71302      +89     
==========================================
+ Hits        53221    53413     +192     
+ Misses      14526    14408     -118     
- Partials     3466     3481      +15     
Flag Coverage Δ
unittests 74.91% <98.37%> (+0.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cmd/terraform/clean.go 48.33% <100.00%> (+24.99%) ⬆️
cmd/terraform/generate/backend.go 71.69% <100.00%> (+9.43%) ⬆️
cmd/terraform/generate/planfile.go 45.76% <100.00%> (+15.25%) ⬆️
cmd/terraform/generate/varfile.go 76.19% <100.00%> (+7.93%) ⬆️
cmd/terraform/shell.go 34.42% <100.00%> (+14.75%) ⬆️
cmd/terraform/utils.go 49.77% <100.00%> (+13.86%) ⬆️
errors/builder.go 95.52% <100.00%> (+0.13%) ⬆️
cmd/terraform/shared/prompt.go 96.80% <98.11%> (+46.80%) ⬆️

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 16, 2026

Caution

Review failed

The head commit changed during the review from 1ef003f to 667e69c.

📝 Walkthrough

Walkthrough

This PR makes component selection stack-aware across Terraform CLI flows by changing PromptForComponent to accept a stack parameter, adds stack-filtered component completion and deployability checks, updates callers to pass/validate stacks, and adds extensive tests plus documentation and a roadmap entry.

Changes

Cohort / File(s) Summary
Component Prompting Updates
cmd/terraform/clean.go, cmd/terraform/generate/backend.go, cmd/terraform/generate/planfile.go, cmd/terraform/generate/varfile.go, cmd/terraform/shell.go, cmd/terraform/utils.go
Call sites updated to pass stack into component prompting; stack is retrieved earlier to enable stack-scoped filtering; redundant later Viper stack reads removed; some flows now explicitly prompt/validate stack when missing.
Shared Prompt Logic
cmd/terraform/shared/prompt.go
PromptForComponent signature changed to PromptForComponent(cmd *cobra.Command, stack string); added stack-aware component completion, deployability checks (isComponentDeployable, filterDeployableComponents), stack-aware listing helpers, and test hooks (initCliConfig, executeDescribeStacks).
Prompt Tests
cmd/terraform/shared/prompt_test.go
Large new test coverage for deployability logic, component/stack listing, completion behavior, and helper functions; mocks and setup/cleanup helpers added.
Terraform utils tests
cmd/terraform/utils_test.go
Added tests covering interactive selection flow, flag helpers, completion, and path resolution/error handling.
Errors builder
errors/builder.go, errors/builder_test.go
Added WithCausef convenience builder method and corresponding tests.
Documentation / Website
website/blog/2026-01-16-component-selection-filtering.mdx, website/src/data/roadmap.js
New blog post documenting behavior and roadmap entry added (Q1-2026 milestone).
Manifest
go.mod
Minor manifest edit referenced by analyzer.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant User
participant CLI as Atmos CLI
participant Viper
participant Prompt as PromptForComponent
participant StackPrompt as PromptForStack
participant Config as Config/DescribeStacks
User->>CLI: run terraform command (maybe --stack)
CLI->>Viper: get flags (including stack)
alt component not provided
CLI->>Prompt: PromptForComponent(stack)
alt stack empty
Prompt->>StackPrompt: PromptForStack()
StackPrompt->>Config: list/validate stacks
Config-->>StackPrompt: stacks
StackPrompt-->>Prompt: selected stack
else stack provided
Prompt->>Config: list components for stack
end
Prompt->>Config: filter deployable components
Config-->>Prompt: component choices
Prompt-->>CLI: selected component and stack
end
CLI->>Viper: retrieve remaining flags / proceed

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

minor

Suggested reviewers

  • osterman
  • kevcube
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the primary change: filtering abstract and disabled components from the component selection menu.
Docstring Coverage ✅ Passed Docstring coverage is 90.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch osterman/fix-menu-option-issue

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 16, 2026
- Add DI variables to cmd/terraform/shared/prompt.go for testability
- Add comprehensive tests for listTerraformComponents, listTerraformComponentsForStack,
  listStacksForComponent, listAllStacks, and componentsArgCompletionWithStack
- Add tests for utils.go helper functions: isMultiComponentExecution,
  hasMultiComponentFlags, hasNonAffectedMultiFlags, hasSingleComponentFlags,
  handlePathResolutionError, handleInteractiveComponentStackSelection
- Extract common mock setup to helper function to avoid duplication
- Increases cmd/terraform/shared coverage from 30% to 87.9%

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions github-actions bot added size/xl Extra large size PR and removed size/m Medium size PR labels Jan 16, 2026
@mergify
Copy link
Copy Markdown

mergify bot commented Jan 16, 2026

Warning

This PR exceeds the recommended limit of 1,000 lines.

Large PRs are difficult to review and may be rejected due to their size.

Please verify that this PR does not address multiple issues.
Consider refactoring it into smaller, more focused PRs to facilitate a smoother review process.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cmd/terraform/shared/prompt.go (1)

182-324: Honor global config flags during stack/component listing.
These helpers initialize ConfigAndStacksInfo as empty, which can ignore --config, --config-path, --base-path, and --profile during prompts/completions, leading to options from the wrong config. Please thread parsed global flags into initCliConfig (e.g., via flags.ParseGlobalFlags on the calling cmd) before listing stacks/components. Based on learnings, ...

🤖 Fix all issues with AI agents
In `@website/src/data/roadmap.js`:
- Line 193: The roadmap entry for 'Smarter component selection filtering'
(object with label 'Smarter component selection filtering', pr: 1977, changelog:
'component-selection-filtering') is marked shipped for q1-2026 but the quarters
state still lists q4-2025 as current and q1-2026 as planned; update the quarters
data to mark q4-2025 completed and set q1-2026 as current, and if PR 1977 is
classified as minor/major, increment the DX initiative progress value in the
same roadmap data structure to reflect the shipped milestone.
🧹 Nitpick comments (2)
cmd/terraform/shared/prompt_test.go (1)

326-524: Good coverage of deployability rules; add cmd.NewTestKit(t) for cmd/ test isolation.
These are solid, but per cmd test hygiene, initialize cmd.NewTestKit(t) to auto-clean RootCmd state and avoid cross-test leakage. As per coding guidelines, ...

cmd/terraform/utils_test.go (1)

345-395: Multi-component execution tests are solid; add cmd.NewTestKit(t).
Please initialize cmd.NewTestKit(t) for cmd/ tests to ensure RootCmd cleanup between tests. As per coding guidelines, ...

- Mark Q4 2025 as completed
- Mark Q1 2026 as current

Addresses CodeRabbit feedback about quarter status alignment
with shipped Q1 2026 milestone.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 17, 2026
When running `atmos terraform plan --stack <invalid>` without a component,
the command would exit silently. Now it validates the stack exists and
shows a helpful error with available stacks.

Changes:
- Add ValidateStackExists() to cmd/terraform/shared/prompt.go
- Add stack validation in handleInteractiveComponentStackSelection()
- Add WithCausef() method to ErrorBuilder for formatted cause messages
- Add comprehensive tests for both features

Example error output:
  Error: invalid stack: stack `demo` does not exist
  Explanation: The specified stack was not found in the configuration
  Hint: Available stacks: acme-west-dev, acme-west-prod, acme-west-staging

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cmd/terraform/shared/prompt_test.go (1)

294-296: Godot: comment line missing trailing period.
Add a period to satisfy the comment-style linter.

🩹 Suggested fix
-	// This tests the branching logic based on args, not the actual completion values
-	// since those require config initialization.
+	// This tests the branching logic based on args, not the actual completion values since those require config initialization.
🤖 Fix all issues with AI agents
In `@cmd/terraform/shared/prompt.go`:
- Around line 183-191: listTerraformComponents currently builds an empty
schema.ConfigAndStacksInfo and calls initCliConfig, which ignores global CLI
selectors (--base-path, --config, --config-path, --profile) and returns wrong
stacks/components; fix by plumbing parsed global flags into all
listing/validation paths: call flags.ParseGlobalFlags to populate a
schema.ConfigAndStacksInfo and pass that populated struct into initCliConfig (or
InitCliConfig) instead of an empty one, and update signatures/usages of
listTerraformComponents, listTerraformComponentsForStack,
listStacksForComponent, listAllStacks and ValidateStackExists to accept and use
the ConfigAndStacksInfo (or reuse an existing cliConfig variable) so the global
selectors are honored during stack/component enumeration and validation.
🧹 Nitpick comments (1)
errors/builder_test.go (1)

473-510: Consider a table-driven structure for the multi-scenario test.
Keeps the cases uniform and aligns with the repo’s test style. As per coding guidelines, prefer table-driven tests for multiple scenarios.

♻️ Proposed refactor
 func TestErrorBuilder_WithCausef(t *testing.T) {
-	t.Run("creates formatted cause error", func(t *testing.T) {
-		stackName := "dev-us-east-1"
-
-		err := Build(ErrInvalidStack).
-			WithCausef("stack `%s` does not exist", stackName).
-			Err()
-
-		assert.Error(t, err)
-		assert.True(t, errors.Is(err, ErrInvalidStack))
-		assert.Contains(t, err.Error(), "stack `dev-us-east-1` does not exist")
-	})
-
-	t.Run("works with multiple format arguments", func(t *testing.T) {
-		err := Build(ErrInvalidComponent).
-			WithCausef("component `%s` not found in stack `%s`", "vpc", "prod").
-			Err()
-
-		assert.Error(t, err)
-		assert.True(t, errors.Is(err, ErrInvalidComponent))
-		assert.Contains(t, err.Error(), "component `vpc` not found in stack `prod`")
-	})
-
-	t.Run("chains with other builder methods", func(t *testing.T) {
-		err := Build(ErrInvalidStack).
-			WithCausef("stack `%s` does not exist", "demo").
-			WithExplanation("The stack was not found").
-			WithHint("Check your configuration").
-			Err()
-
-		assert.Error(t, err)
-		assert.True(t, errors.Is(err, ErrInvalidStack))
-		assert.Contains(t, err.Error(), "stack `demo` does not exist")
-
-		// Verify hint is present.
-		hints := errors.GetAllHints(err)
-		assert.Contains(t, hints, "Check your configuration")
-	})
+	type testCase struct {
+		name         string
+		build        func() error
+		wantIs       error
+		wantContains string
+		assertExtra  func(t *testing.T, err error)
+	}
+
+	cases := []testCase{
+		{
+			name: "creates formatted cause error",
+			build: func() error {
+				stackName := "dev-us-east-1"
+				return Build(ErrInvalidStack).
+					WithCausef("stack `%s` does not exist", stackName).
+					Err()
+			},
+			wantIs:       ErrInvalidStack,
+			wantContains: "stack `dev-us-east-1` does not exist",
+		},
+		{
+			name: "works with multiple format arguments",
+			build: func() error {
+				return Build(ErrInvalidComponent).
+					WithCausef("component `%s` not found in stack `%s`", "vpc", "prod").
+					Err()
+			},
+			wantIs:       ErrInvalidComponent,
+			wantContains: "component `vpc` not found in stack `prod`",
+		},
+		{
+			name: "chains with other builder methods",
+			build: func() error {
+				return Build(ErrInvalidStack).
+					WithCausef("stack `%s` does not exist", "demo").
+					WithExplanation("The stack was not found").
+					WithHint("Check your configuration").
+					Err()
+			},
+			wantIs:       ErrInvalidStack,
+			wantContains: "stack `demo` does not exist",
+			assertExtra: func(t *testing.T, err error) {
+				hints := errors.GetAllHints(err)
+				assert.Contains(t, hints, "Check your configuration")
+			},
+		},
+	}
+
+	for _, tc := range cases {
+		t.Run(tc.name, func(t *testing.T) {
+			err := tc.build()
+			assert.Error(t, err)
+			if tc.wantIs != nil {
+				assert.True(t, errors.Is(err, tc.wantIs))
+			}
+			if tc.wantContains != "" {
+				assert.Contains(t, err.Error(), tc.wantContains)
+			}
+			if tc.assertExtra != nil {
+				tc.assertExtra(t, err)
+			}
+		})
+	}
 }

@aknysh aknysh merged commit 372cae1 into main Jan 17, 2026
58 checks passed
@aknysh aknysh deleted the osterman/fix-menu-option-issue branch January 17, 2026 23:16
@github-actions
Copy link
Copy Markdown

These changes were released in v1.204.1-rc.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch A minor, backward compatible change size/xl Extra large size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants