- Add projectsync package with checkout logic and tests - Integrate project sync into server initialization - Update HTTP handlers and middleware for project sync endpoints - Update workitempipeline service with project sync support - Migrate task documents to archive structure with standardized naming
76 lines
2.4 KiB
Go
76 lines
2.4 KiB
Go
package projectsync
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func validCheckoutConfig() Config {
|
|
return Config{
|
|
Target: ProviderProjectTarget{
|
|
Provider: "plane",
|
|
Tenant: "general",
|
|
Project: "project-1",
|
|
},
|
|
GitRemoteURL: "git@example.com:org/nomadcode.git",
|
|
SourceBranch: "develop",
|
|
WorkspaceID: "ws-main",
|
|
WorkspaceBasePath: "/home/user/workspace",
|
|
RepoDirName: "nomadcode",
|
|
}
|
|
}
|
|
|
|
func TestBuildCheckoutPlanDefaultSlotUsesZeroPaddedPath(t *testing.T) {
|
|
plan, err := BuildCheckoutPlan(validCheckoutConfig(), WorkspaceSlot{Index: DefaultSlotIndex})
|
|
if err != nil {
|
|
t.Fatalf("BuildCheckoutPlan returned error: %v", err)
|
|
}
|
|
if plan.RemoteURL != "git@example.com:org/nomadcode.git" {
|
|
t.Errorf("remote: got %q", plan.RemoteURL)
|
|
}
|
|
if plan.SourceBranch != "develop" {
|
|
t.Errorf("source branch: got %q", plan.SourceBranch)
|
|
}
|
|
if plan.ProjectWorkspaceRoot != "/home/user/workspace/nomadcode" {
|
|
t.Errorf("project root: got %q", plan.ProjectWorkspaceRoot)
|
|
}
|
|
if plan.SlotPath != "/home/user/workspace/nomadcode/000" {
|
|
t.Errorf("slot path: got %q", plan.SlotPath)
|
|
}
|
|
if plan.SlotIndex != DefaultSlotIndex {
|
|
t.Errorf("slot index: got %d", plan.SlotIndex)
|
|
}
|
|
}
|
|
|
|
func TestBuildCheckoutPlanParallelSlotKeepsRemoteAndIncrementsPath(t *testing.T) {
|
|
plan, err := BuildCheckoutPlan(validCheckoutConfig(), WorkspaceSlot{Index: SlotIndex(1)})
|
|
if err != nil {
|
|
t.Fatalf("BuildCheckoutPlan returned error: %v", err)
|
|
}
|
|
// Parallel slot keeps the same remote/branch but gets an independent path.
|
|
if plan.RemoteURL != "git@example.com:org/nomadcode.git" {
|
|
t.Errorf("remote: got %q", plan.RemoteURL)
|
|
}
|
|
if plan.SourceBranch != "develop" {
|
|
t.Errorf("source branch: got %q", plan.SourceBranch)
|
|
}
|
|
if plan.SlotPath != "/home/user/workspace/nomadcode/001" {
|
|
t.Errorf("slot path: got %q", plan.SlotPath)
|
|
}
|
|
}
|
|
|
|
func TestBuildCheckoutPlanRejectsInvalidConfig(t *testing.T) {
|
|
bad := validCheckoutConfig()
|
|
bad.GitRemoteURL = ""
|
|
if _, err := BuildCheckoutPlan(bad, WorkspaceSlot{Index: DefaultSlotIndex}); !errors.Is(err, ErrInvalidConfig) {
|
|
t.Fatalf("expected ErrInvalidConfig, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestBuildCheckoutPlanRejectsInvalidSlotIndex(t *testing.T) {
|
|
for _, index := range []SlotIndex{-1, MaxSlotIndex + 1} {
|
|
if _, err := BuildCheckoutPlan(validCheckoutConfig(), WorkspaceSlot{Index: index}); !errors.Is(err, ErrInvalidConfig) {
|
|
t.Errorf("index %d: expected ErrInvalidConfig, got %v", index, err)
|
|
}
|
|
}
|
|
}
|