Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

test(ai): verify occurrence projection across JSON checkpoint replay

pulse-triage[bot]3f68a61c8dd9
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 5decceecf9..00c7e0f8d3 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -54,6 +54,10 @@ remain outside this guarantee. Legacy shell lookup retains its time tolerance;
events preceding the selected shell's exact opening are not projected into it.
`TestIncidentStore_CanonicalProjectionOccurrenceBounds` verifies both boundaries,
subsecond starts, unordered successors and unrelated alert/resource isolation.
+It also checkpoints all retained shells to JSON, reconstructs the incident store
+and replays a firing: projected identity/state stays identical and the unchanged
+checkpoint is not replaced. The canonical timeline stays in memory; this is not
+a durable event-store restart or installed-process write-rate measurement.
### Unchanged incident JSON checkpoints
diff --git a/internal/ai/memory/incidents_test.go b/internal/ai/memory/incidents_test.go
index 3540d5f53c..f7d6a7423c 100644
--- a/internal/ai/memory/incidents_test.go
+++ b/internal/ai/memory/incidents_test.go
@@ -1205,6 +1205,47 @@ func TestIncidentStore_CanonicalProjectionOccurrenceBounds(t *testing.T) {
if projected.Status != IncidentStatusResolved || projected.ClosedAt == nil || !projected.ClosedAt.Equal(end) || projected.Acknowledged {
t.Fatalf("another occurrence changed historical state: %+v", projected)
}
+
+ // Checkpoint all retained boundaries, not just an isolated closed
+ // shell. The canonical timeline remains in memory: this exercises
+ // JSON recovery and projection, not a durable event-store restart.
+ before, err := json.Marshal(projected)
+ if err != nil {
+ t.Fatal(err)
+ }
+ store.dataDir = t.TempDir()
+ store.filePath = store.dataDir + "/ai_incidents.json"
+ if err := store.saveToDisk(); err != nil {
+ t.Fatal(err)
+ }
+ reloaded := NewIncidentStore(IncidentStoreConfig{})
+ reloaded.filePath = store.filePath
+ if err := reloaded.loadFromDisk(); err != nil {
+ t.Fatal(err)
+ }
+ reloaded.SetResourceTimelineStore(canonical)
+ for i := 0; i < 10; i++ {
+ reloaded.RecordAlertFired(old)
+ }
+ if len(reloaded.incidents) != len(store.incidents) {
+ t.Fatal("checkpoint replay duplicated a retained occurrence")
+ }
+ after, err := json.Marshal(reloaded.GetTimelineByAlertAt(old.ID, start))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if string(before) != string(after) {
+ t.Fatalf("checkpoint replay changed projected identity or timeline:\nbefore %s\nafter %s", before, after)
+ }
+ // Keep persistence synchronous so a successful comparison proves
+ // no checkpoint replacement, rather than a scheduling observation.
+ reloaded.dataDir = store.dataDir
+ if err := reloaded.saveToDisk(); err != nil {
+ t.Fatal(err)
+ }
+ if got := reloaded.savesCompleted.Load(); got != 0 {
+ t.Fatalf("unchanged checkpoint replay replaced JSON %d times", got)
+ }
})
}
}