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 <canonical>" 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 <version>". 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 <canonical>
- version.go is wrong: scripts/update-versions.sh <intended-version>

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 <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Julian Knutsen 2026-10-01 11:34:06 -07:00 • committed by GitHub
commit 555b01d789
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 141 additions and 7 deletions

View file

@ -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 <version>" >&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

View file

@ -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 <version>`, 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

View file

@ -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"),

View file

@ -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",

View file

@ -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 <intended-version>",
r.CanonicalVersion,
)
}
// Check compares every released metadata surface with cmd/bd/version.go.
func Check(root string) (Report, error) {
report := Report{CheckedSources: len(releaseSources)}

View file

@ -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
}

View file

@ -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 <intended-version>",
} {
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()

View file

@ -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)
}
}