Files
archie/internal/tools/provider/contract_test.go
T
sam 1586fef2b9 feat(mcp): answer server-initiated sampling from the chat model
MCP servers could not ask the client for a completion: the transports
routed only responses by id and dropped every server-initiated request,
so a server calling sampling/createMessage hung waiting for a reply.

Route server->client requests through the transport readers to a handler
on the client. The client answers sampling/createMessage from a
configured SamplingHandler and maps a missing handler, malformed params
and handler failure to JSON-RPC errors for that request alone -- never a
silent drop or a failed session. stdio and SSE implement the routing;
the stateless HTTP transport cannot receive the request at all and says
so in its doc.

The daemon wires the handler to its own chat runtime and active model
role, so a sample is answered by the model a chat turn uses, capped by
the request's maxTokens and the model's output ceiling, and recorded on
/status like every other model call. No model configured is a refused
request with a clear error.
2026-10-02 09:33:32 +10:00

79 lines
2.5 KiB
Go

package provider_test
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestToolProviderEngineContractExists(t *testing.T) {
t.Parallel()
source, err := os.ReadFile("provider.go")
if err != nil {
t.Fatalf("read provider.go: %v", err)
}
text := string(source)
for _, required := range []string{
"type Engine interface",
"plugin.Module",
"Discover(context.Context) ([]tools.ToolEntry, error)",
"type Registry struct",
"func (r *Registry) Register(engine Engine) error",
"func (r *Registry) Get(id string) (Engine, bool)",
} {
if !strings.Contains(text, required) {
t.Errorf("provider.go does not contain required typed-family contract %q", required)
}
}
}
func TestArchiedWiresTypedProvidersAndExecutableConsumers(t *testing.T) {
t.Parallel()
mainPath := filepath.Join("..", "..", "..", "internal", "app", "archied", "main.go")
source, err := os.ReadFile(mainPath)
if err != nil {
t.Fatalf("read archied main: %v", err)
}
var text strings.Builder
text.WriteString(string(source))
// Also check the chat composition files, which hold the chat-turn wiring
// extracted from main.go during the structural refactor.
for _, name := range []string{"telegram_setup.go", "chat_turn_model.go", "bootstrap.go"} {
path := filepath.Join("..", "..", "..", "internal", "app", "archied", name)
source, readErr := os.ReadFile(path)
if readErr == nil {
text.WriteString(string(source))
}
}
for _, required := range []string{
// The provider registry, its engines and the consumer wiring live
// in bootstrap.go (the boot-phase carrier) since the composition
// root was decomposed; the receiver makes the arg expressions
// carry the b. prefix there.
"toolprovider.NewRegistry(b.toolReg)",
"configuredMCPProvider(srv, cfg.WorkDir, b.mcpSamplingHandler())",
"capabilityHost.Register(b.providerRegistry)",
// The chat turn builds its toolset from the registry before the
// system prompt is rendered, so the prompt can advertise exactly
// the tools the model is handed. After the structural refactor these
// calls live in the chat composition files.
"chatGenerateOptions(ctx,",
"toolSummaries(options.Tools)",
} {
if !strings.Contains(text.String(), required) {
t.Errorf("archied wiring not found: %q", required)
}
}
if strings.Contains(text.String(), ".RegisterTools(ctx, toolReg)") {
t.Error("composition bypasses the typed provider registry with direct MCP registration")
}
if strings.Contains(text.String(), "NewLoopRunner") {
t.Error("archied constructs a worker-local autonomous runner")
}
}