Skip to content

Conversation

osterman
Copy link
Member

@osterman osterman commented Sep 5, 2025

Summary

  • Implements a comprehensive precondition-based test skipping strategy to improve developer experience
  • Adds SDK-based helper functions for checking AWS, Git, GitHub, and OCI authentication preconditions
  • Updates all failing tests to gracefully skip when environmental requirements aren't met

Problem

Previously, ~18 tests were failing locally due to missing environmental setup (AWS profiles, Git configuration, network access, GitHub tokens), making it difficult for developers to contribute to Atmos without extensive environment configuration.

Solution

This PR introduces intelligent precondition checking that:

  1. Detects missing requirements using official SDKs (AWS SDK, go-git) rather than manual checks
  2. Skips tests gracefully with clear, actionable messages explaining what's missing and how to fix it
  3. Provides an escape hatch via ATMOS_TEST_SKIP_PRECONDITION_CHECKS=true for CI/CD environments

Changes

New Files

  • tests/test_preconditions.go - Centralized helper functions for precondition checking
  • docs/prd/testing-strategy.md - Product Requirements Document for the testing strategy
  • Updated tests/README.md - Practical developer guidance

Helper Functions Added

  • RequireAWSProfile(t, profile) - Validates AWS profile configuration
  • RequireGitRepository(t) - Checks for Git repository
  • RequireGitRemoteWithValidURL(t) - Validates Git remote URLs
  • RequireGitHubAccess(t) - Checks GitHub connectivity and rate limits
  • RequireOCIAuthentication(t) - Validates GitHub token for OCI registry access
  • RequireNetworkAccess(t, url) - General network connectivity check

Tests Updated

  • AWS tests: internal/aws_utils, internal/terraform_backend, pkg/store
  • Git tests: internal/exec/describe_affected, internal/exec/terraform_utils, pkg/atlantis, pkg/describe
  • Vendor tests: internal/exec/vendor_utils (GitHub + OCI auth)

Testing

All previously failing packages now pass:

ok  github.com/cloudposse/atmos/internal/aws_utils
ok  github.com/cloudposse/atmos/internal/terraform_backend
ok  github.com/cloudposse/atmos/internal/exec
ok  github.com/cloudposse/atmos/pkg/store
ok  github.com/cloudposse/atmos/pkg/atlantis
ok  github.com/cloudposse/atmos/pkg/describe

Tests skip with helpful messages when preconditions aren't met:

TestExecuteVendorPull: GitHub token not configured: required for pulling OCI images from ghcr.io. 
Set GITHUB_TOKEN or ATMOS_GITHUB_TOKEN environment variable, or set ATMOS_TEST_SKIP_PRECONDITION_CHECKS=true

Benefits

✅ Developers can run tests locally without extensive environment setup
✅ Clear skip messages guide developers to fix specific issues
✅ CI/CD can bypass checks when using mocked dependencies
✅ Improves contributor onboarding experience
✅ Distinguishes between environmental issues and actual code failures

References

  • Fixes issues with local test execution
  • Implements testing best practices for open-source projects
  • Follows Go testing conventions with t.Skipf()

🤖 Generated with Claude Code

… experience

This commit introduces a comprehensive testing strategy that gracefully handles missing environmental preconditions, making Atmos locally testable for developers without requiring full environment setup.

## Changes

### Core Implementation
- Added `tests/test_preconditions.go` with SDK-based helper functions for checking:
  - AWS profile availability (`RequireAWSProfile`)
  - Git repository and remote configuration (`RequireGitRepository`, `RequireGitRemoteWithValidURL`)
  - GitHub network access and rate limits (`RequireGitHubAccess`)
  - OCI registry authentication via GitHub token (`RequireOCIAuthentication`)
  - General network connectivity (`RequireNetworkAccess`)
  - Environment variables, executables, and file paths

### Test Updates
- Updated AWS-related tests to check for AWS profile availability
- Updated Git-related tests to verify repository and remote configuration
- Updated vendor tests to check for GitHub access and OCI authentication
- All tests now skip gracefully with informative messages when preconditions aren't met

### Documentation
- Created comprehensive PRD at `docs/prd/testing-strategy.md` outlining the testing strategy
- Updated `tests/README.md` with practical guidance and examples
- Updated `CLAUDE.md` with references to new testing approach

### Environment Variables
- Added `ATMOS_TEST_SKIP_PRECONDITION_CHECKS=true` to bypass all precondition checks
- Supports both `GITHUB_TOKEN` and `ATMOS_GITHUB_TOKEN` for OCI authentication

## Benefits
- Tests no longer fail due to missing environment setup
- Clear, actionable skip messages guide developers to fix issues
- CI/CD can bypass checks when running with mocked dependencies
- Improves developer onboarding and contribution experience

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

Co-Authored-By: Claude <[email protected]>
@osterman osterman requested review from a team as code owners September 5, 2025 19:24
@github-actions github-actions bot added the size/l Large size PR label Sep 5, 2025
@osterman osterman added the no-release Do not create a new release (wait for additional code changes) label Sep 5, 2025
Copy link

codecov bot commented Sep 5, 2025

Codecov Report

❌ Patch coverage is 78.03738% with 47 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.15%. Comparing base (f2781b5) to head (96237a8).

Files with missing lines Patch % Lines
tests/test_preconditions.go 78.03% 32 Missing and 15 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1450      +/-   ##
==========================================
+ Coverage   55.94%   56.15%   +0.21%     
==========================================
  Files         274      275       +1     
  Lines       28936    29150     +214     
==========================================
+ Hits        16188    16369     +181     
- Misses      10956    10972      +16     
- Partials     1792     1809      +17     
Flag Coverage Δ
unittests 56.15% <78.03%> (+0.21%) ⬆️

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

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

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

- Added test_preconditions_test.go with comprehensive tests for all helper functions
- Achieved 41.2% coverage (up from 36.81%) for the tests package
- Updated .golangci.yml with text-based exclusion rules for os.Getenv/Setenv in test files
- Kept nolint:forbidigo comments as text-based exclusion didn't work reliably
- Updated GitHub Actions to use golangci-lint-action@v8 (latest version)
- All precondition helpers now have tests covering bypass scenarios and actual usage

The test coverage improvement helps meet the minimum testing requirements for the PR.
@osterman osterman force-pushed the skip-tests-missing-precondition branch from b705af5 to 9fa9407 Compare September 5, 2025 20:35
@github-actions github-actions bot added size/xl Extra large size PR and removed size/l Large size PR labels Sep 5, 2025
Copy link

mergify bot commented Sep 5, 2025

Warning

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

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

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

Copy link

mergify bot commented Sep 5, 2025

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.

@mergify mergify bot added the needs-cloudposse Needs Cloud Posse assistance label Sep 5, 2025
autofix-ci bot and others added 6 commits September 5, 2025 20:36
Remove the os.Setenv pattern from forbidigo linter configuration as requested.
Keep os.Getenv pattern for production code but use nolint comments in test files.

After extensive sandbox testing, determined that text-based exclusion patterns
don't work reliably with forbidigo in golangci-lint. The most reliable approach
is using //nolint:forbidigo comments in test files where os.Getenv is legitimately needed.

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

Co-Authored-By: Claude <[email protected]>
…ns, not entire testing strategy

- Renamed testing-strategy.md to test-preconditions.md to accurately reflect content
- Rewrote document to position precondition checking as one component of testing strategy
- Removed claims about defining the entire testing approach
- Added context about relationship to broader testing framework
- Focused content on the specific capability of handling missing environmental dependencies

🤖 Generated with Claude Code

Co-Authored-By: Claude <[email protected]>
- Added tests for RequireAWSProfile with non-existent profile (94.1% coverage)
- Added tests for RequireGitRepository in and out of repo (85.7% coverage)
- Added tests for RequireGitHubAccess without token (72.4% coverage)
- Added tests for RequireNetworkAccess with valid/invalid URLs (90.0% coverage)
- Added tests for RequireGitRemoteWithValidURL scenarios
- Overall test coverage increased from 41.2% to 78.1%, exceeding 60% target

🤖 Generated with Claude Code

Co-Authored-By: Claude <[email protected]>
- Removed unsupported 'exclude-rules' field that caused CI failure
- Restored 'exclusions' structure compatible with golangci-lint v2.4.0
- Forbidigo is now properly excluded from test files via exclusions.rules
- Kept os.Setenv pattern removed as requested
- Fixed pattern syntax for os.Getenv (removed unnecessary quotes)

🤖 Generated with Claude Code

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

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

golangci-lint found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

osterman and others added 3 commits September 5, 2025 21:17
- Add periods to all test function comments (godot)
- Replace magic numbers with named constants
- Refactor RequireGitHubAccess to split rate limit logic into separate function
- Fix function-length issue by extracting checkGitHubRateLimit helper

These changes address all critical linting errors reported by CI.
- Extract setAWSProfileEnv helper function to reduce nesting complexity
- Simplifies AWS profile environment variable management
- Reduces cognitive complexity from 4 to acceptable levels
- Add envAWSProfile constant to avoid string literal repetition
- Replace all AWS_PROFILE string literals with the constant
- Addresses linting warning about repeated string literals
- Add section on how to check PR checks status
- Include commands for getting check run annotations
- Add examples for inspecting code scanning alerts
- Provide concrete examples for the Atmos repository
coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 6, 2025
The addition of test precondition checks was causing tests to be skipped in CI
environments where AWS credentials and GitHub tokens weren't available. This
resulted in a 1.84% decrease in code coverage.

By setting ATMOS_TEST_SKIP_PRECONDITION_CHECKS=true in the GitHub Actions
workflow, tests will bypass precondition checks and run normally in CI,
maintaining the expected coverage levels while still providing helpful
skip messages for developers running tests locally.

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

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cloudposse Needs Cloud Posse assistance no-release Do not create a new release (wait for additional code changes) size/xl Extra large size PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant