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.
138 lines
4.9 KiB
Go
138 lines
4.9 KiB
Go
package workapi
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/steveyegge/beads/issueops"
|
|
)
|
|
|
|
// TestPlanVersionReconcile pins the whole decision table of
|
|
// issueops.VersionReconciler in one place and with no database, so the
|
|
// conformance contract is free to assert only what a real backend can show.
|
|
//
|
|
// The two marker states a workspace reaches ONLY through something outside the
|
|
// role — a recorded version below the high-water mark — are here rather than
|
|
// there: reproducing them on three backends costs a seeded write per case to
|
|
// test arithmetic that never touches storage.
|
|
func TestPlanVersionReconcile(t *testing.T) {
|
|
for _, test := range []struct {
|
|
name string
|
|
cliVersion string
|
|
recorded string
|
|
highWaterMark string
|
|
want issueops.VersionReconcileResult
|
|
wantVersion bool
|
|
wantMark bool
|
|
}{
|
|
{
|
|
name: "a workspace with no markers records both",
|
|
cliVersion: "1.2.0",
|
|
want: issueops.VersionReconcileResult{Previous: "", Current: "1.2.0", Migrated: true},
|
|
wantVersion: true,
|
|
wantMark: true,
|
|
},
|
|
{
|
|
name: "the same version again is a no-op",
|
|
cliVersion: "1.2.0",
|
|
recorded: "1.2.0",
|
|
highWaterMark: "1.2.0",
|
|
want: issueops.VersionReconcileResult{Previous: "1.2.0", Current: "1.2.0"},
|
|
},
|
|
{
|
|
name: "an upgrade advances both markers",
|
|
cliVersion: "1.3.0",
|
|
recorded: "1.2.0",
|
|
highWaterMark: "1.2.0",
|
|
want: issueops.VersionReconcileResult{Previous: "1.2.0", Current: "1.3.0", Migrated: true},
|
|
wantVersion: true,
|
|
wantMark: true,
|
|
},
|
|
{
|
|
name: "a binary older than the marker is refused",
|
|
cliVersion: "1.2.0",
|
|
recorded: "1.3.0",
|
|
highWaterMark: "1.3.0",
|
|
want: issueops.VersionReconcileResult{Previous: "1.3.0", Current: "1.3.0", Downgrade: true},
|
|
},
|
|
{
|
|
// The state only something outside this role produces, and the
|
|
// whole reason the second marker exists: the marker says 1.2.0 and
|
|
// would accept 1.3.0, the mark remembers that 1.4.0 has already
|
|
// prepared this workspace.
|
|
name: "a binary older than the mark is refused even when the marker would accept it",
|
|
cliVersion: "1.3.0",
|
|
recorded: "1.2.0",
|
|
highWaterMark: "1.4.0",
|
|
want: issueops.VersionReconcileResult{Previous: "1.2.0", Current: "1.2.0", Downgrade: true},
|
|
},
|
|
{
|
|
name: "catching up to the mark moves the marker and leaves the mark",
|
|
cliVersion: "1.4.0",
|
|
recorded: "1.2.0",
|
|
highWaterMark: "1.4.0",
|
|
want: issueops.VersionReconcileResult{Previous: "1.2.0", Current: "1.4.0", Migrated: true},
|
|
wantVersion: true,
|
|
wantMark: false,
|
|
},
|
|
{
|
|
name: "a pre-release records over the release it equals",
|
|
cliVersion: "1.4.0-rc1",
|
|
recorded: "1.4.0",
|
|
highWaterMark: "1.4.0",
|
|
want: issueops.VersionReconcileResult{Previous: "1.4.0", Current: "1.4.0-rc1", Migrated: true},
|
|
wantVersion: true,
|
|
wantMark: false,
|
|
},
|
|
{
|
|
name: "a missing component reads as zero",
|
|
cliVersion: "1.4",
|
|
recorded: "1.4.0",
|
|
highWaterMark: "1.4.0",
|
|
want: issueops.VersionReconcileResult{Previous: "1.4.0", Current: "1.4", Migrated: true},
|
|
wantVersion: true,
|
|
wantMark: false,
|
|
},
|
|
{
|
|
name: "a marker this role cannot parse reads as zero and is overwritten",
|
|
cliVersion: "1.4.0",
|
|
recorded: "unknown",
|
|
highWaterMark: "unknown",
|
|
want: issueops.VersionReconcileResult{Previous: "unknown", Current: "1.4.0", Migrated: true},
|
|
wantVersion: true,
|
|
wantMark: true,
|
|
},
|
|
} {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
plan, err := PlanVersionReconcile(test.cliVersion, test.recorded, test.highWaterMark)
|
|
if err != nil {
|
|
t.Fatalf("PlanVersionReconcile(%q, %q, %q) error = %v",
|
|
test.cliVersion, test.recorded, test.highWaterMark, err)
|
|
}
|
|
if plan.Result != test.want {
|
|
t.Errorf("result = %+v, want %+v", plan.Result, test.want)
|
|
}
|
|
if plan.RecordVersion != test.wantVersion {
|
|
t.Errorf("RecordVersion = %v, want %v", plan.RecordVersion, test.wantVersion)
|
|
}
|
|
if plan.RecordHighWaterMark != test.wantMark {
|
|
t.Errorf("RecordHighWaterMark = %v, want %v", plan.RecordHighWaterMark, test.wantMark)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestPlanVersionReconcileRefusesAnEmptyVersion pins the one validation
|
|
// failure, and pins that it plans no write: recording "" over a real marker
|
|
// would take the downgrade guard down with it.
|
|
func TestPlanVersionReconcileRefusesAnEmptyVersion(t *testing.T) {
|
|
for _, cliVersion := range []string{"", " "} {
|
|
plan, err := PlanVersionReconcile(cliVersion, "1.2.0", "1.2.0")
|
|
if !errors.Is(err, issueops.ErrValidation) {
|
|
t.Fatalf("PlanVersionReconcile(%q, ...) error = %v, want ErrValidation", cliVersion, err)
|
|
}
|
|
if plan.RecordVersion || plan.RecordHighWaterMark {
|
|
t.Fatalf("PlanVersionReconcile(%q, ...) plans a write: %+v", cliVersion, plan)
|
|
}
|
|
}
|
|
}
|