fix: dep add stores an unresolved target as a bare external ref, then readers drop it (#6571)
* test(feat): red — dep add stores a cross-store target as a bare external ref, then readers drop it (from:gm-ri3xl0) (refs be-gmdx5) * feat: green — dep add stores a cross-store target as a bare external ref, then readers drop it (from:gm-ri3xl0) (refs be-gmdx5) * chore: release gate PASS for dep-add-external-ref (be-fghsd) * fix(dep): keep the bare cross-prefix dep target, refuse only type:id Review of #6571. The previous commit closed both bug shapes by requiring any target that failed local/routed resolution to be a well-formed external: ref. That over-reached: only one of the two shapes was malformed. A bare, differently-prefixed target is first-class by this codebase's own definition. issueops.IsExternalDepTarget says a target "whose id prefix names ANOTHER REPOSITORY" belongs in depends_on_external alongside external: refs, and calls that the single rule every backend must classify by; db.pickDepTargetColumn restates it. It is the multi-rig "add now, route later" shape, and the ExtractPrefix fallbacks in validateBulkDepEdges and dep remove still address such an edge. Refusing it in dep add meant refusing to create an edge the store holds and dep remove can still delete. The type:id misparse stays refused, and by a sharper test than a prefix comparison: no bd ID contains ":", and the external: shape is already handled above, so anything else containing ":" is malformed regardless of prefix. The error now names the flag form that would have worked. Adds a test pinning dep add's accept decision to IsExternalDepTarget, so the CLI and the storage classification cannot drift apart again. * chore: drop the release-gate record from the PR Review of #6571. The reviewer is right that a 111-line record of our deployment ritual is not something a bd user gets anything from, and the "but the directory already exists upstream" defence does not survive checking who put it there: 45 of the 47 commits touching release-gates/ on main are ours. That is not a repo convention, it is us. The gate record itself is not lost — it stays in this branch's history at 0e8d7e2a4386 and on the deploy bead. Dropping only this PR's file; the existing 31 are a separate conversation we should have on our side rather than settle by unilateral deletion here. * fix(dep): apply the target refusal at every dep add site, and get its suggested command right Maintainer review fixes for #6571. The PR extracted resolveUnresolvedDepTarget to centralize the dep add target decision, but installed it at one of four decision sites. The be-gmdx5 silent mangle — a "type:id" positional arg stored verbatim as a bogus external ref with the type dropped — survived on `dep add --file` (validateBulkDepEdges kept a byte-equivalent copy of the replaced ladder) and, more sharply, on both proxied paths, where the identical invocation was refused in direct mode and stored in proxied mode. Nothing below the CLI backstops it: addDependencyEdgeInTx classifies by ExtractPrefix alone and validates no target shape. Split the resolution-free half of the decision into refuseMalformedDepTarget so all sites share it: validateBulkDepEdges now routes through resolveUnresolvedDepTarget (per-line message unchanged), and the two proxied paths — which deliberately resolve no IDs — call the shape refusal directly. The refusal's suggested command was also backwards for the one reversing spelling. parseDepSpec sets SwapDirection for the literal "blocks:" only, so `--deps blocks:B` on A stores "B depends on A"; the suggested `bd dep add A B --type blocks` stored the opposite, handing the user a reversed bd ready/bd blocked gate. Emit the swapped operands for "blocks:" and keep the natural order for the depends-on/blocked-by aliases, which are compared before canonicalDependencyType and do not swap. Also gate the "`bd create --deps` <type>:<id> syntax" diagnosis on the token before the ":" being a type --type would accept, so an unrelated colon-bearing typo ("https://example.com/x") gets the generic refusal instead of a confidently wrong cause and a --type the next validation rejects. Review iteration 2 closed the enumeration at the fifth surface and the last coverage gap: - runDepBlocksProxiedServer — the `bd dep <blocker> --blocks <blocked>` alias the dep help documents as "equivalent to: bd dep add <blocked-id> <blocker-id>" — reached the edge builder from raw args with no shape check, so the same invocation stayed refused in direct mode and stored in proxied mode. It now mirrors the dep add proxied site, with the operands inverted (the blocker is the target), and the helper's doc comment names all five sites instead of claiming four. - refuseMalformedDepTarget TrimSpaces both halves like parseDepSpec, so pasting an accepted `--deps "blocks : bd-2"` spec into dep add still gets the actionable translation rather than the generic refusal. Tests: blocks:/depends-on: direction rows with an omit-guard on the wrong operand order, a non-type-prefix row for the gated diagnosis, a whitespace row for the trimmed diagnosis, call-site refusal pins on all three proxied paths, and a call-site pin for direct `--file` (validateBulkDepEdges) driven by a stub store, which replaces the previous coverage-by-construction argument on the one converted site with the worst regression history. Each new pin was mutation-proved to red only for its own site. Refs be-gmdx5, be-fghsd Co-authored-by: Claude Opus 5 <noreply@anthropic.com> --------- Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
fb43d97220
commit
1cbac71ef7
3 changed files with 520 additions and 15 deletions
128
cmd/bd/dep.go
128
cmd/bd/dep.go
|
|
@ -107,6 +107,112 @@ func resolveIDForMutation(ctx context.Context, localStore storage.DoltStorage, i
|
|||
return result.ResolvedID, s, func() { result.Close() }, nil
|
||||
}
|
||||
|
||||
// refuseMalformedDepTarget refuses a dep add target that contains ":" but is
|
||||
// not an "external:" ref. This is the half of the target decision that needs no
|
||||
// ID resolution, so it is the half every dep add surface can share — including
|
||||
// the proxied-server paths, which deliberately resolve nothing and so cannot
|
||||
// call resolveUnresolvedDepTarget. A colon-free target is not this helper's
|
||||
// business and returns nil; the caller still owns the resolve/cross-prefix
|
||||
// decision. Refusing here rather than per-surface is what keeps `bd dep add`
|
||||
// from being mode-dependently correct (be-gmdx5 survived in proxied mode and on
|
||||
// --file until every site routed through this). The five sites are: the
|
||||
// positional and --file direct routes (both via resolveUnresolvedDepTarget),
|
||||
// their two proxied twins, and runDepBlocksProxiedServer — the `bd dep <a>
|
||||
// --blocks <b>` alias the dep help documents as equivalent to dep add, which
|
||||
// passes the blocker as the target and so inverts the operands.
|
||||
//
|
||||
// The refused shape is be-gmdx5 itself: a "type:id" positional arg (e.g.
|
||||
// "discovered-from:ga-x", the spec syntax `bd create --deps` accepts) was read
|
||||
// as a foreign-store ID, because ExtractPrefix stops at the first "-" and so
|
||||
// returns "discovered-". The type keyword was silently dropped (the edge
|
||||
// defaulted to blocks) and the whole string was stored as a bogus external ref.
|
||||
// No bd ID contains ":", and callers take the only legal ":" shape
|
||||
// ("external:") first, so anything reaching here is malformed regardless of
|
||||
// prefix.
|
||||
//
|
||||
// Two details in the message:
|
||||
//
|
||||
// - The `bd create --deps` diagnosis is only asserted when the token before
|
||||
// the ":" is a type --type would actually accept. Otherwise an unrelated
|
||||
// colon-bearing typo ("https://example.com/x") is told a confidently wrong
|
||||
// cause and handed "--type https", which the next validation rejects.
|
||||
// - The suggested command respects direction. parseDepSpec reverses the
|
||||
// endpoints for the literal "blocks:" spelling only (create_deps.go sets
|
||||
// SwapDirection for rawType == DepBlocks), so `--deps blocks:B` on A stores
|
||||
// "B depends on A" and the equivalent dep add has to name B first. The
|
||||
// "depends-on"/"blocked-by" aliases are compared before
|
||||
// canonicalDependencyType and do not swap, so they keep the natural order.
|
||||
// Getting this backwards would hand the user a reversed bd ready/bd blocked
|
||||
// gate (Type.AffectsReadyWork), not just a cosmetically odd command.
|
||||
func refuseMalformedDepTarget(sourceID, dependsOnArg string) error {
|
||||
idx := strings.Index(dependsOnArg, ":")
|
||||
if idx < 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Trim both halves the way parseDepSpec does (create_deps.go), or the
|
||||
// diagnosis this branch exists to give degrades on exactly the specs
|
||||
// `bd create --deps` accepts: "blocks : bd-2" parses there, but read
|
||||
// verbatim here the type is "blocks " — neither types.DepBlocks (so the
|
||||
// direction swap is never considered) nor well-known (so the suggestion is
|
||||
// suppressed), and the user is handed the generic refusal instead of the
|
||||
// translation. The refusal itself is correct either way; only the message
|
||||
// is at stake, and it must name a command that actually runs.
|
||||
depType, target := strings.TrimSpace(dependsOnArg[:idx]), strings.TrimSpace(dependsOnArg[idx+1:])
|
||||
if depType == "" || target == "" ||
|
||||
validateDependencyType(canonicalDependencyType(types.DependencyType(depType))) != nil {
|
||||
return fmt.Errorf("invalid dependency target %q: not a bd ID and not a well-formed external:<project>:<capability> reference", dependsOnArg)
|
||||
}
|
||||
|
||||
first, second := sourceID, target
|
||||
if types.DependencyType(depType) == types.DepBlocks {
|
||||
first, second = target, sourceID
|
||||
}
|
||||
return fmt.Errorf("invalid dependency target %q: that is `bd create --deps` <type>:<id> syntax, not a target ID; use: bd dep add %s %s --type %s",
|
||||
dependsOnArg, first, second, depType)
|
||||
}
|
||||
|
||||
// resolveUnresolvedDepTarget decides what to do when a dep add target could
|
||||
// not be resolved locally or via cross-store routing (resolveIDWithRouting's
|
||||
// error). Three outcomes, in order:
|
||||
//
|
||||
// 1. An "external:" ref is validated and passed through, as before.
|
||||
// 2. Anything else containing ":" is refused by name, by
|
||||
// refuseMalformedDepTarget — see there for the be-gmdx5 mechanism and the
|
||||
// message's direction/type rules.
|
||||
// 3. A bare, differently-prefixed target is passed through unchanged. This is
|
||||
// NOT malformed: issueops.IsExternalDepTarget defines a target "whose id
|
||||
// prefix names ANOTHER REPOSITORY" as belonging in depends_on_external
|
||||
// alongside "external:" refs, and calls that the single rule every backend
|
||||
// classifies by (db.pickDepTargetColumn restates it). It is the multi-rig
|
||||
// "add now, route later" shape — a gt- bead depending on a bd- bead whose
|
||||
// rig is not in routes.jsonl yet — and dep remove (the ExtractPrefix
|
||||
// fallback further down this file) still addresses such an edge. Refusing
|
||||
// it here would make dep add reject an edge the store holds and dep remove
|
||||
// can still delete.
|
||||
//
|
||||
// A same-prefix target that resolves nowhere is still an error, unchanged.
|
||||
func resolveUnresolvedDepTarget(sourceID, dependsOnArg string, resolveErr error) (string, error) {
|
||||
if IsExternalRef(dependsOnArg) {
|
||||
if err := validateExternalRef(dependsOnArg); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return dependsOnArg, nil
|
||||
}
|
||||
|
||||
if err := refuseMalformedDepTarget(sourceID, dependsOnArg); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
srcPrefix := types.ExtractPrefix(sourceID)
|
||||
tgtPrefix := types.ExtractPrefix(dependsOnArg)
|
||||
if srcPrefix != "" && tgtPrefix != "" && srcPrefix != tgtPrefix {
|
||||
return dependsOnArg, nil
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("resolving dependency ID %s: %v", dependsOnArg, resolveErr)
|
||||
}
|
||||
|
||||
// isChildOf returns true if childID is a hierarchical child of parentID.
|
||||
// For example, "bd-abc.1" is a child of "bd-abc", and "bd-abc.1.2" is a child of "bd-abc.1".
|
||||
func isChildOf(childID, parentID string) bool {
|
||||
|
|
@ -382,12 +488,9 @@ Examples:
|
|||
var toCleanup func()
|
||||
toID, _, toCleanup, err = resolveIDWithRouting(ctx, store, dependsOnArg)
|
||||
if err != nil {
|
||||
srcPrefix := types.ExtractPrefix(fromID)
|
||||
tgtPrefix := types.ExtractPrefix(dependsOnArg)
|
||||
if srcPrefix != "" && tgtPrefix != "" && srcPrefix != tgtPrefix {
|
||||
toID = dependsOnArg
|
||||
} else {
|
||||
return HandleErrorRespectJSON("resolving dependency ID %s: %v", dependsOnArg, err)
|
||||
toID, err = resolveUnresolvedDepTarget(fromID, dependsOnArg, err)
|
||||
if err != nil {
|
||||
return HandleErrorRespectJSON("%v", err)
|
||||
}
|
||||
} else {
|
||||
defer toCleanup()
|
||||
|
|
@ -708,12 +811,13 @@ func validateBulkDepEdges(ctx context.Context, edges []bulkDepEdge) ([]bulkDepEd
|
|||
} else {
|
||||
toID, _, toCleanup, err := resolveIDWithRouting(ctx, store, edge.DependsOnID)
|
||||
if err != nil {
|
||||
srcPrefix := types.ExtractPrefix(current.IssueID)
|
||||
tgtPrefix := types.ExtractPrefix(edge.DependsOnID)
|
||||
if srcPrefix != "" && tgtPrefix != "" && srcPrefix != tgtPrefix {
|
||||
toID = edge.DependsOnID
|
||||
} else {
|
||||
errs = append(errs, fmt.Sprintf("line %d: resolving dependency ID %s: %v", edge.Line, edge.DependsOnID, err))
|
||||
// Same decision as the single-edge add, through the same helper:
|
||||
// --file used to carry its own copy of the cross-prefix ladder,
|
||||
// which left the be-gmdx5 "type:id" shape accepted and stored
|
||||
// here after the positional path started refusing it.
|
||||
toID, err = resolveUnresolvedDepTarget(current.IssueID, edge.DependsOnID, err)
|
||||
if err != nil {
|
||||
errs = append(errs, fmt.Sprintf("line %d: %v", edge.Line, err))
|
||||
resolved = append(resolved, current)
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
377
cmd/bd/dep_add_target_test.go
Normal file
377
cmd/bd/dep_add_target_test.go
Normal file
|
|
@ -0,0 +1,377 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
storeissueops "github.com/steveyegge/beads/internal/storage/issueops"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
// resolveUnresolvedDepTarget is the decision point `bd dep add` reaches when
|
||||
// its depends-on target could not be resolved locally or via cross-store
|
||||
// routing (resolveIDWithRouting's error return). It has to separate two things
|
||||
// the old prefix-comparison heuristic conflated:
|
||||
//
|
||||
// - A "type:id"-shaped positional argument (e.g. "discovered-from:ga-dguvnb",
|
||||
// the syntax `bd create --deps` accepts via parseDepSpec) was misparsed:
|
||||
// types.ExtractPrefix takes everything up to the first "-", so it read
|
||||
// "discovered-" as a bd ID prefix instead of recognizing "discovered-from"
|
||||
// as a dependency-type keyword. The intended type was silently dropped
|
||||
// (defaulting to blocks) and the whole "type:id" string was stored as a
|
||||
// bogus external reference. That is bd-gmdx5, and it is a real bug.
|
||||
//
|
||||
// - A bare, differently-prefixed target (e.g. "xy-999" from a "be-" issue) is
|
||||
// NOT a bug. storeissueops.IsExternalDepTarget defines exactly this shape as
|
||||
// belonging in depends_on_external, and calls that the single rule every
|
||||
// backend classifies by. It is the multi-rig "add now, route later" shape,
|
||||
// and `bd dep remove` still addresses such an edge. dep add must keep
|
||||
// accepting it, or it would refuse to create an edge the store holds and
|
||||
// dep remove can still delete.
|
||||
func TestResolveUnresolvedDepTarget(t *testing.T) {
|
||||
resolveErr := errors.New("issue not found")
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
sourceID string
|
||||
dependsOnArg string
|
||||
wantToID string
|
||||
wantErr bool
|
||||
wantErrContains string
|
||||
// wantErrOmits is the direction/diagnosis guard: for the reversing
|
||||
// spelling it holds the operand order the message must NOT suggest, so a
|
||||
// refusal that merely names the target cannot pass by accident.
|
||||
wantErrOmits string
|
||||
}{
|
||||
{
|
||||
name: "bare cross-prefix target is passed through as a cross-store edge",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "xy-999",
|
||||
wantToID: "xy-999",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "type:id-shaped positional arg is rejected, not silently misparsed",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "discovered-from:ga-dguvnb",
|
||||
wantErr: true,
|
||||
wantErrContains: "discovered-from:ga-dguvnb",
|
||||
},
|
||||
{
|
||||
name: "type:id rejection names the flag form that would have worked",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "discovered-from:ga-dguvnb",
|
||||
wantErr: true,
|
||||
wantErrContains: "bd dep add be-abc ga-dguvnb --type discovered-from",
|
||||
},
|
||||
{
|
||||
// `bd create --deps blocks:B` on A stores "B depends on A":
|
||||
// parseDepSpec sets SwapDirection for the literal "blocks" spelling
|
||||
// and both consumers swap the endpoints. The equivalent dep add
|
||||
// therefore names the target first. Suggesting the natural order
|
||||
// here would hand the user a reversed bd ready/bd blocked gate.
|
||||
name: "blocks: is the reversing spelling, so the suggestion swaps the operands",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "blocks:xy-999",
|
||||
wantErr: true,
|
||||
wantErrContains: "bd dep add xy-999 be-abc --type blocks",
|
||||
wantErrOmits: "bd dep add be-abc xy-999",
|
||||
},
|
||||
{
|
||||
// The documented aliases are compared before canonicalDependencyType,
|
||||
// so they do not swap — the operand order stays natural. This is the
|
||||
// twin that stops the blocks: fix from swapping everything.
|
||||
name: "depends-on: alias keeps direction, so the suggestion keeps the operand order",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "depends-on:xy-999",
|
||||
wantErr: true,
|
||||
wantErrContains: "bd dep add be-abc xy-999 --type depends-on",
|
||||
wantErrOmits: "bd dep add xy-999 be-abc",
|
||||
},
|
||||
{
|
||||
// parseDepSpec TrimSpaces both halves, so `bd create --deps
|
||||
// "blocks : xy-999"` is accepted there. Read verbatim here the type
|
||||
// would be "blocks " — neither DepBlocks nor well-known — and the
|
||||
// paste of that same spec into dep add would lose the translation
|
||||
// and fall to the generic refusal. wantErrOmits is what pins that:
|
||||
// the message must still be the actionable one, and still swapped.
|
||||
name: "whitespace-bearing spec keeps the actionable diagnosis, matching parseDepSpec",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "blocks : xy-999",
|
||||
wantErr: true,
|
||||
wantErrContains: "bd dep add xy-999 be-abc --type blocks",
|
||||
wantErrOmits: "not a bd ID and not a well-formed external:",
|
||||
},
|
||||
{
|
||||
// The `--deps` diagnosis is a claim about the token before the ":".
|
||||
// An unrelated colon-bearing typo must not be told that cause and
|
||||
// handed a --type the next validation rejects.
|
||||
name: "colon-bearing target whose prefix is not a dependency type gets the generic refusal",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "https://example.com/x",
|
||||
wantErr: true,
|
||||
wantErrContains: "not a bd ID and not a well-formed external:",
|
||||
wantErrOmits: "--type https",
|
||||
},
|
||||
{
|
||||
name: "well-formed external ref is still accepted",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "external:otherproj:some-capability",
|
||||
wantToID: "external:otherproj:some-capability",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "malformed external-looking ref missing capability is rejected",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "external:otherproj",
|
||||
wantErr: true,
|
||||
wantErrContains: "external:otherproj",
|
||||
},
|
||||
{
|
||||
name: "same-prefix target that resolves nowhere is still an error",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "be-nosuchbead",
|
||||
wantErr: true,
|
||||
wantErrContains: "be-nosuchbead",
|
||||
},
|
||||
{
|
||||
name: "target with no prefix at all is rejected",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "nodashhere",
|
||||
wantErr: true,
|
||||
wantErrContains: "nodashhere",
|
||||
},
|
||||
{
|
||||
name: "empty target is rejected",
|
||||
sourceID: "be-abc",
|
||||
dependsOnArg: "",
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
toID, err := resolveUnresolvedDepTarget(tt.sourceID, tt.dependsOnArg, resolveErr)
|
||||
|
||||
if tt.wantErr {
|
||||
if err == nil {
|
||||
t.Fatalf("resolveUnresolvedDepTarget(%q, %q): got nil error, want error naming the unresolved target", tt.sourceID, tt.dependsOnArg)
|
||||
}
|
||||
if tt.wantErrContains != "" && !strings.Contains(err.Error(), tt.wantErrContains) {
|
||||
t.Errorf("resolveUnresolvedDepTarget(%q, %q): error %q does not contain %q", tt.sourceID, tt.dependsOnArg, err.Error(), tt.wantErrContains)
|
||||
}
|
||||
if tt.wantErrOmits != "" && strings.Contains(err.Error(), tt.wantErrOmits) {
|
||||
t.Errorf("resolveUnresolvedDepTarget(%q, %q): error %q must not contain %q", tt.sourceID, tt.dependsOnArg, err.Error(), tt.wantErrOmits)
|
||||
}
|
||||
if toID != "" {
|
||||
t.Errorf("resolveUnresolvedDepTarget(%q, %q): got toID %q on error, want empty", tt.sourceID, tt.dependsOnArg, toID)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("resolveUnresolvedDepTarget(%q, %q): unexpected error: %v", tt.sourceID, tt.dependsOnArg, err)
|
||||
}
|
||||
if toID != tt.wantToID {
|
||||
t.Errorf("resolveUnresolvedDepTarget(%q, %q) = %q, want %q", tt.sourceID, tt.dependsOnArg, toID, tt.wantToID)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestResolveUnresolvedDepTargetMatchesStorageClassification pins the CLI's
|
||||
// accept/refuse decision to the storage layer's own definition of an external
|
||||
// dependency target. Every target dep add passes through here must be one
|
||||
// IsExternalDepTarget classifies as external — i.e. one depends_on_external can
|
||||
// actually hold. If these two ever disagree, dep add is writing edges a backend
|
||||
// will route to the wrong column (or refusing edges it would have held fine),
|
||||
// which is the failure this whole change is about.
|
||||
func TestResolveUnresolvedDepTargetMatchesStorageClassification(t *testing.T) {
|
||||
resolveErr := errors.New("issue not found")
|
||||
|
||||
const sourceID = "be-abc"
|
||||
accepted := []string{
|
||||
"xy-999",
|
||||
"external:otherproj:some-capability",
|
||||
}
|
||||
|
||||
for _, target := range accepted {
|
||||
t.Run(target, func(t *testing.T) {
|
||||
toID, err := resolveUnresolvedDepTarget(sourceID, target, resolveErr)
|
||||
if err != nil {
|
||||
t.Fatalf("resolveUnresolvedDepTarget(%q, %q): unexpected error: %v", sourceID, target, err)
|
||||
}
|
||||
if !storeissueops.IsExternalDepTarget(sourceID, toID) {
|
||||
t.Errorf("dep add accepted %q but storage would not classify it as an external dep target; "+
|
||||
"the edge would be written to a column that cannot hold it", toID)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// newDepAddCommandForTest mirrors depAddCmd's flag set (dep.go's init) so the
|
||||
// proxied RunE helpers can be driven directly. Only the flags read before the
|
||||
// target decision matter, but registering all of them keeps the fixture honest
|
||||
// if that order ever changes.
|
||||
func newDepAddCommandForTest() *cobra.Command {
|
||||
cmd := &cobra.Command{Use: "add"}
|
||||
cmd.Flags().StringP("type", "t", "blocks", "")
|
||||
cmd.Flags().String("blocked-by", "", "")
|
||||
cmd.Flags().String("depends-on", "", "")
|
||||
cmd.Flags().String("file", "", "")
|
||||
cmd.Flags().Bool("no-cycle-check", false, "")
|
||||
return cmd
|
||||
}
|
||||
|
||||
// TestDepAddProxiedServerRefusesDepsSpecTarget pins the refusal on the proxied
|
||||
// route, where be-gmdx5 survived the original fix: usesProxiedServer() is
|
||||
// consulted before any flag handling (dep.go), this path resolves no IDs, and
|
||||
// nothing below it validates target shape — ExecuteAddDependencies classifies by
|
||||
// ExtractPrefix alone (internal/storage/issueops/dependency_editor.go). Without
|
||||
// the refusal the identical invocation that now errors in direct mode stores the
|
||||
// bogus external ref with the type dropped, so `bd dep add` would be
|
||||
// mode-dependently correct.
|
||||
//
|
||||
// The assertion is on the message, not merely on "an error came back": the
|
||||
// unguarded path also fails here (it reaches proxiedDependencyEditor with no
|
||||
// server configured), so only the refusal text distinguishes the two.
|
||||
func TestDepAddProxiedServerRefusesDepsSpecTarget(t *testing.T) {
|
||||
var err error
|
||||
stderr := captureStderr(t, func() {
|
||||
err = runDepAddProxiedServer(newDepAddCommandForTest(), context.Background(),
|
||||
[]string{"be-abc", "discovered-from:ga-dguvnb"})
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
t.Fatal("proxied dep add accepted discovered-from:ga-dguvnb; the be-gmdx5 edge would be stored with its type dropped")
|
||||
}
|
||||
if !strings.Contains(stderr, "bd dep add be-abc ga-dguvnb --type discovered-from") {
|
||||
t.Errorf("proxied refusal = %q, want the same target refusal the direct route emits", stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDepAddBulkProxiedRefusesDepsSpecTarget covers the fourth decision site.
|
||||
// The bulk format carries an explicit "type" field, so a "type:id" value in
|
||||
// "to" is precisely the malformed input — and it was accepted and stored.
|
||||
func TestDepAddBulkProxiedRefusesDepsSpecTarget(t *testing.T) {
|
||||
file := filepath.Join(t.TempDir(), "edges.jsonl")
|
||||
if err := os.WriteFile(file, []byte(`{"from":"be-abc","to":"discovered-from:ga-dguvnb"}`+"\n"), 0o600); err != nil {
|
||||
t.Fatalf("write bulk edge file: %v", err)
|
||||
}
|
||||
|
||||
var err error
|
||||
stderr := captureStderr(t, func() {
|
||||
err = runDepAddBulkProxied(newDepAddCommandForTest(), context.Background(), file, "blocks")
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
t.Fatal("proxied bulk dep add accepted discovered-from:ga-dguvnb in \"to\"")
|
||||
}
|
||||
if !strings.Contains(stderr, "line 1:") ||
|
||||
!strings.Contains(stderr, "bd dep add be-abc ga-dguvnb --type discovered-from") {
|
||||
t.Errorf("proxied bulk refusal = %q, want the per-line target refusal", stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// bulkDepStubStore resolves exactly one issue ID and nothing else, which is
|
||||
// all validateBulkDepEdges needs to reach its target decision: the source has
|
||||
// to resolve (or the line fails earlier with "resolving issue ID"), and the
|
||||
// target has to not resolve anywhere (or the decision point is skipped).
|
||||
// Four methods carry that. SearchIssues is ResolvePartialID's fast path and
|
||||
// GetIssue is resolveAndGetFromStore's follow-up; GetConfig and GetAllConfig
|
||||
// are consulted by the prefix-routing and auto-routing fallbacks the target
|
||||
// falls through on its way to failing. Nothing here opens a store, so this
|
||||
// needs no cgo build tag and no container — the same reason the proxied pins
|
||||
// above are cheap.
|
||||
type bulkDepStubStore struct {
|
||||
storage.DoltStorage
|
||||
resolvableID string
|
||||
}
|
||||
|
||||
func (s *bulkDepStubStore) SearchIssues(_ context.Context, _ string, filter types.IssueFilter) ([]*types.Issue, error) {
|
||||
for _, id := range filter.IDs {
|
||||
if id == s.resolvableID {
|
||||
return []*types.Issue{{ID: s.resolvableID}}, nil
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *bulkDepStubStore) GetIssue(_ context.Context, id string) (*types.Issue, error) {
|
||||
if id == s.resolvableID {
|
||||
return &types.Issue{ID: s.resolvableID}, nil
|
||||
}
|
||||
return nil, storage.ErrNotFound
|
||||
}
|
||||
|
||||
func (s *bulkDepStubStore) GetConfig(_ context.Context, _ string) (string, error) {
|
||||
return "be", nil
|
||||
}
|
||||
|
||||
func (s *bulkDepStubStore) GetAllConfig(_ context.Context) (map[string]string, error) {
|
||||
return map[string]string{}, nil
|
||||
}
|
||||
|
||||
// TestValidateBulkDepEdgesRefusesDepsSpecTarget is the call-site pin for the
|
||||
// direct `bd dep add --file` route — the one converted site with the worst
|
||||
// regression history, because it is where the be-gmdx5 shape survived the
|
||||
// first fix by carrying its own private copy of the prefix ladder.
|
||||
//
|
||||
// TestResolveUnresolvedDepTarget pins the decision in isolation, but that is
|
||||
// coverage by construction: it stays green if a future change re-inlines a
|
||||
// prefix comparison at the call site, or short-circuits before reaching the
|
||||
// helper at all. This asserts on the per-line text the route actually emits,
|
||||
// so the wiring itself is what goes red.
|
||||
func TestValidateBulkDepEdgesRefusesDepsSpecTarget(t *testing.T) {
|
||||
oldStore := store
|
||||
t.Cleanup(func() { store = oldStore })
|
||||
store = &bulkDepStubStore{resolvableID: "be-abc"}
|
||||
|
||||
_, err := validateBulkDepEdges(context.Background(), []bulkDepEdge{
|
||||
{Line: 1, IssueID: "be-abc", DependsOnID: "discovered-from:ga-dguvnb", Type: types.DepBlocks},
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
t.Fatal("bulk dep add --file accepted discovered-from:ga-dguvnb; the be-gmdx5 edge would be stored with its type dropped")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "line 1:") ||
|
||||
!strings.Contains(err.Error(), "bd dep add be-abc ga-dguvnb --type discovered-from") {
|
||||
t.Errorf("bulk validation error = %q, want the per-line target refusal", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// TestDepBlocksProxiedServerRefusesDepsSpecTarget covers the fifth decision
|
||||
// site. `bd dep <blocker> --blocks <blocked>` is dispatched before any dep add
|
||||
// helper runs, and `bd dep --help` documents it as "equivalent to: bd dep add
|
||||
// <blocked-id> <blocker-id>" — so leaving it unguarded kept exactly the
|
||||
// be-gmdx5 mode-dependence this change exists to remove: the direct twin
|
||||
// hard-errors on the resolve, while the proxied twin built the edge straight
|
||||
// from the raw args and stored the bogus external ref with its type forced to
|
||||
// blocks.
|
||||
//
|
||||
// The operands are inverted here relative to dep add: the blocker is the
|
||||
// target (it becomes DependsOnID) and the blocked issue is the source, which
|
||||
// is why the suggested command still reads `bd dep add <blocked> <blocker>`.
|
||||
// As with the two pins above, the assertion is on the message — the unguarded
|
||||
// path errors too, just from the missing proxied UOW provider.
|
||||
func TestDepBlocksProxiedServerRefusesDepsSpecTarget(t *testing.T) {
|
||||
var err error
|
||||
stderr := captureStderr(t, func() {
|
||||
err = runDepBlocksProxiedServer(newDepAddCommandForTest(), context.Background(),
|
||||
"discovered-from:ga-dguvnb", "be-abc")
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
t.Fatal("proxied dep --blocks accepted discovered-from:ga-dguvnb as the blocker; the be-gmdx5 edge would be stored")
|
||||
}
|
||||
if !strings.Contains(stderr, "bd dep add be-abc ga-dguvnb --type discovered-from") {
|
||||
t.Errorf("proxied --blocks refusal = %q, want the same target refusal the dep add surfaces emit", stderr)
|
||||
}
|
||||
}
|
||||
|
|
@ -160,6 +160,23 @@ func proxiedLookupTitle(ctx context.Context, uw uow.UnitOfWork, id string) strin
|
|||
}
|
||||
|
||||
func runDepBlocksProxiedServer(cmd *cobra.Command, ctx context.Context, blockerID, blockedID string) error {
|
||||
// `bd dep <blocker> --blocks <blocked>` is the fifth dep add surface: this
|
||||
// command's own help calls it "equivalent to: bd dep add <blocked-id>
|
||||
// <blocker-id>", and it lands here before any of the dep add helpers run.
|
||||
// The target endpoint is the blocker (it becomes DependsOnID below), and
|
||||
// the source is the blocked issue — the operands are inverted relative to
|
||||
// dep add, so the suggested command comes out in the order the help
|
||||
// documents. Without this the alias stays mode-dependently correct: the
|
||||
// direct twin hard-errors on resolveIDWithRouting, while this path builds
|
||||
// the edge from raw args and stores the be-gmdx5 external ref.
|
||||
if strings.HasPrefix(blockerID, "external:") {
|
||||
if err := validateExternalRef(blockerID); err != nil {
|
||||
return HandleErrorRespectJSON("%v", err)
|
||||
}
|
||||
} else if err := refuseMalformedDepTarget(blockedID, blockerID); err != nil {
|
||||
return HandleErrorRespectJSON("%v", err)
|
||||
}
|
||||
|
||||
if isDisallowedHierarchicalDependency(blockedID, blockerID, types.DepBlocks) {
|
||||
return HandleErrorRespectJSON("cannot add dependency: %s is already a child of %s. Children inherit dependency on parent completion via hierarchy. Adding an explicit dependency would create a deadlock", blockedID, blockerID)
|
||||
}
|
||||
|
|
@ -219,10 +236,15 @@ func runDepAddProxiedServer(cmd *cobra.Command, ctx context.Context, args []stri
|
|||
if err := validateExternalRef(dependsOnArg); err != nil {
|
||||
return HandleErrorRespectJSON("%v", err)
|
||||
}
|
||||
toID = dependsOnArg
|
||||
} else {
|
||||
toID = dependsOnArg
|
||||
} else if err := refuseMalformedDepTarget(fromID, dependsOnArg); err != nil {
|
||||
// This path resolves no IDs, so the colon-shape refusal is the only
|
||||
// part of the direct route's target decision it can run — and it has to
|
||||
// run it, or the same `bd dep add` invocation is refused in direct mode
|
||||
// and silently stores the be-gmdx5 bogus external ref here (nothing in
|
||||
// ExecuteAddDependencies validates target shape).
|
||||
return HandleErrorRespectJSON("%v", err)
|
||||
}
|
||||
toID = dependsOnArg
|
||||
|
||||
dt := canonicalDependencyType(types.DependencyType(depType))
|
||||
if isDisallowedHierarchicalDependency(fromID, toID, dt) {
|
||||
|
|
@ -284,6 +306,8 @@ func runDepAddBulkProxied(cmd *cobra.Command, ctx context.Context, file, default
|
|||
if err := validateExternalRef(edge.DependsOnID); err != nil {
|
||||
return HandleErrorRespectJSON("line %d: %v", edge.Line, err)
|
||||
}
|
||||
} else if err := refuseMalformedDepTarget(edge.IssueID, edge.DependsOnID); err != nil {
|
||||
return HandleErrorRespectJSON("line %d: %v", edge.Line, err)
|
||||
}
|
||||
depEdges = append(depEdges, issueops.DependencyEdge{
|
||||
IssueID: edge.IssueID,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue