diff --git a/cmd/bd/history.go b/cmd/bd/history.go index 246af0320..0151cae95 100644 --- a/cmd/bd/history.go +++ b/cmd/bd/history.go @@ -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) diff --git a/cmd/bd/history_full_hash_test.go b/cmd/bd/history_full_hash_test.go new file mode 100644 index 000000000..357876bbb --- /dev/null +++ b/cmd/bd/history_full_hash_test.go @@ -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]) + } +} diff --git a/cmd/bd/show.go b/cmd/bd/show.go index cfc0e3b35..14df5a081 100644 --- a/cmd/bd/show.go +++ b/cmd/bd/show.go @@ -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") diff --git a/internal/storage/issueops/as_of_test.go b/internal/storage/issueops/as_of_test.go new file mode 100644 index 000000000..30b2ba994 --- /dev/null +++ b/internal/storage/issueops/as_of_test.go @@ -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) + } + }) + } +}