fix(daemon): cut worktrees from the mapped base branch
Repo.BaseBranch() is where an empty base means "main", and the daemon
handed the raw field to worktree.Prepare -- the one call site that did,
beside the workflow step that passes the mapped value. A repository stored
with no base therefore reached git with "" and its branch was never cut
from main.
Reachable now because the document editor stopped prefilling base (its
per-path skeletons retired in aa650e2c), which had been masking the missing
mapping rather than fixing it (archie-core-lwzd).
The guard is a wiring invariant in architecture_test.go: it walks the
package for the worktree.Prepare call and refuses the raw field, and fails
if the call is gone rather than passing unchecked.
This commit is contained in:
2 files changed
+50
-1
No files matched your search
@@ -108,3 +108,52 @@ func TestDaemonCarriesNoLocalWorkflowExecutionState(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A repository's base branch has exactly one default and Repo.BaseBranch() is
|
||||
// where it lives: an empty base means "main". Handing the raw field to the
|
||||
// worktree manager skips that mapping, so a repository stored with no base
|
||||
// reaches git with "" and the branch is never cut from main
|
||||
// (archie-core-lwzd).
|
||||
//
|
||||
// This is a wiring invariant rather than a behaviour test because the value is
|
||||
// an argument: the worktree manager's own tests cover what it does with a base,
|
||||
// and a daemon-level test would need a real clone to reach the call.
|
||||
func TestDaemonPreparesWorktreesFromTheMappedBaseBranch(t *testing.T) {
|
||||
files, err := filepath.Glob("*.go")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fileset := token.NewFileSet()
|
||||
checked := 0
|
||||
for _, path := range files {
|
||||
if strings.HasSuffix(path, "_test.go") {
|
||||
continue
|
||||
}
|
||||
file, parseErr := parser.ParseFile(fileset, path, nil, 0)
|
||||
if parseErr != nil {
|
||||
t.Errorf("parse %s: %v", path, parseErr)
|
||||
continue
|
||||
}
|
||||
ast.Inspect(file, func(node ast.Node) bool {
|
||||
call, ok := node.(*ast.CallExpr)
|
||||
if !ok || len(call.Args) != 8 {
|
||||
return true
|
||||
}
|
||||
selector, ok := call.Fun.(*ast.SelectorExpr)
|
||||
if !ok || selector.Sel.Name != "Prepare" {
|
||||
return true
|
||||
}
|
||||
checked++
|
||||
base, ok := call.Args[3].(*ast.SelectorExpr)
|
||||
if ok && base.Sel.Name == "Base" {
|
||||
t.Errorf("%s: worktree.Prepare receives the raw base field; pass BaseBranch() so an empty base means main",
|
||||
fileset.Position(call.Pos()))
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
// A rename or a move must not leave this passing without having looked.
|
||||
if checked == 0 {
|
||||
t.Error("no worktree.Prepare call found, so the base-branch invariant went unchecked")
|
||||
}
|
||||
}
|
||||
@@ -1175,7 +1175,7 @@ func (d *Daemon) process(ctx context.Context, task *workflow.Task) {
|
||||
// go-git has no --dissociate, so a shared cache would stay a live
|
||||
// dependency of each worktree and expiring one would corrupt running
|
||||
// tasks. repo.PersistentStorage still governs the container volume.
|
||||
_, branch, err = trees.Prepare(ctx, task.Owner, task.Repo, repo.Base, task.IssueNumber, task.Title, task.Body, task.Labels)
|
||||
_, branch, err = trees.Prepare(ctx, task.Owner, task.Repo, repo.BaseBranch(), task.IssueNumber, task.Title, task.Body, task.Labels)
|
||||
if err != nil {
|
||||
d.Log.Error("worktree prepare failed", "err", err)
|
||||
d.parkRunningTask(ctx, task.ID, "worktree prepare failed: "+err.Error())
|
||||
|
||||
Reference in new issue
Block a user