cmd/agent-watcher/main_test.go builds the real binary in TestMain, then
launches it twice with temp configs to exercise the full path:
TestEndToEnd_BothSourcesEmitToInbox
- drops a *.json file via tmp+rename (mirrors Syncthing semantics)
- POSTs a webhook with template variables ({{ .repo }}, {{ .actor }})
- POSTs a urgent alert with empty body and fixed-string template
- asserts 3 JSONL lines land in bob.inbox with exact shape
- confirms each event's source field tracks origin
("drop-folder:drop1.json", "webhook:/forgejo/push")
- hits /health and verifies emitted=2 (one webhook didn't 200, that
counter only counts successful emits)
TestEndToEnd_GracefulShutdown
- SIGTERM after listener up
- asserts process exits within 3s
Total: 43 tests across 5 packages, all passing. Real binary verified
end-to-end on Linux/amd64.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
internal/config loads ~/.config/agent-watcher/collector.yaml with strict
validation (KnownFields=true, so typos fail loud), applies sensible
defaults, and expands ~/ in path fields. Either source can be omitted
but at least one must be configured.
cmd/agent-watcher is the entry point: load config, build inbox.Writer,
build configured sources, run them concurrently with a shared Emit
closure, wait for SIGINT/SIGTERM, shut down. Logs to stderr — text by
default, JSON via --json-log for journald structured fields per spec
§3.4.
SIGHUP reload is a v2 item; for now restart the systemd unit to pick
up config changes.
10 config tests passing — full happy path, defaults applied, ~/
expansion, and a table of 9 invalid configs that must all reject
(missing agent, no sources, empty webhook routes, route missing
recipient/type/template, route path without leading /, unknown
top-level field, negative poll seconds).
Binary builds clean: 10.8M single static binary on Linux/amd64.
go.mod stays at Go 1.22 to match VPS toolchain.
Total: 41 tests across 4 packages, all passing. Build clean. go vet
clean.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>