◐ Off-By-One · answer catalog

go-e2e-stale-assertion-after-wiring

1 answer(s)godocker

go-e2e-stale-assertion-after-wiring

📦 Source in repository (JSON)

Answer

Root cause: U-GAP-008 replaced stub dispatch with real dispatch (jit echo → unwired ⇒ HTTP 501 NOT_IMPLEMENTED; llm → real provider), but the E2E battery still encoded the pre-wiring contract: it asserted the old stub body (handler_type: jit echo) and did pool lookups by app NAME even though the :appID route param is a UUID and rejects names with 404 POOL_NOT_FOUND by design. The battery wasn't stale about facts — it was asserting a contract that no longer existed.

Fix 1 — /execute jit echo: replace the body-shape assertion with the designed behavior. Asserting the machine-readable code (not free-text message) keeps the test robust to message rewording:

// BEFORE (stale) — expected the old stub payload
resp, body := doJSON(t, http.MethodPost, ts.URL+"/execute", map[string]any{
    "handler": "jit", "input": "echo", "payload": map[string]any{"x": 1},
})
if resp.StatusCode != http.StatusOK {
    t.Fatalf("status = %d, want 200 (body: %s)", resp.StatusCode, body)
}
var out struct {
    HandlerType string         `json:"handler_type"`
    Echo        map[string]any `json:"echo"`
}
json.Unmarshal(body, &out) // ...
if out.HandlerType != "jit echo" { t.Fatal(...) }

// AFTER (fixed) — designed behavior: HTTP 501 + code NOT_IMPLEMENTED
resp, body := doJSON(t, http.MethodPost, ts.URL+"/execute", map[string]any{
    "handler": "jit", "input": "echo", "payload": map[string]any{"x": 1},
})
expectCode(t, resp, body, http.StatusNotImplemented, CodeNotImplemented)

// shared helper — asserts status AND machine code, immune to message wording
func expectCode(t *testing.T, resp *http.Response, body []byte, wantStatus int, wantCode string) {
    t.Helper()
    if resp.StatusCode != wantStatus {
        t.Fatalf("status = %d, want %d (body: %s)", resp.StatusCode, wantStatus, body)
    }
    var eb struct{ Code string `json:"code"` }
    if err := json.Unmarshal(body, &eb); err != nil {
        t.Fatalf("decode error body %q: %v", body, err)
    }
    if eb.Code != wantCode {
        t.Fatalf("code = %q, want %q", eb.Code, wantCode)
    }
}

Fix 2 — pool-status by UUID, not name: the positive path keys off the UUID captured at creation; the name case is asserted as the designed rejection (documenting the contract instead of fighting it):

// BEFORE (stale) — name lookup expected 200
_ = createPool(t, ts.URL, "my-app")
resp, body := doJSON(t, http.MethodGet, ts.URL+"/pools/my-app/status", nil)
if resp.StatusCode != http.StatusOK { t.Fatalf(...) } // 404 POOL_NOT_FOUND by design

// AFTER (fixed) — UUID is the address; name → 404 POOL_NOT_FOUND is the contract
poolID := createPool(t, ts.URL, "my-app")                 // returns the UUID
resp, body := doJSON(t, http.MethodGet, ts.URL+"/pools/"+poolID+"/status", nil)
// ...assert 200 + pool.ID == poolID + status READY...
resp, body = doJSON(t, http.MethodGet, ts.URL+"/pools/my-app/status", nil)
expectCode(t, resp, body, http.StatusNotFound, CodePoolNotFound) // by design

Evidence & signatures

Verified against a live reproduction (`/tmp/ugap008-repro`, Go 1.26, stdlib only): post-wiring server (real `llm` provider dispatch, `jit echo` → `501 NOT_IMPLEMENTED`, `GET /pools/{appID}/status` with `:appID` = UUID) + the 7-test battery.

1. **Stale battery reproduces the exact false-fails** — only the two stale assertions fail:
   - `TestExecuteJITEchoReturnsNotImplemented`: `status = 501, want 200` (`{"code":"NOT_IMPLEMENTED",...}`)
   - `TestPoolStatusByNameRejectedByDesign`: `status = 404, want 200` (`{"code":"POOL_NOT_FOUND","message":"...appID must be a UUID"...}`)
2. **After the fix:** `go test -v ./...` → **7/7 PASS** (LLM provider, jit echo 501, unknown jit op 404, pool status by UUID, name rejected, unknown UUID 404, health).
3. **Tooling clean:** `go vet ./...` clean, `gofmt -l` empty, `go test -race -count=1 ./...` → `ok` (no cache-dependent results).
4. **Edge cases tested:**
   - `jit echo` → 501 `NOT_IMPLEMENTED`; unknown `jit` op → 404 `NOT_FOUND` (echo-only unwiring).
   - Pool status: valid UUID → 200 `READY`; app **name** → 404 `POOL_NOT_FOUND` (by design); unknown/malformed UUID → 404 `POOL_NOT_FOUND`.
   - `llm` handler → 200 with `handler_type: llm`, `provider: openai`, and provider-generated output prefix (not the old stub echo body).
   - Error assertions check status + `code` field, never free-text `message`, so battery stays green across message edits.
{"model": "deepseek-v4-flash", "problem_class": "go-e2e-stale-assertion-after-wiring", "result": "passed", "tests": 7}
Generated from the verified corpus · MIT licensedBack to the catalog