Skip to content

fix: treat S3 NoSuchBucket as not-provisioned in state reads#2257

Open
osterman wants to merge 3 commits intomainfrom
osterman/fix-all-flag-backend
Open

fix: treat S3 NoSuchBucket as not-provisioned in state reads#2257
osterman wants to merge 3 commits intomainfrom
osterman/fix-all-flag-backend

Conversation

@osterman
Copy link
Copy Markdown
Member

@osterman osterman commented Mar 26, 2026

what

  • Treat S3 NoSuchBucket errors the same as NoSuchKey in the Terraform state reader — return nil, nil (state not provisioned) instead of crashing
  • Handle both typed *types.NoSuchBucket (AWS SDK v2) and generic smithy.APIError with code "NoSuchBucket" (S3-compatible backends like MinIO, Wasabi)
  • Skip retry loop for NoSuchBucket — the bucket won't appear between retries

why

  • When using atmos terraform plan --all -s <stack> with provision.backend.enabled: true, the ExecuteDescribeStacks enumeration call evaluates YAML functions (!terraform.state) for ALL components before any provisioners have run
  • If the S3 backend bucket hasn't been created yet, GetObject returns NoSuchBucket which was not handled gracefully — it fell through to the retry loop, exhausted retries, returned ErrGetObjectFromS3 (not recoverable), and crashed the entire --all operation
  • NoSuchKey (missing state file) was already handled gracefully by returning nil, nil, which flows through ErrTerraformStateNotProvisionedisRecoverableTerraformError() → graceful fallback. NoSuchBucket is a superset of the same condition (if the bucket doesn't exist, the state can't exist either)
  • Single-component mode was not affected because provisioners create the bucket during terraform init before any state reads

references

Summary by CodeRabbit

  • Bug Fixes

    • Fixed authentication chain behavior so final assume-role step is not skipped when cached credentials exist
    • Prevented crashes during terraform plan --all with backend provisioning when remote state bucket is missing
    • Ensured AWS pod-identity (IRSA) credentials are not leaked into subprocesses
  • Improvements

    • Made environment sanitization consistent for Terraform, Packer, Helmfile and other subprocess execution paths
  • Documentation

    • Added notes describing the backend provisioning and credential isolation fixes

osterman and others added 2 commits March 26, 2026 11:45
…ls on EKS pods (#2143)

* fix: prevent IRSA credentials from overriding Atmos-managed credentials on EKS pods

On EKS pods with IRSA (IAM Roles for Service Accounts), the pod identity webhook
injects AWS_WEB_IDENTITY_TOKEN_FILE, AWS_ROLE_ARN, and AWS_ROLE_SESSION_NAME. When
using Atmos auth on ARC (Actions Runner Controller), these IRSA vars were leaking
into the terraform subprocess because PrepareEnvironment only cleared vars from
ComponentEnvSection (stack YAML env vars), not from os.Environ() where the pod
vars live. AWS SDK credential chain gives web identity tokens higher precedence
than shared credential files, so the pod's runner role was used instead of the
Atmos-managed tfplan role.

## Changes

1. Add IRSA vars to problematicAWSEnvVars so they're cleared during the auth flow itself
2. Change PrepareEnvironment to set cleared vars to empty string (not delete) so they
   appear in ComponentEnvList and override inherited IRSA values in the subprocess
3. Update tests to expect empty strings (which override os.Environ()) instead of absent keys
4. Add TestPrepareEnvironment_IRSALeakPrevention to reproduce the full ARC/IRSA scenario

## How it works

When subprocess env is built as os.Environ() + ComponentEnvList, Go's exec.Cmd
respects the last occurrence of each key. Setting IRSA vars to empty string in
ComponentEnvList ensures they override the pod's injected values.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>

* fix: scrub IRSA env vars via sanitized environment instead of empty strings

Replace the empty-string override approach with a clean, sanitized environment.
Pass os.Environ() through PrepareShellEnvironment (which deletes problematic
IRSA/credential vars), store the result as SanitizedEnv, and pass it to
subprocess execution via WithEnvironment — preventing os.Environ() re-reads
that reintroduce pod-injected IRSA vars on EKS.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: auth credential chain skipping AssumeRole when target identity credentials are cached

When findFirstValidCachedCredentials() found valid cached credentials at the
last identity in the chain (e.g., index 1 in [provider, assume-role]),
fetchCachedCredentials advanced startIndex past the end of the chain, causing
authenticateIdentityChain's loop to never execute. This returned stale cached
credentials without performing the actual AssumeRole API call.

In GitHub Actions on EKS runners, this caused Terraform to use the runner's
pod credentials instead of the Atmos-authenticated planner role, because the
credential file contained provider-level credentials that were never replaced
by a fresh AssumeRole call.

The fix skips cached credentials at the target (last) identity and continues
scanning earlier in the chain, ensuring the identity's Authenticate() method
is always called. This aligns with the existing comment: "CRITICAL: Always
re-authenticate through the full chain, even if the target identity has
cached credentials."

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs: add fix doc for auth credential chain skipping AssumeRole

Documents the bug where findFirstValidCachedCredentials() returns the
last chain index, causing fetchCachedCredentials to advance past the
chain end and skip the actual AssumeRole API call. Also documents the
relationship with PR #2143 (IRSA env var scrubbing).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* docs: remove self-referential links from fix doc

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: forward shell options (CI capture) through ExecuteTerraform to executeCommandPipeline

The 0fc44f4 refactoring extracted executeCommandPipeline but forgot to
forward the opts parameter, silently dropping CI stdout/stderr capture
buffers and producing empty CI summaries.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: use UpdateEnvVar for os.StartProcess env dedup and cross-platform tests

Address CodeRabbit review comments on PR #2143:

- Use envpkg.UpdateEnvVar in ExecAuthShellCommand to prevent duplicate env
  keys that os.StartProcess resolves with "first value wins" semantics
- Replace Unix-only echo/sh test cases with cross-platform os.Executable()
  subprocess pattern, matching the established convention in internal/exec/

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: replace gomonkey with extracted function to fix SIGBUS on darwin/arm64

Gomonkey binary patching crashes with SIGBUS on Apple Silicon (darwin/arm64)
with Go 1.26. Extract componentExistsInStacks() from CheckComponentExists()
and test the logic directly, removing the gomonkey dependency from this package.

Also fix pre-existing lint issues in describe_dependents.go (nestif, gocritic).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
Co-authored-by: Alexander Matveev <26750966+AleksandrMatveev@users.noreply.github.com>
Co-authored-by: Andriy Knysh <aknysh@users.noreply.github.com>
When using `--all` with `provision.backend.enabled: true`, YAML functions
like `!terraform.state` are evaluated before provisioners create the S3
bucket. NoSuchBucket was not handled gracefully like NoSuchKey, causing the
entire operation to crash instead of treating it as "state not provisioned."

Handle both typed (*types.NoSuchBucket) and generic API error forms to
support AWS and S3-compatible backends (MinIO, Wasabi). Also avoids
unnecessary retries on a bucket that cannot appear between attempts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@osterman osterman requested a review from a team as a code owner March 26, 2026 16:46
@github-actions github-actions bot added the size/m Medium size PR label Mar 26, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 26, 2026

Dependency Review

✅ No vulnerabilities or license issues found.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA a9a80b4.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Scanned Files

None

@osterman osterman added the patch A minor, backward compatible change label Mar 26, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 29948e4c-7dc7-41a8-9f1d-4d7f388619c9

📥 Commits

Reviewing files that changed from the base of the PR and between 1f5c68e and a9a80b4.

📒 Files selected for processing (1)
  • docs/fixes/2026-03-26-all-flag-nosuchbucket-backend-provisioning.md

📝 Walkthrough

Walkthrough

Pre-sanitized environment slices ( []string ) are threaded end-to-end into subprocess execution, removing re-reading/merging of the host env. Auth hooks now persist sanitized env to schema, auth manager skips terminal cached credentials, and S3 backend treats missing buckets as unprovisioned (nil, nil).

Changes

Cohort / File(s) Summary
Command exec & test harness
cmd/auth_exec.go, cmd/auth_exec_test.go, cmd/testing_main_test.go
Switch command-exec helpers/tests to pass and accept env as []string; test binary can self-exit (_ATMOS_TEST_EXIT_ONE) for cross-platform subprocess tests.
Shell exec options & auth shell
internal/exec/shell_utils.go, internal/exec/shell_utils_test.go
Added WithEnvironment([]string); ExecAuthShellCommand now accepts sanitized []string and builds cmd.Env from it (no re-read of os.Environ()). Tests updated to use slice form.
Exec callers plumbing
internal/exec/helmfile.go, internal/exec/packer.go, internal/exec/terraform.go, internal/exec/terraform_execute_helpers.go, internal/exec/terraform_execute_helpers_exec.go
Forward WithEnvironment(info.SanitizedEnv) through Execute* paths; init/workspace helpers accept and forward ShellCommandOption variadics.
Auth hooks & schema
pkg/auth/hooks.go, pkg/schema/schema.go
authenticateAndWriteEnv merges os.Environ() with component env, persists sanitized env to ConfigAndStacksInfo.SanitizedEnv, writes back only auth-managed keys; new merge/whitelist helpers; added SanitizedEnv []string field.
AWS env isolation & tests
pkg/auth/cloud/aws/env.go, pkg/auth/cloud/aws/env_test.go, pkg/auth/cloud/aws/setup_test.go
Expanded problematic AWS vars to include IRSA/web-identity keys; updated tests and added IRSA-leak prevention test verifying those keys are removed.
Auth manager chain
pkg/auth/manager_chain.go, pkg/auth/manager_test.go
findFirstValidCachedCredentials() now skips the terminal identity in the chain so final identity re-authenticates; tests adjusted.
S3 backend missing-bucket handling
internal/terraform_backend/terraform_backend_s3.go, internal/terraform_backend/terraform_backend_s3_test.go
Added isNoSuchBucketError and treat NoSuchBucket as unprovisioned by returning (nil, nil) (both typed and generic API errors covered); tests split/updated.
Misc exec helpers & tests
internal/exec/helmfile.go, internal/exec/packer.go, internal/exec/shell_utils_test.go
Various callers updated to include WithEnvironment(info.SanitizedEnv) and tests aligned to new env slice convention.
Component detection refactor & tests
pkg/list/utils/utils.go, pkg/list/utils/check_component_test.go
Extracted componentExistsInStacks for pure unit testing; removed gomonkey mocks and added focused test cases.
Docs
docs/fixes/2026-03-23-auth-credential-chain-skipping-assume-role.md, docs/fixes/2026-03-26-all-flag-nosuchbucket-backend-provisioning.md
Added documentation describing the credential-chain skip fix and NoSuchBucket handling for S3 backend provisioning.

Sequence Diagram(s)

sequenceDiagram
    participant Hooks as Auth Hooks
    participant Manager as Auth Manager
    participant Sanitizer as PrepareShellEnvironment
    participant Exec as ExecuteShellCommand
    participant Sub as Subprocess

    Hooks->>Manager: Request Authenticate for identity chain
    Manager->>Sanitizer: PrepareShellEnvironment (remove AWS/IRSA vars)
    Sanitizer-->>Manager: Return sanitized env ([]string)
    Manager-->>Hooks: Provide auth env list
    Hooks->>Hooks: Persist sanitized env into ConfigAndStacksInfo.SanitizedEnv
    Hooks->>Exec: ExecuteShellCommand with WithEnvironment(SanitizedEnv)
    Exec->>Exec: Build cmd.Env from SanitizedEnv (no os.Environ re-read)
    Exec->>Sub: Launch subprocess with sanitized env
    Sub-->>Exec: Exit code / output
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Suggested reviewers

  • aknysh
  • milldr
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 76.60% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately captures the primary fix: treating S3 NoSuchBucket errors as unprovisioned state (like NoSuchKey), which is the core change in terraform_backend_s3.go. However, the changeset also includes substantial refactoring of environment variable handling across multiple files (shell_utils.go, auth hooks, terraform execution, helmfile, packer), which represents a parallel major effort not reflected in the title.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch osterman/fix-all-flag-backend

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

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

⚠️ Outside diff range comments (1)
pkg/list/utils/utils.go (1)

17-29: 🛠️ Refactor suggestion | 🟠 Major

Add perf tracking to this public function.

CheckComponentExists does I/O on Line 23, so it should be instrumented with perf.Track for consistency and observability.

Proposed diff
 import (
 	e "github.com/cloudposse/atmos/internal/exec"
+	"github.com/cloudposse/atmos/internal/perf"
 	"github.com/cloudposse/atmos/pkg/list/errors"
 	"github.com/cloudposse/atmos/pkg/schema"
 )
@@
 func CheckComponentExists(atmosConfig *schema.AtmosConfiguration, componentName string) bool {
+	defer perf.Track(atmosConfig, "list.utils.CheckComponentExists")()
+
 	if componentName == "" {
 		return false
 	}

As per coding guidelines, "Add defer perf.Track(atmosConfig, "pkg.FuncName")() plus blank line to all public functions ...".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/list/utils/utils.go` around lines 17 - 29, Add perf tracking to the
public function CheckComponentExists: at the top of the function (immediately
after the parameter checks or start of body) add a defer perf.Track(atmosConfig,
"pkg.CheckComponentExists")() and ensure a blank line follows that defer for
readability; this will instrument the I/O call made by ExecuteDescribeStacks and
provide consistent observability for CheckComponentExists.
🧹 Nitpick comments (5)
pkg/list/utils/check_component_test.go (2)

15-140: Rebalance coverage toward exported behavior, not mostly private helper internals.

Most new coverage targets componentExistsInStacks directly; consider adding broader contract tests through CheckComponentExists (beyond empty-name) so refactors don’t force test rewrites.

Based on learnings, "Applies to **/*_test.go: Test behavior, not implementation. Never test stub functions. Avoid tautological tests. Make code testable via dependency injection.".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/list/utils/check_component_test.go` around lines 15 - 140, The tests
currently target the internal helper componentExistsInStacks; replace or add
tests that exercise the exported CheckComponentExists function (not the
stub/private helper) to verify the public contract: call CheckComponentExists
with realistic inputs (nil/empty stacks, stacks missing components, stacks with
components present in different component types and different stacks) and assert
true/false outcomes; remove tautological tests of internal helpers and, if
CheckComponentExists depends on external state, refactor it to accept the stacks
map as an argument (or inject a provider) so tests can pass controlled inputs
and avoid poking private functions like componentExistsInStacks.

15-140: Refactor these cases into a single table-driven test.

These scenarios are good, but the current one-test-per-case pattern is repetitive and harder to maintain.

As per coding guidelines, "**/*_test.go: Use table-driven tests for testing multiple scenarios in Go".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/list/utils/check_component_test.go` around lines 15 - 140, Combine the
many individual tests into one table-driven test named like
TestComponentExistsInStacks_TableDriven: create a slice of test cases each with
a name, input stacks (map[string]any) and expected bool, then loop with
t.Run(tc.name, func(t *testing.T){ result := componentExistsInStacks(tc.stacks,
"test-component"); assert.Equal(t, tc.want, result) }) to cover EmptyMap,
InvalidStackData, NoComponentsKey, InvalidComponentsType,
InvalidComponentTypeMap, ComponentNotFound, ComponentFound,
ComponentFoundInSecondStack and MixedValidInvalidStacks cases; remove the old
duplicated test functions.
pkg/auth/cloud/aws/env_test.go (1)

588-596: Consider using strings.IndexByte.

The indexOf helper duplicates strings.IndexByte functionality. Could simplify with:

if idx := strings.IndexByte(entry, '='); idx >= 0 {

This is a minor nitpick - the current implementation works correctly.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/auth/cloud/aws/env_test.go` around lines 588 - 596, The custom indexOf(s
string, b byte) function duplicates standard library behavior; replace its usage
with strings.IndexByte (importing "strings" if missing) and remove the indexOf
function; e.g., where indexOf(entry, '=') is used, call strings.IndexByte(entry,
'=') and handle the >= 0 check the same way to preserve behavior in the tests in
pkg/auth/cloud/aws/env_test.go.
internal/terraform_backend/terraform_backend_s3_test.go (1)

212-228: Add a direct assertion that NoSuchBucket does not retry.

These cases validate (nil, nil) correctly, but they don’t assert the new short-circuit behavior. Please track GetObject call count and assert exactly one call for both NoSuchBucket variants.

As per coding guidelines, "Every new feature must include comprehensive unit tests targeting >80% code coverage for all packages."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/terraform_backend/terraform_backend_s3_test.go` around lines 212 -
228, Add a counter to the test cases using the erroringS3Client to track calls
to GetObject and assert it is invoked exactly once for both NoSuchBucket
variants; specifically, modify the test entries named "no such bucket - generic
API error (backend not provisioned)" and "no such bucket - typed error (backend
not provisioned)" to wrap the client with a call-counting erroringS3Client (or
add a counter field on erroringS3Client) that increments on GetObject, run the
operation under test, and add assertions that the returned body is nil and that
the GetObject call count equals 1 for each case to verify the short-circuit
behavior.
pkg/auth/manager_test.go (1)

705-723: Nice update—add one explicit terminal-only cache case for completeness.

Consider adding a case where only the last identity has valid cache and earlier steps are missing/invalid, asserting -1. That makes the new skip-last contract explicit and regression-resistant.

Proposed test addition.
 func TestManager_findFirstValidCachedCredentials(t *testing.T) {
@@
 	require.Equal(t, 1, idx)
 
+	// Only target identity valid, no earlier valid cache -> should return -1.
+	delete(s.data, "id1")
+	s.data["id2"] = &testCreds{exp: &validExp}
+	idx = m.findFirstValidCachedCredentials()
+	require.Equal(t, -1, idx)
+
 	// id2 expired, id1 still valid -> should pick id1.
 	s.data["id2"] = &testCreds{exp: &expiredExp}
+	s.data["id1"] = &testCreds{exp: &validExp}
 	idx = m.findFirstValidCachedCredentials()
 	require.Equal(t, 1, idx)

As per coding guidelines "Every new feature must include comprehensive unit tests targeting >80% code coverage for all packages."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/auth/manager_test.go` around lines 705 - 723, Add a terminal-only cache
test: modify the existing test around s.data and
m.findFirstValidCachedCredentials() to include a case where only the last
identity (the target) has valid cached credentials (e.g., set s.data["id2"] =
&testCreds{exp: &validExp} and s.data["id1"] = &testCreds{exp: &expiredExp} or
nil), then call m.findFirstValidCachedCredentials() and assert it returns -1;
this makes the "skip last identity" contract explicit and prevents regressions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/fixes/2026-03-26-all-flag-nosuchbucket-backend-provisioning.md`:
- Around line 36-54: Add the missing fenced code block language tags ("text")
for the two markdown code blocks that illustrate the S3/GetTerraform state flows
(the block starting with "S3 GetObject returns NoSuchBucket" and the block
starting with "nil content from S3 reader") so the linter MD040 is satisfied;
update those triple-backtick fences to ```text while leaving the content
unchanged, ensuring the examples around ReadTerraformBackendS3Internal,
ErrGetObjectFromS3, GetTerraformBackend, GetTerraformState,
isRecoverableTerraformError, and ErrTerraformStateNotProvisioned remain intact.

---

Outside diff comments:
In `@pkg/list/utils/utils.go`:
- Around line 17-29: Add perf tracking to the public function
CheckComponentExists: at the top of the function (immediately after the
parameter checks or start of body) add a defer perf.Track(atmosConfig,
"pkg.CheckComponentExists")() and ensure a blank line follows that defer for
readability; this will instrument the I/O call made by ExecuteDescribeStacks and
provide consistent observability for CheckComponentExists.

---

Nitpick comments:
In `@internal/terraform_backend/terraform_backend_s3_test.go`:
- Around line 212-228: Add a counter to the test cases using the
erroringS3Client to track calls to GetObject and assert it is invoked exactly
once for both NoSuchBucket variants; specifically, modify the test entries named
"no such bucket - generic API error (backend not provisioned)" and "no such
bucket - typed error (backend not provisioned)" to wrap the client with a
call-counting erroringS3Client (or add a counter field on erroringS3Client) that
increments on GetObject, run the operation under test, and add assertions that
the returned body is nil and that the GetObject call count equals 1 for each
case to verify the short-circuit behavior.

In `@pkg/auth/cloud/aws/env_test.go`:
- Around line 588-596: The custom indexOf(s string, b byte) function duplicates
standard library behavior; replace its usage with strings.IndexByte (importing
"strings" if missing) and remove the indexOf function; e.g., where
indexOf(entry, '=') is used, call strings.IndexByte(entry, '=') and handle the
>= 0 check the same way to preserve behavior in the tests in
pkg/auth/cloud/aws/env_test.go.

In `@pkg/auth/manager_test.go`:
- Around line 705-723: Add a terminal-only cache test: modify the existing test
around s.data and m.findFirstValidCachedCredentials() to include a case where
only the last identity (the target) has valid cached credentials (e.g., set
s.data["id2"] = &testCreds{exp: &validExp} and s.data["id1"] = &testCreds{exp:
&expiredExp} or nil), then call m.findFirstValidCachedCredentials() and assert
it returns -1; this makes the "skip last identity" contract explicit and
prevents regressions.

In `@pkg/list/utils/check_component_test.go`:
- Around line 15-140: The tests currently target the internal helper
componentExistsInStacks; replace or add tests that exercise the exported
CheckComponentExists function (not the stub/private helper) to verify the public
contract: call CheckComponentExists with realistic inputs (nil/empty stacks,
stacks missing components, stacks with components present in different component
types and different stacks) and assert true/false outcomes; remove tautological
tests of internal helpers and, if CheckComponentExists depends on external
state, refactor it to accept the stacks map as an argument (or inject a
provider) so tests can pass controlled inputs and avoid poking private functions
like componentExistsInStacks.
- Around line 15-140: Combine the many individual tests into one table-driven
test named like TestComponentExistsInStacks_TableDriven: create a slice of test
cases each with a name, input stacks (map[string]any) and expected bool, then
loop with t.Run(tc.name, func(t *testing.T){ result :=
componentExistsInStacks(tc.stacks, "test-component"); assert.Equal(t, tc.want,
result) }) to cover EmptyMap, InvalidStackData, NoComponentsKey,
InvalidComponentsType, InvalidComponentTypeMap, ComponentNotFound,
ComponentFound, ComponentFoundInSecondStack and MixedValidInvalidStacks cases;
remove the old duplicated test functions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c97d8230-a9db-4b63-ba25-fcfa8d286afa

📥 Commits

Reviewing files that changed from the base of the PR and between e33692b and 1f5c68e.

📒 Files selected for processing (24)
  • cmd/auth_exec.go
  • cmd/auth_exec_test.go
  • cmd/auth_shell.go
  • cmd/testing_main_test.go
  • docs/fixes/2026-03-23-auth-credential-chain-skipping-assume-role.md
  • docs/fixes/2026-03-26-all-flag-nosuchbucket-backend-provisioning.md
  • internal/exec/helmfile.go
  • internal/exec/packer.go
  • internal/exec/shell_utils.go
  • internal/exec/shell_utils_test.go
  • internal/exec/terraform.go
  • internal/exec/terraform_execute_helpers.go
  • internal/exec/terraform_execute_helpers_exec.go
  • internal/terraform_backend/terraform_backend_s3.go
  • internal/terraform_backend/terraform_backend_s3_test.go
  • pkg/auth/cloud/aws/env.go
  • pkg/auth/cloud/aws/env_test.go
  • pkg/auth/cloud/aws/setup_test.go
  • pkg/auth/hooks.go
  • pkg/auth/manager_chain.go
  • pkg/auth/manager_test.go
  • pkg/list/utils/check_component_test.go
  • pkg/list/utils/utils.go
  • pkg/schema/schema.go

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 26, 2026

Codecov Report

❌ Patch coverage is 88.88889% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.25%. Comparing base (ce67b78) to head (a9a80b4).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
internal/exec/shell_utils.go 71.42% 2 Missing and 2 partials ⚠️
internal/exec/helmfile.go 0.00% 1 Missing ⚠️
internal/exec/terraform_execute_helpers_exec.go 85.71% 0 Missing and 1 partial ⚠️
pkg/list/utils/utils.go 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2257      +/-   ##
==========================================
+ Coverage   77.19%   77.25%   +0.05%     
==========================================
  Files        1015     1017       +2     
  Lines       96065    96271     +206     
==========================================
+ Hits        74158    74374     +216     
+ Misses      17717    17703      -14     
- Partials     4190     4194       +4     
Flag Coverage Δ
unittests 77.25% <88.88%> (+0.05%) ⬆️

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

Files with missing lines Coverage Δ
cmd/auth_exec.go 84.00% <100.00%> (-1.33%) ⬇️
cmd/auth_shell.go 57.30% <100.00%> (-2.70%) ⬇️
internal/exec/packer.go 63.75% <100.00%> (+0.24%) ⬆️
internal/exec/terraform.go 79.48% <100.00%> (+0.26%) ⬆️
internal/exec/terraform_execute_helpers.go 75.86% <100.00%> (+0.09%) ⬆️
internal/terraform_backend/terraform_backend_s3.go 91.97% <100.00%> (+0.70%) ⬆️
pkg/auth/cloud/aws/env.go 100.00% <ø> (ø)
pkg/auth/hooks.go 83.84% <100.00%> (+2.10%) ⬆️
pkg/auth/manager_chain.go 87.83% <100.00%> (-1.75%) ⬇️
pkg/schema/schema.go 87.70% <ø> (ø)
... and 4 more

... and 10 files with indirect coverage changes

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

Address CodeRabbit MD040 lint warning.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch A minor, backward compatible change size/m Medium size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant