forgejo-mcp-broker/internal
Ole-Morten Duesund 7be7f5e199 feat(supervisor): managed stdio subprocess (forgejo-mcp-broker-zuq)
Adds internal/supervisor: a thin wrapper around os/exec that handles the
zombie/leak/escalation concerns once, so phase-4 (bridge) and phase-5
(session glue) don't each have to re-derive them.

Lifecycle (Stop):
  1. Close stdin — well-behaved stdio servers exit on EOF
  2. Send SIGTERM
  3. Wait up to StopGrace (default 5s) for exit
  4. SIGKILL if still alive

Reaping is mandatory: a goroutine calls cmd.Wait so the kernel actually
collects the child. Without it you accumulate zombies under N concurrent
sessions. Tests exercise this via the helper-process pattern (TestMain
re-execs the test binary in helper mode) — no shell or external binary
dependency.

Tests cover: empty Cmd validation, missing-binary error, echo round
trip via stdin/stdout, stderr drainer collecting lines, SIGTERM-friendly
graceful stop, SIGTERM-ignoring child escalating to SIGKILL (with a
ready-on-stdout sync barrier so the test isn't racing the helper's
signal.Notify), idempotent Stop, clean exit detection, non-zero exit
detection, env override propagation. 89.6% coverage; remaining gap is
unreachable-from-public-API defensive branches (pipe-creation failures
under FD exhaustion, post-release Pid).

Manual smoke test against a real `forgejo-mcp --transport stdio` is
deferred to phase 4b's integration test (where it adds the most value).

Closes forgejo-mcp-broker-zuq.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 13:41:00 +02:00
..
buildinfo feat: bootstrap Go project layout (forgejo-mcp-broker-n84) 2026-04-24 16:54:27 +02:00
config feat(config): flag + env parsing with validation (forgejo-mcp-broker-9nq) 2026-04-24 17:10:18 +02:00
forgejo feat(forgejo): upstream OAuth client (forgejo-mcp-broker-b9i) 2026-04-27 13:31:19 +02:00
httpserver feat(httpserver,log): /healthz, graceful shutdown, slog constructor 2026-04-24 17:26:32 +02:00
log feat(httpserver,log): /healthz, graceful shutdown, slog constructor 2026-04-24 17:26:32 +02:00
store feat(store): OAuth tables migration (forgejo-mcp-broker-cpb) 2026-04-27 13:28:12 +02:00
supervisor feat(supervisor): managed stdio subprocess (forgejo-mcp-broker-zuq) 2026-04-27 13:41:00 +02:00