From c2f0345e18c20ed5ff2bb183822155a8afafc5c7 Mon Sep 17 00:00:00 2001 From: Simon Chrzanowski Date: Sun, 8 Nov 2026 18:56:24 +0100 Subject: [PATCH] Pick up the follow-ups from the #676 and #680 reviews The repeated dist-tags name in the jsontext test now has a different first value, so the test checks that the last one counts. Comments that repeat the code go, and the upload-pack paragraph states its check rule once. --- docs/configuration.md | 8 +++----- internal/gitcache/relay.go | 3 +-- internal/metadata/npm/stream.go | 6 ++---- internal/metadata/npm/stream_test.go | 2 +- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 6eceb334..868aeb5c 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -904,11 +904,9 @@ confirmed. A repository the upstream reports missing (404), refuses (401, 403) or redirects is not served from the cache, also to requests that skip the ref listing and go straight to `git-upload-pack`, until a later check succeeds. Redirects are never followed, so point the upstream at a repository's current -location. A `git-upload-pack` request does not check the upstream itself -unless the upstream refused the repository at the last check or the copy was -last checked more than a minute past `stale_max_age` ago, so the requests of a -clone that follow its ref listing check nothing again; otherwise the -repository is checked first, as for a ref listing. +location. A `git-upload-pack` request checks the upstream only when the last +check refused the repository or the copy was last checked more than a minute +past `stale_max_age` ago, so a clone checks once, at its ref listing. The proxy runs `git` 2.31 or newer, which must be installed (the Docker image includes it). The `git` processes never reach the network themselves: their fetches go diff --git a/internal/gitcache/relay.go b/internal/gitcache/relay.go index bd65b255..468879c0 100644 --- a/internal/gitcache/relay.go +++ b/internal/gitcache/relay.go @@ -39,8 +39,7 @@ type relay struct { type relayRoute struct { repoURL string - // ctx ends when the fetch does, which stops its relayed requests, so a - // git helper left behind by a killed git does not keep downloading. + // ctx ends when the fetch does. ctx context.Context // limit caps the response bytes the route relays, 0 for no cap, and // budget, when set, holds space within MaxSize for them. exceeded and diff --git a/internal/metadata/npm/stream.go b/internal/metadata/npm/stream.go index b00f6a23..aac40717 100644 --- a/internal/metadata/npm/stream.go +++ b/internal/metadata/npm/stream.go @@ -274,8 +274,7 @@ func decodeValue(dec *jsontext.Decoder, v any) error { return json.Unmarshal(raw, v) } -// objectKeys reads a value and returns its keys when it is an object. The -// members' values are skipped without being kept. +// objectKeys reads a value and returns its keys when it is an object. func objectKeys(dec *jsontext.Decoder) ([]string, bool, error) { kind := dec.PeekKind() if kind != '{' && kind != '[' { @@ -391,8 +390,7 @@ func LookupVersion(r io.Reader, version string) (VersionEntry, error) { } // objectMember reads a value and returns its member key when it is an object -// that has one, the last if repeated, or nil. Other members are skipped -// without being kept. +// that has one, the last if repeated, or nil. func objectMember(dec *jsontext.Decoder, key string) (json.RawMessage, error) { kind := dec.PeekKind() if kind != '{' && kind != '[' { diff --git a/internal/metadata/npm/stream_test.go b/internal/metadata/npm/stream_test.go index 0bd93ae0..620882da 100644 --- a/internal/metadata/npm/stream_test.go +++ b/internal/metadata/npm/stream_test.go @@ -230,7 +230,7 @@ func TestLookupVersion(t *testing.T) { // invalid UTF-8 in strings, and a version entry's bytes kept as they are. func TestStreamReadsJSONAsEncodingJSON(t *testing.T) { entry := "{ \"name\" : \"demo\",\n \"x\":1, \"x\":2, \"note\":\"caf\xe9\" }" - doc := "{\"readme\":\"bad \xff byte\",\"meta\":{\"k\":1,\"k\":2},\"dist-tags\":{\"latest\":\"1.0.0\",\"latest\":\"1.0.0\"}," + + doc := "{\"readme\":\"bad \xff byte\",\"meta\":{\"k\":1,\"k\":2},\"dist-tags\":{\"latest\":\"0.9.0\",\"latest\":\"1.0.0\"}," + "\"versions\":{\"1.0.0\":" + entry + "},\"time\":{\"1.0.0\":\"2020-01-01T00:00:00Z\"}}\n" if !json.Valid([]byte(strings.ToValidUTF8(doc, "?"))) { t.Fatal("test document isn't JSON")