beads/internal/httpclient/gate_fields_test.go
Julian Knutsen 3862b03ff5
feat(http): gate await members on create and update over bd serve (#7589)
* feat(issueops): gate members on create and update, one bounds validator

The library half of serving gate await fields. Every local leg already
stores await_type, await_id, timeout and waiters on create, and await_id
on update; this adds the two missing pieces.

- IssuePatch.Waiters: a whole-value replacement of the waiter list (nil
  or empty clears, stored as []), mapped by UpdateFields and by the
  unit-of-work updateSpec, deep-copied by CloneUpdateRequest, and
  classified as a non-coordination signal on the dolt leg. Duplicates are
  stored as given; dedup stays the CLI's.
- ValidateGateFields / ValidateGatePatch with *issueops.GateFieldError
  {Field, Detail} wrapping ErrValidation, mirroring ReclaimFieldError so a
  front door can name the member. The rules are the columns' only:
  await_type <= 32 characters, await_id <= 255 characters, the JSON
  waiter list <= one TEXT column (65535 bytes), and timeout >= 0. No
  await_type allowlist, no gate-type-only rule, no timer-needs-timeout
  rule. Run from ValidatePublicCreateRequest (every create shape on every
  backend) and ValidateUpdateRequest (await_id, waiters).
- Conformance: LifecycleCreate WritesTheGateMembers / BoundsTheGateMembers,
  LifecycleUpdate PatchesTheGateMembers / BoundsTheGateMembers and
  BatchApply CarriesTheGateMembers, each bound asserted from both sides,
  wired on the dolt, embedded and uow legs and parked on the http leg on
  the live refusal rows until the wire slices land.
- httpclient: IssuePatch.Waiters is refused before the dial on both patch
  documents under a new W-IssuePatch.Waiters row (refuse-not-drop), until
  the wire publishes it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat(httpapi): publish the gate members on create and update

The wire half of serving gate await fields, over the library slice.

- createIssue and the issues:batchApply create item publish await_type,
  await_id, timeout (nanoseconds, the encoding Issue.timeout reads back)
  and waiters, behind the new behavior token issues.create.gates (one token
  for both create shapes, the issues.create.defaultPriority precedent).
- updateIssue's patch and the batchApply update item's patch publish
  await_id and waiters (whole-value replacement; [] clears), behind
  issues.update.gates. await_type and timeout are not patch members: no
  local update route changes them. Neither is nullable; null is refused
  naming the member, as on title.
- The handlers only decode and project (createGateMembers,
  patchGateMembers). The wire is no stricter than the library: every bound
  is the role's *issueops.GateFieldError (await_type <= 32, await_id <=
  255, the JSON waiter list <= one TEXT column, timeout >= 0), mapped to the
  existing 400 invalid_argument with param naming the member at its level
  (await_type, patch.waiters, items[i].create.timeout,
  items[i].update.patch.await_id). The spec mirrors exactly that:
  maxLength 32/255 and minimum 0, and no minLength/maxLength/maxItems on
  waiters. Blank and duplicate waiters and any await_type reach the role
  untouched.
- Spec: the four schemas, the capability prose, and the stale sentences
  (createIssue's "await_* publishes on no operation, read or write" and the
  patch's "spec_id and await_id publish nowhere yet"). apigen regenerated
  (from the remote drift test's diff), wireshape golden regenerated:
  additive entries and sides only, wire_revision stays 2.
- Client: the two tokens are mirrored in wire.behaviorCapabilities so the
  vocabulary stays set-equal with the server's. The client still refuses
  every gate member before the dial (the client slice flips that); the write-ledger
  pending sets name the newly published members under their live refusal
  rows, and the W-CreateRequest.Issue / W-IssuePatch.AwaitID /
  W-IssuePatch.Waiters reasons, the served-leg park reasons and the S4b
  waiver now say the server publishes them and this client does not send
  them yet.

Tests: internal/httpapi/gate_fields_test.go pins member mapping on all four
bodies, clear-by-empty on both patches, null and unpublished-member refusal,
GateFieldError -> param at every nesting level, and both tokens advertised.
Mutating the handlers (dropping the mapping, the GateFieldError arms or the
tokens) turns them red.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat(httpclient): send the gate members behind their tokens

The client half of serving gate await fields, over the wire slice.

- Create: await_type, await_id, timeout (nanoseconds) and waiters join the
  create vocabulary on createIssue and batchApply create items (now
  twenty-four members), sent verbatim when populated. Patch: await_id (by
  presence; "" clears) and waiters (whole-value; nil/empty travels as [])
  are encoded on both updateIssue's and the batchApply update item's patch.
- Token gate before the dial: a create naming any gate member needs
  issues.create.gates, a patch naming one needs issues.update.gates. Without
  the token the request refuses with wire.NewCapabilityError naming it
  (typed ErrUnsupported{Capability}), never a dropped member. batchApply
  checks the whole plan once, so no partial plan is sent. A request naming
  no gate member never reads either token. Store.requireCapabilityBeforeDial
  is the shared helper; requirePersistenceMove now uses it.
- Bounds read back typed: the server's 400 invalid_argument/invalid_value
  whose param names a gate member at any level (await_type, patch.waiters,
  items[i].create.timeout, items[i].update.patch.await_id) is rebuilt as the
  role's *issueops.GateFieldError, the problem kept in the chain (and a batch
  refusal still becomes its *ItemError). Without this the served bounds
  contracts could not pass.
- Ledger: W-IssuePatch.AwaitID RETIRED; the library slice's W-IssuePatch.Waiters row
  deleted (it never shipped outside this branch); W-CreateRequest.Issue and
  W-CreateItem.Issue no longer cover the gate members; new
  W-CreateRequest.Gates (refuse, Capability issues.create.gates) records the
  token-gated late refusal for both create shapes. engdocs ledger
  regenerated from Ledger() (262 rows: 201 refuse, 34 degrade, 27 retired).
- Write-ledger table: the wire slice's pending sets are flipped into carried.
- Served leg: the five gate cases (LifecycleCreate Writes/Bounds,
  LifecycleUpdate Patches/Bounds, BatchApply Carries) are un-parked and run;
  the S4b waiver and served comments now say await_id is sent.

Tests: internal/httpclient/gate_fields_test.go (encode on all four bodies,
clears, old-server refusal per member naming the token with no dial, no
partial batchApply plan, plain requests unaffected on old and new servers,
GateFieldError rebuilt from the problem). Disabling the three pre-dial
checks turns the refusal tests red.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* build(bazel): auto-sync BUILD files

Applied from the bazel-sync-patch artifact of https://github.com/gastownhall/beads/actions/runs/38841144413
(`make bazel-sync`: gazelle, tools/bazel/go_srcs.py, bazel mod tidy).
Only BUILD.bazel, MODULE.bazel and MODULE.bazel.lock are ever pushed; see
scripts/bazel-autofix-push.sh.

* docs(issueops): say the gate timeout rule is no column's

The gate validator's doc said its rules were the stored columns' and that
no command line can produce a negative timeout. The widths are the
columns' (VARCHAR(32), VARCHAR(255), TEXT), but timeout_ns is a BIGINT,
so a non-negative timeout is a rule no column enforces; the wire
publishes it as minimum 0. The raw store creates (CreateIssue,
CreateIssues) and import do not run the validator, so bd gate create
--timeout=-5m, a formula step's gate.timeout and a template clone still
store a negative timeout until they move onto the role.

Also say that GateFieldError.Detail is prose whose HTTP copy ends with
the server's own clause, so a caller dispatches on Field, and why a
create omits an empty waiter list while a patch sends [] to clear it.

Comments only; no behaviour change.

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(corpus): gh:run await_id persist refuses by the missing gate token

#7604 (now on main) made bd gate check persist a gh:run gate's discovered
run ID through Lifecycle.Update. Its served test expected the HTTP
client's W-IssuePatch.AwaitID refusal, which persistGateCheckAwaitID
rewords to name await_id. This PR retires that row: the patch carries
await_id behind issues.update.gates. Through the reference proxy, whose
server advertises no gate token, the persist is now refused before the
dial by the capability error ("bd serve at ... does not advertise
capability "issues.update.gates", which updateIssue requires"), so the
merged tree failed the subtest's await_id and updateIssue assertions.

The subtest now expects that refusal: no writes, the error names the
gate, the missing token and the server, no role or store method leaks,
and await_id is untouched. persistGateCheckAwaitID already returns a
capability error as the role raised it (#7604 pins that), so no code
changes. Against a server that advertises the token the persist goes
through: a scratch probe against the in-process server recorded
await_id=4242 and closed the gate.

Also correct the gate.go comment and the CHANGELOG entry that still said
the HTTP client refuses every await_id patch.

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 (1M context) <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Eddie the Engineer <adopt-pr@gascity.com>
2026-10-16 17:02:27 +00:00

398 lines
15 KiB
Go

package httpclient
import (
"errors"
"slices"
"strings"
"testing"
"time"
"github.com/steveyegge/beads/internal/httpapi/apigen"
"github.com/steveyegge/beads/internal/httpclient/wire"
"github.com/steveyegge/beads/issueops"
)
// The gate members: await_type, await_id, timeout and
// waiters on createIssue and batchApply create items, behind
// issues.create.gates; await_id and waiters on updateIssue's patch and
// batchApply update items' patch, behind issues.update.gates.
//
// Each pair below is the two sides of version skew:
//
// new client, new server the members are sent, verbatim, and nothing else
// about the request changes.
// new client, old server the cached handshake lacks the token, so the
// request refuses BEFORE the dial with the typed
// capability error naming it. Never a dropped member:
// a gate created without its await_type is a gate
// that never resolves, and a waiter dropped from a
// patch is a wake-up nobody receives.
// old client, either a request naming no gate member is untouched by
// the token, so the client never asks a server for a
// token it does not need.
// gateServer is a server that advertises both gate tokens beside the two
// stubStore's current server advertises.
func gateServer(t *testing.T, w *stubWire, caps ...string) *Store {
t.Helper()
return New(testTarget(t), w, &apigen.ContextResponse{
BdVersion: "1.2.3",
Capabilities: append([]string{wire.CapIssuesUpdateAllowTemplate, wire.CapIssuesUpdateClaim}, caps...),
})
}
func gateIssue() *issueops.Issue {
return &issueops.Issue{
Title: "gate",
IssueType: "gate",
AwaitType: "timer",
AwaitID: "run-42",
Timeout: 90 * time.Second,
Waiters: []string{"rig/workers/a", "rig/workers/a", "mayor"},
}
}
func TestCreateSendsTheGateMembersToAServerThatAdvertisesThem(t *testing.T) {
t.Run("createIssue", func(t *testing.T) {
w := &stubWire{}
lifecycle, err := gateServer(t, w, wire.CapIssuesCreateGates).IssueLifecycle()
if err != nil {
t.Fatal(err)
}
if _, err := lifecycle.Create(t.Context(), issueops.CreateRequest{Actor: "alice", Issue: gateIssue()}); err != nil {
t.Fatalf("Create: %v", err)
}
body := w.lastCreate
if got := derefStringPtr(body.AwaitType); got != "timer" {
t.Errorf("await_type = %q, want timer", got)
}
if got := derefStringPtr(body.AwaitId); got != "run-42" {
t.Errorf("await_id = %q, want run-42", got)
}
if body.Timeout == nil || *body.Timeout != int64(90*time.Second) {
t.Errorf("timeout = %v, want %d nanoseconds", body.Timeout, int64(90*time.Second))
}
// Stored as sent: the duplicate is the caller's to keep or drop.
if body.Waiters == nil || !slices.Equal(*body.Waiters, []string{"rig/workers/a", "rig/workers/a", "mayor"}) {
t.Errorf("waiters = %v, want the list verbatim", body.Waiters)
}
})
t.Run("batchApply create item", func(t *testing.T) {
w := &stubWire{}
applier, err := gateServer(t, w, wire.CapIssuesCreateGates).BatchApplier()
if err != nil {
t.Fatal(err)
}
req := applyOneCreate()
req.Items[0].Create.Issue = gateIssue()
if _, err := applier.ApplyBatch(t.Context(), req); err != nil {
t.Fatalf("ApplyBatch: %v", err)
}
item := w.lastApply.Items[0].Create
if derefStringPtr(item.AwaitType) != "timer" || derefStringPtr(item.AwaitId) != "run-42" {
t.Errorf("await_type/await_id = %v/%v, want timer/run-42", item.AwaitType, item.AwaitId)
}
if item.Timeout == nil || *item.Timeout != int64(90*time.Second) {
t.Errorf("timeout = %v, want %d nanoseconds", item.Timeout, int64(90*time.Second))
}
if item.Waiters == nil || len(*item.Waiters) != 3 {
t.Errorf("waiters = %v, want the three verbatim", item.Waiters)
}
})
}
// TestCreateRefusesTheGateMembersAgainstAServerWithoutTheToken is a new client
// against an old server, one member at a time, on both create shapes.
func TestCreateRefusesTheGateMembersAgainstAServerWithoutTheToken(t *testing.T) {
members := map[string]func(*issueops.Issue){
"AwaitType": func(i *issueops.Issue) { i.AwaitType = "human" },
"AwaitID": func(i *issueops.Issue) { i.AwaitID = "bead:bd-1" },
"Timeout": func(i *issueops.Issue) { i.Timeout = time.Minute },
"Waiters": func(i *issueops.Issue) { i.Waiters = []string{"mayor"} },
}
for name, populate := range members {
t.Run("createIssue/"+name, func(t *testing.T) {
issue := &issueops.Issue{Title: "t"}
populate(issue)
w := &stubWire{}
// The update token alone is not the create token.
lifecycle, err := gateServer(t, w, wire.CapIssuesUpdateGates).IssueLifecycle()
if err != nil {
t.Fatal(err)
}
_, err = lifecycle.Create(t.Context(), issueops.CreateRequest{Actor: "alice", Issue: issue})
requireCapabilityRefusal(t, err, wire.CapIssuesCreateGates, w)
if !errors.Is(err, wire.ErrCapabilityAbsent) {
t.Errorf("err = %v, want it to match wire.ErrCapabilityAbsent", err)
}
if !strings.Contains(err.Error(), wire.CapIssuesCreateGates) {
t.Errorf("refusal %q does not name %s", err.Error(), wire.CapIssuesCreateGates)
}
})
t.Run("batchApply/"+name, func(t *testing.T) {
issue := &issueops.Issue{Title: "t"}
populate(issue)
// The gate item is the SECOND of two: the whole plan is checked
// before the dial, so the plain create ahead of it is never sent
// on its own.
req := applyOneCreate()
req.Items = append(req.Items, issueops.ApplyItem{
Kind: issueops.ItemCreate, Create: &issueops.CreateItem{Issue: issue},
})
w := &stubWire{}
_, err := applyRoleWithSnapshot(t, w, &apigen.ContextResponse{
BdVersion: "1.2.3", Capabilities: []string{wire.CapIssuesUpdateGates},
}).ApplyBatch(t.Context(), req)
requireCapabilityRefusal(t, err, wire.CapIssuesCreateGates, w)
})
}
}
func TestUpdateSendsTheGateMembersToAServerThatAdvertisesThem(t *testing.T) {
for _, tc := range []struct {
name string
patch issueops.IssuePatch
want map[string]any
}{
{"await_id", issueops.IssuePatch{AwaitID: set("12345")}, map[string]any{"await_id": "12345"}},
// The empty string CLEARS await_id, so presence alone decides.
{"await_id clear", issueops.IssuePatch{AwaitID: set("")}, map[string]any{"await_id": ""}},
{"waiters", issueops.IssuePatch{Waiters: set([]string{"a", "a", "b"})}, map[string]any{"waiters": []string{"a", "a", "b"}}},
// A set nil list CLEARS; it travels as [] because null is refused.
{"waiters clear", issueops.IssuePatch{Waiters: set[[]string](nil)}, map[string]any{"waiters": []string{}}},
} {
t.Run("updateIssue/"+tc.name, func(t *testing.T) {
w := &stubWire{update: &apigen.UpdateIssueResponse{Revision: "7", Changed: true}}
lifecycle, err := gateServer(t, w, wire.CapIssuesUpdateGates).IssueLifecycle()
if err != nil {
t.Fatal(err)
}
if _, err := lifecycle.Update(t.Context(), issueops.UpdateRequest{
Actor: "alice", IssueID: "bd-g1", Patch: tc.patch,
}); err != nil {
t.Fatalf("Update: %v", err)
}
assertPatchDocument(t, w.lastPatch, tc.want)
})
t.Run("batchApply/"+tc.name, func(t *testing.T) {
w := &stubWire{}
applier, err := gateServer(t, w, wire.CapIssuesUpdateGates).BatchApplier()
if err != nil {
t.Fatal(err)
}
if _, err := applier.ApplyBatch(t.Context(), applyOneUpdate(tc.patch)); err != nil {
t.Fatalf("ApplyBatch: %v", err)
}
assertPatchDocument(t, w.lastApply.Items[0].Update.Patch, tc.want)
})
}
}
// TestUpdateRefusesTheGateMembersAgainstAServerWithoutTheToken is a new client
// against an old server on both patch documents.
func TestUpdateRefusesTheGateMembersAgainstAServerWithoutTheToken(t *testing.T) {
for name, patch := range map[string]issueops.IssuePatch{
"AwaitID": {AwaitID: set("12345")},
"Waiters": {Waiters: set([]string{"mayor"})},
// Beside an ordinary member the whole update still refuses: sending
// the title alone would be half the edit the caller asked for.
"Waiters beside a title": {Title: set("t"), Waiters: set([]string{"mayor"})},
} {
t.Run("updateIssue/"+name, func(t *testing.T) {
w := &stubWire{update: &apigen.UpdateIssueResponse{Revision: "7"}}
// The create token alone is not the update token.
lifecycle, err := gateServer(t, w, wire.CapIssuesCreateGates).IssueLifecycle()
if err != nil {
t.Fatal(err)
}
_, err = lifecycle.Update(t.Context(), issueops.UpdateRequest{Actor: "alice", IssueID: "bd-g1", Patch: patch})
requireCapabilityRefusal(t, err, wire.CapIssuesUpdateGates, w)
if !strings.Contains(err.Error(), wire.CapIssuesUpdateGates) {
t.Errorf("refusal %q does not name %s", err.Error(), wire.CapIssuesUpdateGates)
}
})
t.Run("batchApply/"+name, func(t *testing.T) {
// A plain create first: no partial plan is ever sent.
req := applyOneCreate()
req.Items = append(req.Items, applyOneUpdate(patch).Items...)
w := &stubWire{}
_, err := applyRoleWithSnapshot(t, w, &apigen.ContextResponse{
BdVersion: "1.2.3", Capabilities: []string{wire.CapIssuesCreateGates},
}).ApplyBatch(t.Context(), req)
requireCapabilityRefusal(t, err, wire.CapIssuesUpdateGates, w)
})
}
}
// TestARequestWithoutGateMembersIgnoresTheGateTokens is the old-client half
// of the skew: a create or patch naming no gate member dials an old server as
// it always has, and carries no gate member to a new one.
func TestARequestWithoutGateMembersIgnoresTheGateTokens(t *testing.T) {
for _, server := range []struct {
name string
caps []string
}{
{"old server", nil},
{"new server", []string{wire.CapIssuesCreateGates, wire.CapIssuesUpdateGates}},
} {
t.Run(server.name, func(t *testing.T) {
w := &stubWire{update: &apigen.UpdateIssueResponse{Revision: "7", Changed: true}}
store := gateServer(t, w, server.caps...)
lifecycle, err := store.IssueLifecycle()
if err != nil {
t.Fatal(err)
}
if _, err := lifecycle.Create(t.Context(), issueops.CreateRequest{
Actor: "alice", Issue: &issueops.Issue{Title: "plain"},
}); err != nil {
t.Fatalf("Create: %v", err)
}
body := w.lastCreate
if body.AwaitType != nil || body.AwaitId != nil || body.Timeout != nil || body.Waiters != nil {
t.Errorf("a plain create carries a gate member: %+v", body)
}
if _, err := lifecycle.Update(t.Context(), issueops.UpdateRequest{
Actor: "alice", IssueID: "bd-1", Patch: issueops.IssuePatch{Title: set("t")},
}); err != nil {
t.Fatalf("Update: %v", err)
}
for _, m := range []string{"await_id", "waiters"} {
if _, sent := w.lastPatch[m]; sent {
t.Errorf("a title patch carries %s: %v", m, w.lastPatch)
}
}
applier, err := store.BatchApplier()
if err != nil {
t.Fatal(err)
}
if _, err := applier.ApplyBatch(t.Context(), applyOneCreate()); err != nil {
t.Fatalf("ApplyBatch: %v", err)
}
if w.lastApply.Items[0].Create.Waiters != nil {
t.Errorf("a plain create item carries waiters")
}
})
}
}
func applyOneUpdate(patch issueops.IssuePatch) issueops.ApplyBatchRequest {
return issueops.ApplyBatchRequest{
Actor: "planner",
Items: []issueops.ApplyItem{{
Kind: issueops.ItemUpdate,
Update: &issueops.UpdateItem{Target: issueops.Ref{ID: "bd-g1"}, Patch: patch},
}},
}
}
func assertPatchDocument(t *testing.T, got, want map[string]any) {
t.Helper()
if len(got) != len(want) {
t.Errorf("patch = %v, want exactly %v", got, want)
}
for member, value := range want {
sent, ok := got[member]
if !ok {
t.Errorf("patch = %v, missing %s", got, member)
continue
}
switch v := value.(type) {
case []string:
list, ok := sent.([]string)
if !ok || list == nil || !slices.Equal(list, v) {
t.Errorf("patch.%s = %#v, want %#v", member, sent, v)
}
default:
if sent != v {
t.Errorf("patch.%s = %#v, want %#v", member, sent, v)
}
}
}
}
// TestABoundRefusalRebuildsTheGateFieldError pins the read side of the bounds:
// the server answers the role's *issueops.GateFieldError as a 400
// invalid_argument / invalid_value with `param` naming the member at its
// level, and each role hands the caller the same typed error a local
// backend raises, the problem still in the chain.
func TestABoundRefusalRebuildsTheGateFieldError(t *testing.T) {
problem := func(param string) error {
return &wire.ProblemError{
Op: "op", Status: 400, Code: "invalid_argument", Reason: "invalid_value",
Param: param, Detail: "the member is past its bound; nothing was written",
Err: issueops.ErrValidation,
}
}
assertField := func(t *testing.T, err error, field string) {
t.Helper()
var fieldErr *issueops.GateFieldError
if !errors.As(err, &fieldErr) {
t.Fatalf("err = %v, want a *GateFieldError naming %s", err, field)
}
if fieldErr.Field != field {
t.Errorf("GateFieldError.Field = %q, want %q", fieldErr.Field, field)
}
if !errors.Is(err, issueops.ErrValidation) {
t.Errorf("err = %v, want ErrValidation through", err)
}
var wireErr *wire.ProblemError
if !errors.As(err, &wireErr) {
t.Errorf("err = %v lost the problem it was read from", err)
}
}
caps := []string{wire.CapIssuesCreateGates, wire.CapIssuesUpdateGates}
t.Run("createIssue", func(t *testing.T) {
w := &stubWire{errs: []error{problem("await_type")}}
lifecycle, err := gateServer(t, w, caps...).IssueLifecycle()
if err != nil {
t.Fatal(err)
}
_, err = lifecycle.Create(t.Context(), issueops.CreateRequest{Actor: "alice", Issue: gateIssue()})
assertField(t, err, issueops.GateFieldAwaitType)
})
t.Run("updateIssue", func(t *testing.T) {
w := &stubWire{errs: []error{problem("patch.waiters")}}
lifecycle, err := gateServer(t, w, caps...).IssueLifecycle()
if err != nil {
t.Fatal(err)
}
_, err = lifecycle.Update(t.Context(), issueops.UpdateRequest{
Actor: "alice", IssueID: "bd-g1", Patch: issueops.IssuePatch{Waiters: set([]string{"a"})},
})
assertField(t, err, issueops.GateFieldWaiters)
})
t.Run("batchApply", func(t *testing.T) {
index := 0
bad := problem("items[0].update.patch.await_id").(*wire.ProblemError)
bad.ItemIndex = &index
kind := "update"
bad.ItemKind = &kind
w := &stubWire{errs: []error{bad}}
applier, err := gateServer(t, w, caps...).BatchApplier()
if err != nil {
t.Fatal(err)
}
_, err = applier.ApplyBatch(t.Context(), applyOneUpdate(issueops.IssuePatch{AwaitID: set("x")}))
assertField(t, err, issueops.GateFieldAwaitID)
var itemErr *issueops.ItemError
if !errors.As(err, &itemErr) || itemErr.Index != 0 {
t.Errorf("err = %v, want the *ItemError naming item 0", err)
}
})
t.Run("a refusal naming another member is untouched", func(t *testing.T) {
w := &stubWire{errs: []error{problem("patch.title")}}
lifecycle, err := gateServer(t, w, caps...).IssueLifecycle()
if err != nil {
t.Fatal(err)
}
_, err = lifecycle.Update(t.Context(), issueops.UpdateRequest{
Actor: "alice", IssueID: "bd-g1", Patch: issueops.IssuePatch{Title: set("t")},
})
var fieldErr *issueops.GateFieldError
if errors.As(err, &fieldErr) {
t.Errorf("err = %v reads as a GateFieldError for a title refusal", err)
}
})
}