Pulse/internal/config/ai_usage_persistence_test.go
rcourtman 88d419dd5b feat(ai): Add enriched context with historical trends and predictions
Phase 1 of Pulse AI differentiation:

- Create internal/ai/context package with types, trends, builder, formatter
- Implement linear regression for trend computation (growing/declining/stable/volatile)
- Add storage capacity predictions (predicts days until 90% and 100%)
- Wire MetricsHistory from monitor to patrol service
- Update patrol to use buildEnrichedContext instead of basic summary
- Update patrol prompt to reference trend indicators and predictions

This gives the AI awareness of historical patterns, enabling it to:
- Identify resources with concerning growth rates
- Predict capacity exhaustion before it happens
- Distinguish between stable high usage vs growing problems
- Provide more actionable, time-aware insights

All tests passing. Falls back to basic summary if metrics history unavailable.
2025-12-12 09:45:57 +00:00

41 lines
858 B
Go

package config
import (
"testing"
"time"
)
func TestSaveLoadAIUsageHistory(t *testing.T) {
dir := t.TempDir()
cp := NewConfigPersistence(dir)
now := time.Now()
events := []AIUsageEventRecord{
{
Timestamp: now,
Provider: "openai",
RequestModel: "openai:gpt-4o",
InputTokens: 123,
OutputTokens: 45,
UseCase: "chat",
TargetType: "vm",
TargetID: "vm-101",
},
}
if err := cp.SaveAIUsageHistory(events); err != nil {
t.Fatalf("SaveAIUsageHistory: %v", err)
}
loaded, err := cp.LoadAIUsageHistory()
if err != nil {
t.Fatalf("LoadAIUsageHistory: %v", err)
}
if len(loaded.Events) != 1 {
t.Fatalf("expected 1 event, got %d", len(loaded.Events))
}
if loaded.Events[0].Provider != "openai" || loaded.Events[0].InputTokens != 123 {
t.Fatalf("loaded event mismatch: %+v", loaded.Events[0])
}
}