fix(create): resolve --deps targets like bd dep add (#5127)

`bd create --deps type:slug` stored the target id verbatim, while
`bd dep add` resolves partial IDs. Bare slugs became dangling rows that
`bd dep list` could not see; `bd dep remove` then resolved the bare
argument to the qualified good edge and deleted the wrong row.

- resolveDepSpecTargets in createIssueWithDeps (fail closed if unknown)
- dep remove prefers exact depends_on_id match before partial resolve

Fixes #5005
This commit is contained in:
Vishnu J 2026-07-31 01:43:05 -07:00 • committed by GitHub
commit 9d7052ba68
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 138 additions and 0 deletions

View file

@ -37,6 +37,15 @@ func createIssueWithDeps(ctx context.Context, st storage.DoltStorage, issue *typ
return st.CreateIssue(ctx, issue, actor)
}
// Normalize --deps targets to full IDs before any write (GH#5005). Fail
// closed if a target does not resolve — never store a bare slug that
// would become a dangling, list-invisible edge.
resolvedSpecs, err := resolveDepSpecTargets(ctx, st, edges.specs)
if err != nil {
return err
}
edges.specs = resolvedSpecs
// Store-level CreateIssue routes configured infra types to the wisps
// tables; transaction-level CreateIssue routes on the Ephemeral/NoHistory
// flags only, so resolve the routing up front (mirrors DoltStore and

View file

@ -50,6 +50,34 @@ type createAtomicFakeStore struct {
func (s *createAtomicFakeStore) IsInfraTypeCtx(context.Context, types.IssueType) bool { return false }
// SearchIssues + GetConfig satisfy utils.ResolvePartialID for --deps target
// normalization (GH#5005). Known IDs resolve to themselves; unknown bare
// slugs become prefix-qualified and also resolve so unit tests can exercise
// the resolve path without a real store.
func (s *createAtomicFakeStore) GetConfig(_ context.Context, key string) (string, error) {
if key == "issue_prefix" {
return "fake", nil
}
return "", nil
}
func (s *createAtomicFakeStore) SearchIssues(_ context.Context, _ string, filter types.IssueFilter) ([]*types.Issue, error) {
out := make([]*types.Issue, 0, len(filter.IDs))
for _, id := range filter.IDs {
if id == "" {
continue
}
// Real stores never mint bare slugs as issue IDs; only return hits for
// prefix-qualified forms so ResolvePartialID exercises the bare→prefix
// path used by create --deps (GH#5005).
if !strings.Contains(id, "-") {
continue
}
out = append(out, &types.Issue{ID: id, Title: "resolved", Status: types.StatusOpen, IssueType: types.TypeTask})
}
return out, nil
}
func (s *createAtomicFakeStore) CreateIssue(_ context.Context, issue *types.Issue, _ string) error {
s.storeCreateCalls++
if issue.ID == "" {

View file

@ -1,12 +1,15 @@
package main
import (
"context"
"fmt"
"strings"
"github.com/steveyegge/beads/internal/config"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/storage/domain"
"github.com/steveyegge/beads/internal/types"
"github.com/steveyegge/beads/internal/utils"
)
func parseDepSpecs(deps []string) ([]domain.DependencySpec, error) {
@ -63,6 +66,37 @@ func dedupeDepSpecs(specs []domain.DependencySpec) ([]domain.DependencySpec, err
return out, nil
}
// resolveDepSpecTargets rewrites each non-external TargetID through the same
// partial-ID resolution path as `bd dep add` (utils.ResolvePartialID).
//
// Without this, `bd create --deps discovered-from:8vezf` stores the bare
// token as depends_on_id, producing a dangling edge that `bd dep list` cannot
// see and that `bd dep remove … 8vezf` then mis-targets after resolving the
// good fully-qualified row (GH#5005).
func resolveDepSpecTargets(ctx context.Context, st storage.Storage, specs []domain.DependencySpec) ([]domain.DependencySpec, error) {
if len(specs) == 0 {
return specs, nil
}
out := make([]domain.DependencySpec, len(specs))
for i, spec := range specs {
out[i] = spec
target := strings.TrimSpace(spec.TargetID)
if target == "" {
return nil, fmt.Errorf("--deps target is empty")
}
if strings.HasPrefix(target, "external:") {
out[i].TargetID = target
continue
}
resolved, err := utils.ResolvePartialID(ctx, st, target)
if err != nil {
return nil, fmt.Errorf("resolving --deps target %q: %w", target, err)
}
out[i].TargetID = resolved
}
return out, nil
}
func parseDepSpec(raw string) (domain.DependencySpec, error) {
if !strings.Contains(raw, ":") {
return domain.DependencySpec{

View file

@ -1,7 +1,9 @@
package main
import (
"context"
"reflect"
"strings"
"testing"
"github.com/steveyegge/beads/internal/config"
@ -278,6 +280,45 @@ func TestDiscoveredFromParent(t *testing.T) {
}
}
func TestResolveDepSpecTargetsNormalizesBareSlug(t *testing.T) {
st := &createAtomicFakeStore{}
specs := []domain.DependencySpec{
{Type: types.DepDiscoveredFrom, TargetID: "8vezf"},
{Type: types.DepBlocks, TargetID: "fake-already-full"},
{Type: types.DepRelated, TargetID: "external:other-system/42"},
}
got, err := resolveDepSpecTargets(context.Background(), st, specs)
if err != nil {
t.Fatalf("resolveDepSpecTargets: %v", err)
}
if got[0].TargetID != "fake-8vezf" {
t.Errorf("bare slug resolved to %q, want fake-8vezf (GH#5005)", got[0].TargetID)
}
if got[1].TargetID != "fake-already-full" {
t.Errorf("full id became %q, want unchanged", got[1].TargetID)
}
if got[2].TargetID != "external:other-system/42" {
t.Errorf("external target became %q, want unchanged", got[2].TargetID)
}
// Types / swap flags must be preserved.
if got[0].Type != types.DepDiscoveredFrom || got[1].Type != types.DepBlocks {
t.Errorf("types mutated: %#v", got)
}
}
func TestResolveDepSpecTargetsRejectsEmptyTarget(t *testing.T) {
st := &createAtomicFakeStore{}
_, err := resolveDepSpecTargets(context.Background(), st, []domain.DependencySpec{
{Type: types.DepBlocks, TargetID: " "},
})
if err == nil {
t.Fatal("expected error for empty target")
}
if !strings.Contains(err.Error(), "empty") {
t.Errorf("error should mention empty target, got: %v", err)
}
}
func TestOverlayYAMLPrefix(t *testing.T) {
t.Run("yaml wins when set", func(t *testing.T) {
config.ResetForTesting()

View file

@ -20,6 +20,26 @@ import (
"github.com/steveyegge/beads/internal/ui"
)
// exactDependencyTarget returns the depends_on_id of a raw dependency edge on
// issueID that equals rawTarget exactly. Used by `bd dep remove` so a bare
// slug that was stored verbatim (pre-GH#5005 create --deps bug) is removed
// instead of being resolved to a different, fully-qualified good edge.
func exactDependencyTarget(ctx context.Context, st storage.DependencyQueryStore, issueID, rawTarget string) (string, bool) {
if st == nil || rawTarget == "" {
return "", false
}
records, err := st.GetDependencyRecords(ctx, issueID)
if err != nil {
return "", false
}
for _, r := range records {
if r != nil && r.DependsOnID == rawTarget {
return rawTarget, true
}
}
return "", false
}
// resolveIDWithRouting resolves a partial issue ID using prefix-based routing.
// It returns the resolved full ID and the store that contains the issue.
// If the issue routes to a different database, a routed store is returned
@ -959,6 +979,12 @@ var depRemoveCmd = &cobra.Command{
if err := validateExternalRef(toID); err != nil {
return HandleErrorRespectJSON("%v", err)
}
} else if exact, ok := exactDependencyTarget(ctx, fromStore, fromID, args[1]); ok {
// Prefer an exact depends_on_id match against raw edge records
// before partial-ID resolution (GH#5005). Otherwise
// `bd dep remove X 8vezf` resolves to the qualified good edge and
// deletes it while leaving a dangling bare-id row behind.
toID = exact
} else {
var toCleanup func()
toID, _, toCleanup, err = resolveIDWithRouting(ctx, store, args[1])