Skip to content

test: add unit tests for core packages (P1+P2)#14

Merged
luthermonson merged 1 commit into
mainfrom
feat/unit-tests
Apr 12, 2026
Merged

test: add unit tests for core packages (P1+P2)#14
luthermonson merged 1 commit into
mainfrom
feat/unit-tests

Conversation

@luthermonson
Copy link
Copy Markdown
Contributor

Summary

  • Add 101 unit tests across 5 packages that previously had zero coverage: pkg/names, pkg/config, pkg/github, pkg/scheduler, pkg/networking
  • Fix pre-existing go:embed failure that broke go test, go vet, and linting on Windows (missing ephemerd-linux placeholder)
  • Fix 11 pre-existing lint issues (7 errcheck, 3 unused functions, 1 unused method)

What's tested

Package Tests Key coverage
pkg/names 6 Format, word lists, variety, duplicates
pkg/config 25 Load/validate branches, duration parsers, logger, VM config
pkg/github 28 Signature verification, label filtering, YAML image parsing, WebhookHandler
pkg/scheduler 30 Label building, platform filtering, conflict detection, dedup TTL, healthz
pkg/networking 12 Subnet selection, CIDR validation, loopback detection

Lint/build fixes

  • mage/download: EnsurePlaceholders() creates empty ephemerd-linux for go:embed on Windows
  • pkg/networking: moved Config.subnet() to subnet_linux.go (unused on Windows/macOS)
  • pkg/networking: fixed 5 unchecked Delete()/NamespaceDetach() calls in network_windows.go
  • pkg/vm: fixed 2 unchecked Close() calls, removed unused wslOutput() in linuxvm_windows.go

Test plan

  • mage ci passes (lint + test + build)
  • go test ./... passes with 0 failures
  • CI workflow passes on self-hosted runner

🤖 Generated with Claude Code

Add 101 unit tests across 5 packages that previously had zero test coverage:

- pkg/names: format validation, word list integrity, variety, no duplicates
- pkg/config: Load() with defaults/missing/invalid/overrides, validate()
  branches (PAT vs App auth, owner, webhook secret gen), duration parsers,
  Logger levels/formats, VM config TOML parsing
- pkg/github: verifySignature (7 cases), isSelfHosted, isTrackedRepo,
  IsOrgLevel, parseEphemerdImage (YAML parsing + explicit job names),
  base64url, WebhookHandler (method filtering, sig verification, event
  filtering, repo filtering, malformed payloads, nil fields)
- pkg/scheduler: New() defaults/custom/edge, buildLabelsForOS, isLinuxJob,
  canHandleJob (platform + dispatch), isConflict (GitHub ErrorResponse,
  wrapped, string fallback), cleanSeen TTL expiry, handleHealthz JSON
- pkg/networking: subnetInUse (invalid/empty/loopback/valid CIDRs),
  pickSubnet (valid CIDR, prefers default, determinism), DefaultSubnet

Also fixes pre-existing issues:

- Fix go:embed failure on Windows by adding EnsurePlaceholders() to
  mage/download that creates empty ephemerd-linux placeholder when the
  cross-compiled binary doesn't exist
- Move Config.subnet() to subnet_linux.go (only called from linux code)
  to fix unused function lint errors on Windows/macOS
- Fix 7 errcheck violations in network_windows.go and linuxvm_windows.go
- Remove unused wslOutput() function from linuxvm_windows.go
@luthermonson luthermonson merged commit 96646b8 into main Apr 12, 2026
@luthermonson luthermonson deleted the feat/unit-tests branch April 12, 2026 05:02
luthermonson added a commit that referenced this pull request Apr 28, 2026
Adds three groups of unit tests around scheduler invariants the existing
suite did not exercise:

- backoffDuration repo-level state: a simulated provider event sequence
  (failure/success/failure) that asserts resetBackoff returns the next
  failure to the 2s base; a 60s cap stress test running 50 iterations;
  and an interleaved multi-repo test guarding against accidental shared
  state in the failureCounts map.

- Concurrent claim + dedup (item #13): 32 goroutines call handleQueued
  for the same job id at the same time; only one ClaimJob and one
  dispatch CreateJob fire. A companion test verifies that two providers
  both claiming the SAME numeric job id each get exactly one claim
  (composite-key routing).

- Timeout / cancellation during cleanup (item #14): handleCompleted
  invoked with a cancelled parent ctx still calls dispatch.Destroy via
  context.Background; destroyAll destroys every dispatched container
  even when the parent ctx is cancelled; handleLinuxJob whose Wait
  errors triggers a Destroy on the cleanup path; destroyAll Stops every
  macosVM exactly once.

Tests use an in-process gRPC dispatch fake (TCP loopback) plus a
counting provider mock so no external systems are touched.
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