* feat(httpclient): wire the S4 Sweeper extension (wisps-plane, live-dependent protection, limit)
Publish SweepRequest.ProtectLiveDependents and .Limit (plus a
wisps-plane tier and SweepResult.Remaining/.LiveDependent) on the v0
wire behind three new behavior-capability tokens
(issues.sweep.wispsPlane, issues.sweep.liveDependents,
issues.sweep.limit), and wire the client to send them once the
handshake advertises the tokens (refuseUnservedSweep otherwise).
Retire the two W-SweepRequest ledger rows that previously refused
these fields for lack of a wire member.
CurrentWireRevision stays at 2. A new wisps-plane SweepRequest.Tier
value is a request-only enum widening: it cannot cause an older
client to misdecode a response, and it is already gated by its own
capability token, so it is additive rather than a wire break. Teach
wireshape's drift gate that distinction directly: a Digest.Sides side
channel records whether each schema member is request-only,
response-only or both, and widensAdditively now treats a request-only
enum's new value as additive while still treating any response-side
widening as breaking, with tests pinning both directions and a
regenerated golden.json. min_client_wire_revision stays 0.
internal/httpapi/apigen/types.gen.go and openapi.v0.yaml's comments are
regenerated/updated to match (make api-gen).
Six served Sweeper contracts that were parked now run for real against
the in-process HTTP server; TestSweepSendsTheS4MembersOnceTheServerAdvertisesThem
pins the capability-gated encode.
Re-review fix: walk()'s side classification short-circuited on a
name-only visited set, so a node already walked from one side never
had its CHILDREN walked again when a later path promoted the parent
to "both" — children stayed classified under whichever side reached
them first, order-dependent on Go's map iteration. Side recursion is
now guarded per (schema, side) pair (sideWalked, keyed on
name+"\x00"+side) instead of per schema name alone, so a child
reachable from both sides is always walked, and therefore recorded,
from both. Added TestSidePropagatesToNestedChildren (a named grandchild
and an inline nested child both reachable from a request body and,
via a wrapper, a response, assert "both" on every level and that
widening either enum breaks instead of being classed additive),
TestEnumWideningOnSharedNestedChildIsNotAdditive, and
TestComputeFromSideAssignmentIsDeterministic (200 runs, asserts
identical Sides/Entries every time). golden.json is confirmed
unchanged by the fix (regenerated and diffed byte-for-byte). Also
removes a bd-enterprise mention introduced in this slice's own
write_ledger_test.go comment (not a provenance header) in favor of
neutral wording.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(storage): ratchet the http leg's role-contract ceiling to zero
Classify all 42 previously-ceilinged http-leg entrypoints and clear
the ceiling:
- ExpectedRevision + Refusal (10): wire a Phase-0 all-nil fixture,
matching every other backend's current (unbuilt-CAS-feature) state.
Said honestly: these ten entrypoints are counted here, the hook is
unbuilt on every leg (not just this one), and every case runs zero
assertions until a CompareAndSetVersion wire operation exists for
this client to bind.
- Lifecycle ExpectedVersion concurrency (4): wire the two races that
land on Priority/Notes and on Close for real over the served HTTP
harness (precondition_failed decodes to storage.ErrVersionMismatch
via errors.Is, same as the local legs). The other two, which race
IssuePatch.SpecID/.AwaitID/.Owner edits against updateIssue, stay
waived, but PENDING rather than permanent: IssuePatchBody refuses
those three fields outright (W-IssuePatch.SpecID/.AwaitID/.Owner,
D8 refuse-not-drop) rather than ever sending them, so the race never
reaches the wire today. Closing the gap means publishing those
fields on the wire, tracked as a follow-up slice, S4b: publish
owner/spec_id/await_id on the wire.
- DualWrite (6): wired for real instead of waived. Mutate and
MutateAsNoOp drive the client's Lifecycle role (Create/Update)
against an in-process served harness with its own reference store,
so VersionedHistoryConfigurer can be toggled per fixture;
CurrentRevision, VersionRowCount and LatestVersionAttribution read
the reference store's raw columns the same way every other served
fixture's postcondition hooks do. All six FR-1/FR-2/FR-3/FR-5/FR-7
cases (one version row per accepted mutation, no-op skip, atomic
attribution, current_revision parity, and flag-off producing no
rows) now run and pass.
- VersionReconciler + InitVerifier (13), and the raw
IssueOperationsUpdate seam (3): waived — unservable over a typed
HTTP role boundary, not a wiring gap.
adoptionCeiling: 42 -> 0 for the http leg; the "adopting" field is
removed (a zero ceiling with a reason is a registry error) since every
remaining gap is now a named waiver, PENDING or permanent as stated
above, instead of a budgeted unnamed one. Also deletes the scratch
zzz_dump_missing_test.go used to enumerate the ceiling during triage.
Re-review fix: the shared conformance attribution case only asserts
change_actor is non-empty (it runs across every leg, each with a
different literal Mutate actor). The http fixture's own Mutate always
sends Actor: "writer", so this leg's AttributionIsRecordedWithTheMutation
subtest now also mutates a second, independent issue and asserts the
recorded actor equals exactly "writer", in addition to the shared
non-empty check.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(types): make ParseRevisionToken the exact inverse of FormatInt
ParseRevisionToken's doc comment already promised it accepts exactly
what RevisionToken emits, but strconv.ParseInt alone is looser than
that: besides a leading "+" that FormatInt never produces, it also
accepts a leading zero on a digit string longer than one character
("007") and the literal "-0" — none of which FormatInt ever emits
(FormatInt(0, 10) is always "0", never "-0", and it never pads a
digit run). A caller is only ever supposed to echo a token a response
carried, so any of these is a client that invented a value rather
than a server this client should follow; reject them explicitly
instead of accepting them silently.
Pins the string<->int64 boundary with
TestParseRevisionTokenRejectsMalformedTokens, covering empty strings,
fractional/exponent spellings, leading "+", surrounding whitespace,
non-decimal bases, one-past-int64-boundary values, non-ASCII digits,
and now "007", "-007" and "-0".
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fixup(wireshape): guard widensAdditively against "no enum before"
bee-ghosttrack / CHANGES_REQUESTED on #7251: widensAdditively required
len(new.Enum) > len(old.Enum), which holds vacuously when the old side
has no enum at all (a free `type: string`). That let a request-only
member go from unconstrained to a fixed enum at the same wire_revision
-- the opposite of widening, since the server now 400s a value an old
client could send yesterday.
Add the guard `len(old.Enum) == 0 || len(new.Enum) <= len(old.Enum) ->
false` so the no-enum-before case falls through to the ordinary
non-additive Changed path, same as a strict narrowing. Add a pinning
case to TestEnumWideningAdditivity and extend the doc comment.
Also reword the ExpectedRevision contract file comment from "runs ZERO
assertions" to "SKIPS", per the reviewer's note that the Run* helpers
t.Skip when CompareAndSetVersion is nil -- it's a skip, not an
assertion-free run.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* docs(httpclient): regenerate the divergence ledger after rebasing onto #7247's review fixes
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* test(httpclient): Sweep Limit now refuses on the missing issues.sweep.limit capability
#7247's review round pinned Sweep{Limit} as an encoder refusal. With S4 the
wire carries limit behind issues.sweep.limit, so against a server without
the token the refusal is a pre-dial capability refusal: still
*storage.ErrUnsupported for this backend, now naming the capability.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(httpapi,httpclient): name the invalid_value refusal; add tests to Bazel
Maintainer fixup for the review of #7251 (iteration 1). There are no blocker or
major findings. This applies the three optional findings that both reviewers
reported.
- Eight comment and description sites added by this PR say that an older
server refuses an unpublished `tier` (or S4) member with `unknown_value`.
No such reason exists. The server refuses with ReasonInvalidValue =
"invalid_value" (internal/httpapi/problem.go), and sweep.go uses it for a
bad tier. The sites are in openapi.v0.yaml, apigen/types.gen.go (regenerated
by `make api-gen`), routes.go, sweeper.go and wire/handshake.go. The base has
none of them, so this only corrects the PR's own text. A client author now
matches the token the server actually sends.
- wire/handshake.go said the tier member carries no ledger row because it
"narrows" an existing enum. Adding a value widens the accepted set, so the
word is now "widens".
- internal/httpclient/BUILD.bazel: add expected_revision_contract_test.go and
served_dualwrite_history_test.go to the httpclient_test srcs. Both files are
new in this PR. Without the entries, `go test` runs them but no Bazel lane
compiles them. The srcs list now matches the package's files, and the
existing deps already cover their imports.
Provenance: this is the residue of the stranded fixup cad1cf02a2 from the
previous adoption of this PR, replayed onto the current head. Its patch-id
(b62e7d6d5562) is identical to that reviewed residue. That fixup's
widensAdditively guard and SKIP-message nit are not repeated here. The author
already landed both in b3f1516e55 (d41f317e0a after the rebase).
Validation: git diff --check; make api-gen (no-op) and make api-check;
go build, go vet and gofmt on internal/httpapi/... and internal/httpclient/...;
go test for internal/httpclient/wire, internal/httpclient/encode and
test/docsync; the httpclient Sweep* and TestExpectedRevisionContract tests; the
served dual-write tests with BEADS_TEST_EMBEDDED_DOLT=1; and
tools/bazel/go_srcs.py --check.
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs(httpclient): regenerate the divergence ledger on main after #7247 merged
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(httpclient): give encode_test the httpclient tests its pin check reads
Maintainer fixup for the pre-review CI of #7251. Bazel / test and
Bazel / integration (PR run 37781419956) each fail one target,
//internal/httpclient/encode:encode_test, which also fails CI Gate / Required.
TestLedgerRowsAreWellFormed reports that rows W-SweepRequest.ProtectLiveDependents
and W-SweepRequest.Limit are pinned by
TestSweepSendsTheS4MembersOnceTheServerAdvertisesThem, which is "neither a test
in this package nor a TODO(<bead>)".
The pin is right. The test lives in internal/httpclient/bulk_roles_test.go.
testFunctionsInThisPackage collects test names from ".", ".." and
../../../cmd/bd, but the data of encode_test declares only its own sources,
//cmd/bd:go_srcs, the ledger doc and the OpenAPI spec. Under Bazel, ".."
exists in the runfiles but holds no _test.go files, so the walk silently finds
nothing there. go test reads the real directory and passes. This PR changes
neither the walk nor the BUILD file. Every pin on main resolves from this
package or cmd/bd, which is why main is green. These two rows are the only ones
pinned to a test that exists only in internal/httpclient. The red stayed hidden
until now because the PR sat on a stacked base. PR CI, including the Bazel
lanes, runs only for PRs against main, release/** and hotfix/**.
Declare //internal/httpclient:go_srcs as data, so Bazel sees the files that
go test reads. The filegroup already exists with //:__subpackages__ visibility.
The pins stay on the test that actually covers the S4 members.
Validation: bazel test //internal/httpclient/encode:encode_test --config=ci
--nocache_test_results, run two ways. In the local processwrapper sandbox
(--remote_executor= --strategy=TestRunner=processwrapper-sandbox) the same
command fails both rows without this change and passes with it. It also passes
on the remote executor. Plus tools/bazel/go_srcs.py --check, gazelle
-mode=diff on the package (no change), git diff --check, and
go test ./internal/httpclient/encode/.
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(httpapi): pin the S4 sweep members at the wire edge, gate golden sides
The `sides` map this change adds to golden.json predates schemas main gained
since (#7248's BatchGetIssue*, BatchGetIssuesRequest* and
BatchGetIssuesResult*, plus IssueDetails.gated_by[]), so the rebase left it 9
schemas short of what gendigest writes, and goldenDrift never compared Sides,
so nothing noticed. Regenerated (+9 sides lines, no entry changes), and
goldenDrift now fails with the regenerate instruction when the golden's sides
disagree with a fresh digest; TestGoldenDrift drives that arm three ways.
The SweepSkips description still called the first two buckets protections
and the last four defenses, which filed the new live_dependent protection
under the defenses. It now names pinned, referenced and live_dependent as the
protections (apigen regenerated: the two comment copies only), and
handleSweep's comment counts eight members.
internal/httpapi's sweep pins stopped at the original six members: nothing
there sent protect_live_dependents or limit, refused a mistyped one, or read
live_dependent or remaining back. The forward, refuse and publish tests now
cover all four, and TestSweepResponseCarriesEveryRoleField, named by
sweepResponse's comment but never written, counts both projection levels and
requires every wire field populated from a fully set role result.
The httpclient Sweep defer comment described ProtectLiveDependents/Limit
refusal paths this change replaced with capability gates; it now says why
the pass-through defer stays.
Validation: go test ./internal/httpapi/... ./internal/httpclient/... (CGO,
gms_pure_go), the served sweeper tier with BEADS_TEST_EMBEDDED_DOLT=1 (19/19
pass, none skipped), make api-check, go vet, git diff --check, and bazel test
--config=ci on httpapi_test, wireshape/..., httpclient_test, encode_test and
types_gen_drift_test. Mutants, each restored: disabling the sides arm reds
three TestGoldenDrift arms; the pre-fix golden reds TestWireShapeDigest
naming the 9 schemas; dropping the live_dependent or remaining projection,
the protect_live_dependents decode, or the limit assignment each reds its
new pin.
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 Sonnet 5 <noreply@anthropic.com>
299 lines
11 KiB
Go
299 lines
11 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"net/http"
|
|
"slices"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/steveyegge/beads/internal/httpapi/apigen"
|
|
"github.com/steveyegge/beads/issueops"
|
|
)
|
|
|
|
// The request body's member vocabulary. The schema is
|
|
// additionalProperties: false, so anything else is refused BY NAME — the same
|
|
// posture the unknown-query-parameter rule takes, and on this operation for a
|
|
// sharper reason: a narrowing term the server silently ignored would widen
|
|
// what is erased.
|
|
const (
|
|
sweepTierMember = "tier"
|
|
sweepActorMember = "actor"
|
|
sweepClosedBeforeMember = "closed_before"
|
|
sweepPatternMember = "pattern"
|
|
sweepProtectReferencedMember = "protect_referenced"
|
|
sweepDryRunMember = "dry_run"
|
|
sweepProtectLiveDependentsMember = "protect_live_dependents"
|
|
sweepLimitMember = "limit"
|
|
)
|
|
|
|
// sweepMembers is the whole vocabulary, in one place, so the unknown-member
|
|
// refusal and the decoding below cannot come to disagree about what this
|
|
// operation accepts.
|
|
var sweepMembers = []string{
|
|
sweepTierMember,
|
|
sweepActorMember,
|
|
sweepClosedBeforeMember,
|
|
sweepPatternMember,
|
|
sweepProtectReferencedMember,
|
|
sweepDryRunMember,
|
|
sweepProtectLiveDependentsMember,
|
|
sweepLimitMember,
|
|
}
|
|
|
|
// handleSweep answers POST /v0/beads/issues:sweep — one of the two DESTRUCTIVE
|
|
// operations on this surface, the other being issues:delete.
|
|
//
|
|
// WHAT THIS HANDLER DOES NOT DO. It does not decide which beads are closed,
|
|
// does not match the glob, does not recheck closed_at, does not protect pinned
|
|
// beads, and — the one that matters most — does not implement the
|
|
// require-a-filter safety gate. All of that is issueops.Sweeper, the same
|
|
// library surface `bd prune` calls, so this endpoint could not erase every
|
|
// closed bead in a workspace by omission even if a future edit here forgot the
|
|
// rule existed. With the gate in the CLI handler instead, a second front door
|
|
// would be one handler away from an unguarded mass delete.
|
|
//
|
|
// Everything above the role here is argument validation: the media type, the
|
|
// body shape, and the eight members the document publishes.
|
|
//
|
|
// NO ACTOR IS INFERRED, for the reason the claim gives: the server's own
|
|
// identity is meaningless to a remote caller. Unlike the claim, the actor is
|
|
// OPTIONAL here — a deleted bead leaves no row to attribute the deletion on —
|
|
// and it is validated by the same rules when present, because it reaches the
|
|
// same commit-message interpolation.
|
|
func (s *Server) handleSweep(w http.ResponseWriter, r *http.Request) {
|
|
if !s.requireNoQuery(w, r) {
|
|
return
|
|
}
|
|
if !s.requireJSONContent(w, r) {
|
|
return
|
|
}
|
|
request, ok := s.sweepRequest(w, r)
|
|
if !ok {
|
|
return
|
|
}
|
|
|
|
sweeper, err := s.sweeper(r)
|
|
if err != nil {
|
|
s.failErr(w, r, err)
|
|
return
|
|
}
|
|
result, err := sweeper.Sweep(r.Context(), request)
|
|
if err != nil {
|
|
s.failSweepErr(w, r, err)
|
|
return
|
|
}
|
|
writeJSON(w, sweepResponse(result))
|
|
}
|
|
|
|
// sweepRequest decodes the body into the role's request, member by member.
|
|
//
|
|
// Member by member rather than straight into apigen.SweepRequest so that every
|
|
// refusal can NAME the member it is about: unmarshaling the generated struct
|
|
// reports a type mismatch only inside an error string, and this endpoint
|
|
// exists so clients can stop parsing prose.
|
|
func (s *Server) sweepRequest(w http.ResponseWriter, r *http.Request) (issueops.SweepRequest, bool) {
|
|
members, res := decodeJSONObjectBody(w, r)
|
|
if res != nil {
|
|
s.fail(w, r, *res)
|
|
return issueops.SweepRequest{}, false
|
|
}
|
|
|
|
var unknown []string
|
|
for name := range members {
|
|
if !slices.Contains(sweepMembers, name) {
|
|
unknown = append(unknown, name)
|
|
}
|
|
}
|
|
if len(unknown) > 0 {
|
|
// One offender, chosen deterministically so a client dispatching on
|
|
// `param` never sees it depend on map order.
|
|
offender := slices.Min(unknown)
|
|
requestInfo(r.Context()).refuse(offender)
|
|
s.fail(w, r, InvalidArgument(offender, ReasonUnknownParameter,
|
|
"this operation's request body carries "+sweepMemberList()+" and nothing else"))
|
|
return issueops.SweepRequest{}, false
|
|
}
|
|
|
|
var request issueops.SweepRequest
|
|
// protect_referenced DEFAULTS ON over HTTP, and the default is set here
|
|
// rather than left to the zero value on purpose.
|
|
//
|
|
// This is the only destructive operation on the surface, and a configured
|
|
// bearer is not a per-caller right: one shared token admits a client to
|
|
// everything published here, so being authenticated says nothing about
|
|
// whether this particular deletion was meant. A remote caller that omits
|
|
// the member must not get weaker protection than the operator typing `bd
|
|
// prune`, which protects unless --ignore-references is passed. Leaving the
|
|
// zero value would have inverted exactly that: locally you opt OUT of
|
|
// protection, remotely you had to opt IN.
|
|
//
|
|
// The cost is a full scan of the not-done set and its comments. A caller
|
|
// that wants the cheaper sweep asks for it by sending
|
|
// `protect_referenced: false`.
|
|
request.ProtectReferenced = true
|
|
|
|
raw, ok := members[sweepTierMember]
|
|
if !ok {
|
|
s.fail(w, r, InvalidArgument(sweepTierMember, ReasonInvalidValue,
|
|
"`"+sweepTierMember+"` is required and has no default"))
|
|
return issueops.SweepRequest{}, false
|
|
}
|
|
var tier *string
|
|
if err := json.Unmarshal(raw, &tier); err != nil || tier == nil {
|
|
s.fail(w, r, InvalidArgument(sweepTierMember, ReasonInvalidValue,
|
|
"`"+sweepTierMember+"` must be a string"))
|
|
return issueops.SweepRequest{}, false
|
|
}
|
|
// The enum check uses the GENERATED validator, which is derived from the
|
|
// document rather than a second hand-written copy of the vocabulary. The
|
|
// role refuses an unrecognized tier too; this is here so the refusal can
|
|
// name the member.
|
|
if !apigen.SweepRequestTier(*tier).Valid() {
|
|
s.fail(w, r, InvalidArgument(sweepTierMember, ReasonInvalidValue,
|
|
"`"+sweepTierMember+"` must be \"ephemeral\", \"durable\", or \"wisps-plane\""))
|
|
return issueops.SweepRequest{}, false
|
|
}
|
|
request.Tier = issueops.SweepTier(*tier)
|
|
|
|
if raw, ok := members[sweepActorMember]; ok {
|
|
var value *string
|
|
if err := json.Unmarshal(raw, &value); err != nil || value == nil {
|
|
s.fail(w, r, InvalidArgument(sweepActorMember, ReasonInvalidValue,
|
|
"`"+sweepActorMember+"` must be a string"))
|
|
return issueops.SweepRequest{}, false
|
|
}
|
|
// The claim's rules, unchanged: trim, then refuse empty, over-long and
|
|
// any control character. `param` reads "actor" there too, so the two
|
|
// operations are one vocabulary for a client.
|
|
trimmed, res := validateActor(*value)
|
|
if res != nil {
|
|
s.fail(w, r, *res)
|
|
return issueops.SweepRequest{}, false
|
|
}
|
|
request.Actor = trimmed
|
|
}
|
|
|
|
if raw, ok := members[sweepClosedBeforeMember]; ok {
|
|
var value *time.Time
|
|
if err := json.Unmarshal(raw, &value); err != nil || value == nil {
|
|
s.fail(w, r, InvalidArgument(sweepClosedBeforeMember, ReasonInvalidValue,
|
|
"`"+sweepClosedBeforeMember+"` must be an RFC 3339 timestamp"))
|
|
return issueops.SweepRequest{}, false
|
|
}
|
|
request.ClosedBefore = value
|
|
}
|
|
|
|
if raw, ok := members[sweepPatternMember]; ok {
|
|
var value *string
|
|
if err := json.Unmarshal(raw, &value); err != nil || value == nil {
|
|
s.fail(w, r, InvalidArgument(sweepPatternMember, ReasonInvalidValue,
|
|
"`"+sweepPatternMember+"` must be a string"))
|
|
return issueops.SweepRequest{}, false
|
|
}
|
|
// A malformed glob is NOT refused here. The role refuses it, and
|
|
// routing it through the role is what keeps one definition of what a
|
|
// pattern is: filepath.Match's, matched in Go on both front doors.
|
|
request.IDPattern = *value
|
|
}
|
|
|
|
for _, flag := range []struct {
|
|
member string
|
|
dest *bool
|
|
}{
|
|
{sweepProtectReferencedMember, &request.ProtectReferenced},
|
|
{sweepDryRunMember, &request.DryRun},
|
|
{sweepProtectLiveDependentsMember, &request.ProtectLiveDependents},
|
|
} {
|
|
raw, ok := members[flag.member]
|
|
if !ok {
|
|
continue
|
|
}
|
|
var value *bool
|
|
if err := json.Unmarshal(raw, &value); err != nil || value == nil {
|
|
s.fail(w, r, InvalidArgument(flag.member, ReasonInvalidValue,
|
|
"`"+flag.member+"` must be a boolean"))
|
|
return issueops.SweepRequest{}, false
|
|
}
|
|
*flag.dest = *value
|
|
}
|
|
|
|
if raw, ok := members[sweepLimitMember]; ok {
|
|
var value *int64
|
|
if err := json.Unmarshal(raw, &value); err != nil || value == nil {
|
|
s.fail(w, r, InvalidArgument(sweepLimitMember, ReasonInvalidValue,
|
|
"`"+sweepLimitMember+"` must be an integer"))
|
|
return issueops.SweepRequest{}, false
|
|
}
|
|
// A negative value is NOT refused here. The role refuses it
|
|
// (issueops.ErrValidation), and routing it through the role is what
|
|
// keeps one definition of what a valid limit is, the same way a
|
|
// malformed pattern is left to the role above.
|
|
request.Limit = int(*value)
|
|
}
|
|
|
|
return request, true
|
|
}
|
|
|
|
func sweepMemberList() string {
|
|
quoted := make([]string, len(sweepMembers))
|
|
for i, name := range sweepMembers {
|
|
quoted[i] = "`" + name + "`"
|
|
}
|
|
return strings.Join(quoted, ", ")
|
|
}
|
|
|
|
// failSweepErr answers a failed sweep.
|
|
//
|
|
// issueops.ErrValidation is mapped to a 400 HERE rather than in ClassifyError,
|
|
// because this operation's ROLE performs request validation the handler does
|
|
// not duplicate — the require-a-filter gate, the tier vocabulary and the glob
|
|
// are all refused below the wire. Delete, tree, edges, blocking and batch-create
|
|
// each draw the same line in their own handler, deliberately in the same shape.
|
|
// Widening ClassifyError instead would change what every other operation
|
|
// returns for an error it has never produced.
|
|
func (s *Server) failSweepErr(w http.ResponseWriter, r *http.Request, err error) {
|
|
if errors.Is(err, issueops.ErrValidation) {
|
|
// No `param`: the refusal is about the REQUEST rather than one member
|
|
// of it — an unfiltered durable sweep is two absent members at once —
|
|
// and the document's `param` is documented absent on exactly that
|
|
// case. The detail carries the role's own sentence, which names what
|
|
// to send instead.
|
|
s.fail(w, r, InvalidArgument("", ReasonInvalidValue, err.Error()))
|
|
return
|
|
}
|
|
s.failErr(w, r, err)
|
|
}
|
|
|
|
// sweepResponse projects the role's result onto the wire type. It is a field
|
|
// list rather than an alias because SweepResult is deliberately not
|
|
// x-go-type-pinned: there is no canonical Go struct whose JSON encoding is
|
|
// this body (see the schema's own description), so the projection is where the
|
|
// two shapes are held together and TestSweepResponseCarriesEveryRoleField is
|
|
// what keeps a new result field from being dropped here in silence.
|
|
func sweepResponse(result issueops.SweepResult) apigen.SweepResult {
|
|
body := apigen.SweepResult{
|
|
DryRun: result.DryRun,
|
|
Swept: result.Swept,
|
|
Dependencies: result.Dependencies,
|
|
Labels: result.Labels,
|
|
Events: result.Events,
|
|
Skipped: apigen.SweepSkips{
|
|
Pinned: result.Skipped.Pinned,
|
|
Referenced: result.Skipped.Referenced,
|
|
NotClosed: result.Skipped.NotClosed,
|
|
UnknownClosedAt: result.Skipped.UnknownClosedAt,
|
|
ClosedAtOrAfterCutoff: result.Skipped.ClosedAtOrAfterCutoff,
|
|
Unreadable: result.Skipped.Unreadable,
|
|
LiveDependent: &result.Skipped.LiveDependent,
|
|
},
|
|
}
|
|
remaining := int64(result.Remaining)
|
|
body.Remaining = &remaining
|
|
if len(result.ReferencedIDs) > 0 {
|
|
ids := append([]string(nil), result.ReferencedIDs...)
|
|
body.ReferencedIds = &ids
|
|
}
|
|
return body
|
|
}
|