Skip to content

cmd/ncps: Implement urfave/cli and the serve command - #1

Merged
kalbasit merged 36 commits into
mainfrom
first-version
Dec 1, 2024
Merged

kalbasit merged 36 commits into
mainfrom
first-version

Conversation

@kalbasit

Copy link
Copy Markdown
Owner

No description provided.

* main:
  GitHub: Configure CI and Docker workflows
  docker: add support for building Docker image
* main:
  cache: create the cache package auto-generating secretKey if not found (#2)
* main:
  cache/upstream: Create an upstream cache package (#3)
  nixcacheinfo: Create a parser to parse NixCacheInfo (#5)
  devbox: Prefer double quotes
  GitHub: Remove dead code
  GitHub: Use the same Go version as we have in Nix
  GitHub: Improve the CI test
  GitHub: Disable build for multiple platforms
  golangci-lint: Enable many of the linters (#4)
  devbox: install golangci-lint at its latest version
  GitHub: Configure action to run golangci-lint
* main:
  cache: Implement GetNar() and GetNarInfo() (#8)
  helper: Add a helper to compute path of narInfo and nar (#7)
  cache: take in upstream caches and sort them by priority (#6)
* main:
  server: create a new server to serve from cache (#9)
@kalbasit kalbasit changed the title treewide: First fully working version cmd/ncps: Implement urfave/cli and the serve command Dec 1, 2024
@kalbasit
kalbasit enabled auto-merge (squash) December 1, 2024 22:46
@kalbasit
kalbasit merged commit 9588b68 into main Dec 1, 2024
@kalbasit
kalbasit deleted the first-version branch December 1, 2024 23:02
kalbasit added a commit that referenced this pull request May 24, 2026
## Summary

Three pre-existing `pkg/cache` flakes from #1247 share one root cause:
assertions that race against absolute wall-clock time and break under CI
load even when the production code is correct. Surfaced repeatedly
during the lean-flake-check measurement runs in #1249 (which sits
stacked on top of this branch).

All three fixes are **test-only**. No production code is touched.

## What changed

| Flake (from #1247) | Test | Before | After |
| --- | --- | --- | --- |
| #5 |
`TestCDCBackends/{SQLite,MySQL}/first_pull_completes_before_CDC_chunking_finishes`
| `assert.Less(elapsed, 500ms)` racing the slow chunker | Happens-before
check: `select { case <-chunkingStarted: t.Fatal(…) }` after
`io.ReadAll`. `slowChunker` grew an optional `started chan struct{}`
closed when its delay expires. Delay bumped 500 ms → 10 s (only matters
under regression). |
| #1 | `TestCacheBackends/MySQL/PutNarInfoDeadlock` |
`context.WithTimeout(2s)` then `assert.NoError`. Could not distinguish
"deadlock" from "MariaDB slow." | Timeout bumped 2 s → 60 s. A real
deadlock still fails fast; non-deadlocked slow path now passes. |
| #2 | Six instances of `assert.WithinDuration(CreatedAt,
LastAccessedAt, 2s)` across `TestCacheBackends` | 2 s tolerance was
tight enough that two CLOSE-TO-NOW() timestamps from different SQL
operations under MariaDB load could fall outside it (observed -3 s
spread). | Tolerance bumped 2 s → 30 s. Still tight enough to catch a
genuinely broken "set both timestamps at row creation" semantic. |

## Why "test-only" and not "fix the production bug"

These three are *measurement bugs*: the assertions encode an assumption
("operation X completes within Y milliseconds") that's an artifact of
the dev host's speed, not a property the codebase ever promised. The
behavior the tests *want* to verify (no deadlock, timestamps set close
together at creation, GetNar doesn't block on chunking) is still being
verified — the encoding is just no longer wall-clock-dependent.

Flakes #3 and #4 from #1247 are NOT addressed here because they are not
the same shape:

- **#3** (`ConcurrentDownloadCancelOneClientOthersContinue`, 20-min
hang) is a real hang in `io.ReadAll(readerB)` or `wg.Wait()` after all
the existing 5–10 s guards have passed — almost certainly a
production-code bug in the shared-reader-fanout path. Filed as **#1252**
for separate investigation.
- **#4** (`GetNarInfoConcurrentPutNarInfoDuringMigration`) exercises the
same concurrent-migration-vs-PutNarInfo window that the next test
(`testGetNarInfoMultipleConcurrentPutsDuringMigration`) explicitly
`t.Skip`s with `"blocked on pgx transaction-abort cascade in PutNarInfo
re-fetch path"`. That tracked production bug is the actual root cause;
this test exercising it less reliably isn't a separate issue.

## Stack

This PR is stacked under #1249 (`improve-flake-check-time`); landing
this first should unblock #1249's CI by eliminating three of the five
flakes that were causing intermittent reds.

```
main → fix-cache-test-timing-assertions (this PR, #1253)
     → improve-flake-check-time (#1249)
```

## Test plan

- [x] `nix develop -- go test -race -count=1 -run
"TestCDCBackends/SQLite/first_pull_completes_before_CDC_chunking_finishes"
./pkg/cache/` passes locally.
- [x] `nix develop -- go test -race -count=1 -run
"TestCacheBackends/SQLite/(PutNarInfoDeadlock|GetNarInfo/narinfo_exists_upstream/nar_does_exist)"
./pkg/cache/` passes locally.
- [x] `golangci-lint run` clean (run inside `nix develop` so the
toolchain resolves).

---------

Co-authored-by: Claude Opus 4.7 <[email protected]>
kalbasit added a commit that referenced this pull request Jun 1, 2026
## Summary

- Removes `ref: ${{ github.event.pull_request.head.sha }}` from the
`actions/checkout` step in the backport workflow
- `pull_request_target` runs with write access to secrets (needed to
create backport PRs); checking out the unreviewed fork head in this
context is a CodeQL high-severity finding (alert #1): a malicious fork
PR could place code that gets executed while the PAT is in scope
- The `korthout/backport-action` resolves commit SHAs via the GitHub API
— it does not require the PR branch to be the current HEAD; removing
`ref:` makes the checkout use the base branch (trusted, reviewed code)
instead

## Test plan

- [ ] Merge a PR with a `backport` label and verify the backport action
still creates the backport PR correctly

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant