Files
archie/internal/tools/provider/contract_test.go
T
sam e6c69a1f48 feat(tools): reconcile MCP servers and tool settings live
Flip tool-settings to ApplyMode live (archie-core-zfb0.3): the daemon now
watches the kind, diffs the stored MCP server set against the running
providers -- connecting added servers, disconnecting removed ones and
reconnecting changed ones while an unchanged server keeps running -- and
rebuilds the web_fetch and minimax entries, whose config is captured at
construction. A changed server whose replacement fails to start is rolled
back to the one running, and the refusal is reported through apply status.

toolprovider.Registry grows running-state Add/Remove/Replace beside
Register, Start and Stop, isolating a provider's failure the way the plugin
host's Add/Replace do. The chat turn model resolves its tool-output policy
per turn instead of capturing it at construction, and the boot registration
reads the running holder so a stored update that lands during boot is not
lost.
2026-10-02 11:46:37 +10:00

84 lines
2.8 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", "mcp_reconcile.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)",
// buildMCPProvider is the single construction seam: boot registration
// and the live reconciliation both reach configuredMCPProvider through
// it, so an MCP server is always built with the daemon's sampling
// handler.
"configuredMCPProvider(srv, b.cfgHolder.Get().WorkDir, b.mcpSamplingHandler())",
"b.buildMCPProvider(srv)",
"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")
}
}