agent/pkg/agentic/commands_workspace_test.go
Snider 277510ee16 test: 413 new tests — agentic 54.3%, setup 75.8%, all packages passing
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>
2026-03-25 00:44:17 +00:00

64 lines
1.7 KiB
Go

// SPDX-License-Identifier: EUPL-1.2
package agentic
import (
"testing"
"github.com/stretchr/testify/assert"
)
// --- extractField ---
func TestExtractField_Good_SimpleJSON(t *testing.T) {
json := `{"status":"running","repo":"go-io","agent":"codex"}`
assert.Equal(t, "running", extractField(json, "status"))
assert.Equal(t, "go-io", extractField(json, "repo"))
assert.Equal(t, "codex", extractField(json, "agent"))
}
func TestExtractField_Good_PrettyPrinted(t *testing.T) {
json := `{
"status": "completed",
"repo": "go-crypt"
}`
assert.Equal(t, "completed", extractField(json, "status"))
assert.Equal(t, "go-crypt", extractField(json, "repo"))
}
func TestExtractField_Good_TabSeparated(t *testing.T) {
json := `{"status": "blocked"}`
assert.Equal(t, "blocked", extractField(json, "status"))
}
func TestExtractField_Bad_MissingField(t *testing.T) {
json := `{"status":"running"}`
assert.Empty(t, extractField(json, "nonexistent"))
}
func TestExtractField_Bad_EmptyJSON(t *testing.T) {
assert.Empty(t, extractField("", "status"))
assert.Empty(t, extractField("{}", "status"))
}
func TestExtractField_Bad_NoValue(t *testing.T) {
// Field key exists but no quoted value after colon
json := `{"status": 42}`
assert.Empty(t, extractField(json, "status"))
}
func TestExtractField_Bad_TruncatedJSON(t *testing.T) {
// Field key exists but string is truncated
json := `{"status":`
assert.Empty(t, extractField(json, "status"))
}
func TestExtractField_Good_EmptyValue(t *testing.T) {
json := `{"status":""}`
assert.Equal(t, "", extractField(json, "status"))
}
func TestExtractField_Good_ValueWithSpaces(t *testing.T) {
json := `{"task":"fix the failing tests"}`
assert.Equal(t, "fix the failing tests", extractField(json, "task"))
}