Skip to content

feat: add subprocess coverage collection for tests - #1526

Merged
Andriy Knysh (aknysh) merged 10 commits into
mainfrom
feat/subprocess-coverage
Sep 26, 2025
Merged

Andriy Knysh (aknysh) merged 10 commits into
mainfrom
feat/subprocess-coverage

Conversation

@osterman

Copy link
Copy Markdown
Member

what

  • Add subprocess coverage collection for tests using Go 1.20+ GOCOVERDIR support
  • Enable coverage data collection from Atmos binary when executed as subprocess during testing
  • Replace legacy binary management with smart AtmosRunner helper
  • Update Makefile with cleaner coverage targets using native go tool covdata

why

  • Tests that execute Atmos as a subprocess (most CLI tests) were not contributing to coverage reports
  • The existing binary staleness checking was complex and fragile
  • Go 1.20+ provides native support for subprocess coverage collection via GOCOVERDIR
  • This change provides more accurate coverage metrics by including all code executed during tests

references

Implementation Details

AtmosRunner Helper

Created tests/testhelpers/atmos_runner.go that:

  • Automatically builds Atmos with -cover flag when GOCOVERDIR is set
  • Falls back to using existing binary when coverage isn't needed
  • Manages temporary binary lifecycle
  • Passes GOCOVERDIR to subprocesses transparently

Makefile Changes

  • Updated testacc-cover target to use Go 1.20+ subprocess coverage
  • Uses go tool covdata textfmt to convert binary coverage to text format
  • Automatically merges unit test and subprocess coverage
  • Added helper targets for coverage viewing

Test Infrastructure Refactoring

  • Updated TestMain to use AtmosRunner
  • Replaced all exec.Command calls with atmosRunner.Command
  • Fixed environment variable handling to preserve GOCOVERDIR
  • Removed ~100 lines of binary checking/management code

Benefits

✅ Complete coverage visibility including subprocess execution
✅ No manual binary building required for tests
✅ Cleaner, more maintainable code
✅ CI/CD compatible without changes
✅ Native Go tooling instead of complex bash scripts

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

Enable coverage collection from Atmos subprocesses during test execution using Go 1.20+ GOCOVERDIR support.

## Summary
- Add AtmosRunner helper to build Atmos with coverage instrumentation
- Update Makefile with clean coverage targets using native go tool covdata
- Refactor tests to use AtmosRunner instead of exec.Command
- Remove legacy binary staleness checking code

This allows tests that execute Atmos as a subprocess to have their coverage included in the overall test coverage report, providing more accurate coverage metrics.

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

Co-Authored-By: Claude <[email protected]>
@github-actions github-actions Bot added the size/m Medium size PR label Sep 25, 2025
@mergify

mergify Bot commented Sep 25, 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.

@mergify mergify Bot added the needs-cloudposse Needs Cloud Posse assistance label Sep 25, 2025
@osterman Erik Osterman (Cloud Posse) (osterman) added the no-release Do not create a new release (wait for additional code changes) label Sep 25, 2025
- Move all bash complexity to scripts/collect-coverage.sh
- Makefile now just calls the script - clean and simple
- Much more maintainable approach
…mmand types

- Remove AtmosRunner initialization from TestMain to support lazy loading
- Store GOCOVERDIR in global variable for use when needed
- Handle both atmos and non-atmos commands in runCLICommandTest
- Improve binary selection to prefer build/atmos over PATH binaries
- Ensure coverage directory is created before building with coverage
- Make instrumented binaries executable after building
- Refactor complex nested blocks to satisfy linting requirements

This fixes the issue where non-atmos commands were incorrectly trying to use AtmosRunner,
and ensures proper binary selection for both coverage and non-coverage test runs.

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

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

codecov Bot commented Sep 26, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.37383% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.25%. Comparing base (e8c1aed) to head (21ac19c).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
tests/testhelpers/atmos_runner.go 80.37% 14 Missing and 7 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1526      +/-   ##
==========================================
+ Coverage   57.04%   57.25%   +0.21%     
==========================================
  Files         286      276      -10     
  Lines       30595    30325     -270     
==========================================
- Hits        17452    17364      -88     
+ Misses      11304    11113     -191     
- Partials     1839     1848       +9     
Flag Coverage Δ
unittests 57.25% <80.37%> (+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.

- Add .exe extension when building coverage binaries on Windows
- Update findBuildAtmos() to look for atmos.exe on Windows
- Skip os.Chmod() on Windows as it's not needed
- Import runtime package for OS detection

This fixes the 'executable file not found in %PATH%' errors on Windows CI
- Add comprehensive test suite for AtmosRunner class (~500 lines)
- Achieve 100% coverage for core methods (Command, CommandContext, Cleanup, etc.)
- Achieve 81-91% coverage for complex methods (buildWithCoverage, findBuildAtmos, etc.)
- Fix Cleanup method to properly handle path comparisons across platforms
- Add edge case testing for error conditions and platform-specific behavior
- Add integration tests for actual coverage collection workflow
- Add concurrent build tests to ensure thread safety
- Add path handling tests for different directory structures

The patch coverage has been improved from 33.98% to approximately 80-85%, meeting the target requirement.
@github-actions github-actions Bot added size/xl Extra large size PR and removed size/m Medium size PR labels Sep 26, 2025
This file was for documentation purposes only and should not be tracked in the repository.
@mergify

mergify Bot commented Sep 26, 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.

- Remove accidentally committed coverage-all.out file
- Update .gitignore to use wildcard pattern coverage*.out instead of just coverage.out
- This prevents future accidental commits of coverage output files like coverage-all.out
@github-actions github-actions Bot added size/l Large size PR and removed size/xl Extra large size PR labels Sep 26, 2025
…naries

- Modified AtmosRunner to always build a fresh binary for tests
- Added buildWithoutCoverage() for non-coverage test runs
- Removed useExistingBinary() and findBuildAtmos() functions
- Tests now automatically build with latest code changes
- Updated documentation to reflect new test behavior
- Removed obsolete tests for functions that no longer exist

This ensures tests always run against the current code without requiring manual rebuilds,
making the development workflow smoother and preventing stale binary issues.

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

Co-Authored-By: Claude <[email protected]>
@aknysh
Andriy Knysh (aknysh) merged commit 0dfd333 into main Sep 26, 2025
@aknysh
Andriy Knysh (aknysh) deleted the feat/subprocess-coverage branch September 26, 2025 05:50
@mergify mergify Bot removed the needs-cloudposse Needs Cloud Posse assistance label Sep 26, 2025
@github-actions

Copy link
Copy Markdown

These changes were released in v1.192.0.

@github-actions

Copy link
Copy Markdown

These changes were released in v1.193.0-test.1.

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

Labels

no-release Do not create a new release (wait for additional code changes) size/l Large size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants