test(metadata): harden Retry-After clamp boundary + log tests (bookshelf-8oj1) #1026
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "bd-bookshelf-8oj1"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
ParseRetryAfter(confirmingclamped=falsewhen value equals cap exactly — the>vs>=correctness verified by 0sha refactor)googlebooks/ratelimit_test.gopinning theretry_after_clampedfield: set for values > cap (9999), set for overflow input (1e300), absent for value == cap (60)Test plan
go test ./internal/metadata/...passes (all new tests green)Closes bead bookshelf-8oj1 on merge.
CODE REVIEW: APPROVED — 0 blocker, 0 major, 1 minor
Phase 0: DEMO Verification
This PR is test-only (no production code); the "DEMO" is CI green. Verified via diff inspection per the review-standard instructions (no test re-run).
Phase 1: Spec Compliance
Truly test-only confirmed. Diff touches exactly two files, both
*_test.go:internal/metadata/provider_helpers_test.gointernal/metadata/googlebooks/ratelimit_test.goNo production file changed. Scope is correct.
All four cases from the bead description are covered:
ParseRetryAfter("60", MaxRetryAfterWait)→(MaxRetryAfterWait, false)—provider_helpers_test.gonew ItRetry-After: 9999→retry_after_clampedpresent in log —ratelimit_test.gonew Describe #1Retry-After: 1e300→retry_after_clampedpresent in log —ratelimit_test.gonew Describe #2Retry-After: 60→retry_after_clampedabsent from log —ratelimit_test.gonew Describe #3Phase 2: Code Quality
Boundary correctness — verified against production code
provider_helpers.go:57:if secs > maxSecs { return capDur, true }— strictly greater-than."60"→secs=60.0,maxSecs=60.0→60 > 60= false → returns(60s, false)✓ test assertsclamped=BeFalse()✓"9999"→9999 > 60= true → returns(60s, true)✓ test asserts field present ✓"1e300"→1e300 > 60= true (no overflow, comparison is in float64 space) →(60s, true)✓ test asserts field present ✓All three boundary cases are semantically correct.
Log field assertions — meaningful, not vacuous
ratelimit_test.go(new Describe #3, Retry-After=60):NotTo(ContainSubstring("retry_after_clamped"))could pass vacuously if no Warn was ever logged. Verified it cannot:handle429always emitslogger.Warn("google books: retryable status", ...)before callingSleepWithContext— the log line is written unconditionally before the sleep that times out. The buffer will contain the Warn entry (just without the clamped field). Assertion is meaningful. ✓ContainSubstring("retry_after_clamped")on slog JSON output: the key nameretry_after_clampedis unique —"retry_after"does not contain"retry_after_clamped"as a substring. No false-positive risk from the shorter sibling field. ✓Black-box / package declarations
provider_helpers_test.go:package metadata_test✓ratelimit_test.go:package googlebooks_test✓Both black-box. No unexported symbols referenced. ✓
No coverage exclusions or golangci changes
No exclusion list edits anywhere in the diff. ✓
[MINOR]
internal/metadata/provider_helpers_test.gonew boundary It — two separateExpectcalls in oneItblock (Expect(d).To(...)thenExpect(clamped).To(BeFalse())). Per project conventions, eachItshould assert exactly one behavior; the boundary test should be split: oneItford == MaxRetryAfterWaitand oneItforclamped == false. Note: this pattern already exists in the same file at the "caps at capDur" and "does not clamp when value is within cap" Its — the new test follows established (but non-compliant) file convention. No correctness impact; does not block.REVIEW VERDICT: 0 blocker, 0 major, 1 minor
e4ff89a6224a500635e5