mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-11-29 17:21:13 +01:00
An agent holding /api/agent/events open heard about findings, approvals and action completions, but not about the facts it most often has to react to: an alert firing or clearing, or a resource going down. Pulse already records those as resource changes that list_recent_changes reads; this publishes them live as alert.fired, alert.resolved and resource.status_changed, so agents and Pulse MCP --emit-notifications clients can react without polling. The monitor adapter tells an observer about each change after the store accepts it, with the resource ID resolved to the canonical identity it was stored under. Registry diffs are announced after the new generation is swapped in. Alert rows are announced only from the alert manager's live lifecycle callback through RecordLiveChange; lifecycle replay, active-alert reconciliation and imported history keep using RecordChange, so a restart never re-announces old alerts. Nothing new is persisted and nothing is read back from the store, so there are no extra disk writes. Payloads mirror the timeline record (changeId, kind, canonical resourceId, current name and type, from/to or alert identifier, type, level and resolution) and never carry alert messages, change reasons or command metadata. Only state transitions whose status field changed count as status events. Status changes are coalesced per resource over 30 seconds: the first is immediate, later ones fold into at most one event per window, and a flap that returns to the announced status publishes nothing. Change events carry the recording monitor's organization and reach only subscribers in that organization.
55 lines
1.7 KiB
Go
55 lines
1.7 KiB
Go
package agentcapabilities
|
|
|
|
import (
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestAgentActionableEventKindsReturnsDetachedKnownKinds(t *testing.T) {
|
|
got := AgentActionableEventKinds()
|
|
want := []string{
|
|
string(EventKindFindingCreated),
|
|
string(EventKindApprovalPending),
|
|
string(EventKindActionCompleted),
|
|
string(EventKindAlertFired),
|
|
string(EventKindAlertResolved),
|
|
string(EventKindResourceStatusChanged),
|
|
}
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("AgentActionableEventKinds() = %v, want %v", got, want)
|
|
}
|
|
|
|
got[0] = "mutated"
|
|
second := AgentActionableEventKinds()
|
|
if second[0] != string(EventKindFindingCreated) {
|
|
t.Fatalf("AgentActionableEventKinds returned aliased slice: %v", second)
|
|
}
|
|
}
|
|
|
|
func TestIsTransportEventKindPinsStreamPlumbing(t *testing.T) {
|
|
for _, kind := range []EventKind{EventKindStreamConnected, EventKindHeartbeat} {
|
|
if !IsTransportEventKind(string(kind)) {
|
|
t.Fatalf("%s must be transport plumbing", kind)
|
|
}
|
|
}
|
|
for _, kind := range AgentActionableEventKinds() {
|
|
if IsTransportEventKind(kind) {
|
|
t.Fatalf("%s must remain agent-actionable", kind)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSubscribeEventsDescriptionUsesSharedEventKinds(t *testing.T) {
|
|
description := SubscribeEventsDescription()
|
|
for _, kind := range append(AgentActionableEventKinds(), string(EventKindHeartbeat)) {
|
|
if !strings.Contains(description, kind) {
|
|
t.Fatalf("subscribe_events description missing %q: %s", kind, description)
|
|
}
|
|
}
|
|
// Change events point agents at the timeline read for surrounding history.
|
|
if !strings.Contains(description, ListRecentChangesCapabilityName) {
|
|
t.Fatalf("subscribe_events description must name %s: %s", ListRecentChangesCapabilityName, description)
|
|
}
|
|
}
|