Skip to content

Conversation

j4zzcat
Copy link
Contributor

@j4zzcat j4zzcat commented Aug 17, 2025

This PR updates the workflow utils so that when a workflow-level stack is provided, the generated -s <stack> flag is placed before any -- argument in the command args (instead of always at the end).

The -- marker indicates the end of Atmos CLI arguments; anything after it is passed directly to the underlying tool or script. Appending -s <stack> after -- caused the stack flag to be ignored in such cases.

Changes

  • In workflow_utils.go, modified the logic around appending -s <stack>:
    • If -- exists in args, insert the stack flag immediately before it.
    • If no -- is present, behavior remains the same (flag is appended at the end).

Example

Before

atmos workflow deploy -- foo bar
# produces args: ["deploy", "--", "foo", "bar", "-s", "my-stack"]
# "-s my-stack" is ignored since it's after `--`

After

atmos workflow deploy -- foo bar
# produces args: ["deploy", "-s", "my-stack", "--", "foo", "bar"]
# stack flag is correctly passed to Atmos

Summary by CodeRabbit

  • Bug Fixes
    • Correctly positions the stack option when executing workflows that include a “--” separator so the stack is not treated as a passthrough argument.
    • Prevents conflicts between workflow options and additional passthrough arguments, ensuring the intended stack is reliably applied.
    • Improves reliability when running commands that mix tool options and passthrough arguments.

@j4zzcat j4zzcat requested a review from a team as a code owner August 17, 2025 23:32
@j4zzcat j4zzcat marked this pull request as draft August 17, 2025 23:32
@mergify mergify bot added the triage Needs triage label Aug 17, 2025
Copy link
Contributor

coderabbitai bot commented Aug 17, 2025

📝 Walkthrough

Walkthrough

Adjusts atmos command argument assembly in ExecuteWorkflow to insert -s <stack> before a -- sentinel if present, otherwise append at the end. Adds import for slices. Debug logging of the selected stack remains. No public APIs changed.

Changes

Cohort / File(s) Summary
Workflow execution utils
internal/exec/workflow_utils.go
Import slices. Modify args construction to insert -s and finalStack before "--" if present using slices.Index, else append. Preserve debug logging.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant CLI
  participant ExecuteWorkflow
  participant ArgBuilder
  participant Atmos

  User->>CLI: run workflow
  CLI->>ExecuteWorkflow: ExecuteWorkflow(opts)
  ExecuteWorkflow->>ArgBuilder: build args
  ArgBuilder->>ArgBuilder: find "--" via slices.Index
  alt "--" found
    ArgBuilder->>ArgBuilder: insert "-s", stack before "--"
  else
    ArgBuilder->>ArgBuilder: append "-s", stack at end
  end
  ExecuteWorkflow->>Atmos: invoke with args
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

patch

Suggested reviewers

  • osterman
  • aknysh

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
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

🧹 Nitpick comments (1)
internal/exec/workflow_utils.go (1)

141-151: Use slices.Insert for clarity; optionally de-dupe existing stack flags.

  • Readability: slices.Insert makes the intent obvious.
  • Optional: if the original command already includes a stack flag before “--”, consider removing it so the injected one is the single source of truth.

Apply:

-    			if idx := slices.Index(args, "--"); idx != -1 {
-        			// Insert before the "--"
-                    // Take everything up to idx, then add "-s", finalStack, then tack on the rest
-        			args = append(args[:idx], append([]string{"-s", finalStack}, args[idx:]...)...)
-    			} else {
-        			// just append at the end
-        			args = append(args, "-s", finalStack)
-    			}
+    			if idx := slices.Index(args, "--"); idx != -1 {
+        			// Insert "-s <stack>" immediately before "--"
+        			args = slices.Insert(args, idx, "-s", finalStack)
+    			} else {
+        			args = append(args, "-s", finalStack)
+    			}

Notes:

  • If you want to avoid duplicate stack flags, prune any existing “-s/--stack” before the sentinel prior to insertion.
  • Also consider aligning the user-facing “Executing command” message to display the mutated args so it reflects the actual invocation.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 26b1147 and 7ce94e4.

📒 Files selected for processing (1)
  • internal/exec/workflow_utils.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go

📄 CodeRabbit Inference Engine (.cursor/rules/atmos-rules.mdc)

**/*.go: Use Viper for managing configuration, environment variables, and flags
Use interfaces for external dependencies to facilitate mocking
All code must pass golangci-lint checks
Follow Go's error handling idioms
Use meaningful error messages
Wrap errors with context using fmt.Errorf("context: %w", err)
Consider using a custom error type for domain-specific errors
Follow standard Go coding style
Use gofmt and goimports to format code
Prefer short, descriptive variable names
Use snake_case for environment variables
Document all exported functions, types, and methods
Document complex logic with inline comments
Follow Go's documentation conventions
Use Viper for configuration management
Support configuration via files, environment variables, and flags
Follow the precedence order: flags > environment variables > config file > defaults

Files:

  • internal/exec/workflow_utils.go
🧠 Learnings (6)
📓 Common learnings
Learnt from: aknysh
PR: cloudposse/atmos#1261
File: internal/exec/utils.go:639-640
Timestamp: 2025-05-22T15:42:10.906Z
Learning: In the Atmos codebase, when appending slices with `args := append(configAndStacksInfo.CliArgs, configAndStacksInfo.AdditionalArgsAndFlags...)`, it's intentional that the result is not stored back in the original slice. This pattern is used when the merged result serves a different purpose than the original slices, such as when creating a filtered version for component section assignments.
📚 Learning: 2025-05-22T15:42:10.906Z
Learnt from: aknysh
PR: cloudposse/atmos#1261
File: internal/exec/utils.go:639-640
Timestamp: 2025-05-22T15:42:10.906Z
Learning: In the Atmos codebase, when appending slices with `args := append(configAndStacksInfo.CliArgs, configAndStacksInfo.AdditionalArgsAndFlags...)`, it's intentional that the result is not stored back in the original slice. This pattern is used when the merged result serves a different purpose than the original slices, such as when creating a filtered version for component section assignments.

Applied to files:

  • internal/exec/workflow_utils.go
📚 Learning: 2024-11-13T21:37:07.852Z
Learnt from: Cerebrovinny
PR: cloudposse/atmos#764
File: internal/exec/describe_stacks.go:289-295
Timestamp: 2024-11-13T21:37:07.852Z
Learning: In the `internal/exec/describe_stacks.go` file of the `atmos` project written in Go, avoid extracting the stack name handling logic into a helper function within the `ExecuteDescribeStacks` method, even if the logic appears duplicated.

Applied to files:

  • internal/exec/workflow_utils.go
📚 Learning: 2024-12-07T16:16:13.038Z
Learnt from: Listener430
PR: cloudposse/atmos#825
File: internal/exec/helmfile_generate_varfile.go:28-31
Timestamp: 2024-12-07T16:16:13.038Z
Learning: In `internal/exec/helmfile_generate_varfile.go`, the `--help` command (`./atmos helmfile generate varfile --help`) works correctly without requiring stack configurations, and the only change needed was to make `ProcessCommandLineArgs` exportable by capitalizing its name.

Applied to files:

  • internal/exec/workflow_utils.go
📚 Learning: 2025-06-02T14:12:02.710Z
Learnt from: milldr
PR: cloudposse/atmos#1229
File: internal/exec/workflow_test.go:0-0
Timestamp: 2025-06-02T14:12:02.710Z
Learning: In the atmos codebase, workflow error handling was refactored to use `PrintErrorMarkdown` followed by returning specific error variables (like `ErrWorkflowNoSteps`, `ErrInvalidFromStep`, `ErrInvalidWorkflowStepType`, `ErrWorkflowStepFailed`) instead of `PrintErrorMarkdownAndExit`. This pattern allows proper error testing without the function terminating the process with `os.Exit`, enabling unit tests to assert on error conditions while maintaining excellent user-facing error formatting.

Applied to files:

  • internal/exec/workflow_utils.go
📚 Learning: 2025-02-21T20:56:05.539Z
Learnt from: samtholiya
PR: cloudposse/atmos#1077
File: pkg/downloader/custom_github_detector.go:0-0
Timestamp: 2025-02-21T20:56:05.539Z
Learning: The `github.com/charmbracelet/log` package should be imported with the alias `log` according to the project's import alias configuration.

Applied to files:

  • internal/exec/workflow_utils.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Summary
🔇 Additional comments (1)
internal/exec/workflow_utils.go (1)

10-10: Go stdlib “slices” is supported
The repo’s go.mod specifies Go 1.24.5, which includes the “slices” package (added in Go 1.21). No changes required.

coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 17, 2025
@mergify mergify bot removed the triage Needs triage label Aug 17, 2025
@mergify mergify bot added the triage Needs triage label Aug 17, 2025
@j4zzcat j4zzcat marked this pull request as ready for review August 17, 2025 23:59
coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 18, 2025
@mergify mergify bot removed the triage Needs triage label Aug 18, 2025
@osterman osterman added the patch A minor, backward compatible change label Aug 18, 2025
Copy link
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: 0

🧹 Nitpick comments (3)
internal/exec/workflow_utils.go (3)

141-149: Stack flag insertion before -- works; consider two polish items.

The insertion logic is correct and meets the PR goal. Two optional refinements:

  • Consider stripping any existing pre--- occurrences of -s/--stack to avoid duplicate flags.
  • Add a brief comment noting that -- terminates Atmos flag parsing (future readers will thank you).

No blocker—just quality-of-life improvements.


154-154: Show the actual executed args in the TUI message.

This currently prints the original command string and not the arg list after inserting -s. Display the joined args so users see the real invocation.

Apply:

-			u.PrintfMessageToTUI("Executing command: `atmos %s`\n", command)
+			u.PrintfMessageToTUI("Executing command: `atmos %s`\n", strings.Join(args, " "))

186-193: Make the failure message reflect the actual invocation (insert -s before --).

When building failedCmd, appending -s to the end will place it after -- if present, which misrepresents how the command was executed. Construct the message using the same insertion logic used for args.

Apply:

-			failedCmd = config.AtmosCommand + " " + command
-			// Add stack parameter to failed command if a stack was used
-			if finalStack != "" {
-				failedCmd = fmt.Sprintf("%s -s %s", failedCmd, finalStack)
-			}
+			// Build a faithful representation of the executed command (stack flag before any "--")
+			argsForMsg := strings.Fields(command)
+			if finalStack != "" {
+				if i := slices.Index(argsForMsg, "--"); i != -1 {
+					argsForMsg = append(argsForMsg[:i], append([]string{"-s", finalStack}, argsForMsg[i:]...)...)
+				} else {
+					argsForMsg = append(argsForMsg, "-s", finalStack)
+				}
+			}
+			failedCmd = config.AtmosCommand + " " + strings.Join(argsForMsg, " ")
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3950da6 and 19e2a7b.

📒 Files selected for processing (1)
  • internal/exec/workflow_utils.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go

📄 CodeRabbit Inference Engine (.cursor/rules/atmos-rules.mdc)

**/*.go: Use Viper for managing configuration, environment variables, and flags
Use interfaces for external dependencies to facilitate mocking
All code must pass golangci-lint checks
Follow Go's error handling idioms
Use meaningful error messages
Wrap errors with context using fmt.Errorf("context: %w", err)
Consider using a custom error type for domain-specific errors
Follow standard Go coding style
Use gofmt and goimports to format code
Prefer short, descriptive variable names
Use snake_case for environment variables
Document all exported functions, types, and methods
Document complex logic with inline comments
Follow Go's documentation conventions
Use Viper for configuration management
Support configuration via files, environment variables, and flags
Follow the precedence order: flags > environment variables > config file > defaults

Files:

  • internal/exec/workflow_utils.go
🧠 Learnings (9)
📓 Common learnings
Learnt from: aknysh
PR: cloudposse/atmos#1261
File: internal/exec/utils.go:639-640
Timestamp: 2025-05-22T15:42:10.906Z
Learning: In the Atmos codebase, when appending slices with `args := append(configAndStacksInfo.CliArgs, configAndStacksInfo.AdditionalArgsAndFlags...)`, it's intentional that the result is not stored back in the original slice. This pattern is used when the merged result serves a different purpose than the original slices, such as when creating a filtered version for component section assignments.
Learnt from: Cerebrovinny
PR: cloudposse/atmos#764
File: internal/exec/describe_stacks.go:289-295
Timestamp: 2024-11-13T21:37:07.852Z
Learning: In the `internal/exec/describe_stacks.go` file of the `atmos` project written in Go, avoid extracting the stack name handling logic into a helper function within the `ExecuteDescribeStacks` method, even if the logic appears duplicated.
📚 Learning: 2025-05-22T15:42:10.906Z
Learnt from: aknysh
PR: cloudposse/atmos#1261
File: internal/exec/utils.go:639-640
Timestamp: 2025-05-22T15:42:10.906Z
Learning: In the Atmos codebase, when appending slices with `args := append(configAndStacksInfo.CliArgs, configAndStacksInfo.AdditionalArgsAndFlags...)`, it's intentional that the result is not stored back in the original slice. This pattern is used when the merged result serves a different purpose than the original slices, such as when creating a filtered version for component section assignments.

Applied to files:

  • internal/exec/workflow_utils.go
📚 Learning: 2024-11-13T21:37:07.852Z
Learnt from: Cerebrovinny
PR: cloudposse/atmos#764
File: internal/exec/describe_stacks.go:289-295
Timestamp: 2024-11-13T21:37:07.852Z
Learning: In the `internal/exec/describe_stacks.go` file of the `atmos` project written in Go, avoid extracting the stack name handling logic into a helper function within the `ExecuteDescribeStacks` method, even if the logic appears duplicated.

Applied to files:

  • internal/exec/workflow_utils.go
📚 Learning: 2024-12-07T16:16:13.038Z
Learnt from: Listener430
PR: cloudposse/atmos#825
File: internal/exec/helmfile_generate_varfile.go:28-31
Timestamp: 2024-12-07T16:16:13.038Z
Learning: In `internal/exec/helmfile_generate_varfile.go`, the `--help` command (`./atmos helmfile generate varfile --help`) works correctly without requiring stack configurations, and the only change needed was to make `ProcessCommandLineArgs` exportable by capitalizing its name.

Applied to files:

  • internal/exec/workflow_utils.go
📚 Learning: 2025-06-02T14:12:02.710Z
Learnt from: milldr
PR: cloudposse/atmos#1229
File: internal/exec/workflow_test.go:0-0
Timestamp: 2025-06-02T14:12:02.710Z
Learning: In the atmos codebase, workflow error handling was refactored to use `PrintErrorMarkdown` followed by returning specific error variables (like `ErrWorkflowNoSteps`, `ErrInvalidFromStep`, `ErrInvalidWorkflowStepType`, `ErrWorkflowStepFailed`) instead of `PrintErrorMarkdownAndExit`. This pattern allows proper error testing without the function terminating the process with `os.Exit`, enabling unit tests to assert on error conditions while maintaining excellent user-facing error formatting.

Applied to files:

  • internal/exec/workflow_utils.go
📚 Learning: 2024-10-23T21:36:40.262Z
Learnt from: osterman
PR: cloudposse/atmos#740
File: cmd/cmd_utils.go:340-359
Timestamp: 2024-10-23T21:36:40.262Z
Learning: In the Go codebase for Atmos, when reviewing functions like `checkAtmosConfig` in `cmd/cmd_utils.go`, avoid suggesting refactoring to return errors instead of calling `os.Exit` if such changes would significantly increase the scope due to the need to update multiple call sites.

Applied to files:

  • internal/exec/workflow_utils.go
📚 Learning: 2024-10-30T13:25:45.965Z
Learnt from: osterman
PR: cloudposse/atmos#727
File: internal/exec/terraform_clean.go:405-412
Timestamp: 2024-10-30T13:25:45.965Z
Learning: In `internal/exec/terraform_clean.go`, when appending `stackFolders` to `folders` in the `handleCleanSubCommand` function, it's unnecessary to check if `stackFolders` is nil before appending, because in Go, appending a nil slice is safe and does not cause a panic.

Applied to files:

  • internal/exec/workflow_utils.go
📚 Learning: 2024-12-07T16:19:01.683Z
Learnt from: aknysh
PR: cloudposse/atmos#825
File: internal/exec/terraform.go:30-30
Timestamp: 2024-12-07T16:19:01.683Z
Learning: In `internal/exec/terraform.go`, skipping stack validation when help flags are present is not necessary.

Applied to files:

  • internal/exec/workflow_utils.go
📚 Learning: 2024-11-19T23:00:45.899Z
Learnt from: osterman
PR: cloudposse/atmos#795
File: internal/exec/stack_processor_utils.go:378-386
Timestamp: 2024-11-19T23:00:45.899Z
Learning: In the `ProcessYAMLConfigFile` function within `internal/exec/stack_processor_utils.go`, directory traversal in stack imports is acceptable and should not be restricted.

Applied to files:

  • internal/exec/workflow_utils.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Build (macos-latest, macos)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
  • GitHub Check: Lint (golangci)
  • GitHub Check: Summary
🔇 Additional comments (1)
internal/exec/workflow_utils.go (1)

8-8: stdlib “slices” is supported (Go 1.24.5)
go.mod specifies go 1.24.5 (≥ 1.21), so the standard-library slices import is valid. No changes required.

Copy link

codecov bot commented Aug 18, 2025

Codecov Report

❌ Patch coverage is 37.50000% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.33%. Comparing base (26b1147) to head (19e2a7b).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/exec/workflow_utils.go 37.50% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1411      +/-   ##
==========================================
+ Coverage   55.29%   55.33%   +0.03%     
==========================================
  Files         272      272              
  Lines       28481    28487       +6     
==========================================
+ Hits        15748    15762      +14     
+ Misses      10957    10946      -11     
- Partials     1776     1779       +3     
Flag Coverage Δ
unittests 55.33% <37.50%> (+0.03%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@aknysh aknysh added no-release Do not create a new release (wait for additional code changes) and removed patch A minor, backward compatible change labels Aug 18, 2025
Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

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

thanks @j4zzcat

@aknysh aknysh merged commit 1f8c046 into cloudposse:main Aug 18, 2025
95 of 97 checks passed
Copy link

These changes were released in v1.188.0-test.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-release Do not create a new release (wait for additional code changes)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants