Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions core/deeptreeecho/backend_capability_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,24 @@ import (
"github.com/o9nn/echo.go/core/llm"
)

// testModelProvider stands in for a real remote model in tests only.
type testModelProvider struct{ reply string }

func (p testModelProvider) Generate(_ context.Context, _ string, _ llm.GenerateOptions) (string, error) {
return p.reply, nil
}
func (p testModelProvider) StreamGenerate(_ context.Context, _ string, _ llm.GenerateOptions) (<-chan llm.StreamChunk, error) {
ch := make(chan llm.StreamChunk, 1)
ch <- llm.StreamChunk{Content: p.reply, Done: true}
close(ch)
return ch, nil
}
func (testModelProvider) Name() string { return "test_model" }
func (testModelProvider) Available() bool { return true }
func (testModelProvider) MaxTokens() int { return 4096 }

func TestLocalModelProviderExposesBackendDecisionAndFallsBack(t *testing.T) {
fallback := &llm.SimpleFallbackProvider{}
fallback := testModelProvider{reply: "a reply from the test model"}
provider := NewLocalModelProvider(LocalModelConfig{
ModelPath: "/tmp/nonexistent-echo-model.gguf",
ModelName: "nonexistent",
Expand All @@ -31,8 +47,18 @@ func TestLocalModelProviderExposesBackendDecisionAndFallsBack(t *testing.T) {
if err != nil {
t.Fatalf("expected fallback generation to succeed: %v", err)
}
if response == "" {
t.Fatalf("expected non-empty fallback response")
if response != "a reply from the test model" {
t.Fatalf("expected the fallback *model* to answer, got %q", response)
}
}

func TestLocalModelProviderWithoutAnyModelErrors(t *testing.T) {
provider := NewLocalModelProvider(LocalModelConfig{
ModelPath: "/tmp/nonexistent-echo-model.gguf",
ModelName: "nonexistent",
})
if _, err := provider.Generate(context.Background(), "hello", llm.GenerateOptions{MaxTokens: 8}); err == nil {
t.Fatalf("expected an error when no model is available; the character must not answer from a stub")
}
}

Expand Down
12 changes: 0 additions & 12 deletions core/deeptreeecho/evolution_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,6 @@ func (es *EvolutionSystem) registerProviders(pm *llm.ProviderManager) error {
}
}

// Always keep the simple continuity fallback registered so autonomous loops can degrade gracefully.
if err := pm.RegisterProvider(&llm.SimpleFallbackProvider{}); err == nil {
registered++
if es.config.Debug {
fmt.Println(" ✓ Registered SimpleFallback provider")
}
}

// Set fallback chain from explicit preferences, then append any remaining providers.
available := make(map[string]bool)
for _, name := range pm.ListProviders() {
Expand All @@ -207,13 +199,9 @@ func (es *EvolutionSystem) registerProviders(pm *llm.ProviderManager) error {
delete(available, preferred)
}
}
if available["SimpleFallback"] {
delete(available, "SimpleFallback")
}
for name := range available {
chain = append(chain, name)
}
chain = append(chain, "SimpleFallback")
if len(chain) > 0 {
pm.SetFallbackChain(chain)
}
Expand Down
21 changes: 9 additions & 12 deletions core/deeptreeecho/evolution_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,17 @@ func TestEvolutionSystemWithoutAPIProvidersUsesContinuityFallback(t *testing.T)
config := DefaultEvolutionSystemConfig()
es, err := NewEvolutionSystem(config)

if err != nil {
t.Fatalf("expected fallback-backed evolution system, got error: %v", err)
}

providers := es.GetStatus()["providers"].([]string)
foundFallback := false
for _, provider := range providers {
if provider == "SimpleFallback" {
foundFallback = true
// With no model configured there is deliberately no stub provider: the
// character must not speak from pattern-matched text. Either construction
// fails with a clear error, or it succeeds with zero providers registered.
if err == nil {
providers := es.GetStatus()["providers"].([]string)
for _, provider := range providers {
if provider == "SimpleFallback" {
t.Fatalf("stub fallback provider must not be registered, got %v", providers)
}
}
}
if !foundFallback {
t.Fatalf("expected SimpleFallback provider in continuity mode, got %v", providers)
}
}

func TestEvolutionSystemModelPathsSurfaceConcreteCapabilities(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions core/deeptreeecho/llm_provider_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ func CreateLLMProviderManager(anthropicKey, openRouterKey, openAIKey string) *ll
if openAIKey != "" {
chain = append(chain, "openai")
}
pm.RegisterProvider(&llm.SimpleFallbackProvider{})
chain = append(chain, "SimpleFallback")
// No stub provider is registered: when no key is configured the chain is
// empty and generation errors instead of producing pattern-matched text.
if len(chain) > 0 {
pm.SetFallbackChain(chain)
pm.ApplyBackendDecision(backendcap.Select(backendcap.Workload{PreferNative: true, MinMemoryTier: backendcap.MemoryConstrained}))
Expand Down
Loading
Loading