rdev/internal/sdlc/paths_test.go
jordan 425ef0f806 feat: add SDLC orchestration - library, CLI, and API integration
Implements deterministic feature lifecycle management for agent-driven
development. Agents use the CLI in pods; operators control via REST API.

Library (internal/sdlc/):
- Feature lifecycle with 10 phases (draft → released)
- Classifier engine with priority-ordered rules
- Artifact tracking with approval workflow
- Task management within features
- YAML-based state persistence

CLI (cmd/sdlc/):
- init, state, next, feature, artifact, task, query commands
- --json flag for machine-readable output
- Runs inside project pods

API (21 endpoints under /projects/{id}/sdlc/):
- State: GET /state, GET /next
- Features: CRUD + transition/block/unblock
- Artifacts: approve/reject per type
- Tasks: add/start/complete/block
- Queries: blocked/ready/needs-approval

Architecture:
- Port: SDLCExecutor interface (internal/port/)
- Adapter: kubectl exec into pods (internal/adapter/kubernetes/)
- Service: pod resolution + logging (internal/service/)
- Handlers: 5 files under 500-line limit (internal/handlers/)

Also includes template upgrades (chassis framework, UI components,
OpenAPI helpers, backend/frontend guides) and component improvements.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 09:57:05 -07:00

115 lines
2.9 KiB
Go

package sdlc
import (
"path/filepath"
"testing"
)
func TestStatePath(t *testing.T) {
got := StatePath("/project")
want := filepath.Join("/project", ".sdlc", "state.yaml")
if got != want {
t.Errorf("StatePath = %q, want %q", got, want)
}
}
func TestConfigPath(t *testing.T) {
got := ConfigPath("/project")
want := filepath.Join("/project", ".sdlc", "config.yaml")
if got != want {
t.Errorf("ConfigPath = %q, want %q", got, want)
}
}
func TestFeatureDir(t *testing.T) {
got := FeatureDir("/project", "auth")
want := filepath.Join("/project", ".sdlc", "features", "auth")
if got != want {
t.Errorf("FeatureDir = %q, want %q", got, want)
}
}
func TestManifestPath(t *testing.T) {
got := ManifestPath("/project", "auth")
want := filepath.Join("/project", ".sdlc", "features", "auth", "manifest.yaml")
if got != want {
t.Errorf("ManifestPath = %q, want %q", got, want)
}
}
func TestArtifactPath(t *testing.T) {
tests := []struct {
artifact ArtifactType
wantFile string
}{
{ArtifactSpec, "spec.md"},
{ArtifactDesign, "design.md"},
{ArtifactTasks, "tasks.md"},
{ArtifactQAPlan, "qa-plan.md"},
{ArtifactReview, "review.md"},
{ArtifactAudit, "audit.md"},
{ArtifactQAResults, "qa-results.md"},
}
for _, tt := range tests {
got := ArtifactPath("/project", "auth", tt.artifact)
want := filepath.Join("/project", ".sdlc", "features", "auth", tt.wantFile)
if got != want {
t.Errorf("ArtifactPath(%q) = %q, want %q", tt.artifact, got, want)
}
}
}
func TestArtifactPathInvalid(t *testing.T) {
got := ArtifactPath("/project", "auth", ArtifactType("bogus"))
if got != "" {
t.Errorf("ArtifactPath(bogus) = %q, want empty", got)
}
}
func TestValidateSlug(t *testing.T) {
valid := []string{"auth", "user-auth", "a1", "my-feature-2"}
for _, s := range valid {
if err := ValidateSlug(s); err != nil {
t.Errorf("ValidateSlug(%q) = %v, want nil", s, err)
}
}
invalid := []string{"", "Auth", "UPPER", "123start", "has spaces", "has_underscores", "-leading"}
for _, s := range invalid {
if err := ValidateSlug(s); err == nil {
t.Errorf("ValidateSlug(%q) = nil, want error", s)
}
}
}
func TestPhaseIndex(t *testing.T) {
if i := PhaseIndex(PhaseDraft); i != 0 {
t.Errorf("PhaseIndex(draft) = %d, want 0", i)
}
if i := PhaseIndex(PhaseReleased); i != 9 {
t.Errorf("PhaseIndex(released) = %d, want 9", i)
}
if i := PhaseIndex("bogus"); i != -1 {
t.Errorf("PhaseIndex(bogus) = %d, want -1", i)
}
}
func TestIsValidPhase(t *testing.T) {
if !IsValidPhase(PhaseDraft) {
t.Error("IsValidPhase(draft) = false, want true")
}
if IsValidPhase("bogus") {
t.Error("IsValidPhase(bogus) = true, want false")
}
}
func TestIsValidArtifactType(t *testing.T) {
if !IsValidArtifactType(ArtifactSpec) {
t.Error("IsValidArtifactType(spec) = false, want true")
}
if IsValidArtifactType("bogus") {
t.Error("IsValidArtifactType(bogus) = true, want false")
}
}