Files
kandev/apps/backend/internal/agent/lifecycle/env_preparer_sprites_test.go
T
José Almeida 9012698172 feat(sprites,docker): generate a kandev feature branch for clone-based executors
Sprites tasks committed straight onto the chosen base branch because
SpritesPreparer didn't populate WorktreeBranch and the orchestrator's
"forward env.WorktreeBranch on reuse" check only fired for Docker.

Mirror the Docker preparer's TaskBranchName generation in Sprites,
extract a shared `nonWorktreeTaskBranch` helper that uses a
deterministic suffix derived from the task ID (so legacy env rows that
predate this change resolve to the same branch on every resume), and
let the orchestrator forward env.WorktreeBranch for any clone-based
executor — Docker or Sprites.
2026-05-05 22:26:42 +01:00

71 lines
2.2 KiB
Go

package lifecycle
import (
"context"
"strings"
"testing"
"github.com/kandev/kandev/internal/agent/executor"
)
func TestSpritesPreparer_GeneratesDeterministicTaskBranch(t *testing.T) {
preparer := NewSpritesPreparer(newTestLogger())
first, err := preparer.Prepare(context.Background(), &EnvPrepareRequest{
TaskID: "task-abc-123",
SessionID: "session-1",
TaskTitle: "Sprite Branch Fix",
ExecutorType: executor.NameSprites,
WorkspacePath: "/workspace",
BaseBranch: "main",
WorktreeBranchPrefix: "feature/",
}, nil)
if err != nil {
t.Fatalf("Prepare: %v", err)
}
if first.WorktreeBranch == "" {
t.Fatal("expected Sprites preparer to populate WorktreeBranch")
}
if !strings.HasPrefix(first.WorktreeBranch, "feature/sprite-branch-fix-") {
t.Fatalf("WorktreeBranch = %q, want feature/sprite-branch-fix-*", first.WorktreeBranch)
}
// Re-running with the same task fields must yield the same branch so
// resumes (legacy env rows with empty worktree_branch) don't churn.
second, err := preparer.Prepare(context.Background(), &EnvPrepareRequest{
TaskID: "task-abc-123",
SessionID: "session-2",
TaskTitle: "Sprite Branch Fix",
ExecutorType: executor.NameSprites,
WorkspacePath: "/workspace",
BaseBranch: "main",
WorktreeBranchPrefix: "feature/",
}, nil)
if err != nil {
t.Fatalf("Prepare (second call): %v", err)
}
if second.WorktreeBranch != first.WorktreeBranch {
t.Fatalf("non-deterministic branch: first=%q second=%q", first.WorktreeBranch, second.WorktreeBranch)
}
}
func TestSpritesPreparer_ReusesExistingTaskBranch(t *testing.T) {
preparer := NewSpritesPreparer(newTestLogger())
result, err := preparer.Prepare(context.Background(), &EnvPrepareRequest{
TaskID: "task-abc-123",
SessionID: "session-1",
TaskTitle: "Sprite Branch Fix",
ExecutorType: executor.NameSprites,
WorkspacePath: "/workspace",
BaseBranch: "main",
WorktreeBranch: "feature/already-set-xyz",
}, nil)
if err != nil {
t.Fatalf("Prepare: %v", err)
}
if result.WorktreeBranch != "feature/already-set-xyz" {
t.Fatalf("WorktreeBranch = %q, want existing branch passthrough", result.WorktreeBranch)
}
}