test(egress): a recording session performs no central tool call
This commit is contained in:
1 parent
559ac3a00f
commit
1cffc39f7f
1 file changed
+60
@@ -2,12 +2,15 @@ package egress
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
"github.com/modelcontextprotocol/go-sdk/mcp"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/events"
|
||||
)
|
||||
|
||||
@@ -78,3 +81,60 @@ func TestRecordedSessionRecordsDeliveries(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// A recording session performs no central tool call, so a mutating tool cannot
|
||||
// act for real during a test run. Discovery still reaches the gateway: a run
|
||||
// that cannot list its tools cannot use any.
|
||||
func TestRecordedToolsPerformNoCall(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var listed, called atomic.Int32
|
||||
backend := stubBackend{
|
||||
list: func(context.Context, string) ([]*mcp.Tool, error) {
|
||||
listed.Add(1)
|
||||
return []*mcp.Tool{{Name: "memory_create"}}, nil
|
||||
},
|
||||
call: func(context.Context, string, string, json.RawMessage) (*mcp.CallToolResult, error) {
|
||||
called.Add(1)
|
||||
return nil, nil
|
||||
},
|
||||
}
|
||||
var recorded []events.Event
|
||||
proxy := NewProxy(nil, ProxyOptions{Events: func(event events.Event) { recorded = append(recorded, event) }})
|
||||
session := &Session{record: &RecordOptions{TaskID: 7}}
|
||||
tools := recordedTools{Backend: backend, proxy: proxy, session: session}
|
||||
|
||||
if _, err := tools.List(context.Background(), "grant"); err != nil || listed.Load() != 1 {
|
||||
t.Fatalf("discovery did not reach the gateway: listed=%d err=%v", listed.Load(), err)
|
||||
}
|
||||
result, err := tools.Call(context.Background(), "grant", "memory_create", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("a recorded call reports success: %v", err)
|
||||
}
|
||||
if called.Load() != 0 {
|
||||
t.Fatalf("a recorded call reached the gateway")
|
||||
}
|
||||
text, ok := result.Content[0].(*mcp.TextContent)
|
||||
if !ok || text.Text != "would call memory_create" {
|
||||
t.Fatalf("answered %+v", result.Content)
|
||||
}
|
||||
if len(recorded) != 1 || recorded[0].Kind != events.KindDeliveryRecorded ||
|
||||
recorded[0].TaskID != 7 || recorded[0].Detail != "would call memory_create" {
|
||||
t.Fatalf("recorded %+v, want one \"would call memory_create\" on task 7", recorded)
|
||||
}
|
||||
}
|
||||
|
||||
type stubBackend struct {
|
||||
list func(context.Context, string) ([]*mcp.Tool, error)
|
||||
call func(context.Context, string, string, json.RawMessage) (*mcp.CallToolResult, error)
|
||||
}
|
||||
|
||||
func (b stubBackend) List(ctx context.Context, credential string) ([]*mcp.Tool, error) {
|
||||
return b.list(ctx, credential)
|
||||
}
|
||||
|
||||
func (b stubBackend) Call(ctx context.Context, credential, tool string, args json.RawMessage) (*mcp.CallToolResult, error) {
|
||||
return b.call(ctx, credential, tool, args)
|
||||
}
|
||||
|
||||
func (b stubBackend) Close(context.Context, string) error { return nil }
|
||||
Reference in new issue
Block a user