mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-04-28 11:30:15 +00:00
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.
41 lines
858 B
Go
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])
|
|
}
|
|
}
|