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;
+24 -5
View File
@@ -7,10 +7,11 @@
// replaced with a recording spy before the app loads, and the real browser
// permission is granted (or denied) through CDP, so the drive proves the real
// bridge's behaviour: the initial seed raises nothing, one live transition
// raises exactly one notification with the entry's own words and run+kind+marker
// identity, a dismissed transition and a reconnect replay raise none, and the
// Settings tile reads honestly in every state on both hosts at 320 logical px
// and 2x text. One PNG is written per captured state.
// raises exactly one notification with the entry's own words and run+kind
// identity, a dismissed transition and a reconnect replay raise none, a second
// decision gate of one run raises a fresh notification (the waiting shape has no
// finished_at), and the Settings tile reads honestly in every state on both
// hosts at 320 logical px and 2x text. One PNG is written per captured state.
import { createServer } from 'node:http';
import { spawn } from 'node:child_process';
import { once } from 'node:events';
@@ -217,7 +218,7 @@ try {
check('transition count', posted.length === 1, JSON.stringify(posted));
check('transition title', posted[0].title === 'A run failed', JSON.stringify(posted[0]));
check('transition body', posted[0].body === 'Nightly audit · nightly', JSON.stringify(posted[0]));
check('transition identity', /^1:Failed@/.test(posted[0].tag), JSON.stringify(posted[0]));
check('transition identity', posted[0].tag === '1:Failed', JSON.stringify(posted[0]));
await capture('notification-transition-material-dark-320-2x.png');
captures.push('notification-transition-material-dark-320-2x.png');
@@ -233,6 +234,24 @@ try {
check('reconnect posted once', reconnectReport.includes('posted=1'), reconnectReport);
check('reconnect count', JSON.parse(await notifications()).length === 1, await notifications());
// 4b. A second decision gate of one run notifies again. The waiting frames
// carry no finished_at, so the run's timestamps cannot tell the gates apart.
await navigate({ mode: 'secondgate' });
const secondGateReport = await waitForReport('secondgate');
check('second gate posted twice', secondGateReport.includes('posted=2'), secondGateReport);
const gates = JSON.parse(await notifications());
check('second gate count', gates.length === 2, JSON.stringify(gates));
check(
'second gate identity',
gates.every((item) => item.tag === '7:Decision'),
JSON.stringify(gates),
);
check(
'second gate title',
gates.every((item) => item.title === 'A run needs your decision'),
JSON.stringify(gates),
);
// 5. A denied page is honest and posts nothing.
await deny();
await navigate({ mode: 'denied', semantics: true });