New properly named tests:
- TestStatus_Status_Ugly — dead PID detection (blocked/completed/failed)
- TestPaths_DefaultBranch_{Good,Bad,Ugly} — main/master/non-git
- TestAutoPR_AutoCreatePR_{Good,Bad,Ugly} — early returns + no commits
- TestPrep_BuildPrompt_{Good,Bad,Ugly} — basic/empty/persona+issue
558 agentic tests, 74.0% coverage
Co-Authored-By: Virgil <virgil@lethean.io>
114 lines
3.1 KiB
Go
114 lines
3.1 KiB
Go
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
package agentic
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestAutoPR_AutoCreatePR_Good(t *testing.T) {
|
|
t.Skip("needs real git + forge integration")
|
|
}
|
|
|
|
func TestAutoPR_AutoCreatePR_Bad(t *testing.T) {
|
|
root := t.TempDir()
|
|
t.Setenv("CORE_WORKSPACE", root)
|
|
|
|
s := &PrepSubsystem{
|
|
backoff: make(map[string]time.Time),
|
|
failCount: make(map[string]int),
|
|
}
|
|
|
|
// No status file → early return (no panic)
|
|
wsNoStatus := filepath.Join(root, "ws-no-status")
|
|
require.NoError(t, os.MkdirAll(wsNoStatus, 0o755))
|
|
assert.NotPanics(t, func() {
|
|
s.autoCreatePR(wsNoStatus)
|
|
})
|
|
|
|
// Empty branch → early return
|
|
wsNoBranch := filepath.Join(root, "ws-no-branch")
|
|
require.NoError(t, os.MkdirAll(wsNoBranch, 0o755))
|
|
st := &WorkspaceStatus{
|
|
Status: "completed",
|
|
Agent: "codex",
|
|
Repo: "go-io",
|
|
Branch: "",
|
|
}
|
|
data, err := json.MarshalIndent(st, "", " ")
|
|
require.NoError(t, err)
|
|
require.NoError(t, os.WriteFile(filepath.Join(wsNoBranch, "status.json"), data, 0o644))
|
|
assert.NotPanics(t, func() {
|
|
s.autoCreatePR(wsNoBranch)
|
|
})
|
|
|
|
// Empty repo → early return
|
|
wsNoRepo := filepath.Join(root, "ws-no-repo")
|
|
require.NoError(t, os.MkdirAll(wsNoRepo, 0o755))
|
|
st2 := &WorkspaceStatus{
|
|
Status: "completed",
|
|
Agent: "codex",
|
|
Repo: "",
|
|
Branch: "agent/fix-tests",
|
|
}
|
|
data2, err := json.MarshalIndent(st2, "", " ")
|
|
require.NoError(t, err)
|
|
require.NoError(t, os.WriteFile(filepath.Join(wsNoRepo, "status.json"), data2, 0o644))
|
|
assert.NotPanics(t, func() {
|
|
s.autoCreatePR(wsNoRepo)
|
|
})
|
|
}
|
|
|
|
func TestAutoPR_AutoCreatePR_Ugly(t *testing.T) {
|
|
root := t.TempDir()
|
|
t.Setenv("CORE_WORKSPACE", root)
|
|
|
|
// Set up a real git repo with no commits ahead of origin/dev
|
|
wsDir := filepath.Join(root, "ws-no-ahead")
|
|
repoDir := filepath.Join(wsDir, "repo")
|
|
require.NoError(t, os.MkdirAll(repoDir, 0o755))
|
|
|
|
// Init the repo
|
|
cmd := exec.Command("git", "init", "-b", "dev", repoDir)
|
|
require.NoError(t, cmd.Run())
|
|
cmd = exec.Command("git", "-C", repoDir, "config", "user.name", "Test")
|
|
require.NoError(t, cmd.Run())
|
|
cmd = exec.Command("git", "-C", repoDir, "config", "user.email", "test@test.com")
|
|
require.NoError(t, cmd.Run())
|
|
|
|
require.NoError(t, os.WriteFile(filepath.Join(repoDir, "README.md"), []byte("# test"), 0o644))
|
|
cmd = exec.Command("git", "-C", repoDir, "add", ".")
|
|
require.NoError(t, cmd.Run())
|
|
cmd = exec.Command("git", "-C", repoDir, "commit", "-m", "init")
|
|
require.NoError(t, cmd.Run())
|
|
|
|
// Write status with valid branch + repo
|
|
st := &WorkspaceStatus{
|
|
Status: "completed",
|
|
Agent: "codex",
|
|
Repo: "go-io",
|
|
Branch: "agent/fix-tests",
|
|
StartedAt: time.Now(),
|
|
}
|
|
data, err := json.MarshalIndent(st, "", " ")
|
|
require.NoError(t, err)
|
|
require.NoError(t, os.WriteFile(filepath.Join(wsDir, "status.json"), data, 0o644))
|
|
|
|
s := &PrepSubsystem{
|
|
backoff: make(map[string]time.Time),
|
|
failCount: make(map[string]int),
|
|
}
|
|
|
|
// git log origin/dev..HEAD will fail (no origin remote) → early return
|
|
assert.NotPanics(t, func() {
|
|
s.autoCreatePR(wsDir)
|
|
})
|
|
}
|