Agent notifications are system notifications, never in-app toasts
An agent's notify call now always posts an OS notification when permitted, whatever app is in front (only skipped while that chat is open in the focused page); no toast or chime. Without permission the tab title counts it. The browser's permission prompt is shown on the operator's first click. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -126,16 +126,17 @@ void main() {
|
||||
await gateway.controller.close();
|
||||
});
|
||||
|
||||
test('a focused page shows a toast that opens the chat', () async {
|
||||
test('a focused page on another chat still posts a system notification '
|
||||
'that opens the chat; nothing shows in the app', () async {
|
||||
await setUpWith();
|
||||
gateway.controller.add(_push(_notice('a')));
|
||||
await pump();
|
||||
|
||||
expect(bridge.shown, isEmpty);
|
||||
expect(toasts.single.headline, 'Release chat: Build done');
|
||||
expect(toasts.single.message, 'All tests pass');
|
||||
expect(bridge.shown.single.title, 'Release chat: Build done');
|
||||
expect(bridge.shown.single.body, 'All tests pass');
|
||||
expect(toasts, isEmpty);
|
||||
expect(page.badges, isEmpty);
|
||||
toasts.single.open();
|
||||
bridge.taps.first!();
|
||||
expect(opened, ['ses_1']);
|
||||
});
|
||||
|
||||
@@ -152,8 +153,8 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test('an unfocused page posts a system notification and badges the title; '
|
||||
'focus clears the badge', () async {
|
||||
test('an unfocused page posts a system notification, even for the chat '
|
||||
'in view', () async {
|
||||
await setUpWith();
|
||||
page.current = PagePresence.hidden;
|
||||
active = 'ses_1'; // In view but not looked at: still notified.
|
||||
@@ -168,60 +169,49 @@ void main() {
|
||||
expect(bridge.shown.first.tag, 'chat:ses_1:notify:a');
|
||||
expect(bridge.shown.first.body, 'All tests pass');
|
||||
expect(toasts, isEmpty);
|
||||
expect(page.badges, [1, 2]);
|
||||
expect(notices.badge, 2);
|
||||
expect(page.badges, isEmpty);
|
||||
expect(page.chimes, 0);
|
||||
bridge.taps.first!();
|
||||
expect(opened, ['ses_1']);
|
||||
});
|
||||
|
||||
test('a low priority notice is a system notification too', () async {
|
||||
await setUpWith();
|
||||
page.current = PagePresence.visible;
|
||||
gateway.controller.add(_push(_notice('low', priority: 2)));
|
||||
await pump();
|
||||
expect(bridge.shown, hasLength(1));
|
||||
expect(toasts, isEmpty);
|
||||
});
|
||||
|
||||
test('without notification permission only the tab title counts it, and '
|
||||
'focus clears the count', () async {
|
||||
await setUpWith(permission: 'default', secure: false);
|
||||
page.current = PagePresence.hidden;
|
||||
gateway.controller.add(_push(_notice('a', priority: 4)));
|
||||
await pump();
|
||||
|
||||
expect(notifications.canNotify, isFalse);
|
||||
expect(bridge.shown, isEmpty);
|
||||
expect(toasts, isEmpty);
|
||||
expect(page.badges, [1]);
|
||||
expect(page.chimes, 0);
|
||||
|
||||
page.current = PagePresence.focused;
|
||||
page.focus.add(null);
|
||||
await pump();
|
||||
expect(page.badges.last, 0);
|
||||
expect(notices.badge, 0);
|
||||
});
|
||||
|
||||
test('a low priority notice waits as a toast on a visible page and posts '
|
||||
'only when the page is hidden', () async {
|
||||
await setUpWith();
|
||||
page.current = PagePresence.visible;
|
||||
gateway.controller.add(_push(_notice('low', priority: 2)));
|
||||
await pump();
|
||||
expect(bridge.shown, isEmpty);
|
||||
expect(toasts, hasLength(1));
|
||||
expect(page.badges, [1]);
|
||||
expect(page.chimes, 0);
|
||||
|
||||
page.current = PagePresence.hidden;
|
||||
gateway.controller.add(_push(_notice('low2', priority: 2)));
|
||||
await pump();
|
||||
expect(bridge.shown, hasLength(1));
|
||||
});
|
||||
|
||||
test(
|
||||
'an insecure page falls back to a toast, a title count and a chime',
|
||||
() async {
|
||||
await setUpWith(permission: 'default', secure: false);
|
||||
page.current = PagePresence.hidden;
|
||||
gateway.controller.add(_push(_notice('a', priority: 4)));
|
||||
await pump();
|
||||
|
||||
expect(notifications.canNotify, isFalse);
|
||||
expect(bridge.shown, isEmpty);
|
||||
expect(toasts.single.headline, 'Release chat: Build done');
|
||||
expect(page.badges, [1]);
|
||||
expect(page.chimes, 1);
|
||||
},
|
||||
);
|
||||
|
||||
test('a refused system notification falls back to the toast', () async {
|
||||
test('a refused system notification is counted in the tab title', () async {
|
||||
await setUpWith();
|
||||
bridge.accepts = false;
|
||||
page.current = PagePresence.hidden;
|
||||
gateway.controller.add(_push(_notice('a')));
|
||||
await pump();
|
||||
expect(bridge.shown, hasLength(1));
|
||||
expect(toasts, hasLength(1));
|
||||
expect(toasts, isEmpty);
|
||||
expect(page.badges, [1]);
|
||||
});
|
||||
|
||||
test('other notification kinds are left to their own surfaces', () async {
|
||||
@@ -243,7 +233,7 @@ void main() {
|
||||
gateway.backlog = [_notice('a')];
|
||||
await notices.connected();
|
||||
await pump();
|
||||
expect(toasts, hasLength(1));
|
||||
expect(bridge.shown, hasLength(1));
|
||||
},
|
||||
);
|
||||
|
||||
@@ -259,7 +249,7 @@ void main() {
|
||||
await notices.connected();
|
||||
await pump();
|
||||
expect(gateway.calls, ['subscribe_notifications']);
|
||||
expect(toasts.map((t) => t.headline), ['Release chat: Build done']);
|
||||
expect(bridge.shown.map((m) => m.title), ['Release chat: Build done']);
|
||||
|
||||
// The ledger persisted both chat_notify ids, so a reload shows neither.
|
||||
final stored = decodeNotificationLedger(store.stored);
|
||||
@@ -274,11 +264,11 @@ void main() {
|
||||
bridge: bridge,
|
||||
);
|
||||
await notifications.load();
|
||||
toasts.clear();
|
||||
bridge.shown.clear();
|
||||
notices = build();
|
||||
await notices.connected();
|
||||
await pump();
|
||||
expect(toasts, isEmpty);
|
||||
expect(bridge.shown, isEmpty);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -310,7 +300,7 @@ void main() {
|
||||
'notifications': [_notice('missed', age: const Duration(minutes: 5))],
|
||||
});
|
||||
await pump();
|
||||
expect(toasts.single.headline, 'Release chat: Build done');
|
||||
expect(bridge.shown.single.title, 'Release chat: Build done');
|
||||
});
|
||||
|
||||
test('a replay shows at most the newest few and never chimes', () async {
|
||||
@@ -322,7 +312,7 @@ void main() {
|
||||
];
|
||||
await notices.connected();
|
||||
await pump();
|
||||
expect(toasts, hasLength(agentNoticeReplayLimit));
|
||||
expect(toasts, isEmpty);
|
||||
expect(page.chimes, 0);
|
||||
expect(page.badges.last, agentNoticeReplayLimit);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user