From 0eb72981e0c236251ab5f51a2025e027166fe198 Mon Sep 17 00:00:00 2001 From: zheli <157039+zheli@users.noreply.github.com> Date: Tue, 10 Nov 2026 14:43:45 +0000 Subject: [PATCH 1/5] chore: catalogue new Splice versions --- internal/splice/versions.json | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/internal/splice/versions.json b/internal/splice/versions.json index 3393b80e..2573f098 100644 --- a/internal/splice/versions.json +++ b/internal/splice/versions.json @@ -3,6 +3,20 @@ "_comment": "Maintainer flow: scripts/add-splice-version.sh resolves the tag → commit, downloads the archive, computes ContentSHA, and appends an entry here. Reviewer checks the diff before merging.", "latest_alias": "0.8.1", "versions": [ + { + "tag": "0.10.0", + "commit": "4dc85cc2eb9b3451f5c38d992fa30ada958e80e8", + "content_sha": "d1e8c0a709c8f5d9254d08c56ccd073ee3a163dc807529138ba1a4fac3ccfdbb", + "size": 228432553, + "major": "0.10" + }, + { + "tag": "0.10.1", + "commit": "69260d05fafe4adca45b87b3fd49878b94328f8f", + "content_sha": "d1e8c0a709c8f5d9254d08c56ccd073ee3a163dc807529138ba1a4fac3ccfdbb", + "size": 228487041, + "major": "0.10" + }, { "tag": "0.5.18", "commit": "b162650cd18df5b96dddeffd9bd48be5b2ff37d7", From 2ca682a979524aad73884d9b8226032144fdf27a Mon Sep 17 00:00:00 2001 From: Zhe Li Date: Tue, 10 Nov 2026 16:42:06 +0100 Subject: [PATCH 2/5] fix(splice): set memory floors for the 0.10 major line New catalogue entries inherit no same-major floor until one tag is curated; pin 0.10.0 to the same 8/12 GiB thresholds as 0.9 so preflight gates and catalogue invariant tests pass. --- internal/splice/versions.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/splice/versions.json b/internal/splice/versions.json index 2573f098..b37215c5 100644 --- a/internal/splice/versions.json +++ b/internal/splice/versions.json @@ -8,7 +8,9 @@ "commit": "4dc85cc2eb9b3451f5c38d992fa30ada958e80e8", "content_sha": "d1e8c0a709c8f5d9254d08c56ccd073ee3a163dc807529138ba1a4fac3ccfdbb", "size": 228432553, - "major": "0.10" + "major": "0.10", + "min_memory_bytes": 8000000000, + "recommended_memory_bytes": 12000000000 }, { "tag": "0.10.1", From 28a33c61ff3451fefa52d9576bb0edf06c32cb2e Mon Sep 17 00:00:00 2001 From: Zhe Li Date: Tue, 10 Nov 2026 21:22:29 +0100 Subject: [PATCH 3/5] fix(splice): default memory floors in code, overrides in JSON Refresh PRs for new majors should not require hand-edited floors; use 4/6 GB code defaults and keep JSON only when a release line needs a different gate. --- docs/limitations.md | 12 ++--- docs/versions.md | 14 ++--- internal/splice/versions.go | 92 ++++++++++++++------------------ internal/splice/versions.json | 4 +- internal/splice/versions_test.go | 54 ++++++------------- 5 files changed, 71 insertions(+), 105 deletions(-) diff --git a/docs/limitations.md b/docs/limitations.md index 925c4cc8..1ca4573d 100644 --- a/docs/limitations.md +++ b/docs/limitations.md @@ -83,12 +83,12 @@ resolved. 16 GB Mac). Bump via Settings → Resources before running multi-instance scenarios. - The preflight check enforces a per-version hard floor: 8 GB for the - 0.6, 0.7, and 0.8 lines (and any uncurated tag on those majors, which - inherits the strictest catalogued floor for its major), 4 GB for - 0.5.18 and only for tags whose major has no catalogued entry. The 12 GB figure is the coded recommendation - threshold (`recommended_memory_bytes`) — below it preflight WARNs - but does not refuse. + The preflight check uses code defaults of 4 GB minimum and 6 GB + recommended. Catalogue entries may override those per release line + (today 8 GB min / 12 GB recommended for the 0.6+ lines); tags with + no override of their own inherit the largest same-major override, + otherwise the code defaults. Below the recommended threshold + preflight WARNs but does not refuse. On timeout, `WaitForHealthy` now dumps the last `docker compose ps` snapshot in its error so the stuck service + state are visible diff --git a/docs/versions.md b/docs/versions.md index d141db09..013e6461 100644 --- a/docs/versions.md +++ b/docs/versions.md @@ -57,8 +57,8 @@ the canonical name in code and docs. | `content_sha` | `scripts/compute-tree-sha.sh` | SHA-256 over the extracted `cluster/compose/localnet/` subtree (sorted by path). Stable across upstream gzip-envelope rewrites; this is the authoritative integrity check at fetch time. | | `size` | byte count of the source-tarball | Informational; used to print a hint before download and to size the in-flight body cap. | | `major` | first two segments of `tag` (or set manually for branch tags) | Routes to the per-major Splice adapter for that release line. | -| `min_memory_bytes` | empirically derived per release line (see `versions.go`) | Minimum Docker daemon memory the version needs to start cleanly; the pre-flight memory gate refuses to `up` below it. `0` / absent inherits the strictest catalogued floor for the same major line; the global 4 GB floor applies only when the major has no catalogued entry at all. | -| `recommended_memory_bytes` | empirically derived per release line (see `versions.go`) | The value at which the version runs without resource warnings; surfaced as the "raise Docker memory to ≥ N" remediation hint when the minimum passes but this threshold is not met. | +| `min_memory_bytes` | override only (see `versions.go`) | Optional. Minimum Docker daemon memory the version needs to start cleanly; the pre-flight memory gate refuses to `up` below it. Omit when the line matches the code default (4 GB). When set, later tags in the same major inherit the largest override; otherwise the code default applies. | +| `recommended_memory_bytes` | override only (see `versions.go`) | Optional. The value at which the version runs without resource warnings; surfaced as the "raise Docker memory to ≥ N" remediation hint when the minimum passes but this threshold is not met. Omit when the line matches the code default (6 GB). Same-major inheritance matches `min_memory_bytes`. | | `channel` *(optional)* | catalogue maintainer | `""` / `"stable"` → production-ready; `"alpha"` → opt-in pre-release (Token Standard V2 snapshot etc.). `up` prints a one-line warning when an alpha entry is selected. | | `image_repo` *(optional)* | catalogue maintainer | Overrides the default Docker image repository. Defaults to `ghcr.io/digital-asset/decentralized-canton-sync/docker`. Set to `ghcr.io/digital-asset/decentralized-canton-sync-dev/docker` for the V2 alpha track. The v06 adapter forwards this as the `IMAGE_REPO` compose env. | | `image_tag` *(optional)* | catalogue maintainer | Overrides the Docker image tag. Empty falls back to `tag`, which is right for stable releases; the branch-backed `token-standard-v2` alpha entry sets it explicitly to a `0.6.5-snapshot` tag. The adapter forwards it as the `IMAGE_TAG` compose env. | @@ -109,11 +109,11 @@ A maintainer then: - Reviews the diff. - Bumps `latest_alias` if the new tag should become the default `--version latest`. -- Sets `min_memory_bytes` and `recommended_memory_bytes` on the first - entry of a new major line (from that release's - `cluster/compose/localnet/resource-constraints.yaml`). Later tags in - the line inherit them; `go test ./internal/splice/` fails until a - new major has them. +- Sets `min_memory_bytes` and `recommended_memory_bytes` only when + the release line needs floors different from the code defaults + (4 GB min / 6 GB recommended), using that release's + `cluster/compose/localnet/resource-constraints.yaml`. One override + on the major line is enough; later tags inherit it. - Optionally runs the integration test against the new entry before merging. - Commits + pushes. diff --git a/internal/splice/versions.go b/internal/splice/versions.go index 868dac0e..b8c74681 100644 --- a/internal/splice/versions.go +++ b/internal/splice/versions.go @@ -50,24 +50,17 @@ type Version struct { Size int64 `json:"size"` // informational; used only to print a hint before download Major string `json:"major"` // routes to internal/splice/v0X adapter - // MinMemoryBytes is the minimum Docker daemon memory the version - // needs to start cleanly. Empirically derived: Splice 0.6.x boots - // a single canton container hosting 2 sequencers + 2 mediators + - // 3 participants each at -Xmx 2.5 GiB, so the container OOM-loops - // on a stock Docker Desktop install (4 GB default). 0.5.x is - // lighter. 0 means "use docker.DefaultMinMemoryBytes" — the - // historical 4 GB floor. - // - // Values use decimal GB (1 GB = 10^9 bytes) to match Docker - // Desktop on macOS, which is the primary platform where users - // must manually set a memory limit. Using decimal GB ensures - // that "8 GB" in Docker Desktop satisfies a min_memory_bytes - // of 8_000_000_000. + // MinMemoryBytes overrides the code default min for this entry. + // Omit (0) when the release line matches defaultMinMemoryBytesFallback; + // set only when a line needs a different floor (e.g. 8 GB for 0.6+). + // Values use decimal GB (1 GB = 10^9 bytes) so "8 GB" in Docker + // Desktop satisfies min_memory_bytes of 8_000_000_000. MinMemoryBytes uint64 `json:"min_memory_bytes,omitempty"` - // RecommendedMemoryBytes is the value at which the version - // runs without resource warnings. UI surfaces this as the - // "raise Docker memory to ≥ N" remediation hint when Min* - // passes but the recommended threshold is not met. + // RecommendedMemoryBytes overrides the code default recommended + // memory for this entry. Omit (0) when the line matches + // defaultRecommendedMemoryBytesFallback; set only when different. + // Surfaces as the "raise Docker memory to ≥ N" remediation hint + // when Min* passes but this threshold is not met. RecommendedMemoryBytes uint64 `json:"recommended_memory_bytes,omitempty"` // Channel labels the maturity of a catalogue entry. Empty (the @@ -186,32 +179,17 @@ func Resolve(req string) (Version, error) { return v, nil } -// MinMemoryFor returns the version-specific Docker daemon memory -// floor for v. Called from both `dpm localnet up` (CLI gate) and the -// Web UI's GET /api/preflight handler so the two surfaces enforce -// identical numbers (see CONTRIBUTING.md "CLI ↔ Web UI parity"). The -// fallback constant is duplicated below to avoid an import cycle with -// internal/docker. +// MinMemoryFor returns the Docker daemon memory floor for v. Called +// from both `dpm localnet up` (CLI gate) and the Web UI's GET +// /api/preflight handler so the two surfaces enforce identical numbers +// (see CONTRIBUTING.md "CLI ↔ Web UI parity"). The fallback constant +// is duplicated below to avoid an import cycle with internal/docker. // // Resolution order: -// 1. v.MinMemoryBytes when the entry sets it (curated entries). -// 2. The STRICTEST (largest) MinMemoryFor across every catalogued -// entry that shares v.Major — this is the uncurated path. An -// uncurated 0.6.x tag has no memory fields of its own, but its -// resource profile is governed by the Splice major, not by -// whether DevKit reviewed the tag; reusing the catalogued floor -// for the same major means the escape hatch TIGHTENS the gate to -// match curated 0.6.x (8 GiB) instead of silently loosening it to -// the global 4 GiB default, which is exactly backwards for the -// least-tested versions. -// 3. The global defaultMinMemoryBytesFallback when neither applies -// (e.g. a major with no catalogued entry at all). -// -// Invariant pinned by TestThresholdParity_VersionMinAtLeastDefault: -// every catalogued MinMemoryBytes is >= the global default, so the -// derived floor for a known major is also >= the default. A user on a -// 4 GiB host always sees a refusal regardless of which version they -// pick, curated or not. +// 1. v.MinMemoryBytes when the entry sets an override. +// 2. The largest MinMemoryBytes among catalogued entries that share +// v.Major — one override covers the whole major line. +// 3. defaultMinMemoryBytesFallback (4 GB). func MinMemoryFor(v Version) uint64 { if v.MinMemoryBytes > 0 { return v.MinMemoryBytes @@ -223,25 +201,30 @@ func MinMemoryFor(v Version) uint64 { } // RecommendedMemoryFor returns the version's recommended memory -// (above which there are no resource warnings). For uncurated entries -// (no recommendation of their own) it falls back to the strictest -// catalogued recommendation for the same major, so the WARN tier is -// not silently disabled for the least-tested versions. Returns 0 only -// when neither the entry nor any same-major catalogue entry sets a -// recommendation; 0 disables the WARN tier in docker.checkDockerMemory -// — see internal/docker/checks.go. +// (above which there are no resource warnings). Resolution order: +// 1. v.RecommendedMemoryBytes when the entry sets an override. +// 2. The largest RecommendedMemoryBytes among catalogued entries +// that share v.Major. +// 3. defaultRecommendedMemoryBytesFallback (6 GB), raised to at +// least MinMemoryFor(v) so the WARN tier never undercuts the +// hard gate and never returns 0. func RecommendedMemoryFor(v Version) uint64 { if v.RecommendedMemoryBytes > 0 { return v.RecommendedMemoryBytes } - return strictestRecommendedForMajor(v.Major) + if m := strictestRecommendedForMajor(v.Major); m > 0 { + return m + } + rec := defaultRecommendedMemoryBytesFallback + if min := MinMemoryFor(v); rec < min { + return min + } + return rec } // strictestMinForMajor returns the largest MinMemoryBytes among // catalogued entries whose Major matches, or 0 when major is empty or -// no catalogued entry shares it. "Strictest" (max) is deliberate: the -// gate must refuse a host that any same-major curated entry would -// refuse. +// no catalogued entry shares an override. func strictestMinForMajor(major string) uint64 { if major == "" { return 0 @@ -278,6 +261,11 @@ func strictestRecommendedForMajor(major string) uint64 { // drifts. const defaultMinMemoryBytesFallback uint64 = 4_000_000_000 +// defaultRecommendedMemoryBytesFallback is the WARN-tier default when +// neither the entry nor any same-major catalogue entry sets an +// override. Matches the historical 0.5.x recommendation. +const defaultRecommendedMemoryBytesFallback uint64 = 6_000_000_000 + // Supported returns the supported tags in ascending version order. // Ordering is numeric (0.6.9 before 0.6.10), not lexical, so the CLI's // `--version` list matches the semver-sorted Web UI picker; non-semver diff --git a/internal/splice/versions.json b/internal/splice/versions.json index b37215c5..9177d524 100644 --- a/internal/splice/versions.json +++ b/internal/splice/versions.json @@ -24,9 +24,7 @@ "commit": "b162650cd18df5b96dddeffd9bd48be5b2ff37d7", "content_sha": "1a9d0b329cd7c9f76c04085674b9e8dc98169064b0404d007d7e2b22cb582150", "size": 124198413, - "major": "0.5", - "min_memory_bytes": 4000000000, - "recommended_memory_bytes": 6000000000 + "major": "0.5" }, { "tag": "0.6.10", diff --git a/internal/splice/versions_test.go b/internal/splice/versions_test.go index dcda213d..ee4cad9b 100644 --- a/internal/splice/versions_test.go +++ b/internal/splice/versions_test.go @@ -158,15 +158,10 @@ func TestLatestAliasIsInSupported(t *testing.T) { } } -// TestMinMemoryFor_UncuratedInheritsMajorFloor is the regression: -// an uncurated Version (no MinMemoryBytes of its own) must inherit the -// STRICTEST catalogued floor for its Major rather than the global 4 GiB -// default. Splice 0.6.x's resource profile doesn't change just because -// the tag wasn't reviewed, so the gate must TIGHTEN, not loosen, on the -// escape hatch. +// TestMinMemoryFor_UncuratedInheritsMajorFloor checks that a Version +// with no memory fields of its own still picks up a same-major +// catalogue override (one floored entry covers the whole major line). func TestMinMemoryFor_UncuratedInheritsMajorFloor(t *testing.T) { - // Compute the expected strictest 0.6 floor straight from the - // catalogue so this test tracks versions.json without hardcoding. var want06 uint64 for _, v := range SupportedVersions { if v.Major == "0.6" && v.MinMemoryBytes > want06 { @@ -174,21 +169,14 @@ func TestMinMemoryFor_UncuratedInheritsMajorFloor(t *testing.T) { } } if want06 == 0 { - t.Skip("no 0.6 catalogue entry with a memory floor — nothing to inherit") + t.Skip("no 0.6 catalogue entry with a memory override — nothing to inherit") } - // Uncurated 0.6.x: no memory fields, Major inferred from the tag. uncurated := Version{Tag: "0.6.99-rc.1", Commit: "deadbeef", Major: "0.6"} if got := MinMemoryFor(uncurated); got != want06 { - t.Errorf("MinMemoryFor(uncurated 0.6) = %d, want strictest-0.6 floor %d (not the 4 GiB default)", - got, want06) - } - if got := MinMemoryFor(uncurated); got <= defaultMinMemoryBytesFallback { - t.Errorf("uncurated 0.6 floor %d must exceed the global default %d — the escape hatch must not loosen the gate", - got, defaultMinMemoryBytesFallback) + t.Errorf("MinMemoryFor(uncurated 0.6) = %d, want same-major override %d", got, want06) } - // Recommended (WARN tier) must also inherit, not silently disable. var wantRec06 uint64 for _, v := range SupportedVersions { if v.Major == "0.6" && v.RecommendedMemoryBytes > wantRec06 { @@ -200,20 +188,20 @@ func TestMinMemoryFor_UncuratedInheritsMajorFloor(t *testing.T) { } } -// TestMinMemoryFor_UnknownMajorFallsBackToDefault covers the safety -// net: a tag whose Major has no catalogue entry at all (or an empty -// Major) still gets the global default floor — never 0, which would -// silently disable the gate. +// TestMinMemoryFor_UnknownMajorFallsBackToDefault covers the code +// defaults: a tag with no same-major override gets min 4 GB and +// recommended 6 GB — never 0. func TestMinMemoryFor_UnknownMajorFallsBackToDefault(t *testing.T) { for _, v := range []Version{ {Tag: "9.9.9", Major: "9.9"}, // no catalogued 9.9 entry {Tag: "weird", Major: ""}, // unparseable tag → empty major + {}, // empty Version } { if got := MinMemoryFor(v); got != defaultMinMemoryBytesFallback { t.Errorf("MinMemoryFor(%+v) = %d, want default %d", v, got, defaultMinMemoryBytesFallback) } - if got := RecommendedMemoryFor(v); got != 0 { - t.Errorf("RecommendedMemoryFor(%+v) = %d, want 0 (no same-major recommendation)", v, got) + if got := RecommendedMemoryFor(v); got != defaultRecommendedMemoryBytesFallback { + t.Errorf("RecommendedMemoryFor(%+v) = %d, want default %d", v, got, defaultRecommendedMemoryBytesFallback) } } } @@ -230,20 +218,12 @@ func TestMinMemoryFor_ExplicitOverrideWins(t *testing.T) { } } -func TestEveryCataloguedMajorHasCuratedFloor(t *testing.T) { - curated := map[string]bool{} - for _, v := range SupportedVersions { - if _, ok := curated[v.Major]; !ok { - curated[v.Major] = false - } - if v.MinMemoryBytes > 0 && v.RecommendedMemoryBytes > 0 { - curated[v.Major] = true - } - } - for major, ok := range curated { - if !ok { - t.Errorf("Splice major %q has no entry with min_memory_bytes and recommended_memory_bytes set", major) - } +// TestRecommendedMemoryFor_NeverBelowMin pins the clamp when a major +// has a min override but no recommended override. +func TestRecommendedMemoryFor_NeverBelowMin(t *testing.T) { + v := Version{Tag: "custom", Major: "orphan-major", MinMemoryBytes: 10_000_000_000} + if got := RecommendedMemoryFor(v); got != 10_000_000_000 { + t.Errorf("RecommendedMemoryFor(min-only) = %d, want raised to MinMemoryFor %d", got, 10_000_000_000) } } From 1eab6639af589c4cd173aa56651afab5c1de30fb Mon Sep 17 00:00:00 2001 From: Zhe Li Date: Tue, 10 Nov 2026 21:42:05 +0100 Subject: [PATCH 4/5] chore(splice): drop stale and narrating comments in version catalogue The defaultMinMemoryBytesFallback comment cited a parity test that does not exist and claimed an equality check nobody performs. Other comments restated signatures, narrated callers, or duplicated docs/versions.md. --- internal/splice/versions.go | 88 +++++--------------------------- internal/splice/versions_test.go | 38 ++------------ 2 files changed, 17 insertions(+), 109 deletions(-) diff --git a/internal/splice/versions.go b/internal/splice/versions.go index b8c74681..a36cc5e3 100644 --- a/internal/splice/versions.go +++ b/internal/splice/versions.go @@ -33,16 +33,6 @@ import ( // the resolved image digests post-up and warns on drift — see // internal/localnet/image_digests.go and docs/limitations.md ("Container // image pinning"). -// -// # Maintainer flow -// -// Add a new entry via: -// -// scripts/add-splice-version.sh -// -// The script resolves → commit SHA via the GitHub API, fetches + -// extracts the archive, computes ContentSHA, and appends a versions.json -// entry. A maintainer reviews the diff and commits. type Version struct { Tag string `json:"tag"` Commit string `json:"commit"` // immutable git commit SHA the tag pointed to @@ -50,52 +40,32 @@ type Version struct { Size int64 `json:"size"` // informational; used only to print a hint before download Major string `json:"major"` // routes to internal/splice/v0X adapter - // MinMemoryBytes overrides the code default min for this entry. - // Omit (0) when the release line matches defaultMinMemoryBytesFallback; - // set only when a line needs a different floor (e.g. 8 GB for 0.6+). - // Values use decimal GB (1 GB = 10^9 bytes) so "8 GB" in Docker + // MinMemoryBytes overrides the code default min for this entry; + // 0 defers to MinMemoryFor. Values use decimal GB (1 GB = 10^9 bytes) so "8 GB" in Docker // Desktop satisfies min_memory_bytes of 8_000_000_000. MinMemoryBytes uint64 `json:"min_memory_bytes,omitempty"` // RecommendedMemoryBytes overrides the code default recommended - // memory for this entry. Omit (0) when the line matches - // defaultRecommendedMemoryBytesFallback; set only when different. - // Surfaces as the "raise Docker memory to ≥ N" remediation hint - // when Min* passes but this threshold is not met. + // memory for this entry; 0 defers to RecommendedMemoryFor. RecommendedMemoryBytes uint64 `json:"recommended_memory_bytes,omitempty"` // Channel labels the maturity of a catalogue entry. Empty (the // historical default) and "stable" both mean a production-ready - // release; "alpha" marks an opt-in pre-release that the user is - // expected to know they are pulling (e.g. the Token Standard V2 - // snapshot, which runs on a separate -dev image repo and needs - // `--profile tokens-v2` for the alpha Canton protocol). The - // `versions` command surfaces this and `up` warns on selection. + // release; "alpha" marks an opt-in pre-release. Channel string `json:"channel,omitempty"` // ImageRepo overrides the default Docker image repository for // this entry. Empty falls back to the stable repo that Splice's - // compose env files default to (currently - // `ghcr.io/digital-asset/decentralized-canton-sync/docker`). The - // Token Standard V2 pre-release stream publishes to a separate - // `-dev` repo, so its catalogue entry sets this explicitly. The - // adapter forwards it as the `IMAGE_REPO` compose env. + // compose env files default to. The adapter forwards it as the + // `IMAGE_REPO` compose env. ImageRepo string `json:"image_repo,omitempty"` // ImageTag overrides the Docker image tag used for this entry. - // Empty falls back to Tag, which is right for stable releases - // (where the catalogue Tag === the upstream ghcr tag). The - // Token Standard V2 alpha publishes its images under a snapshot - // tag distinct from the catalogue tag (e.g. - // `0.6.5-snapshot.20260526.2931.0.ve28a6722`), so its entry sets - // this explicitly. The adapter forwards it as the `IMAGE_TAG` - // compose env. + // Empty falls back to Tag. The adapter forwards it as the + // `IMAGE_TAG` compose env. ImageTag string `json:"image_tag,omitempty"` } -// IsAlpha reports whether the entry is in the alpha channel — an -// opt-in pre-release the user must consciously select. Equivalent to -// `v.Channel == "alpha"` but kept as a method so the comparison string -// only lives in one place. +// IsAlpha reports whether the entry is in the alpha channel. func (v Version) IsAlpha() bool { return v.Channel == "alpha" } // SupportsTokenStandardV2 reports whether a Splice release includes the @@ -113,15 +83,9 @@ func SupportsTokenStandardV2(tag string) bool { return v[0] > 0 || (v[0] == 0 && (v[1] > 6 || (v[1] == 6 && v[2] >= 11))) } -// catalogueFile is the embedded JSON catalogue. Kept as a separate file -// (rather than literal Go code) so the maintainer refresh script can -// append entries with a tiny JSON edit instead of regenerating Go -// source. -// //go:embed versions.json var catalogueFile []byte -// catalogue holds the in-memory shape of versions.json after init(). var catalogue struct { LatestAlias string `json:"latest_alias"` Versions []Version `json:"versions"` @@ -163,10 +127,6 @@ func init() { // the catalogue return ErrUncuratedTag — the caller is responsible for // deciding whether to fall through to runtime resolution (see // ResolveOrUpstream / ResolveUpstream). -// -// We keep Resolve catalogue-only so a "just give me whatever works" -// caller can't accidentally start running arbitrary upstream tags -// without an explicit opt-in elsewhere. func Resolve(req string) (Version, error) { if req == "" || req == "latest" { req = LatestAlias @@ -179,12 +139,7 @@ func Resolve(req string) (Version, error) { return v, nil } -// MinMemoryFor returns the Docker daemon memory floor for v. Called -// from both `dpm localnet up` (CLI gate) and the Web UI's GET -// /api/preflight handler so the two surfaces enforce identical numbers -// (see CONTRIBUTING.md "CLI ↔ Web UI parity"). The fallback constant -// is duplicated below to avoid an import cycle with internal/docker. -// +// MinMemoryFor returns the Docker daemon memory floor for v. // Resolution order: // 1. v.MinMemoryBytes when the entry sets an override. // 2. The largest MinMemoryBytes among catalogued entries that share @@ -222,9 +177,6 @@ func RecommendedMemoryFor(v Version) uint64 { return rec } -// strictestMinForMajor returns the largest MinMemoryBytes among -// catalogued entries whose Major matches, or 0 when major is empty or -// no catalogued entry shares an override. func strictestMinForMajor(major string) uint64 { if major == "" { return 0 @@ -238,8 +190,6 @@ func strictestMinForMajor(major string) uint64 { return max } -// strictestRecommendedForMajor mirrors strictestMinForMajor for the -// recommended (WARN) threshold. func strictestRecommendedForMajor(major string) uint64 { if major == "" { return 0 @@ -253,17 +203,8 @@ func strictestRecommendedForMajor(major string) uint64 { return max } -// defaultMinMemoryBytesFallback mirrors docker.DefaultMinMemoryBytes, -// duplicated so this package can compute the effective min without -// importing internal/docker (docker imports splice — importing back -// would create a cycle). TestThresholdParity_VersionMinAtLeastDefault -// asserts equality with docker.DefaultMinMemoryBytes so this never -// drifts. const defaultMinMemoryBytesFallback uint64 = 4_000_000_000 -// defaultRecommendedMemoryBytesFallback is the WARN-tier default when -// neither the entry nor any same-major catalogue entry sets an -// override. Matches the historical 0.5.x recommendation. const defaultRecommendedMemoryBytesFallback uint64 = 6_000_000_000 // Supported returns the supported tags in ascending version order. @@ -279,9 +220,6 @@ func Supported() []string { return out } -// compareTags orders two catalogue tags by numeric major.minor.patch. -// Semver tags sort before non-semver ones (token-standard-v2); ties and -// two non-semver tags fall back to a lexical compare. func compareTags(a, b string) int { va, oka := parseSemver(a) vb, okb := parseSemver(b) @@ -294,19 +232,17 @@ func compareTags(a, b string) int { return 1 } } - return strings.Compare(a, b) // same major.minor.patch: pre-release suffix, etc. + return strings.Compare(a, b) } if oka != okb { if oka { - return -1 // semver before non-semver + return -1 } return 1 } return strings.Compare(a, b) } -// parseSemver reads the leading major.minor.patch of a tag, ignoring any -// `-pre`/`+build` suffix. Returns false when the tag isn't N.N.N. func parseSemver(tag string) ([3]int, bool) { var v [3]int base := tag diff --git a/internal/splice/versions_test.go b/internal/splice/versions_test.go index ee4cad9b..43ad3c33 100644 --- a/internal/splice/versions_test.go +++ b/internal/splice/versions_test.go @@ -6,11 +6,6 @@ import ( "testing" ) -// TestAlphaChannelEntryShape pins that the catalogue carries at least -// one alpha entry with a non-empty ImageRepo override — the Token -// Standard V2 snapshot — and that the IsAlpha helper agrees. -// Contract: alpha catalogue entries opt into a separate image repo via -// these fields, and the CLI/up paths key off `Channel == "alpha"`. func TestAlphaChannelEntryShape(t *testing.T) { var sawAlpha bool for tag, v := range SupportedVersions { @@ -107,10 +102,6 @@ func TestResolveSupportedTag(t *testing.T) { } } -// TestVersionsJSONIsValid sanity-checks the embedded catalogue: every -// commit SHA looks like a hex git SHA (40 chars), every ContentSHA is -// SHA-256 hex (64 chars). Catches typos that init() would also catch -// but with a clearer error. func TestVersionsJSONIsValid(t *testing.T) { for tag, v := range SupportedVersions { if len(v.Commit) != 40 { @@ -139,11 +130,6 @@ func TestResolveUnsupported(t *testing.T) { if err == nil { t.Fatal("expected error for unsupported version") } - // Resolve returns ErrUncuratedTag (rather than a generic - // "unsupported" error) so orchestrators can distinguish - // "tag exists nowhere" from "tag is upstream but not curated." - // The list of curated tags is still embedded so users see what - // the safe options are. if !errors.Is(err, ErrUncuratedTag) { t.Errorf("expected ErrUncuratedTag, got %v", err) } @@ -158,9 +144,6 @@ func TestLatestAliasIsInSupported(t *testing.T) { } } -// TestMinMemoryFor_UncuratedInheritsMajorFloor checks that a Version -// with no memory fields of its own still picks up a same-major -// catalogue override (one floored entry covers the whole major line). func TestMinMemoryFor_UncuratedInheritsMajorFloor(t *testing.T) { var want06 uint64 for _, v := range SupportedVersions { @@ -188,14 +171,11 @@ func TestMinMemoryFor_UncuratedInheritsMajorFloor(t *testing.T) { } } -// TestMinMemoryFor_UnknownMajorFallsBackToDefault covers the code -// defaults: a tag with no same-major override gets min 4 GB and -// recommended 6 GB — never 0. func TestMinMemoryFor_UnknownMajorFallsBackToDefault(t *testing.T) { for _, v := range []Version{ - {Tag: "9.9.9", Major: "9.9"}, // no catalogued 9.9 entry - {Tag: "weird", Major: ""}, // unparseable tag → empty major - {}, // empty Version + {Tag: "9.9.9", Major: "9.9"}, + {Tag: "weird", Major: ""}, + {}, } { if got := MinMemoryFor(v); got != defaultMinMemoryBytesFallback { t.Errorf("MinMemoryFor(%+v) = %d, want default %d", v, got, defaultMinMemoryBytesFallback) @@ -206,8 +186,6 @@ func TestMinMemoryFor_UnknownMajorFallsBackToDefault(t *testing.T) { } } -// TestMinMemoryFor_ExplicitOverrideWins confirms a curated entry's own -// MinMemoryBytes still takes precedence over the Major-derived floor. func TestMinMemoryFor_ExplicitOverrideWins(t *testing.T) { v := Version{Tag: "custom", Major: "0.6", MinMemoryBytes: 16_000_000_000, RecommendedMemoryBytes: 20_000_000_000} if got := MinMemoryFor(v); got != 16_000_000_000 { @@ -218,8 +196,6 @@ func TestMinMemoryFor_ExplicitOverrideWins(t *testing.T) { } } -// TestRecommendedMemoryFor_NeverBelowMin pins the clamp when a major -// has a min override but no recommended override. func TestRecommendedMemoryFor_NeverBelowMin(t *testing.T) { v := Version{Tag: "custom", Major: "orphan-major", MinMemoryBytes: 10_000_000_000} if got := RecommendedMemoryFor(v); got != 10_000_000_000 { @@ -237,15 +213,12 @@ func TestSupportedIsSorted(t *testing.T) { } } -// TestSupportedOrderIsNumeric guards the double-digit-patch regression: -// with lexical sorting "0.6.10" sorts before "0.6.3", which is wrong. func TestSupportedOrderIsNumeric(t *testing.T) { got := Supported() pos := map[string]int{} for i, tag := range got { pos[tag] = i } - // 0.6.9 must precede 0.6.10, which must precede 0.6.11. for _, pair := range [][2]string{{"0.6.9", "0.6.10"}, {"0.6.10", "0.6.11"}, {"0.6.4", "0.6.9"}} { lo, okLo := pos[pair[0]] hi, okHi := pos[pair[1]] @@ -253,7 +226,6 @@ func TestSupportedOrderIsNumeric(t *testing.T) { t.Errorf("Supported() ordered %q after %q: %v", pair[0], pair[1], got) } } - // token-standard-v2 (non-semver) sorts last. if p, ok := pos["token-standard-v2"]; ok && p != len(got)-1 { t.Errorf("token-standard-v2 should sort last, got position %d in %v", p, got) } @@ -262,13 +234,13 @@ func TestSupportedOrderIsNumeric(t *testing.T) { func TestCompareTags(t *testing.T) { cases := []struct { a, b string - want int // sign of the expected result + want int }{ {"0.6.9", "0.6.10", -1}, {"0.6.10", "0.6.9", 1}, {"0.6.4", "0.6.4", 0}, {"0.5.18", "0.6.3", -1}, - {"0.6.11", "token-standard-v2", -1}, // semver before non-semver + {"0.6.11", "token-standard-v2", -1}, {"token-standard-v2", "0.6.3", 1}, } for _, c := range cases { From 2af15a74cf27f198f85419ad013583185483ed4b Mon Sep 17 00:00:00 2001 From: Zhe Li Date: Tue, 10 Nov 2026 21:44:35 +0100 Subject: [PATCH 5/5] refactor(splice): collapse duplicate major-floor helpers after comment scrub Comment Sicko left reshape targets in the catalogue helpers; merge the twin strictest-* functions and rename the semver/sign bits so the deleted comments stay unnecessary. --- internal/splice/versions.go | 43 ++++++++++++-------------------- internal/splice/versions_test.go | 8 +++--- 2 files changed, 20 insertions(+), 31 deletions(-) diff --git a/internal/splice/versions.go b/internal/splice/versions.go index a36cc5e3..cb3cbc30 100644 --- a/internal/splice/versions.go +++ b/internal/splice/versions.go @@ -37,15 +37,15 @@ type Version struct { Tag string `json:"tag"` Commit string `json:"commit"` // immutable git commit SHA the tag pointed to ContentSHA string `json:"content_sha"` // sha-256 of the extracted localnet subtree (sorted, path+content) - Size int64 `json:"size"` // informational; used only to print a hint before download - Major string `json:"major"` // routes to internal/splice/v0X adapter + Size int64 `json:"size"` + Major string `json:"major"` // routes to internal/splice/v0X adapter // MinMemoryBytes overrides the code default min for this entry; - // 0 defers to MinMemoryFor. Values use decimal GB (1 GB = 10^9 bytes) so "8 GB" in Docker - // Desktop satisfies min_memory_bytes of 8_000_000_000. + // 0 means no override. Values use decimal GB (1 GB = 10^9 bytes) so + // "8 GB" in Docker Desktop satisfies min_memory_bytes of 8_000_000_000. MinMemoryBytes uint64 `json:"min_memory_bytes,omitempty"` // RecommendedMemoryBytes overrides the code default recommended - // memory for this entry; 0 defers to RecommendedMemoryFor. + // memory for this entry; 0 means no override. RecommendedMemoryBytes uint64 `json:"recommended_memory_bytes,omitempty"` // Channel labels the maturity of a catalogue entry. Empty (the @@ -76,7 +76,7 @@ func SupportsTokenStandardV2(tag string) bool { if tag == "token-standard-v2" { return true } - v, ok := parseSemver(tag) + v, ok := parseLeadingSemver(tag) if !ok { return false } @@ -149,7 +149,7 @@ func MinMemoryFor(v Version) uint64 { if v.MinMemoryBytes > 0 { return v.MinMemoryBytes } - if m := strictestMinForMajor(v.Major); m > 0 { + if m := strictestForMajor(v.Major, func(v Version) uint64 { return v.MinMemoryBytes }); m > 0 { return m } return defaultMinMemoryBytesFallback @@ -167,7 +167,7 @@ func RecommendedMemoryFor(v Version) uint64 { if v.RecommendedMemoryBytes > 0 { return v.RecommendedMemoryBytes } - if m := strictestRecommendedForMajor(v.Major); m > 0 { + if m := strictestForMajor(v.Major, func(v Version) uint64 { return v.RecommendedMemoryBytes }); m > 0 { return m } rec := defaultRecommendedMemoryBytesFallback @@ -177,27 +177,16 @@ func RecommendedMemoryFor(v Version) uint64 { return rec } -func strictestMinForMajor(major string) uint64 { +func strictestForMajor(major string, field func(Version) uint64) uint64 { if major == "" { return 0 } var max uint64 for _, v := range SupportedVersions { - if v.Major == major && v.MinMemoryBytes > max { - max = v.MinMemoryBytes - } - } - return max -} - -func strictestRecommendedForMajor(major string) uint64 { - if major == "" { - return 0 - } - var max uint64 - for _, v := range SupportedVersions { - if v.Major == major && v.RecommendedMemoryBytes > max { - max = v.RecommendedMemoryBytes + if v.Major == major { + if n := field(v); n > max { + max = n + } } } return max @@ -221,8 +210,8 @@ func Supported() []string { } func compareTags(a, b string) int { - va, oka := parseSemver(a) - vb, okb := parseSemver(b) + va, oka := parseLeadingSemver(a) + vb, okb := parseLeadingSemver(b) if oka && okb { for k := 0; k < 3; k++ { if va[k] != vb[k] { @@ -243,7 +232,7 @@ func compareTags(a, b string) int { return strings.Compare(a, b) } -func parseSemver(tag string) ([3]int, bool) { +func parseLeadingSemver(tag string) ([3]int, bool) { var v [3]int base := tag if i := strings.IndexAny(base, "-+"); i >= 0 { diff --git a/internal/splice/versions_test.go b/internal/splice/versions_test.go index 43ad3c33..0b4224bd 100644 --- a/internal/splice/versions_test.go +++ b/internal/splice/versions_test.go @@ -233,8 +233,8 @@ func TestSupportedOrderIsNumeric(t *testing.T) { func TestCompareTags(t *testing.T) { cases := []struct { - a, b string - want int + a, b string + wantSign int }{ {"0.6.9", "0.6.10", -1}, {"0.6.10", "0.6.9", 1}, @@ -245,8 +245,8 @@ func TestCompareTags(t *testing.T) { } for _, c := range cases { got := compareTags(c.a, c.b) - if (got < 0) != (c.want < 0) || (got > 0) != (c.want > 0) { - t.Errorf("compareTags(%q, %q) = %d, want sign %d", c.a, c.b, got, c.want) + if (got < 0) != (c.wantSign < 0) || (got > 0) != (c.wantSign > 0) { + t.Errorf("compareTags(%q, %q) = %d, want sign %d", c.a, c.b, got, c.wantSign) } } }