fix(daemon): resume a retry whose worktree is gone
prepareWorkspace chose between Manager.Prepare (refresh onto base) and a separate Manager.Resume, and Manager.Resume only opened an already-prepared clone. A remediation whose local worktree the terminal cleanup removed, an expired volume dropped, or a different host never had could therefore never be resumed, and the retry path had no way to select the mode that continues pushed work. Unify the two matched methods into Prepare(..., Target): Fresh resets onto origin/<base>, a non-empty Target resets onto origin/<that branch>, and either target clones a missing worktree. The daemon's retry path selects the target from the task row and passes the persisted branch, so a resume lands on the branch the open PR lives on and fails closed when it is not on the remote. Delete the container-mode no-op resume (hybridTrees.Resume and the resumableTrees capability) now that the daemon owns it. The remediate workflow no longer stages a resume, and the retired remediate.resume step word stays resolvable as an inert stage: a stored definition is validated as a whole collection, so a removed word would fail every workflow to decode, not just its own.
This commit is contained in:
1 parent
12b59a046d
commit
4e5b91d791
22 files changed
+363
-246
No files matched your search
@@ -154,7 +154,7 @@
|
|||||||
"url": "/dev/development/workflows/",
|
"url": "/dev/development/workflows/",
|
||||||
"title": "Workflows",
|
"title": "Workflows",
|
||||||
"section": "Development",
|
"section": "Development",
|
||||||
"body": "# Workflows\n\nAuthority: `docs/architecture/agent-system.md` for the lifecycle,\n`docs/prds/event-automation.md` for inputs, repository modes and profiles.\n\nWorkflow definitions are YAML stored as a control-plane resource. The State\nStore validates them and the agent compiles them, each against the step\nvocabulary it registers, so both must see the same step types.\n\n## Adding a step type\n\n1. Write the factory in `internal/domain/workflow` as a `StepType`. It decodes\n and validates its settings and returns an error for anything it cannot\n honour. The factory runs when a definition is saved and again when it is\n compiled, so a bad definition is refused on save.\n2. Register it through a provider in\n `internal/infrastructure/workflowsteps/workflowsteps.go`. That one list is\n what every process registers, which is how the validating and executing\n sides agree.\n3. An agent-driven step builds on `AgentStage`; do not start a second path to\n the agent runner.\n4. A step that needs no repository goes in `repoFreeStepTypes` in\n `definition.go`, or workflows declaring `repository: none` or `optional`\n cannot use it. A step that needs one may assume `tc.Dir` holds a worktree\n only when the workflow's repository is `required`.\n5. A step that ends the workflow sets `tc.Outcome`. A workflow that runs out of\n steps without an outcome is parked as a definition bug.\n6. Add a parse test (settings accepted and refused) and a run test with fake\n `Trees` and agent runner.\n\n## Changing the definition format\n\n- The fields a caller needs without the engine (inputs, repository, profile)\n live in `task.WorkflowInterface`, because the dashboard process must not\n import the workflow engine (`cmd/archie-ui/architecture_test.go`). Anything a\n binding or the dashboard checks goes there.\n- The YAML decoder rejects unknown keys. Existing stored definitions must keep\n parsing, so a new key is optional with a default that preserves today's\n behaviour.\n- A declared `outputs:` entry is written through a capture tool, so it forces\n the captures need: `task.WorkflowInterface.Needs` resolves that from the\n declaration rather than the author also writing `needs.captures`. A Kit\n profile whose harness serves no capture tools is refused before dispatch.\n- Examples in `examples/workflows/` are parsed against the registered\n vocabulary by `TestExampleWorkflowsParse`. Add one for a new capability.\n\n## Enabling and disabling\n\nThe `workflow-enablement` control-plane resource lists, per org, the workflows\nthat org has disabled; anything unlisted is enabled. Its readers are the\ndaemon's binding dispatch (a disabled workflow's binding is skipped like an\nunarmed one), the dashboard's binding save (refused) and binding list\n(`workflow_disabled`), and work requests. A new reader of \"may this org run\nthis workflow\" goes through `task.WorkflowEnablement.Enabled`, never a second\nlist. The dashboard acts in the default org until access resolves a caller's\nown.\n\n## Starting a workflow from chat\n\n`task_spawn` accepts `workflow` and an `inputs` object. The gateway forwards\ninputs through the task creation contract; it does not interpret individual\nworkflows. The daemon checks inputs against the pinned `WorkflowInterface`\nbefore acquiring a container and parks invalid requests with the reason.\n"
|
"body": "# Workflows\n\nAuthority: `docs/architecture/agent-system.md` for the lifecycle,\n`docs/prds/event-automation.md` for inputs, repository modes and profiles.\n\nWorkflow definitions are YAML stored as a control-plane resource. The State\nStore validates them and the agent compiles them, each against the step\nvocabulary it registers, so both must see the same step types.\n\n## Adding a step type\n\n1. Write the factory in `internal/domain/workflow` as a `StepType`. It decodes\n and validates its settings and returns an error for anything it cannot\n honour. The factory runs when a definition is saved and again when it is\n compiled, so a bad definition is refused on save.\n2. Register it through a provider in\n `internal/infrastructure/workflowsteps/workflowsteps.go`. That one list is\n what every process registers, which is how the validating and executing\n sides agree.\n3. An agent-driven step builds on `AgentStage`; do not start a second path to\n the agent runner.\n4. A step that needs no repository goes in `repoFreeStepTypes` in\n `definition.go`, or workflows declaring `repository: none` or `optional`\n cannot use it. A step that needs one may assume `tc.Dir` holds a worktree\n only when the workflow's repository is `required`.\n5. A step that ends the workflow sets `tc.Outcome`. A workflow that runs out of\n steps without an outcome is parked as a definition bug.\n6. Add a parse test (settings accepted and refused) and a run test with fake\n `Trees` and agent runner.\n\n## Retiring a step type\n\nA step word cannot simply be deleted. A stored or pinned definition is\nvalidated as a whole collection, so one unknown word fails EVERY workflow's\ndefinition to decode and the workflow-definitions resource becomes unreadable.\nRetire a stage by removing it from its workflow's `Stages` and adding it to\n`retiredSteps` in `definition.go`, which keeps the word resolving as an inert\nstage. The retired stage must do nothing: the behaviour it used to perform now\nbelongs to whatever layer took it over (the remediate workflow's in-container\nresume moved to daemon worktree preparation, `archie-core-866m`).\n\n## Changing the definition format\n\n- The fields a caller needs without the engine (inputs, repository, profile)\n live in `task.WorkflowInterface`, because the dashboard process must not\n import the workflow engine (`cmd/archie-ui/architecture_test.go`). Anything a\n binding or the dashboard checks goes there.\n- The YAML decoder rejects unknown keys. Existing stored definitions must keep\n parsing, so a new key is optional with a default that preserves today's\n behaviour.\n- A declared `outputs:` entry is written through a capture tool, so it forces\n the captures need: `task.WorkflowInterface.Needs` resolves that from the\n declaration rather than the author also writing `needs.captures`. A Kit\n profile whose harness serves no capture tools is refused before dispatch.\n- Examples in `examples/workflows/` are parsed against the registered\n vocabulary by `TestExampleWorkflowsParse`. Add one for a new capability.\n\n## Enabling and disabling\n\nThe `workflow-enablement` control-plane resource lists, per org, the workflows\nthat org has disabled; anything unlisted is enabled. Its readers are the\ndaemon's binding dispatch (a disabled workflow's binding is skipped like an\nunarmed one), the dashboard's binding save (refused) and binding list\n(`workflow_disabled`), and work requests. A new reader of \"may this org run\nthis workflow\" goes through `task.WorkflowEnablement.Enabled`, never a second\nlist. The dashboard acts in the default org until access resolves a caller's\nown.\n\n## Starting a workflow from chat\n\n`task_spawn` accepts `workflow` and an `inputs` object. The gateway forwards\ninputs through the task creation contract; it does not interpret individual\nworkflows. The daemon checks inputs against the pinned `WorkflowInterface`\nbefore acquiring a container and parks invalid requests with the reason.\n"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url": "/dev/prds/01-project-management/",
|
"url": "/dev/prds/01-project-management/",
|
||||||
|
|||||||
@@ -28,6 +28,17 @@ vocabulary it registers, so both must see the same step types.
|
|||||||
6. Add a parse test (settings accepted and refused) and a run test with fake
|
6. Add a parse test (settings accepted and refused) and a run test with fake
|
||||||
`Trees` and agent runner.
|
`Trees` and agent runner.
|
||||||
|
|
||||||
|
## Retiring a step type
|
||||||
|
|
||||||
|
A step word cannot simply be deleted. A stored or pinned definition is
|
||||||
|
validated as a whole collection, so one unknown word fails EVERY workflow's
|
||||||
|
definition to decode and the workflow-definitions resource becomes unreadable.
|
||||||
|
Retire a stage by removing it from its workflow's `Stages` and adding it to
|
||||||
|
`retiredSteps` in `definition.go`, which keeps the word resolving as an inert
|
||||||
|
stage. The retired stage must do nothing: the behaviour it used to perform now
|
||||||
|
belongs to whatever layer took it over (the remediate workflow's in-container
|
||||||
|
resume moved to daemon worktree preparation, `archie-core-866m`).
|
||||||
|
|
||||||
## Changing the definition format
|
## Changing the definition format
|
||||||
|
|
||||||
- The fields a caller needs without the engine (inputs, repository, profile)
|
- The fields a caller needs without the engine (inputs, repository, profile)
|
||||||
|
|||||||
@@ -107,22 +107,6 @@ func (h *hybridTrees) Snapshot(ctx context.Context, dir, destDir string) error {
|
|||||||
return h.local.Snapshot(ctx, dir, destDir)
|
return h.local.Snapshot(ctx, dir, destDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resume is a no-op here for the same reason Prepare is: resuming a PR
|
|
||||||
// branch needs the daemon's forge credential to fetch, so archied must run
|
|
||||||
// it against the bind-mounted worktree before the container starts, the
|
|
||||||
// same way it runs Prepare today. The container's worktree is already
|
|
||||||
// resumed by the time a remediate run reaches this stage.
|
|
||||||
func (h *hybridTrees) Resume(ctx context.Context, dir, branch string) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dir returns the bind-mounted worktree path archied already prepared,
|
|
||||||
// ignoring its arguments -- the sandbox has no way to independently derive
|
|
||||||
// or verify the path, same as Prepare above.
|
|
||||||
func (h *hybridTrees) Dir(owner, repo string, issue int) string {
|
|
||||||
return h.localDir
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *hybridTrees) ChangedLines(ctx context.Context, dir, base string) (int, error) {
|
func (h *hybridTrees) ChangedLines(ctx context.Context, dir, base string) (int, error) {
|
||||||
return h.local.ChangedLines(ctx, dir, base)
|
return h.local.ChangedLines(ctx, dir, base)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -302,7 +302,7 @@ type remoteManager struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *remoteManager) Prepare(ctx context.Context, owner, repo, base string, issue int, title, body, labels string) (string, string, error) {
|
func (r *remoteManager) Prepare(ctx context.Context, owner, repo, base string, issue int, title, body, labels string) (string, string, error) {
|
||||||
dir, branch, err := r.manager.Prepare(ctx, owner, repo, base, issue, title, body, labels)
|
dir, branch, err := r.manager.Prepare(ctx, owner, repo, base, issue, title, body, labels, worktree.Fresh)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
r.dir = dir
|
r.dir = dir
|
||||||
r.branch = branch
|
r.branch = branch
|
||||||
@@ -634,7 +634,7 @@ func TestExecuteTaskRequestUsesInfrastructureRPCDependencies(t *testing.T) {
|
|||||||
BotEmail: "archie-bot@example.com",
|
BotEmail: "archie-bot@example.com",
|
||||||
BaseURL: "file://" + host,
|
BaseURL: "file://" + host,
|
||||||
}
|
}
|
||||||
hostDir, branch, err := daemonTrees.Prepare(ctx, "acme", "rpc-widget", "main", 2, task.Title, "", "bootstrap")
|
hostDir, branch, err := daemonTrees.Prepare(ctx, "acme", "rpc-widget", "main", 2, task.Title, "", "bootstrap", worktree.Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -726,7 +726,7 @@ func TestExecuteTaskRequestForwardsWorkflowEventsOverNATS(t *testing.T) {
|
|||||||
BotEmail: "archie-bot@example.com",
|
BotEmail: "archie-bot@example.com",
|
||||||
BaseURL: "file://" + host,
|
BaseURL: "file://" + host,
|
||||||
}
|
}
|
||||||
hostDir, branch, err := daemonTrees.Prepare(ctx, "acme", "events-widget", "main", 3, task.Title, "", "bootstrap")
|
hostDir, branch, err := daemonTrees.Prepare(ctx, "acme", "events-widget", "main", 3, task.Title, "", "bootstrap", worktree.Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -919,7 +919,7 @@ func TestHybridTreesForwardsChangedFileStatsToItsLocalManager(t *testing.T) {
|
|||||||
WorkDir: t.TempDir(), Token: "unused",
|
WorkDir: t.TempDir(), Token: "unused",
|
||||||
BotUser: "archie-bot", BotEmail: "archie-bot@example.com", BaseURL: "file://" + host,
|
BotUser: "archie-bot", BotEmail: "archie-bot@example.com", BaseURL: "file://" + host,
|
||||||
}
|
}
|
||||||
dir, branch, err := manager.Prepare(ctx, "acme", "diffstat", "main", 4, "feat: widget", "", "")
|
dir, branch, err := manager.Prepare(ctx, "acme", "diffstat", "main", 4, "feat: widget", "", "", worktree.Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("prepare: %v", err)
|
t.Fatalf("prepare: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,7 +136,9 @@ func TestDaemonPreparesWorktreesFromTheMappedBaseBranch(t *testing.T) {
|
|||||||
}
|
}
|
||||||
ast.Inspect(file, func(node ast.Node) bool {
|
ast.Inspect(file, func(node ast.Node) bool {
|
||||||
call, ok := node.(*ast.CallExpr)
|
call, ok := node.(*ast.CallExpr)
|
||||||
if !ok || len(call.Args) != 8 {
|
// Prepare carries owner, repo, base, issue, title, body, labels and
|
||||||
|
// the daemon's prepare target: nine arguments.
|
||||||
|
if !ok || len(call.Args) != 9 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
selector, ok := call.Fun.(*ast.SelectorExpr)
|
selector, ok := call.Fun.(*ast.SelectorExpr)
|
||||||
|
|||||||
+28
-35
@@ -1485,25 +1485,42 @@ func (d *Daemon) prepareWorkspace(ctx context.Context, task *workflow.Task, tree
|
|||||||
}
|
}
|
||||||
return dir, true
|
return dir, true
|
||||||
}
|
}
|
||||||
// A task that continues an already-open PR branch -- the remediate
|
// The retry path selects the worktree mode from the task row. A task that
|
||||||
// workflow -- resumes that branch's remote tip instead of resetting onto
|
// continues an already-open PR branch -- the remediate workflow -- resumes
|
||||||
// base. Preparing one the ordinary way discarded the commits the implement
|
// that branch's remote tip instead of resetting onto base: preparing one
|
||||||
// run had already pushed, so the agent remediated a PR from a tree that no
|
// the ordinary way discarded the commits the implement run had already
|
||||||
// longer contained it. This runs before Acquire, because the daemon holds
|
// pushed, so the agent remediated a PR from a tree that no longer contained
|
||||||
// the forge credential that fetches the branch and the container must find
|
// it. Every other task starts fresh on base. This runs before Acquire,
|
||||||
// the PR's work already in place.
|
// because the daemon holds the forge credential that fetches the branch and
|
||||||
|
// the container must find the PR's work already in place. It also runs on a
|
||||||
|
// retry whose local worktree is gone: Prepare clones a missing worktree for
|
||||||
|
// either target, which is how a resume reaches a task whose clone the
|
||||||
|
// terminal cleanup removed.
|
||||||
|
target := worktree.Fresh
|
||||||
if continuesOpenPRBranch(task) {
|
if continuesOpenPRBranch(task) {
|
||||||
return d.resumePRBranchWorkspace(ctx, task, trees)
|
if task.Branch == "" {
|
||||||
|
// A remediation task is queued against the branch its implement
|
||||||
|
// run pushed, so an empty branch is a dispatch bug upstream and no
|
||||||
|
// retry can fix it.
|
||||||
|
d.Log.Error("remediate task has no persisted branch", "task", task.ID)
|
||||||
|
d.parkRunningTask(ctx, task.ID, "worktree resume failed: remediate task has no branch to resume", taskstate.ParkNeedsHuman)
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
target = worktree.Target(task.Branch)
|
||||||
}
|
}
|
||||||
// Every task gets an independent full clone. The former
|
// Every task gets an independent full clone. The former
|
||||||
// PreparePersistent path shared objects with a per-repo bare cache;
|
// PreparePersistent path shared objects with a per-repo bare cache;
|
||||||
// go-git has no --dissociate, so a shared cache would stay a live
|
// go-git has no --dissociate, so a shared cache would stay a live
|
||||||
// dependency of each worktree and expiring one would corrupt running
|
// dependency of each worktree and expiring one would corrupt running
|
||||||
// tasks. repo.PersistentStorage still governs the container volume.
|
// tasks. repo.PersistentStorage still governs the container volume.
|
||||||
dir, branch, err := trees.Prepare(ctx, task.Owner, task.Repo, repo.BaseBranch(), task.IssueNumber, task.Title, task.Body, task.Labels)
|
dir, branch, err := trees.Prepare(ctx, task.Owner, task.Repo, repo.BaseBranch(), task.IssueNumber, task.Title, task.Body, task.Labels, target)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.Log.Error("worktree prepare failed", "err", err)
|
reason := "worktree prepare failed: " + err.Error()
|
||||||
d.parkRunningTask(ctx, task.ID, "worktree prepare failed: "+err.Error(), taskstate.ParkTransient)
|
if target != worktree.Fresh {
|
||||||
|
reason = "worktree resume failed: " + err.Error()
|
||||||
|
}
|
||||||
|
d.Log.Error("worktree prepare failed", "task", task.ID, "err", err)
|
||||||
|
d.parkRunningTask(ctx, task.ID, reason, taskstate.ParkTransient)
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
task.Branch = branch
|
task.Branch = branch
|
||||||
@@ -1524,30 +1541,6 @@ func continuesOpenPRBranch(task *workflow.Task) bool {
|
|||||||
return task.Workflow == "remediate"
|
return task.Workflow == "remediate"
|
||||||
}
|
}
|
||||||
|
|
||||||
// resumePRBranchWorkspace prepares a task's worktree on the branch its row
|
|
||||||
// names, never on a branch recomputed from the title or labels: the PR was
|
|
||||||
// opened from the persisted branch, and a retitled issue or relabelled task
|
|
||||||
// would otherwise name a branch that does not exist. It fails closed -- there
|
|
||||||
// is deliberately no fallback to preparing base, because that fallback is the
|
|
||||||
// defect this route removes.
|
|
||||||
func (d *Daemon) resumePRBranchWorkspace(ctx context.Context, task *workflow.Task, trees *worktree.Manager) (string, bool) {
|
|
||||||
if task.Branch == "" {
|
|
||||||
// A remediation task is queued against the branch its implement run
|
|
||||||
// pushed, so an empty branch is a dispatch bug upstream and no retry
|
|
||||||
// can fix it.
|
|
||||||
d.Log.Error("remediate task has no persisted branch", "task", task.ID)
|
|
||||||
d.parkRunningTask(ctx, task.ID, "worktree resume failed: remediate task has no branch to resume", taskstate.ParkNeedsHuman)
|
|
||||||
return "", false
|
|
||||||
}
|
|
||||||
dir := trees.Dir(task.Owner, task.Repo, task.IssueNumber)
|
|
||||||
if err := trees.Resume(ctx, dir, task.Branch); err != nil {
|
|
||||||
d.Log.Error("worktree resume failed", "task", task.ID, "branch", task.Branch, "err", err)
|
|
||||||
d.parkRunningTask(ctx, task.ID, "worktree resume failed: "+err.Error(), taskstate.ParkTransient)
|
|
||||||
return "", false
|
|
||||||
}
|
|
||||||
return dir, true
|
|
||||||
}
|
|
||||||
|
|
||||||
// cleanupTerminalTaskWorktree removes a task's worktree once its forge side is
|
// cleanupTerminalTaskWorktree removes a task's worktree once its forge side is
|
||||||
// settled, unless the worktree still holds work no commit captured.
|
// settled, unless the worktree still holds work no commit captured.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import (
|
|||||||
func pushedImplementRun(t *testing.T, trees *worktree.Manager, title string) (dir, branch string, tip plumbing.Hash) {
|
func pushedImplementRun(t *testing.T, trees *worktree.Manager, title string) (dir, branch string, tip plumbing.Hash) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
dir, branch, err := trees.Prepare(ctx, "acme", "widget", "main", 7, title, "", "bug")
|
dir, branch, err := trees.Prepare(ctx, "acme", "widget", "main", 7, title, "", "bug", worktree.Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Prepare() error = %v", err)
|
t.Fatalf("Prepare() error = %v", err)
|
||||||
}
|
}
|
||||||
@@ -116,6 +116,42 @@ func TestPrepareWorkspaceResumesThePersistedBranchForARemediation(t *testing.T)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestPrepareWorkspaceResumesAPRBranchAfterTheWorktreeWasRemoved pins the
|
||||||
|
// retry failure archie-core-866m reports. Manager.Resume opens an
|
||||||
|
// already-prepared worktree, so a remediation whose local clone is gone -- a
|
||||||
|
// first run on this host, an expired volume, a worktree the terminal cleanup
|
||||||
|
// removed before a retry -- can never be resumed, and the retry path offers
|
||||||
|
// only fresh-from-base or that unrunnable resume. Preparing a resume must
|
||||||
|
// clone when the worktree is missing, exactly as a fresh prepare does, and
|
||||||
|
// land on the PR branch tip rather than base.
|
||||||
|
func TestPrepareWorkspaceResumesAPRBranchAfterTheWorktreeWasRemoved(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
trees := newTestTrees(t, newLocalRemote(t, "acme", "widget"))
|
||||||
|
dir, branch, tip := pushedImplementRun(t, trees, "fix: original issue")
|
||||||
|
|
||||||
|
// The clone is gone before the retry reaches prepareWorkspace.
|
||||||
|
if err := os.RemoveAll(dir); err != nil {
|
||||||
|
t.Fatalf("remove worktree: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
d, st, _ := testDaemon(t, 3, 0)
|
||||||
|
task := claimedTask(t, st, "fix: original issue", "remediate", branch)
|
||||||
|
|
||||||
|
gotDir, ok := d.prepareWorkspace(ctx, task, trees, config.Repo{Owner: "acme", Name: "widget", Base: "main"})
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("prepareWorkspace() = false, want the remediation prepared on its PR branch after the worktree was removed")
|
||||||
|
}
|
||||||
|
if gotDir != dir {
|
||||||
|
t.Errorf("prepareWorkspace() dir = %q, want the task's worktree %q", gotDir, dir)
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(filepath.Join(gotDir, "widget.go")); err != nil {
|
||||||
|
t.Fatalf("widget.go missing after prepare: %v (the PR branch's work was not restored)", err)
|
||||||
|
}
|
||||||
|
if got := headOf(t, gotDir); got != tip {
|
||||||
|
t.Errorf("worktree HEAD = %s, want the PR branch tip %s", got, tip)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TestPrepareWorkspaceFailsClosedWhenTheRemediationBranchIsGone pins the other
|
// TestPrepareWorkspaceFailsClosedWhenTheRemediationBranchIsGone pins the other
|
||||||
// half of the same routing: a remediation whose branch is not on the remote
|
// half of the same routing: a remediation whose branch is not on the remote
|
||||||
// must park, not quietly fall back to preparing base -- the fallback is exactly
|
// must park, not quietly fall back to preparing base -- the fallback is exactly
|
||||||
|
|||||||
@@ -276,7 +276,7 @@ func TestCleanupTerminalTaskWorktreeWithCancelledContext(t *testing.T) {
|
|||||||
// A prepared clone: the cancelled context is the thing under test,
|
// A prepared clone: the cancelled context is the thing under test,
|
||||||
// so the worktree itself is readied with a live one.
|
// so the worktree itself is readied with a live one.
|
||||||
if _, _, err := trees.Prepare(context.Background(), task.Owner, task.Repo, "main",
|
if _, _, err := trees.Prepare(context.Background(), task.Owner, task.Repo, "main",
|
||||||
task.IssueNumber, task.Title, task.Body, task.Labels); err != nil {
|
task.IssueNumber, task.Title, task.Body, task.Labels, worktree.Fresh); err != nil {
|
||||||
t.Fatalf("prepare worktree: %v", err)
|
t.Fatalf("prepare worktree: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ func TestCleanupTerminalTaskWorktreeLifecycle(t *testing.T) {
|
|||||||
workDir := targetTrees.Dir(claimed.Owner, claimed.Repo, claimed.IssueNumber)
|
workDir := targetTrees.Dir(claimed.Owner, claimed.Repo, claimed.IssueNumber)
|
||||||
// A prepared clone, the only shape the daemon ever cleans up.
|
// A prepared clone, the only shape the daemon ever cleans up.
|
||||||
if _, _, err := targetTrees.Prepare(ctx, claimed.Owner, claimed.Repo, "main",
|
if _, _, err := targetTrees.Prepare(ctx, claimed.Owner, claimed.Repo, "main",
|
||||||
claimed.IssueNumber, claimed.Title, claimed.Body, claimed.Labels); err != nil {
|
claimed.IssueNumber, claimed.Title, claimed.Body, claimed.Labels, worktree.Fresh); err != nil {
|
||||||
t.Fatalf("prepare worktree: %v", err)
|
t.Fatalf("prepare worktree: %v", err)
|
||||||
}
|
}
|
||||||
if tt.uncommitted {
|
if tt.uncommitted {
|
||||||
|
|||||||
@@ -188,6 +188,20 @@ func noSettingsFactory(stage Stage) StepFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// retiredSteps are step types no shipped workflow names any more but that must
|
||||||
|
// keep resolving. A stored workflow definition is validated as a whole
|
||||||
|
// collection, so a word dropped from the vocabulary does not merely fail its
|
||||||
|
// own step -- it fails every workflow's definition to decode, taking the whole
|
||||||
|
// workflow-definitions resource down with it. Each entry is inert by
|
||||||
|
// construction: the behaviour its stage used to perform has another owner now,
|
||||||
|
// and it exists only so a definition pinned or stored before that move still
|
||||||
|
// parses and compiles.
|
||||||
|
var retiredSteps = map[string]Stage{
|
||||||
|
// The remediate workflow's in-container resume stage moved to daemon
|
||||||
|
// preparation (archie-core-866m); see retiredResumeStep.
|
||||||
|
"remediate.resume": retiredResumeStep(),
|
||||||
|
}
|
||||||
|
|
||||||
// BuiltinStepRegistry exposes every shipped stage as a typed, non-interpreted step.
|
// BuiltinStepRegistry exposes every shipped stage as a typed, non-interpreted step.
|
||||||
func BuiltinStepRegistry() StepRegistry {
|
func BuiltinStepRegistry() StepRegistry {
|
||||||
registry := StepRegistry{}
|
registry := StepRegistry{}
|
||||||
@@ -196,6 +210,9 @@ func BuiltinStepRegistry() StepRegistry {
|
|||||||
registry[id+"."+stage.Name] = noSettingsFactory(stage)
|
registry[id+"."+stage.Name] = noSettingsFactory(stage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for name, stage := range retiredSteps {
|
||||||
|
registry[name] = noSettingsFactory(stage)
|
||||||
|
}
|
||||||
return registry
|
return registry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -134,3 +134,28 @@ func TestShippedDefinitionsPreserveStageOrder(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestRetiredStepTypeStillCompiles pins the compatibility contract for a step
|
||||||
|
// word retired from a shipped workflow (archie-core-866m). A stored definition
|
||||||
|
// is validated as a whole collection, so one unknown step type fails EVERY
|
||||||
|
// workflow's definition to decode, taking the workflow-definitions resource
|
||||||
|
// down with it. A definition pinned or stored before the retire must therefore
|
||||||
|
// keep parsing, compiling, and running -- and the retired stage itself must be
|
||||||
|
// inert, because the behaviour it used to perform now happens before the
|
||||||
|
// container starts.
|
||||||
|
func TestRetiredStepTypeStillCompiles(t *testing.T) {
|
||||||
|
src := "id: remediate\nsteps:\n - type: remediate.check-review-payload\n - type: remediate.resume\n"
|
||||||
|
wf, err := ParseAndCompile(src, BuiltinStepRegistry())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ParseAndCompile(a stored definition naming a retired step): %v", err)
|
||||||
|
}
|
||||||
|
if len(wf.Stages) != 2 {
|
||||||
|
t.Fatalf("stages = %d, want 2", len(wf.Stages))
|
||||||
|
}
|
||||||
|
if wf.Stages[1].Name != "resume" {
|
||||||
|
t.Fatalf("stage 2 = %q, want the retired resume stage", wf.Stages[1].Name)
|
||||||
|
}
|
||||||
|
if err := wf.Stages[1].Run(t.Context(), &TaskContext{Task: &Task{}}); err != nil {
|
||||||
|
t.Fatalf("the retired resume stage is not inert: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -514,7 +514,7 @@ func TestDiffRulesStepReadsARealDiff(t *testing.T) {
|
|||||||
}
|
}
|
||||||
var log bytes.Buffer
|
var log bytes.Buffer
|
||||||
tc := diffRulesTestTaskContext(t, dir, &log)
|
tc := diffRulesTestTaskContext(t, dir, &log)
|
||||||
tc.Trees = &worktree.Manager{WorkDir: t.TempDir()}
|
tc.Trees = &realTrees{Manager: &worktree.Manager{WorkDir: t.TempDir()}}
|
||||||
|
|
||||||
if err := stage.Run(context.Background(), tc); err != nil {
|
if err := stage.Run(context.Background(), tc); err != nil {
|
||||||
t.Fatalf("stage.Run(): %v", err)
|
t.Fatalf("stage.Run(): %v", err)
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func TestStageBaselineGateAccountsForRepairAgentUsage(t *testing.T) {
|
|||||||
tc := &TaskContext{
|
tc := &TaskContext{
|
||||||
Task: task, Repo: config.Repo{Owner: "o", Name: "r", Gate: [][]string{{"sh", script}}},
|
Task: task, Repo: config.Repo{Owner: "o", Name: "r", Gate: [][]string{{"sh", script}}},
|
||||||
Cfg: config.Config{Models: map[string]string{"builder": "provider/model"}},
|
Cfg: config.Config{Models: map[string]string{"builder": "provider/model"}},
|
||||||
Agent: runner, Trees: &worktree.Manager{BotUser: "archie", BotEmail: "archie@example.com"},
|
Agent: runner, Trees: &realTrees{Manager: &worktree.Manager{BotUser: "archie", BotEmail: "archie@example.com"}},
|
||||||
Dir: dir, Log: slog.New(slog.DiscardHandler),
|
Dir: dir, Log: slog.New(slog.DiscardHandler),
|
||||||
}
|
}
|
||||||
if err := StageBaselineGate().Run(t.Context(), tc); err != nil {
|
if err := StageBaselineGate().Run(t.Context(), tc); err != nil {
|
||||||
@@ -154,7 +154,7 @@ func TestStageBaselineGateMissionOmitsPassingPackageOutput(t *testing.T) {
|
|||||||
Task: &Task{ID: 1, Owner: "o", Repo: "r"},
|
Task: &Task{ID: 1, Owner: "o", Repo: "r"},
|
||||||
Repo: config.Repo{Owner: "o", Name: "r", Gate: [][]string{{"sh", script}}},
|
Repo: config.Repo{Owner: "o", Name: "r", Gate: [][]string{{"sh", script}}},
|
||||||
Cfg: config.Config{Models: map[string]string{"builder": "provider/model"}},
|
Cfg: config.Config{Models: map[string]string{"builder": "provider/model"}},
|
||||||
Agent: runner, Trees: &worktree.Manager{BotUser: "archie", BotEmail: "archie@example.com"},
|
Agent: runner, Trees: &realTrees{Manager: &worktree.Manager{BotUser: "archie", BotEmail: "archie@example.com"}},
|
||||||
Dir: dir, Log: slog.New(slog.DiscardHandler),
|
Dir: dir, Log: slog.New(slog.DiscardHandler),
|
||||||
}
|
}
|
||||||
if err := StageBaselineGate().Run(t.Context(), tc); err != nil {
|
if err := StageBaselineGate().Run(t.Context(), tc); err != nil {
|
||||||
@@ -193,7 +193,7 @@ func TestStageBaselineGateSetsBaselineFixedWhenItCommits(t *testing.T) {
|
|||||||
tc := &TaskContext{
|
tc := &TaskContext{
|
||||||
Task: task, Repo: config.Repo{Owner: "o", Name: "r", Gate: [][]string{{"sh", script}}},
|
Task: task, Repo: config.Repo{Owner: "o", Name: "r", Gate: [][]string{{"sh", script}}},
|
||||||
Cfg: config.Config{Models: map[string]string{"builder": "provider/model"}},
|
Cfg: config.Config{Models: map[string]string{"builder": "provider/model"}},
|
||||||
Agent: runner, Trees: &worktree.Manager{BotUser: "archie", BotEmail: "archie@example.com"},
|
Agent: runner, Trees: &realTrees{Manager: &worktree.Manager{BotUser: "archie", BotEmail: "archie@example.com"}},
|
||||||
Dir: dir, Log: slog.New(slog.DiscardHandler),
|
Dir: dir, Log: slog.New(slog.DiscardHandler),
|
||||||
}
|
}
|
||||||
if err := StageBaselineGate().Run(t.Context(), tc); err != nil {
|
if err := StageBaselineGate().Run(t.Context(), tc); err != nil {
|
||||||
@@ -475,11 +475,6 @@ type fakeTrees struct {
|
|||||||
// change" from "not committed yet". The zero value is a clean worktree.
|
// change" from "not committed yet". The zero value is a clean worktree.
|
||||||
uncommitted bool
|
uncommitted bool
|
||||||
uncommittedErr error
|
uncommittedErr error
|
||||||
|
|
||||||
resumed bool
|
|
||||||
resumeDir string
|
|
||||||
resumeBranch string
|
|
||||||
resumeErr error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *fakeTrees) Prepare(context.Context, string, string, string, int, string, string, string) (string, string, error) {
|
func (f *fakeTrees) Prepare(context.Context, string, string, string, int, string, string, string) (string, string, error) {
|
||||||
@@ -513,13 +508,6 @@ func (f *fakeTrees) ChangedLines(context.Context, string, string) (int, error) {
|
|||||||
|
|
||||||
func (f *fakeTrees) Snapshot(context.Context, string, string) error { return nil }
|
func (f *fakeTrees) Snapshot(context.Context, string, string) error { return nil }
|
||||||
|
|
||||||
func (f *fakeTrees) Resume(_ context.Context, dir, branch string) error {
|
|
||||||
f.resumed, f.resumeDir, f.resumeBranch = true, dir, branch
|
|
||||||
return f.resumeErr
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *fakeTrees) Dir(string, string, int) string { return f.dir }
|
|
||||||
|
|
||||||
// TestStageCommitPushPushesBaselineFixEvenWithNothingNewToCommit is the
|
// TestStageCommitPushPushesBaselineFixEvenWithNothingNewToCommit is the
|
||||||
// regression case for archie-core-95dj: StageBaselineGate already
|
// regression case for archie-core-95dj: StageBaselineGate already
|
||||||
// committed a real, gate-verified fix for a pre-existing failure, and the
|
// committed a real, gate-verified fix for a pre-existing failure, and the
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package workflow
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/samcharles93/archie-core/internal/worktree"
|
||||||
|
)
|
||||||
|
|
||||||
|
// realTrees adapts a real worktree.Manager to the workflow's Trees contract for
|
||||||
|
// the tests that drive a stage against a real clone. Manager.Prepare carries
|
||||||
|
// the daemon's prepare target -- worktree.Fresh for a run that starts new work
|
||||||
|
// -- which the workflow's Trees contract deliberately does not expose, so the
|
||||||
|
// manager no longer satisfies Trees directly. Embedding keeps every other
|
||||||
|
// method; these tests never call Prepare, they only need the manager's git
|
||||||
|
// reads (Diff, ChangedFiles, ChangedFileStats).
|
||||||
|
type realTrees struct{ *worktree.Manager }
|
||||||
|
|
||||||
|
func (t realTrees) Prepare(ctx context.Context, owner, repo, base string, issue int, title, body, labels string) (string, string, error) {
|
||||||
|
return t.Manager.Prepare(ctx, owner, repo, base, issue, title, body, labels, worktree.Fresh)
|
||||||
|
}
|
||||||
@@ -115,42 +115,18 @@ func orUnknown(s string) string {
|
|||||||
// other clipped park reasons in this package.
|
// other clipped park reasons in this package.
|
||||||
const remediationRoundCapBytes = 2000
|
const remediationRoundCapBytes = 2000
|
||||||
|
|
||||||
// resumableTrees is the optional capability a Trees implementation offers
|
// retiredResumeStep is the remediate workflow's old in-container resume stage,
|
||||||
// for continuing work on an already-open PR branch instead of starting a
|
// kept as an inert word in the step vocabulary. The resume it used to perform
|
||||||
// fresh worktree. It stays separate because Trees is already at the interface
|
// now happens in daemon.prepareWorkspace before the container starts
|
||||||
// size cap and most workflow stages do not need branch resumption.
|
// (archie-core-866m): the daemon holds the forge credential that fetches the
|
||||||
//
|
// branch and positions the worktree onto origin/<branch>, so by the time a
|
||||||
// *worktree.Manager (real git access) and the container-mode hybrid
|
// container-side stage could run there is nothing left to do. It is
|
||||||
// implementation both already satisfy this structurally; a Trees
|
// deliberately not a stage of Remediate() any more -- a new definition never
|
||||||
// implementation that doesn't (a narrower test fake, say) simply cannot run
|
// names it -- but a definition pinned or stored before that move still does,
|
||||||
// the remediate workflow, which StageResumeWorktree reports plainly.
|
// and a step word removed from the vocabulary fails every workflow's
|
||||||
type resumableTrees interface {
|
// definition to decode, not just its own.
|
||||||
Dir(owner, repo string, issue int) string
|
func retiredResumeStep() Stage {
|
||||||
Resume(ctx context.Context, dir, branch string) error
|
return Stage{Name: "resume", Run: func(context.Context, *TaskContext) error { return nil }}
|
||||||
}
|
|
||||||
|
|
||||||
// StageResumeWorktree re-syncs the task's already-prepared worktree onto
|
|
||||||
// its PR branch's remote tip, so the remediate workflow continues on the
|
|
||||||
// branch the implement run pushed instead of resetting to base the way
|
|
||||||
// StagePrepareWorktree's refresh would (docs/prds/pr-review-remediation.md
|
|
||||||
// decision 4). A remediate task always has a branch: it only ever runs
|
|
||||||
// against a PR archie itself opened.
|
|
||||||
func StageResumeWorktree() Stage {
|
|
||||||
return Stage{Name: "resume", Run: func(ctx context.Context, tc *TaskContext) error {
|
|
||||||
if tc.Task.Branch == "" {
|
|
||||||
return fmt.Errorf("remediate: task has no branch to resume")
|
|
||||||
}
|
|
||||||
rt, ok := tc.Trees.(resumableTrees)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("remediate: this worktree implementation cannot resume a PR branch")
|
|
||||||
}
|
|
||||||
dir := rt.Dir(tc.Task.Owner, tc.Task.Repo, tc.Task.IssueNumber)
|
|
||||||
if err := rt.Resume(ctx, dir, tc.Task.Branch); err != nil {
|
|
||||||
return fmt.Errorf("resume worktree onto %s: %w", tc.Task.Branch, err)
|
|
||||||
}
|
|
||||||
tc.Dir, tc.Branch = dir, tc.Task.Branch
|
|
||||||
return nil
|
|
||||||
}}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// StageRemediationRoundCap enforces the hard stop on an unbounded
|
// StageRemediationRoundCap enforces the hard stop on an unbounded
|
||||||
@@ -294,14 +270,15 @@ func StageRemediationReply() Stage {
|
|||||||
// Remediate runs one remediation round against an archie-owned, still-open
|
// Remediate runs one remediation round against an archie-owned, still-open
|
||||||
// pull request in response to a forge review reaction
|
// pull request in response to a forge review reaction
|
||||||
// (docs/prds/pr-review-remediation.md decision 4). It reuses the task's
|
// (docs/prds/pr-review-remediation.md decision 4). It reuses the task's
|
||||||
// existing worktree and branch rather than opening a new PR.
|
// existing worktree and branch rather than opening a new PR: the worktree is
|
||||||
|
// positioned onto the PR branch by daemon.prepareWorkspace before the container
|
||||||
|
// starts, so there is no in-container resume stage.
|
||||||
func Remediate() Workflow {
|
func Remediate() Workflow {
|
||||||
return Workflow{
|
return Workflow{
|
||||||
Name: "remediate",
|
Name: "remediate",
|
||||||
Stages: []Stage{
|
Stages: []Stage{
|
||||||
StageCheckReviewPayload(),
|
StageCheckReviewPayload(),
|
||||||
StageRemediationRoundCap(),
|
StageRemediationRoundCap(),
|
||||||
StageResumeWorktree(),
|
|
||||||
remediateBuildStage(),
|
remediateBuildStage(),
|
||||||
StageRemediationCommitPush(),
|
StageRemediationCommitPush(),
|
||||||
StageRemediationReply(),
|
StageRemediationReply(),
|
||||||
|
|||||||
@@ -42,31 +42,6 @@ func TestStageCheckReviewPayloadFailsOnEmptyPayload(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStageResumeWorktreeRequiresABranch(t *testing.T) {
|
|
||||||
tc := &TaskContext{Task: &Task{ID: 1, Owner: "o", Repo: "r", IssueNumber: 5}, Trees: &fakeTrees{}}
|
|
||||||
if err := StageResumeWorktree().Run(t.Context(), tc); err == nil {
|
|
||||||
t.Fatal("StageResumeWorktree with no branch = nil error, want an error")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestStageResumeWorktreeResumesOntoTheTaskBranch(t *testing.T) {
|
|
||||||
trees := &fakeTrees{dir: "/worktrees/o-r-5"}
|
|
||||||
tc := &TaskContext{
|
|
||||||
Task: &Task{ID: 1, Owner: "o", Repo: "r", IssueNumber: 5, Branch: "archie/issue-5"},
|
|
||||||
Trees: trees,
|
|
||||||
}
|
|
||||||
if err := StageResumeWorktree().Run(t.Context(), tc); err != nil {
|
|
||||||
t.Fatalf("StageResumeWorktree: %v", err)
|
|
||||||
}
|
|
||||||
if !trees.resumed || trees.resumeDir != "/worktrees/o-r-5" || trees.resumeBranch != "archie/issue-5" {
|
|
||||||
t.Fatalf("Resume call = resumed=%v dir=%q branch=%q, want true /worktrees/o-r-5 archie/issue-5",
|
|
||||||
trees.resumed, trees.resumeDir, trees.resumeBranch)
|
|
||||||
}
|
|
||||||
if tc.Dir != "/worktrees/o-r-5" || tc.Branch != "archie/issue-5" {
|
|
||||||
t.Fatalf("tc.Dir/Branch = %q/%q, want /worktrees/o-r-5/archie/issue-5", tc.Dir, tc.Branch)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestStageRemediationRoundCapCountsARoundUnderTheCap(t *testing.T) {
|
func TestStageRemediationRoundCapCountsARoundUnderTheCap(t *testing.T) {
|
||||||
forge := &fakeForge{}
|
forge := &fakeForge{}
|
||||||
tc := &TaskContext{
|
tc := &TaskContext{
|
||||||
@@ -231,9 +206,6 @@ func TestRemediateEndToEndAddressesCommentsAndReplies(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !trees.resumed {
|
|
||||||
t.Fatal("worktree was never resumed")
|
|
||||||
}
|
|
||||||
if !trees.pushed {
|
if !trees.pushed {
|
||||||
t.Fatal("remediation commit was never pushed")
|
t.Fatal("remediation commit was never pushed")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ func newYaegiGateTaskContext(t *testing.T, dir string) *TaskContext {
|
|||||||
return &TaskContext{
|
return &TaskContext{
|
||||||
Task: &Task{ID: 1, Owner: "acme", Repo: "todo", IssueNumber: 42},
|
Task: &Task{ID: 1, Owner: "acme", Repo: "todo", IssueNumber: 42},
|
||||||
Repo: config.Repo{Owner: "acme", Name: "todo", Base: "main"},
|
Repo: config.Repo{Owner: "acme", Name: "todo", Base: "main"},
|
||||||
Trees: &worktree.Manager{WorkDir: t.TempDir()},
|
Trees: &realTrees{Manager: &worktree.Manager{WorkDir: t.TempDir()}},
|
||||||
Dir: dir,
|
Dir: dir,
|
||||||
Log: slog.New(slog.DiscardHandler),
|
Log: slog.New(slog.DiscardHandler),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,23 +7,34 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/go-git/go-git/v6"
|
"github.com/go-git/go-git/v6"
|
||||||
|
"github.com/go-git/go-git/v6/plumbing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestResumeResetsToBranchTipNotBase pins the remediate workflow's worktree
|
// headHash reads a worktree's HEAD commit, so a test can assert which commit a
|
||||||
// semantics: Resume must land the worktree on the PR branch's remote tip (the
|
// prepare landed on.
|
||||||
// committed work), not reset to base the way refresh does for a fresh run.
|
func headHash(t *testing.T, dir string) plumbing.Hash {
|
||||||
func TestResumeResetsToBranchTipNotBase(t *testing.T) {
|
t.Helper()
|
||||||
ctx := context.Background()
|
r, err := git.PlainOpen(dir)
|
||||||
host := newLocalRemote(t, "acme", "todo")
|
if err != nil {
|
||||||
m := newManager(t, host)
|
t.Fatalf("PlainOpen(%s): %v", dir, err)
|
||||||
|
}
|
||||||
|
ref, err := r.Head()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Head(%s): %v", dir, err)
|
||||||
|
}
|
||||||
|
return ref.Hash()
|
||||||
|
}
|
||||||
|
|
||||||
dir, branch, err := m.Prepare(ctx, "acme", "todo", testBase, 7, "feat: add widget", "", "feature")
|
// prepareResume models what a task retry starts from: a fresh prepare, a commit
|
||||||
|
// pushed onto the task branch, and the pushed tip. It returns the worktree
|
||||||
|
// directory, branch and tip.
|
||||||
|
func prepareResume(t *testing.T, m *Manager, issue int, title string) (dir, branch string, tip plumbing.Hash) {
|
||||||
|
t.Helper()
|
||||||
|
ctx := context.Background()
|
||||||
|
dir, branch, err := m.Prepare(ctx, "acme", "todo", testBase, issue, title, "", "bug", Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Prepare() error = %v", err)
|
t.Fatalf("Prepare() error = %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit + push work on the branch, so origin/<branch> has widget.go
|
|
||||||
// while base (main) has only README.
|
|
||||||
r, err := git.PlainOpen(dir)
|
r, err := git.PlainOpen(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("PlainOpen: %v", err)
|
t.Fatalf("PlainOpen: %v", err)
|
||||||
@@ -32,51 +43,98 @@ func TestResumeResetsToBranchTipNotBase(t *testing.T) {
|
|||||||
if err := m.Push(ctx, dir, branch); err != nil {
|
if err := m.Push(ctx, dir, branch); err != nil {
|
||||||
t.Fatalf("Push() error = %v", err)
|
t.Fatalf("Push() error = %v", err)
|
||||||
}
|
}
|
||||||
|
return dir, branch, headHash(t, dir)
|
||||||
|
}
|
||||||
|
|
||||||
if err := m.Resume(ctx, dir, branch); err != nil {
|
// TestPrepareResumeLandsOnTheBranchTipNotBase pins the resume target's
|
||||||
t.Fatalf("Resume() error = %v", err)
|
// semantics: it must land the worktree on the PR branch's remote tip (the
|
||||||
|
// committed work), not reset to base the way a fresh prepare does.
|
||||||
|
func TestPrepareResumeLandsOnTheBranchTipNotBase(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
m := newManager(t, newLocalRemote(t, "acme", "todo"))
|
||||||
|
dir, branch, tip := prepareResume(t, m, 7, "feat: add widget")
|
||||||
|
|
||||||
|
if _, _, err := m.Prepare(ctx, "acme", "todo", testBase, 7, "feat: add widget", "", "bug", Target(branch)); err != nil {
|
||||||
|
t.Fatalf("Prepare(resume) error = %v", err)
|
||||||
}
|
}
|
||||||
content, err := os.ReadFile(filepath.Join(dir, "widget.go"))
|
content, err := os.ReadFile(filepath.Join(dir, "widget.go"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("widget.go missing after Resume: %v (resume reset to base and discarded the branch work)", err)
|
t.Fatalf("widget.go missing after resume: %v (resume reset to base and discarded the branch work)", err)
|
||||||
}
|
}
|
||||||
if string(content) != "package widget\n" {
|
if string(content) != "package widget\n" {
|
||||||
t.Fatalf("widget.go = %q, want %q", content, "package widget\n")
|
t.Fatalf("widget.go = %q, want %q", content, "package widget\n")
|
||||||
}
|
}
|
||||||
|
if got := headHash(t, dir); got != tip {
|
||||||
|
t.Fatalf("HEAD = %s, want the branch tip %s", got, tip)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestResumeCleansAbandonedFiles ensures Resume clears untracked residue the
|
// TestPrepareResumeClonesAMissingWorktree is the root-cause test for
|
||||||
// way refresh does, so a prior interrupted remediation cannot leak files into
|
// archie-core-866m: a resume must create the clone when it is missing, so a
|
||||||
// the next run.
|
// retry reaches a task whose worktree the terminal cleanup removed, an expired
|
||||||
func TestResumeCleansAbandonedFiles(t *testing.T) {
|
// volume dropped, or a different host never had.
|
||||||
|
func TestPrepareResumeClonesAMissingWorktree(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
host := newLocalRemote(t, "acme", "todo")
|
m := newManager(t, newLocalRemote(t, "acme", "todo"))
|
||||||
m := newManager(t, host)
|
dir, branch, tip := prepareResume(t, m, 8, "fix: thing")
|
||||||
|
|
||||||
dir, branch, err := m.Prepare(ctx, "acme", "todo", testBase, 8, "fix: thing", "", "bug")
|
if err := os.RemoveAll(dir); err != nil {
|
||||||
|
t.Fatalf("remove worktree: %v", err)
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(filepath.Join(dir, preparedSentinel)); !os.IsNotExist(err) {
|
||||||
|
t.Fatalf("worktree not removed: sentinel stat err = %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
gotDir, gotBranch, err := m.Prepare(ctx, "acme", "todo", testBase, 8, "fix: thing", "", "bug", Target(branch))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Prepare() error = %v", err)
|
t.Fatalf("Prepare(resume) on a missing worktree error = %v, want it cloned", err)
|
||||||
}
|
}
|
||||||
|
if gotDir != dir || gotBranch != branch {
|
||||||
// The branch must be pushed for Resume to resolve origin/<branch>.
|
t.Fatalf("Prepare(resume) = (%q, %q), want (%q, %q)", gotDir, gotBranch, dir, branch)
|
||||||
r, err := git.PlainOpen(dir)
|
}
|
||||||
|
content, err := os.ReadFile(filepath.Join(gotDir, "widget.go"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("PlainOpen: %v", err)
|
t.Fatalf("widget.go missing after resume cloned: %v", err)
|
||||||
}
|
}
|
||||||
writeSeedCommit(t, r, dir, "change.go", "package change\n", "a change")
|
if string(content) != "package widget\n" {
|
||||||
if err := m.Push(ctx, dir, branch); err != nil {
|
t.Fatalf("widget.go = %q, want %q", content, "package widget\n")
|
||||||
t.Fatalf("Push() error = %v", err)
|
|
||||||
}
|
}
|
||||||
|
if got := headHash(t, gotDir); got != tip {
|
||||||
|
t.Fatalf("HEAD = %s, want the branch tip %s", got, tip)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestPrepareResumeFailsClosedWhenTheBranchIsNotPushed pins that a resume
|
||||||
|
// never falls back to base: a branch that is not on the remote is a dispatch
|
||||||
|
// defect, and a base checkout would silently remediate the wrong tree.
|
||||||
|
func TestPrepareResumeFailsClosedWhenTheBranchIsNotPushed(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
m := newManager(t, newLocalRemote(t, "acme", "todo"))
|
||||||
|
dir, _, tip := prepareResume(t, m, 9, "fix: thing")
|
||||||
|
|
||||||
|
if _, _, err := m.Prepare(ctx, "acme", "todo", testBase, 9, "fix: thing", "", "bug", Target("fix/9-never-pushed")); err == nil {
|
||||||
|
t.Fatal("Prepare(resume) with an unpushed branch = nil error, want a fail-closed error")
|
||||||
|
}
|
||||||
|
if got := headHash(t, dir); got != tip {
|
||||||
|
t.Fatalf("HEAD = %s, want the worktree left on the branch tip %s", got, tip)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestPrepareResumeCleansAbandonedFiles ensures a resume clears untracked
|
||||||
|
// residue the way a fresh prepare does, so a prior interrupted run cannot leak
|
||||||
|
// files into the next commit.
|
||||||
|
func TestPrepareResumeCleansAbandonedFiles(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
m := newManager(t, newLocalRemote(t, "acme", "todo"))
|
||||||
|
dir, branch, _ := prepareResume(t, m, 10, "fix: thing")
|
||||||
|
|
||||||
// Untracked residue that a clean run must remove.
|
|
||||||
if err := os.WriteFile(filepath.Join(dir, "scratch.txt"), []byte("junk\n"), 0o600); err != nil {
|
if err := os.WriteFile(filepath.Join(dir, "scratch.txt"), []byte("junk\n"), 0o600); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
if _, _, err := m.Prepare(ctx, "acme", "todo", testBase, 10, "fix: thing", "", "bug", Target(branch)); err != nil {
|
||||||
if err := m.Resume(ctx, dir, branch); err != nil {
|
t.Fatalf("Prepare(resume) error = %v", err)
|
||||||
t.Fatalf("Resume() error = %v", err)
|
|
||||||
}
|
}
|
||||||
if _, err := os.Stat(filepath.Join(dir, "scratch.txt")); !os.IsNotExist(err) {
|
if _, err := os.Stat(filepath.Join(dir, "scratch.txt")); !os.IsNotExist(err) {
|
||||||
t.Errorf("scratch.txt still exists after Resume; untracked residue was not cleaned")
|
t.Errorf("scratch.txt still exists after resume; untracked residue was not cleaned")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -120,70 +120,103 @@ func (m *Manager) signature() *object.Signature {
|
|||||||
return &object.Signature{Name: m.BotUser, Email: m.BotEmail, When: time.Now()}
|
return &object.Signature{Name: m.BotUser, Email: m.BotEmail, When: time.Now()}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare creates a fresh clone for the task and checks out its branch.
|
// Target selects the commit a prepared worktree is positioned at.
|
||||||
// Any leftover worktree from a prior attempt is removed first. If the
|
//
|
||||||
// worktree is already prepared, it is refreshed and reused.
|
// The zero value is Fresh: a run that starts new work is reset onto
|
||||||
|
// origin/<base>. A non-empty Target is a resume: the worktree is reset onto
|
||||||
|
// origin/<that branch>, continuing the work an earlier attempt already pushed.
|
||||||
|
//
|
||||||
|
// The branch travels with the choice rather than being recomputed from the
|
||||||
|
// title, because a resume must land on the branch the open pull request lives
|
||||||
|
// on: a retitled issue would otherwise name a branch that does not exist.
|
||||||
|
//
|
||||||
|
// It is a string rather than a bool or an enum precisely so the branch to
|
||||||
|
// resume onto is carried by the choice; a bool would force a second parameter
|
||||||
|
// and let a caller select a resume without naming what it resumes onto.
|
||||||
|
type Target string
|
||||||
|
|
||||||
|
// Fresh is the fresh-run target: reset onto origin/<base>.
|
||||||
|
const Fresh Target = ""
|
||||||
|
|
||||||
|
// Prepare creates (or reuses) the task's clone and positions it on target,
|
||||||
|
// returning the worktree directory and the branch it is on.
|
||||||
|
//
|
||||||
|
// A missing clone is created for either target. That is what lets a resume
|
||||||
|
// recover a worktree the terminal cleanup, an expired volume or a different
|
||||||
|
// host removed before a retry. Fresh lands it on origin/<base>; a resume lands
|
||||||
|
// it on origin/<branch> and fails closed when that branch is not on the remote
|
||||||
|
// rather than falling back to base.
|
||||||
func (m *Manager) Prepare(
|
func (m *Manager) Prepare(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
owner, repo, base string,
|
owner, repo, base string,
|
||||||
issue int,
|
issue int,
|
||||||
title, body, labels string,
|
title, body, labels string,
|
||||||
|
target Target,
|
||||||
) (dir, branch string, err error) {
|
) (dir, branch string, err error) {
|
||||||
if !ValidCoordinates(owner, repo, issue) {
|
if !ValidCoordinates(owner, repo, issue) {
|
||||||
return "", "", fmt.Errorf("invalid worktree coordinates")
|
return "", "", fmt.Errorf("invalid worktree coordinates")
|
||||||
}
|
}
|
||||||
dir = m.Dir(owner, repo, issue)
|
dir = m.Dir(owner, repo, issue)
|
||||||
branch = archieBranch(issue, title, labels)
|
branch = archieBranch(issue, title, labels)
|
||||||
|
if target != Fresh {
|
||||||
|
branch = string(target)
|
||||||
|
}
|
||||||
|
|
||||||
|
prepared := false
|
||||||
if _, statErr := os.Stat(filepath.Join(dir, preparedSentinel)); statErr == nil {
|
if _, statErr := os.Stat(filepath.Join(dir, preparedSentinel)); statErr == nil {
|
||||||
if err := m.refresh(ctx, dir, base, branch); err != nil {
|
prepared = true
|
||||||
return "", "", err
|
} else {
|
||||||
|
migrated, migrateErr := m.migrateLegacy(owner, repo, issue, dir)
|
||||||
|
if migrateErr != nil {
|
||||||
|
return "", "", migrateErr
|
||||||
}
|
}
|
||||||
return dir, branch, nil
|
prepared = migrated
|
||||||
}
|
|
||||||
if migrated, migrateErr := m.migrateLegacy(owner, repo, issue, dir); migrateErr != nil {
|
|
||||||
return "", "", migrateErr
|
|
||||||
} else if migrated {
|
|
||||||
if err := m.refresh(ctx, dir, base, branch); err != nil {
|
|
||||||
return "", "", err
|
|
||||||
}
|
|
||||||
return dir, branch, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !prepared {
|
||||||
|
if err := m.createClone(ctx, owner, repo, base, dir); err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := m.sync(ctx, dir, base, branch, target); err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
return dir, branch, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// createClone removes whatever sits at dir, clones the task's repository there,
|
||||||
|
// records the bot identity and marks the worktree prepared. Prepare calls it
|
||||||
|
// only for a worktree it could not reuse.
|
||||||
|
func (m *Manager) createClone(ctx context.Context, owner, repo, base, dir string) error {
|
||||||
if err := os.RemoveAll(dir); err != nil {
|
if err := os.RemoveAll(dir); err != nil {
|
||||||
return "", "", fmt.Errorf("clear stale worktree: %w", err)
|
return fmt.Errorf("clear stale worktree: %w", err)
|
||||||
}
|
}
|
||||||
if err := os.MkdirAll(filepath.Dir(dir), 0o755); err != nil {
|
if err := os.MkdirAll(filepath.Dir(dir), 0o755); err != nil {
|
||||||
return "", "", fmt.Errorf("create worktree parent: %w", err)
|
return fmt.Errorf("create worktree parent: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := git.PlainCloneContext(ctx, dir, &git.CloneOptions{
|
r, err := git.PlainCloneContext(ctx, dir, &git.CloneOptions{
|
||||||
URL: m.cloneURL(owner, repo),
|
URL: m.cloneURL(owner, repo),
|
||||||
ClientOptions: m.auth(),
|
ClientOptions: m.auth(),
|
||||||
ReferenceName: plumbing.NewBranchReferenceName(base),
|
ReferenceName: plumbing.NewBranchReferenceName(base),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", fmt.Errorf("clone %s/%s: %w", owner, repo, err)
|
return fmt.Errorf("clone %s/%s: %w", owner, repo, err)
|
||||||
}
|
}
|
||||||
if err := m.setIdentity(r); err != nil {
|
if err := m.setIdentity(r); err != nil {
|
||||||
return "", "", err
|
return err
|
||||||
}
|
}
|
||||||
|
return writeSentinel(dir)
|
||||||
|
}
|
||||||
|
|
||||||
wt, err := r.Worktree()
|
// sync positions an already-prepared worktree: Fresh resets it onto
|
||||||
if err != nil {
|
// origin/<base>; a resume resets it onto origin/<branch>. Both fetch first and
|
||||||
return "", "", fmt.Errorf("open worktree: %w", err)
|
// clear the worktree against the target tree before committing to it.
|
||||||
|
func (m *Manager) sync(ctx context.Context, dir, base, branch string, target Target) error {
|
||||||
|
if target == Fresh {
|
||||||
|
return m.refresh(ctx, dir, base, branch)
|
||||||
}
|
}
|
||||||
if err := wt.Checkout(&git.CheckoutOptions{
|
return m.resume(ctx, dir, branch)
|
||||||
Branch: plumbing.NewBranchReferenceName(branch),
|
|
||||||
Create: true,
|
|
||||||
}); err != nil {
|
|
||||||
return "", "", fmt.Errorf("create branch %s: %w", branch, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := writeSentinel(dir); err != nil {
|
|
||||||
return "", "", err
|
|
||||||
}
|
|
||||||
return dir, branch, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) legacyDir(owner, repo string, issue int) string {
|
func (m *Manager) legacyDir(owner, repo string, issue int) string {
|
||||||
@@ -256,12 +289,13 @@ func (m *Manager) refresh(ctx context.Context, dir, base, branch string) error {
|
|||||||
return resetOnto(r, dir, branch, baseHash, remoteBase(base))
|
return resetOnto(r, dir, branch, baseHash, remoteBase(base))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resume re-syncs an already-prepared worktree onto its branch's remote tip
|
// resume re-syncs an already-prepared worktree onto its branch's remote tip
|
||||||
// without resetting to base, so the remediate workflow can continue work on
|
// without resetting to base, so a remediation can continue work on the PR
|
||||||
// the PR branch the implement run already pushed. It is refresh's complement:
|
// branch an earlier attempt already pushed. It is refresh's complement: refresh
|
||||||
// refresh resets to origin/<base> for a fresh run; Resume resets to
|
// resets to origin/<base> for a fresh run; resume resets to origin/<branch> so
|
||||||
// origin/<branch> so the committed PR work survives.
|
// the committed PR work survives. It is reached through Prepare's Target, and
|
||||||
func (m *Manager) Resume(ctx context.Context, dir, branch string) error {
|
// the worktree it opens is one Prepare has already cloned when it was missing.
|
||||||
|
func (m *Manager) resume(ctx context.Context, dir, branch string) error {
|
||||||
r, err := git.PlainOpen(dir)
|
r, err := git.PlainOpen(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("open prepared worktree: %w", err)
|
return fmt.Errorf("open prepared worktree: %w", err)
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ func TestPushSucceedsWhenPostPublicationMetadataFails(t *testing.T) {
|
|||||||
m.Log = slog.New(logs)
|
m.Log = slog.New(logs)
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, branch, err := m.Prepare(ctx, "acme", "push-test", testBase, tc.issue, tc.title, "", tc.labels)
|
dir, branch, err := m.Prepare(ctx, "acme", "push-test", testBase, tc.issue, tc.title, "", tc.labels, Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Prepare() error = %v", err)
|
t.Fatalf("Prepare() error = %v", err)
|
||||||
}
|
}
|
||||||
@@ -178,7 +178,7 @@ func TestRecordUpstreamErrorPaths(t *testing.T) {
|
|||||||
host := newLocalRemote(t, "acme", "record-upstream")
|
host := newLocalRemote(t, "acme", "record-upstream")
|
||||||
m := newManager(t, host)
|
m := newManager(t, host)
|
||||||
|
|
||||||
dir, branch, err := m.Prepare(ctx, "acme", "record-upstream", testBase, 105, "feat: record upstream", "", "feature")
|
dir, branch, err := m.Prepare(ctx, "acme", "record-upstream", testBase, 105, "feat: record upstream", "", "feature", Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Prepare() error = %v", err)
|
t.Fatalf("Prepare() error = %v", err)
|
||||||
}
|
}
|
||||||
@@ -229,7 +229,7 @@ func TestCommitAllHonoursCancellation(t *testing.T) {
|
|||||||
host := newLocalRemote(t, "acme", "cancel-test")
|
host := newLocalRemote(t, "acme", "cancel-test")
|
||||||
m := newManager(t, host)
|
m := newManager(t, host)
|
||||||
|
|
||||||
dir, _, err := m.Prepare(ctx, "acme", "cancel-test", testBase, 201, "feat: cancel test", "", "feature")
|
dir, _, err := m.Prepare(ctx, "acme", "cancel-test", testBase, 201, "feat: cancel test", "", "feature", Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Prepare() error = %v", err)
|
t.Fatalf("Prepare() error = %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ func TestPrepareCommitPushRoundTrip(t *testing.T) {
|
|||||||
host := newLocalRemote(t, "acme", "todo")
|
host := newLocalRemote(t, "acme", "todo")
|
||||||
m := newManager(t, host)
|
m := newManager(t, host)
|
||||||
|
|
||||||
dir, branch, err := m.Prepare(ctx, "acme", "todo", testBase, 7, "feat: add widget", "", "feature")
|
dir, branch, err := m.Prepare(ctx, "acme", "todo", testBase, 7, "feat: add widget", "", "feature", Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Prepare() error = %v", err)
|
t.Fatalf("Prepare() error = %v", err)
|
||||||
}
|
}
|
||||||
@@ -194,7 +194,7 @@ func TestPrepareIsIdempotent(t *testing.T) {
|
|||||||
host := newLocalRemote(t, "acme", "todo")
|
host := newLocalRemote(t, "acme", "todo")
|
||||||
m := newManager(t, host)
|
m := newManager(t, host)
|
||||||
|
|
||||||
dir1, branch1, err := m.Prepare(ctx, "acme", "todo", testBase, 3, "fix: thing", "", "bug")
|
dir1, branch1, err := m.Prepare(ctx, "acme", "todo", testBase, 3, "fix: thing", "", "bug", Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("first Prepare() error = %v", err)
|
t.Fatalf("first Prepare() error = %v", err)
|
||||||
}
|
}
|
||||||
@@ -205,7 +205,7 @@ func TestPrepareIsIdempotent(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dir2, branch2, err := m.Prepare(ctx, "acme", "todo", testBase, 3, "fix: thing", "", "bug")
|
dir2, branch2, err := m.Prepare(ctx, "acme", "todo", testBase, 3, "fix: thing", "", "bug", Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("second Prepare() error = %v", err)
|
t.Fatalf("second Prepare() error = %v", err)
|
||||||
}
|
}
|
||||||
@@ -260,7 +260,7 @@ func TestPrepareRecoversFromADirtyWorktreeOnRetry(t *testing.T) {
|
|||||||
}
|
}
|
||||||
m := newManager(t, host)
|
m := newManager(t, host)
|
||||||
|
|
||||||
dir, branch, err := m.Prepare(ctx, "acme", "todo", testBase, 9, "fix: retry robustness", "", "bug")
|
dir, branch, err := m.Prepare(ctx, "acme", "todo", testBase, 9, "fix: retry robustness", "", "bug", Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("first Prepare() error = %v", err)
|
t.Fatalf("first Prepare() error = %v", err)
|
||||||
}
|
}
|
||||||
@@ -280,7 +280,7 @@ func TestPrepareRecoversFromADirtyWorktreeOnRetry(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dir2, branch2, err := m.Prepare(ctx, "acme", "todo", testBase, 9, "fix: retry robustness", "", "bug")
|
dir2, branch2, err := m.Prepare(ctx, "acme", "todo", testBase, 9, "fix: retry robustness", "", "bug", Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("retry Prepare() on a dirty worktree error = %v, want recovery", err)
|
t.Fatalf("retry Prepare() on a dirty worktree error = %v, want recovery", err)
|
||||||
}
|
}
|
||||||
@@ -384,13 +384,13 @@ func TestPrepareRecoversFromAPathTypeConflictOnRetry(t *testing.T) {
|
|||||||
seedTrackedPath(t, host, "pkg/a.txt", "a\n")
|
seedTrackedPath(t, host, "pkg/a.txt", "a\n")
|
||||||
m := newManager(t, host)
|
m := newManager(t, host)
|
||||||
|
|
||||||
dir, branch, err := m.Prepare(ctx, "acme", "todo", testBase, 21, "fix: path type conflict", "", "bug")
|
dir, branch, err := m.Prepare(ctx, "acme", "todo", testBase, 21, "fix: path type conflict", "", "bug", Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("first Prepare() error = %v", err)
|
t.Fatalf("first Prepare() error = %v", err)
|
||||||
}
|
}
|
||||||
c.wreck(t, dir)
|
c.wreck(t, dir)
|
||||||
|
|
||||||
dir2, branch2, err := m.Prepare(ctx, "acme", "todo", testBase, 21, "fix: path type conflict", "", "bug")
|
dir2, branch2, err := m.Prepare(ctx, "acme", "todo", testBase, 21, "fix: path type conflict", "", "bug", Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("retry Prepare() over a path type conflict error = %v, want recovery", err)
|
t.Fatalf("retry Prepare() over a path type conflict error = %v, want recovery", err)
|
||||||
}
|
}
|
||||||
@@ -439,7 +439,7 @@ func TestPrepareCreatesTheBranchWhenItIsGenuinelyMissing(t *testing.T) {
|
|||||||
host := newLocalRemote(t, "acme", "todo")
|
host := newLocalRemote(t, "acme", "todo")
|
||||||
m := newManager(t, host)
|
m := newManager(t, host)
|
||||||
|
|
||||||
dir, _, err := m.Prepare(ctx, "acme", "todo", testBase, 22, "fix: first title", "", "bug")
|
dir, _, err := m.Prepare(ctx, "acme", "todo", testBase, 22, "fix: first title", "", "bug", Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("first Prepare() error = %v", err)
|
t.Fatalf("first Prepare() error = %v", err)
|
||||||
}
|
}
|
||||||
@@ -452,7 +452,7 @@ func TestPrepareCreatesTheBranchWhenItIsGenuinelyMissing(t *testing.T) {
|
|||||||
t.Fatalf("remove branch %s: %v", first, err)
|
t.Fatalf("remove branch %s: %v", first, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, branch, err := m.Prepare(ctx, "acme", "todo", testBase, 22, "fix: renamed title", "", "bug")
|
_, branch, err := m.Prepare(ctx, "acme", "todo", testBase, 22, "fix: renamed title", "", "bug", Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Prepare() after the branch was removed error = %v, want it created", err)
|
t.Fatalf("Prepare() after the branch was removed error = %v, want it created", err)
|
||||||
}
|
}
|
||||||
@@ -506,7 +506,7 @@ func TestCleanUntrackedHandlesGitdirFile(t *testing.T) {
|
|||||||
host := newLocalRemote(t, "acme", "todo")
|
host := newLocalRemote(t, "acme", "todo")
|
||||||
m := newManager(t, host)
|
m := newManager(t, host)
|
||||||
|
|
||||||
dir, _, err := m.Prepare(ctx, "acme", "todo", testBase, 12, "fix: gitdir file", "", "bug")
|
dir, _, err := m.Prepare(ctx, "acme", "todo", testBase, 12, "fix: gitdir file", "", "bug", Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Prepare() error = %v", err)
|
t.Fatalf("Prepare() error = %v", err)
|
||||||
}
|
}
|
||||||
@@ -591,7 +591,7 @@ func TestPrepareDiscardsDirectoryWithoutSentinel(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, _, err := m.Prepare(ctx, "acme", "todo", testBase, 11, "chore: retry", "", "chore"); err != nil {
|
if _, _, err := m.Prepare(ctx, "acme", "todo", testBase, 11, "chore: retry", "", "chore", Fresh); err != nil {
|
||||||
t.Fatalf("Prepare() error = %v", err)
|
t.Fatalf("Prepare() error = %v", err)
|
||||||
}
|
}
|
||||||
if _, err := os.Stat(junk); !os.IsNotExist(err) {
|
if _, err := os.Stat(junk); !os.IsNotExist(err) {
|
||||||
@@ -619,7 +619,7 @@ func TestPrepareErrors(t *testing.T) {
|
|||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
m := newManager(t, tc.host)
|
m := newManager(t, tc.host)
|
||||||
_, _, err := m.Prepare(context.Background(), tc.owner, tc.repo, tc.base, 1, "t", "", "")
|
_, _, err := m.Prepare(context.Background(), tc.owner, tc.repo, tc.base, 1, "t", "", "", Fresh)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("Prepare() error = nil, want a failure")
|
t.Fatal("Prepare() error = nil, want a failure")
|
||||||
}
|
}
|
||||||
@@ -631,10 +631,10 @@ func TestPrepareRefreshRejectsUnknownBase(t *testing.T) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
host := newLocalRemote(t, "acme", "todo")
|
host := newLocalRemote(t, "acme", "todo")
|
||||||
m := newManager(t, host)
|
m := newManager(t, host)
|
||||||
if _, _, err := m.Prepare(ctx, "acme", "todo", testBase, 12, "fix: base", "", "bug"); err != nil {
|
if _, _, err := m.Prepare(ctx, "acme", "todo", testBase, 12, "fix: base", "", "bug", Fresh); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if _, _, err := m.Prepare(ctx, "acme", "todo", "missing-base", 12, "fix: base", "", "bug"); err == nil {
|
if _, _, err := m.Prepare(ctx, "acme", "todo", "missing-base", 12, "fix: base", "", "bug", Fresh); err == nil {
|
||||||
t.Fatal("prepared worktree accepted an unknown base")
|
t.Fatal("prepared worktree accepted an unknown base")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -682,7 +682,7 @@ func TestSnapshotExportsTrackedFilesWithoutGit(t *testing.T) {
|
|||||||
host := newLocalRemote(t, "acme", "todo")
|
host := newLocalRemote(t, "acme", "todo")
|
||||||
m := newManager(t, host)
|
m := newManager(t, host)
|
||||||
|
|
||||||
dir, _, err := m.Prepare(ctx, "acme", "todo", testBase, 9, "feat: snapshot me", "", "feature")
|
dir, _, err := m.Prepare(ctx, "acme", "todo", testBase, 9, "feat: snapshot me", "", "feature", Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Prepare() error = %v", err)
|
t.Fatalf("Prepare() error = %v", err)
|
||||||
}
|
}
|
||||||
@@ -718,7 +718,7 @@ func TestDiffUsesMergeBaseNotRemoteTip(t *testing.T) {
|
|||||||
host := newLocalRemote(t, "acme", "todo")
|
host := newLocalRemote(t, "acme", "todo")
|
||||||
m := newManager(t, host)
|
m := newManager(t, host)
|
||||||
|
|
||||||
dir, _, err := m.Prepare(ctx, "acme", "todo", testBase, 5, "feat: mine", "", "feature")
|
dir, _, err := m.Prepare(ctx, "acme", "todo", testBase, 5, "feat: mine", "", "feature", Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Prepare() error = %v", err)
|
t.Fatalf("Prepare() error = %v", err)
|
||||||
}
|
}
|
||||||
@@ -771,7 +771,7 @@ func TestDiffOperationsRejectUnrelatedBaseHistory(t *testing.T) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
host := newLocalRemote(t, "acme", "todo")
|
host := newLocalRemote(t, "acme", "todo")
|
||||||
m := newManager(t, host)
|
m := newManager(t, host)
|
||||||
dir, _, err := m.Prepare(ctx, "acme", "todo", testBase, 6, "feat: task", "", "feature")
|
dir, _, err := m.Prepare(ctx, "acme", "todo", testBase, 6, "feat: task", "", "feature", Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -886,7 +886,7 @@ func TestPushWithoutTokenOverHTTPFailsWithClearMessage(t *testing.T) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
host := newLocalRemote(t, "acme", "todo")
|
host := newLocalRemote(t, "acme", "todo")
|
||||||
seeder := newManager(t, host)
|
seeder := newManager(t, host)
|
||||||
dir, branch, err := seeder.Prepare(ctx, "acme", "todo", testBase, 1, "t", "", "")
|
dir, branch, err := seeder.Prepare(ctx, "acme", "todo", testBase, 1, "t", "", "", Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Prepare() error = %v", err)
|
t.Fatalf("Prepare() error = %v", err)
|
||||||
}
|
}
|
||||||
@@ -973,7 +973,7 @@ func TestPrepareMigratesMatchingLegacyWorktree(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, _, err := m.Prepare(ctx, "acme", "todo", testBase, 44, "feat: migrate", "", "feature")
|
dir, _, err := m.Prepare(ctx, "acme", "todo", testBase, 44, "feat: migrate", "", "feature", Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -1008,7 +1008,7 @@ func TestPreparePreservesMismatchedLegacyWorktree(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, _, err := m.Prepare(ctx, "acme", "todo", testBase, 45, "feat: safe migration", "", "feature"); err != nil {
|
if _, _, err := m.Prepare(ctx, "acme", "todo", testBase, 45, "feat: safe migration", "", "feature", Fresh); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if _, err := os.Stat(marker); err != nil {
|
if _, err := os.Stat(marker); err != nil {
|
||||||
@@ -1059,7 +1059,7 @@ func TestSentinelIsNeverCommitted(t *testing.T) {
|
|||||||
host := newLocalRemote(t, "acme", "todo")
|
host := newLocalRemote(t, "acme", "todo")
|
||||||
m := newManager(t, host)
|
m := newManager(t, host)
|
||||||
|
|
||||||
dir, _, err := m.Prepare(ctx, "acme", "todo", testBase, 21, "feat: thing", "", "feature")
|
dir, _, err := m.Prepare(ctx, "acme", "todo", testBase, 21, "feat: thing", "", "feature", Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Prepare() error = %v", err)
|
t.Fatalf("Prepare() error = %v", err)
|
||||||
}
|
}
|
||||||
@@ -1097,7 +1097,7 @@ func TestTaskBriefIsNeverCommitted(t *testing.T) {
|
|||||||
host := newLocalRemote(t, "acme", "todo")
|
host := newLocalRemote(t, "acme", "todo")
|
||||||
m := newManager(t, host)
|
m := newManager(t, host)
|
||||||
|
|
||||||
dir, _, err := m.Prepare(ctx, "acme", "todo", testBase, 22, "feat: brief", "", "feature")
|
dir, _, err := m.Prepare(ctx, "acme", "todo", testBase, 22, "feat: brief", "", "feature", Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Prepare() error = %v", err)
|
t.Fatalf("Prepare() error = %v", err)
|
||||||
}
|
}
|
||||||
@@ -1397,7 +1397,7 @@ func TestChangedFileStatsRecordsTheDiffedBaseNotTheAdvancedTip(t *testing.T) {
|
|||||||
host := newLocalRemote(t, "acme", "todo")
|
host := newLocalRemote(t, "acme", "todo")
|
||||||
m := newManager(t, host)
|
m := newManager(t, host)
|
||||||
|
|
||||||
dir, _, err := m.Prepare(ctx, "acme", "todo", testBase, 8, "feat: mine", "", "feature")
|
dir, _, err := m.Prepare(ctx, "acme", "todo", testBase, 8, "feat: mine", "", "feature", Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Prepare() error = %v", err)
|
t.Fatalf("Prepare() error = %v", err)
|
||||||
}
|
}
|
||||||
@@ -1473,7 +1473,7 @@ func TestHasUncommittedChangesReportsWorkNoCommitHasCaptured(t *testing.T) {
|
|||||||
host := newLocalRemote(t, "acme", "todo")
|
host := newLocalRemote(t, "acme", "todo")
|
||||||
m := newManager(t, host)
|
m := newManager(t, host)
|
||||||
|
|
||||||
dir, _, err := m.Prepare(ctx, "acme", "todo", testBase, 7, "feat: mine", "", "feature")
|
dir, _, err := m.Prepare(ctx, "acme", "todo", testBase, 7, "feat: mine", "", "feature", Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Prepare() error = %v", err)
|
t.Fatalf("Prepare() error = %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ func TestManagerPrepareCannotDeleteOutsideWorkDir(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m := &worktree.Manager{WorkDir: workDir, BaseURL: t.TempDir()}
|
m := &worktree.Manager{WorkDir: workDir, BaseURL: t.TempDir()}
|
||||||
_, _, _ = m.Prepare(ctx, "../escape", "widget", "main", 7, "feat: test", "", "")
|
_, _, _ = m.Prepare(ctx, "../escape", "widget", "main", 7, "feat: test", "", "", worktree.Fresh)
|
||||||
if _, err := os.Stat(marker); err != nil {
|
if _, err := os.Stat(marker); err != nil {
|
||||||
t.Fatalf("Prepare removed a path outside WorkDir: %v", err)
|
t.Fatalf("Prepare removed a path outside WorkDir: %v", err)
|
||||||
}
|
}
|
||||||
@@ -140,7 +140,7 @@ func TestClientPushRejectsTaskMismatchedCoordinates(t *testing.T) {
|
|||||||
BotEmail: "archie-bot@example.com",
|
BotEmail: "archie-bot@example.com",
|
||||||
BaseURL: host,
|
BaseURL: host,
|
||||||
}
|
}
|
||||||
dir, branch, err := m.Prepare(ctx, "other", "widget", "main", 9, "feat: other", "", "")
|
dir, branch, err := m.Prepare(ctx, "other", "widget", "main", 9, "feat: other", "", "", worktree.Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -181,7 +181,7 @@ func TestClientPushPublishesViaServer(t *testing.T) {
|
|||||||
BaseURL: host,
|
BaseURL: host,
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, branch, err := m.Prepare(ctx, "acme", "widget", "main", 1, "feat: test", "", "")
|
dir, branch, err := m.Prepare(ctx, "acme", "widget", "main", 1, "feat: test", "", "", worktree.Fresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("prepare: %v", err)
|
t.Fatalf("prepare: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user