From 61f5d637a44e5a51a82fb292aeff4ca5d141d801 Mon Sep 17 00:00:00 2001 From: DAVID AMID Date: Thu, 3 Sep 2026 20:41:43 +0300 Subject: [PATCH] test(proxy): make the dangling-marker assertion baseline-relative, not absolute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #188 added a third instance of the defect #192 documents, and it is mine. TestAnExhaustedRewindReserveNeitherStampsUnbackedMarkersNorHidesItself asserted `snap.StashMissing != 0` as an ABSOLUTE value. StashMissing is a process-wide counter shared with every test in the binary, and TestStatsPublishesDanglingReplaysFromTheLiveCounter — added in the same PR, declared below it in the same file — deliberately drives it non-zero. So the assertion passed on the first run and failed on the second: go test ./proxy/ -run "TestAnExhaustedRewindReserve|TestStatsPublishesDangling" -count=2 --- FAIL: TestAnExhaustedRewindReserveNeitherStampsUnbackedMarkersNorHidesItself /stats stash_missing = 1 in a fixture where every refusal left the content verbatim; a declined removal is being counted as a dangling marker The message was even accurate about its own confusion: on the second run a DIFFERENT test's dangling marker was being read as this fixture's. Now baseline-relative — captured before the request this fixture makes, so the assertion measures what the fixture did rather than what the binary has accumulated. Other tests in the same file were already written this way (StashRefusals, and the live-counter comparison below); this one was not, which is the whole of the defect. Verification: gofmt -l . clean, go vet ./... clean, go test ./... all packages pass, and the two tests now pass at -count=2. Revert-verified: restoring the absolute form fails at -count=2 with /stats stash_missing moved by 1 in a fixture where every refusal left the content verbatim The first cut of that mutation did not compile — reverting the assertion left `missingBefore` unused — so it was re-cut with `_ = missingBefore` to fail as a TEST rather than as a build error. A mutation that breaks the build is not a caught mutation. #192's count is accurate again: at -count=2 the proxy package now fails only on TestExtractEconomicsAreExported and TestExpandUnresolvedSeriesRender, which are the two pre-existing instances that issue describes. Signed-off-by: DAVID AMID Assisted-By: Claude Opus 5 (1M context) --- proxy/stashreserve_test.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/proxy/stashreserve_test.go b/proxy/stashreserve_test.go index 2cd9cb6b..9d44ffbe 100644 --- a/proxy/stashreserve_test.go +++ b/proxy/stashreserve_test.go @@ -71,6 +71,9 @@ func TestAnExhaustedRewindReserveNeitherStampsUnbackedMarkersNorHidesItself(t *t if err != nil { t.Fatal(err) } + // Captured before the request, so the dangling-marker assertion below measures what THIS + // fixture did rather than what the whole test binary has accumulated. + missingBefore := offloadStashMissing() resp, err := http.Post(srv.URL+"/openai/v1/chat/completions", "application/json", strings.NewReader(string(body))) if err != nil { t.Fatal(err) @@ -158,9 +161,14 @@ func TestAnExhaustedRewindReserveNeitherStampsUnbackedMarkersNorHidesItself(t *t t.Error(`/stats does not render a "stash_missing" key, so the one reserve outcome that ` + `genuinely breaks reversibility is indistinguishable from the safe one`) } - if snap.StashMissing != 0 { - t.Errorf("/stats stash_missing = %d in a fixture where every refusal left the content "+ - "verbatim; a declined removal is being counted as a dangling marker", snap.StashMissing) + // BASELINE-RELATIVE, because StashMissing is a PROCESS-WIDE counter shared with every other + // test in this binary — TestStatsPublishesDanglingReplaysFromTheLiveCounter below deliberately + // drives it non-zero. An absolute `!= 0` therefore passed on the first run and failed on the + // second under -count=2, which is the class of defect #192 already documents; this assertion + // was a third instance of it. + if got := snap.StashMissing - missingBefore; got != 0 { + t.Errorf("/stats stash_missing moved by %d in a fixture where every refusal left the "+ + "content verbatim; a declined removal is being counted as a dangling marker", got) } }