Skip to content

Conversation

leodido
Copy link

@leodido leodido commented Sep 30, 2025

Description

Adds support for the LEEWAY_ENABLE_IN_FLIGHT_CHECKSUMS environment variable to enable in-flight checksumming without requiring CLI flags. This makes it easier to configure in CI environments while maintaining full backward compatibility.

Merge after #243

Key Changes:

  • Add LEEWAY_ENABLE_IN_FLIGHT_CHECKSUMS environment variable constant
  • Implement environment variable as default with CLI flag override in getBuildOpts()
  • Follow the same pattern as existing SLSA environment variables (EnvvarSLSACacheVerification)
  • Use cmd.Flags().Changed() to distinguish explicit flag setting from default values
  • Add comprehensive test coverage for all environment variable and flag combinations
  • Update help documentation to include the new environment variable

Behavior:

  • Environment variable serves as the default value when CLI flag is not explicitly set
  • CLI flag always takes precedence when explicitly provided (maintains backward compatibility)
  • No behavior change for existing users unless they set the environment variable

Related Issue(s)

Addresses the need for easier CI configuration of the in-flight checksumming feature.

Fixes https://linear.app/ona-team/issue/CLC-1960/implement-in-flight-checksumming-leeway

How to test

Manual Testing

# Test 1: Environment variable enables feature
export LEEWAY_ENABLE_IN_FLIGHT_CHECKSUMS=true
leeway build --dry-run <target>
# Should show in-flight checksumming enabled

# Test 2: CLI flag overrides environment variable
export LEEWAY_ENABLE_IN_FLIGHT_CHECKSUMS=false
leeway build --in-flight-checksums --dry-run <target>
# Should show in-flight checksumming enabled (flag wins)

# Test 3: Default behavior unchanged
unset LEEWAY_ENABLE_IN_FLIGHT_CHECKSUMS
leeway build --dry-run <target>
# Should show in-flight checksumming disabled

Automated Testing

# Run the new environment variable tests
go test -run TestInFlightChecksumsEnvironmentVariable ./cmd/ -v

# Run all build-related tests
go test ./cmd/ -v

leodido and others added 3 commits September 30, 2025 15:36
- Add LEEWAY_ENABLE_IN_FLIGHT_CHECKSUMS environment variable constant
- Implement env var as default with CLI flag override in getBuildOpts()
- Follow same pattern as SLSA environment variables (EnvvarSLSACacheVerification)
- Use cmd.Flags().Changed() to distinguish explicit flag setting from default
- Add comprehensive test coverage for all env var and flag combinations
- Update help documentation to include new environment variable
- Maintain full backward compatibility with existing CLI flag usage

Environment variable enables easier CI configuration while preserving
CLI flag precedence for explicit control.

Co-authored-by: Ona <[email protected]>
- Add TestInFlightChecksumsEnvironmentVariable with 5 test scenarios
- Test env var enabled/disabled with and without CLI flags
- Verify CLI flag precedence over environment variable
- Add os import for environment variable manipulation
- Ensure proper cleanup of environment variables in tests

Fixes missing test coverage for LEEWAY_ENABLE_IN_FLIGHT_CHECKSUMS
environment variable functionality.

Co-authored-by: Ona <[email protected]>
- Remove duplicate TestInFlightChecksumsEnvironmentVariable function
- Use t.Setenv() instead of manual os.Setenv/os.Unsetenv for proper cleanup
- Test actual getBuildOpts logic instead of just checking for no errors
- Replicate exact environment variable + CLI flag precedence logic
- Verify all 5 test scenarios: env var enabled/disabled with/without flags
- Follow same testing pattern as TestBuildCommandFlags

Fixes test coverage gaps and improves test quality by actually
validating the business logic rather than just execution.

Co-authored-by: Ona <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants