* 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.
185 lines
5 KiB
Go
185 lines
5 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/steveyegge/beads/internal/metrics"
|
|
"github.com/steveyegge/beads/internal/storage"
|
|
"github.com/steveyegge/beads/internal/types"
|
|
"github.com/steveyegge/beads/internal/ui"
|
|
"github.com/steveyegge/beads/internal/utils"
|
|
)
|
|
|
|
var (
|
|
historyLimit int
|
|
historyEvents bool
|
|
)
|
|
|
|
var historyCmd = &cobra.Command{
|
|
Use: "history <id>",
|
|
GroupID: "views",
|
|
Short: "Show version history for an issue",
|
|
Long: `Show the complete version history of an issue, including all commits
|
|
where the issue was modified.
|
|
|
|
Examples:
|
|
bd history bd-123 # Show all history for issue bd-123
|
|
bd history bd-123 --limit 5 # Show last 5 changes
|
|
bd history bd-123 --events # Show database audit events`,
|
|
Args: cobra.ExactArgs(1),
|
|
SilenceUsage: true,
|
|
SilenceErrors: true,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
evt := metrics.NewCommandEvent("history")
|
|
defer func() {
|
|
if c := metrics.Global(); c != nil {
|
|
c.CloseEventAndAdd(evt)
|
|
}
|
|
}()
|
|
|
|
issueID := args[0]
|
|
|
|
if usesProxiedServer() {
|
|
// Proxied mode has no local store to resolve against, so partial-ID
|
|
// resolution is unavailable here -- pass the raw ID through and let
|
|
// the proxied server's own lookup handle it.
|
|
return runHistoryProxiedServer(rootCtx, issueID, historyLimit, historyEvents)
|
|
}
|
|
|
|
if resolved, err := utils.ResolvePartialID(rootCtx, store, issueID); err == nil {
|
|
issueID = resolved
|
|
} else if errors.Is(err, utils.ErrAmbiguousID) {
|
|
return HandleErrorRespectJSON("%v", err)
|
|
}
|
|
// Not-found IDs fall through unchanged -- the queries below just find
|
|
// nothing and hit the existing "No history found" path (GH#3502), so we
|
|
// don't hard-error on an id that never existed.
|
|
|
|
return runHistory(rootCtx, store, issueID, historyLimit, historyEvents)
|
|
},
|
|
}
|
|
|
|
type historyBackend interface {
|
|
History(ctx context.Context, id string) ([]*storage.HistoryEntry, error)
|
|
IterEvents(ctx context.Context, id string, limit int) (storage.Iter[types.Event], error)
|
|
}
|
|
|
|
func runHistory(ctx context.Context, backend historyBackend, issueID string, limit int, showEvents bool) error {
|
|
if showEvents {
|
|
events, err := collectHistoryEvents(ctx, backend, issueID, limit)
|
|
if err != nil {
|
|
return HandleErrorRespectJSON("failed to get history events: %v", err)
|
|
}
|
|
if jsonOutput {
|
|
return outputJSON(events)
|
|
}
|
|
printHistoryEvents(issueID, events)
|
|
return nil
|
|
}
|
|
|
|
history, err := backend.History(ctx, issueID)
|
|
if err != nil {
|
|
return HandleErrorRespectJSON("failed to get history: %v", err)
|
|
}
|
|
|
|
if len(history) == 0 {
|
|
if jsonOutput {
|
|
return outputJSON(history)
|
|
}
|
|
fmt.Printf("No history found for issue %s\n", issueID)
|
|
return nil
|
|
}
|
|
|
|
if limit > 0 && limit < len(history) {
|
|
history = history[:limit]
|
|
}
|
|
|
|
if jsonOutput {
|
|
return outputJSON(history)
|
|
}
|
|
|
|
fmt.Printf("\n%s History for %s (%d entries)\n\n",
|
|
ui.RenderAccent("📜"), issueID, len(history))
|
|
|
|
for i, entry := range history {
|
|
fmt.Printf("%s %s\n",
|
|
ui.RenderMuted(entry.CommitHash),
|
|
ui.RenderMuted(entry.CommitDate.Format("2006-01-02 15:04:05")))
|
|
fmt.Printf(" Author: %s\n", entry.Committer)
|
|
|
|
if entry.Issue != nil {
|
|
statusIcon := ui.GetStatusIcon(string(entry.Issue.Status))
|
|
fmt.Printf(" %s %s: %s [P%d - %s]\n",
|
|
statusIcon,
|
|
entry.Issue.ID,
|
|
entry.Issue.Title,
|
|
entry.Issue.Priority,
|
|
entry.Issue.Status)
|
|
}
|
|
|
|
if i < len(history)-1 {
|
|
fmt.Println()
|
|
}
|
|
}
|
|
fmt.Println()
|
|
return nil
|
|
}
|
|
|
|
func init() {
|
|
historyCmd.Flags().IntVar(&historyLimit, "limit", 0, "Limit number of history entries (0 = all)")
|
|
historyCmd.Flags().BoolVar(&historyEvents, "events", false, "Show database audit events instead of commit snapshots")
|
|
historyCmd.ValidArgsFunction = issueIDCompletion
|
|
rootCmd.AddCommand(historyCmd)
|
|
}
|
|
|
|
func collectHistoryEvents(ctx context.Context, backend historyBackend, issueID string, limit int) ([]types.Event, error) {
|
|
iter, err := backend.IterEvents(ctx, issueID, limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer func() { _ = iter.Close() }()
|
|
|
|
var events []types.Event
|
|
for iter.Next(ctx) {
|
|
event := iter.Value()
|
|
if event != nil {
|
|
events = append(events, *event)
|
|
}
|
|
}
|
|
if err := iter.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return events, nil
|
|
}
|
|
|
|
func printHistoryEvents(issueID string, events []types.Event) {
|
|
if len(events) == 0 {
|
|
fmt.Printf("No history events found for issue %s\n", issueID)
|
|
return
|
|
}
|
|
|
|
fmt.Printf("\n%s History events for %s (%d entries)\n\n",
|
|
ui.RenderAccent("📜"), issueID, len(events))
|
|
for i, event := range events {
|
|
fmt.Printf("%s %s by %s\n",
|
|
ui.RenderMuted(event.CreatedAt.Format("2006-01-02 15:04:05")),
|
|
event.EventType,
|
|
event.Actor)
|
|
if event.OldValue != nil && *event.OldValue != "" {
|
|
fmt.Printf(" Old: %s\n", *event.OldValue)
|
|
}
|
|
if event.NewValue != nil && *event.NewValue != "" {
|
|
fmt.Printf(" New: %s\n", *event.NewValue)
|
|
}
|
|
if event.Comment != nil && *event.Comment != "" {
|
|
fmt.Printf(" Comment: %s\n", *event.Comment)
|
|
}
|
|
if i < len(events)-1 {
|
|
fmt.Println()
|
|
}
|
|
}
|
|
fmt.Println()
|
|
}
|