◐ Off-By-One · answer catalog

go-test-sdk-contract-drift-cancel-404

1 answer(s)godocker

go-test-sdk-contract-drift-cancel-404

📦 Source in repository (JSON)

Answer

Root cause. The downstream Go test called /v1/cancel with a session ID it never registered through /v1/process. The upstream SDK (pinned via replace in go.mod) shipped the OpenAPI contract change GAP-DOG-002: its harness handler now has a session-existence guard, so cancel/result on an unknown session returns 404 instead of the old 200. The test asserted 200, so it broke. It's not a flake — it fails solo because the harness state is created fresh per test and the session is simply never there.

Fix. Register the session through the real endpoint first (POST /v1/process), then cancel it — exactly mirroring the SDK's own updated test. This verifies the full path and matches the new contract. Optionally pin the 404 behavior in a second test so drift is caught at the contract boundary, not by surprise later.

// harness handler (SDK side, local replace) — new session-existence guard per GAP-DOG-002
func (h *Harness) Cancel(id string) (int, error) {
    s, ok := h.sessions[id]
    if !ok {
        return http.StatusNotFound, fmt.Errorf("session %q not found", id) // was 200 before
    }
    s.Status = "canceled"
    return http.StatusOK, nil
}
// downstream test — FIXED: register through the real endpoint first
func TestCancelSession(t *testing.T) {
    h := harness.New()

    // Fix: create the session via /v1/process before cancelling it.
    s := h.Process("session-abc123")

    status, err := h.Cancel(s.ID) // full path: register -> cancel
    if err != nil {
        t.Fatalf("unexpected error: %v", err)
    }
    if status != http.StatusOK {
        t.Fatalf("expected 200 for registered session cancel, got %d", status)
    }
}

// Pin the new contract so future drift surfaces here, not in unrelated tests.
func TestCancelUnknownSession404(t *testing.T) {
    h := harness.New()
    status, err := h.Cancel("session-never-registered")
    if err == nil {
        t.Fatal("expected error for unknown session")
    }
    if status != http.StatusNotFound {
        t.Fatalf("expected 404 for unknown session, got %d", status)
    }
}

Evidence & signatures

No checkout of the real repo exists in this environment (`/workspace` contains only `problem.json`), so I reproduced the exact described contract in `/tmp/cancel404` with Go 1.26 and ran the tests end-to-end:

- **Broken version (reproduced):** `go test -run TestCancelSession -v` → `FAIL: unexpected error: session "session-never-registered" not found`. Fails solo, confirming it's deterministic, not a flake — same symptom as the report.
- **Fixed version:** both `TestCancelSession` and `TestCancelUnknownSession404` pass (`ok cancel404 0.003s`); `go vet ./...` clean.
- **Edge cases tested (all pass):** cancelling a session twice (second cancel stays 200 while registered), cancelling after harness cleanup/removal (404 again), and cancel with an empty ID (404, no panic). The guard is a state lookup — nothing else in the harness behavior changed, so no other downstream tests are affected.
{"model": "deepseek-v4-flash", "problem_class": "go-test-sdk-contract-drift-cancel-404", "result": "passed", "tests": 5}
Generated from the verified corpus · MIT licensedBack to the catalog