* feat(http): serve IsBlockedBatch through the BlockingAnnotator role behind dependencies.blocking.isBlocked
gc's native ready cache needs bd's stored, transitive is_blocked column for
the active set (beads.BlockedQuerier.IsBlockedBatch). Over http the client
answered it with the generated stub, so every reconcile logged
`operation "IsBlockedBatch" not supported by the http backend`, the
projection stayed disabled and native Ready took ~5 s on the MC shadow.
No read a deployed (1.3.0) server serves can answer the column exactly:
the /v0 reads hydrate issues without is_blocked, the blocking decoration is
direct and two edge types only, and the flag also propagates down
parent-child edges and reads waits-for / conditional-blocks gates. So this
is an additive server behaviour plus a token, not a client-side
composition.
- issueops: BlockingRequest.IncludeIsBlocked asks for, and
IssueBlocking.IsBlocked carries, each answered id's stored flag (nil =
no row, never "free"). issueops.BlockedFlags is the one library entry
for the batched read over the role, chunked at BlockedFlagsChunk (100,
held equal to the served issue_id bound by an httpapi test).
- Bodies: storage/issueops.ExecuteBlockingAnnotation reads the flag with
IsBlockedBatchInTx in the same read transaction (dolt, embeddeddolt and
every sqlkit-style store that calls it); the unit-of-work body asks the
new DependencyUseCase/Repository IsBlockedBatch (same shared SQL body).
externaldeps keeps IsBlockedBatch's external-blocker invariant on the
local and remote annotators, and its Store.IsBlockedBatch no longer makes
the raw edge read over a role-served store.
- Wire: GET /v0/beads/dependencies/blocking accepts `is_blocked` behind the
new behaviour token dependencies.blocking.isBlocked (spec, apigen,
wire-shape golden). wire_revision stays 2.
- Client: httpBlockingAnnotator forwards IncludeIsBlocked and refuses it
BEFORE dialing with *ErrUnsupported{Capability:
dependencies.blocking.isBlocked} against a server that does not
advertise it; Store.IsBlockedBatch is issueops.BlockedFlags over that
annotator, so gc's errors.As latch still sees the typed refusal on an
old server, now naming the token that lifts it.
Tests: conformance case RunBlockingAnnotatorReportsTheTransitiveBlockedFlag
(child of a blocked parent is blocked, free is false, a ghost has no flag,
unasked carries none, BlockedFlags agrees) on the dolt, embedded, uow and
served legs; httpapi handler and chunk-bound tests; client tests for
chunking, the wire shape and the zero-dial refusal; vocabulary/capability
gates.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(externaldeps): keep the external blocker on the unit-of-work IsBlockedBatch
bd serve on a server or proxied-server workspace serves through the
unit-of-work arm (WrapUOWProvider) and advertises
policy.external_dependencies, so a client trusts the server's answers and
adds no external term of its own. That arm's dependency use case did not
override IsBlockedBatch, so the new dependencies.blocking.isBlocked flag
answered the stored is_blocked column, which has no external term. An issue
blocked only by an unsatisfied external: ref came back is_blocked=false,
with that ref listed in its own blocked_by, while GET /v0/beads/ready
excluded it.
dependencyUseCase.IsBlockedBatch now raises every id that has an
unsatisfied external blocker, deciding by the edges and resolver
GetReadyWork excludes by, read through the same unit of work. Unlike Ready
it resolves only the refs of the ids the column answered: a client asks in
chunks, and no chunk should reopen every foreign project the workspace
names. An id naming no row stays absent.
Also correct the store decorator's IsBlockedBatch doc (the served flag now
comes from the annotator role), add the CHANGELOG entry for the new
capability, and pin the flag against Ready on every arm: WrapUOWProvider,
directly and through its BlockingAnnotator (an absent id stays absent), the
local annotator, and the served test, which now asserts the flag and the
batched read. A counting opener pins that the unit-of-work read opens only
the foreign projects its asked rows name.
Checked against a real bd serve on a proxied-server workspace. At
97bcb57738 an issue blocked by external:remote:payments answered
is_blocked=false while /ready excluded it. With this change it answers
true, and once the capability ships /ready includes the issue and
is_blocked is false. Asked about a free issue alone, the server resolves
no external project; asked about the remote-blocked issue, it resolves
remote and leaves alone the unconfigured project another issue names.
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(externaldeps): pin that a satisfied external blocker leaves the unit-of-work is_blocked false
Review of 192b73676 (bee-ghosttrack): the two new IsBlockedBatch tests only
had unsatisfied external refs, so a body that raised every answered id with
any external record (ignoring the resolver) stayed green.
TestWrapUOWProviderBlockedFlagResolvesOnlyTheAskedRefs's opener now
returns a foreign store whose labelled index carries a CLOSED provider of
provides:payments (the decorator_test.go shape). be-shipped blocks on
external:remote:payments (satisfied) and must read false; be-blocked moves
to external:remote:invoices (still unsatisfied) and reads true; both still
open /projects/remote once. With the reviewer's mutant applied
(`if _, ok := answered[id]; ok && len(state.refsByIssue) >= 0 {`) the test
fails on be-shipped in both new cases; restored, it passes
(bazel test //internal/storage/externaldeps:externaldeps_test).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(externaldeps): pin the store arm's satisfied external ref and the unasked is_blocked flag
The store arm decides an external blocker in two places: IsBlockedBatch's
local loop skips a ref the resolver reports satisfied, and the
BlockingAnnotator role folds IsBlocked's verdict, which applies the same
filter, into the served flag. Both annotators, store and remote, add that
flag only when the request asks for it. No test checked either store answer
for a ref whose project had shipped the capability, or that an unasked
annotation carries no flag, so dropping any of those checks left the
package green.
Pin them: IsBlockedBatch and the store annotator answer false for a row
whose only blocker is external:remote:payments once remote has closed its
provides:payments issue, and neither annotator flags a row unasked, even
one an external ref blocks. This is the store half of bd-yewju3; the
previous commit pinned the unit-of-work half.
Each mutant below survives the package at the previous commit and fails
exactly one test here (go test -tags=gms_pure_go
./internal/storage/externaldeps/; unmutated, bazel test
//internal/storage/externaldeps:externaldeps_test passes):
- decorator.go IsBlockedBatch: `&& !satisfied[dep.DependsOnID]` made
`&& len(satisfied) >= 0` fails TestIsBlockedBatchHonorsShippedExternalRef.
- decorator.go IsBlocked: `if !satisfied[ref.raw] {` made always true fails
TestBlockingAnnotatorLeavesShippedExternalRefUnblocked.
- role_accessors.go: `if req.IncludeIsBlocked {` made `if true {` fails
TestBlockingAnnotatorAddsNoFlagUnasked.
- remote_roles.go: dropping `req.IncludeIsBlocked &&` fails
TestRemoteBlockingAnnotatorMergesExternalBlockers.
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
221 lines
9.8 KiB
Go
221 lines
9.8 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/steveyegge/beads/issueops"
|
|
)
|
|
|
|
// These cover the transport half of GET /v0/beads/dependencies/blocking: that
|
|
// the request reaches the role unaltered, the two size refusals this operation
|
|
// owns, how a role refusal is named on the wire, and the never-null members.
|
|
// Everything below the wire — which edge types count, which row's status decides
|
|
// an edge is live, the order within each list — is the role's, and is pinned by
|
|
// backend/conformance/blocking_annotator_contract.go at all three backends.
|
|
|
|
func newBlockingServer(t *testing.T, annotator *roleBlockingAnnotator) *testServer {
|
|
t.Helper()
|
|
return newTestServer(t, rolesConfig(Config{BlockingAnnotator: annotator}))
|
|
}
|
|
|
|
// TestBlockingAnnotationsPassTheIDsThroughUnaltered pins the half of this
|
|
// handler that is easiest to get wrong by helping: the ids go to the role in
|
|
// the order they arrived, repeats and all. Collapsing them is the ROLE's
|
|
// promise, and a handler that did it first would make the two front doors
|
|
// collapse in different places.
|
|
func TestBlockingAnnotationsPassTheIDsThroughUnaltered(t *testing.T) {
|
|
annotator := &roleBlockingAnnotator{}
|
|
ts := newBlockingServer(t, annotator)
|
|
|
|
ts.get(t, "/v0/beads/dependencies/blocking?issue_id=bd-2&issue_id=bd-1&issue_id=bd-2")
|
|
|
|
reads := annotator.blockingRequests()
|
|
if len(reads) != 1 {
|
|
t.Fatalf("the role saw %d requests, want exactly one", len(reads))
|
|
}
|
|
want := []string{"bd-2", "bd-1", "bd-2"}
|
|
if len(reads[0].IDs) != len(want) {
|
|
t.Fatalf("role saw IDs = %v, want %v", reads[0].IDs, want)
|
|
}
|
|
for i := range want {
|
|
if reads[0].IDs[i] != want[i] {
|
|
t.Fatalf("role saw IDs = %v, want %v", reads[0].IDs, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestBlockingAnnotationsCarryTheRoleAnswer pins the wire projection: one entry
|
|
// per annotated id, in the role's order, with the role's own struct as the
|
|
// element — which is what makes this body and `bd list`'s decoration one
|
|
// compatibility domain.
|
|
func TestBlockingAnnotationsCarryTheRoleAnswer(t *testing.T) {
|
|
annotator := &roleBlockingAnnotator{result: issueops.BlockingResult{Items: []issueops.IssueBlocking{
|
|
{ID: "bd-1", BlockedBy: []string{"bd-2", "external:ticket-9"}, Blocks: []string{}, Parent: "bd-9"},
|
|
{ID: "bd-3", BlockedBy: []string{}, Blocks: []string{"bd-1"}},
|
|
}}}
|
|
ts := newBlockingServer(t, annotator)
|
|
|
|
body := decodeBody(t, ts.get(t, "/v0/beads/dependencies/blocking?issue_id=bd-1&issue_id=bd-3"))
|
|
items, _ := body["items"].([]any)
|
|
if len(items) != 2 {
|
|
t.Fatalf("items = %v, want one entry per annotated id", body["items"])
|
|
}
|
|
first, _ := items[0].(map[string]any)
|
|
if first["id"] != "bd-1" || first["parent"] != "bd-9" {
|
|
t.Errorf("items[0] = %v, want bd-1 with parent bd-9", first)
|
|
}
|
|
blockedBy, _ := first["blocked_by"].([]any)
|
|
if len(blockedBy) != 2 || blockedBy[0] != "bd-2" || blockedBy[1] != "external:ticket-9" {
|
|
t.Errorf("items[0].blocked_by = %v, want the role's list in the role's order", first["blocked_by"])
|
|
}
|
|
second, _ := items[1].(map[string]any)
|
|
// An entry with no parent omits the member rather than shipping "": the
|
|
// document types it as optional and a client reads absence as "no parent".
|
|
if _, present := second["parent"]; present {
|
|
t.Errorf("items[1] carries a `parent` %v; an id with none omits the member", second["parent"])
|
|
}
|
|
}
|
|
|
|
// TestBlockingAnnotationsNeverAnswerNull pins both lists and the envelope as
|
|
// empty arrays rather than null: a client that ranges over the answer must not
|
|
// have to nil-check any of them, which is what "always present" in the document
|
|
// means.
|
|
func TestBlockingAnnotationsNeverAnswerNull(t *testing.T) {
|
|
annotator := &roleBlockingAnnotator{result: issueops.BlockingResult{Items: []issueops.IssueBlocking{
|
|
{ID: "bd-1", BlockedBy: []string{}, Blocks: []string{}},
|
|
}}}
|
|
ts := newBlockingServer(t, annotator)
|
|
|
|
raw := readAll(t, ts.get(t, "/v0/beads/dependencies/blocking?issue_id=bd-1"))
|
|
if strings.Contains(raw, "null") {
|
|
t.Fatalf("body = %s, want empty arrays rather than null", raw)
|
|
}
|
|
|
|
// And the envelope itself, for a role that answered with a nil slice: the
|
|
// wire promise does not depend on the role keeping its own.
|
|
bare := newBlockingServer(t, &roleBlockingAnnotator{})
|
|
if got := readAll(t, bare.get(t, "/v0/beads/dependencies/blocking?issue_id=bd-1")); strings.Contains(got, "null") {
|
|
t.Fatalf("body = %s, want an empty items array rather than null", got)
|
|
}
|
|
}
|
|
|
|
// TestBlockingAnnotationsBoundTheQuestion pins the two refusals this operation
|
|
// owns. They are on the ID COUNT rather than on the answer, and they share
|
|
// maxDependencyAnchors with the stored-edge read: the two operations are asked
|
|
// about the same page of ids, and two different numbers would let a client ask
|
|
// one of them about a page the other refuses.
|
|
func TestBlockingAnnotationsBoundTheQuestion(t *testing.T) {
|
|
ts := newBlockingServer(t, &roleBlockingAnnotator{})
|
|
|
|
for _, tc := range []struct {
|
|
name string
|
|
query string
|
|
}{
|
|
{"no issue_id at all", "/v0/beads/dependencies/blocking"},
|
|
{"more ids than the cap", "/v0/beads/dependencies/blocking?" + repeatedIssueIDs(maxDependencyAnchors+1)},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
resp := ts.get(t, tc.query)
|
|
if resp.StatusCode != http.StatusBadRequest {
|
|
t.Fatalf("status = %d, want 400: %s", resp.StatusCode, readAll(t, resp))
|
|
}
|
|
body := decodeBody(t, resp)
|
|
if body["code"] != string(CodeInvalidArgument) || body["param"] != "issue_id" || body["reason"] != string(ReasonInvalidValue) {
|
|
t.Errorf("problem = %v, want invalid_argument on issue_id with invalid_value", body)
|
|
}
|
|
})
|
|
}
|
|
|
|
// The cap is a bound, not a rejection of large requests: exactly the cap is
|
|
// served.
|
|
if resp := ts.get(t, "/v0/beads/dependencies/blocking?"+repeatedIssueIDs(maxDependencyAnchors)); resp.StatusCode != http.StatusOK {
|
|
t.Errorf("status = %d for exactly %d ids, want 200: %s", resp.StatusCode, maxDependencyAnchors, readAll(t, resp))
|
|
}
|
|
}
|
|
|
|
// TestBlockingAnnotationsRefuseAnUnknownParameter keeps this operation under
|
|
// the document's uniform rule. It publishes exactly ONE parameter, so a client
|
|
// that guessed at a `type` or `direction` filter would otherwise receive the
|
|
// unfiltered decoration and believe it narrowed.
|
|
func TestBlockingAnnotationsRefuseAnUnknownParameter(t *testing.T) {
|
|
ts := newBlockingServer(t, &roleBlockingAnnotator{})
|
|
|
|
resp := ts.get(t, "/v0/beads/dependencies/blocking?issue_id=bd-1&type=blocks")
|
|
if resp.StatusCode != http.StatusBadRequest {
|
|
t.Fatalf("status = %d, want 400: %s", resp.StatusCode, readAll(t, resp))
|
|
}
|
|
body := decodeBody(t, resp)
|
|
if body["param"] != "type" || body["reason"] != string(ReasonUnknownParameter) {
|
|
t.Errorf("problem = %v, want unknown_parameter on type", body)
|
|
}
|
|
}
|
|
|
|
// TestABlockingRoleRefusalIsTheDocumentedBadRequest pins the mapping from the
|
|
// role's ErrValidation onto the one parameter that can cause it, and that
|
|
// nothing else becomes a 400.
|
|
func TestABlockingRoleRefusalIsTheDocumentedBadRequest(t *testing.T) {
|
|
ts := newBlockingServer(t, &roleBlockingAnnotator{
|
|
err: fmt.Errorf("annotate blocking: %w", issueops.ErrValidation),
|
|
})
|
|
resp := ts.get(t, "/v0/beads/dependencies/blocking?issue_id=bd-1&issue_id=")
|
|
if resp.StatusCode != http.StatusBadRequest {
|
|
t.Fatalf("status = %d, want 400: %s", resp.StatusCode, readAll(t, resp))
|
|
}
|
|
body := decodeBody(t, resp)
|
|
if body["code"] != string(CodeInvalidArgument) || body["param"] != "issue_id" || body["reason"] != string(ReasonInvalidValue) {
|
|
t.Errorf("problem = %v, want invalid_argument on issue_id with invalid_value", body)
|
|
}
|
|
|
|
opaque := newBlockingServer(t, &roleBlockingAnnotator{err: errors.New("backend is unreachable")})
|
|
if resp := opaque.get(t, "/v0/beads/dependencies/blocking?issue_id=bd-1"); resp.StatusCode != http.StatusInternalServerError {
|
|
t.Errorf("status = %d for an opaque role failure, want 500: %s", resp.StatusCode, readAll(t, resp))
|
|
}
|
|
}
|
|
|
|
// TestBlockingAnnotationsCarryTheTransitiveFlagWhenAsked pins the
|
|
// dependencies.blocking.isBlocked parameter: `is_blocked=true` reaches the
|
|
// role as IncludeIsBlocked, the role's flag is shipped as `is_blocked`, an
|
|
// item without one omits the member, and a request without the parameter
|
|
// asks for nothing.
|
|
func TestBlockingAnnotationsCarryTheTransitiveFlagWhenAsked(t *testing.T) {
|
|
blocked := true
|
|
annotator := &roleBlockingAnnotator{result: issueops.BlockingResult{Items: []issueops.IssueBlocking{
|
|
{ID: "bd-1", BlockedBy: []string{}, Blocks: []string{}, IsBlocked: &blocked},
|
|
{ID: "bd-ghost", BlockedBy: []string{}, Blocks: []string{}},
|
|
}}}
|
|
ts := newBlockingServer(t, annotator)
|
|
|
|
body := decodeBody(t, ts.get(t, "/v0/beads/dependencies/blocking?issue_id=bd-1&issue_id=bd-ghost&is_blocked=true"))
|
|
reads := annotator.blockingRequests()
|
|
if len(reads) != 1 || !reads[0].IncludeIsBlocked {
|
|
t.Fatalf("role saw %+v, want one request with IncludeIsBlocked", reads)
|
|
}
|
|
items, _ := body["items"].([]any)
|
|
if len(items) != 2 {
|
|
t.Fatalf("items = %v", body["items"])
|
|
}
|
|
if first, _ := items[0].(map[string]any); first["is_blocked"] != true {
|
|
t.Errorf("items[0].is_blocked = %v, want true", first["is_blocked"])
|
|
}
|
|
if second, _ := items[1].(map[string]any); second["is_blocked"] != nil {
|
|
t.Errorf("items[1] carries is_blocked %v; an item with no flag omits it", second["is_blocked"])
|
|
}
|
|
|
|
ts.get(t, "/v0/beads/dependencies/blocking?issue_id=bd-1")
|
|
if reads := annotator.blockingRequests(); len(reads) != 2 || reads[1].IncludeIsBlocked {
|
|
t.Errorf("a request without is_blocked asked for the flag: %+v", reads)
|
|
}
|
|
}
|
|
|
|
// TestBlockedFlagsChunkIsTheServedAnchorBound holds issueops.BlockedFlagsChunk
|
|
// to this operation's issue_id bound, so the library entry never asks a
|
|
// question the served operation refuses.
|
|
func TestBlockedFlagsChunkIsTheServedAnchorBound(t *testing.T) {
|
|
if issueops.BlockedFlagsChunk != maxDependencyAnchors {
|
|
t.Errorf("issueops.BlockedFlagsChunk = %d, maxDependencyAnchors = %d; they must be equal", issueops.BlockedFlagsChunk, maxDependencyAnchors)
|
|
}
|
|
}
|