Skip to content

Fix Windows compatibility and cross-platform test issues#12

Merged
victoralfred merged 25 commits intomainfrom
fix/windows-compatibility
Jan 19, 2026
Merged

Fix Windows compatibility and cross-platform test issues#12
victoralfred merged 25 commits intomainfrom
fix/windows-compatibility

Conversation

@victoralfred
Copy link
Owner

Summary

This PR fixes all Windows compatibility issues and ensures tests pass across Linux, macOS, and Windows platforms.

Changes Made

1. Updated Dependencies

2. Fixed Hardcoded Unix Paths (18+ instances)

Replaced hardcoded /tmp paths with t.TempDir() for cross-platform compatibility:

  • internal/cli/scan_edge_test.go
  • internal/cli/scan_security_test.go
  • internal/helm/chart_test.go
  • internal/pipeline/runner_test.go
  • internal/policy/decision_test.go
  • internal/policy/engine_test.go
  • internal/scanner/osv/osv_security_test.go
  • internal/scanner/osv/osv_test.go
  • internal/scanner/semgrep/semgrep_test.go
  • internal/scanner/trivy/trivy_test.go

3. Fixed Platform-Specific Command Issues

  • Replaced /bin/echo with exec.LookPath("go") for cross-platform binary execution
  • Updated test to use platform-agnostic commands

4. Fixed Flaky Timing Tests

  • TestTimeoutHandling: Increased timeout from 1ns to 1ms for reliable execution
  • TestRunPolicyCheckContextTimeout: Same fix applied

5. Fixed Linter Warnings

  • Addressed gocritic warnings for intentional invalid path tests
  • Added appropriate //nolint directives with explanations

6. Fixed Staticcheck SA1012 Warnings

  • Fixed nil context handling in tests using variable assignment pattern
  • Fixed prealloc warnings by preallocating slices

Test Results

All tests now pass on all platforms:

  • Linux (ubuntu-latest) - All Go versions (1.22, 1.23, stable)
  • macOS (macos-latest) - All Go versions (1.22, 1.23, stable)
  • Windows (windows-latest) - All Go versions (1.22, 1.23, stable)

CI Status

  • ✅ Go Workflow: All checks passing
  • ✅ CI Workflow: All checks passing
  • ✅ Static Analysis: Passing
  • ✅ Security Scans: Passing
  • ✅ Coverage: Passing

Breaking Changes

None

Additional Notes

These changes ensure full cross-platform compatibility without affecting functionality. All fixes maintain backward compatibility and follow Go best practices.

Add comprehensive GitHub Actions workflows for:

License Workflow:
- Verify LICENSE file exists and is MIT
- Check dependency licenses for compatibility
- Scan for copyleft licenses (GPL/LGPL/AGPL)
- Generate license reports for all dependencies

Go Workflow:
- Test matrix across multiple Go versions and OS (1.22, 1.23, stable)
- Vulnerability scanning with govulncheck
- Go module tidiness checks
- Static analysis with staticcheck and revive
- Code formatting validation (gofmt, goimports)
- Benchmark tests on main branch
- Code coverage with Codecov integration
- Weekly scheduled runs for dependency updates
Replace golangci-lint style directives with staticcheck-native
format to properly suppress intentional nil context test cases.

Changed from:
  //nolint:staticcheck // Testing nil context
To:
  //lint:ignore SA1012 Testing nil context handling

This resolves CI failures while preserving valuable nil context
validation tests across 16 test files.
Changed all nil context tests to pass nil instead of context.TODO()
and added nolint:staticcheck comments on the same line as the call
Changed //nolint:staticcheck to //lint:ignore SA1012 since staticcheck
only recognizes its own lint:ignore directive format
Changed //lint:ignore SA1012 to //nolint:staticcheck since golangci-lint
requires the nolint format for staticcheck rules
The //lint:ignore SA1012 directive is recognized by both standalone
staticcheck and golangci-lint, unlike //nolint which only works with
golangci-lint
Instead of passing nil directly to functions, assign nil to a
context.Context variable first. This avoids triggering SA1012
staticcheck warning while still testing nil context handling
This update resolves Windows-specific path handling issues where drive
letters were being corrupted (e.g., \C:: instead of C:\), causing file
write operations to fail on Windows platforms.

All tests now pass on Linux, macOS, and Windows.
Replace hardcoded Unix paths with cross-platform alternatives:
- Use t.TempDir() instead of /tmp for temporary directories
- Use exec.LookPath to find absolute paths to binaries
- Replace /bin/echo with platform-independent go binary

This ensures all tests pass on Windows, macOS, and Linux.
Replace hardcoded /tmp paths with t.TempDir() in:
- internal/policy/decision_test.go
- internal/policy/engine_test.go
- internal/scanner/osv/osv_security_test.go
- internal/scanner/osv/osv_test.go

These tests were failing on Windows because /tmp translates to D:\tmp
which doesn't exist. Using t.TempDir() ensures cross-platform compatibility.
Replace hardcoded /tmp paths with t.TempDir() in:
- internal/scanner/semgrep/semgrep_test.go (4 instances)
- internal/scanner/trivy/trivy_test.go (4 instances)

These tests were failing on Windows due to hardcoded /tmp paths.
Increase timeout from 1 nanosecond to 1 millisecond and sleep time
from 10 nanoseconds to 10 milliseconds to make the test more reliable
across different platforms, especially Windows where nanosecond-level
timing can be unreliable.
Change timeout from 1 nanosecond to 1 millisecond and sleep from 10
nanoseconds to 10 milliseconds for reliable cross-platform behavior.
Use direct string concatenation instead of filepath.Join for test cases
that intentionally test invalid paths containing newlines and null bytes.
Added nolint directives with explanation.
@victoralfred victoralfred merged commit e0f3a80 into main Jan 19, 2026
48 checks passed
@victoralfred victoralfred deleted the fix/windows-compatibility branch January 19, 2026 08:22
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.

1 participant