test: RegisterTools GBU + buildPrompt git log — 840 tests, 79.9% coverage
- RegisterTools: exercises all 12 register*Tool functions via mcp.NewServer (+1.4pp) - buildPrompt: test with real git repo for RECENT CHANGES path - AX-7: 92% categories filled 0.1pp from 80%. Remaining gap is process-dependent functions awaiting go-process v0.7.0 update. Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
d67336c761
commit
3522a3bea5
2 changed files with 65 additions and 0 deletions
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
"dappco.re/go/agent/pkg/messages"
|
||||
core "dappco.re/go/core"
|
||||
"github.com/modelcontextprotocol/go-sdk/mcp"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
|
@ -209,3 +210,41 @@ func TestPrep_OnStartup_Good_Registers(t *testing.T) {
|
|||
err := s.OnStartup(context.Background())
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
// --- RegisterTools (exercises all register*Tool functions) ---
|
||||
|
||||
func TestPrep_RegisterTools_Good(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
t.Setenv("CORE_WORKSPACE", root)
|
||||
|
||||
srv := mcp.NewServer(&mcp.Implementation{Name: "test", Version: "0.0.1"}, nil)
|
||||
s := NewPrep()
|
||||
s.SetCore(core.New())
|
||||
|
||||
assert.NotPanics(t, func() { s.RegisterTools(srv) })
|
||||
}
|
||||
|
||||
func TestPrep_RegisterTools_Bad(t *testing.T) {
|
||||
// RegisterTools on prep without Core — should still register tools
|
||||
srv := mcp.NewServer(&mcp.Implementation{Name: "test", Version: "0.0.1"}, nil)
|
||||
s := &PrepSubsystem{
|
||||
backoff: make(map[string]time.Time),
|
||||
failCount: make(map[string]int),
|
||||
}
|
||||
assert.NotPanics(t, func() { s.RegisterTools(srv) })
|
||||
}
|
||||
|
||||
func TestPrep_RegisterTools_Ugly(t *testing.T) {
|
||||
// Call RegisterTools twice — should not panic or double-register
|
||||
root := t.TempDir()
|
||||
t.Setenv("CORE_WORKSPACE", root)
|
||||
|
||||
srv := mcp.NewServer(&mcp.Implementation{Name: "test", Version: "0.0.1"}, nil)
|
||||
s := NewPrep()
|
||||
s.SetCore(core.New())
|
||||
|
||||
assert.NotPanics(t, func() {
|
||||
s.RegisterTools(srv)
|
||||
s.RegisterTools(srv)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
|
@ -357,6 +358,31 @@ func TestPrep_BuildPrompt_Ugly(t *testing.T) {
|
|||
assert.Contains(t, prompt, "CONSTRAINTS:")
|
||||
}
|
||||
|
||||
func TestPrep_BuildPrompt_Ugly_WithGitLog(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
os.WriteFile(filepath.Join(dir, "go.mod"), []byte("module test\n\ngo 1.22\n"), 0o644)
|
||||
|
||||
// Init a real git repo with commits so git log path is covered
|
||||
exec.Command("git", "init", "-b", "main", dir).Run()
|
||||
exec.Command("git", "-C", dir, "config", "user.email", "t@t.com").Run()
|
||||
exec.Command("git", "-C", dir, "config", "user.name", "T").Run()
|
||||
exec.Command("git", "-C", dir, "add", ".").Run()
|
||||
exec.Command("git", "-C", dir, "commit", "-m", "init").Run()
|
||||
|
||||
s := &PrepSubsystem{
|
||||
codePath: t.TempDir(),
|
||||
backoff: make(map[string]time.Time),
|
||||
failCount: make(map[string]int),
|
||||
}
|
||||
|
||||
prompt, _, _ := s.buildPrompt(context.Background(), PrepInput{
|
||||
Task: "Fix tests", Org: "core", Repo: "go-io",
|
||||
}, "dev", dir)
|
||||
|
||||
assert.Contains(t, prompt, "RECENT CHANGES:")
|
||||
assert.Contains(t, prompt, "init")
|
||||
}
|
||||
|
||||
// --- runQA ---
|
||||
|
||||
func TestDispatch_RunQA_Good_PHPNoComposer(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue