@davoodmehraban89 / VELYQOR / commits / d641b32
Fork 0

Intelligence, Advanced Charting & Trading Platform

test(db): verify suspended gate cannot enqueue even with valid recipient consent

davoodmehraban89 committed Oct 22, 2026 at 23:43 UTC d641b32463727fcac57a23f1cca86d0e00ec8473
1 file changed +25 -1
db/tests/alert_runtime_invariants.sql
+25 -1
@@ -26,7 +26,19 @@ BEGIN
26 'triggeredAt','2026-10-22T12:01:00.000Z',
27 'eventId',event_id,
28 'highWater',1100,
29 - 'consecutive',1));
29 + 'consecutive',1),
30 + 'gate',jsonb_build_object(
31 + 'suspended',false,
32 + 'lastSampleAt','2026-10-22T12:01:00.000Z',
33 + 'lastAccepted',jsonb_build_object(
34 + 'timestamp','2026-10-22T12:01:00.000Z',
35 + 'provider','S1',
36 + 'symbol','USD_IRT_FREE',
37 + 'side','SELL',
38 + 'unit','IRT_PER_USD',
39 + 'price',1100
40 + )
41 + ));
42
43 -- Safe rule-state writes require no user notification at all.
44 SELECT * INTO result FROM public.alert_rule_commit(v_user,'threshold1',0,
@@ -61,6 +73,18 @@ BEGIN
73 INSERT INTO public.alert_notification_consents
74 (user_id,recipient_ref,channel,consented_at)
75 VALUES (v_user,v_recipient,'BALE',t-interval '10 minutes');
76 + -- Simulate a forged trigger with a suspended quality gate. It must not
77 + -- create any outbox record or advance revision even with valid consent.
78 + BEGIN
79 + PERFORM * FROM public.alert_rule_commit(v_user,'threshold1',1,
80 + jsonb_set(crossed_state,'{gate,suspended}','true'::jsonb),
81 + event_id,'BALE',v_recipient,t+interval '1 minute');
82 + RAISE EXCEPTION 'suspended gate enqueued an informational alert';
83 + EXCEPTION WHEN invalid_parameter_value THEN NULL;
84 + END;
85 + SELECT count(*) INTO n FROM public.notification_outbox WHERE user_id=v_user;
86 + IF n <> 0 THEN RAISE EXCEPTION 'suspended gate wrote outbox'; END IF;
87 +
88
89 -- Two changes happen in the SAME SQL transaction, no write half-completion.
90 SELECT * INTO result FROM public.alert_rule_commit(v_user,'threshold1',1,