Beads had two implementations of most issue verbs: one for the direct route
(the CLI talking to a store it opened itself) and one for the proxied-server
route (the CLI talking through a unit of work over a running Dolt server).
They drifted — different commit messages, different transaction boundaries,
different refusals, occasionally different answers.
Seven role interfaces now live in the leaf package issueops: Lifecycle,
Reader, ReadyClaimer, BatchCloser, DependencyEditor, Commenter and Relations.
Each is reached only through a store accessor, never a constructor, because
the accessor is where the hook and telemetry decorators add their layers.
Three implementations back every role — dolt, embeddeddolt, and the
unit-of-work provider the proxied route uses. Both routes call the same role
for close, dep add/remove/list, comment, ready --claim and update.
A depguard rule (httpapi-domain-boundary) denies internal/storage/domain from
internal/httpapi, so a handler cannot reach uw.IssueUseCase() past the roles
and open a second front door one lint-clean commit at a time.
Behaviour users will notice, all in the CHANGELOG:
- bd close a b c is one Dolt commit, not three, and --claim-next moved
inside that transaction so it fires only when something landed
- the open-children guard moved into the transaction and its hand-rolled
cmd/bd copy is gone, removing a read-then-write window that made
bd close <child> <parent> depend on argument order
- bd dep add --file honours deferred version commit
- embedded bd comment writes the role's message and author
- dep verb commit messages are the role's on the direct route
Wisp-sourced dependency edges are restored. Moving bd dep add onto the role
had pinned an edge's SOURCE to the issues plane, and the two routes did not
even fail alike: direct refused with "issue <id> not found", proxied threw an
fk_dep_issue violation. The comment justifying the pin claimed the issues
plane was "the only one its unit-of-work sibling can reach" — that was false;
domain.DependencyUseCase declared a full set of wisp twins with no production
caller. All three implementations now route per edge by the edge's own
source. A mixed request stays one transaction: parent-child-first ordering
and the whole-graph cycle gate span both planes, and a refusal rolls back
both. Behind the role, three bulk add verbs collapsed into one source-routed
AddDependencies, so no plane-pinned variant is left to reach for by mistake.
Six Provenance fields with no production caller were deleted rather than
wired — CloseRequest, CloseBatchRequest, ClaimNextRequest, AddCommentRequest,
AddDependenciesRequest, RemoveDependencyRequest. Each role already composes an
id-bearing message, so a caller could only restate the default and make it
unreachable from production. Two are not caller-settable even in principle:
CloseBatchCommitMessage names what LANDED and ClaimNextCommitMessage names the
id the claim WON. UpdateRequest and ReopenRequest keep theirs; commit messages
users see are unchanged.
Verified: build, vet and gofmt clean; golangci-lint 0 issues; protocol corpus
byte-identical under BEADS_PROTOCOL_REQUIRE_DOLT=1; all twelve
DependencyEditor conformance wirings green (four contract functions against
each implementation); TestEmbeddedDepAddWispSource runs bd dep add <wisp-id>
at the front door and was demonstrated RED against the pinned routing first.
Three internal/storage/dolt failures reproduce on pristine origin/main.
Known gaps are enumerated in the PR description rather than left to be found:
comment listing is on no role, bd dep tree and bd dep cycles have no role,
bd create and bd reopen are on Lifecycle only on the direct route, per-edge
line attribution is lost in bd dep add --file, multi-store bd close
--claim-next rides only the first store's batch, and the is_blocked staging gap
(bd-2y9ke, predates this change). Seven of the eight role interfaces now have a
shared conformance contract in backend/conformance, run at all three
implementations; main's Claimer, added in parallel by #5334, is the eighth and
has none yet.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
144 lines
6.3 KiB
Go
144 lines
6.3 KiB
Go
// Package storereader holds the store-backed implementation of
|
|
// issueops.Reader: one shared body that every store-shaped backend's
|
|
// IssueReader accessor hands back.
|
|
//
|
|
// It is a package of its own rather than a file in internal/workapi for one
|
|
// reason. internal/workapi is the builders' home and 22 cmd/bd files import
|
|
// it, so a constructor living there was a one-line drop-in replacement for
|
|
// store.IssueReader() from any front door — and one that silently skips the
|
|
// telemetry decorator's reader-level spans, because a decorator adds its layer
|
|
// in its own accessor. Down here the only importers are the two Dolt store
|
|
// packages, and the cmd-bd-reader-constructor depguard rule in .golangci.yml
|
|
// makes a front door importing it a lint failure rather than a review comment.
|
|
//
|
|
// The accessor is the door. This is the thing behind it.
|
|
package storereader
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/steveyegge/beads/internal/storage"
|
|
"github.com/steveyegge/beads/internal/types"
|
|
"github.com/steveyegge/beads/internal/workapi"
|
|
"github.com/steveyegge/beads/issueops"
|
|
)
|
|
|
|
// New returns the issue-query surface backed by a store handle. *DoltStore and
|
|
// *EmbeddedDoltStore answer identically because the difference between them is
|
|
// below storage.DoltStorage, not above it.
|
|
//
|
|
// The reader supplies its own ConfigSource from the store it already holds, so
|
|
// a caller ON THE ROLE cannot half-perform the "load config, build filter,
|
|
// execute" ritual: it has no way to reach the pieces.
|
|
//
|
|
// THE BOUNDARY, stated once here because this is where the constructor lives:
|
|
// today the store-backed role answers `bd show --json` on the direct route,
|
|
// and the HTTP surface and the proxied `bd show --json` reach the uow-backed
|
|
// one. `bd ready` and `bd list` still call the workapi builders directly —
|
|
// they consume the FILTER for the max-rows cap, --claim, --watch, the
|
|
// hierarchical --parent tree and the text renderings — so Ready and List below
|
|
// are reached only by tests until a front door moves. They are covered by
|
|
// reader_test.go for exactly that reason, and their page epilogue is
|
|
// workapi.FinishPage, which `bd list` DOES run in every mode but the
|
|
// hierarchical --parent tree, so the untravelled path here is the query and
|
|
// not the tail. See issueops.Reader's doc comment for why routing only those
|
|
// commands' JSON paths through the role would be worse.
|
|
func New(store storage.DoltStorage) (issueops.Reader, error) {
|
|
if store == nil {
|
|
return nil, &issueops.ErrUnsupported{Op: "storereader.New", Backend: "nil"}
|
|
}
|
|
return &storeReader{store: store}, nil
|
|
}
|
|
|
|
type storeReader struct{ store storage.DoltStorage }
|
|
|
|
var _ issueops.Reader = (*storeReader)(nil)
|
|
|
|
// offsetBackend names the backend an Offset refusal comes from. One name for
|
|
// both engines on purpose: the server-backed and embedded stores hand back
|
|
// THIS body, and it is the body — not the engine underneath it — that cannot
|
|
// page by offset.
|
|
const offsetBackend = "dolt-store"
|
|
|
|
// refuseOffset is the shared refusal. The store seam renders LIMIT without
|
|
// OFFSET (internal/storage/issueops/ready_work.go, search_counts.go), so a
|
|
// request carrying one used to come back as the unpaged first page with no
|
|
// error on it — a caller paging with Offset saw the same rows forever. The
|
|
// field is not dead: `bd ready/list/query --offset` are real flags, and their
|
|
// direct routes already reject a non-zero offset before reaching any of this
|
|
// (cmd/bd/ready.go, list.go, query.go). This is the same refusal one layer
|
|
// down, for the callers that are not the CLI.
|
|
func refuseOffset(op string) error {
|
|
return &issueops.ErrUnsupported{Op: op, Backend: offsetBackend}
|
|
}
|
|
|
|
func (r *storeReader) Ready(ctx context.Context, req issueops.ReadyRequest) (issueops.IssuePage, error) {
|
|
if req.Offset != 0 {
|
|
return issueops.IssuePage{}, refuseOffset("Reader.Ready(Offset)")
|
|
}
|
|
filter, err := workapi.BuildReadyFilter(req)
|
|
if err != nil {
|
|
return issueops.IssuePage{}, err
|
|
}
|
|
limit := filter.Limit
|
|
if limit > 0 {
|
|
// The store seam has no HasMore of its own, so ask for one row past
|
|
// the page and let its presence be the answer.
|
|
filter.Limit = limit + 1
|
|
}
|
|
items, err := r.store.GetReadyWorkWithCounts(ctx, filter)
|
|
if err != nil {
|
|
return issueops.IssuePage{}, err
|
|
}
|
|
// Ready has no display order to apply — the ordering is the sort POLICY
|
|
// the query ran under — so the epilogue's sort is a no-op here and only
|
|
// its trim and its verdict do any work. It is still the shared one: a
|
|
// second trim written out longhand is how the two arms of List came apart.
|
|
items, hasMore := workapi.FinishPage(items, "", false, limit, false)
|
|
return issueops.IssuePage{Items: items, HasMore: hasMore}, nil
|
|
}
|
|
|
|
func (r *storeReader) List(ctx context.Context, req issueops.ListRequest) (issueops.IssuePage, error) {
|
|
if req.Offset != 0 {
|
|
return issueops.IssuePage{}, refuseOffset("Reader.List(Offset)")
|
|
}
|
|
cfg, err := workapi.LoadStoreListConfig(ctx, r.store)
|
|
if err != nil {
|
|
return issueops.IssuePage{}, err
|
|
}
|
|
filter, err := workapi.BuildListFilter(req, cfg)
|
|
if err != nil {
|
|
return issueops.IssuePage{}, err
|
|
}
|
|
|
|
var items []*types.IssueWithCounts
|
|
if req.ReadyFlag {
|
|
items, err = r.store.GetReadyWorkWithCounts(ctx, workapi.ReadyFilterFromIssueFilter(workapi.WithFetchOneExtra(filter)))
|
|
} else {
|
|
items, err = r.store.SearchIssuesWithCounts(ctx, "", workapi.WithFetchOneExtra(filter))
|
|
}
|
|
if err != nil {
|
|
return issueops.IssuePage{}, err
|
|
}
|
|
|
|
// The sort, the trim and the HasMore verdict are workapi.FinishPage's, not
|
|
// this implementation's: `bd list` on both its routes and the uow-backed
|
|
// sibling of this method call the same function, so the only thing left
|
|
// that can differ between a CLI listing and an HTTP one is presentation.
|
|
// This seam reports no HasMore of its own, so the over-fetched row above
|
|
// is what speaks.
|
|
items, hasMore := workapi.FinishPage(items, req.SortBy, req.Reverse, workapi.PageLimit(req), false)
|
|
return issueops.IssuePage{Items: items, HasMore: hasMore}, nil
|
|
}
|
|
|
|
func (r *storeReader) Get(ctx context.Context, req issueops.GetRequest) (*issueops.IssueDetails, error) {
|
|
src := workapi.NewStoreDetailSource(r.store)
|
|
issue, isWisp, err := workapi.GetIssueOrWisp(ctx, src, req.ID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return workapi.BuildIssueDetails(ctx, src, issue, isWisp, workapi.DetailOptions{
|
|
IncludeDependents: req.IncludeDependents,
|
|
IncludeComments: req.IncludeComments,
|
|
})
|
|
}
|