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>
104 lines
4 KiB
Go
104 lines
4 KiB
Go
package dolt
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/steveyegge/beads/internal/types"
|
|
publicops "github.com/steveyegge/beads/issueops"
|
|
)
|
|
|
|
// This file is the persistence tier of the Commenter role: what the shared
|
|
// contract in package conformance deliberately leaves out because it is a
|
|
// property of the Dolt working set rather than a promised result of the
|
|
// operation. It is pinned at this backend only.
|
|
//
|
|
// - The commit-message spelling is single-sourced in
|
|
// storageissueops.AddCommentCommitMessage, so one backend pinning it is
|
|
// enough and re-pinning it three times would be duplication.
|
|
// - The staging assertions need a planted dirty working set and a dolt_status
|
|
// read. The working set is not a caller-visible thing on the unit-of-work
|
|
// route, which is where the same line was already drawn for Lifecycle in
|
|
// conformance/issue_operations_staging.go.
|
|
//
|
|
// Everything else the old commenter_test.go asserted — verbatim text, the
|
|
// result mirroring the row, wisp-thread routing, ErrNotFound — is now
|
|
// conformance.RunCommenter*, wired at all three backends.
|
|
|
|
// TestDoltStoreCommenterNamesTheIssueInHistoryAndCommitsTheTable pins the two
|
|
// persistence halves of a durable comment: the history entry is named
|
|
// "bd: comment <id>", and the comments table is committed rather than left
|
|
// dirty in the working set.
|
|
func TestDoltStoreCommenterNamesTheIssueInHistoryAndCommitsTheTable(t *testing.T) {
|
|
store, cleanup := setupTestStore(t)
|
|
defer cleanup()
|
|
ctx, cancel := testContext(t)
|
|
defer cancel()
|
|
seedIssues(ctx, t, store, "test-comment-role")
|
|
|
|
commenter, err := store.Commenter()
|
|
if err != nil {
|
|
t.Fatalf("Commenter(): %v", err)
|
|
}
|
|
if _, err := commenter.AddComment(ctx, publicops.AddCommentRequest{
|
|
Author: "author",
|
|
IssueID: "test-comment-role",
|
|
Text: "a durable comment",
|
|
}); err != nil {
|
|
t.Fatalf("AddComment: %v", err)
|
|
}
|
|
|
|
if !doltHasCommitMessage(ctx, t, store, "bd: comment test-comment-role") {
|
|
t.Error("the comment did not name its issue in history")
|
|
}
|
|
requireCleanTables(ctx, t, store, "comments")
|
|
}
|
|
|
|
// TestDoltStoreCommenterOnAWispSweepsNoPendingRow pins the staging half of the
|
|
// ephemeral case, which no data read can see.
|
|
//
|
|
// It needs a pending row in the durable comments table to be visible at all.
|
|
// The wisp tables are dolt-ignored, so a commit that named one is swallowed
|
|
// and a commit count alone cannot tell a correctly-staged wisp write from one
|
|
// that reached for `comments` — which is exactly what a wrongly resolved plane
|
|
// would do while the thread read still passed. A comment on a wisp must
|
|
// therefore leave `comments` dirty: it neither wrote to it nor swept someone
|
|
// else's pending row into a commit.
|
|
func TestDoltStoreCommenterOnAWispSweepsNoPendingRow(t *testing.T) {
|
|
store, cleanup := setupTestStore(t)
|
|
defer cleanup()
|
|
ctx, cancel := testContext(t)
|
|
defer cancel()
|
|
seedIssues(ctx, t, store, "test-comment-neighbor")
|
|
wisp := &types.Issue{ID: "test-comment-wisp", Title: "wisp", Status: types.StatusOpen, Priority: 2, IssueType: types.TypeTask, Ephemeral: true}
|
|
if err := store.CreateIssue(ctx, wisp, "seed"); err != nil {
|
|
t.Fatalf("create wisp: %v", err)
|
|
}
|
|
if _, err := store.db.ExecContext(ctx, `
|
|
INSERT INTO comments (id, issue_id, author, text, created_at)
|
|
VALUES (?, ?, ?, ?, NOW())`,
|
|
"00000000-0000-4000-8000-00000000c0de", "test-comment-neighbor", "someone-else", "pending",
|
|
); err != nil {
|
|
t.Fatalf("stage a pending comment row: %v", err)
|
|
}
|
|
|
|
commenter, err := store.Commenter()
|
|
if err != nil {
|
|
t.Fatalf("Commenter(): %v", err)
|
|
}
|
|
if _, err := commenter.AddComment(ctx, publicops.AddCommentRequest{
|
|
Author: "author",
|
|
IssueID: wisp.ID,
|
|
Text: "on the ephemeral plane",
|
|
}); err != nil {
|
|
t.Fatalf("AddComment on a wisp: %v", err)
|
|
}
|
|
|
|
var dirty int
|
|
if err := store.db.QueryRowContext(ctx,
|
|
"SELECT COUNT(*) FROM dolt_status WHERE table_name = 'comments'").Scan(&dirty); err != nil {
|
|
t.Fatalf("query dolt_status: %v", err)
|
|
}
|
|
if dirty == 0 {
|
|
t.Fatal("comments is clean: the wisp comment staged the durable table and carried a pending row with it")
|
|
}
|
|
}
|