Repository navigation
test(cache): de-flake TestGetNarInfoOpaqueUpstreamURL size assert - #1349
Conversation
The first GetNar in TestGetNarInfoOpaqueUpstreamURL asserted the exact NAR size, but GetNar legitimately returns -1 (size unknown) when it serves the bytes via the live-streaming path while the upstream download is still in flight (cache.go:1449). Which path it takes is timing- dependent, so under CPU contention (parallel integration cohorts) the assertion failed with 'expected 50308, actual -1' even though the streamed bytes were always correct. Accept either the concrete file size or -1 and keep the authoritative byte-equality check, mirroring the post-eviction re-fetch a few lines below that already handled this. Reproduced deterministically under load before; 80x -race runs under full CPU load pass after. Also fold in OpenSpec change fix-flaky-opaque-upstream-nar-size: - nar-concurrent-streaming: document the GetNar -1 size contract. - api-surface: correct the stale Cache.GetNar / NarStore / NarInfoStore signatures to match the real code (no behavior change). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Sync the change's delta specs into the canonical specs and move the change to openspec/changes/archive/2026-06-07-fix-flaky-opaque-upstream-nar-size: - nar-concurrent-streaming: documents the GetNar -1 (size unknown) streaming contract. - api-surface: corrects the stale Cache.GetNar / NarStore / NarInfoStore signatures to match the real code. Satisfies the openspec-guard (no active changes remain). Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
This change is part of the following stack: Change managed by git-spice. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (9)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis PR documents and fixes a flaky test for NAR (Nix Archive) cache operations. The test ChangesNAR GetNar Size Flakiness and Specification
🎯 2 (Simple) | ⏱️ ~12 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
Code Review
This pull request addresses a flaky test (TestGetNarInfoOpaqueUpstreamURL) in pkg/cache/cache_test.go by relaxing the exact size assertion to accept either the concrete NAR file size or the -1 sentinel value, which is returned when streaming an in-flight upstream download. It also documents this behavior in the nar-concurrent-streaming specification and updates stale signatures for Cache.GetNar, NarStore, and NarInfoStore in the api-surface specification. No review comments were provided, so there is no feedback to address.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
Documentation Updates 1 document(s) were updated by changes in this PR: NAR File Download and StreamingView Changes@@ -18,7 +18,7 @@
func (c *Cache) GetNar(ctx context.Context, narURL nar.URL) (nar.URL, int64, io.ReadCloser, error)
```
-The returned `nar.URL` contains the `TransparentZstd` flag indicating whether the server was able to serve compressed data directly.
+The returned `nar.URL` contains the `TransparentZstd` flag indicating whether the server was able to serve compressed data directly. The `int64` size can be `-1` (size unknown) when live-streaming an in-flight download, or the concrete `nar_files.file_size` when serving from local storage or completed chunks. Consumers must handle both cases; the streamed bytes are always correct regardless of the size value.
**CDC Chunks and Transparent Compression:**
|
Summary
TestGetNarInfoOpaqueUpstreamURLflaked in CI withcache_test.go:529 expected: 50308, actual: -1. The firstGetNarasserted the exact NAR size, butGetNarlegitimately returns-1(size unknown) when it serves bytes via the live-streaming path while the upstream download is still in flight (cache.go:1449). Which path it takes is timing-dependent, so under CPU contention (parallel integration cohorts) the assertion failed even though the streamed bytes were always correct.pkg/cache/cache_test.go): accept either the concrete file size or-1, keeping the authoritative byte-equality check — mirroring the post-eviction re-fetch just below that already handled this.nar-concurrent-streaming): document theGetNar-1streaming size contract so it's explicit and testable.api-surface): correct the staleCache.GetNar/NarStore/NarInfoStoresignatures to match the real code (the block also omittedStatNar/WalkNarsand listed a phantomGetNarSize). Docs only — no behavior change.OpenSpec change archived as
2026-06-07-fix-flaky-opaque-upstream-nar-size; canonical specs synced.Test plan
go test ./pkg/cache -run '^TestGetNarInfoOpaqueUpstreamURL$' -count=60 -raceunder full CPU saturation →expected 50308, actual -1.-raceruns under full CPU load →ok.task fmt(0 changed),task lint(0 issues),task test(pass).openspec validate --specs→ 33 passed, 0 failed.