Files
archie/internal/domain/curator/definition_engine_test.go
T
sam c394348d19 fix(curator): grant the definition engine its model runner
Registry.filter stripped the LLM capability whenever a manifest declared
no tools, skills, memory or conversation capabilities, but
DefinitionEngine.Pass always calls the model. An instruction-only custom
curator therefore registered healthy and then failed every pass with
'no model runner is bound'. The definition engine is inherently agentic,
so the filter now keeps the model runner for it while every other
capability service stays bound only when declared.

Adds tests reproducing the instruction-only pass through the
registry/engine path and pinning that the registrar view for an
instruction-only manifest exposes the model but no tools, skills,
memory or conversations.

Closes #1132
2026-10-30 00:22:50 +11:00

142 lines
4.6 KiB
Go

package curator
import (
"context"
"strings"
"testing"
"time"
domainmemory "github.com/samcharles93/archie-core/internal/domain/memory"
"github.com/samcharles93/archie-core/internal/tools"
)
// fakeLLM records every chat request and returns a canned result.
type fakeLLM struct {
requests []ChatRequest
}
func (f *fakeLLM) Chat(_ context.Context, req ChatRequest) (ChatResult, error) {
f.requests = append(f.requests, req)
return ChatResult{Text: "done"}, nil
}
// stubToolBuilder, stubSkillStore, stubMemorySource and stubConversationSource
// stand in for host capability services so tests can prove the registrar view
// filters them out for a curator that does not declare them.
type stubToolBuilder struct{}
func (stubToolBuilder) Build(context.Context, []string) ([]tools.ToolEntry, error) {
return nil, nil
}
type stubSkillStore struct{}
func (stubSkillStore) List(context.Context) ([]SkillRef, error) { return nil, nil }
func (stubSkillStore) Read(context.Context, string) (Skill, error) { return Skill{}, nil }
func (stubSkillStore) Write(context.Context, Skill) error { return nil }
func (stubSkillStore) Delete(context.Context, string) error { return nil }
type stubMemorySource struct{}
func (stubMemorySource) Get(string) (domainmemory.MemoryEngine, bool) { return nil, false }
type stubConversationSource struct{}
func (stubConversationSource) RecentSessions(context.Context, time.Time) ([]SessionRef, error) {
return nil, nil
}
func (stubConversationSource) Messages(context.Context, string, int) ([]ConversationMessage, error) {
return nil, nil
}
// fullHost returns a registrar carrying every host service, so a test can
// prove what the filtered view keeps and drops.
func fullHost(llm LLMRunner) Registrar {
return Registrar{
Model: "test/model",
LLM: llm,
Tools: stubToolBuilder{},
Skills: stubSkillStore{},
MemoryEngines: stubMemorySource{},
Conversations: stubConversationSource{},
}
}
func instructionOnlyDefinition() Definition {
return Definition{
Name: "custom",
Enabled: true,
Instructions: "You are a tidy curator.",
Manifest: Manifest{Interval: time.Hour},
}
}
// TestInstructionOnlyDefinitionPass runs an instruction-only custom curator
// end to end through the registry/engine path: registration binds a filtered
// view, and the pass reaches the model. Before the filter granted the
// definition engine its model runner, this pass failed with "no model runner
// is bound".
func TestInstructionOnlyDefinitionPass(t *testing.T) {
llm := &fakeLLM{}
registry := NewRegistry(fullHost(llm))
engine := NewDefinitionEngine(instructionOnlyDefinition())
if err := registry.Register(engine); err != nil {
t.Fatal(err)
}
if _, err := engine.Pass(t.Context(), PassInput{Reason: "test"}); err != nil {
t.Fatalf("instruction-only pass: %v", err)
}
if len(llm.requests) != 1 {
t.Fatalf("model calls = %d, want 1", len(llm.requests))
}
req := llm.requests[0]
if req.Model != "test/model" {
t.Errorf("model = %q, want the registrar default %q", req.Model, "test/model")
}
if len(req.Tools) != 0 {
t.Errorf("model received %d tools, want none: undeclared tools must stay unavailable", len(req.Tools))
}
var system string
for _, msg := range req.Messages {
if msg.Role == "system" {
system = msg.Content
}
}
if !strings.Contains(system, "You are a tidy curator.") {
t.Errorf("system prompt %q does not carry the definition's instructions", system)
}
}
// TestInstructionOnlyRegistrarViewFiltered pins capability filtering for an
// instruction-only manifest: the bound registrar view exposes the model
// runner but no tools, skills, memory or conversation access.
func TestInstructionOnlyRegistrarViewFiltered(t *testing.T) {
registry := NewRegistry(fullHost(&fakeLLM{}))
engine := NewDefinitionEngine(instructionOnlyDefinition())
if err := registry.Register(engine); err != nil {
t.Fatal(err)
}
host := engine.host
if host.LLM == nil {
t.Error("registrar view has no model runner; the definition engine always calls the model")
}
if host.Tools != nil {
t.Error("registrar view exposes tools the manifest does not declare")
}
if host.Skills != nil {
t.Error("registrar view exposes the skills capability the manifest does not declare")
}
if host.MemoryEngines != nil {
t.Error("registrar view exposes memory engines the manifest does not declare")
}
if host.Conversations != nil {
t.Error("registrar view exposes conversation history the manifest does not declare")
}
if host.Clock == nil {
t.Error("registrar view has no clock; time is always bound")
}
}