`bd update` was believed to be converged. It was not. Only the direct route
and the proxied `--claim` were on issueops.Lifecycle; the proxied PLAIN update
ran a read-merge-write of its own in cmd/bd — resolve the id across both
planes, apply the assignee fence, build a domain.UpdateSpec by hand, call
ApplyUpdate, drive uow.RunTxResultWithin, commit, and attribute the resulting
error to a stage by watching a decorated provider. Every one of those had a
second implementation. This deletes it: 339 lines out of
update_proxied_server.go for 113 in, and the plain path now makes the same
Lifecycle.Update call the claim already made.
WHAT STAYS IN cmd/bd, because none of it is an update: the template guard, the
advisory reassign pre-read, the per-id failure taxonomy the multi-id batch
needs, the notes-overwrite warning and the completion hooks. The HTTP surface
has none of them, which is the test for whether something belongs to the
command or to the contract.
WHAT THE MOVE CHANGES, all of it converging proxied onto the direct route:
- PERSISTENCE IS NOW AN AGGREGATE MOVE. This is the one nobody predicted.
`--ephemeral` / `--no-history` went through the hand-built spec as
fields["wisp"]=true — a column UPDATE on whichever table the row already
sat in. So a proxied `bd update --ephemeral` left the row in `issues`
carrying ephemeral=1: still durable, still versioned, still replicated,
invisible to every wisp-plane read. The direct route has always sent
IssuePatch.Persistence, which moves the aggregate, retargets inbound
edges and drops the lease in one transaction, exactly as the leaf promises
("Ephemeral and NoHistory select wisp retention modes, never durable
unversioned storage. Every aggregate move is atomic."). Both routes now do
that. Two assertions in TestProxiedServerUpdate2 read `issues` directly to
pin the old column flip and now pin the move. Recorded for the owner's
batch as Q13; NO MIGRATION repairs rows the old path already produced.
- STAGE ATTRIBUTION IS GONE. "opening unit of work" and "committing" were
told apart by watching a provider this path no longer owns; both now read
as the generic update failure. The claim path paid the same price when it
moved. The id still fails, loudly and non-zero.
- A COMMIT THAT FAILS WITH A CONTEXT ERROR now aborts the batch rather than
recording one per-id verdict, because it is no longer distinguishable from
a cancellation between retries. Again the claim path's existing choice.
- --json CARRIES LABELS on a plain update, which the direct route and the
protocol corpus already publish. A claim still strips them, so
`bd update --claim --json` stays byte-identical to the v0 claim response.
WHAT IT DOES NOT CHANGE: the commit message (`bd: update <id>`, carried as
Provenance), the wisp-id resolve, the exit codes including ExitGuardMismatch,
and the conflict-retry semantics — the whole-attempt retry and the
nothing-to-commit tolerance the bespoke loop reproduced are RunTxResultWithin's
own, reached now through the contract instead of alongside it.
THE CONTRACT GAINS ONE CASE, at all three backends with no parks:
RunIssueOperationsUpdateConditionalGuardsGateOrdinaryEdits. ExpectedAssignee
and ExpectedStatus were pinned only beside a fenced transfer, where the case
is about the ORDER two guards resolve in. Gating an ORDINARY field edit — which
is how `--if-status` / `--if-assignee` actually reach the contract, and what
the proxied route newly delegates — was untested. A refusal that leaked a
partial write would exit 13, telling scripts nothing was written, while having
written.
No HTTP handler is rewired: `bd serve` exposes no update operation. Its
POST /v0/beads/issues/{id}:claim already reaches Lifecycle.Update, and the
Tier-1 spec is not extended here.
Verified: build, vet, gofmt, golangci-lint (0 issues); the new contract case
green at dolt, embeddeddolt and uow; the proxied update integration suites and
the protocol corpus green under BEADS_TEST_PROXIED_SERVER=1 and
BEADS_TEST_EMBEDDED_DOLT=1.
146 lines
5.9 KiB
Go
146 lines
5.9 KiB
Go
//go:build cgo
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/steveyegge/beads/internal/storage"
|
|
"github.com/steveyegge/beads/internal/storage/issueops"
|
|
"github.com/steveyegge/beads/internal/types"
|
|
)
|
|
|
|
// Generic update close policy belongs to shared lifecycle conformance. These
|
|
// command tests retain only command-specific wiring for direct assignee
|
|
// transfer and the batch, proxied, embedded, and cross-backend update paths.
|
|
|
|
// TestUpdateClosePolicyDirectForceStillFencesAssigneeTransfer keeps the other
|
|
// half of `--force` intact. Conditioning it on an assignee edit must not turn
|
|
// it off when there IS one: a transfer away from a live foreign claim is still
|
|
// exactly what the flag authorizes.
|
|
func TestUpdateClosePolicyDirectForceStillFencesAssigneeTransfer(t *testing.T) {
|
|
env := newParityEnv(t)
|
|
env.seed("test-ucpa", "Held by another actor", func(i *types.Issue) {
|
|
i.Assignee = "someone-else"
|
|
i.Status = types.StatusInProgress
|
|
})
|
|
|
|
// Without --force the fence holds.
|
|
env.setFlags(updateCmd, map[string]string{"assignee": "thief"})
|
|
if res := env.run(updateCmd, "test-ucpa"); res.exitCode == 0 {
|
|
t.Fatalf("unforced transfer succeeded; the fence is gone\nstderr:\n%s", res.stderr)
|
|
}
|
|
if got := env.get("test-ucpa").Assignee; got != "someone-else" {
|
|
t.Fatalf("assignee = %q after a refused transfer, want someone-else", got)
|
|
}
|
|
|
|
// With it, the transfer is authorized.
|
|
env.setFlags(updateCmd, map[string]string{"assignee": "thief", "force": "true"})
|
|
if res := env.run(updateCmd, "test-ucpa"); res.exitCode != 0 {
|
|
t.Fatalf("forced transfer exit = %d, want 0\nstderr:\n%s", res.exitCode, res.stderr)
|
|
}
|
|
if got := env.get("test-ucpa").Assignee; got != "thief" {
|
|
t.Errorf("assignee = %q, want thief", got)
|
|
}
|
|
}
|
|
|
|
// TestUpdateClosePolicyBatchCrossesIntoDone drives `bd batch update`, whose
|
|
// transaction reaches the same embedded write funnel without going through the
|
|
// facade at all.
|
|
func TestUpdateClosePolicyBatchCrossesIntoDone(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
st := newTestStoreWithPrefix(t, filepath.Join(tmpDir, ".beads", "beads.db"), "tbc")
|
|
ctx := context.Background()
|
|
|
|
seedBatchTestIssues(t, ctx, st, "tbc-parent", "tbc-child", "tbc-blocker", "tbc-blocked")
|
|
for _, dep := range []*types.Dependency{
|
|
{IssueID: "tbc-child", DependsOnID: "tbc-parent", Type: types.DepParentChild},
|
|
{IssueID: "tbc-blocked", DependsOnID: "tbc-blocker", Type: types.DepBlocks},
|
|
} {
|
|
if err := st.AddDependency(ctx, dep, "test"); err != nil {
|
|
t.Fatalf("seed dependency %s -> %s: %v", dep.IssueID, dep.DependsOnID, err)
|
|
}
|
|
}
|
|
|
|
// An unforced crossing refuses — and because the batch is one transaction,
|
|
// it takes the WHOLE batch down, including the priority edit on a line that
|
|
// had nothing to do with the refusal. That is the documented contract.
|
|
script := "update tbc-blocker priority=0\nupdate tbc-parent status=closed\n"
|
|
err := runBatchScriptInTx(t, ctx, st, script)
|
|
if err == nil {
|
|
t.Fatal("batch update into done with an open child succeeded, want a refusal")
|
|
}
|
|
if !errors.Is(err, storage.ErrCloseOpenChildren) {
|
|
t.Errorf("batch error = %v, want ErrCloseOpenChildren", err)
|
|
}
|
|
rolledBack, getErr := st.GetIssue(ctx, "tbc-blocker")
|
|
if getErr != nil {
|
|
t.Fatalf("GetIssue tbc-blocker: %v", getErr)
|
|
}
|
|
if rolledBack.Priority != 2 {
|
|
t.Errorf("tbc-blocker priority = %d; an unforced refusal must roll back the whole batch", rolledBack.Priority)
|
|
}
|
|
|
|
if err := runBatchScriptInTx(t, ctx, st, "update tbc-blocked status=closed\n"); !errors.Is(err, storage.ErrCloseBlocked) {
|
|
t.Errorf("batch error = %v, want ErrCloseBlocked", err)
|
|
}
|
|
|
|
// force=true overrides both, in the same one transaction.
|
|
forced := "update tbc-parent status=closed force=true\nupdate tbc-blocked status=closed force=true\n"
|
|
if err := runBatchScriptInTx(t, ctx, st, forced); err != nil {
|
|
t.Fatalf("forced batch update into done: %v", err)
|
|
}
|
|
for _, id := range []string{"tbc-parent", "tbc-blocked"} {
|
|
got, err := st.GetIssue(ctx, id)
|
|
if err != nil {
|
|
t.Fatalf("GetIssue %s: %v", id, err)
|
|
}
|
|
if got.Status != types.StatusClosed {
|
|
t.Errorf("%s status = %q, want closed", id, got.Status)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestUpdateClosePolicyBatchGrammarForceToken pins the batch update grammar's
|
|
// spelling of the override, and — the part that matters — pins the allowlist
|
|
// that keeps the reserved update-map key from being client-reachable. A script
|
|
// asks for force by the grammar's own token; it can never name the transport
|
|
// key itself, which is what stops the key from becoming a policy bypass.
|
|
func TestUpdateClosePolicyBatchGrammarForceToken(t *testing.T) {
|
|
updates, err := parseUpdateKVs([]string{"status=closed", "force=true"})
|
|
if err != nil {
|
|
t.Fatalf("parseUpdateKVs(force=true): %v", err)
|
|
}
|
|
if got := updates[issueops.OpForceClosePolicy]; got != true {
|
|
t.Errorf("updates[%q] = %v, want true", issueops.OpForceClosePolicy, got)
|
|
}
|
|
if updates["status"] != "closed" {
|
|
t.Errorf("updates[status] = %v, want closed", updates["status"])
|
|
}
|
|
|
|
unforced, err := parseUpdateKVs([]string{"status=closed", "force=false"})
|
|
if err != nil {
|
|
t.Fatalf("parseUpdateKVs(force=false): %v", err)
|
|
}
|
|
if got := unforced[issueops.OpForceClosePolicy]; got != false {
|
|
t.Errorf("updates[%q] = %v, want false", issueops.OpForceClosePolicy, got)
|
|
}
|
|
|
|
if _, err := parseUpdateKVs([]string{"force=perhaps"}); err == nil {
|
|
t.Error("parseUpdateKVs accepted a non-boolean force value")
|
|
}
|
|
if _, err := parseUpdateKVs([]string{"_force_close_policy=true"}); err == nil {
|
|
t.Error("parseUpdateKVs accepted the reserved update-map key as a client token")
|
|
}
|
|
if _, err := parseUpdateKVs([]string{"description=foo"}); err == nil {
|
|
t.Error("parseUpdateKVs stopped rejecting keys outside its allowlist")
|
|
}
|
|
}
|
|
|
|
// The proxied path's own translation of `--force` is pinned in
|
|
// update_proxied_server_test.go (TestProxiedUpdateCarriesForce), against the
|
|
// UpdateRequest that path now hands issueops.Lifecycle — the spec it used to
|
|
// build by hand is gone.
|