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.
100 lines
3.9 KiB
Go
100 lines
3.9 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/steveyegge/beads/issueops"
|
|
)
|
|
|
|
// fakeIdentityReader stands in for issueops.InitVerifier, which is what
|
|
// adoptTeamServerIdentity now reads the bts-provisioned identity through.
|
|
//
|
|
// It answers with the PAIR and one error, because that is the shape of the role:
|
|
// the two markers are read in one snapshot, so there is no longer a state where
|
|
// the prefix read succeeded and the project-id read did not.
|
|
type fakeIdentityReader struct {
|
|
prefix string
|
|
projectID string
|
|
readErr error
|
|
}
|
|
|
|
func (f *fakeIdentityReader) VerifyIdentity(_ context.Context, _ issueops.VerifyIdentityRequest) (issueops.VerifyIdentityResult, error) {
|
|
if f.readErr != nil {
|
|
return issueops.VerifyIdentityResult{}, f.readErr
|
|
}
|
|
return issueops.VerifyIdentityResult{Prefix: f.prefix, ProjectID: f.projectID}, nil
|
|
}
|
|
|
|
func TestAdoptTeamServerIdentity(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
t.Run("adopts provisioned identity", func(t *testing.T) {
|
|
reader := &fakeIdentityReader{prefix: "gc", projectID: "bts-id"}
|
|
prefix, projectID, err := adoptTeamServerIdentity(ctx, reader, "beads_gc", "local_guess", false, "local-id")
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "gc", prefix)
|
|
assert.Equal(t, "bts-id", projectID)
|
|
})
|
|
|
|
t.Run("matching explicit prefix adopts", func(t *testing.T) {
|
|
reader := &fakeIdentityReader{prefix: "gc", projectID: "bts-id"}
|
|
prefix, _, err := adoptTeamServerIdentity(ctx, reader, "beads_gc", "gc", true, "local-id")
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "gc", prefix)
|
|
})
|
|
|
|
t.Run("conflicting explicit prefix is a hard error naming both", func(t *testing.T) {
|
|
reader := &fakeIdentityReader{prefix: "gc", projectID: "bts-id"}
|
|
_, _, err := adoptTeamServerIdentity(ctx, reader, "beads_gc", "other", true, "local-id")
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), `"other"`)
|
|
assert.Contains(t, err.Error(), `"gc"`)
|
|
})
|
|
|
|
t.Run("conflicting derived prefix adopts silently", func(t *testing.T) {
|
|
reader := &fakeIdentityReader{prefix: "gc", projectID: "bts-id"}
|
|
prefix, _, err := adoptTeamServerIdentity(ctx, reader, "beads_gc", "cwd_basename", false, "local-id")
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "gc", prefix)
|
|
})
|
|
|
|
t.Run("missing prefix names bts init", func(t *testing.T) {
|
|
reader := &fakeIdentityReader{prefix: "", projectID: "bts-id"}
|
|
_, _, err := adoptTeamServerIdentity(ctx, reader, "beads_gc", "gc", false, "local-id")
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), "bts init")
|
|
assert.Contains(t, err.Error(), "bts migrate")
|
|
})
|
|
|
|
t.Run("missing project id names bts init", func(t *testing.T) {
|
|
reader := &fakeIdentityReader{prefix: "gc", projectID: ""}
|
|
_, _, err := adoptTeamServerIdentity(ctx, reader, "beads_gc", "gc", false, "local-id")
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), "bts init")
|
|
assert.Contains(t, err.Error(), "_project_id")
|
|
})
|
|
|
|
// The distinction this pins is issueops.InitVerifier's whole reason for
|
|
// existing: an ABSENT identity means "unprovisioned, run bts init" and an
|
|
// UNREADABLE one means "the connection failed". Reporting the second as the
|
|
// first is how a flaky link gets a shared database re-provisioned.
|
|
t.Run("read error surfaces as transient, not unprovisioned", func(t *testing.T) {
|
|
reader := &fakeIdentityReader{readErr: errors.New("connection reset")}
|
|
_, _, err := adoptTeamServerIdentity(ctx, reader, "beads_gc", "gc", false, "local-id")
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), "connection reset")
|
|
assert.NotContains(t, err.Error(), "bts init")
|
|
})
|
|
|
|
t.Run("stale local project id is replaced by the provisioned one", func(t *testing.T) {
|
|
reader := &fakeIdentityReader{prefix: "gc", projectID: "bts-id"}
|
|
_, projectID, err := adoptTeamServerIdentity(ctx, reader, "beads_gc", "gc", false, "stale-local-id")
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "bts-id", projectID)
|
|
})
|
|
}
|