Files
Pulse/internal/ai/patrol_init_additional_test.go
rcourtman 39f988b220 Remove AI Discovery
AI Discovery ran a separate model-backed service scanner beside Patrol
and the Assistant: its own store, scheduler, model route, API, tool and
drawer UI. No telemetry counter ever measured its use (the telemetry
discovery_enabled flag OR'd it with network subnet discovery), the
maintainer judged it a flop, and the context it produced is already
available to the models through pulse_query, pulse_read and the
unified-resource context sections.

This deletes internal/servicediscovery, internal/ai/infradiscovery, the
pulse_discovery tool, the /api/discovery routes, the mock Discovery
fixtures, the Discovery tabs in the resource, guest, node and Docker host
drawers, the identified-service cards, readiness badges, provenance
markers, suggested web-interface URLs, the Workloads AI Context column,
the chat "Discovery is off" hint and the AI Service Context settings page.
The old settings route redirects to Assistant settings. The model-bound
sanitizer allow-list existed only to pass Discovery context through, so it
goes too, along with the CopyableCodeRow primitive that only the
Discovery tab used.

Network subnet discovery (/api/discover, the Infrastructure discovery
settings) and the discoveryTarget agent coordinates are separate features
and stay. Stored discovery_enabled, discovery_interval_hours and
discovery_model AI settings are ignored on load; the settings API decoder
is lenient, so older frontends saving those fields still succeed.
2026-10-11 22:20:25 +01:00

158 lines
4.5 KiB
Go

package ai
import (
"context"
"testing"
"time"
"github.com/rcourtman/pulse-go-rewrite/internal/ai/circuit"
"github.com/rcourtman/pulse-go-rewrite/internal/ai/knowledge"
"github.com/rcourtman/pulse-go-rewrite/internal/config"
)
type mockLearningProvider struct{}
func (m mockLearningProvider) FormatForContext() string { return "prefs" }
type mockProxmoxEventProvider struct{}
func (m mockProxmoxEventProvider) FormatForPatrol(duration time.Duration) string { return "events" }
type mockForecastProvider struct{}
func (m mockForecastProvider) FormatKeyForecasts() string { return "forecast" }
type stubInvestigationOrchestrator struct {
maxTurns int
timeout time.Duration
}
func (s *stubInvestigationOrchestrator) InvestigateFinding(ctx context.Context, finding *InvestigationFinding, autonomyLevel string) error {
return nil
}
func (s *stubInvestigationOrchestrator) GetInvestigationByFinding(findingID string) *InvestigationSession {
return nil
}
func (s *stubInvestigationOrchestrator) GetRunningCount() int { return 0 }
func (s *stubInvestigationOrchestrator) GetFixedCount() int { return 0 }
func (s *stubInvestigationOrchestrator) CanStartInvestigation() bool { return true }
func (s *stubInvestigationOrchestrator) ReinvestigateFinding(ctx context.Context, findingID, autonomyLevel string) error {
return nil
}
func (s *stubInvestigationOrchestrator) Shutdown(ctx context.Context) error { return nil }
func (s *stubInvestigationOrchestrator) SetInvestigationExecutionLimits(maxTurns int, timeout time.Duration) {
s.maxTurns = maxTurns
s.timeout = timeout
}
func TestApplyPatrolAutonomyConfigPublishesInvestigationExecutionLimits(t *testing.T) {
orchestrator := &stubInvestigationOrchestrator{}
patrol := &PatrolService{investigationOrchestrator: orchestrator}
service := &Service{
cfg: config.NewDefaultAIConfig(),
patrolService: patrol,
}
next := config.NewDefaultAIConfig()
next.PatrolAutonomyLevel = config.PatrolAutonomyApproval
next.PatrolInvestigationBudget = 27
next.PatrolInvestigationTimeoutSec = 420
if err := service.ApplyPatrolAutonomyConfig(next); err != nil {
t.Fatalf("ApplyPatrolAutonomyConfig: %v", err)
}
if orchestrator.maxTurns != 27 {
t.Fatalf("investigation max turns = %d, want 27", orchestrator.maxTurns)
}
if orchestrator.timeout != 7*time.Minute {
t.Fatalf("investigation timeout = %s, want 7m", orchestrator.timeout)
}
}
func TestPatrolService_Setters(t *testing.T) {
ps := NewPatrolService(nil, nil)
ks := &knowledge.Store{}
ps.SetKnowledgeStore(ks)
if ps.GetKnowledgeStore() != ks {
t.Fatalf("expected knowledge store to be set")
}
lp := mockLearningProvider{}
ps.SetLearningProvider(lp)
if ps.learningProvider == nil {
t.Fatalf("expected learning provider to be set")
}
pep := mockProxmoxEventProvider{}
ps.SetProxmoxEventProvider(pep)
if ps.proxmoxEventProvider == nil {
t.Fatalf("expected proxmox event provider to be set")
}
fp := mockForecastProvider{}
ps.SetForecastProvider(fp)
if ps.forecastProvider == nil {
t.Fatalf("expected forecast provider to be set")
}
tm := NewTriggerManager(TriggerManagerConfig{MaxPendingTriggers: 1})
ps.SetTriggerManager(tm)
if ps.GetTriggerManager() == nil {
t.Fatalf("expected trigger manager to be set")
}
}
func TestPatrolService_AdditionalSetters(t *testing.T) {
ps := NewPatrolService(nil, nil)
breaker := circuit.NewBreaker("test", circuit.Config{})
ps.SetCircuitBreaker(breaker)
if ps.circuitBreaker != breaker {
t.Fatalf("expected circuit breaker to be set")
}
engine := newTestRemediationEngine()
ps.SetRemediationEngine(engine)
if ps.GetRemediationEngine() != engine {
t.Fatalf("expected remediation engine to be set")
}
orchestrator := &stubInvestigationOrchestrator{}
ps.SetInvestigationOrchestrator(orchestrator)
if ps.GetInvestigationOrchestrator() != orchestrator {
t.Fatalf("expected investigation orchestrator to be set")
}
callbackCalled := false
ps.SetUnifiedFindingCallback(func(f *Finding) bool {
callbackCalled = true
return true
})
if ps.unifiedFindingCallback == nil {
t.Fatalf("expected unified finding callback to be set")
}
ps.unifiedFindingCallback(&Finding{})
if !callbackCalled {
t.Fatalf("expected unified finding callback to be invoked")
}
var resolvedID string
ps.SetUnifiedFindingResolver(func(id string) {
resolvedID = id
})
if ps.unifiedFindingResolver == nil {
t.Fatalf("expected unified finding resolver to be set")
}
ps.unifiedFindingResolver("finding-1")
if resolvedID != "finding-1" {
t.Fatalf("expected unified finding resolver to capture id, got %q", resolvedID)
}
}