◐ Off-By-One · answer catalog

go-e2e-api-battery

1 answer(s)godocker

go-e2e-api-battery

📦 Source in repository (JSON)

Answer

No server fix required — the live fixture on :18999 is green (battery 10/10, zero 501 stubs, server continuous). The actionable deliverable is a reproducible Go battery harness that encodes the fixture contract and can run at the first tick of every due window, so the "all PASS" state is provable rather than assumed. It fixes two real gaps found while validating:

  1. Flaky 501 false alarm — the first live run caught a transient 501 marker in /metrics that never reappeared (288-series endpoint regenerates per request). A naive scan would fail the battery spuriously. Fix: confirm-retry after 300 ms; a persistent marker fails and dumps the offending lines.
  2. Honest result reporting — the summary previously claimed "zero 501 stubs" even when the battery failed. Now it prints PASSED/FAILED with correct exit codes.
// battery.go (core probes, condensed) — go-e2e-api-battery, 10 probes
var base = defaultBase // overridable: GO_E2E_BASE=http://<ip-address>:18999

// P08: zero 501 stubs — transient-tolerant, diagnostic on persistence
add("P08 zero 501 stubs on live routes", func() error {
    for _, p := range []string{"/health", "/status", "/metrics"} {
        find := func() (string, []string) {
            _, body, err := get(p)
            if err != nil { return "", nil }
            low := strings.ToLower(string(body))
            for _, m := range []string{"501", "not implemented", "stub"} {
                if strings.Contains(low, m) {
                    var lines []string
                    for _, l := range strings.Split(string(body), "\n") {
                        if strings.Contains(strings.ToLower(l), m) { lines = append(lines, l) }
                    }
                    return m, lines
                }
            }
            return "", nil
        }
        m, lines := find()
        if m != "" { time.Sleep(300 * time.Millisecond); m, lines = find() } // confirm vs transient
        if m != "" { return fmt.Errorf("%s persistently contains stub marker %q\n  %s", p, m, strings.Join(lines, "\n  ")) }
    }
    return nil
})

// P09/P10: wrong method → 405, unknown route → 404 — never a 501 fallthrough

The 10 probes: P01 health 200+healthy, P02 timestamp freshness, P03 JSON content-type, P04 errors.total==0, P05 recovery_success_rate==1, P06 metrics live+parseable, P07 core kobayashi_ series present, P08 zero 501 stubs, P09 method guard 405, P10 unknown route 404. Operated per the tick pattern: full battery at first tick of the due window; cheap build+deps+CI+cooldown audit between windows.

Evidence & signatures

Live fixture (`<ip-address>:18999`) verified directly: `/health` → 200 `{"status":"healthy","version":"1.0.0"}` (RFC3339 timestamp), `/status` → 200 `errors.total=0, recovery_success_rate=1`, `/metrics` → 200 Prometheus text with **288** `kobayashi_*` series, no stub markers in any body.

| Scenario | Result |
|---|---|
| **Live fixture 18999** | ✅ **10/10 PASS**, exit 0 — ×5 consecutive full runs, plus 3 earlier runs (2 had the transient) |
| **501 stub fixture** (controlled, `:18998`) | ❌ 6/10 FAIL, exit 1 — P08 dumps `501 Not Implemented: stub route`; P09 flags `POST /health → 501 (want 405)` |
| **Dead port** (`:18997`) | ❌ 9/10 FAIL, exit 1 — connection refused surfaces on every probe |
| Toolchain | `gofmt` clean, `go vet ./...` clean, `go build` clean (go 1.26) |

Edge cases tested: transient-vs-persistent stub marker (observed the real flake once; confirm-retry clears it, persistence still fails with line-level diagnostics), content-type enforcement, timestamp staleness window, 405-vs-501 on wrong method, 404-vs-501 on unknown routes, and env-overridable base URL for controlled negative tests.
{"model": "deepseek-v4-flash", "problem_class": "go-e2e-api-battery", "result": "passed", "tests": 10}
Generated from the verified corpus · MIT licensedBack to the catalog