feat(app): notification capability with transition dedupe

This commit is contained in:
2026-10-22 02:05:20 +01:00
parent 7718604268
commit b8e5c3e7e3
13 changed files with 871 additions and 393 deletions
+37 -11
View File
@@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
import 'package:pipelines_app/features/attention/domain/attention_models.dart';
import 'package:pipelines_app/features/attention/notify/notification_bridge.dart';
import 'package:pipelines_app/features/attention/notify/notification_controller.dart';
import 'package:pipelines_app/features/attention/notify/notification_ledger.dart';
import 'package:pipelines_app/features/attention/notify/notification_models.dart';
import 'package:pipelines_app/features/attention/notify/notification_store.dart';
import 'package:pipelines_app/features/attention/runtime/attention_controller.dart';
@@ -17,8 +18,9 @@ import 'package:pipelines_app/features/attention/ui/notification_permission_tile
///
/// It drives the real [NotificationController] over the real web bridge, so a
/// browser drive can prove the seed is silent, one live transition raises
/// exactly one notification with the entry's own words and identity, a dismissed
/// or replayed transition raises none, and the Settings tile reads honestly in
/// exactly one notification with the entry's own words and run+kind identity, a
/// dismissed or replayed transition raises none, a second decision gate of one
/// run raises a fresh notification, and the Settings tile reads honestly in
/// every state on both hosts. Nothing here opens a socket or touches real
/// operator data; the store is in memory.
void main() {
@@ -89,7 +91,10 @@ Map<String, dynamic> _summary(
'status': status,
'diagnostic': diagnostic,
'created_at': _at(const Duration(hours: 1)),
'finished_at': _at(const Duration(minutes: 55)),
// The server leaves finished_at empty while a run is in flight or waiting.
'finished_at': status == 'waiting' || status == 'running'
? ''
: _at(const Duration(minutes: 55)),
};
Map<String, dynamic> _frame(
@@ -105,9 +110,20 @@ Map<String, dynamic> _frame(
'title': title ?? 'Run $id',
'status': status,
'diagnostic': diagnostic,
'finished_at': _at(const Duration(minutes: 1)),
'finished_at': status == 'waiting' || status == 'running'
? ''
: _at(const Duration(minutes: 1)),
};
/// Publish exactly as the manager wires it: the accumulated transitions and the
/// current qualifying keys from the same attention snapshot.
int _publish(NotificationController notify, AttentionController attention) =>
notify.publishTransitions(
attention.transitions,
qualifying: notificationQualifyingKeys(attention.rows),
dismissed: attention.dismissed,
);
/// Runs one notification scenario against the real bridge, then reports it and
/// draws the live permission tile underneath.
class _NotificationProbe extends StatefulWidget {
@@ -147,27 +163,37 @@ class _NotificationProbeState extends State<_NotificationProbe> {
_summary(1, 'failed', diagnostic: 'Stage 3 stopped'),
_summary(2, 'waiting'),
]);
notify.publishTransitions(attention.transitions);
_publish(notify, attention);
case 'dismissed':
attention.seedRows([_summary(1, 'running')]);
await attention.dismiss(attentionEntryFor(_summary(1, 'failed'))!);
attention.observeFrame(_frame(1, 'failed'));
notify.publishTransitions(attention.transitions);
_publish(notify, attention);
case 'reconnect':
attention.seedRows([_summary(1, 'running')]);
attention.observeFrame(_frame(1, 'failed'));
notify.publishTransitions(attention.transitions);
_publish(notify, attention);
attention.resetForReconnect();
attention.seedRows([_summary(1, 'failed')], reconnect: true);
notify.publishTransitions(attention.transitions);
_publish(notify, attention);
attention.observeFrame(_frame(1, 'failed'));
notify.publishTransitions(attention.transitions);
_publish(notify, attention);
case 'secondgate':
// A waiting run has no finished_at, so two gates of one run carry the
// same timestamps; leaving the state is what makes the second new.
attention.seedRows([_summary(7, 'running')]);
attention.observeFrame(_frame(7, 'waiting'));
_publish(notify, attention);
attention.observeFrame(_frame(7, 'running'));
_publish(notify, attention);
attention.observeFrame(_frame(7, 'waiting'));
_publish(notify, attention);
case 'denied':
case 'unsupported':
case 'default':
attention.seedRows([_summary(1, 'running')]);
attention.observeFrame(_frame(1, 'failed'));
notify.publishTransitions(attention.transitions);
_publish(notify, attention);
default:
attention.seedRows([_summary(1, 'running', name: 'nightly')]);
attention.observeFrame(
@@ -179,7 +205,7 @@ class _NotificationProbeState extends State<_NotificationProbe> {
diagnostic: 'Stage 3 stopped',
),
);
notify.publishTransitions(attention.transitions);
_publish(notify, attention);
}
if (!mounted) return;