shouldCacheResponse is the pure policy function the guard uses to decide between Complete (cache) and Release (free for retry). Exhaustive matrix.
(t *testing.T)
| 9 | // decide between Complete (cache) and Release (free for retry). |
| 10 | // Exhaustive matrix. |
| 11 | func TestShouldCacheResponse(t *testing.T) { |
| 12 | cases := []struct { |
| 13 | name string |
| 14 | status int |
| 15 | sideEff bool |
| 16 | wantCache bool |
| 17 | }{ |
| 18 | {"200 + no side effect → cache", 200, false, true}, |
| 19 | {"202 (HITL held) + no side effect → cache", 202, false, true}, |
| 20 | {"302 redirect + no side effect → cache", 302, false, true}, |
| 21 | {"400 + no side effect → release", 400, false, false}, |
| 22 | {"422 + no side effect → release", 422, false, false}, |
| 23 | {"500 + no side effect → release", 500, false, false}, |
| 24 | {"503 + no side effect → release", 503, false, false}, |
| 25 | |
| 26 | // The new behavior: once the side effect committed, even error |
| 27 | // responses must be cached so a retry can't re-trigger the |
| 28 | // side effect. The 500 here is from a panic recovery / |
| 29 | // post-send failure; we MUST NOT release. |
| 30 | {"200 + side effect committed → cache", 200, true, true}, |
| 31 | {"400 + side effect committed → cache (defensive)", 400, true, true}, |
| 32 | {"500 + side effect committed → cache (no double-send)", 500, true, true}, |
| 33 | {"503 + side effect committed → cache (no double-send)", 503, true, true}, |
| 34 | } |
| 35 | for _, c := range cases { |
| 36 | t.Run(c.name, func(t *testing.T) { |
| 37 | if got := shouldCacheResponse(c.status, c.sideEff); got != c.wantCache { |
| 38 | t.Errorf("shouldCacheResponse(%d, %v) = %v, want %v", c.status, c.sideEff, got, c.wantCache) |
| 39 | } |
| 40 | }) |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | // markSideEffectCommitted is a no-op when the writer isn't a |
| 45 | // capturingWriter (no-header path or replay path). Verify it doesn't |
nothing calls this directly
no test coverage detected