diff --git a/cmd/bd/BUILD.bazel b/cmd/bd/BUILD.bazel index 89240c36a..4d581e7c2 100644 --- a/cmd/bd/BUILD.bazel +++ b/cmd/bd/BUILD.bazel @@ -452,6 +452,7 @@ go_library( "@io_opentelemetry_go_otel_trace//:trace", "@land_charm_huh_v2//:huh", "@land_charm_lipgloss_v2//:lipgloss", + "@org_golang_x_mod//module", "@org_golang_x_mod//semver", "@org_golang_x_term//:term", ] + select({ diff --git a/cmd/bd/version_tracking.go b/cmd/bd/version_tracking.go index c3f343e9d..98e59eba9 100644 --- a/cmd/bd/version_tracking.go +++ b/cmd/bd/version_tracking.go @@ -17,6 +17,7 @@ import ( "github.com/steveyegge/beads/internal/storage/dolt" "github.com/steveyegge/beads/internal/storage/schema" "github.com/steveyegge/beads/issueops" + "golang.org/x/mod/module" ) // localVersionFile is the gitignored file that stores the last bd version used locally. @@ -309,22 +310,30 @@ func autoMigrateOnVersionBump(beadsDir string) { // recoverPreV56IfNeeded rebuilds a Dolt database left behind by the pre-0.56 // embedded mode (GH#2137) — which means deleting .dolt — but only when the -// recorded predecessor is an actual semantic version older than 0.56.0. +// recorded predecessor is a release older than 0.56.0. // -// The validity check is not redundant with the comparison. CompareVersions -// scans every dot-separated part with %d and leaves whatever it cannot read at -// 0, so any non-semver string writeLocalVersion has recorded compares as -// pre-0.56 and routes a current workspace into this destructive path: -// Homebrew's "HEAD-" from a --HEAD install (#5603), and the -// v-prefixed Go pseudo-version a `go install`-built bd stamps (#5650). Neither -// is a pre-0.56 workspace; both would lose their database. +// Neither refusal below is redundant with the comparison: // -// IsValidSemver rejects exactly the shapes CompareVersions misreads, so this -// gate can only remove predecessors from the recovery set, never add one: a -// stamp that reaches RecoverPreV56DoltDir today and still parses keeps its -// recovery unchanged. +// - CompareVersions scans every dot-separated part with %d and leaves +// whatever it cannot read at 0, so a stamp it cannot parse compares as +// pre-0.56: Homebrew's "HEAD-" from a --HEAD install (#5603). +// IsValidSemver rejects those shapes. +// - A Go pseudo-version parses, but its numbers do not name a release. +// "v0.55.5-0.-" is some commit after v0.55.4, and +// "v0.0.0--" a build with no tag in reach at all: the +// prefix bounds the build from below, never from above, so it cannot show +// that the workspace predates 0.56. IsValidSemver used to refuse the +// v-prefixed ones some build paths stamp (#5650) only because it read +// the "v" as a malformed part. Since it accepts a leading "v" (GH#6152), +// a major-0 one can compare below 0.56.0, so pseudo-versions are refused +// here explicitly, however they are spelled. +// +// A v-prefixed release ("v0.55.4") is compared numerically and still +// recovers. The .bd-dolt-ok marker RecoverPreV56DoltDir checks is the last +// gate, but only bd 0.58.0 and later write it: a database that only 0.56.x or +// 0.57.x has served has none, so for it these refusals are the only gate. func recoverPreV56IfNeeded(previousVersion, dbPath string) { - if !doctor.IsValidSemver(previousVersion) { + if !doctor.IsValidSemver(previousVersion) || isGoPseudoVersion(previousVersion) { return } if doctor.CompareVersions(previousVersion, "0.56.0") >= 0 { @@ -340,6 +349,14 @@ func recoverPreV56IfNeeded(previousVersion, dbPath string) { } } +// isGoPseudoVersion reports whether a version stamp is a Go pseudo-version, +// with or without the leading "v". The module parser requires the "v", so the +// stamp is normalized the way the doctor version helpers read it (trimmed, one +// optional "v") and then given one. +func isGoPseudoVersion(version string) bool { + return module.IsPseudoVersion("v" + strings.TrimPrefix(strings.TrimSpace(version), "v")) +} + // noticeSharedMigrateRefusal turns the one failure autoMigrateOnVersionBump // must not swallow into a one-line stderr notice. // diff --git a/cmd/bd/version_tracking_test.go b/cmd/bd/version_tracking_test.go index e3af15f56..1cf4b1044 100644 --- a/cmd/bd/version_tracking_test.go +++ b/cmd/bd/version_tracking_test.go @@ -548,11 +548,16 @@ func writePreV56DoltFixture(t *testing.T) (doltDir, sentinel string) { } // TestRecoverPreV56IfNeeded_OnlySemverPredecessorsAreRecovered pins the -// destructive edge from #5603/#5625: CompareVersions reads any unparsable -// version part as 0, so a non-semver predecessor compares as pre-0.56 and -// hands a live workspace to a path that deletes .dolt. The Homebrew --HEAD -// stamp and the v-prefixed Go pseudo-version from #5650 are both such -// predecessors and both reach this call today. +// destructive edge from #5603/#5625/#5650: only a release older than 0.56.0 +// may hand its workspace to the path that deletes .dolt. +// +// - CompareVersions reads any unparsable version part as 0, so the Homebrew +// --HEAD stamp compares as pre-0.56 and must fail the validity check. +// - A Go pseudo-version passes the validity check since the GH#6152 fix, +// and a major-0 one can compare below 0.56.0, but its numbers only bound +// the build from below. It must be refused on its own, with or without +// the "v". +// - A v-prefixed release is a genuine predecessor and still recovers. func TestRecoverPreV56IfNeeded_OnlySemverPredecessorsAreRecovered(t *testing.T) { tests := []struct { name string @@ -563,11 +568,16 @@ func TestRecoverPreV56IfNeeded_OnlySemverPredecessorsAreRecovered(t *testing.T) {name: "bare brew HEAD stamp", previous: "HEAD"}, {name: "brew HEAD stamp with revision", previous: "HEAD-f925f3f_1"}, {name: "go pseudo-version", previous: "v1.1.1-0.20260805093327-bf97b73749ac"}, + {name: "go pseudo-version with no tag in reach", previous: "v0.0.0-20260805093327-bf97b73749ac"}, + {name: "go pseudo-version after a pre-0.56 tag", previous: "v0.55.5-0.20260101000000-abcdefabcdef"}, + {name: "go pseudo-version without its v", previous: "0.0.0-20260805093327-bf97b73749ac"}, + {name: "go pseudo-version with surrounding space", previous: " v0.0.0-20260805093327-bf97b73749ac\n"}, {name: "unreadable witness", previous: "not-a-version"}, {name: "no predecessor", previous: ""}, {name: "current release", previous: "1.1.2"}, {name: "0.56.0 itself", previous: "0.56.0"}, {name: "pre-0.56 release", previous: "0.55.4", wantRecovery: true}, + {name: "v-prefixed pre-0.56 release", previous: "v0.55.4", wantRecovery: true}, {name: "pre-0.56 pre-release", previous: "0.55.4-rc.1", wantRecovery: true}, }