Ten agents over 216 files, one directory-balanced group each, working to a rubric that named what to cut (duplication narration, restatement of the next line, the governing rule echoed in every command file, throat-clearing) and what to keep (traps, invariants, security, tracker ids, behaviour changes, and the "why a naive simplification destroys this assertion" rationale). Net 1,523 lines. Density against this repo's own per-directory norm on main: cmd/bd 33.6% -> 27.3% (main 10.7%) internal/storage 26.1% -> 23.1% (main 14.1%) backend/conformance 34.0% -> 29.6% (main 22.8%) internal/httpapi 30.9% -> 27.8% (main 30.6%, now below) overall 34.7% -> 31.6% Every agent landed at 18-25% rather than the 30% asked for, and every one gave the same reason independently: what remained was on the keep list. Ten separate judgements agreeing is the most useful result here — the prose is dense, but it is mostly load-bearing, and the shortfall is the honest answer rather than a failure to try. TWO REVERTS, both to protect something worth more than the lines. issueops/ is back to its pre-trim state, giving up 610 lines. The conformance contracts cite the leaf docs BY LINE — "pins treewalker.go:52-66" — 155 times. Trimming the cited files silently repointed those at whatever text moved into those numbers, across agent boundaries so no agent could see it. A semantic remapper recovered 141 of them, but 23 needed judgement and several landed on struct fields. The leaf docs are the spec the contracts are written against; they are the one place in this change where dense prose IS the deliverable, and keeping them stable is worth more than the 610 lines. tree_walker_contract.go and version_reconciler_contract.go went back for the same reason: an agent had deleted a paragraph containing a citation, so positional restoration could not align them. After the reverts, exactly 5 citations point into a still-trimmed file and 2 of those are weak — both in cmd/bd/config_guard_test.go, which this series never touched and whose citations were already wrong on main (init.go:361 pointed at a closing brace; the guard it names is at init.go:1499). VERIFICATION. A guard strips every comment and all whitespace from each of the 193 modified files at HEAD and in the worktree and requires the two to be byte-identical, so a code change cannot hide in a comment diff. It handles `//` inside string and raw-string literals, and was tested against a deliberate code change before being trusted. gofmt clean, go build, go vet, golangci-lint 0 issues, and the two AST-based tests that PARSE trimmed files — the timed provider binding pin over claim.go and the serve database-source gate over serve.go — both pass. One real defect found while trimming: checkDatabaseSource's doc block ran into `// sourceRoles is ...` with no blank line, so godoc attached thirty-one lines of the wrong prose to func sourceRoles and left checkDatabaseSource undocumented. Fixed by separating them.
129 lines
5.1 KiB
Go
129 lines
5.1 KiB
Go
//go:build cgo
|
|
|
|
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/steveyegge/beads/internal/types"
|
|
)
|
|
|
|
// countAttemptRefusals counts the refusals printed for one issue, not the run's
|
|
// failure summary. proxiedUpdateFailure prints the policy error flush left;
|
|
// reportUpdateFailures reprints the same text indented behind the issue ID, so
|
|
// "unindented" separates the two.
|
|
func countAttemptRefusals(out string) int {
|
|
n := 0
|
|
for _, line := range strings.Split(out, "\n") {
|
|
if strings.Contains(line, "cannot close ") && !strings.HasPrefix(line, " ") {
|
|
n++
|
|
}
|
|
}
|
|
return n
|
|
}
|
|
|
|
// TestProxiedServerUpdateClosePolicy pins close policy on the PROXIED update
|
|
// path — `bd update --status closed` against a dolt sql-server.
|
|
//
|
|
// It exists because the two halves of this behavior were written against each
|
|
// other's stale shape. #5206 added the policy and its two proxied refusal arms
|
|
// while this path still ran a bespoke read-merge-write of its own, and the only
|
|
// proxied coverage it shipped was a unit test on the spec that path built —
|
|
// which passes whether or not the refusal ever reaches a user. These assertions
|
|
// are the only proxied close-policy coverage that watches a user-visible
|
|
// boundary rather than an internal request.
|
|
//
|
|
// So the assertions here are end-to-end and deliberately narrow:
|
|
//
|
|
// - the sentinels still match through the contract's wrapping, so the
|
|
// boundary prints the close-path copy rather than the generic
|
|
// "Error updating" arm;
|
|
// - the refusal is TERMINAL, printed exactly once. A policy error is not a
|
|
// serialization failure, so the contract's retry loop wraps it Permanent:
|
|
// no commit, no retry. If a later change let it propagate as a retryable
|
|
// error instead, the backoff would redo the attempt for its whole budget
|
|
// and this count would climb;
|
|
// - it exits 1, never ExitGuardMismatch/13, which is reserved for a stale
|
|
// --if-assignee/--if-status precondition;
|
|
// - nothing is written; and --force overrides, on the same path.
|
|
func TestProxiedServerUpdateClosePolicy(t *testing.T) {
|
|
requireSharedProxiedServer(t)
|
|
t.Parallel()
|
|
bd := buildEmbeddedBD(t)
|
|
|
|
t.Run("live_blocker_refuses_once", func(t *testing.T) {
|
|
t.Parallel()
|
|
p := newSharedProxiedProject(t, bd, "upcb")
|
|
blocker := bdProxiedCreate(t, bd, p.dir, "Blocker")
|
|
blocked := bdProxiedCreate(t, bd, p.dir, "Blocked", "--deps", "depends-on:"+blocker.ID)
|
|
|
|
out, code := bdProxiedUpdateFailCode(t, bd, p.dir, blocked.ID, "--status", "closed")
|
|
if code != 1 {
|
|
t.Errorf("exit code = %d, want 1 (a policy refusal is not a guard mismatch); output:\n%s", code, out)
|
|
}
|
|
if !strings.Contains(out, "cannot close blocked issue") {
|
|
t.Errorf("refusal did not use the close-path copy; output:\n%s", out)
|
|
}
|
|
if !strings.Contains(out, "(use --force to override)") {
|
|
t.Errorf("refusal did not name the override; output:\n%s", out)
|
|
}
|
|
if n := countAttemptRefusals(out); n != 1 {
|
|
t.Errorf("attempt printed the refusal %d times, want exactly 1 — a policy refusal must not be retried; output:\n%s", n, out)
|
|
}
|
|
db := openProxiedDB(t, p)
|
|
if got := readStatus(t, db, blocked.ID); got == types.StatusClosed {
|
|
t.Error("a refused status update must write nothing")
|
|
}
|
|
})
|
|
|
|
t.Run("live_blocker_forced_crosses", func(t *testing.T) {
|
|
t.Parallel()
|
|
p := newSharedProxiedProject(t, bd, "upcf")
|
|
blocker := bdProxiedCreate(t, bd, p.dir, "Blocker force")
|
|
blocked := bdProxiedCreate(t, bd, p.dir, "Blocked force", "--deps", "depends-on:"+blocker.ID)
|
|
|
|
bdProxiedUpdateOne(t, bd, p.dir, blocked.ID, "--status", "closed", "--force")
|
|
db := openProxiedDB(t, p)
|
|
if got := readStatus(t, db, blocked.ID); got != types.StatusClosed {
|
|
t.Errorf("status = %q, want closed: --force must override close policy here too", got)
|
|
}
|
|
})
|
|
|
|
t.Run("open_children_refuse_once", func(t *testing.T) {
|
|
t.Parallel()
|
|
p := newSharedProxiedProject(t, bd, "upcc")
|
|
parent := bdProxiedCreate(t, bd, p.dir, "Parent")
|
|
child := bdProxiedCreate(t, bd, p.dir, "Child")
|
|
bdProxiedDep(t, bd, p.dir, "add", child.ID, parent.ID, "--type", "parent-child")
|
|
|
|
out, code := bdProxiedUpdateFailCode(t, bd, p.dir, parent.ID, "--status", "closed")
|
|
if code != 1 {
|
|
t.Errorf("exit code = %d, want 1; output:\n%s", code, out)
|
|
}
|
|
if !strings.Contains(out, "open child issue(s)") {
|
|
t.Errorf("refusal did not use the close-path copy; output:\n%s", out)
|
|
}
|
|
if n := countAttemptRefusals(out); n != 1 {
|
|
t.Errorf("attempt printed the refusal %d times, want exactly 1; output:\n%s", n, out)
|
|
}
|
|
db := openProxiedDB(t, p)
|
|
if got := readStatus(t, db, parent.ID); got == types.StatusClosed {
|
|
t.Error("a refused status update must write nothing")
|
|
}
|
|
})
|
|
|
|
t.Run("open_children_forced_crosses", func(t *testing.T) {
|
|
t.Parallel()
|
|
p := newSharedProxiedProject(t, bd, "upcg")
|
|
parent := bdProxiedCreate(t, bd, p.dir, "Parent force")
|
|
child := bdProxiedCreate(t, bd, p.dir, "Child force")
|
|
bdProxiedDep(t, bd, p.dir, "add", child.ID, parent.ID, "--type", "parent-child")
|
|
|
|
bdProxiedUpdateOne(t, bd, p.dir, parent.ID, "--status", "closed", "--force")
|
|
db := openProxiedDB(t, p)
|
|
if got := readStatus(t, db, parent.ID); got != types.StatusClosed {
|
|
t.Errorf("status = %q, want closed", got)
|
|
}
|
|
})
|
|
}
|