style: clear the last lint findings on #55's code

- goconst: extracted testVariantKeyTwo alongside testVariantKeyOne.
- paralleltest: t.Parallel() on
  TestEvictSourceBlobExcludesConcurrentStoreOfIdenticalContent. The test
  asserts that a concurrent store stays blocked for 200ms while eviction
  holds the content lock; parallel load can only make it more blocked,
  never less, so the assertion does not become timing-fragile. Verified
  over repeated full -race runs.
- gosec G115: a live, justified suppression on the int64 conversion in
  ComputeDefaultCacheMaxBytes. The preceding clamp was an explicit
  if-statement that gosec could follow; the modernize linter requires it
  to be min(), which gosec's range analysis cannot see through. The
  clamp is still there and still correct, so the conversion cannot
  overflow. Unlike the directives removed earlier in this branch, this
  one is live: nolintlint confirms it suppresses a finding that is
  actually raised.
This commit is contained in:
2026-08-09 13:39:49 +00:00
parent da54083a59
commit 70d96cebac
2 changed files with 17 additions and 7 deletions

View File

@@ -66,6 +66,10 @@ func ComputeDefaultCacheMaxBytes(
computed := freeBytes / freeSpaceFractionDenominator * freeSpaceFractionNumerator computed := freeBytes / freeSpaceFractionDenominator * freeSpaceFractionNumerator
computed = min(computed, math.MaxInt64) computed = min(computed, math.MaxInt64)
// gosec cannot see that min() above bounds computed, so it reads
// this conversion as potentially overflowing. It cannot: computed is
// at most math.MaxInt64 on every path here.
//nolint:gosec // G115: clamped to MaxInt64 by min above
limit := int64(computed) limit := int64(computed)
limit = max(limit, DefaultCacheMaxBytesFloor) limit = max(limit, DefaultCacheMaxBytesFloor)

View File

@@ -20,9 +20,13 @@ import (
// implementation writes. // implementation writes.
const sqliteTimestampFormat = "2006-01-02 15:04:05" const sqliteTimestampFormat = "2006-01-02 15:04:05"
// testVariantKeyOne is the variant cache key reused across the eviction // testVariantKeyOne and testVariantKeyTwo are the variant cache keys
// tests as the first stored variant. // reused across the eviction tests as the first and second stored
const testVariantKeyOne VariantKey = "aabbccdd0001" // variants.
const (
testVariantKeyOne VariantKey = "aabbccdd0001"
testVariantKeyTwo VariantKey = "aabbccdd0002"
)
// evictionTestDB creates an in-memory SQLite database with the real // evictionTestDB creates an in-memory SQLite database with the real
// production schema, limited to a single connection so the background // production schema, limited to a single connection so the background
@@ -287,7 +291,7 @@ func TestUsageBytesAccountsSourceAndVariantBytes(t *testing.T) {
bytes.Repeat([]byte{0xAB}, 2000)) bytes.Repeat([]byte{0xAB}, 2000))
storeEvictionTestVariant(t, cache, testVariantKeyOne, storeEvictionTestVariant(t, cache, testVariantKeyOne,
bytes.Repeat([]byte{0xAC}, 500)) bytes.Repeat([]byte{0xAC}, 500))
storeEvictionTestVariant(t, cache, "aabbccdd0002", storeEvictionTestVariant(t, cache, testVariantKeyTwo,
bytes.Repeat([]byte{0xAD}, 250)) bytes.Repeat([]byte{0xAD}, 250))
usage, err := cache.UsageBytes(context.Background()) usage, err := cache.UsageBytes(context.Background())
@@ -336,7 +340,7 @@ func TestEvictToLimitEvictsLeastRecentlyUsedFirst(t *testing.T) {
now := time.Now() now := time.Now()
keys := []VariantKey{ keys := []VariantKey{
testVariantKeyOne, "aabbccdd0002", "aabbccdd0003", "aabbccdd0004", testVariantKeyOne, testVariantKeyTwo, "aabbccdd0003", "aabbccdd0004",
} }
fills := []byte{0x01, 0x02, 0x03, 0x04} fills := []byte{0x01, 0x02, 0x03, 0x04}
ages := []time.Duration{4 * time.Hour, 3 * time.Hour, 2 * time.Hour, 1 * time.Hour} ages := []time.Duration{4 * time.Hour, 3 * time.Hour, 2 * time.Hour, 1 * time.Hour}
@@ -652,7 +656,7 @@ func TestEvictionRunsUnderWritePressure(t *testing.T) {
cache.StartEviction(time.Hour) cache.StartEviction(time.Hour)
defer cache.StopEviction() defer cache.StopEviction()
keys := []VariantKey{testVariantKeyOne, "aabbccdd0002", "aabbccdd0003"} keys := []VariantKey{testVariantKeyOne, testVariantKeyTwo, "aabbccdd0003"}
fills := []byte{0x11, 0x12, 0x13} fills := []byte{0x11, 0x12, 0x13}
for i, key := range keys { for i, key := range keys {
@@ -683,7 +687,7 @@ func TestEvictionRunsOnPeriodicSchedule(t *testing.T) {
cache.StartEviction(100 * time.Millisecond) cache.StartEviction(100 * time.Millisecond)
defer cache.StopEviction() defer cache.StopEviction()
keys := []VariantKey{testVariantKeyOne, "aabbccdd0002", "aabbccdd0003"} keys := []VariantKey{testVariantKeyOne, testVariantKeyTwo, "aabbccdd0003"}
fills := []byte{0x21, 0x22, 0x23} fills := []byte{0x21, 0x22, 0x23}
for i, key := range keys { for i, key := range keys {
@@ -860,6 +864,8 @@ func TestPeriodicReconciliationAdoptsFileThatAppearsAfterStartup(t *testing.T) {
// mid-unlink, and must not lose its own store once eviction has fully // mid-unlink, and must not lose its own store once eviction has fully
// released the content hash. // released the content hash.
func TestEvictSourceBlobExcludesConcurrentStoreOfIdenticalContent(t *testing.T) { func TestEvictSourceBlobExcludesConcurrentStoreOfIdenticalContent(t *testing.T) {
t.Parallel()
cache, _ := newEvictionTestCache(t, 1<<30) cache, _ := newEvictionTestCache(t, 1<<30)
ctx := context.Background() ctx := context.Background()