fix(version): refuse Go pseudo-version predecessors in pre-0.56 recovery (#7000)
#6153 taught the doctor version helpers to accept a leading "v" (GH#6152). recoverPreV56IfNeeded reused IsValidSemver as the gate that kept the v-prefixed Go pseudo-versions from #5650 off the path that deletes .dolt, so that protection went with it: a major-0 pseudo-version such as v0.0.0-<ts>-<hash> or v0.55.5-0.<ts>-<hash> now passes the validity check and compares below 0.56.0. The .bd-dolt-ok marker only stops the rebuild for databases bd 0.58.0 or later has served; 0.56.x and 0.57.x never wrote it. Refuse pseudo-versions explicitly with golang.org/x/mod/module, after normalizing the stamp the way the doctor helpers read it, so the spelling of a stamp never decides whether its database is deleted. A pseudo-version's numbers bound the build from below only, so they can never show that a workspace predates 0.56. This also refuses a bare pseudo-version (0.0.0-<ts>-<hash>), which the digit scan has always accepted. A v-prefixed release such as v0.55.4 still recovers. Post-merge review follow-up for #6153. Co-authored-by: Eddie the Engineer <adopt-pr@gascity.local> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
de8567eaae
commit
8951ca56ba
3 changed files with 46 additions and 18 deletions
|
|
@ -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({
|
||||
|
|
|
|||
|
|
@ -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-<shortsha>" 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-<shortsha>" 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.<timestamp>-<hash>" is some commit after v0.55.4, and
|
||||
// "v0.0.0-<timestamp>-<hash>" 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.
|
||||
//
|
||||
|
|
|
|||
|
|
@ -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},
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue