fix(history): print full commit hashes so bd show --as-of accepts them (#6730)
* test(feat): red — Fix bd history 8-char hash truncation causing misleading AS OF errors (refs be-95c0y)
* feat: green — Fix bd history 8-char hash truncation causing misleading AS OF errors (refs be-95c0y)
* test(feat): red — Review: Fix bd history 8-char hash truncation causing misleading AS OF errors (refs be-3phh0)
* feat: green — narrow truncated-hash heuristic to 16-31 chars so it stops
false-positiving on real short branch names (round 2, refs be-3phh0)
Round 1's ^[0-9a-v]{1,31}$ heuristic rejected any 1-31 char ref drawn from
Dolt's hash alphabet, including real short branch names spelled entirely in
[0-9a-v] (e.g. "main"). That broke the pre-existing
internal/storage/dolt/dolt_test.go:TestValidateRef "valid hash"/"valid
branch" subtests, which this diff does not touch.
Raising the floor to 16 chars keeps the heuristic well clear of "main"(4) and
"abc123def456"(12) while still catching the strongest signal case (up to 31
chars, one short of a full 32-char hash). The original 8-char truncation
example no longer gets the specific error and falls back to Dolt's generic
"branch not found" -- an accepted, disclosed tradeoff since FIX A (bd history
now prints the full hash) already removed the only first-party source of an
8-char truncated hash in this codebase.
* fix(issueops): drop the truncated-hash rejection from ValidateRef (be-i5s9b)
Review feedback on #6730: ValidateRef is not the --as-of validator. It is
the shared ref guard for AS OF, dolt_diff, the fast-forward path
(LocalAheadBehind, FastForwardAdopt), CommitExists and federation sync
status, so a shape heuristic there rejects well-formed refs for every
caller, not just --as-of. ^[0-9a-v]{16,31}$ made ordinary 16-character
branch names such as "productionmirror", "releasecandidate" and
"integrationtests" invalid for AS OF, dolt_diff and the fast-forward path,
and made CommitExists return false for the hash prefixes it is documented
to accept.
With bd history now printing the full hash, the heuristic had almost
nothing left to catch, so it is removed rather than moved. as_of.go is
back to its pre-PR content, which also makes ValidateRef's doc comment
accurate again. The --as-of flag help still says a full 32-character hash
is required.
The tests for the dropped heuristic are replaced by a contract test:
ValidateRef must accept well-formed refs spelled entirely in Dolt's hash
alphabet, including the three branch names above. Against the previous
head it fails on those three and on two hash prefixes.
This commit is contained in:
parent
6e812903d7
commit
d94e0c7cd9
4 changed files with 110 additions and 2 deletions
|
|
@ -106,7 +106,7 @@ func runHistory(ctx context.Context, backend historyBackend, issueID string, lim
|
|||
|
||||
for i, entry := range history {
|
||||
fmt.Printf("%s %s\n",
|
||||
ui.RenderMuted(entry.CommitHash[:8]),
|
||||
ui.RenderMuted(entry.CommitHash),
|
||||
ui.RenderMuted(entry.CommitDate.Format("2006-01-02 15:04:05")))
|
||||
fmt.Printf(" Author: %s\n", entry.Committer)
|
||||
|
||||
|
|
|
|||
68
cmd/bd/history_full_hash_test.go
Normal file
68
cmd/bd/history_full_hash_test.go
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
// fakeHistoryBackend is a minimal historyBackend for exercising runHistory
|
||||
// without a real store.
|
||||
type fakeHistoryBackend struct {
|
||||
entries []*storage.HistoryEntry
|
||||
}
|
||||
|
||||
func (f *fakeHistoryBackend) History(_ context.Context, _ string) ([]*storage.HistoryEntry, error) {
|
||||
return f.entries, nil
|
||||
}
|
||||
|
||||
func (f *fakeHistoryBackend) IterEvents(_ context.Context, _ string, _ int) (storage.Iter[types.Event], error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// TestHistoryTextOutputShowsFullCommitHash covers be-95c0y FIX A: text-mode
|
||||
// `bd history` output must print the full Dolt commit hash, not just its
|
||||
// first 8 characters -- an 8-char prefix is not valid input to `bd show
|
||||
// --as-of` (Dolt's AS OF does not resolve hash prefixes), so truncating it
|
||||
// here hands the user a value that looks copyable but always fails.
|
||||
func TestHistoryTextOutputShowsFullCommitHash(t *testing.T) {
|
||||
const fullHash = "0123456789abcdefghijklmnopqrstuv" // 32 chars, Dolt's [0-9a-v] alphabet
|
||||
if len(fullHash) != 32 {
|
||||
t.Fatalf("test fixture bug: fullHash is %d chars, want 32", len(fullHash))
|
||||
}
|
||||
|
||||
backend := &fakeHistoryBackend{
|
||||
entries: []*storage.HistoryEntry{
|
||||
{
|
||||
CommitHash: fullHash,
|
||||
Committer: "test-user",
|
||||
CommitDate: time.Date(2026, 1, 2, 3, 4, 5, 0, time.UTC),
|
||||
Issue: &types.Issue{
|
||||
ID: "test-1",
|
||||
Title: "test issue",
|
||||
Priority: 2,
|
||||
Status: types.StatusOpen,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
oldJSON := jsonOutput
|
||||
jsonOutput = false
|
||||
t.Cleanup(func() { jsonOutput = oldJSON })
|
||||
|
||||
out := captureStdout(t, func() error {
|
||||
return runHistory(context.Background(), backend, "test-1", 0, false)
|
||||
})
|
||||
|
||||
if !strings.Contains(out, fullHash) {
|
||||
t.Errorf("bd history text output does not contain the full commit hash %q; got:\n%s", fullHash, out)
|
||||
}
|
||||
if strings.Contains(out, fullHash[:8]) && !strings.Contains(out, fullHash) {
|
||||
t.Errorf("bd history text output contains only the truncated 8-char hash %q, not the full hash", fullHash[:8])
|
||||
}
|
||||
}
|
||||
|
|
@ -301,7 +301,7 @@ func init() {
|
|||
showCmd.Flags().Bool("long", false, "Show all available fields (extended metadata, agent identity, gate fields, etc.)")
|
||||
showCmd.Flags().Bool("refs", false, "Show issues that reference this issue (reverse lookup)")
|
||||
showCmd.Flags().Bool("children", false, "Show only the children of this issue")
|
||||
showCmd.Flags().String("as-of", "", "Show issue as it existed at a specific commit hash or branch (requires Dolt)")
|
||||
showCmd.Flags().String("as-of", "", "Show issue as it existed at a specific commit hash or branch (requires Dolt; commit hashes must be the full 32-character hash from 'bd history', not a prefix)")
|
||||
showCmd.Flags().StringArray("id", nil, "Issue ID (use for IDs that look like flags, e.g., --id=gt--xyz)")
|
||||
showCmd.Flags().Bool("local-time", false, "Show timestamps in local time instead of UTC")
|
||||
showCmd.Flags().BoolP("watch", "w", false, "Watch for changes and auto-refresh display")
|
||||
|
|
|
|||
40
internal/storage/issueops/as_of_test.go
Normal file
40
internal/storage/issueops/as_of_test.go
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package issueops
|
||||
|
||||
import "testing"
|
||||
|
||||
// TestValidateRefAcceptsWellFormedRefs pins ValidateRef to its documented
|
||||
// contract: it checks syntax only. It is the shared ref guard for AS OF,
|
||||
// dolt_diff, the fast-forward path, CommitExists' hash-prefix lookup and
|
||||
// federation remote refs, so it must never reject a well-formed ref by
|
||||
// guessing what the ref means. Refs spelled entirely within Dolt's [0-9a-v]
|
||||
// hash alphabet are the case that matters: no shape check can tell such a
|
||||
// branch name from a hash prefix, and CommitExists is documented to accept
|
||||
// prefixes. The rejection cases are covered by TestValidateRef in
|
||||
// internal/storage/dolt.
|
||||
func TestValidateRefAcceptsWellFormedRefs(t *testing.T) {
|
||||
valid := []string{
|
||||
"main",
|
||||
"release/v2.0",
|
||||
"feature/auth.flow",
|
||||
"wip/my-feature",
|
||||
// 16-character branch names spelled entirely within Dolt's [0-9a-v]
|
||||
// hash alphabet, so nothing about their shape separates them from a
|
||||
// hash prefix.
|
||||
"productionmirror",
|
||||
"releasecandidate",
|
||||
"integrationtests",
|
||||
// Hash prefixes, which CommitExists resolves with a LIKE match.
|
||||
"0123456789abcdef",
|
||||
"0123456789abcdefghijklmnopqrstu",
|
||||
// A full 32-character Dolt commit hash.
|
||||
"0123456789abcdefghijklmnopqrstuv",
|
||||
}
|
||||
|
||||
for _, ref := range valid {
|
||||
t.Run(ref, func(t *testing.T) {
|
||||
if err := ValidateRef(ref); err != nil {
|
||||
t.Errorf("ValidateRef(%q) = %v, want nil", ref, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue