From 555b01d7891d4b592d83c4545a6dcedd018cbb9c Mon Sep 17 00:00:00 2001 From: Julian Knutsen Date: Thu, 1 Oct 2026 11:34:06 -0700 Subject: [PATCH] fix(release): name the version-drift remedies that work (#7083) Post-merge review follow-up to #5614. #5614 replaced the shell checker's three-way drift remedy with a bare "Run: scripts/update-versions.sh " in both the Go checker (status 1) and bd preflight's Version sync output, and the release-tag pre-push hook kept answering status 1 with "Fix with: scripts/update-versions.sh ". update-versions.sh derives the old version from cmd/bd/version.go and anchors its substitutions on it, so with version.go already at the canonical version that re-run rewrites only the .githooks markers and uv.lock and leaves any other drifted file as it was. Restore the remedy as versioncheck.Report.MismatchRemedy, shared by the checker and preflight: - one file drifted: edit it to the expected value - several drifted: set version.go to the previous version, then replay scripts/update-versions.sh - version.go is wrong: scripts/update-versions.sh The hook's status-1 text now points at the checker output instead of prescribing update-versions.sh; status 3 is unchanged. The text is sized so one drifted file shows in full within preflight's 500-byte human output, with the several-files case ahead of the version.go one. Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR Co-authored-by: Gas City Adopt-PR Co-authored-by: Claude Opus 5.5 --- .githooks/pre-push | 2 +- CHANGELOG.md | 5 ++ cmd/bd/preflight_test.go | 13 +++++ cmd/bd/preflight_versions.go | 2 +- internal/versioncheck/check.go | 22 ++++++++ scripts/check-versions/main.go | 6 +-- scripts/check-versions/main_test.go | 42 +++++++++++++++ scripts/check-versions/pre_push_hook_test.go | 56 ++++++++++++++++++++ 8 files changed, 141 insertions(+), 7 deletions(-) diff --git a/.githooks/pre-push b/.githooks/pre-push index 5c6acc315..992d7ece3 100755 --- a/.githooks/pre-push +++ b/.githooks/pre-push @@ -37,7 +37,7 @@ if [ "$pushing_version_tag" -eq 1 ]; then echo "" if [ "$checker_status" -eq 1 ]; then echo "āŒ Refusing to push release tag v$tag_version: versions are inconsistent." >&2 - echo " Fix with: scripts/update-versions.sh " >&2 + echo " See the checker output above for what is inconsistent and how to fix it." >&2 elif [ "$checker_status" -eq 3 ]; then echo "āŒ Refusing to push release tag v$tag_version: the tag does not match this checkout's release version." >&2 echo " The release surfaces agree with each other, so do NOT re-run update-versions.sh." >&2 diff --git a/CHANGELOG.md b/CHANGELOG.md index dbb29bd39..4aa5e6472 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `bd preflight --fix --json` no longer returns a `Version sync` fix result: version updates must keep all release surfaces aligned via `scripts/update-versions.sh`. - Release-tag pushes require Go and reject batches containing different release versions. +- On version drift the release-tag pre-push hook points at the checker's + remedies instead of prescribing `scripts/update-versions.sh `, and + `scripts/check-versions.sh` and `bd preflight` list the three that work: with + `cmd/bd/version.go` already at the release version, that re-run rewrites only + the `.githooks` markers and `uv.lock` and leaves any other drifted file as it was. ### Fixed diff --git a/cmd/bd/preflight_test.go b/cmd/bd/preflight_test.go index 4f7e54b3f..4f254fc18 100644 --- a/cmd/bd/preflight_test.go +++ b/cmd/bd/preflight_test.go @@ -514,6 +514,19 @@ func TestRunVersionSyncCheck_BeadsUsesBuiltInAuthority(t *testing.T) { if !strings.Contains(result.Output, "npm package.json: 9.9.9 (expected 1.1.0)") { t.Fatalf("unexpected mismatch output: %q", result.Output) } + // A bare update-versions.sh re-run no-ops on a drifted file, so the check + // carries the remedies that work, and the human view (which prints the + // first 500 bytes of a failed check) shows all of them for one drift. + remedy := versioncheck.Report{CanonicalVersion: "1.1.0"}.MismatchRemedy() + if !strings.HasSuffix(result.Output, "\n"+remedy) { + t.Fatalf("mismatch output lacks the drift remedy: %q", result.Output) + } + if strings.Contains(result.Output, "Run: scripts/update-versions.sh") { + t.Fatalf("mismatch output prescribes a bare update-versions.sh run: %q", result.Output) + } + if shown := truncateOutput(result.Output, 500); strings.HasSuffix(shown, "(truncated)") { + t.Fatalf("human output cuts the remedy for one drifted file: %q", shown) + } if err := os.WriteFile( filepath.Join(root, "npm-package", "package.json"), diff --git a/cmd/bd/preflight_versions.go b/cmd/bd/preflight_versions.go index 199c6bd86..fa74aaa7d 100644 --- a/cmd/bd/preflight_versions.go +++ b/cmd/bd/preflight_versions.go @@ -21,7 +21,7 @@ func runBeadsVersionSyncCheckWithUV( if err != nil { output := err.Error() if report.CanonicalVersion != "" { - output += "\nRun: scripts/update-versions.sh " + report.CanonicalVersion + output += "\n" + report.MismatchRemedy() } return CheckResult{ Name: "Version sync", diff --git a/internal/versioncheck/check.go b/internal/versioncheck/check.go index 2d6f92f7f..16a59288a 100644 --- a/internal/versioncheck/check.go +++ b/internal/versioncheck/check.go @@ -163,6 +163,28 @@ func (r Report) SuccessMessage() string { ) } +// MismatchRemedy formats the operator guidance for a mismatch found against a +// readable canonical version. scripts/update-versions.sh derives the OLD +// version from cmd/bd/version.go and rewrites every other surface with a +// substitution anchored on it, so re-running it for the canonical version +// leaves a drifted file as it was; only the .githooks markers (rewritten +// wholesale) and uv.lock (regenerated) heal that way. Kept short, with the +// several-files case ahead of the version.go one: bd preflight's human output +// shows only the first 500 bytes of a failed check, this follows the list of +// mismatches, and a wrong version.go mismatches every surface, so that list +// alone fills those bytes. +func (r Report) MismatchRemedy() string { + return fmt.Sprintf( + "Re-running scripts/update-versions.sh %[1]s fixes only .githooks markers and\n"+ + "uv.lock (version.go already reads %[1]s). Fix whichever applies:\n"+ + "- one file drifted: edit it to the expected value above\n"+ + "- several drifted: set version.go to the previous version, then\n"+ + " scripts/update-versions.sh %[1]s\n"+ + "- version.go is wrong: scripts/update-versions.sh ", + r.CanonicalVersion, + ) +} + // Check compares every released metadata surface with cmd/bd/version.go. func Check(root string) (Report, error) { report := Report{CheckedSources: len(releaseSources)} diff --git a/scripts/check-versions/main.go b/scripts/check-versions/main.go index 48224e948..5b284eb09 100644 --- a/scripts/check-versions/main.go +++ b/scripts/check-versions/main.go @@ -77,11 +77,7 @@ func run( if err != nil { fmt.Fprintf(stderr, "\n%sāŒ %v%s\n", red, err, reset) if report.CanonicalVersion != "" { - fmt.Fprintf( - stderr, - "Run: scripts/update-versions.sh %s\nOr manually update the mismatched files.\n", - report.CanonicalVersion, - ) + fmt.Fprintf(stderr, "\n%s\n", report.MismatchRemedy()) } return 1 } diff --git a/scripts/check-versions/main_test.go b/scripts/check-versions/main_test.go index 0167b661f..6ff14e194 100644 --- a/scripts/check-versions/main_test.go +++ b/scripts/check-versions/main_test.go @@ -182,6 +182,48 @@ func TestRunRejectsTrackedHookMarkerMismatch(t *testing.T) { } } +// On surface drift cmd/bd/version.go already holds the canonical version, so +// scripts/update-versions.sh with that version leaves the drifted file as it +// was. Status 1 must not offer that re-run as the fix; it names the remedies +// that do work. +func TestRunDriftRemedyDoesNotPrescribeUpdateVersionsAlone(t *testing.T) { + root := writeReleaseFixture(t, "1.1.0") + if err := os.WriteFile( + filepath.Join(root, "plugins", "beads", ".copilot-plugin", "plugin.json"), + []byte(`{"version":"1.0.9"}`), + 0o644, + ); err != nil { + t.Fatal(err) + } + + var stdout bytes.Buffer + var stderr bytes.Buffer + code := run(nil, root, &stdout, &stderr, nil) + if code != 1 { + t.Fatalf("exit code = %d, want 1\nstderr:\n%s", code, stderr.String()) + } + for _, want := range []string{ + "Copilot plugin.json: 1.0.9 (expected 1.1.0)", + "Re-running scripts/update-versions.sh 1.1.0 fixes only .githooks markers", + "- one file drifted: edit it to the expected value above", + "- several drifted: set version.go to the previous version, then\n" + + " scripts/update-versions.sh 1.1.0", + "- version.go is wrong: scripts/update-versions.sh ", + } { + if !strings.Contains(stderr.String(), want) { + t.Errorf("stderr lacks %q:\n%s", want, stderr.String()) + } + } + for _, bare := range []string{ + "Run: scripts/update-versions.sh 1.1.0", + "Or manually update the mismatched files", + } { + if strings.Contains(stderr.String(), bare) { + t.Errorf("stderr still prescribes %q:\n%s", bare, stderr.String()) + } + } +} + func writeReleaseFixture(t *testing.T, version string) string { t.Helper() diff --git a/scripts/check-versions/pre_push_hook_test.go b/scripts/check-versions/pre_push_hook_test.go index a417fb0ed..2b3ede171 100644 --- a/scripts/check-versions/pre_push_hook_test.go +++ b/scripts/check-versions/pre_push_hook_test.go @@ -81,3 +81,59 @@ func TestPrePushHookOrdinaryPushWorksWithSystemBash(t *testing.T) { }) } } + +// On drift (checker status 1) the hook defers to the checker's remedies rather +// than prescribing scripts/update-versions.sh itself: with cmd/bd/version.go +// already at the release version, that re-run leaves a drifted file as it was. +// Stub git and checker keep this independent of the checkout, so it also runs +// under Bazel. +func TestPrePushHookDriftRefusalPointsAtCheckerRemedy(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("Windows does not provide the oldest supported /bin/bash") + } + + const bash = "/bin/bash" + if _, err := os.Stat(bash); err != nil { + t.Skipf("system Bash unavailable: %v", err) + } + + hook := filepath.Join(bazeltest.RepoRoot(t), ".githooks", "pre-push") + scratch := t.TempDir() + for name, body := range map[string]string{ + "bin/git": "#!/bin/sh\necho '" + scratch + "'\n", + "scripts/check-versions.sh": "#!/bin/sh\necho 'stub drift report'\nexit 1\n", + } { + path := filepath.Join(scratch, filepath.FromSlash(name)) + if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(path, []byte(body), 0o755); err != nil { + t.Fatal(err) + } + } + + command := exec.Command(bash, hook, "origin", "https://example.invalid/repo.git") + command.Dir = scratch + command.Env = append(os.Environ(), "PATH="+filepath.Join(scratch, "bin")+":/bin:/usr/bin") + command.Stdin = strings.NewReader( + "refs/tags/v1.1.0 1111111111111111111111111111111111111111 " + + "refs/tags/v1.1.0 0000000000000000000000000000000000000000\n", + ) + output, err := command.CombinedOutput() + var exit *exec.ExitError + if !errors.As(err, &exit) || exit.ExitCode() != 1 { + t.Fatalf("hook status = %v, want 1: %s", err, output) + } + for _, want := range []string{ + "stub drift report", + "versions are inconsistent", + "See the checker output above", + } { + if !strings.Contains(string(output), want) { + t.Errorf("hook output lacks %q:\n%s", want, output) + } + } + if strings.Contains(string(output), "update-versions.sh") { + t.Errorf("hook prescribes update-versions.sh for drift:\n%s", output) + } +}