Coverage: agentic 40.1% → 54.3%, setup 71.5% → 75.8% Total: 695 passing tests across all packages (was ~357) New test files (15): - commands_forge_test.go — parseForgeArgs, fmtIndex - commands_workspace_test.go — extractField (9 cases) - commands_test.go — command registration + Core integration - handlers_test.go — RegisterHandlers, IPC pipeline, lifecycle - plan_crud_test.go — full CRUD via MCP handlers (23 tests) - prep_extra_test.go — buildPrompt, findConsumersList, pullWikiContent, getIssueBody - queue_extra_test.go — ConcurrencyLimit YAML, delayForAgent, drainOne - remote_client_test.go — mcpInitialize, mcpCall, readSSEData, setHeaders - remote_test.go — resolveHost, remoteToken - resume_test.go — resume dry run, agent override, validation - review_queue_test.go — countFindings, parseRetryAfter, buildAutoPRBody - review_queue_extra_test.go — buildReviewCommand, rateLimitState, reviewQueue - verify_extra_test.go — attemptVerifyAndMerge, autoVerifyAndMerge pipeline - watch_test.go — findActiveWorkspaces, resolveWorkspaceDir - setup/setup_extra_test.go — defaultBuildCommand, defaultTestCommand all branches Co-Authored-By: Virgil <virgil@lethean.io>
85 lines
2.3 KiB
Go
85 lines
2.3 KiB
Go
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
package agentic
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// --- resolveWorkspaceDir ---
|
|
|
|
func TestResolveWorkspaceDir_Good_RelativeName(t *testing.T) {
|
|
s := &PrepSubsystem{
|
|
backoff: make(map[string]time.Time),
|
|
failCount: make(map[string]int),
|
|
}
|
|
dir := s.resolveWorkspaceDir("go-io-abc123")
|
|
assert.Contains(t, dir, "go-io-abc123")
|
|
assert.True(t, filepath.IsAbs(dir))
|
|
}
|
|
|
|
func TestResolveWorkspaceDir_Good_AbsolutePath(t *testing.T) {
|
|
s := &PrepSubsystem{
|
|
backoff: make(map[string]time.Time),
|
|
failCount: make(map[string]int),
|
|
}
|
|
abs := "/some/absolute/path"
|
|
assert.Equal(t, abs, s.resolveWorkspaceDir(abs))
|
|
}
|
|
|
|
// --- findActiveWorkspaces ---
|
|
|
|
func TestFindActiveWorkspaces_Good_WithActive(t *testing.T) {
|
|
root := t.TempDir()
|
|
t.Setenv("CORE_WORKSPACE", root)
|
|
|
|
wsRoot := filepath.Join(root, "workspace")
|
|
|
|
// Create running workspace
|
|
ws1 := filepath.Join(wsRoot, "ws-running")
|
|
os.MkdirAll(ws1, 0o755)
|
|
st1, _ := json.Marshal(WorkspaceStatus{Status: "running", Repo: "go-io", Agent: "codex"})
|
|
os.WriteFile(filepath.Join(ws1, "status.json"), st1, 0o644)
|
|
|
|
// Create completed workspace (should not be in active list)
|
|
ws2 := filepath.Join(wsRoot, "ws-done")
|
|
os.MkdirAll(ws2, 0o755)
|
|
st2, _ := json.Marshal(WorkspaceStatus{Status: "completed", Repo: "go-crypt", Agent: "codex"})
|
|
os.WriteFile(filepath.Join(ws2, "status.json"), st2, 0o644)
|
|
|
|
// Create queued workspace
|
|
ws3 := filepath.Join(wsRoot, "ws-queued")
|
|
os.MkdirAll(ws3, 0o755)
|
|
st3, _ := json.Marshal(WorkspaceStatus{Status: "queued", Repo: "go-log", Agent: "gemini"})
|
|
os.WriteFile(filepath.Join(ws3, "status.json"), st3, 0o644)
|
|
|
|
s := &PrepSubsystem{
|
|
backoff: make(map[string]time.Time),
|
|
failCount: make(map[string]int),
|
|
}
|
|
active := s.findActiveWorkspaces()
|
|
assert.Contains(t, active, "ws-running")
|
|
assert.Contains(t, active, "ws-queued")
|
|
assert.NotContains(t, active, "ws-done")
|
|
}
|
|
|
|
func TestFindActiveWorkspaces_Good_Empty(t *testing.T) {
|
|
root := t.TempDir()
|
|
t.Setenv("CORE_WORKSPACE", root)
|
|
|
|
// Ensure workspace dir exists but is empty
|
|
os.MkdirAll(filepath.Join(root, "workspace"), 0o755)
|
|
|
|
s := &PrepSubsystem{
|
|
backoff: make(map[string]time.Time),
|
|
failCount: make(map[string]int),
|
|
}
|
|
active := s.findActiveWorkspaces()
|
|
assert.Empty(t, active)
|
|
}
|