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.
131 lines
4.4 KiB
Go
131 lines
4.4 KiB
Go
package main
|
|
|
|
// End-to-end cover for `bd create --file` on the DIRECT route, which is where
|
|
// this command's behaviour changed when it moved onto issueops.BatchCreator.
|
|
// They run the real bd binary against an isolated embedded-Dolt workspace and
|
|
// reuse create_deps_atomic_test.go's hermetic environment and output helpers.
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// writeMarkdownPlan writes a plan file and returns its path.
|
|
func writeMarkdownPlan(t *testing.T, dir, name, body string) string {
|
|
t.Helper()
|
|
path := filepath.Join(dir, name)
|
|
if err := os.WriteFile(path, []byte(body), 0o600); err != nil {
|
|
t.Fatalf("write markdown plan: %v", err)
|
|
}
|
|
return path
|
|
}
|
|
|
|
func TestCreateFromMarkdownFile(t *testing.T) {
|
|
bd := buildBDForInitTests(t)
|
|
dir := t.TempDir()
|
|
runCreateDepsBD(t, bd, dir, "init", "--backend", "dolt", "--prefix", "test",
|
|
"--quiet", "--non-interactive", "--skip-hooks", "--skip-agents")
|
|
|
|
t.Run("creates_every_template_in_the_file", func(t *testing.T) {
|
|
plan := writeMarkdownPlan(t, dir, "plan.md", `## First from file
|
|
|
|
Opening body.
|
|
|
|
### Priority
|
|
1
|
|
|
|
### Type
|
|
bug
|
|
|
|
### Labels
|
|
api, batch
|
|
|
|
## Second from file
|
|
|
|
### Description
|
|
Second body.
|
|
`)
|
|
out := runCreateDepsBD(t, bd, dir, "create", "--file", plan)
|
|
if !strings.Contains(out, "Created 2 issues from") {
|
|
t.Errorf("create --file output = %q, want the two-issue summary", out)
|
|
}
|
|
titles := createDepsIssueTitles(t, bd, dir)
|
|
for _, title := range []string{"First from file", "Second from file"} {
|
|
if !titles[title] {
|
|
t.Errorf("issue %q was not created", title)
|
|
}
|
|
}
|
|
})
|
|
|
|
// The direct route used to hand the whole slice to the store's batch create
|
|
// with no create-only guard and no per-item content validation. A file the
|
|
// workspace refuses now refuses WHOLE, so a caller can fix the file and
|
|
// re-run it without working out which half landed.
|
|
t.Run("a_refused_template_leaves_nothing_behind", func(t *testing.T) {
|
|
plan := writeMarkdownPlan(t, dir, "half-bad.md", `## Lands before the refusal
|
|
|
|
### Description
|
|
Fine.
|
|
|
|
## Names a dependency that does not exist
|
|
|
|
### Dependencies
|
|
test-nosuchissue
|
|
`)
|
|
out, err := runCreateDepsBDRaw(bd, dir, "create", "--file", plan)
|
|
if err == nil {
|
|
t.Fatalf("create --file with an unresolvable dependency exited 0; output:\n%s", out)
|
|
}
|
|
titles := createDepsIssueTitles(t, bd, dir)
|
|
if titles["Lands before the refusal"] {
|
|
t.Error(`issue "Lands before the refusal" persisted despite the file being refused: ` +
|
|
"a --file create is all or nothing")
|
|
}
|
|
if titles["Names a dependency that does not exist"] {
|
|
t.Error("the refusing template itself persisted")
|
|
}
|
|
})
|
|
|
|
// --ephemeral is not in singleIssueOnlyFlags, so this route has always
|
|
// ACCEPTED it while building the issues without reading it: a caller who
|
|
// asked for scratch work got durable rows and no warning.
|
|
t.Run("ephemeral_is_honoured_rather_than_accepted_and_ignored", func(t *testing.T) {
|
|
plan := writeMarkdownPlan(t, dir, "scratch.md", `## Scratch from file
|
|
|
|
### Description
|
|
Ephemeral body.
|
|
`)
|
|
out := runCreateDepsBD(t, bd, dir, "create", "--file", plan, "--ephemeral", "--json")
|
|
if !strings.Contains(out, `"ephemeral": true`) && !strings.Contains(out, `"ephemeral":true`) {
|
|
t.Errorf("create --file --ephemeral --json does not report an ephemeral row:\n%s", out)
|
|
}
|
|
// And the durable listing does not carry it, which is the half a
|
|
// caller asking for scratch work actually depends on.
|
|
if createDepsIssueTitles(t, bd, dir)["Scratch from file"] {
|
|
t.Error(`"Scratch from file" is in the durable listing; --file --ephemeral must create a wisp`)
|
|
}
|
|
})
|
|
|
|
// The edges the file declares are written with the issues, in the same
|
|
// transaction — including an edge onto an issue created EARLIER in the file.
|
|
t.Run("writes_the_edges_the_file_declares", func(t *testing.T) {
|
|
blocker := strings.TrimSpace(runCreateDepsBD(t, bd, dir, "create", "file edge blocker", "--silent"))
|
|
if blocker == "" {
|
|
t.Fatal("blocker create returned empty ID")
|
|
}
|
|
plan := writeMarkdownPlan(t, dir, "edges.md", `## Blocked by an existing issue
|
|
|
|
### Dependencies
|
|
`+blocker+`
|
|
`)
|
|
runCreateDepsBD(t, bd, dir, "create", "--file", plan)
|
|
// --direction=up is what the blocker BLOCKS, which is where the edge
|
|
// the file declared shows up.
|
|
out := runCreateDepsBD(t, bd, dir, "dep", "tree", blocker, "--direction=up", "--json")
|
|
if !strings.Contains(out, "Blocked by an existing issue") {
|
|
t.Errorf("the declared edge was not written; dependents of %s:\n%s", blocker, out)
|
|
}
|
|
})
|
|
}
|