MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / TestProtectionEvents_Idempotent

Function TestProtectionEvents_Idempotent

internal/identity/screening_test.go:112–141  ·  view source on GitHub ↗

TestProtectionEvents_Idempotent proves a deterministic id makes re-screening (e.g. an MTA-retried inbound delivery) a no-op rather than a duplicate.

(t *testing.T)

Source from the content-addressed store, hash-verified

110// TestProtectionEvents_Idempotent proves a deterministic id makes re-screening (e.g.
111// an MTA-retried inbound delivery) a no-op rather than a duplicate.
112func TestProtectionEvents_Idempotent(t *testing.T) {
113 pool := testutil.TestDB(t)
114 store := identity.NewStore(pool)
115 ctx := context.Background()
116
117 const msgID = "msg_idemp1"
118 agentID := seedProtAgent(t, store, ctx, "agent@idem.example.com", "idem.example.com")
119 ev := identity.ProtectionEvent{
120 ID: identity.DeterministicProtectionEventID(msgID, identity.ScreeningSourceScan, identity.ReviewReasonInboundScan, "heuristics"),
121 MessageID: msgID,
122 AgentID: agentID,
123 Direction: "inbound",
124 Source: identity.ScreeningSourceScan,
125 Reason: identity.ReviewReasonInboundScan,
126 Action: "review",
127 Detector: "heuristics",
128 }
129 for i := 0; i < 3; i++ {
130 if err := store.CreateProtectionEvent(ctx, ev); err != nil {
131 t.Fatalf("insert %d: %v", i, err)
132 }
133 }
134 got, err := store.ListProtectionEventsByMessage(ctx, msgID)
135 if err != nil {
136 t.Fatalf("list: %v", err)
137 }
138 if len(got) != 1 {
139 t.Errorf("idempotent insert produced %d rows, want 1", len(got))
140 }
141}
142
143// TestProtectionEvents_SoftRefAndAgentList proves message_id is a soft reference
144// (events insert and list with no corresponding messages row — so the audit trail

Callers

nothing calls this directly

Calls 6

CreateProtectionEventMethod · 0.95
TestDBFunction · 0.92
NewStoreFunction · 0.92
seedProtAgentFunction · 0.85

Tested by

no test coverage detected