Skip to content

fix: make Linux example tests resilient to CI environments#11

Merged
christiangda merged 14 commits intomainfrom
fix/linux-example-tests
Mar 21, 2026
Merged

fix: make Linux example tests resilient to CI environments#11
christiangda merged 14 commits intomainfrom
fix/linux-example-tests

Conversation

@christiangda
Copy link
Contributor

@christiangda christiangda commented Mar 21, 2026

Summary

  • Linux example tests were failing on CI runners (ubuntu-latest) because they depended on DMI/hardware access that requires root privileges
  • ExampleProvider_Diagnostics: expected exactly 2 collected components, but /sys/class/dmi/id/product_uuid requires root — now asserts >= 1 instead
  • Example_integrity: expected WithMotherboard() to produce a different ID, but /sys/class/dmi/id/board_serial requires root — now uses salt-based differentiation which always works
  • Example_linuxFileSources: used WithDisk() which needs lsblk//sys/block — now uses only WithCPU() since /proc/cpuinfo is always readable

Test plan

  • GOOS=linux go build ./... succeeds
  • GOOS=linux go vet ./... passes
  • GOOS=linux golangci-lint run ./... reports 0 issues
  • CI make test passes on ubuntu-latest (this PR)

🤖 Generated with Claude Code

Linux example tests were failing on CI runners (ubuntu-latest) because:

- ExampleProvider_Diagnostics expected exactly 2 collected components,
  but the count varies: /sys/class/dmi/id/product_uuid requires root,
  /etc/machine-id availability differs across environments.

- Example_integrity expected WithMotherboard() to produce a different
  ID, but /sys/class/dmi/id/board_serial requires root on CI, so the
  motherboard component silently fails and both IDs are identical.

- Example_linuxFileSources used WithDisk() which needs lsblk or
  /sys/block access that may not work on CI runners.

Fix: use salt-based differentiation (always works regardless of
hardware access), assert >= 1 collected instead of exact counts,
and use only /proc/cpuinfo (always readable) in the file sources
example.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@christiangda christiangda self-assigned this Mar 21, 2026
christiangda and others added 13 commits March 21, 2026 14:52
Use go-test-coverage with .testcoverage.yml config for structured
coverage reporting. Add set -o pipefail to catch failures in piped
commands. Add pass/fail indicators to coverage output.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
All three workflows (release, main, pr) were hiding make command
output due to exec_cmd redirecting to /dev/null. This made test
failures impossible to debug in CI.

Changes:
- Replace MAKE_STOP_ON_ERRORS with MAKE_DEBUG=true globally so all
  make commands show raw output in CI logs
- Pipe make output through 2>&1 | tee for step summaries
- Align step names across all workflows ("Check out code", "Set up Go")
- Add explicit job names to main.yml and pr.yml
- Remove redundant "Go version" steps (setup-go already logs it)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Run tests on all three target platforms (ubuntu-latest, macos-latest,
windows-latest) using a matrix strategy with fail-fast disabled.

The test matrix uses `go test` directly (not `make test`) to avoid
Makefile/bash portability issues on Windows runners. The Linux-only
report job (summary, scc, coverage, build) runs after all platform
tests pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
After testing, each matrix runner (Linux, macOS, Windows) now builds
the CLI binary and runs a smoke test that:
- Prints version info
- Generates a default machine ID and validates it is 64-char hex
- Runs all components with JSON + diagnostics output
- Validates the generated ID against the current machine
- Tests VM-friendly, format 32, and salt modes

Uses shell: bash on all runners (available on windows-latest) and
runner.temp for the binary path to avoid cross-OS path issues.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The mockExecutor was accessed concurrently by Windows collectIdentifiers
goroutines without synchronization, causing data races on callCount map
writes and concurrent map reads. Add sync.RWMutex to protect all map
access in Execute, setOutput, and setError.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Update all documentation to reflect the go.mod bump to Go 1.26.1:
- README.md: Go 1.25+ -> Go 1.26+
- CONTRIBUTING.md: Go 1.22 -> Go 1.26
- copilot-instructions.md: Go 1.22+ -> Go 1.26+

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
On Windows CI runners, WMI can become transiently unavailable after
repeated rapid invocations (each spawning concurrent wmic/PowerShell
processes). This caused -vm and other modes to fail intermittently.

The smoke test now:
- Strictly validates the core path: version, 64-char hex ID, and
  round-trip validation (these must pass)
- Runs additional CLI exercises (-all, -vm, -format, -salt) as
  non-fatal with WARN logging, since the core validation already
  proved the binary works

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Fix README.md: add missing ctx argument to ID() calls in Testing
  and Best Practices sections
- Add sync.RWMutex to mock executor example in README.md to reflect
  thread safety requirement
- Document that CommandExecutor implementations must be safe for
  concurrent use (Windows parallel goroutines)
- Update doc.go Testing section with concurrency note

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove auto-generated boilerplate comments, align step names with
other workflows, and remove unused swift runner conditional. The
file coverage deprecation warning on PRs is a CodeQL informational
notice and requires no action (coverage still runs on push/schedule).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Set CODEQL_ACTION_FILE_COVERAGE_ON_PRS=false to explicitly adopt the
new default (April 2026) and suppress the informational warning.
File coverage is still computed on push and schedule analyses.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@christiangda christiangda merged commit 8ed24ab into main Mar 21, 2026
8 checks passed
@christiangda christiangda deleted the fix/linux-example-tests branch March 21, 2026 14:30
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