Skip to content

fix: Resolve CI regression where terraform fails without TTY for identity selection - #1735

Merged
Andriy Knysh (aknysh) merged 50 commits into
mainfrom
fix-auth-login-failure
Nov 1, 2025
Merged

Andriy Knysh (aknysh) merged 50 commits into
mainfrom
fix-auth-login-failure

Conversation

@osterman

@osterman Erik Osterman (Cloud Posse) (osterman) commented Oct 31, 2025 •

Copy link
Copy Markdown
Member

Summary

Fixed critical regression in v1.196.0 where atmos terraform plan fails in CI environments with "interactive identity selection requires a TTY" error even when no authentication is configured.

The Problem

Running atmos terraform plan in CI (non-TTY) fails with:

Error: default identity error: interactive identity selection requires a TTY

This happens even when:

  • No authentication is configured
  • No --identity flag is provided
  • No identity-related environment variables are set

Root Causes

  1. Viper global state pollution: viper.BindPFlag() in cmd/auth_shell.go created two-way binding that persisted the __SELECT__ value across commands
  2. Incorrect fallback logic: Code would read from viper when the flag wasn't provided, getting polluted values from previous command executions

Solution

Key Changes

cmd/terraform_utils.go (lines 75-128):

  • Only process --identity flag when explicitly provided (flags.Changed())
  • Never read from viper global state (which can be polluted)
  • Check TTY availability BEFORE attempting interactive selection
  • Skip identity selection with debug log when no identities configured

cmd/auth_shell.go and cmd/auth_exec.go:

  • Remove duplicate identity flag definitions that shadowed parent PersistentFlags
  • Remove viper.BindPFlag() calls (the pollution source)
  • Identity flag properly inherited from parent authCmd

All 6 Scenarios Now Handled Correctly

✅ No flag + default identity configured → Use default identity (TerraformPreHook)
✅ --identity + TTY + identities available → Show interactive selector
✅ --identity + no TTY → Fast fail with clear error message
✅ --identity + no identities → Skip with debug log (no error)
✅ --identity=value + exists → Use that identity
✅ --identity=value + missing → Error from auth manager

Tests

Added comprehensive test suites covering all scenarios:

  • cmd/viper_bindings_test.go - Proves BindPFlag pollution mechanism
  • cmd/viper_identity_flag_test.go - Tests viper resolution scenarios
  • cmd/terraform_identity_flag_test.go - Tests terraform command behavior
  • cmd/cobra_flag_defaults_test.go - Tests Cobra NoOptDefVal behavior
  • Updated auth command tests to check flag inheritance

All tests use t.Setenv() per CLAUDE.md guidelines and check inherited flags via cmd.Flag().

Documentation

Created pkg/auth/docs/identity-flag-behavior.md documenting:

  • All 6 scenarios and expected behavior
  • Authentication flow and precedence order
  • Architecture decisions and rationale
  • Non-functional requirements
  • Future enhancements

Verification

  • ✅ Build passes
  • ✅ All tests pass
  • ✅ Pre-commit hooks pass (excluding pre-existing lint issues in unrelated files)
  • ✅ No viper pollution between command executions
  • ✅ Default identity authentication works without --identity flag
  • ✅ Interactive selection works in TTY
  • ✅ Fast failure with clear error in CI (no TTY)

Related Issues

Fixes v1.196.0 regression where CI pipelines fail unnecessarily.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added interactive identity selection when --identity flag is used without a value
    • Implemented SSO token caching to prevent re-authentication prompts
    • Added unified, secure command-line argument parsing for trailing arguments
  • Bug Fixes

    • Fixed authentication chain truncation in container environments
    • Improved shell safety for custom commands with special characters and whitespace
    • Enhanced identity flag handling across CLI commands
  • Documentation

    • Added comprehensive guides on safe argument parsing and shell quoting
    • Documented authentication chain and credential caching fixes
    • Updated CLI help text for identity flag behavior
  • Chores

    • Updated dependencies to latest versions

…tity selection

## What
Fixed critical regression in v1.196.0 where `atmos terraform plan` fails in CI
environments with "interactive identity selection requires a TTY" error even when:
- No authentication is configured
- No --identity flag is provided
- No identity-related environment variables are set

## Why
The bug had two root causes:
1. **Viper global state pollution**: `viper.BindPFlag()` in auth_shell.go created
   two-way binding that persisted the `__SELECT__` value across commands
2. **Incorrect fallback logic**: Code would read from viper when flag wasn't
   provided, getting polluted values from previous command executions

## How
### Fix in cmd/terraform_utils.go (lines 75-128):
- Only check `flags.Changed()` when flag explicitly provided
- Don't read from viper global state (which can be polluted)
- Check TTY availability before interactive selection
- Skip identity selection with debug log when no identities configured
- ProcessCommandLineArgs already handles identity from env vars

### Fix in cmd/auth_shell.go and cmd/auth_exec.go:
- Remove duplicate identity flag definitions that shadowed parent PersistentFlags
- Remove viper.BindPFlag() calls (the pollution source)
- Identity flag properly inherited from parent authCmd

### Behavior (6 scenarios):
✅ No flag + default identity → Use default (TerraformPreHook)
✅ --identity + TTY + identities → Interactive selector
✅ --identity + no TTY → ERROR: "requires TTY"
✅ --identity + no identities → Debug log, continue
✅ --identity=value + exists → Use that identity
✅ --identity=value + missing → ERROR: "not found"

## Tests
- Added comprehensive test suites for all scenarios
- Tests renamed to assert passing state (not regression names)
- All tests use t.Setenv() per CLAUDE.md guidelines
- Proved viper pollution mechanism with BindPFlag tests
- Tests for inherited flags via cmd.Flag() not cmd.Flags().Lookup()

## Documentation
- Created pkg/auth/docs/identity-flag-behavior.md
- Documents all 6 scenarios and expected behavior
- Explains authentication flow and precedence order
- Details non-functional requirements and decisions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@github-actions github-actions Bot added the size/xl Extra large size PR label Oct 31, 2025
@mergify

mergify Bot commented Oct 31, 2025

Copy link
Copy Markdown
Contributor

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.

@github-actions

github-actions Bot commented Oct 31, 2025 •

Copy link
Copy Markdown

Dependency Review

The following issues were found:
  • ✅ 0 vulnerable package(s)
  • ✅ 0 package(s) with incompatible licenses
  • ✅ 0 package(s) with invalid SPDX license definitions
  • ⚠️ 1 package(s) with unknown licenses.
See the Details below.

License Issues

go.mod

PackageVersionLicenseIssue Type
golang.org/x/time0.14.0NullUnknown License
Allowed Licenses: MIT, Apache-2.0, BSD-2-Clause, BSD-3-Clause, ISC, MPL-2.0, 0BSD, Unlicense, CC0-1.0

OpenSSF Scorecard

Scorecard details
PackageVersionScoreDetails
gomod/cloud.google.com/go 0.121.6 🟢 8.3
Details
CheckScoreReason
Code-Review🟢 10all changesets reviewed
Maintained🟢 1030 commit(s) and 4 issue activity found in the last 90 days -- score normalized to 10
Packaging⚠️ -1packaging workflow not detected
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Security-Policy🟢 10security policy file detected
Token-Permissions🟢 10GitHub workflow tokens follow principle of least privilege
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
License🟢 10license file detected
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration
Signed-Releases⚠️ -1no releases found
Fuzzing🟢 10project is fuzzed
Binary-Artifacts🟢 10no binaries found in the repo
Pinned-Dependencies⚠️ 1dependency not pinned by hash detected -- score normalized to 1
SAST⚠️ 0SAST tool is not run on all commits -- score normalized to 0
Vulnerabilities🟢 100 existing vulnerabilities detected
gomod/cloud.google.com/go/storage 1.57.1 🟢 8.3
Details
CheckScoreReason
Code-Review🟢 10all changesets reviewed
Maintained🟢 1030 commit(s) and 4 issue activity found in the last 90 days -- score normalized to 10
Packaging⚠️ -1packaging workflow not detected
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Security-Policy🟢 10security policy file detected
Token-Permissions🟢 10GitHub workflow tokens follow principle of least privilege
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
License🟢 10license file detected
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration
Signed-Releases⚠️ -1no releases found
Fuzzing🟢 10project is fuzzed
Binary-Artifacts🟢 10no binaries found in the repo
Pinned-Dependencies⚠️ 1dependency not pinned by hash detected -- score normalized to 1
SAST⚠️ 0SAST tool is not run on all commits -- score normalized to 0
Vulnerabilities🟢 100 existing vulnerabilities detected
gomod/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob 1.6.3 🟢 7.2
Details
CheckScoreReason
Packaging⚠️ -1packaging workflow not detected
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Code-Review🟢 10all changesets reviewed
Maintained🟢 1030 commit(s) and 14 issue activity found in the last 90 days -- score normalized to 10
Security-Policy🟢 10security policy file detected
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Token-Permissions🟢 9detected GitHub workflow tokens with excessive permissions
License🟢 10license file detected
Branch-Protection🟢 5branch protection is not maximal on development and all release branches
Signed-Releases⚠️ -1no releases found
Fuzzing⚠️ 0project is not fuzzed
Binary-Artifacts🟢 10no binaries found in the repo
SAST⚠️ 0SAST tool is not run on all commits -- score normalized to 0
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
Vulnerabilities🟢 91 existing vulnerabilities detected
gomod/github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric 0.53.0 🟢 7.6
Details
CheckScoreReason
Code-Review🟢 10all changesets reviewed
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Maintained🟢 55 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 5
Token-Permissions🟢 10GitHub workflow tokens follow principle of least privilege
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Security-Policy🟢 10security policy file detected
Packaging⚠️ -1packaging workflow not detected
Binary-Artifacts🟢 10no binaries found in the repo
Fuzzing⚠️ 0project is not fuzzed
License🟢 10license file detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
Signed-Releases⚠️ -1no releases found
Branch-Protection🟢 8branch protection is not maximal on development and all release branches
Vulnerabilities🟢 82 existing vulnerabilities detected
SAST🟢 10SAST tool is run on all commits
gomod/github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping 0.53.0 🟢 7.6
Details
CheckScoreReason
Code-Review🟢 10all changesets reviewed
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Maintained🟢 55 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 5
Token-Permissions🟢 10GitHub workflow tokens follow principle of least privilege
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Security-Policy🟢 10security policy file detected
Packaging⚠️ -1packaging workflow not detected
Binary-Artifacts🟢 10no binaries found in the repo
Fuzzing⚠️ 0project is not fuzzed
License🟢 10license file detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
Signed-Releases⚠️ -1no releases found
Branch-Protection🟢 8branch protection is not maximal on development and all release branches
Vulnerabilities🟢 82 existing vulnerabilities detected
SAST🟢 10SAST tool is run on all commits
gomod/github.com/aws/aws-sdk-go-v2 1.39.5 🟢 6.9
Details
CheckScoreReason
Code-Review⚠️ 2Found 7/30 approved changesets -- score normalized to 2
Maintained🟢 1030 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Packaging⚠️ -1packaging workflow not detected
License🟢 10license file detected
Signed-Releases⚠️ -1no releases found
Token-Permissions🟢 9detected GitHub workflow tokens with excessive permissions
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: some github tokens can't read classic branch protection rules: https://github.com/ossf/scorecard-action/blob/main/docs/authentication/fine-grained-auth-token.md
Security-Policy🟢 10security policy file detected
Fuzzing⚠️ 0project is not fuzzed
SAST🟢 8SAST tool is not run on all commits -- score normalized to 8
Binary-Artifacts🟢 9binaries present in source code
Vulnerabilities🟢 82 existing vulnerabilities detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
gomod/github.com/aws/aws-sdk-go-v2/config 1.31.16 🟢 6.9
Details
CheckScoreReason
Code-Review⚠️ 2Found 7/30 approved changesets -- score normalized to 2
Maintained🟢 1030 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Packaging⚠️ -1packaging workflow not detected
License🟢 10license file detected
Signed-Releases⚠️ -1no releases found
Token-Permissions🟢 9detected GitHub workflow tokens with excessive permissions
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: some github tokens can't read classic branch protection rules: https://github.com/ossf/scorecard-action/blob/main/docs/authentication/fine-grained-auth-token.md
Security-Policy🟢 10security policy file detected
Fuzzing⚠️ 0project is not fuzzed
SAST🟢 8SAST tool is not run on all commits -- score normalized to 8
Binary-Artifacts🟢 9binaries present in source code
Vulnerabilities🟢 82 existing vulnerabilities detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
gomod/github.com/aws/aws-sdk-go-v2/credentials 1.18.20 🟢 6.9
Details
CheckScoreReason
Code-Review⚠️ 2Found 7/30 approved changesets -- score normalized to 2
Maintained🟢 1030 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Packaging⚠️ -1packaging workflow not detected
License🟢 10license file detected
Signed-Releases⚠️ -1no releases found
Token-Permissions🟢 9detected GitHub workflow tokens with excessive permissions
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: some github tokens can't read classic branch protection rules: https://github.com/ossf/scorecard-action/blob/main/docs/authentication/fine-grained-auth-token.md
Security-Policy🟢 10security policy file detected
Fuzzing⚠️ 0project is not fuzzed
SAST🟢 8SAST tool is not run on all commits -- score normalized to 8
Binary-Artifacts🟢 9binaries present in source code
Vulnerabilities🟢 82 existing vulnerabilities detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
gomod/github.com/aws/aws-sdk-go-v2/feature/ec2/imds 1.18.12 🟢 6.9
Details
CheckScoreReason
Code-Review⚠️ 2Found 7/30 approved changesets -- score normalized to 2
Maintained🟢 1030 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Packaging⚠️ -1packaging workflow not detected
License🟢 10license file detected
Signed-Releases⚠️ -1no releases found
Token-Permissions🟢 9detected GitHub workflow tokens with excessive permissions
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: some github tokens can't read classic branch protection rules: https://github.com/ossf/scorecard-action/blob/main/docs/authentication/fine-grained-auth-token.md
Security-Policy🟢 10security policy file detected
Fuzzing⚠️ 0project is not fuzzed
SAST🟢 8SAST tool is not run on all commits -- score normalized to 8
Binary-Artifacts🟢 9binaries present in source code
Vulnerabilities🟢 82 existing vulnerabilities detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
gomod/github.com/aws/aws-sdk-go-v2/feature/s3/manager 1.20.2 🟢 6.9
Details
CheckScoreReason
Code-Review⚠️ 2Found 7/30 approved changesets -- score normalized to 2
Maintained🟢 1030 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Packaging⚠️ -1packaging workflow not detected
License🟢 10license file detected
Signed-Releases⚠️ -1no releases found
Token-Permissions🟢 9detected GitHub workflow tokens with excessive permissions
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: some github tokens can't read classic branch protection rules: https://github.com/ossf/scorecard-action/blob/main/docs/authentication/fine-grained-auth-token.md
Security-Policy🟢 10security policy file detected
Fuzzing⚠️ 0project is not fuzzed
SAST🟢 8SAST tool is not run on all commits -- score normalized to 8
Binary-Artifacts🟢 9binaries present in source code
Vulnerabilities🟢 82 existing vulnerabilities detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
gomod/github.com/aws/aws-sdk-go-v2/internal/configsources 1.4.12 🟢 6.9
Details
CheckScoreReason
Code-Review⚠️ 2Found 7/30 approved changesets -- score normalized to 2
Maintained🟢 1030 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Packaging⚠️ -1packaging workflow not detected
License🟢 10license file detected
Signed-Releases⚠️ -1no releases found
Token-Permissions🟢 9detected GitHub workflow tokens with excessive permissions
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: some github tokens can't read classic branch protection rules: https://github.com/ossf/scorecard-action/blob/main/docs/authentication/fine-grained-auth-token.md
Security-Policy🟢 10security policy file detected
Fuzzing⚠️ 0project is not fuzzed
SAST🟢 8SAST tool is not run on all commits -- score normalized to 8
Binary-Artifacts🟢 9binaries present in source code
Vulnerabilities🟢 82 existing vulnerabilities detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
gomod/github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 2.7.12 🟢 6.9
Details
CheckScoreReason
Code-Review⚠️ 2Found 7/30 approved changesets -- score normalized to 2
Maintained🟢 1030 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Packaging⚠️ -1packaging workflow not detected
License🟢 10license file detected
Signed-Releases⚠️ -1no releases found
Token-Permissions🟢 9detected GitHub workflow tokens with excessive permissions
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: some github tokens can't read classic branch protection rules: https://github.com/ossf/scorecard-action/blob/main/docs/authentication/fine-grained-auth-token.md
Security-Policy🟢 10security policy file detected
Fuzzing⚠️ 0project is not fuzzed
SAST🟢 8SAST tool is not run on all commits -- score normalized to 8
Binary-Artifacts🟢 9binaries present in source code
Vulnerabilities🟢 82 existing vulnerabilities detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
gomod/github.com/aws/aws-sdk-go-v2/internal/v4a 1.4.12 🟢 6.9
Details
CheckScoreReason
Code-Review⚠️ 2Found 7/30 approved changesets -- score normalized to 2
Maintained🟢 1030 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Packaging⚠️ -1packaging workflow not detected
License🟢 10license file detected
Signed-Releases⚠️ -1no releases found
Token-Permissions🟢 9detected GitHub workflow tokens with excessive permissions
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: some github tokens can't read classic branch protection rules: https://github.com/ossf/scorecard-action/blob/main/docs/authentication/fine-grained-auth-token.md
Security-Policy🟢 10security policy file detected
Fuzzing⚠️ 0project is not fuzzed
SAST🟢 8SAST tool is not run on all commits -- score normalized to 8
Binary-Artifacts🟢 9binaries present in source code
Vulnerabilities🟢 82 existing vulnerabilities detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
gomod/github.com/aws/aws-sdk-go-v2/service/internal/checksum 1.9.3 🟢 6.9
Details
CheckScoreReason
Code-Review⚠️ 2Found 7/30 approved changesets -- score normalized to 2
Maintained🟢 1030 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Packaging⚠️ -1packaging workflow not detected
License🟢 10license file detected
Signed-Releases⚠️ -1no releases found
Token-Permissions🟢 9detected GitHub workflow tokens with excessive permissions
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: some github tokens can't read classic branch protection rules: https://github.com/ossf/scorecard-action/blob/main/docs/authentication/fine-grained-auth-token.md
Security-Policy🟢 10security policy file detected
Fuzzing⚠️ 0project is not fuzzed
SAST🟢 8SAST tool is not run on all commits -- score normalized to 8
Binary-Artifacts🟢 9binaries present in source code
Vulnerabilities🟢 82 existing vulnerabilities detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
gomod/github.com/aws/aws-sdk-go-v2/service/internal/presigned-url 1.13.12 🟢 6.9
Details
CheckScoreReason
Code-Review⚠️ 2Found 7/30 approved changesets -- score normalized to 2
Maintained🟢 1030 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Packaging⚠️ -1packaging workflow not detected
License🟢 10license file detected
Signed-Releases⚠️ -1no releases found
Token-Permissions🟢 9detected GitHub workflow tokens with excessive permissions
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: some github tokens can't read classic branch protection rules: https://github.com/ossf/scorecard-action/blob/main/docs/authentication/fine-grained-auth-token.md
Security-Policy🟢 10security policy file detected
Fuzzing⚠️ 0project is not fuzzed
SAST🟢 8SAST tool is not run on all commits -- score normalized to 8
Binary-Artifacts🟢 9binaries present in source code
Vulnerabilities🟢 82 existing vulnerabilities detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
gomod/github.com/aws/aws-sdk-go-v2/service/internal/s3shared 1.19.12 🟢 6.9
Details
CheckScoreReason
Code-Review⚠️ 2Found 7/30 approved changesets -- score normalized to 2
Maintained🟢 1030 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Packaging⚠️ -1packaging workflow not detected
License🟢 10license file detected
Signed-Releases⚠️ -1no releases found
Token-Permissions🟢 9detected GitHub workflow tokens with excessive permissions
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: some github tokens can't read classic branch protection rules: https://github.com/ossf/scorecard-action/blob/main/docs/authentication/fine-grained-auth-token.md
Security-Policy🟢 10security policy file detected
Fuzzing⚠️ 0project is not fuzzed
SAST🟢 8SAST tool is not run on all commits -- score normalized to 8
Binary-Artifacts🟢 9binaries present in source code
Vulnerabilities🟢 82 existing vulnerabilities detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
gomod/github.com/aws/aws-sdk-go-v2/service/s3 1.89.1 🟢 6.9
Details
CheckScoreReason
Code-Review⚠️ 2Found 7/30 approved changesets -- score normalized to 2
Maintained🟢 1030 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Packaging⚠️ -1packaging workflow not detected
License🟢 10license file detected
Signed-Releases⚠️ -1no releases found
Token-Permissions🟢 9detected GitHub workflow tokens with excessive permissions
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: some github tokens can't read classic branch protection rules: https://github.com/ossf/scorecard-action/blob/main/docs/authentication/fine-grained-auth-token.md
Security-Policy🟢 10security policy file detected
Fuzzing⚠️ 0project is not fuzzed
SAST🟢 8SAST tool is not run on all commits -- score normalized to 8
Binary-Artifacts🟢 9binaries present in source code
Vulnerabilities🟢 82 existing vulnerabilities detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
gomod/github.com/aws/aws-sdk-go-v2/service/ssm 1.66.3 🟢 6.9
Details
CheckScoreReason
Code-Review⚠️ 2Found 7/30 approved changesets -- score normalized to 2
Maintained🟢 1030 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Packaging⚠️ -1packaging workflow not detected
License🟢 10license file detected
Signed-Releases⚠️ -1no releases found
Token-Permissions🟢 9detected GitHub workflow tokens with excessive permissions
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: some github tokens can't read classic branch protection rules: https://github.com/ossf/scorecard-action/blob/main/docs/authentication/fine-grained-auth-token.md
Security-Policy🟢 10security policy file detected
Fuzzing⚠️ 0project is not fuzzed
SAST🟢 8SAST tool is not run on all commits -- score normalized to 8
Binary-Artifacts🟢 9binaries present in source code
Vulnerabilities🟢 82 existing vulnerabilities detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
gomod/github.com/aws/aws-sdk-go-v2/service/sso 1.30.0 🟢 6.9
Details
CheckScoreReason
Code-Review⚠️ 2Found 7/30 approved changesets -- score normalized to 2
Maintained🟢 1030 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Packaging⚠️ -1packaging workflow not detected
License🟢 10license file detected
Signed-Releases⚠️ -1no releases found
Token-Permissions🟢 9detected GitHub workflow tokens with excessive permissions
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: some github tokens can't read classic branch protection rules: https://github.com/ossf/scorecard-action/blob/main/docs/authentication/fine-grained-auth-token.md
Security-Policy🟢 10security policy file detected
Fuzzing⚠️ 0project is not fuzzed
SAST🟢 8SAST tool is not run on all commits -- score normalized to 8
Binary-Artifacts🟢 9binaries present in source code
Vulnerabilities🟢 82 existing vulnerabilities detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
gomod/github.com/aws/aws-sdk-go-v2/service/ssooidc 1.35.4 🟢 6.9
Details
CheckScoreReason
Code-Review⚠️ 2Found 7/30 approved changesets -- score normalized to 2
Maintained🟢 1030 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Packaging⚠️ -1packaging workflow not detected
License🟢 10license file detected
Signed-Releases⚠️ -1no releases found
Token-Permissions🟢 9detected GitHub workflow tokens with excessive permissions
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: some github tokens can't read classic branch protection rules: https://github.com/ossf/scorecard-action/blob/main/docs/authentication/fine-grained-auth-token.md
Security-Policy🟢 10security policy file detected
Fuzzing⚠️ 0project is not fuzzed
SAST🟢 8SAST tool is not run on all commits -- score normalized to 8
Binary-Artifacts🟢 9binaries present in source code
Vulnerabilities🟢 82 existing vulnerabilities detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
gomod/github.com/aws/aws-sdk-go-v2/service/sts 1.39.0 🟢 6.9
Details
CheckScoreReason
Code-Review⚠️ 2Found 7/30 approved changesets -- score normalized to 2
Maintained🟢 1030 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Packaging⚠️ -1packaging workflow not detected
License🟢 10license file detected
Signed-Releases⚠️ -1no releases found
Token-Permissions🟢 9detected GitHub workflow tokens with excessive permissions
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: some github tokens can't read classic branch protection rules: https://github.com/ossf/scorecard-action/blob/main/docs/authentication/fine-grained-auth-token.md
Security-Policy🟢 10security policy file detected
Fuzzing⚠️ 0project is not fuzzed
SAST🟢 8SAST tool is not run on all commits -- score normalized to 8
Binary-Artifacts🟢 9binaries present in source code
Vulnerabilities🟢 82 existing vulnerabilities detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
gomod/github.com/bytecodealliance/wasmtime-go/v37 37.0.0 🟢 5
Details
CheckScoreReason
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Code-Review⚠️ 2Found 6/30 approved changesets -- score normalized to 2
Binary-Artifacts🟢 10no binaries found in the repo
Maintained🟢 109 commit(s) and 3 issue activity found in the last 90 days -- score normalized to 10
Packaging⚠️ -1packaging workflow not detected
Token-Permissions⚠️ 0detected GitHub workflow tokens with excessive permissions
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Security-Policy⚠️ 0security policy file not detected
Fuzzing⚠️ 0project is not fuzzed
Signed-Releases⚠️ -1no releases found
License🟢 10license file detected
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: some github tokens can't read classic branch protection rules: https://github.com/ossf/scorecard-action/blob/main/docs/authentication/fine-grained-auth-token.md
Vulnerabilities🟢 100 existing vulnerabilities detected
SAST⚠️ 0SAST tool is not run on all commits -- score normalized to 0
gomod/github.com/hashicorp/go-getter 1.8.3 🟢 6.9
Details
CheckScoreReason
Code-Review🟢 10all changesets reviewed
Maintained🟢 1022 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Binary-Artifacts🟢 10no binaries found in the repo
Pinned-Dependencies🟢 9dependency not pinned by hash detected -- score normalized to 9
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Token-Permissions⚠️ 0detected GitHub workflow tokens with excessive permissions
Fuzzing⚠️ 0project is not fuzzed
License🟢 10license file detected
Vulnerabilities🟢 100 existing vulnerabilities detected
Packaging🟢 10packaging workflow detected
Signed-Releases🟢 84 out of the last 4 releases have a total of 4 signed artifacts.
Security-Policy🟢 10security policy file detected
Branch-Protection⚠️ 1branch protection is not maximal on development and all release branches
SAST⚠️ 0SAST tool is not run on all commits -- score normalized to 0
gomod/github.com/open-policy-agent/opa 1.10.0 🟢 8.6
Details
CheckScoreReason
Maintained🟢 1030 commit(s) and 21 issue activity found in the last 90 days -- score normalized to 10
Code-Review🟢 9Found 27/28 approved changesets -- score normalized to 9
Dependency-Update-Tool🟢 10update tool detected
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Security-Policy🟢 9security policy file detected
Token-Permissions🟢 10GitHub workflow tokens follow principle of least privilege
Packaging⚠️ -1packaging workflow not detected
Binary-Artifacts🟢 9binaries present in source code
CII-Best-Practices🟢 5badge detected: Passing
Pinned-Dependencies🟢 8dependency not pinned by hash detected -- score normalized to 8
SAST🟢 7SAST tool detected but not run on all commits
Vulnerabilities🟢 100 existing vulnerabilities detected
Signed-Releases⚠️ 0Project has not signed or included provenance with any releases.
Fuzzing🟢 10project is fuzzed
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: some github tokens can't read classic branch protection rules: https://github.com/ossf/scorecard-action/blob/main/docs/authentication/fine-grained-auth-token.md
License🟢 10license file detected
CI-Tests🟢 1028 out of 28 merged PRs checked by a CI test -- score normalized to 10
Contributors🟢 10project has 30 contributing companies or organizations
gomod/golang.org/x/time 0.14.0 UnknownUnknown
gomod/google.golang.org/api 0.254.0 🟢 7.5
Details
CheckScoreReason
Packaging⚠️ -1packaging workflow not detected
Dangerous-Workflow⚠️ -1no workflows found
Maintained🟢 1030 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 10
Code-Review🟢 10all changesets reviewed
Token-Permissions⚠️ -1No tokens found
Security-Policy🟢 10security policy file detected
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
License🟢 10license file detected
Fuzzing⚠️ 0project is not fuzzed
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration
Binary-Artifacts🟢 10no binaries found in the repo
Signed-Releases⚠️ -1no releases found
Vulnerabilities🟢 100 existing vulnerabilities detected
Pinned-Dependencies⚠️ -1no dependencies found
SAST⚠️ 0SAST tool is not run on all commits -- score normalized to 0
gomod/google.golang.org/genproto/googleapis/rpc 0.0.0-20251022142026-3a174f9686a8 🟢 6.6
Details
CheckScoreReason
Code-Review🟢 10all changesets reviewed
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Packaging⚠️ -1packaging workflow not detected
Maintained🟢 1015 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 10
Security-Policy🟢 10security policy file detected
Token-Permissions⚠️ 0detected GitHub workflow tokens with excessive permissions
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
License🟢 10license file detected
Fuzzing⚠️ 0project is not fuzzed
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: some github tokens can't read classic branch protection rules: https://github.com/ossf/scorecard-action/blob/main/docs/authentication/fine-grained-auth-token.md
Signed-Releases⚠️ -1no releases found
Binary-Artifacts🟢 10no binaries found in the repo
Vulnerabilities🟢 91 existing vulnerabilities detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
SAST⚠️ 2SAST tool is not run on all commits -- score normalized to 2

Scanned Files

  • go.mod

## What
This commit adds multiple enhancements to Atmos:
1. Safe argument parsing with proper shell quoting for custom commands
2. Mock AWS provider for testing auth workflows
3. Additional auth improvements and test fixtures

## Why
### Problem 1: Shell Argument Quoting (Critical Security Issue)
Custom commands using `{{ .TrailingArgs }}` would join arguments without proper
shell quoting, causing:
- **Data loss**: Whitespace collapsed (e.g., "hello  world" → "hello world")
- **Security risk**: Command injection via unquoted shell metacharacters
- **User confusion**: Users had to work around the bug with excessive quoting

### Problem 2: Testing Auth Workflows
Integration tests needed a mock provider to avoid requiring real AWS credentials
and browser-based SSO flows.

### Problem 3: Auth Provider Improvements
Various improvements to auth provider handling, identity resolution, and error messages.

## How
### Safe Argument Parsing (cmd/args_separator.go, cmd/flag_utils.go)
- New `ExtractSeparatedArgs()` function handles `--` separator consistently
- Uses `mvdan.cc/sh/v3/syntax.Quote()` for proper bash/POSIX shell quoting
- Replaces fragmented implementations across terraform, helmfile, packer commands
- Comprehensive tests proving whitespace preservation and security

**Key Functions:**
- `ExtractSeparatedArgs()`: Splits args on `--` separator
- `QuoteArgsForShell()`: Applies proper shell quoting to argument list
- `ParseAtmosFlags()`: Extracts Atmos flags before separator

### Mock AWS Provider (pkg/auth/providers/mock/aws/)
- Implements full AWS provider interface for testing
- Generates mock credentials (access key, secret key, session token)
- Supports permission set and assume role identity types
- No network calls, no browser prompts - pure in-process testing

### Test Coverage
- **Integration tests**: `cmd/integration_shell_parsing_test.go` uses real shell parser
- **Unit tests**: Comprehensive coverage of separator extraction across commands
- **Regression tests**: Proves whitespace bug is fixed
- **Security tests**: Validates proper quoting prevents command injection

### Documentation
- **docs/prd/safe-argument-parsing.md**: Complete PRD with problem analysis, solution
- **docs/argument-parsing.md**: User-facing guide on argument handling
- **website/blog/2025-10-31-shell-argument-quoting-fix.mdx**: Blog post for release

## Changes by Area

### Argument Parsing (New)
- `cmd/args_separator.go`: Core separator extraction logic
- `cmd/args_separator_test.go`: Comprehensive tests
- `cmd/flag_utils.go`: Flag parsing utilities
- `cmd/flag_utils_test.go`: Flag parsing tests

### Command Tests (New)
- `cmd/terraform_separator_test.go`: Terraform arg parsing tests
- `cmd/helmfile_separator_test.go`: Helmfile arg parsing tests
- `cmd/packer_separator_test.go`: Packer arg parsing tests
- `cmd/custom_commands_separator_test.go`: Custom command tests
- `cmd/integration_shell_parsing_test.go`: Shell integration tests
- `cmd/custom_commands_whitespace_bug_test.go`: Regression tests

### Mock Provider (New)
- `pkg/auth/providers/mock/aws/provider.go`: Mock AWS provider
- `pkg/auth/providers/mock/aws/identity.go`: Mock identity types
- `pkg/auth/providers/mock/aws/credentials.go`: Mock credential generation

### Auth Improvements (Modified)
- `cmd/auth_env.go`: Enhanced auth env command
- `cmd/cmd_utils.go`: Improved utility functions
- `pkg/auth/factory/factory.go`: Factory improvements
- `pkg/auth/identities/aws/*.go`: AWS identity enhancements
- `pkg/auth/manager.go`: Manager improvements

### Test Fixtures (Modified)
- `tests/fixtures/scenarios/atmos-auth-mock/atmos.yaml`: Mock provider config
- `tests/snapshots/*.golden`: Updated snapshots
- `pkg/auth/providers/mock/identity_test.go`: Enhanced tests

### Documentation (New)
- `docs/prd/safe-argument-parsing.md`: Technical PRD
- `docs/argument-parsing.md`: User documentation
- `website/blog/2025-10-31-shell-argument-quoting-fix.mdx`: Release blog post

## Security Impact
**Before**: Shell metacharacters could cause command injection
**After**: All arguments properly quoted, metacharacters treated as literals

Example:
```bash
# Before (VULNERABLE):
atmos cmd -- echo "foo;rm -rf /"
# Shell saw: echo foo;rm -rf /  (DANGEROUS!)

# After (SAFE):
atmos cmd -- echo "foo;rm -rf /"
# Shell saw: echo 'foo;rm -rf /'  (SAFE - literal string)
```

## Breaking Changes
None. This fix preserves user intent more accurately than before.

## Testing
- ✅ All existing tests pass
- ✅ New integration tests with real shell parser
- ✅ Security tests prevent command injection
- ✅ Mock provider enables auth testing without real credentials

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 31, 2025 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR refactors identity flag handling across auth commands, consolidates argument parsing into unified utilities for safe subprocess execution, implements AWS SSO token caching, and adds comprehensive mock AWS provider support with deterministic testing capabilities.

Changes

Cohort / File(s) Summary
Identity Flag Resolution
cmd/identity_flag.go, cmd/identity_flag_test.go, cmd/auth_login.go, cmd/auth_whoami.go, cmd/auth_env.go
Replaces manual Cobra flag parsing with centralized GetIdentityFromFlags() helper that handles --identity value, --identity=value, and interactive selection via sentinel IdentityFlagSelectValue. Supports both long and short -i forms.
Auth Command Refactoring
cmd/auth_exec.go, cmd/auth_exec_test.go, cmd/auth_shell.go, cmd/auth_shell_test.go
Introduces extractIdentityFlag() and extractAuthShellFlags() to parse flags while respecting -- separator. Updates ExecAuthShellCommand() signature to include providerName parameter for enhanced shell messaging.
Argument Separation Utilities
cmd/args_separator.go, cmd/args_separator_test.go, cmd/flag_utils.go, cmd/flag_utils_test.go, cmd/cmd_utils.go, cmd/cmd_utils_test.go
Implements unified ExtractSeparatedArgs() for safe argument parsing around -- separator with SeparatedCommandArgs struct. Provides shell-quoting via GetAfterSeparatorAsQuotedString(). Removes legacy extractTrailingArgs().
Separator Testing
cmd/custom_commands_separator_test.go, cmd/custom_commands_whitespace_bug_test.go, cmd/helmfile_separator_test.go, cmd/packer_separator_test.go, cmd/terraform_separator_test.go
Validates argument separation across custom commands, helmfile, packer, and terraform with edge cases (whitespace, special chars, quoting). Tests demonstrate whitespace preservation via proper shell quoting.
Terraform Integration
cmd/terraform_utils.go, cmd/terraform_utils_test.go, cmd/terraform_commands.go, cmd/terraform_identity_completion_test.go
Delegates interactive identity selection to new handleInteractiveIdentitySelection(). Updates terraformRun() signature to return error. Adds identity flag completion and tests for identity handling.
Auth Shell Utils & Messaging
internal/exec/shell_utils.go, internal/exec/shell_utils_test.go
Updates ExecAuthShellCommand() and shell messaging functions (printShellEnterMessage, printShellExitMessage) to accept and display providerName alongside identity.
CLI Args Processing
internal/exec/cli_utils.go, internal/exec/cli_utils_identity_test.go
Adds debug logging and enhanced identity flag parsing supporting --identity <value>, --identity=<value>, and --identity (interactive) forms. Includes comprehensive test coverage for identity flag variants across command types.
Auth Manager Refactoring
pkg/auth/manager.go, pkg/auth/manager_test.go
Introduces ensureIdentityHasManager() and setIdentityManager() helpers. Enhances GetDefaultIdentity() with force-select TTY requirement. Updates credential and environment flows to resolve root providers. Adds CI detection via telemetry.
AWS SSO Token Caching
pkg/auth/providers/aws/sso.go, pkg/auth/providers/aws/sso_cache.go, pkg/auth/providers/aws/sso_cache_test.go
Implements XDG-compliant token caching with 5-minute expiration buffer. Adds CacheStorage interface, loadCachedToken(), saveCachedToken(), deleteCachedToken() methods. Non-fatal cache failures with debug logging.
AWS Identity/Provider Updates
pkg/auth/identities/aws/assume_role.go, pkg/auth/identities/aws/permission_set.go, pkg/auth/identities/aws/permission_set_test.go
Adds SetManagerAndProvider() method to identities for injecting auth manager and root provider name. Updates credential/environment retrieval to use injected manager. Improves CredentialsExist() semantics.
Mock AWS Provider Implementation
pkg/auth/providers/mock/aws/provider.go, pkg/auth/providers/mock/aws/identity.go, pkg/auth/providers/mock/aws/credentials.go
Introduces complete mock AWS provider suite with deterministic credentials, fixed 2099 expiration, per-identity file persistence, and lifecycle methods (Authenticate, PostAuthenticate, CredentialsExist, LoadCredentials, Logout).
Auth Factory & Config
pkg/auth/factory/factory.go, pkg/config/const.go, cmd/auth.go
Adds "mock-aws" provider support to factory. Exports IdentityFlagSelectValue constant ("__SELECT__") from config package.
Generic Mock Provider
pkg/auth/providers/mock/identity.go, pkg/auth/providers/mock/identity_test.go
Removes AWS-specific env vars; adds ATMOS_IDENTITY and MOCK_IDENTITY. AWS env vars now only in mock/aws provider.
Interactive Identity Selection
pkg/auth/interactive_test.go, tests/cli_identity_flag_test.go, tests/cli_interactive_test.go
Adds comprehensive tests for TTY detection, CI environment handling (GitHub Actions, GitLab CI, CircleCI, Jenkins, Travis, Buildkite), interactive selection modes, and environment-variable precedence.
Formatter & Testing Utilities
pkg/auth/list/formatter_utils.go, pkg/auth/list/formatter_utils_test.go, tests/test-cases/auth-mock.yaml
Introduces getCurrentTime() for deterministic time via ATMOS_TEST_NOW env var. Updates test snapshots to use deterministic expiration.
Error Definitions
errors/errors.go
Adds ErrIdentitySelectionRequiresTTY and ErrAuthenticationChainNotBuilt error sentinels.
Documentation
docs/argument-parsing.md, docs/prd/safe-argument-parsing.md, docs/prd/container-auth-fixes.md, docs/prd/credential-retrieval-consolidation.md, pkg/auth/docs/identity-flag-behavior.md, website/blog/2025-10-31-shell-argument-quoting-fix.mdx
Comprehensive docs covering safe argument parsing patterns, shell quoting security, container auth fixes (chain truncation bug, SSO token caching), identity flag behavior precedence, and blog post on shell argument quoting.
Test Fixtures & Snapshots
tests/fixtures/scenarios/atmos-auth-mock/atmos.yaml, tests/snapshots/*, tests/cli_terraform_test.go, tests/test-cases/auth-*.yaml
Updates mock provider from "mock" to "mock-aws". Updates terraform clean tests to use --force flag. Updates error snapshots and test expectations.
Test Infrastructure
internal/exec/terraform_affected_test.go
Adds ARM64 skips for gomonkey-dependent tests.
Config & Dependencies
.golangci.yml, go.mod, examples/quick-start-advanced/Dockerfile, scripts/test-geodesic-prebuilt.sh, NOTICE, website/docs/integrations/atlantis.mdx
Adds forbidigo patterns for debug logging. Updates dependency versions (AWS SDK, Google Cloud, OPA, etc.). Adds cache mount for SSO token caching in test scripts. Updates Atmos version to 1.197.0.
Integration Tests
cmd/integration_shell_parsing_test.go
Documents shell parser behavior with unquoted vs. quoted strings and special characters. Validates that proper quoting preserves whitespace.

Sequence Diagram(s)

sequenceDiagram
    participant User as CLI User
    participant AuthCmd as Auth Command
    participant GetIdFunc as GetIdentityFromFlags()
    participant AuthMgr as Auth Manager
    participant Identity as Identity Provider
    participant Shell as Shell

    rect rgb(200, 220, 255)
    Note over User,Shell: Identity Resolution Flow
    User->>AuthCmd: atmos auth exec [--identity [value]] -- cmd
    AuthCmd->>GetIdFunc: GetIdentityFromFlags(cmd, osArgs)
    alt Flag with explicit value
        GetIdFunc-->>AuthCmd: identity_value
    else Flag without value (no TTY or in args)
        GetIdFunc-->>AuthCmd: __SELECT__ (sentinel)
    else Flag absent or env var
        GetIdFunc-->>AuthCmd: env or default
    end
    end

    rect rgb(200, 255, 200)
    Note over AuthCmd,AuthMgr: Authentication Flow
    AuthCmd->>AuthMgr: GetCachedCredentials(identity)
    alt Cached credentials valid
        AuthMgr-->>AuthCmd: credentials
    else No cache or expired
        AuthMgr->>Identity: Authenticate()
        Identity-->>AuthMgr: credentials
        AuthMgr->>Identity: PostAuthenticate(credentials)
    end
    end

    rect rgb(255, 220, 200)
    Note over AuthCmd,Shell: Command Execution
    AuthCmd->>AuthMgr: PrepareShellEnvironment(identity)
    AuthMgr-->>AuthCmd: env_map
    AuthCmd->>Shell: ExecuteCommand(cmd, env_map)
    Shell-->>User: output
    end
Loading
sequenceDiagram
    participant User as User Process
    participant Atmos as Atmos Command
    participant ArgSep as ExtractSeparatedArgs()
    participant Shell as exec.Command

    rect rgb(220, 220, 255)
    Note over User,Shell: Safe Argument Parsing Pattern
    User->>Atmos: atmos terraform plan -- -var foo=bar
    Atmos->>ArgSep: ExtractSeparatedArgs(cmd, args, osArgs)
    ArgSep-->>Atmos: SeparatedCommandArgs{<br/>  BeforeSeparator: [plan],<br/>  AfterSeparator: [-var, foo=bar],<br/>  HasSeparator: true<br/>}
    end

    rect rgb(220, 255, 220)
    Note over Atmos,Shell: Subprocess Execution (Safe)
    Atmos->>Shell: exec.Command("terraform",<br/>"plan", "-var", "foo=bar")
    Shell-->>User: result
    Note over Shell: Arguments preserved<br/>as boundaries (no shell<br/>re-parsing needed)
    end

    rect rgb(255, 220, 220)
    Note over Atmos,Shell: Alternative: Shell Template (Quoted)
    Atmos->>ArgSep: GetAfterSeparatorAsQuotedString()
    ArgSep-->>Atmos: "-var 'foo=bar'"
    Atmos->>Shell: shell.Execute(template,<br/>"plan {{ .QuotedArgs }}")
    Shell-->>User: result
    Note over Shell: Quotes prevent<br/>shell expansion
    end
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Specific areas requiring extra attention:

  • Auth manager refactoring (pkg/auth/manager.go): Dense logic changes to credential chains, identity manager injection, and root provider resolution paths. Requires careful tracing through authentication flow changes and new ensureIdentityHasManager() logic to understand chain preservation semantics.
  • AWS SSO token caching (pkg/auth/providers/aws/sso_cache.go, sso.go): New caching layer with filesystem I/O, expiration validation, and config matching. Verify non-fatal error handling doesn't mask real issues.
  • Argument separation consolidation (cmd/args_separator.go, related test files): Validates safe shell quoting and argument boundary preservation. Review shell quoting logic via mvdan.cc/sh/v3/syntax and test coverage for edge cases (spaces, special chars, injection vectors).
  • Identity flag resolution (cmd/identity_flag.go, internal/exec/cli_utils.go): Multiple parsers and precedence rules across commands. Verify consistency of IdentityFlagSelectValue sentinel handling and TTY detection for interactive paths.
  • AWS identity changes (pkg/auth/identities/aws/permission_set.go, assume_role.go): Modified credential existence semantics, root provider resolution, and PostAuthenticate now storing manager state. Verify file-based credential setup still functions correctly.
  • Shell command signature changes: ExecAuthShellCommand() now requires providerName parameter. Verify all call sites updated and provider name derivation is correct.
  • Test snapshot updates: Verify mock provider behavior changes produce expected outputs and error messages align with new flows.

Possibly related PRs

Suggested reviewers

  • osterman
  • aknysh

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.59% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "fix: Resolve CI regression where terraform fails without TTY for identity selection" directly corresponds to a substantial portion of the changeset, specifically the identity flag handling improvements across cmd/auth_exec.go, cmd/auth_shell.go, cmd/terraform_utils.go, and related modules. The PR objectives confirm this is addressing a real regression where terraform plan failed in CI environments without TTY due to improper identity selection handling. The title is specific, clear, and accurately describes the problem being fixed. While the changeset also includes broader infrastructure work (argument parsing utilities, authentication improvements, mock providers), these serve as enabling changes for this core regression fix.
✨ 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 fix-auth-login-failure

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 coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (1)
cmd/auth_exec.go (1)

108-123: Consider simplifying the environment conversion.

The conversion from env list to map works correctly, but the pattern could be cleaner using a helper function given it may be repeated elsewhere.

Consider extracting this to a helper if used in multiple places:

// Helper to convert environment list to map
func envListToMap(envList []string) map[string]string {
	envMap := make(map[string]string)
	for _, envVar := range envList {
		if idx := strings.IndexByte(envVar, '='); idx >= 0 {
			envMap[envVar[:idx]] = envVar[idx+1:]
		}
	}
	return envMap
}
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • 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 2492e7e and d9aaf36.

📒 Files selected for processing (12)
  • cmd/auth_exec.go (6 hunks)
  • cmd/auth_exec_test.go (2 hunks)
  • cmd/auth_shell.go (4 hunks)
  • cmd/auth_shell_test.go (1 hunks)
  • cmd/cobra_flag_defaults_test.go (1 hunks)
  • cmd/terraform_identity_flag_test.go (1 hunks)
  • cmd/terraform_utils.go (1 hunks)
  • cmd/viper_bindings_test.go (1 hunks)
  • cmd/viper_identity_flag_test.go (1 hunks)
  • internal/exec/shell_utils.go (4 hunks)
  • internal/exec/shell_utils_test.go (1 hunks)
  • pkg/auth/docs/identity-flag-behavior.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
cmd/**/*.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

cmd/**/*.go: Use Cobra's recommended command structure with a root command and subcommands
Implement each CLI command in a separate file under cmd/
Use Viper for managing configuration, environment variables, and flags in the CLI
Keep separation of concerns between CLI interface (cmd) and business logic
Use kebab-case for command-line flags
Provide comprehensive help text for all commands and flags
Include examples in Cobra command help
Use Viper for configuration management; support files, env vars, and flags with precedence flags > env > config > defaults
Follow single responsibility; separate command interface from business logic
Provide meaningful user feedback and include progress indicators for long-running operations
Provide clear error messages to users and troubleshooting hints where appropriate

Files:

  • cmd/auth_exec.go
  • cmd/auth_shell_test.go
  • cmd/viper_identity_flag_test.go
  • cmd/viper_bindings_test.go
  • cmd/auth_exec_test.go
  • cmd/terraform_identity_flag_test.go
  • cmd/cobra_flag_defaults_test.go
  • cmd/auth_shell.go
  • cmd/terraform_utils.go
**/*.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

**/*.go: All code must pass golangci-lint checks
Follow Go error handling idioms and use meaningful error messages
Wrap errors with context using fmt.Errorf("context: %w", err)
Consider custom error types for domain-specific errors
Follow standard Go coding style; run gofmt and goimports
Use snake_case for environment variables
Document complex logic with inline comments

Files:

  • cmd/auth_exec.go
  • cmd/auth_shell_test.go
  • cmd/viper_identity_flag_test.go
  • cmd/viper_bindings_test.go
  • internal/exec/shell_utils.go
  • cmd/auth_exec_test.go
  • cmd/terraform_identity_flag_test.go
  • cmd/cobra_flag_defaults_test.go
  • cmd/auth_shell.go
  • internal/exec/shell_utils_test.go
  • cmd/terraform_utils.go
**/!(*_test).go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

Document all exported functions, types, and methods with Go doc comments

Files:

  • cmd/auth_exec.go
  • internal/exec/shell_utils.go
  • cmd/auth_shell.go
  • cmd/terraform_utils.go
**/*_test.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

**/*_test.go: Every new feature must include comprehensive unit tests
Test both happy paths and error conditions
Use table-driven tests for multiple scenarios

Files:

  • cmd/auth_shell_test.go
  • cmd/viper_identity_flag_test.go
  • cmd/viper_bindings_test.go
  • cmd/auth_exec_test.go
  • cmd/terraform_identity_flag_test.go
  • cmd/cobra_flag_defaults_test.go
  • internal/exec/shell_utils_test.go
🧠 Learnings (40)
📓 Common learnings
Learnt from: osterman
Repo: cloudposse/atmos PR: 1599
File: internal/exec/terraform.go:0-0
Timestamp: 2025-10-11T19:11:58.965Z
Learning: For terraform apply interactivity checks in Atmos (internal/exec/terraform.go), use stdin TTY detection (e.g., `IsTTYSupportForStdin()` or checking `os.Stdin`) to determine if user prompts are possible. This is distinct from stdout/stderr TTY checks used for output display (like TUI rendering). User input requires stdin to be a TTY; output display requires stdout/stderr to be a TTY.
Learnt from: Benbentwo
Repo: cloudposse/atmos PR: 1452
File: cmd/auth_login.go:43-44
Timestamp: 2025-09-07T18:07:00.549Z
Learning: In the atmos project, the identity flag is defined as a persistent flag on the auth root command (cmd/auth.go), making it available to all auth subcommands without needing to be redefined in each individual subcommand.
Learnt from: osterman
Repo: cloudposse/atmos PR: 1599
File: internal/exec/terraform.go:394-402
Timestamp: 2025-10-10T23:51:36.597Z
Learning: In Atmos (internal/exec/terraform.go), when adding OpenTofu-specific flags like `--var-file` for `init`, do not gate them based on command name (e.g., checking if `info.Command == "tofu"` or `info.Command == "opentofu"`) because command names don't reliably indicate the actual binary being executed (symlinks, aliases). Instead, document the OpenTofu requirement in code comments and documentation, trusting users who enable the feature (e.g., `PassVars`) to ensure their terraform command points to an OpenTofu binary.
Learnt from: pkbhowmick
Repo: cloudposse/atmos PR: 786
File: internal/exec/shell_utils.go:159-162
Timestamp: 2024-11-16T17:30:52.893Z
Learning: For the `atmos terraform shell` command in `internal/exec/shell_utils.go`, input validation for the custom shell prompt is not required, as users will use this as a CLI tool and any issues will impact themselves.
Learnt from: aknysh
Repo: cloudposse/atmos PR: 944
File: go.mod:206-206
Timestamp: 2025-01-17T00:18:57.769Z
Learning: For indirect dependencies with license compliance issues in the cloudposse/atmos repository, the team prefers to handle them in follow-up PRs rather than blocking the current changes, as these issues often require deeper investigation of the dependency tree.
Learnt from: Listener430
Repo: cloudposse/atmos PR: 934
File: tests/fixtures/scenarios/docs-generate/README.md.gotmpl:99-118
Timestamp: 2025-01-25T03:51:57.689Z
Learning: For the cloudposse/atmos repository, changes to template contents should be handled in dedicated PRs and are typically considered out of scope for PRs focused on other objectives.
Learnt from: osterman
Repo: cloudposse/atmos PR: 1498
File: website/src/components/Screengrabs/atmos-terraform-metadata--help.html:25-55
Timestamp: 2025-10-07T00:25:16.333Z
Learning: In Atmos CLI, subcommands inherit flags from their parent commands via Cobra's command inheritance. For example, `atmos terraform metadata --help` shows `--affected` and related flags inherited from the parent `terraform` command (defined in cmd/terraform.go), even though the metadata subcommand doesn't explicitly define these flags. This is expected Cobra behavior and auto-generated help screengrabs accurately reflect this inheritance.
Learnt from: Listener430
Repo: cloudposse/atmos PR: 1149
File: internal/exec/go_getter_utils.go:263-264
Timestamp: 2025-03-25T12:24:36.177Z
Learning: Tests for the default Bitbucket username fallback to "x-token-auth" will be added during a future refactoring phase rather than in this PR.
📚 Learning: 2025-09-07T18:07:00.549Z
Learnt from: Benbentwo
Repo: cloudposse/atmos PR: 1452
File: cmd/auth_login.go:43-44
Timestamp: 2025-09-07T18:07:00.549Z
Learning: In the atmos project, the identity flag is defined as a persistent flag on the auth root command (cmd/auth.go), making it available to all auth subcommands without needing to be redefined in each individual subcommand.

Applied to files:

  • cmd/auth_exec.go
  • cmd/auth_shell_test.go
  • cmd/viper_identity_flag_test.go
  • cmd/auth_exec_test.go
  • pkg/auth/docs/identity-flag-behavior.md
  • cmd/terraform_identity_flag_test.go
  • cmd/auth_shell.go
  • cmd/terraform_utils.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to cmd/**/*.go : Use Viper for managing configuration, environment variables, and flags in the CLI

Applied to files:

  • cmd/auth_exec.go
  • cmd/viper_identity_flag_test.go
  • cmd/viper_bindings_test.go
  • cmd/terraform_identity_flag_test.go
  • cmd/cobra_flag_defaults_test.go
  • cmd/auth_shell.go
  • cmd/terraform_utils.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to cmd/**/*.go : Use Cobra's recommended command structure with a root command and subcommands

Applied to files:

  • cmd/auth_exec.go
  • cmd/auth_shell_test.go
  • cmd/viper_bindings_test.go
  • cmd/cobra_flag_defaults_test.go
  • cmd/terraform_utils.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to cmd/**/*.go : Use kebab-case for command-line flags

Applied to files:

  • cmd/auth_exec.go
  • cmd/auth_shell_test.go
  • cmd/viper_identity_flag_test.go
  • cmd/auth_exec_test.go
  • cmd/cobra_flag_defaults_test.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to cmd/**/*.go : Use Viper for configuration management; support files, env vars, and flags with precedence flags > env > config > defaults

Applied to files:

  • cmd/auth_exec.go
  • cmd/viper_identity_flag_test.go
  • cmd/viper_bindings_test.go
  • cmd/terraform_identity_flag_test.go
  • cmd/cobra_flag_defaults_test.go
  • cmd/auth_shell.go
  • cmd/terraform_utils.go
📚 Learning: 2025-01-09T22:37:01.004Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 914
File: cmd/terraform_commands.go:260-265
Timestamp: 2025-01-09T22:37:01.004Z
Learning: In the terraform commands implementation (cmd/terraform_commands.go), the direct use of `os.Args[2:]` for argument handling is intentionally preserved to avoid extensive refactoring. While it could be improved to use cobra's argument parsing, such changes should be handled in a dedicated PR to maintain focus and minimize risk.

Applied to files:

  • cmd/auth_exec.go
  • cmd/terraform_identity_flag_test.go
  • cmd/auth_shell.go
  • cmd/terraform_utils.go
📚 Learning: 2025-10-10T23:51:36.597Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1599
File: internal/exec/terraform.go:394-402
Timestamp: 2025-10-10T23:51:36.597Z
Learning: In Atmos (internal/exec/terraform.go), when adding OpenTofu-specific flags like `--var-file` for `init`, do not gate them based on command name (e.g., checking if `info.Command == "tofu"` or `info.Command == "opentofu"`) because command names don't reliably indicate the actual binary being executed (symlinks, aliases). Instead, document the OpenTofu requirement in code comments and documentation, trusting users who enable the feature (e.g., `PassVars`) to ensure their terraform command points to an OpenTofu binary.

Applied to files:

  • cmd/auth_exec.go
  • cmd/auth_shell_test.go
  • cmd/viper_identity_flag_test.go
  • internal/exec/shell_utils.go
  • cmd/auth_exec_test.go
  • pkg/auth/docs/identity-flag-behavior.md
  • cmd/terraform_identity_flag_test.go
  • cmd/auth_shell.go
  • cmd/terraform_utils.go
📚 Learning: 2025-10-07T00:25:16.333Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1498
File: website/src/components/Screengrabs/atmos-terraform-metadata--help.html:25-55
Timestamp: 2025-10-07T00:25:16.333Z
Learning: In Atmos CLI, subcommands inherit flags from their parent commands via Cobra's command inheritance. For example, `atmos terraform metadata --help` shows `--affected` and related flags inherited from the parent `terraform` command (defined in cmd/terraform.go), even though the metadata subcommand doesn't explicitly define these flags. This is expected Cobra behavior and auto-generated help screengrabs accurately reflect this inheritance.

Applied to files:

  • cmd/auth_exec.go
  • cmd/auth_shell_test.go
  • pkg/auth/docs/identity-flag-behavior.md
  • cmd/terraform_identity_flag_test.go
  • cmd/auth_shell.go
  • cmd/terraform_utils.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to cmd/**/*.go : Provide comprehensive help text for all commands and flags

Applied to files:

  • cmd/auth_exec.go
  • cmd/viper_identity_flag_test.go
  • cmd/viper_bindings_test.go
  • cmd/auth_exec_test.go
  • cmd/terraform_identity_flag_test.go
  • cmd/cobra_flag_defaults_test.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to cmd/**/*.go : Include examples in Cobra command help

Applied to files:

  • cmd/auth_exec.go
  • cmd/viper_bindings_test.go
  • cmd/cobra_flag_defaults_test.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to cmd/**/*.go : Provide clear error messages to users and troubleshooting hints where appropriate

Applied to files:

  • cmd/auth_exec.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to cmd/**/*.go : Keep separation of concerns between CLI interface (cmd) and business logic

Applied to files:

  • cmd/auth_exec.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to cmd/**/*.go : Follow single responsibility; separate command interface from business logic

Applied to files:

  • cmd/auth_exec.go
📚 Learning: 2025-02-18T13:18:53.146Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1068
File: cmd/vendor_pull.go:31-31
Timestamp: 2025-02-18T13:18:53.146Z
Learning: Error checking is not required for cobra.Command.RegisterFlagCompletionFunc calls as these are static configurations done at init time.

Applied to files:

  • cmd/auth_shell_test.go
  • cmd/cobra_flag_defaults_test.go
📚 Learning: 2024-11-16T17:30:52.893Z
Learnt from: pkbhowmick
Repo: cloudposse/atmos PR: 786
File: internal/exec/shell_utils.go:159-162
Timestamp: 2024-11-16T17:30:52.893Z
Learning: For the `atmos terraform shell` command in `internal/exec/shell_utils.go`, input validation for the custom shell prompt is not required, as users will use this as a CLI tool and any issues will impact themselves.

Applied to files:

  • cmd/auth_shell_test.go
  • cmd/viper_identity_flag_test.go
  • internal/exec/shell_utils.go
  • cmd/auth_shell.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to **/*_test.go : Every new feature must include comprehensive unit tests

Applied to files:

  • cmd/viper_identity_flag_test.go
  • cmd/viper_bindings_test.go
  • cmd/terraform_identity_flag_test.go
  • cmd/cobra_flag_defaults_test.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to **/*_test.go : Use table-driven tests for multiple scenarios

Applied to files:

  • cmd/viper_identity_flag_test.go
📚 Learning: 2025-06-23T02:14:30.937Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1327
File: cmd/terraform.go:111-117
Timestamp: 2025-06-23T02:14:30.937Z
Learning: In cmd/terraform.go, flags for the DescribeAffected function are added dynamically at runtime when info.Affected is true. This is intentional to avoid exposing internal flags like "file", "format", "verbose", "include-spacelift-admin-stacks", "include-settings", and "upload" in the terraform command interface, while still providing them for the shared DescribeAffected function used by both `atmos describe affected` and `atmos terraform apply --affected`.

Applied to files:

  • cmd/viper_identity_flag_test.go
  • cmd/terraform_identity_flag_test.go
  • cmd/auth_shell.go
  • cmd/terraform_utils.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to **/*_test.go : Test both happy paths and error conditions

Applied to files:

  • cmd/viper_identity_flag_test.go
  • cmd/viper_bindings_test.go
  • cmd/auth_exec_test.go
  • cmd/terraform_identity_flag_test.go
📚 Learning: 2025-10-11T19:11:58.965Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1599
File: internal/exec/terraform.go:0-0
Timestamp: 2025-10-11T19:11:58.965Z
Learning: For terraform apply interactivity checks in Atmos (internal/exec/terraform.go), use stdin TTY detection (e.g., `IsTTYSupportForStdin()` or checking `os.Stdin`) to determine if user prompts are possible. This is distinct from stdout/stderr TTY checks used for output display (like TUI rendering). User input requires stdin to be a TTY; output display requires stdout/stderr to be a TTY.

Applied to files:

  • cmd/viper_identity_flag_test.go
  • cmd/terraform_identity_flag_test.go
  • cmd/terraform_utils.go
📚 Learning: 2025-10-03T18:02:08.535Z
Learnt from: Benbentwo
Repo: cloudposse/atmos PR: 1475
File: internal/exec/terraform.go:269-272
Timestamp: 2025-10-03T18:02:08.535Z
Learning: In internal/exec/terraform.go, when auth.TerraformPreHook fails, the error is logged but execution continues. This is a deliberate design choice to allow Terraform commands to proceed even if authentication setup fails, rather than failing fast.

Applied to files:

  • cmd/viper_identity_flag_test.go
  • cmd/terraform_utils.go
📚 Learning: 2025-08-15T14:43:41.030Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1352
File: pkg/store/artifactory_store_test.go:108-113
Timestamp: 2025-08-15T14:43:41.030Z
Learning: In test files for the atmos project, it's acceptable to ignore errors from os.Setenv/Unsetenv operations during test environment setup and teardown, as these are controlled test scenarios.

Applied to files:

  • cmd/viper_identity_flag_test.go
📚 Learning: 2025-09-29T15:47:10.908Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1540
File: internal/exec/terraform_cli_args_utils.go:64-73
Timestamp: 2025-09-29T15:47:10.908Z
Learning: In the Atmos codebase, viper.BindEnv is required for CLI commands in the cmd/ package, but internal utilities can use os.Getenv directly when parsing environment variables for business logic purposes. The requirement to use viper is specific to the CLI interface layer, not all environment variable access throughout the codebase.

Applied to files:

  • cmd/viper_bindings_test.go
  • cmd/terraform_identity_flag_test.go
  • cmd/cobra_flag_defaults_test.go
  • cmd/terraform_utils.go
📚 Learning: 2025-04-23T15:02:50.246Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1202
File: pkg/utils/yaml_func_exec.go:104-104
Timestamp: 2025-04-23T15:02:50.246Z
Learning: In the Atmos codebase, direct calls to `os.Getenv` should be avoided. Instead, use `viper.BindEnv` for environment variable access. This provides a consistent approach to configuration management across the codebase.

Applied to files:

  • cmd/viper_bindings_test.go
  • cmd/terraform_identity_flag_test.go
  • cmd/cobra_flag_defaults_test.go
  • cmd/terraform_utils.go
📚 Learning: 2025-08-29T20:57:35.423Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1433
File: cmd/theme_list.go:33-36
Timestamp: 2025-08-29T20:57:35.423Z
Learning: In the Atmos codebase, avoid using viper.SetEnvPrefix("ATMOS") with viper.AutomaticEnv() because canonical environment variable names are not exclusive to Atmos and could cause conflicts. Instead, use selective environment variable binding through the setEnv function in pkg/config/load.go with bindEnv(v, "config.key", "ENV_VAR_NAME") for specific environment variables.

Applied to files:

  • cmd/viper_bindings_test.go
  • cmd/terraform_identity_flag_test.go
  • cmd/cobra_flag_defaults_test.go
  • cmd/terraform_utils.go
📚 Learning: 2025-04-10T20:48:22.687Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1147
File: pkg/config/load.go:0-0
Timestamp: 2025-04-10T20:48:22.687Z
Learning: In the `bindEnv` function in `pkg/config/load.go`, panic is used deliberately instead of returning errors because errors from `BindEnv` would only occur due to developer mistakes. Using panic helps with early detection of these developer errors during initialization.

Applied to files:

  • cmd/viper_bindings_test.go
📚 Learning: 2024-12-07T16:16:13.038Z
Learnt from: Listener430
Repo: cloudposse/atmos PR: 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/shell_utils.go
  • cmd/auth_shell.go
  • cmd/terraform_utils.go
📚 Learning: 2025-09-13T18:06:07.674Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1466
File: toolchain/list.go:39-42
Timestamp: 2025-09-13T18:06:07.674Z
Learning: In the cloudposse/atmos repository, for UI messages in the toolchain package, use utils.PrintfMessageToTUI instead of log.Error or fmt.Fprintln(os.Stderr, ...). Import pkg/utils with alias "u" to follow the established pattern.

Applied to files:

  • internal/exec/shell_utils.go
📚 Learning: 2025-09-05T14:57:37.360Z
Learnt from: RoseSecurity
Repo: cloudposse/atmos PR: 1448
File: cmd/ansible.go:26-28
Timestamp: 2025-09-05T14:57:37.360Z
Learning: The Atmos codebase uses a consistent pattern for commands that delegate to external tools: `PersistentFlags().Bool("", false, doubleDashHint)` where doubleDashHint provides help text about using double dashes to separate Atmos options from native command arguments. This pattern is used across terraform, packer, helmfile, atlantis, aws, and ansible commands.

Applied to files:

  • pkg/auth/docs/identity-flag-behavior.md
  • cmd/auth_shell.go
  • cmd/terraform_utils.go
📚 Learning: 2024-12-07T16:19:01.683Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 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:

  • cmd/terraform_identity_flag_test.go
  • cmd/terraform_utils.go
📚 Learning: 2025-02-19T05:50:35.853Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1068
File: tests/snapshots/TestCLICommands_atmos_terraform_apply_--help.stdout.golden:0-0
Timestamp: 2025-02-19T05:50:35.853Z
Learning: Backtick formatting should only be applied to flag descriptions in Go source files, not in golden test files (test snapshots) as they are meant to capture the raw command output.

Applied to files:

  • cmd/terraform_identity_flag_test.go
📚 Learning: 2024-10-31T19:25:41.298Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 727
File: internal/exec/terraform_clean.go:233-235
Timestamp: 2024-10-31T19:25:41.298Z
Learning: When specifying color values in functions like `confirmDeleteTerraformLocal` in `internal/exec/terraform_clean.go`, avoid hardcoding color values. Instead, use predefined color constants or allow customization through configuration settings to improve accessibility and user experience across different terminals and themes.

Applied to files:

  • cmd/terraform_identity_flag_test.go
  • cmd/terraform_utils.go
📚 Learning: 2025-01-30T19:30:59.120Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 959
File: cmd/workflow.go:74-74
Timestamp: 2025-01-30T19:30:59.120Z
Learning: Error handling for `cmd.Usage()` is not required in the Atmos CLI codebase, as confirmed by the maintainer.

Applied to files:

  • cmd/auth_shell.go
📚 Learning: 2024-10-23T21:36:40.262Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 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:

  • cmd/auth_shell.go
  • cmd/terraform_utils.go
📚 Learning: 2024-12-05T22:33:54.807Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 820
File: cmd/list_stacks.go:55-56
Timestamp: 2024-12-05T22:33:54.807Z
Learning: In the atmos project, the `u.LogErrorAndExit` function logs the error and exits the command execution appropriately within flag completion functions.

Applied to files:

  • cmd/auth_shell.go
📚 Learning: 2025-08-16T23:32:40.412Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1405
File: internal/exec/describe_dependents_test.go:455-456
Timestamp: 2025-08-16T23:32:40.412Z
Learning: In the cloudposse/atmos Go codebase, `InitCliConfig` returns a `schema.AtmosConfiguration` value (not a pointer), while `ExecuteDescribeDependents` expects a `*schema.AtmosConfiguration` pointer parameter. Therefore, when passing the result of `InitCliConfig` to `ExecuteDescribeDependents`, use `&atmosConfig` to pass the address of the value.

Applied to files:

  • cmd/auth_shell.go
📚 Learning: 2024-12-11T18:40:12.808Z
Learnt from: Listener430
Repo: cloudposse/atmos PR: 844
File: cmd/helmfile.go:37-37
Timestamp: 2024-12-11T18:40:12.808Z
Learning: In the atmos project, `cliConfig` is initialized within the `cmd` package in `root.go` and can be used in other command files.

Applied to files:

  • cmd/terraform_utils.go
📚 Learning: 2025-09-23T04:43:31.857Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1430
File: pkg/config/config.go:98-107
Timestamp: 2025-09-23T04:43:31.857Z
Learning: In the Atmos codebase, NO_PAGER environment variable handling is intentionally kept as direct os.Getenv() access in pkg/config/config.go rather than using Viper binding, because adding no_pager to the config file would be confusing for users. This is an acknowledged exception to the normal Viper binding pattern for environment variables.

Applied to files:

  • cmd/terraform_utils.go
📚 Learning: 2025-01-18T15:15:41.645Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 914
File: cmd/terraform.go:37-46
Timestamp: 2025-01-18T15:15:41.645Z
Learning: In the atmos CLI, error handling is intentionally structured to use LogErrorAndExit for consistent error display, avoiding Cobra's default error handling to prevent duplicate error messages.

Applied to files:

  • cmd/terraform_utils.go
🧬 Code graph analysis (10)
cmd/auth_exec.go (1)
cmd/auth.go (1)
  • IdentityFlagSelectValue (12-12)
cmd/auth_shell_test.go (1)
cmd/auth.go (1)
  • IdentityFlagSelectValue (12-12)
cmd/viper_identity_flag_test.go (2)
cmd/testkit_test.go (1)
  • NewTestKit (55-65)
cmd/auth.go (2)
  • IdentityFlagName (11-11)
  • IdentityFlagSelectValue (12-12)
cmd/viper_bindings_test.go (1)
cmd/testkit_test.go (1)
  • NewTestKit (55-65)
internal/exec/shell_utils.go (1)
pkg/ui/theme/colors.go (3)
  • ColorGreen (11-11)
  • ColorCyan (12-12)
  • ColorGray (10-10)
cmd/auth_exec_test.go (1)
cmd/auth.go (1)
  • IdentityFlagSelectValue (12-12)
cmd/terraform_identity_flag_test.go (2)
cmd/testkit_test.go (1)
  • NewTestKit (55-65)
cmd/auth.go (2)
  • IdentityFlagSelectValue (12-12)
  • IdentityFlagName (11-11)
cmd/auth_shell.go (2)
internal/exec/shell_utils.go (1)
  • ExecAuthShellCommand (310-361)
cmd/auth.go (1)
  • IdentityFlagSelectValue (12-12)
internal/exec/shell_utils_test.go (1)
internal/exec/shell_utils.go (1)
  • ExecAuthShellCommand (310-361)
cmd/terraform_utils.go (6)
cmd/auth.go (2)
  • IdentityFlagName (11-11)
  • IdentityFlagSelectValue (12-12)
errors/error_funcs.go (1)
  • CheckErrorPrintAndExit (75-98)
internal/tui/templates/term/term_writer.go (2)
  • IsTTYSupportForStdin (133-135)
  • IsTTYSupportForStdout (121-123)
pkg/logger/log.go (2)
  • Errorf (59-61)
  • Debug (24-26)
errors/errors.go (3)
  • ErrDefaultIdentity (382-382)
  • ErrInitializeCLIConfig (341-341)
  • ErrFailedToInitializeAuthManager (391-391)
pkg/config/config.go (1)
  • InitCliConfig (25-62)
🪛 LanguageTool
pkg/auth/docs/identity-flag-behavior.md

[typographical] ~11-~11: Consider using a typographic opening quote here.
Context: ... fail in CI environments with the error "interactive identity selection requires ...

(EN_QUOTES)


[typographical] ~11-~11: Consider using a typographic close quote here.
Context: ...active identity selection requires a TTY" even when: - No authentication was conf...

(EN_QUOTES)


[grammar] ~18-~18: Please add a punctuation mark at the end of paragraph.
Context: ..., getting polluted values from previous commands ### Success Criteria - ✅ Default iden...

(PUNCTUATION_PARAGRAPH_END)


[typographical] ~50-~50: Consider using a typographic opening quote here.
Context: ...no default identity: error with message "Use the identity flag or specify an iden...

(EN_QUOTES)


[grammar] ~50-~50: Please add a punctuation mark at the end of paragraph.
Context: ...y flag or specify an identity as default" Key Point: Default identity authen...

(PUNCTUATION_PARAGRAPH_END)


[typographical] ~75-~75: Consider using a typographic opening quote here.
Context: ...y selector - No TTY (CI): Error: "interactive identity selection requires ...

(EN_QUOTES)


[typographical] ~76-~76: Consider using a typographic opening quote here.
Context: ...available + no identities:** Debug log: "Identity selection skipped: no authentic...

(EN_QUOTES)


[typographical] ~76-~76: Consider using a typographic close quote here.
Context: ...on skipped: no authentication configured" Key Point: Interactive selection i...

(EN_QUOTES)


[typographical] ~100-~100: Consider using a typographic opening quote here.
Context: ...doesn't exist: Error from auth manager: "identity not found: prod-admin" **Key P...

(EN_QUOTES)


[typographical] ~100-~100: Consider using a typographic close quote here.
Context: ...manager: "identity not found: prod-admin" Key Point: Explicit identity overr...

(EN_QUOTES)


[grammar] ~212-~212: Please add a punctuation mark at the end of paragraph.
Context: ...nged()andflags.GetString()- NEVER viaviper.GetString()` Code Changes: ...

(PUNCTUATION_PARAGRAPH_END)


[grammar] ~254-~254: Please add a punctuation mark at the end of paragraph.
Context: ... - ✅ No viper pollution between command executions ### FR-005: Error Messages Clear, act...

(PUNCTUATION_PARAGRAPH_END)


[typographical] ~265-~265: Consider using a typographic opening quote here.
Context: ...fault.| 1 | | Authentication failed |failed to authenticate with identity "": ` | 1 | **Acceptance C...

(EN_QUOTES)


[grammar] ~277-~277: Ensure spelling is correct
Context: ...ormance - Identity flag parsing adds < 1ms overhead - No performance impact when f...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)


[grammar] ~277-~277: Ensure spelling is correct
Context: ...dentity flag parsing adds < 1ms overhead - No performance impact when flag not prov...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)


[grammar] ~326-~326: Please add a punctuation mark at the end of paragraph.
Context: ...Add comment explaining inheritance from parent 3. cmd/auth_exec.go (init function...

(PUNCTUATION_PARAGRAPH_END)


[grammar] ~335-~335: Please add a punctuation mark at the end of paragraph.
Context: ...dEnv()` (not BindPFlag) - No changes needed ### Test Files Created 1. **cmd/viper...

(PUNCTUATION_PARAGRAPH_END)


[grammar] ~363-~363: Please add a punctuation mark at the end of paragraph.
Context: ...er.BindPFlag()for identity flag, only useviper.BindEnv() **Rationale:** -Bi...

(PUNCTUATION_PARAGRAPH_END)


[style] ~369-~369: Consider replacing ‘only’ with a different word to let your writing stand out.
Context: ...), flags.GetString()`) - Viper should only be used for environment variable resolu...

(ONLY_EXCLUSIVELY_STYLE)


[grammar] ~369-~369: Please add a punctuation mark at the end of paragraph.
Context: ...d only be used for environment variable resolution ### Decision 3: Flag Inheritance **De...

(PUNCTUATION_PARAGRAPH_END)

⏰ 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). (9)
  • GitHub Check: Build (linux)
  • GitHub Check: Build (macos)
  • GitHub Check: Build (windows)
  • GitHub Check: Lint (golangci)
  • GitHub Check: Analyze (go)
  • GitHub Check: Run pre-commit hooks
  • GitHub Check: Review Dependency Licenses
  • GitHub Check: autofix
  • GitHub Check: Summary
🔇 Additional comments (32)
internal/exec/shell_utils_test.go (1)

464-464: LGTM!

The function call correctly updated to include the new providerName parameter matching the updated signature in shell_utils.go:309.

cmd/auth_shell_test.go (2)

89-94: LGTM! Validates inherited flag behavior correctly.

The test properly verifies that the identity flag is inherited from the parent authCmd using Flag() (which searches up the command hierarchy) rather than Flags().Lookup() (which only checks local flags). The addition of the NoOptDefVal assertion confirms the sentinel value is correctly configured for interactive selection.


96-96: Clear documentation of flag scoping.

The comment clarifies that the shell flag is a local flag (not inherited), providing useful context for readers understanding the test structure.

pkg/auth/docs/identity-flag-behavior.md (1)

1-400: Excellent comprehensive documentation.

This document thoroughly explains the identity flag behavior, the regression root cause, and the solution. The structure is clear with:

  • Executive summary and problem statement
  • Three distinct operating modes with examples
  • Precedence order and authentication flows
  • Implementation details and decision rationale
  • Test coverage matrix

The documentation will be invaluable for maintainers understanding this critical fix.

cmd/auth_exec.go (4)

66-78: Identity resolution logic is clear and correct.

The fallback logic is well-structured:

  1. Use explicit identityValue if provided
  2. Otherwise fall back to viper (config/env)
  3. Empty string means no identity provided

This avoids the viper pollution issue by prioritizing the explicit flag value.


174-240: extractIdentityFlag logic appears sound.

The function correctly handles:

  • --identity=value format
  • --identity value format
  • --identity without value (sentinel)
  • -- end-of-flags marker
  • -i shorthand

The logic for determining when to use IdentityFlagSelectValue is correct:

  • Set when --identity provided without a value
  • Set when --identity -- encountered

243-246: Clear documentation of flag inheritance pattern.

The comments correctly explain that the identity flag is inherited from the parent authCmd and shouldn't be redefined. This prevents the duplicate flag issue that contributed to the viper pollution problem.

Based on learnings


45-47: Implementation correctly handles all edge cases.

The extractIdentityFlag function properly addresses the scenarios mentioned in the review comment:

  • --identity=value: Extracted with fallback to IdentityFlagSelectValue if empty
  • --identity value: Consumed next arg if available and doesn't start with - or equal --
  • --identity --: Detects -- at position i+1, skips consuming it, applies IdentityFlagSelectValue, and treats -- as end-of-flags marker
  • --identity value --: Properly chains flag consumption with -- handling

The implementation also includes robust safeguards: state tracking with identityFlagSeen, a skipNext flag to prevent double-processing, and a final check to apply the select value if needed. Edge cases like unrecognized flags and args following -- are correctly handled.

cmd/viper_bindings_test.go (2)

12-95: Excellent reproduction of the viper pollution bug.

This test definitively proves the root cause by simulating two sequential commands:

  1. auth shell --identity sets viper to __SELECT__ via BindPFlag
  2. terraform plan (no flag) still sees __SELECT__ in viper

The test clearly demonstrates that viper pollution persists across commands and would cause the TTY error in CI. The logging statements make the issue very clear.


97-146: Clear comparison of BindPFlag vs BindEnv.

The two subtests effectively demonstrate:

  • BindPFlag creates two-way binding (flag → viper), causing pollution
  • BindEnv only binds env vars, no flag synchronization

This validates that the fix (using only BindEnv) prevents the pollution issue.

cmd/cobra_flag_defaults_test.go (2)

12-130: Comprehensive NoOptDefVal testing.

The table-driven test covers all critical scenarios:

  • Flag not provided with various viper configurations
  • Flag without value triggering NoOptDefVal
  • BindPFlag two-way binding behavior
  • BindEnv one-way binding behavior

The test descriptions clearly explain what each scenario validates. The assertions are thorough, checking flag value, viper value, and flags.Changed() state.


132-173: Additional validation of BindPFlag pollution.

This test provides additional evidence that BindPFlag doesn't cause pollution when the flag is not provided. It validates the normal case where viper should return empty when no env vars are set and no flag is provided.

cmd/terraform_utils.go (5)

75-82: Critical fix: Only process flag when explicitly provided.

The flags.Changed() check is the key fix that prevents reading polluted viper values. The comments correctly explain that ProcessCommandLineArgs already handles env vars and args, so this block only needs to handle the special case of interactive selection.


84-95: Proper TTY guard prevents CI failures.

The TTY check correctly validates both stdin (for input) and stdout (for TUI rendering) before attempting interactive selection. This prevents the regression where CI would fail with "requires a TTY" error.

Based on learnings


97-102: Config initialization with processStacks=false is appropriate.

Passing false for processStacks avoids unnecessary stack processing since only the auth configuration is needed for identity selection. This improves performance and reduces potential errors.


105-122: Graceful handling when no auth configured.

The check for empty providers and identities prevents errors when authentication isn't configured. The debug log provides visibility without failing the command. This is correct behavior since users may run terraform commands without authentication in some environments.


124-128: Explicit flag value correctly overrides defaults.

When the flag has an explicit value (not the sentinel), it's directly assigned to info.Identity. This ensures explicit flags take precedence over environment variables and config defaults, matching the documented precedence order.

cmd/viper_identity_flag_test.go (3)

10-97: Thorough CI regression scenario testing.

The table-driven test covers multiple ways viper could return __SELECT__:

  1. Clean CI (should be empty)
  2. IDENTITY env var set to __SELECT__
  3. ATMOS_IDENTITY env var set to __SELECT__
  4. Viper state pollution from previous command

Each scenario is well-documented with descriptions explaining why it would or wouldn't trigger the bug. The test effectively demonstrates that viper pollution is a real issue that needed to be addressed.


99-137: Investigates potential pollution sources.

These tests explore additional ways viper could get polluted:

  • Config file containing identity: __SELECT__
  • NoOptDefVal leaking through command execution

While somewhat exploratory, these tests provide additional validation that the fix handles edge cases correctly.


139-182: Clear reproduction of the exact bug path.

This test traces through the original buggy code logic step by step, showing exactly how viper returning __SELECT__ would trigger the TTY check in CI. The inline comments referencing specific line numbers make it easy to understand the bug flow.

The test effectively demonstrates that the fix (using flags.Changed() instead of falling back to viper) prevents this bug path from executing.

internal/exec/shell_utils.go (3)

313-313: LGTM - Clean parameter addition.

The providerName parameter slots naturally between identityName and authEnvVars, improving shell messaging context.


560-586: LGTM - Enhanced shell entry messaging.

The providerName display logic is clean: shows "identity (provider)" format when provider is available. The ColorGray styling for the provider creates a nice visual hierarchy.


589-605: LGTM - Consistent exit messaging.

Exit message mirrors the entry format, maintaining consistency in the user experience.

cmd/auth_exec_test.go (3)

49-53: Good edge case coverage.

This test validates the behavior when --identity is provided without a value before the -- marker, correctly expecting the default identity to be used (leading to auth failure in test environment). The comment clarifies the expected behavior.


107-113: LGTM - Validates flag inheritance.

Confirms the identity flag is properly inherited from the parent authCmd and verifies the NoOptDefVal sentinel matches IdentityFlagSelectValue. Good structural validation.


115-215: Excellent comprehensive test coverage.

This table-driven test covers all the critical scenarios for identity flag extraction:

  • Various flag formats (--identity, -i, --identity=value)
  • End-of-flags marker handling
  • Edge cases (empty args, no value, etc.)

The test cases are well-named and assertions are clear.

cmd/terraform_identity_flag_test.go (2)

12-113: Excellent regression test.

This test directly addresses the PR's core issue: reproducing the CI failure when no auth is configured but viper state pollution causes TTY checks. The three test scenarios cover:

  1. Normal case (empty viper)
  2. Bug scenario (viper returns SELECT)
  3. Fixed behavior (don't query viper)

The inline comments clearly document the before/after behavior and the test logging aids debugging. Well done.


115-173: LGTM - Validates viper edge cases.

Tests viper.GetString behavior under different configurations to understand the root cause. Covers BindEnv, explicit Set, and environment variable fallbacks. The setup functions and assertions are clean.

cmd/auth_shell.go (4)

57-59: Clean separation of concerns.

Moving flag extraction into a dedicated helper improves testability and readability. The comment about avoiding pflag parser with DisableFlagParsing is helpful context.


74-86: LGTM - Clear identity resolution flow.

The logic distinguishes between explicitly provided flags (identityValue) and fallback to viper (config/env). The comments clearly document the three states identityValue can have.


146-226: Solid flag extraction logic.

The extractAuthShellFlags implementation correctly handles:

  • End-of-flags marker (--)
  • Equals syntax (--identity=value)
  • Short flags (-i)
  • No value cases (sentinel)
  • Multiple flags (identity and shell)

The logic for determining when to use IdentityFlagSelectValue is consistent across scenarios. Edge cases like empty strings and trailing flags are handled properly.


228-242: Good documentation of flag inheritance.

The comments clearly explain why the identity flag is NOT redefined here (inherited from parent) and document where the completion is handled. This prevents future confusion and accidental flag duplication.

- Fix broken link to custom commands documentation
- Change PRD link to GitHub URL for external reference

This resolves Docusaurus build failures caused by invalid internal links.
…er commands

## Problem

When running `atmos terraform plan --identity` (without a value), the command
failed with "invalid flag: --identity". This prevented users from using the
interactive identity selector for terraform, helmfile, and packer commands.

The issue was in `processArgsAndFlags()` which expected `--identity` to always
have a value and threw an error if no value was provided.

## Solution

Updated `internal/exec/cli_utils.go` `processArgsAndFlags()` to handle three cases:
1. `--identity value` → use the specified value
2. `--identity` (no value) → set to `__SELECT__` for interactive selection
3. `--identity=` (empty value) → set to `__SELECT__` for interactive selection

The fix checks if the next argument exists and is not another flag (doesn't start
with `-`) before treating it as the identity value. Otherwise, it sets the identity
to the special `__SELECT__` value which triggers interactive selection.

Also moved `IdentityFlagSelectValue` constant from `cmd/auth.go` to `pkg/config/const.go`
so it can be used by both `cmd` and `internal/exec` packages without circular dependencies.

## Testing

Added comprehensive unit tests in `internal/exec/cli_utils_identity_test.go` covering:
- `--identity` without value
- `--identity value` with value
- `--identity=value` with equals syntax
- `--identity=` with empty value
- No --identity flag
- `--identity` followed by another flag

All tests pass for terraform, helmfile, and packer commands.

## Manual Testing

```bash
$ ./build/atmos terraform plan vpc --stack test --identity
# No longer shows "invalid flag: --identity" error
# Now correctly triggers interactive identity selection
```

Fixes the regression where `--identity` flag was not recognized for terraform/helmfile/packer commands.
Registers the identity flag completion function for terraform commands so that
shell completion (bash/zsh/fish) suggests available identities when typing
`atmos terraform plan --identity <TAB>`.

The completion function fetches identities from the Atmos configuration and
returns them as suggestions.

Added test to verify completion is registered correctly.
Refactored SSO token caching to use dependency injection pattern for
better testability and comprehensive test coverage.

Changes:
- Extracted cache operations into CacheStorage interface
- Created defaultCacheStorage implementation for production use
- Moved cache functions to dedicated sso_cache.go file
- Added cacheStorage field to ssoProvider struct
- Created comprehensive unit tests with mockCacheStorage

Test coverage improvements:
- Load cached token (8 test cases)
  * Valid cached token
  * Cache file not found
  * Expired token
  * Region mismatch
  * Start URL mismatch
  * Invalid JSON
  * XDG cache dir error
  * Read file error
- Save cached token (3 test cases)
  * Successful save
  * XDG cache dir error (non-fatal)
  * Write file error (non-fatal)
- Delete cached token (4 test cases)
  * Successful delete
  * File not found (non-fatal)
  * XDG cache dir error (non-fatal)
  * Remove error (non-fatal)
- Get token cache path (3 test cases)
  * Successful path generation
  * XDG cache dir error
  * Mkdir error

All error paths are now testable without filesystem dependencies.
All existing SSO tests continue to pass.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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)
pkg/auth/providers/aws/sso_cache_test.go (1)

430-496: Tighten the path assertion?

We already capture wantContains but never assert it. Checking that substring would lock in the provider-name segment and catch regressions.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • 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 5ea6974 and 46532c0.

📒 Files selected for processing (4)
  • pkg/auth/list/formatter_utils_test.go (2 hunks)
  • pkg/auth/providers/aws/sso.go (5 hunks)
  • pkg/auth/providers/aws/sso_cache.go (1 hunks)
  • pkg/auth/providers/aws/sso_cache_test.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
pkg/**/*.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

Place business logic in pkg rather than in cmd

Files:

  • pkg/auth/providers/aws/sso_cache_test.go
  • pkg/auth/list/formatter_utils_test.go
  • pkg/auth/providers/aws/sso.go
  • pkg/auth/providers/aws/sso_cache.go
**/*_test.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

**/*_test.go: Every new feature must include comprehensive unit tests
Test both happy paths and error conditions
Use table-driven tests for multiple scenarios

Files:

  • pkg/auth/providers/aws/sso_cache_test.go
  • pkg/auth/list/formatter_utils_test.go
**/*.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

**/*.go: All code must pass golangci-lint checks
Follow Go error handling idioms and use meaningful error messages
Wrap errors with context using fmt.Errorf("context: %w", err)
Consider custom error types for domain-specific errors
Follow standard Go coding style; run gofmt and goimports
Use snake_case for environment variables
Document complex logic with inline comments

Files:

  • pkg/auth/providers/aws/sso_cache_test.go
  • pkg/auth/list/formatter_utils_test.go
  • pkg/auth/providers/aws/sso.go
  • pkg/auth/providers/aws/sso_cache.go
**/!(*_test).go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

Document all exported functions, types, and methods with Go doc comments

Files:

  • pkg/auth/providers/aws/sso.go
  • pkg/auth/providers/aws/sso_cache.go
🧠 Learnings (13)
📓 Common learnings
Learnt from: Listener430
Repo: cloudposse/atmos PR: 934
File: tests/fixtures/scenarios/docs-generate/README.md.gotmpl:99-118
Timestamp: 2025-01-25T03:51:57.689Z
Learning: For the cloudposse/atmos repository, changes to template contents should be handled in dedicated PRs and are typically considered out of scope for PRs focused on other objectives.
Learnt from: aknysh
Repo: cloudposse/atmos PR: 944
File: go.mod:206-206
Timestamp: 2025-01-17T00:18:57.769Z
Learning: For indirect dependencies with license compliance issues in the cloudposse/atmos repository, the team prefers to handle them in follow-up PRs rather than blocking the current changes, as these issues often require deeper investigation of the dependency tree.
Learnt from: Benbentwo
Repo: cloudposse/atmos PR: 1452
File: cmd/auth_login.go:43-44
Timestamp: 2025-09-07T18:07:00.549Z
Learning: In the atmos project, the identity flag is defined as a persistent flag on the auth root command (cmd/auth.go), making it available to all auth subcommands without needing to be redefined in each individual subcommand.
Learnt from: Benbentwo
Repo: cloudposse/atmos PR: 1475
File: pkg/auth/manager.go:304-312
Timestamp: 2025-09-25T01:02:48.697Z
Learning: The auth manager in pkg/auth/manager.go should remain cloud-agnostic and not contain AWS-specific logic or references to specific cloud providers. Keep the manager generic and extensible.
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to **/*_test.go : Every new feature must include comprehensive unit tests

Applied to files:

  • pkg/auth/providers/aws/sso_cache_test.go
  • pkg/auth/list/formatter_utils_test.go
📚 Learning: 2025-09-08T01:25:44.958Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1466
File: website/docs/cli/commands/toolchain/usage.mdx:117-121
Timestamp: 2025-09-08T01:25:44.958Z
Learning: Final XDG Base Directory Specification implementation for atmos toolchain is complete and verified: toolchain/xdg_cache.go provides GetXDGCacheDir() and GetXDGTempCacheDir() functions, all hardcoded ~/.cache/tools-cache paths have been replaced with XDG-compliant paths using ${XDG_CACHE_HOME}/atmos-toolchain (or ~/.cache/atmos-toolchain fallback), and tests have been updated to expect the new path structure.

Applied to files:

  • pkg/auth/providers/aws/sso_cache_test.go
📚 Learning: 2024-12-13T16:48:00.294Z
Learnt from: Listener430
Repo: cloudposse/atmos PR: 844
File: pkg/config/cache.go:42-42
Timestamp: 2024-12-13T16:48:00.294Z
Learning: The function `withCacheFileLock` in `pkg/config/cache.go` is currently unused and left for future upgrade.

Applied to files:

  • pkg/auth/providers/aws/sso_cache_test.go
  • pkg/auth/providers/aws/sso_cache.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to **/*_test.go : Test both happy paths and error conditions

Applied to files:

  • pkg/auth/providers/aws/sso_cache_test.go
  • pkg/auth/list/formatter_utils_test.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to **/!(*_test).go : Document all exported functions, types, and methods with Go doc comments

Applied to files:

  • pkg/auth/list/formatter_utils_test.go
📚 Learning: 2025-05-23T19:51:47.091Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1255
File: cmd/describe_affected_test.go:15-15
Timestamp: 2025-05-23T19:51:47.091Z
Learning: The atmos codebase has a custom extension to *testing.T that provides a Chdir method, allowing test functions to call t.Chdir() to change working directories during tests. This is used consistently across test files in the codebase.

Applied to files:

  • pkg/auth/list/formatter_utils_test.go
📚 Learning: 2025-07-05T20:59:02.914Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1363
File: internal/exec/template_utils.go:18-18
Timestamp: 2025-07-05T20:59:02.914Z
Learning: In the Atmos project, gomplate v4 is imported with a blank import (`_ "github.com/hairyhenderson/gomplate/v4"`) alongside v3 imports to resolve AWS SDK version conflicts. V3 uses older AWS SDK versions that conflict with newer AWS modules used by Atmos. A full migration to v4 requires extensive refactoring due to API changes and should be handled in a separate PR.

Applied to files:

  • pkg/auth/list/formatter_utils_test.go
📚 Learning: 2025-08-15T14:43:41.030Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1352
File: pkg/store/artifactory_store_test.go:108-113
Timestamp: 2025-08-15T14:43:41.030Z
Learning: In test files for the atmos project, it's acceptable to ignore errors from os.Setenv/Unsetenv operations during test environment setup and teardown, as these are controlled test scenarios.

Applied to files:

  • pkg/auth/list/formatter_utils_test.go
📚 Learning: 2025-05-23T19:51:47.091Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1255
File: cmd/describe_affected_test.go:15-15
Timestamp: 2025-05-23T19:51:47.091Z
Learning: In the atmos codebase, t.Chdir() is a valid method call on *testing.T objects and works correctly for changing directories in tests. This is implemented through custom testing framework extensions and is used consistently throughout the test suite.

Applied to files:

  • pkg/auth/list/formatter_utils_test.go
📚 Learning: 2025-05-23T19:51:47.091Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1255
File: cmd/describe_affected_test.go:15-15
Timestamp: 2025-05-23T19:51:47.091Z
Learning: In the atmos codebase, t.Chdir() is a valid method call on *testing.T objects and works correctly for changing directories in tests.

Applied to files:

  • pkg/auth/list/formatter_utils_test.go
📚 Learning: 2025-05-23T19:51:47.091Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1255
File: cmd/describe_affected_test.go:15-15
Timestamp: 2025-05-23T19:51:47.091Z
Learning: In the atmos codebase, t.Chdir() is a valid method that can be called on *testing.T objects. This functionality is implemented through custom testing framework extensions and is used consistently throughout the test suite for changing working directories during tests.

Applied to files:

  • pkg/auth/list/formatter_utils_test.go
📚 Learning: 2024-12-13T16:51:37.868Z
Learnt from: Listener430
Repo: cloudposse/atmos PR: 844
File: pkg/config/cache.go:69-97
Timestamp: 2024-12-13T16:51:37.868Z
Learning: In `pkg/config/cache.go`, the function `SaveCache2` is currently unused because it does not work properly on Windows and will be addressed later.

Applied to files:

  • pkg/auth/providers/aws/sso_cache.go
🧬 Code graph analysis (4)
pkg/auth/providers/aws/sso_cache_test.go (2)
pkg/xdg/xdg.go (1)
  • GetXDGCacheDir (32-34)
pkg/perf/perf.go (1)
  • Track (121-138)
pkg/auth/list/formatter_utils_test.go (1)
pkg/perf/perf.go (1)
  • Track (121-138)
pkg/auth/providers/aws/sso.go (3)
pkg/schema/schema_auth.go (1)
  • Provider (21-35)
pkg/auth/providers/aws/sso_cache.go (1)
  • CacheStorage (31-42)
pkg/auth/types/aws_credentials.go (1)
  • AWSCredentials (16-24)
pkg/auth/providers/aws/sso_cache.go (2)
pkg/xdg/xdg.go (1)
  • GetXDGCacheDir (32-34)
pkg/logger/log.go (2)
  • Errorf (59-61)
  • Debug (24-26)
⏰ 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). (10)
  • GitHub Check: release / goreleaser
  • GitHub Check: Build (windows)
  • GitHub Check: Build (linux)
  • GitHub Check: website-deploy-preview
  • GitHub Check: Review Dependency Licenses
  • GitHub Check: Lint (golangci)
  • GitHub Check: Analyze (go)
  • GitHub Check: autofix
  • GitHub Check: Run pre-commit hooks
  • GitHub Check: Summary
🔇 Additional comments (3)
pkg/auth/list/formatter_utils_test.go (1)

5-5: LGTM!

The time import is necessary for the new test function.

pkg/auth/providers/aws/sso_cache.go (1)

84-156: Graceful cache fallbacks look great.

Appreciate the five-minute expiry buffer plus config matching and the non-fatal logging—keeps auth resilient without hiding useful diagnostics.

pkg/auth/providers/aws/sso.go (1)

98-193: Nice short-circuit on cached tokens.

Early exit before the TTY gate keeps CI happy while preserving the same AWSCredentials shape—great balance.

Comment thread pkg/auth/list/formatter_utils_test.go Resolved
Three improvements to test code quality:

1. Cross-platform os.DevNull usage:
   - Updated cli_interactive_test.go to use os.DevNull constant
   - Replaced hardcoded "/dev/null" with platform-agnostic constant
   - Added error handling for os.Open call

2. Complete ARM64 skip guards for gomonkey tests:
   - Added ARM64 skip guards to TestExecuteAffectedComponents
   - Added ARM64 skip guards to TestExecuteTerraformAffected
   - Added ARM64 skip guards to BenchmarkGetAffectedComponents
   - Added ARM64 skip guards to BenchmarkExecuteAffectedComponents
   - Ensures consistent behavior across all gomonkey-based tests
   - Prevents SIGBUS crashes on Apple Silicon

3. Better error handling in getCurrentTime test:
   - Check time.Parse error in formatter_utils_test.go
   - Use t.Fatalf to fail immediately on parse error
   - Prevents confusing error messages from malformed test data

All tests pass successfully with these improvements.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
coderabbitai[bot]
coderabbitai Bot previously approved these changes Nov 1, 2025
@github-actions

github-actions Bot commented Nov 1, 2025

Copy link
Copy Markdown

These changes were released in v1.197.0-test.27.

@mergify

mergify Bot commented Nov 1, 2025

Copy link
Copy Markdown
Contributor

Important

Cloud Posse Engineering Team Review Required

This pull request modifies files that require Cloud Posse's review. Please be patient, and a core maintainer will review your changes.

To expedite this process, reach out to us on Slack in the #pr-reviews channel.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • 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 46532c0 and d46c3e4.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (6)
  • examples/quick-start-advanced/Dockerfile (1 hunks)
  • go.mod (10 hunks)
  • internal/exec/terraform_affected_test.go (6 hunks)
  • pkg/auth/list/formatter_utils_test.go (2 hunks)
  • tests/cli_interactive_test.go (1 hunks)
  • website/docs/integrations/atlantis.mdx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/exec/terraform_affected_test.go
  • pkg/auth/list/formatter_utils_test.go
🧰 Additional context used
📓 Path-based instructions (4)
**/*_test.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

**/*_test.go: Every new feature must include comprehensive unit tests
Test both happy paths and error conditions
Use table-driven tests for multiple scenarios

Files:

  • tests/cli_interactive_test.go
**/*.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

**/*.go: All code must pass golangci-lint checks
Follow Go error handling idioms and use meaningful error messages
Wrap errors with context using fmt.Errorf("context: %w", err)
Consider custom error types for domain-specific errors
Follow standard Go coding style; run gofmt and goimports
Use snake_case for environment variables
Document complex logic with inline comments

Files:

  • tests/cli_interactive_test.go
go.{mod,sum}

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

go.{mod,sum}: Manage dependencies with Go modules
Keep dependencies up to date

Files:

  • go.mod
website/**

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

website/**: Update website documentation in website/ when adding features
Ensure consistency between CLI help text and website documentation
Follow the website's documentation structure and style
Keep website code in website/ and follow its architecture/style; test changes locally
Keep CLI and website documentation in sync; document new features with examples and use cases

Files:

  • website/docs/integrations/atlantis.mdx
🧠 Learnings (36)
📓 Common learnings
Learnt from: Listener430
Repo: cloudposse/atmos PR: 934
File: tests/fixtures/scenarios/docs-generate/README.md.gotmpl:99-118
Timestamp: 2025-01-25T03:51:57.689Z
Learning: For the cloudposse/atmos repository, changes to template contents should be handled in dedicated PRs and are typically considered out of scope for PRs focused on other objectives.
Learnt from: aknysh
Repo: cloudposse/atmos PR: 944
File: go.mod:206-206
Timestamp: 2025-01-17T00:18:57.769Z
Learning: For indirect dependencies with license compliance issues in the cloudposse/atmos repository, the team prefers to handle them in follow-up PRs rather than blocking the current changes, as these issues often require deeper investigation of the dependency tree.
Learnt from: Benbentwo
Repo: cloudposse/atmos PR: 1452
File: cmd/auth_login.go:43-44
Timestamp: 2025-09-07T18:07:00.549Z
Learning: In the atmos project, the identity flag is defined as a persistent flag on the auth root command (cmd/auth.go), making it available to all auth subcommands without needing to be redefined in each individual subcommand.
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 914
File: cmd/terraform_commands.go:260-265
Timestamp: 2025-01-09T22:37:01.004Z
Learning: In the terraform commands implementation (cmd/terraform_commands.go), the direct use of `os.Args[2:]` for argument handling is intentionally preserved to avoid extensive refactoring. While it could be improved to use cobra's argument parsing, such changes should be handled in a dedicated PR to maintain focus and minimize risk.
📚 Learning: 2025-10-11T19:11:58.965Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1599
File: internal/exec/terraform.go:0-0
Timestamp: 2025-10-11T19:11:58.965Z
Learning: For terraform apply interactivity checks in Atmos (internal/exec/terraform.go), use stdin TTY detection (e.g., `IsTTYSupportForStdin()` or checking `os.Stdin`) to determine if user prompts are possible. This is distinct from stdout/stderr TTY checks used for output display (like TUI rendering). User input requires stdin to be a TTY; output display requires stdout/stderr to be a TTY.

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to **/*_test.go : Every new feature must include comprehensive unit tests

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to **/*_test.go : Use table-driven tests for multiple scenarios

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2025-05-23T19:51:47.091Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1255
File: cmd/describe_affected_test.go:15-15
Timestamp: 2025-05-23T19:51:47.091Z
Learning: The atmos codebase has a custom extension to *testing.T that provides a Chdir method, allowing test functions to call t.Chdir() to change working directories during tests. This is used consistently across test files in the codebase.

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to **/*_test.go : Test both happy paths and error conditions

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2025-10-10T23:51:36.597Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1599
File: internal/exec/terraform.go:394-402
Timestamp: 2025-10-10T23:51:36.597Z
Learning: In Atmos (internal/exec/terraform.go), when adding OpenTofu-specific flags like `--var-file` for `init`, do not gate them based on command name (e.g., checking if `info.Command == "tofu"` or `info.Command == "opentofu"`) because command names don't reliably indicate the actual binary being executed (symlinks, aliases). Instead, document the OpenTofu requirement in code comments and documentation, trusting users who enable the feature (e.g., `PassVars`) to ensure their terraform command points to an OpenTofu binary.

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2025-01-07T20:38:09.618Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 896
File: cmd/editor_config.go:37-40
Timestamp: 2025-01-07T20:38:09.618Z
Learning: Error handling suggestion for `cmd.Help()` in `cmd/editor_config.go` was deferred as the code is planned for future modifications.

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2024-10-31T19:25:41.298Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 727
File: internal/exec/terraform_clean.go:233-235
Timestamp: 2024-10-31T19:25:41.298Z
Learning: When specifying color values in functions like `confirmDeleteTerraformLocal` in `internal/exec/terraform_clean.go`, avoid hardcoding color values. Instead, use predefined color constants or allow customization through configuration settings to improve accessibility and user experience across different terminals and themes.

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2024-11-07T20:16:15.381Z
Learnt from: pkbhowmick
Repo: cloudposse/atmos PR: 766
File: cmd/cmd_utils.go:177-178
Timestamp: 2024-11-07T20:16:15.381Z
Learning: In 'cmd/cmd_utils.go', using `os.Exit(1)` directly is acceptable in this context, and wrapping it with deferred cleanup is considered unnecessary.

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2024-11-10T18:37:10.032Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 768
File: internal/exec/vendor_component_utils.go:354-360
Timestamp: 2024-11-10T18:37:10.032Z
Learning: In the vendoring process, a TTY can exist without being interactive. If the process does not prompt the user, we should not require interactive mode to display the TUI. The `CheckTTYSupport` function should check TTY support on stdout rather than stdin.

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to cmd/**/*.go : Provide clear error messages to users and troubleshooting hints where appropriate

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to cmd/**/*.go : Provide meaningful user feedback and include progress indicators for long-running operations

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2025-08-15T14:43:41.030Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1352
File: pkg/store/artifactory_store_test.go:108-113
Timestamp: 2025-08-15T14:43:41.030Z
Learning: In test files for the atmos project, it's acceptable to ignore errors from os.Setenv/Unsetenv operations during test environment setup and teardown, as these are controlled test scenarios.

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to go.{mod,sum} : Manage dependencies with Go modules

Applied to files:

  • go.mod
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to go.{mod,sum} : Keep dependencies up to date

Applied to files:

  • go.mod
📚 Learning: 2025-01-17T00:21:32.987Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 944
File: go.mod:3-3
Timestamp: 2025-01-17T00:21:32.987Z
Learning: Go version 1.23.0 was deliberately introduced by the maintainer (aknysh) in January 2025. While this might be a pre-release or development version of Go, it has been approved for use in this project.

Applied to files:

  • go.mod
📚 Learning: 2025-07-05T20:59:02.914Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1363
File: internal/exec/template_utils.go:18-18
Timestamp: 2025-07-05T20:59:02.914Z
Learning: In the Atmos project, gomplate v4 is imported with a blank import (`_ "github.com/hairyhenderson/gomplate/v4"`) alongside v3 imports to resolve AWS SDK version conflicts. V3 uses older AWS SDK versions that conflict with newer AWS modules used by Atmos. A full migration to v4 requires extensive refactoring due to API changes and should be handled in a separate PR.

Applied to files:

  • go.mod
📚 Learning: 2025-01-17T00:21:32.987Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 944
File: go.mod:3-3
Timestamp: 2025-01-17T00:21:32.987Z
Learning: The project uses Go version 1.23.0 which has been confirmed by the maintainer to be working in production for months. Do not flag this as an invalid Go version.

Applied to files:

  • go.mod
📚 Learning: 2025-10-11T04:03:41.651Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1611
File: go.mod:3-3
Timestamp: 2025-10-11T04:03:41.651Z
Learning: The Go module "go" directive supports three-part version numbers (e.g., "go 1.24.8") since Go 1.21+. The format "go 1.N.P" is valid and recommended for specifying patch versions. Earlier Go versions only accepted major.minor format, but modern tooling fully supports the patch component.

Applied to files:

  • go.mod
📚 Learning: 2024-11-18T13:59:10.824Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 768
File: internal/exec/vendor_model_component.go:3-20
Timestamp: 2024-11-18T13:59:10.824Z
Learning: When replacing significant dependencies like `go-getter` that require extensive changes, prefer to address them in separate PRs.

Applied to files:

  • go.mod
📚 Learning: 2025-09-25T01:02:48.697Z
Learnt from: Benbentwo
Repo: cloudposse/atmos PR: 1475
File: pkg/auth/manager.go:304-312
Timestamp: 2025-09-25T01:02:48.697Z
Learning: The auth manager in pkg/auth/manager.go should remain cloud-agnostic and not contain AWS-specific logic or references to specific cloud providers. Keep the manager generic and extensible.

Applied to files:

  • go.mod
📚 Learning: 2025-05-30T03:21:37.197Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1274
File: go.mod:63-63
Timestamp: 2025-05-30T03:21:37.197Z
Learning: The redis dependency (github.com/redis/go-redis/v9) in the atmos project is only used in tests, not in production code.

Applied to files:

  • go.mod
📚 Learning: 2024-11-12T03:15:15.627Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 775
File: examples/quick-start-advanced/Dockerfile:9-9
Timestamp: 2024-11-12T03:15:15.627Z
Learning: It is acceptable to set `ARG ATMOS_VERSION` to a future version like `1.105.0` in `examples/quick-start-advanced/Dockerfile` if that will be the next release.

Applied to files:

  • examples/quick-start-advanced/Dockerfile
  • website/docs/integrations/atlantis.mdx
📚 Learning: 2024-11-23T00:13:22.004Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 801
File: examples/quick-start-advanced/Dockerfile:9-9
Timestamp: 2024-11-23T00:13:22.004Z
Learning: When updating the `ATMOS_VERSION` in Dockerfiles, the team prefers to pin to the next future version when the PR merges, even if the version is not yet released.

Applied to files:

  • examples/quick-start-advanced/Dockerfile
  • website/docs/integrations/atlantis.mdx
📚 Learning: 2025-09-10T21:17:55.273Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1466
File: toolchain/http_client_test.go:3-10
Timestamp: 2025-09-10T21:17:55.273Z
Learning: In the cloudposse/atmos repository, imports should never be changed as per samtholiya's coding guidelines.

Applied to files:

  • examples/quick-start-advanced/Dockerfile
  • website/docs/integrations/atlantis.mdx
📚 Learning: 2025-09-08T01:25:44.958Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1466
File: website/docs/cli/commands/toolchain/usage.mdx:117-121
Timestamp: 2025-09-08T01:25:44.958Z
Learning: The atmos toolchain has been updated to follow XDG Base Directory Specification with helper functions GetXDGCacheDir() and GetXDGTempCacheDir() in toolchain/xdg_cache.go, using XDG_CACHE_HOME when set and falling back to ~/.cache/atmos-toolchain, making it consistent with atmos core's XDG compliance.

Applied to files:

  • examples/quick-start-advanced/Dockerfile
  • website/docs/integrations/atlantis.mdx
📚 Learning: 2025-01-25T03:51:57.689Z
Learnt from: Listener430
Repo: cloudposse/atmos PR: 934
File: tests/fixtures/scenarios/docs-generate/README.md.gotmpl:99-118
Timestamp: 2025-01-25T03:51:57.689Z
Learning: For the cloudposse/atmos repository, changes to template contents should be handled in dedicated PRs and are typically considered out of scope for PRs focused on other objectives.

Applied to files:

  • examples/quick-start-advanced/Dockerfile
📚 Learning: 2024-11-25T17:17:15.703Z
Learnt from: RoseSecurity
Repo: cloudposse/atmos PR: 797
File: pkg/list/atmos.yaml:213-214
Timestamp: 2024-11-25T17:17:15.703Z
Learning: The file `pkg/list/atmos.yaml` is primarily intended for testing purposes.

Applied to files:

  • examples/quick-start-advanced/Dockerfile
  • website/docs/integrations/atlantis.mdx
📚 Learning: 2025-01-17T00:18:57.769Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 944
File: go.mod:206-206
Timestamp: 2025-01-17T00:18:57.769Z
Learning: For indirect dependencies with license compliance issues in the cloudposse/atmos repository, the team prefers to handle them in follow-up PRs rather than blocking the current changes, as these issues often require deeper investigation of the dependency tree.

Applied to files:

  • examples/quick-start-advanced/Dockerfile
📚 Learning: 2025-09-10T17:34:52.568Z
Learnt from: Benbentwo
Repo: cloudposse/atmos PR: 1475
File: pkg/auth/providers/github/oidc.go:96-100
Timestamp: 2025-09-10T17:34:52.568Z
Learning: The ATMOS_ environment variable binding guideline applies to Atmos configuration variables, not external service-required environment variables like GitHub Actions OIDC variables (GITHUB_ACTIONS, ACTIONS_ID_TOKEN_*) which must use their standard names.

Applied to files:

  • examples/quick-start-advanced/Dockerfile
  • website/docs/integrations/atlantis.mdx
📚 Learning: 2024-10-25T20:26:56.449Z
Learnt from: Cerebrovinny
Repo: cloudposse/atmos PR: 729
File: .goreleaser.yml:26-26
Timestamp: 2024-10-25T20:26:56.449Z
Learning: There is no inconsistency in the version path in `build.sh`; it already uses the correct path `github.com/cloudposse/atmos/pkg/version.Version`.

Applied to files:

  • examples/quick-start-advanced/Dockerfile
📚 Learning: 2025-03-18T12:26:25.329Z
Learnt from: Listener430
Repo: cloudposse/atmos PR: 1149
File: tests/snapshots/TestCLICommands_atmos_vendor_pull_ssh.stderr.golden:7-7
Timestamp: 2025-03-18T12:26:25.329Z
Learning: In the Atmos project, typos or inconsistencies in test snapshot files (such as "terrafrom" instead of "terraform") may be intentional as they capture the exact output of commands and should not be flagged as issues requiring correction.

Applied to files:

  • examples/quick-start-advanced/Dockerfile
📚 Learning: 2025-09-13T16:39:20.007Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1466
File: cmd/markdown/atmos_toolchain_aliases.md:2-4
Timestamp: 2025-09-13T16:39:20.007Z
Learning: In the cloudposse/atmos repository, CLI documentation files in cmd/markdown/ follow a specific format that uses " $ atmos command" (with leading space and dollar sign prompt) in code blocks. This is the established project convention and should not be changed to comply with standard markdownlint rules MD040 and MD014.

Applied to files:

  • examples/quick-start-advanced/Dockerfile
  • website/docs/integrations/atlantis.mdx
📚 Learning: 2024-10-27T16:59:26.187Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 729
File: internal/exec/help.go:48-51
Timestamp: 2024-10-27T16:59:26.187Z
Learning: In the Atmos CLI help messages, when providing examples that include the version number, use the actual version variable (e.g., `version.Version`) instead of placeholders like `<version>`.

Applied to files:

  • examples/quick-start-advanced/Dockerfile
📚 Learning: 2024-12-12T15:15:46.457Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 808
File: examples/demo-atmos-cli-imports/atmos.yaml:7-7
Timestamp: 2024-12-12T15:15:46.457Z
Learning: In example configuration files, such as `examples/demo-atmos-cli-imports/atmos.yaml`, it's acceptable to use `refs/heads/main` in remote URLs.

Applied to files:

  • website/docs/integrations/atlantis.mdx
🧬 Code graph analysis (1)
tests/cli_interactive_test.go (2)
tests/testhelpers/atmos_runner.go (1)
  • NewAtmosRunner (31-35)
pkg/logger/log.go (4)
  • Info (34-36)
  • Logf (79-81)
  • Error (54-56)
  • Log (74-76)
⏰ 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). (14)
  • GitHub Check: release / goreleaser
  • GitHub Check: Analyze (go)
  • GitHub Check: Lint (golangci)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Build (macos)
  • GitHub Check: Build (linux)
  • GitHub Check: Build (windows)
  • GitHub Check: Run pre-commit hooks
  • GitHub Check: Analyze (go)
  • GitHub Check: Lint (golangci)
  • GitHub Check: Review Dependency Licenses
  • GitHub Check: autofix
  • GitHub Check: website-deploy-preview
  • GitHub Check: Summary
🔇 Additional comments (3)
examples/quick-start-advanced/Dockerfile (1)

9-9: Version bump aligns with PR fix.

Updating Atmos to 1.197.0 is the right call—this should contain the regression fixes from PR #1735. The version pinning approach matches the team's established pattern.

website/docs/integrations/atlantis.mdx (1)

676-676: Version bump aligns with the fix—looks good.

Bumping to 1.197.0 ensures users following this example GitHub Action get the fix for the v1.196.0 regression. Consistent with the project's practice of pinning examples to the next stable release.

go.mod (1)

7-7: Verify that dependency updates are intentional and necessary for this fix.

This PR focuses on resolving the identity selection regression in terraform/auth commands, but includes extensive dependency version bumps across direct and indirect packages (GCP storage, Azure SDK, AWS SDK, OPA, Google API, wasmtime, and more). These updates aren't mentioned in the PR objectives.

A few concerns:

  1. Scope clarity: Are these dependency updates necessary to fix the identity flag regression, or should they be deferred to a separate dependency-management PR?
  2. Wasmtime major version change (line 167): The jump from v3 → v37 is a large version bump that needs validation for compatibility and breaking changes.
  3. AWS SDK updates (lines 22–30): Multiple patches across credentials, s3, ssm, sso, ssooidc, sts—verify these don't introduce incompatibilities with your identity/auth changes.

If these updates are intentional and necessary for the fix, confirm that testing covers the dependency changes. If they're incidental (e.g., from go mod tidy), consider splitting them into a separate PR to keep the scope of this fix clear.

Also applies to: 13-13, 22-30, 56-56, 76-76, 99-99, 111-111, 129-130, 167-167, 391-391, 396-396

Comment thread tests/cli_interactive_test.go Resolved
@github-actions

github-actions Bot commented Nov 1, 2025

Copy link
Copy Markdown

These changes were released in v1.197.0-test.31.

@aknysh

Copy link
Copy Markdown
Member

CodeRabbit (@coderabbitai) please review if your last comment "Close the os.DevNull handle opened in the scenario setup." was correctly addressed

@coderabbitai

coderabbitai Bot commented Nov 1, 2025

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for os.DevNull usage in the codebase
echo "=== Searching for os.DevNull usage ==="
rg -n "os\.DevNull" --type=go -C5

echo -e "\n=== Searching for Open.*DevNull ==="
rg -n "Open.*DevNull|DevNull.*Open" --type=go -C5

echo -e "\n=== Checking for Close calls in test files ==="
rg -n "\.Close\(\)" tests/ --type=go -C3

Length of output: 7271


Andriy Knysh (@aknysh) Yes, the comment has been correctly addressed! ✅

Both locations where os.DevNull is opened now have proper cleanup:

  1. Line 64 (in TestInteractiveIdentitySelection):

    devNull, err := os.Open(os.DevNull)
    require.NoError(t, err, "Failed to open null device")
    defer devNull.Close()  // ✅ Properly closed with defer
  2. Lines 312-317 (in TestExplicitIdentityAlwaysWorks):

    devNull, err := os.Open(os.DevNull)
    require.NoError(t, err, "failed to open null device")
    cmd.Stdin = devNull
    t.Cleanup(func() {
        _ = devNull.Close()  // ✅ Properly closed with t.Cleanup
    })

Both approaches are correct:

  • defer ensures cleanup when the function exits
  • t.Cleanup ensures cleanup when the test completes (even if it panics), making it particularly well-suited for test scenarios

No resource leaks remain.


🧠 Learnings used
Learnt from: Listener430
Repo: cloudposse/atmos PR: 934
File: tests/fixtures/scenarios/docs-generate/README.md.gotmpl:99-118
Timestamp: 2025-01-25T03:51:57.689Z
Learning: For the cloudposse/atmos repository, changes to template contents should be handled in dedicated PRs and are typically considered out of scope for PRs focused on other objectives.

Learnt from: aknysh
Repo: cloudposse/atmos PR: 944
File: go.mod:206-206
Timestamp: 2025-01-17T00:18:57.769Z
Learning: For indirect dependencies with license compliance issues in the cloudposse/atmos repository, the team prefers to handle them in follow-up PRs rather than blocking the current changes, as these issues often require deeper investigation of the dependency tree.

Learnt from: Benbentwo
Repo: cloudposse/atmos PR: 1452
File: cmd/auth_login.go:43-44
Timestamp: 2025-09-07T18:07:00.549Z
Learning: In the atmos project, the identity flag is defined as a persistent flag on the auth root command (cmd/auth.go), making it available to all auth subcommands without needing to be redefined in each individual subcommand.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (2)
tests/cli_interactive_test.go (2)

254-282: Consider moving this documentation to formal docs or comments.

While documenting the stdout-piping behavior is valuable, a test function that only logs explanations doesn't actually verify the behavior. Since simulating a TTY in unit tests is challenging (as the comment notes), consider either:

  • Moving this explanation to the formal documentation or a code comment in the relevant implementation
  • Converting it to an example test or benchmark that demonstrates the behavior
  • Keeping it as-is if it serves as important reference for maintainers

18-25: Consider extracting atmosRunner initialization to reduce duplication.

The initialization logic for atmosRunner is repeated in three test functions (here, line 159-166, and 287-294). While this provides test independence, you could reduce duplication using a TestMain function or sync.Once pattern to ensure single initialization across all tests.

Current approach is acceptable and provides clarity, but extracting to a shared initialization would better follow DRY principles.

Example with TestMain:

func TestMain(m *testing.M) {
    atmosRunner = testhelpers.NewAtmosRunner(coverDir)
    if err := atmosRunner.Build(); err != nil {
        logger.Info("Failed to build Atmos, tests may be skipped", "error", err)
    }
    os.Exit(m.Run())
}
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • 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 d46c3e4 and bdfcbe8.

📒 Files selected for processing (2)
  • NOTICE (12 hunks)
  • tests/cli_interactive_test.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*_test.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

**/*_test.go: Every new feature must include comprehensive unit tests
Test both happy paths and error conditions
Use table-driven tests for multiple scenarios

Files:

  • tests/cli_interactive_test.go
**/*.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

**/*.go: All code must pass golangci-lint checks
Follow Go error handling idioms and use meaningful error messages
Wrap errors with context using fmt.Errorf("context: %w", err)
Consider custom error types for domain-specific errors
Follow standard Go coding style; run gofmt and goimports
Use snake_case for environment variables
Document complex logic with inline comments

Files:

  • tests/cli_interactive_test.go
🧠 Learnings (27)
📓 Common learnings
Learnt from: osterman
Repo: cloudposse/atmos PR: 1599
File: internal/exec/terraform.go:0-0
Timestamp: 2025-10-11T19:11:58.965Z
Learning: For terraform apply interactivity checks in Atmos (internal/exec/terraform.go), use stdin TTY detection (e.g., `IsTTYSupportForStdin()` or checking `os.Stdin`) to determine if user prompts are possible. This is distinct from stdout/stderr TTY checks used for output display (like TUI rendering). User input requires stdin to be a TTY; output display requires stdout/stderr to be a TTY.
Learnt from: osterman
Repo: cloudposse/atmos PR: 1599
File: internal/exec/terraform.go:394-402
Timestamp: 2025-10-10T23:51:36.597Z
Learning: In Atmos (internal/exec/terraform.go), when adding OpenTofu-specific flags like `--var-file` for `init`, do not gate them based on command name (e.g., checking if `info.Command == "tofu"` or `info.Command == "opentofu"`) because command names don't reliably indicate the actual binary being executed (symlinks, aliases). Instead, document the OpenTofu requirement in code comments and documentation, trusting users who enable the feature (e.g., `PassVars`) to ensure their terraform command points to an OpenTofu binary.
Learnt from: Benbentwo
Repo: cloudposse/atmos PR: 1452
File: cmd/auth_login.go:43-44
Timestamp: 2025-09-07T18:07:00.549Z
Learning: In the atmos project, the identity flag is defined as a persistent flag on the auth root command (cmd/auth.go), making it available to all auth subcommands without needing to be redefined in each individual subcommand.
Learnt from: pkbhowmick
Repo: cloudposse/atmos PR: 786
File: internal/exec/shell_utils.go:159-162
Timestamp: 2024-11-16T17:30:52.893Z
Learning: For the `atmos terraform shell` command in `internal/exec/shell_utils.go`, input validation for the custom shell prompt is not required, as users will use this as a CLI tool and any issues will impact themselves.
Learnt from: aknysh
Repo: cloudposse/atmos PR: 944
File: go.mod:206-206
Timestamp: 2025-01-17T00:18:57.769Z
Learning: For indirect dependencies with license compliance issues in the cloudposse/atmos repository, the team prefers to handle them in follow-up PRs rather than blocking the current changes, as these issues often require deeper investigation of the dependency tree.
Learnt from: Benbentwo
Repo: cloudposse/atmos PR: 1475
File: pkg/auth/manager.go:304-312
Timestamp: 2025-09-25T01:02:48.697Z
Learning: The auth manager in pkg/auth/manager.go should remain cloud-agnostic and not contain AWS-specific logic or references to specific cloud providers. Keep the manager generic and extensible.
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to **/*_test.go : Every new feature must include comprehensive unit tests

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2025-10-11T19:11:58.965Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1599
File: internal/exec/terraform.go:0-0
Timestamp: 2025-10-11T19:11:58.965Z
Learning: For terraform apply interactivity checks in Atmos (internal/exec/terraform.go), use stdin TTY detection (e.g., `IsTTYSupportForStdin()` or checking `os.Stdin`) to determine if user prompts are possible. This is distinct from stdout/stderr TTY checks used for output display (like TUI rendering). User input requires stdin to be a TTY; output display requires stdout/stderr to be a TTY.

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to **/*_test.go : Use table-driven tests for multiple scenarios

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2025-05-23T19:51:47.091Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1255
File: cmd/describe_affected_test.go:15-15
Timestamp: 2025-05-23T19:51:47.091Z
Learning: The atmos codebase has a custom extension to *testing.T that provides a Chdir method, allowing test functions to call t.Chdir() to change working directories during tests. This is used consistently across test files in the codebase.

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to **/*_test.go : Test both happy paths and error conditions

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2025-01-07T20:38:09.618Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 896
File: cmd/editor_config.go:37-40
Timestamp: 2025-01-07T20:38:09.618Z
Learning: Error handling suggestion for `cmd.Help()` in `cmd/editor_config.go` was deferred as the code is planned for future modifications.

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2024-10-31T19:25:41.298Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 727
File: internal/exec/terraform_clean.go:233-235
Timestamp: 2024-10-31T19:25:41.298Z
Learning: When specifying color values in functions like `confirmDeleteTerraformLocal` in `internal/exec/terraform_clean.go`, avoid hardcoding color values. Instead, use predefined color constants or allow customization through configuration settings to improve accessibility and user experience across different terminals and themes.

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2024-11-07T20:16:15.381Z
Learnt from: pkbhowmick
Repo: cloudposse/atmos PR: 766
File: cmd/cmd_utils.go:177-178
Timestamp: 2024-11-07T20:16:15.381Z
Learning: In 'cmd/cmd_utils.go', using `os.Exit(1)` directly is acceptable in this context, and wrapping it with deferred cleanup is considered unnecessary.

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2024-11-10T18:37:10.032Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 768
File: internal/exec/vendor_component_utils.go:354-360
Timestamp: 2024-11-10T18:37:10.032Z
Learning: In the vendoring process, a TTY can exist without being interactive. If the process does not prompt the user, we should not require interactive mode to display the TUI. The `CheckTTYSupport` function should check TTY support on stdout rather than stdin.

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to cmd/**/*.go : Provide clear error messages to users and troubleshooting hints where appropriate

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to cmd/**/*.go : Provide meaningful user feedback and include progress indicators for long-running operations

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2025-08-15T14:43:41.030Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1352
File: pkg/store/artifactory_store_test.go:108-113
Timestamp: 2025-08-15T14:43:41.030Z
Learning: In test files for the atmos project, it's acceptable to ignore errors from os.Setenv/Unsetenv operations during test environment setup and teardown, as these are controlled test scenarios.

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2025-10-10T23:51:36.597Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1599
File: internal/exec/terraform.go:394-402
Timestamp: 2025-10-10T23:51:36.597Z
Learning: In Atmos (internal/exec/terraform.go), when adding OpenTofu-specific flags like `--var-file` for `init`, do not gate them based on command name (e.g., checking if `info.Command == "tofu"` or `info.Command == "opentofu"`) because command names don't reliably indicate the actual binary being executed (symlinks, aliases). Instead, document the OpenTofu requirement in code comments and documentation, trusting users who enable the feature (e.g., `PassVars`) to ensure their terraform command points to an OpenTofu binary.

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2024-10-23T21:36:40.262Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 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:

  • tests/cli_interactive_test.go
📚 Learning: 2025-05-23T19:51:47.091Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1255
File: cmd/describe_affected_test.go:15-15
Timestamp: 2025-05-23T19:51:47.091Z
Learning: In the atmos codebase, t.Chdir() is a valid method call on *testing.T objects and works correctly for changing directories in tests. This is implemented through custom testing framework extensions and is used consistently throughout the test suite.

Applied to files:

  • tests/cli_interactive_test.go
📚 Learning: 2025-04-04T02:03:23.676Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1185
File: internal/exec/yaml_func_store.go:26-26
Timestamp: 2025-04-04T02:03:23.676Z
Learning: The Atmos codebase currently uses `log.Fatal` for error handling in multiple places. The maintainers are aware this isn't an ideal pattern (should only be used in main() or init() functions) and plan to address it comprehensively in a separate PR. CodeRabbit should not flag these issues or push for immediate changes until that refactoring is complete.

Applied to files:

  • tests/cli_interactive_test.go
  • NOTICE
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to go.{mod,sum} : Keep dependencies up to date

Applied to files:

  • NOTICE
📚 Learning: 2025-01-25T03:51:57.689Z
Learnt from: Listener430
Repo: cloudposse/atmos PR: 934
File: tests/fixtures/scenarios/docs-generate/README.md.gotmpl:99-118
Timestamp: 2025-01-25T03:51:57.689Z
Learning: For the cloudposse/atmos repository, changes to template contents should be handled in dedicated PRs and are typically considered out of scope for PRs focused on other objectives.

Applied to files:

  • NOTICE
📚 Learning: 2025-01-17T00:18:57.769Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 944
File: go.mod:206-206
Timestamp: 2025-01-17T00:18:57.769Z
Learning: For indirect dependencies with license compliance issues in the cloudposse/atmos repository, the team prefers to handle them in follow-up PRs rather than blocking the current changes, as these issues often require deeper investigation of the dependency tree.

Applied to files:

  • NOTICE
📚 Learning: 2025-09-10T21:17:55.273Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1466
File: toolchain/http_client_test.go:3-10
Timestamp: 2025-09-10T21:17:55.273Z
Learning: In the cloudposse/atmos repository, imports should never be changed as per samtholiya's coding guidelines.

Applied to files:

  • NOTICE
📚 Learning: 2025-10-27T01:54:35.665Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1714
File: website/blog/2025-10-26-zero-config-terminal-output.md:6-6
Timestamp: 2025-10-27T01:54:35.665Z
Learning: In the Atmos blog (website/blog/), blog post authors in frontmatter should always be set to the actual committer or PR opener (e.g., "osterman"), not generic organization names like "cloudposse" or "atmos". Authors must exist in website/blog/authors.yml.

Applied to files:

  • NOTICE
📚 Learning: 2025-03-18T12:26:25.329Z
Learnt from: Listener430
Repo: cloudposse/atmos PR: 1149
File: tests/snapshots/TestCLICommands_atmos_vendor_pull_ssh.stderr.golden:7-7
Timestamp: 2025-03-18T12:26:25.329Z
Learning: In the Atmos project, typos or inconsistencies in test snapshot files (such as "terrafrom" instead of "terraform") may be intentional as they capture the exact output of commands and should not be flagged as issues requiring correction.

Applied to files:

  • NOTICE
📚 Learning: 2025-09-13T16:39:20.007Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1466
File: cmd/markdown/atmos_toolchain_aliases.md:2-4
Timestamp: 2025-09-13T16:39:20.007Z
Learning: In the cloudposse/atmos repository, CLI documentation files in cmd/markdown/ follow a specific format that uses " $ atmos command" (with leading space and dollar sign prompt) in code blocks. This is the established project convention and should not be changed to comply with standard markdownlint rules MD040 and MD014.

Applied to files:

  • NOTICE
📚 Learning: 2024-11-22T12:38:33.132Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 768
File: internal/exec/vendor_utils.go:496-513
Timestamp: 2024-11-22T12:38:33.132Z
Learning: In the Atmos project, continue to flag path traversal issues in code reviews but acknowledge when they are expected and acceptable in specific cases.

Applied to files:

  • NOTICE
📚 Learning: 2024-12-02T21:26:32.337Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 808
File: pkg/config/config.go:478-483
Timestamp: 2024-12-02T21:26:32.337Z
Learning: In the 'atmos' project, when reviewing Go code like `pkg/config/config.go`, avoid suggesting file size checks after downloading remote configs if such checks aren't implemented elsewhere in the codebase.

Applied to files:

  • NOTICE
📚 Learning: 2025-09-07T17:38:17.619Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1466
File: website/src/components/Screengrabs/demo-stacks/deploy-dev.html:28-37
Timestamp: 2025-09-07T17:38:17.619Z
Learning: Screengrab files in the CloudPosse/atmos repository are programmatically generated and should be ignored during code reviews. Do not provide suggestions or comments on files in screengrab directories or screengrab-related HTML files.

Applied to files:

  • NOTICE
🧬 Code graph analysis (1)
tests/cli_interactive_test.go (2)
tests/testhelpers/atmos_runner.go (1)
  • NewAtmosRunner (31-35)
pkg/logger/log.go (4)
  • Info (34-36)
  • Logf (79-81)
  • Error (54-56)
  • Log (74-76)
🪛 GitHub Actions: Dependency Review
NOTICE

[error] 1-1: NOTICE file is out of date. Run './scripts/generate-notice.sh' locally and commit the changes.

⏰ 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). (2)
  • GitHub Check: release / goreleaser
  • GitHub Check: Summary
🔇 Additional comments (4)
NOTICE (1)

1-1600: Run the NOTICE generation script to sync the file.

The pipeline caught that the NOTICE file is out of sync. Since this file is programmatically maintained (as clarified in earlier discussions), running ./scripts/generate-notice.sh locally and committing the result should resolve the pipeline failure.

Based on learnings and pipeline failures.

tests/cli_interactive_test.go (3)

17-154: Comprehensive test coverage for identity selection scenarios.

This test function thoroughly exercises the identity selection behavior across multiple environments (TTY/non-TTY, CI, piped output) and commands (auth, terraform). The subtests properly validate both success paths (explicit identity works) and failure modes (graceful errors in non-TTY/CI). Resource management with os.DevNull is handled correctly using defer cleanup.


158-249: Excellent CI environment coverage.

The table-driven approach systematically verifies that interactive identity selection is properly disabled across all major CI platforms. The assertions correctly validate both the absence of interactive prompts and the presence of appropriate error messages.


296-328: Resource management correctly implemented.

The setupCmd functions now properly accept *testing.T, and the os.DevNull file handle is correctly opened with error checking and closed via t.Cleanup (lines 312-317). This addresses the previous review feedback completely.

Minor note: The _ = t assignments on lines 304 and 324 explicitly acknowledge unused parameters but are unnecessary in Go—unused parameters in function literals don't cause compilation errors. Feel free to keep or remove them; it's purely stylistic.

@github-actions

github-actions Bot commented Nov 1, 2025

Copy link
Copy Markdown

These changes were released in v1.197.0-test.32.

@github-actions

github-actions Bot commented Nov 2, 2025

Copy link
Copy Markdown

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

@github-actions

github-actions Bot commented Nov 2, 2025

Copy link
Copy Markdown

These changes were released in v1.197.0-test.33.

This branch had an error being deployed

1 failed deployment
feature-releases — bdfcbe8a Deployed Nov 1, 2025 by mergify[bot]
preview — bdfcbe8a Deployed Nov 1, 2025 by github-actions[bot]
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 release/feature Create release from this PR size/xl Extra large size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants