Files
archie/internal/agentexec/harness_mcp_test.go
T

47 lines
1.9 KiB
Go

//go:build unix
package agentexec
import (
"encoding/json"
"os"
"os/exec"
"testing"
"github.com/samcharles93/archie-core/internal/domain/agentrun"
)
// Some CLIs log an unsupported MCP configuration but still exit successfully.
func TestHarnessRequiresMCPInitialization(t *testing.T) {
for _, central := range []bool{false, true} {
t.Run(map[bool]string{false: "captures", true: "central tools"}[central], func(t *testing.T) {
workspace, err := os.MkdirTemp("", "archie-mcp-regression-") //nolint:usetesting // The harness user cannot traverse testing's private parent directory.
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(workspace)
for _, args := range [][]string{{"init", "-q"}, {"-c", "user.name=fixture", "-c", "user.email=fixture@example.invalid", "commit", "--allow-empty", "-q", "-m", "fixture"}} {
cmd := exec.CommandContext(t.Context(), "git", append([]string{"-C", workspace}, args...)...)
if raw, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("git fixture %v: %s", err, raw)
}
}
h := &agentrun.HarnessSpec{Launch: []string{"sh", "-c", "exit 0", "harness"}, Prompt: []string{"{{.Prompt}}"}, MCPConfig: []string{"{{.MCPConfig}}"}, Env: []string{"PATH=/usr/bin:/bin"}, CentralTools: central}
if os.Geteuid() == 0 {
h.User = "65534"
}
req := agentrun.Request{Version: agentrun.ProtocolVersion, TaskID: 7, Attempt: 1, Stage: "test", Mission: "return a result", Model: "fixture/model", Harness: h}
if !central {
req.CaptureTools = []agentrun.CaptureTool{{Name: "capture_result", Parameters: json.RawMessage(`{"type":"object"}`)}}
}
result, err := NewHarnessRunner(nil).Run(t.Context(), workspace, req, nil)
if err != nil {
t.Fatal(err)
}
if result.Status == agentrun.StatusPassed || result.StopReason != StopExited {
t.Fatalf("unsupported MCP silently passed: %+v", result)
}
})
}
}