diff --git a/pkg/agentic/handlers_test.go b/pkg/agentic/handlers_test.go index 1f8d606..1932096 100644 --- a/pkg/agentic/handlers_test.go +++ b/pkg/agentic/handlers_test.go @@ -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) + }) +} diff --git a/pkg/agentic/prep_extra_test.go b/pkg/agentic/prep_extra_test.go index 334acbe..36348ea 100644 --- a/pkg/agentic/prep_extra_test.go +++ b/pkg/agentic/prep_extra_test.go @@ -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) {