test: add Good/Bad/Ugly for status, paths, auto_pr, prep — agentic 74.0%
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>
2026-03-25 08:16:53 +00:00
|
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
|
|
|
|
|
|
package agentic
|
|
|
|
|
|
|
|
|
|
import (
|
2026-03-26 06:38:02 +00:00
|
|
|
"context"
|
test: add Good/Bad/Ugly for status, paths, auto_pr, prep — agentic 74.0%
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>
2026-03-25 08:16:53 +00:00
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
feat(v0.8.0): full AX migration — ServiceRuntime, Actions, quality gates, transport
go-process:
- Register factory, Result lifecycle, 5 named Action handlers
- Start/Run/StartWithOptions/RunWithOptions all return core.Result
- core.ID() replaces fmt.Sprintf, core.As replaces errors.As
core/agent:
- PrepSubsystem + monitor.Subsystem + setup.Service embed ServiceRuntime[T]
- 22 named Actions + agent.completion Task pipeline in OnStartup
- ChannelNotifier removed — all IPC via c.ACTION(messages.X{})
- proc.go: all methods via s.Core().Process(), returns core.Result
- status.go: WriteAtomic + JSONMarshalString
- paths.go: Fs.NewUnrestricted() replaces unsafe.Pointer
- transport.go: ONE net/http file — HTTPGet/HTTPPost/HTTPDo/MCP transport
- All disallowed imports eliminated from source files (13 quality gates)
- String concat eliminated — core.Concat() throughout
- 1:1 _test.go + _example_test.go for every source file
- Reference docs synced from core/go v0.8.0
- RFC-025 updated with net/http, net/url, io/fs quality gates
- lib.go: io/fs eliminated via Data.ListNames, Array[T].Deduplicate
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 01:27:46 +00:00
|
|
|
core "dappco.re/go/core"
|
test: add Good/Bad/Ugly for status, paths, auto_pr, prep — agentic 74.0%
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>
2026-03-25 08:16:53 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2026-04-02 01:59:03 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
test: add Good/Bad/Ugly for status, paths, auto_pr, prep — agentic 74.0%
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>
2026-03-25 08:16:53 +00:00
|
|
|
)
|
|
|
|
|
|
2026-03-26 06:38:02 +00:00
|
|
|
func TestAutopr_AutoCreatePR_Good(t *testing.T) {
|
test: add Good/Bad/Ugly for status, paths, auto_pr, prep — agentic 74.0%
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>
2026-03-25 08:16:53 +00:00
|
|
|
t.Skip("needs real git + forge integration")
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-26 06:38:02 +00:00
|
|
|
func TestAutopr_AutoCreatePR_Bad(t *testing.T) {
|
test: add Good/Bad/Ugly for status, paths, auto_pr, prep — agentic 74.0%
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>
2026-03-25 08:16:53 +00:00
|
|
|
root := t.TempDir()
|
|
|
|
|
t.Setenv("CORE_WORKSPACE", root)
|
|
|
|
|
|
|
|
|
|
s := &PrepSubsystem{
|
feat(v0.8.0): full AX migration — ServiceRuntime, Actions, quality gates, transport
go-process:
- Register factory, Result lifecycle, 5 named Action handlers
- Start/Run/StartWithOptions/RunWithOptions all return core.Result
- core.ID() replaces fmt.Sprintf, core.As replaces errors.As
core/agent:
- PrepSubsystem + monitor.Subsystem + setup.Service embed ServiceRuntime[T]
- 22 named Actions + agent.completion Task pipeline in OnStartup
- ChannelNotifier removed — all IPC via c.ACTION(messages.X{})
- proc.go: all methods via s.Core().Process(), returns core.Result
- status.go: WriteAtomic + JSONMarshalString
- paths.go: Fs.NewUnrestricted() replaces unsafe.Pointer
- transport.go: ONE net/http file — HTTPGet/HTTPPost/HTTPDo/MCP transport
- All disallowed imports eliminated from source files (13 quality gates)
- String concat eliminated — core.Concat() throughout
- 1:1 _test.go + _example_test.go for every source file
- Reference docs synced from core/go v0.8.0
- RFC-025 updated with net/http, net/url, io/fs quality gates
- lib.go: io/fs eliminated via Data.ListNames, Array[T].Deduplicate
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 01:27:46 +00:00
|
|
|
ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{}),
|
2026-04-02 01:59:03 +00:00
|
|
|
backoff: make(map[string]time.Time),
|
|
|
|
|
failCount: make(map[string]int),
|
test: add Good/Bad/Ugly for status, paths, auto_pr, prep — agentic 74.0%
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>
2026-03-25 08:16:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// No status file → early return (no panic)
|
2026-03-26 01:39:41 +00:00
|
|
|
wsNoStatus := core.JoinPath(root, "ws-no-status")
|
2026-03-26 02:07:31 +00:00
|
|
|
fs.EnsureDir(wsNoStatus)
|
test: add Good/Bad/Ugly for status, paths, auto_pr, prep — agentic 74.0%
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>
2026-03-25 08:16:53 +00:00
|
|
|
assert.NotPanics(t, func() {
|
|
|
|
|
s.autoCreatePR(wsNoStatus)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Empty branch → early return
|
2026-03-26 01:39:41 +00:00
|
|
|
wsNoBranch := core.JoinPath(root, "ws-no-branch")
|
2026-03-26 02:07:31 +00:00
|
|
|
fs.EnsureDir(wsNoBranch)
|
|
|
|
|
fs.Write(core.JoinPath(wsNoBranch, "status.json"), core.JSONMarshalString(&WorkspaceStatus{
|
|
|
|
|
Status: "completed", Agent: "codex", Repo: "go-io", Branch: "",
|
|
|
|
|
}))
|
test: add Good/Bad/Ugly for status, paths, auto_pr, prep — agentic 74.0%
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>
2026-03-25 08:16:53 +00:00
|
|
|
assert.NotPanics(t, func() {
|
|
|
|
|
s.autoCreatePR(wsNoBranch)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Empty repo → early return
|
2026-03-26 01:39:41 +00:00
|
|
|
wsNoRepo := core.JoinPath(root, "ws-no-repo")
|
2026-03-26 02:07:31 +00:00
|
|
|
fs.EnsureDir(wsNoRepo)
|
|
|
|
|
fs.Write(core.JoinPath(wsNoRepo, "status.json"), core.JSONMarshalString(&WorkspaceStatus{
|
|
|
|
|
Status: "completed", Agent: "codex", Repo: "", Branch: "agent/fix-tests",
|
|
|
|
|
}))
|
test: add Good/Bad/Ugly for status, paths, auto_pr, prep — agentic 74.0%
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>
2026-03-25 08:16:53 +00:00
|
|
|
assert.NotPanics(t, func() {
|
|
|
|
|
s.autoCreatePR(wsNoRepo)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-26 06:38:02 +00:00
|
|
|
func TestAutopr_AutoCreatePR_Ugly(t *testing.T) {
|
test: add Good/Bad/Ugly for status, paths, auto_pr, prep — agentic 74.0%
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>
2026-03-25 08:16:53 +00:00
|
|
|
root := t.TempDir()
|
|
|
|
|
t.Setenv("CORE_WORKSPACE", root)
|
|
|
|
|
|
|
|
|
|
// Set up a real git repo with no commits ahead of origin/dev
|
2026-03-26 01:39:41 +00:00
|
|
|
wsDir := core.JoinPath(root, "ws-no-ahead")
|
|
|
|
|
repoDir := core.JoinPath(wsDir, "repo")
|
2026-03-26 02:07:31 +00:00
|
|
|
fs.EnsureDir(repoDir)
|
test: add Good/Bad/Ugly for status, paths, auto_pr, prep — agentic 74.0%
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>
2026-03-25 08:16:53 +00:00
|
|
|
|
|
|
|
|
// Init the repo
|
2026-03-26 06:38:02 +00:00
|
|
|
testCore.Process().Run(context.Background(), "git", "init", "-b", "dev", repoDir)
|
|
|
|
|
testCore.Process().RunIn(context.Background(), repoDir, "git", "config", "user.name", "Test")
|
|
|
|
|
testCore.Process().RunIn(context.Background(), repoDir, "git", "config", "user.email", "test@test.com")
|
test: add Good/Bad/Ugly for status, paths, auto_pr, prep — agentic 74.0%
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>
2026-03-25 08:16:53 +00:00
|
|
|
|
2026-03-26 02:07:31 +00:00
|
|
|
fs.Write(core.JoinPath(repoDir, "README.md"), "# test")
|
2026-03-26 06:38:02 +00:00
|
|
|
testCore.Process().RunIn(context.Background(), repoDir, "git", "add", ".")
|
|
|
|
|
testCore.Process().RunIn(context.Background(), repoDir, "git", "commit", "-m", "init")
|
test: add Good/Bad/Ugly for status, paths, auto_pr, prep — agentic 74.0%
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>
2026-03-25 08:16:53 +00:00
|
|
|
|
|
|
|
|
// Write status with valid branch + repo
|
|
|
|
|
st := &WorkspaceStatus{
|
|
|
|
|
Status: "completed",
|
|
|
|
|
Agent: "codex",
|
|
|
|
|
Repo: "go-io",
|
|
|
|
|
Branch: "agent/fix-tests",
|
|
|
|
|
StartedAt: time.Now(),
|
|
|
|
|
}
|
2026-03-26 02:07:31 +00:00
|
|
|
fs.Write(core.JoinPath(wsDir, "status.json"), core.JSONMarshalString(st))
|
test: add Good/Bad/Ugly for status, paths, auto_pr, prep — agentic 74.0%
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>
2026-03-25 08:16:53 +00:00
|
|
|
|
|
|
|
|
s := &PrepSubsystem{
|
feat(v0.8.0): full AX migration — ServiceRuntime, Actions, quality gates, transport
go-process:
- Register factory, Result lifecycle, 5 named Action handlers
- Start/Run/StartWithOptions/RunWithOptions all return core.Result
- core.ID() replaces fmt.Sprintf, core.As replaces errors.As
core/agent:
- PrepSubsystem + monitor.Subsystem + setup.Service embed ServiceRuntime[T]
- 22 named Actions + agent.completion Task pipeline in OnStartup
- ChannelNotifier removed — all IPC via c.ACTION(messages.X{})
- proc.go: all methods via s.Core().Process(), returns core.Result
- status.go: WriteAtomic + JSONMarshalString
- paths.go: Fs.NewUnrestricted() replaces unsafe.Pointer
- transport.go: ONE net/http file — HTTPGet/HTTPPost/HTTPDo/MCP transport
- All disallowed imports eliminated from source files (13 quality gates)
- String concat eliminated — core.Concat() throughout
- 1:1 _test.go + _example_test.go for every source file
- Reference docs synced from core/go v0.8.0
- RFC-025 updated with net/http, net/url, io/fs quality gates
- lib.go: io/fs eliminated via Data.ListNames, Array[T].Deduplicate
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 01:27:46 +00:00
|
|
|
ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{}),
|
2026-04-02 01:59:03 +00:00
|
|
|
backoff: make(map[string]time.Time),
|
|
|
|
|
failCount: make(map[string]int),
|
test: add Good/Bad/Ugly for status, paths, auto_pr, prep — agentic 74.0%
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>
2026-03-25 08:16:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// git log origin/dev..HEAD will fail (no origin remote) → early return
|
|
|
|
|
assert.NotPanics(t, func() {
|
|
|
|
|
s.autoCreatePR(wsDir)
|
|
|
|
|
})
|
|
|
|
|
}
|
2026-04-02 01:59:03 +00:00
|
|
|
|
|
|
|
|
func TestAutopr_CleanupForgeBranch_Good_DeletesRemoteBranch(t *testing.T) {
|
|
|
|
|
remoteDir := core.JoinPath(t.TempDir(), "remote.git")
|
|
|
|
|
require.True(t, testCore.Process().Run(context.Background(), "git", "init", "--bare", remoteDir).OK)
|
|
|
|
|
|
|
|
|
|
repoDir := core.JoinPath(t.TempDir(), "repo")
|
|
|
|
|
require.True(t, testCore.Process().Run(context.Background(), "git", "clone", remoteDir, repoDir).OK)
|
|
|
|
|
require.True(t, testCore.Process().RunIn(context.Background(), repoDir, "git", "config", "user.name", "Test").OK)
|
|
|
|
|
require.True(t, testCore.Process().RunIn(context.Background(), repoDir, "git", "config", "user.email", "test@example.com").OK)
|
|
|
|
|
|
|
|
|
|
branch := "agent/fix-branch"
|
|
|
|
|
require.True(t, testCore.Process().RunIn(context.Background(), repoDir, "git", "checkout", "-b", branch).OK)
|
|
|
|
|
fs.Write(core.JoinPath(repoDir, "README.md"), "# test")
|
|
|
|
|
require.True(t, testCore.Process().RunIn(context.Background(), repoDir, "git", "add", ".").OK)
|
|
|
|
|
require.True(t, testCore.Process().RunIn(context.Background(), repoDir, "git", "commit", "-m", "init").OK)
|
|
|
|
|
require.True(t, testCore.Process().RunIn(context.Background(), repoDir, "git", "push", "-u", "origin", branch).OK)
|
|
|
|
|
|
|
|
|
|
s := &PrepSubsystem{ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{})}
|
|
|
|
|
assert.True(t, s.cleanupForgeBranch(context.Background(), repoDir, remoteDir, branch))
|
|
|
|
|
|
|
|
|
|
remoteHeads := testCore.Process().RunIn(context.Background(), repoDir, "git", "ls-remote", "--heads", remoteDir, branch)
|
|
|
|
|
require.True(t, remoteHeads.OK)
|
|
|
|
|
assert.NotContains(t, remoteHeads.Value.(string), branch)
|
|
|
|
|
}
|