Skip to content

refactor(spored): extract OS-specific surface behind build tags (#77 stage 1) - #84

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/77-windows-spored-stage1
Jun 8, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/77-windows-spored-stage1

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Summary

Stage 1 of Windows spored (#77): a no-op-on-Linux refactor that isolates spored's platform-dependent operations behind build tags, so the agent core becomes OS-agnostic and a Windows build can compile. Landed separately to make any Linux regression easy to spot before the Windows implementation arrives.

What moved

  • pkg/agent/sys_{linux,windows,other}.go — leaf functions for the OS surface: CPU times, network/disk bytes, process check, active sessions, port connections, active terminals, recent-user-activity, user-notify, and the pre-stop shell invocation.
    • linux: the existing /proc readers + w/who/pgrep/last/wall execs, moved verbatim (//go:build linux).
    • windows: conservative stubs + msg.exe/powershell shims (Stage 2 fills in the real WMI/perf-counter sources).
    • other (darwin/dev): stubs that never report idle, so make check stays green on a dev Mac.
  • agent.go calls those leaves; warning + spot-notification files now use os.TempDir() instead of hardcoded /tmp.
  • cmd/spored log path is platform-specific (/var/log Unix, %PROGRAMDATA%\spored Windows).

Verification

  • GOOS=linux, GOOS=windows GOARCH=amd64, and host (darwin) all go build ./... clean.
  • Agent tests + make check pass on Linux/darwin — behavior unchanged (Linux code is byte-for-byte the same, just relocated).
  • Windows idle/metrics bodies are intentionally stubbed here; real implementations + the Windows Service + ship/install land in Stages 2-4.

Refs #77. First of a staged series (Stage 2: WMI idle/metrics; Stage 3: Windows Service; Stage 4: installer + GoReleaser + launch wiring).

…stage 1)

Foundation for Windows spored: spored's only platform-dependent operations
(idle/metrics data sources, user-notify, pre-stop shell, log path) are split
into build-tagged files so the agent core stays OS-agnostic. This is a no-op on
Linux — the existing /proc readers and wall/who/pgrep/last execs move verbatim
into pkg/agent/sys_linux.go behind //go:build linux.

- pkg/agent/sys_{linux,windows,other}.go: leaf functions sysReadCPUTimes,
  sysReadNetworkBytes, sysReadDiskIOBytes, sysIsProcessRunning,
  sysCountActiveSessions, sysCountActivePortConnections, sysHasActiveTerminals,
  sysHasRecentUserActivity, sysWarnUsers, sysShellCommand. Linux = real impls;
  windows = conservative stubs (Stage 2 fills in WMI/perf-counter sources) +
  msg.exe / powershell shims; other(darwin) = stubs that never report idle so
  dev builds compile and `make check` stays green.
- agent.go now calls those leaves; warning/spot-notification files use
  os.TempDir() instead of hardcoded /tmp.
- cmd/spored log path is platform-specific (/var/log on Unix, %PROGRAMDATA% on
  Windows) via paths_{windows,other}.go.

GOOS=linux, GOOS=windows, and host (darwin) all `go build ./...` clean;
agent tests + make check pass on Linux/darwin (behavior unchanged). Windows
idle/metrics bodies are intentionally stubbed here — real implementations land
in Stage 2.

Refs #77.
@scttfrdmn
scttfrdmn merged commit 179ca75 into main Jun 8, 2026
2 checks passed
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 19.75309% with 130 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/agent/sys_linux.go 17.26% 111 Missing and 4 partials ⚠️
pkg/agent/agent.go 40.00% 12 Missing ⚠️
cmd/spored/main.go 0.00% 2 Missing ⚠️
cmd/spored/paths_other.go 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn deleted the feat/77-windows-spored-stage1 branch June 8, 2026 21:47
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