From 3522a3bea5d7a4ccae55972b3bdfbbe19855d876 Mon Sep 17 00:00:00 2001 From: Snider Date: Wed, 25 Mar 2026 10:28:30 +0000 Subject: [PATCH] =?UTF-8?q?test:=20RegisterTools=20GBU=20+=20buildPrompt?= =?UTF-8?q?=20git=20log=20=E2=80=94=20840=20tests,=2079.9%=20coverage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- pkg/agentic/handlers_test.go | 39 ++++++++++++++++++++++++++++++++++ pkg/agentic/prep_extra_test.go | 26 +++++++++++++++++++++++ 2 files changed, 65 insertions(+) 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) {