Files
pipelines/app/test/features/attention/notify/notification_controller_test.dart
T
alan 767643d991 Open the run's artifact from notifications
Phone and browser notifications that carry an artifact open it full
screen in the artifact viewer, with an Open run action and the preview as
expanded text; pipelines://artifact deep links route to the viewer.
2026-11-12 18:56:26 +00:00

223 lines
7.8 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/attention/notify/notification_controller.dart';
import 'package:pipelines_app/features/attention/notify/notification_store.dart';
import 'package:pipelines_app/features/attention/notify/notification_models.dart';
import 'notification_test_support.dart';
void main() {
group('the seed never notifies', () {
test('an already failed and waiting list is silent', () async {
final attention = attentionController();
final bridge = FakeNotificationBridge();
final notify = NotificationController(
store: MemoryNotificationStore(),
bridge: bridge,
);
addTearDown(attention.dispose);
addTearDown(notify.dispose);
await attention.load();
await notify.load();
attention.seedRows([
runSummary(1, 'failed', diagnostic: 'Stage 3 stopped'),
runSummary(2, 'waiting'),
]);
expect(attention.transitions, isEmpty);
expect(publish(notify, attention), 0);
expect(bridge.shown, isEmpty);
});
});
group('a live transition notifies once', () {
test('the frame\'s own words and identity are used', () async {
final attention = attentionController();
final bridge = FakeNotificationBridge(permission: 'granted');
final notify = NotificationController(
store: MemoryNotificationStore(),
bridge: bridge,
);
addTearDown(attention.dispose);
addTearDown(notify.dispose);
await attention.load();
await notify.load();
expect(notify.canNotify, isTrue);
attention.seedRows([runSummary(1, 'running', name: 'nightly')]);
attention.observeFrame(
runFrame(
1,
'failed',
name: 'nightly',
title: 'Nightly audit',
diagnostic: 'Stage 3 stopped',
finishedAt: '2026-10-22T11:00:00Z',
),
);
expect(publish(notify, attention), 1);
final message = bridge.shown.single;
expect(message.title, 'A run failed');
expect(message.body, 'Nightly audit \u00b7 nightly');
expect(message.tag, '1:Failed');
expect(message.runId, 1);
});
test(
'an artifact transition opens the artifact and carries its metadata',
() async {
final attention = attentionController();
final bridge = FakeNotificationBridge(permission: 'granted');
final notify = NotificationController(
store: MemoryNotificationStore(),
bridge: bridge,
);
addTearDown(attention.dispose);
addTearDown(notify.dispose);
await attention.load();
await notify.load();
NotificationArtifact? opened;
notify.onOpenArtifact = (artifact) => opened = artifact;
attention.seedRows([runSummary(1, 'running')]);
attention.observeFrame(
runFrame(
1,
'failed',
extra: {
'artifact': {
'run_id': 1,
'sequence': 2,
'path': 'docs/a%2Fb.md',
'name': 'a/b.md',
'url': '/artifacts/1/2/public/docs/a%252Fb.md',
'media_type': 'text/markdown',
},
'preview': 'A short preview',
},
),
);
expect(publish(notify, attention), 1);
expect(bridge.shown.single.artifact?.mediaType, 'text/markdown');
bridge.taps.single!.call();
expect(opened?.url, '/artifacts/1/2/public/docs/a%252Fb.md');
},
);
test('a duplicate frame and a republished list stay silent', () async {
final attention = attentionController();
final bridge = FakeNotificationBridge(permission: 'granted');
final notify = NotificationController(
store: MemoryNotificationStore(),
bridge: bridge,
);
addTearDown(attention.dispose);
addTearDown(notify.dispose);
await attention.load();
await notify.load();
attention.seedRows([runSummary(1, 'running')]);
attention.observeFrame(runFrame(1, 'failed'));
expect(publish(notify, attention), 1);
attention.observeFrame(runFrame(1, 'failed'));
expect(attention.transitions, hasLength(1));
expect(publish(notify, attention), 0);
expect(bridge.shown, hasLength(1));
});
test('a reconnect reseed cannot replay the notification', () async {
final attention = attentionController();
final bridge = FakeNotificationBridge(permission: 'granted');
final notify = NotificationController(
store: MemoryNotificationStore(),
bridge: bridge,
);
addTearDown(attention.dispose);
addTearDown(notify.dispose);
await attention.load();
await notify.load();
attention.seedRows([runSummary(1, 'running')]);
attention.observeFrame(runFrame(1, 'failed'));
expect(publish(notify, attention), 1);
attention.resetForReconnect();
attention.seedRows([runSummary(1, 'failed')], reconnect: true);
expect(publish(notify, attention), 0);
attention.observeFrame(runFrame(1, 'failed'));
expect(publish(notify, attention), 0);
expect(bridge.shown, hasLength(1));
});
test('a rebuilt controller with the same store stays silent', () async {
final store = MemoryNotificationStore();
final bridge = FakeNotificationBridge(permission: 'granted');
final attention = attentionController();
final notify = NotificationController(store: store, bridge: bridge);
addTearDown(attention.dispose);
addTearDown(notify.dispose);
await attention.load();
await notify.load();
attention.seedRows([runSummary(1, 'running')]);
attention.observeFrame(runFrame(1, 'failed'));
expect(publish(notify, attention), 1);
await settle();
final restarted = NotificationController(store: store, bridge: bridge);
addTearDown(restarted.dispose);
await restarted.load();
expect(restarted.notified, contains('1:Failed'));
expect(publish(restarted, attention), 0);
expect(bridge.shown, hasLength(1));
});
test('a later failure of another run notifies independently', () async {
final attention = attentionController();
final bridge = FakeNotificationBridge(permission: 'granted');
final notify = NotificationController(
store: MemoryNotificationStore(),
bridge: bridge,
);
addTearDown(attention.dispose);
addTearDown(notify.dispose);
await attention.load();
await notify.load();
attention.seedRows([runSummary(1, 'running'), runSummary(2, 'running')]);
attention.observeFrame(runFrame(1, 'failed'));
expect(publish(notify, attention), 1);
attention.observeFrame(runFrame(2, 'failed'));
expect(publish(notify, attention), 1);
expect(bridge.shown, hasLength(2));
expect(bridge.shown.map((m) => m.tag), ['1:Failed', '2:Failed']);
});
test('a transition for a run that left is never re-posted', () async {
final attention = attentionController();
final bridge = FakeNotificationBridge(permission: 'granted');
final notify = NotificationController(
store: MemoryNotificationStore(),
bridge: bridge,
);
addTearDown(attention.dispose);
addTearDown(notify.dispose);
await attention.load();
await notify.load();
attention.seedRows([runSummary(1, 'running')]);
attention.observeFrame(runFrame(1, 'failed'));
expect(publish(notify, attention), 1);
// Publishing the leaving frame forgets the identity; republishing the
// accumulated list afterwards must not resurrect the old alert.
attention.observeFrame(runFrame(1, 'running'));
expect(publish(notify, attention), 0);
expect(publish(notify, attention), 0);
expect(bridge.shown, hasLength(1));
});
});
}