Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Phone: a Swarm notice is told once, not again every 5 seconds (Dee) (#2473)

0xken1573456862021d
diff --git a/mobile/lib/swarm/swarm_asks.dart b/mobile/lib/swarm/swarm_asks.dart
index 56b5493d4..ebdde6149 100644
--- a/mobile/lib/swarm/swarm_asks.dart
+++ b/mobile/lib/swarm/swarm_asks.dart
@@ -118,6 +118,10 @@ class SwarmAsks extends ChangeNotifier {
/// The [SwarmReader.generation] whose asks were read, or need none.
int _settled = -1;
+ /// The read of the lists under way, if any: what waits here is known once
+ /// it ends.
+ Future<void>? get reading => _loading;
+
/// Decisions being answered: their buttons wait for the backend.
final Set<String> answering = {};
diff --git a/mobile/lib/swarm/swarm_inbox.dart b/mobile/lib/swarm/swarm_inbox.dart
index 720af14a3..d3420a003 100644
--- a/mobile/lib/swarm/swarm_inbox.dart
+++ b/mobile/lib/swarm/swarm_inbox.dart
@@ -253,6 +253,14 @@ class SwarmInbox extends ChangeNotifier {
/// phone notice tells.
void Function(SwarmNeed need)? onArrived;
+ /// Swarm [swarmId] was read, and [needs] already hold what that read
+ /// found: what takes a notice down once its need stays gone.
+ void Function(String swarmId)? onSwarmRead;
+
+ /// Swarms read during a read of the list, told once [needs] are worked
+ /// out at its end.
+ final _readDuringList = <String>{};
+
final _readers = <String, SwarmReader>{};
final _asks = <String, SwarmAsks>{};
final _threads = <String, SwarmThreads>{};
@@ -407,6 +415,25 @@ class SwarmInbox extends ChangeNotifier {
_polling = false;
}
_rebuild(told: _face != before);
+ final read = _readDuringList.toList();
+ _readDuringList.clear();
+ for (final id in read) {
+ if (_disposed) return;
+ if (_readers.containsKey(id)) onSwarmRead?.call(id);
+ }
+ }
+
+ /// [reader] answered a read: told after the reader's own notify, which
+ /// works out [needs] again, or at the end of the list read under way.
+ void _readerRead(String id, SwarmReader reader) {
+ scheduleMicrotask(() {
+ if (_disposed || !identical(_readers[id], reader)) return;
+ if (_polling) {
+ _readDuringList.add(id);
+ } else {
+ onSwarmRead?.call(id);
+ }
+ });
}
/// The next quick read while no computer can be asked ([_away]).
@@ -489,6 +516,7 @@ class SwarmInbox extends ChangeNotifier {
request: request,
upload: upload,
)..addListener(_relay);
+ reader.reads.addListener(() => _readerRead(id, reader));
reader.readMarks = SwarmReadMarks(reader, store: readMarks)
..addListener(_relay);
_asks[id] = SwarmAsks(reader)
diff --git a/mobile/lib/swarm/swarm_notices.dart b/mobile/lib/swarm/swarm_notices.dart
index 771b47964..6620cd795 100644
--- a/mobile/lib/swarm/swarm_notices.dart
+++ b/mobile/lib/swarm/swarm_notices.dart
@@ -51,41 +51,62 @@ SwarmNoticeMessage swarmNotice(SwarmNeed need) {
/// Posts a notice for each need that arrives ([SwarmInbox.onArrived]) unless
/// the person is already looking at it ([quiet]), and takes it down once the
-/// need is gone ([settle]): answered on the desktop, done, or no longer
-/// waiting.
+/// need is gone: answered on the desktop, done, or no longer waiting — missing
+/// from two reads of its Swarm in a row ([swarmRead]), as one read may miss
+/// it and the next have it again. One whose Swarm can no longer be read goes
+/// at once ([settle]).
///
/// The app icon counts the needs, as the drawer's waiting badge does, on each
/// read and whether or not a notice was posted; it is set only when the count
/// changes, and the first read sets it even at zero, over what an earlier run
/// left there.
class SwarmAnnouncer {
- SwarmAnnouncer(this.notices, {required this.quiet});
+ SwarmAnnouncer(this.notices, {required this.quiet, SwarmTold? told})
+ : told = told ?? SwarmTold();
final SwarmNotices notices;
/// The person sees [need] where they are: no notice.
final bool Function(SwarmNeed need) quiet;
- /// Keys of the notices posted and not yet taken down.
- final _posted = <String>{};
+ /// What this phone has told the account already: never told again.
+ final SwarmTold told;
+
+ /// The notices posted and not yet taken down: each key's Swarm.
+ final _posted = <String, String>{};
+
+ /// Posted notices whose need the last reads of its Swarm missed: how many
+ /// in a row.
+ final _missed = <String, int>{};
/// The count on the app icon; null before the first read.
int? _badge;
+ /// Posts [need]'s notice, once: a need that left a read and came back
+ /// (another way of reading answered without it, or the session was made
+ /// again) is not news (Dee's iPhone, 2026-11-01: one notice every 5
+ /// seconds).
void announce(SwarmNeed need) {
if (quiet(need)) return;
+ if (!told.add(need.key)) return;
final notice = swarmNotice(need);
- _posted.add(notice.key);
+ _posted[notice.key] = need.swarmId;
+ _missed.remove(notice.key);
unawaited(notices.showSwarm(notice));
}
- /// Takes down the notices of needs not in [needs], and counts [needs] on
- /// the app icon.
- void settle(List<SwarmNeed> needs) {
+ /// The needs as they are now ([needs]), counted on the app icon. A notice
+ /// whose need is back is no longer missed; one whose Swarm is not among
+ /// [readable] (off the account's list, or its access gone) is taken down at
+ /// once. [readable] null: the list is not read yet, and nothing goes.
+ void settle(List<SwarmNeed> needs, {Set<String>? readable}) {
final open = {for (final need in needs) need.key};
- for (final key in _posted.where((key) => !open.contains(key)).toList()) {
- _posted.remove(key);
- unawaited(notices.cancelSwarm(key));
+ for (final MapEntry(key: key, value: swarm) in _posted.entries.toList()) {
+ if (open.contains(key)) {
+ _missed.remove(key);
+ } else if (readable != null && !readable.contains(swarm)) {
+ _takeDown(key);
+ }
}
if (needs.length != _badge) {
_badge = needs.length;
@@ -93,9 +114,77 @@ class SwarmAnnouncer {
}
}
+ /// Swarm [swarmId] was read, and [needs] are what waits now: a notice of
+ /// its whose need this read missed, as the one before did, is taken down.
+ void swarmRead(String swarmId, List<SwarmNeed> needs) {
+ final open = {for (final need in needs) need.key};
+ for (final MapEntry(key: key, value: swarm) in _posted.entries.toList()) {
+ if (swarm != swarmId) continue;
+ if (open.contains(key)) {
+ _missed.remove(key);
+ continue;
+ }
+ final missed = (_missed[key] ?? 0) + 1;
+ if (missed >= 2) {
+ _takeDown(key);
+ } else {
+ _missed[key] = missed;
+ }
+ }
+ }
+
+ void _takeDown(String key) {
+ _posted.remove(key);
+ _missed.remove(key);
+ unawaited(notices.cancelSwarm(key));
+ }
+
/// Takes every notice and the icon's count down: the account that saw them
/// signed out, or Swarm was turned off.
- void clear() => settle(const []);
+ void clear() {
+ for (final key in _posted.keys.toList()) {
+ _takeDown(key);
+ }
+ settle(const []);
+ }
+}
+
+/// The notices this phone has posted for one account, by their keys
+/// ([SwarmNeed.key]: the decision's or tag's id, or the work's assignment and
+/// status): what [SwarmAnnouncer] never posts twice, however often its need
+/// leaves the reads and comes back. [SwarmHost] keeps one for the life of the
+/// app, so a session made again for the same account remembers too.
+///
+/// In memory only, ids only, at most [limit] keys, the oldest let go first.
+/// Another account starts it over ([account]).
+class SwarmTold {
+ SwarmTold({this.limit = 500});
+
+ final int limit;
+
+ /// Kept in the order told: a set literal is a [LinkedHashSet].
+ final _keys = <String>{};
+ String? _account;
+
+ /// Records [key]; false when it was told already.
+ bool add(String key) {
+ if (!_keys.add(key)) return false;
+ while (_keys.length > limit) {
+ _keys.remove(_keys.first);
+ }
+ return true;
+ }
+
+ /// Whose notices these are: another account, or none (Swarm turned off),
+ /// forgets every key.
+ set account(String? id) {
+ if (id == _account) return;
+ _account = id;
+ _keys.clear();
+ }
+
+ @visibleForTesting
+ int get length => _keys.length;
}
/// Takes the app icon's count off each time [app] finds nobody signed in
diff --git a/mobile/lib/swarm/swarm_session.dart b/mobile/lib/swarm/swarm_session.dart
index bb5400ed2..e4b9475cb 100644
--- a/mobile/lib/swarm/swarm_session.dart
+++ b/mobile/lib/swarm/swarm_session.dart
@@ -37,6 +37,7 @@ class SwarmSession extends ChangeNotifier {
this.undoWindow = swarmUndoWindow,
SwarmHomeCache? homeCache,
LocalKeyValueStore? readMarks,
+ SwarmTold? told,
}) : inbox = SwarmInbox(
accountId: accountId,
request: request,
@@ -49,9 +50,11 @@ class SwarmSession extends ChangeNotifier {
_announcer = SwarmAnnouncer(
notices,
quiet: (_) => !swarmLocalNotices || _screens > 0,
+ told: told,
);
inbox
..onArrived = announce
+ ..onSwarmRead = _swarmRead
..addListener(_needsChanged);
}
@@ -104,6 +107,38 @@ class SwarmSession extends ChangeNotifier {
/// Posts [need]'s notice, unless a Swarm screen is up.
void announce(SwarmNeed need) => _announcer.announce(need);
+ /// Swarms read whose decisions and tags are still being read: what the
+ /// read missed is counted once they are ([_countReads]).
+ final _readsToCount = <String>{};
+
+ void _swarmRead(String id) {
+ _readsToCount.add(id);
+ _countReads();
+ }
+
+ /// Tells the announcer of each Swarm read once what waits there is known:
+ /// a Swarm read again from nothing has no decisions or tags until they are
+ /// read again, which is not their being gone. While they cannot be read,
+ /// nothing counts as missed.
+ void _countReads() {
+ for (final id in _readsToCount.toList()) {
+ final asks = inbox.asks(id);
+ if (asks == null) {
+ _readsToCount.remove(id);
+ continue;
+ }
+ if (asks.loading) continue;
+ // The lists are read again after the Swarm: counted once they are.
+ if (asks.reading case final reading?) {
+ unawaited(reading.whenComplete(() => _disposed ? null : _countReads()));
+ continue;
+ }
+ _readsToCount.remove(id);
+ if (asks.error != null) continue;
+ _announcer.swarmRead(id, inbox.needs);
+ }
+ }
+
/// A screen shows Swarm [swarmId] closely (a conversation): it is read
/// every few seconds while Harness is in front, until no screen does.
void watch(String swarmId) {
@@ -178,7 +213,18 @@ class SwarmSession extends ChangeNotifier {
}
// What was read of a Swarm off the list, or out of reach, leaves memory.
peeks.keepOnly([for (final swarm in inbox.swarms) ?inbox.reader(swarm.id)]);
- _announcer.settle(inbox.needs);
+ _announcer.settle(
+ inbox.needs,
+ // A Swarm off the list, or out of reach, keeps no notice up.
+ readable: inbox.loaded
+ ? {
+ for (final swarm in inbox.swarms)
+ if (inbox.reader(swarm.id) case final reader?
+ when !reader.accessRevoked)
+ swarm.id,
+ }
+ : null,
+ );
// Answered somewhere else meanwhile, or out of the list while the Swarm
// is read again: nothing is sent, and a card that comes back says so.
final open = {for (final need in inbox.needs) need.key};
@@ -191,6 +237,7 @@ class SwarmSession extends ChangeNotifier {
_dropped.add(key);
}
if (gone.isNotEmpty) notifyListeners();
+ _countReads();
}
@override
@@ -282,6 +329,10 @@ class SwarmHost extends ChangeNotifier {
SwarmSession? session;
bool _foreground = true;
+ /// What the account was told on this phone, kept across its sessions: a
+ /// session made again (the account read again) tells none of it again.
+ final _told = SwarmTold();
+
/// No session yet, only because the account is on its way: Swarm is on and
/// someone is signed in, so Home shows its skeleton, not that Swarm is off.
bool get accountComing =>
@@ -308,6 +359,13 @@ class SwarmHost extends ChangeNotifier {
final wasOn = _on;
_on = on;
final id = on ? accountId() : null;
+ // Swarm off forgets what was told; a moment with no account does not, as
+ // the same account may be back at once. Another account starts over.
+ if (!on) {
+ _told.account = null;
+ } else if (id != null) {
+ _told.account = id;
+ }
if (id == session?.accountId) {
// Swarm off with no session to end: its switch is read before the first
// frame, so this is known, and what an earlier run kept goes. A missing
@@ -332,6 +390,7 @@ class SwarmHost extends ChangeNotifier {
notices: notices,
homeCache: homeCache,
readMarks: readMarks,
+ told: _told,
)..foreground = _foreground);
notifyListeners();
}
diff --git a/mobile/test/swarm/swarm_notice_repeat_test.dart b/mobile/test/swarm/swarm_notice_repeat_test.dart
new file mode 100644
index 000000000..47893c689
--- /dev/null
+++ b/mobile/test/swarm/swarm_notice_repeat_test.dart
@@ -0,0 +1,370 @@
+import 'package:flutter/foundation.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness_mobile/notify/system_notices.dart';
+import 'package:harness_mobile/settings/experimental_features.dart';
+import 'package:harness_mobile/swarm/swarm_home_cache.dart';
+import 'package:harness_mobile/swarm/swarm_notices.dart';
+import 'package:harness_mobile/swarm/swarm_session.dart';
+
+import '../voice_fakes.dart';
+import 'swarm_fixture.dart';
+
+/// Dee's iPhone (2026-11-01): the same notice came back every 5 seconds.
+/// Each thing a Swarm asks of the person is told once on this phone, however
+/// often it is read, however it is read, and across sessions.
+void main() {
+ TestWidgetsFlutterBinding.ensureInitialized();
+
+ late Backend backend;
+ late _Notices notices;
+ late ExperimentalFeaturesStore features;
+ late ValueNotifier<String?> account;
+ late SwarmHomeCache home;
+ late MemoryKeyValueStore store;
+
+ setUp(() async {
+ backend = Backend();
+ notices = _Notices();
+ features = ExperimentalFeaturesStore(storage: MemoryKeyValueStore());
+ await features.set(PhoneExperiment.swarm, true);
+ account = ValueNotifier(me);
+ home = memoryHomeCache();
+ store = MemoryKeyValueStore();
+ });
+
+ SwarmHost host({bool disposeAtEnd = true}) {
+ final h = SwarmHost(
+ accountId: () => account.value,
+ account: account,
+ request: backend.fake.request,
+ notices: notices,
+ features: features,
+ homeCache: home,
+ readMarks: store,
+ );
+ if (disposeAtEnd) addTearDown(h.dispose);
+ return h;
+ }
+
+ /// One read of the Swarm: through the list (each test moves its last
+ /// change, so it is read), or, [watched], as an open chat reads it on its
+ /// own every 5 seconds.
+ Future<void> poll(SwarmHost h, {bool watched = false}) async {
+ final inbox = h.session!.inbox;
+ final reader = inbox.reader('a');
+ if (watched && reader != null) {
+ await reader.refresh();
+ } else {
+ await inbox.refresh();
+ }
+ await settle();
+ }
+
+ /// What each notice told, by its key, in order.
+ List<String> told() => [for (final n in notices.shown) n.key];
+
+ /// Everything a Swarm can ask, arrived after the first read.
+ void everything() {
+ backend
+ ..decision('d1')
+ ..mention('t1')
+ ..stuck('g1')
+ ..needsYou('g2');
+ }
+
+ const all = [
+ 'decision:d1',
+ 'mention:t1',
+ 'work:a:g1:attempt-g1:blocked',
+ 'work:a:g2:attempt-g2:needs_human',
+ ];
+
+ test('read again and again, each ask is told once', () async {
+ final h = host();
+ h.foreground = false;
+ await poll(h);
+ everything();
+ for (var i = 0; i < 6; i++) {
+ backend.version++;
+ await poll(h);
+ }
+ expect(told()..sort(), [...all]..sort());
+ });
+
+ test('read again from nothing on each read, each ask is told once', () async {
+ final h = host();
+ h.foreground = false;
+ await poll(h);
+ everything();
+ backend.reload = true;
+ for (var i = 0; i < 6; i++) {
+ backend.version++;
+ await poll(h);
+ }
+ expect(told()..sort(), [...all]..sort());
+ });
+
+ test(
+ 'a session made again for the same account tells nothing again',
+ () async {
+ var h = host();
+ h.foreground = false;
+ await poll(h);
+ everything();
+ await poll(h);
+ expect(told()..sort(), [...all]..sort());
+ for (var i = 0; i < 4; i++) {
+ // The account read again: a moment with none, then the same one.
+ account.value = null;
+ account.value = me;
+ h.foreground = false;
+ backend.version++;
+ await poll(h);
+ await poll(h);
+ }
+ expect(told()..sort(), [...all]..sort());
+ },
+ );
+
+ test('what leaves a read and comes back at the next is told once', () async {
+ final h = host();
+ h.foreground = false;
+ await poll(h);
+ everything();
+ // Each read is the Swarm read again from nothing, by turns with and
+ // without what waits: the 5-second rhythm of Dee's notice.
+ backend.reload = true;
+ for (var i = 0; i < 8; i++) {
+ backend
+ ..hidden = i.isOdd
+ ..version += 1;
+ await poll(h, watched: i % 4 >= 2);
+ }
+ expect(told()..sort(), [...all]..sort());
+ expect(
+ notices.cancelled,
+ isEmpty,
+ reason: 'a need back at every other read stays on the lock screen',
+ );
+ });
+
+ test(
+ 'a need gone for two reads in a row has its notice taken down',
+ () async {
+ final h = host();
+ h.foreground = false;
+ await poll(h);
+ everything();
+ await poll(h);
+ expect(told()..sort(), [...all]..sort());
+
+ // Answered, tagged done, and the work moved on, all elsewhere.
+ backend
+ ..decisions = []
+ ..mentions = []
+ ..groups = [
+ groupData('g1', status: 'working'),
+ groupData('g2', status: 'working'),
+ ]
+ ..version += 1;
+ await poll(h);
+ expect(notices.cancelled, isEmpty, reason: 'one read may miss them');
+ backend.version++;
+ await poll(h);
+ expect(notices.cancelled..sort(), [...all]..sort());
+ },
+ );
+
+ test('a session made again tells nothing again, even when its first read '
+ 'misses what waits', () async {
+ final h = host();
+ h.foreground = false;
+ await poll(h);
+ everything();
+ await poll(h);
+ expect(told()..sort(), [...all]..sort());
+ backend.reload = true;
+ for (var i = 0; i < 3; i++) {
+ account.value = null;
+ account.value = me;
+ h.foreground = false;
+ backend
+ ..hidden = true
+ ..version += 1;
+ await poll(h);
+ backend
+ ..hidden = false
+ ..version += 1;
+ await poll(h);
+ }
+ expect(told()..sort(), [...all]..sort());
+ });
+
+ test('another account starts with nothing told', () async {
+ final h = host();
+ h.foreground = false;
+ await poll(h);
+ everything();
+ await poll(h);
+ expect(told(), hasLength(all.length));
+
+ // The same Swarm and asks, for the next account to sign in on this
+ // phone: news to them once their first read is done.
+ account.value = 'person-other';
+ h.foreground = false;
+ final kept = [...backend.decisions];
+ backend
+ ..decisions = []
+ ..reload = true
+ ..version += 1;
+ await poll(h);
+ backend
+ ..decisions = kept
+ ..version += 1;
+ await poll(h);
+ expect(told().where((k) => k == 'decision:d1'), hasLength(2));
+ });
+
+ test('a relaunch tells nothing again of what waits', () async {
+ var h = host(disposeAtEnd: false);
+ h.foreground = false;
+ await poll(h);
+ everything();
+ await poll(h);
+ await homeSaved(home);
+ expect(told()..sort(), [...all]..sort());
+
+ // The app closed and opened again: a new host over the same phone.
+ h.dispose();
+ h = host();
+ h.foreground = false;
+ for (var i = 0; i < 3; i++) {
+ backend.version++;
+ await poll(h);
+ }
+ expect(told()..sort(), [...all]..sort());
+ });
+
+ test('turning Swarm off forgets what was told', () async {
+ final h = host();
+ h.foreground = false;
+ await poll(h);
+ backend
+ ..decision('d1')
+ ..version += 1;
+ await poll(h);
+ expect(told(), ['decision:d1']);
+
+ await features.set(PhoneExperiment.swarm, false);
+ await features.set(PhoneExperiment.swarm, true);
+ h.foreground = false;
+ backend
+ ..decisions = []
+ ..reload = true
+ ..version += 1;
+ await poll(h);
+ backend
+ ..decision('d1')
+ ..version += 1;
+ await poll(h);
+ expect(told(), ['decision:d1', 'decision:d1']);
+ });
+
+ test('the record keeps the newest keys, at most its limit', () {
+ final record = SwarmTold(limit: 3);
+ for (final key in ['a', 'b', 'c', 'd']) {
+ expect(record.add(key), isTrue);
+ }
+ expect(record.length, 3);
+ expect(record.add('d'), isFalse, reason: 'newest kept');
+ expect(record.add('a'), isTrue, reason: 'oldest let go');
+ });
+}
+
+class _Notices extends SilentSystemNotices {
+ final shown = <SwarmNoticeMessage>[];
+ final cancelled = <String>[];
+
+ @override
+ Future<void> showSwarm(SwarmNoticeMessage message) async =>
+ shown.add(message);
+
+ @override
+ Future<void> cancelSwarm(String key) async => cancelled.add(key);
+}
+
+/// Swarm `a`, whose asks and waiting work a test sets as it goes.
+class Backend {
+ final fake = FakeSwarm();
+ var decisions = <Map<String, dynamic>>[];
+ var mentions = <Map<String, dynamic>>[];
+ var groups = <Map<String, dynamic>>[];
+ var reload = false;
+ var version = 2;
+
+ /// This read leaves the waiting work and asks out, as one answered another
+ /// way does (straight from the backend, or through a computer).
+ var hidden = false;
+
+ Map<String, dynamic> get derived => {
+ 'decisionsWaiting': decisions.length,
+ 'mentionsWaiting': mentions.length,
+ };
+
+ Backend() {
+ fake.routes['/api/super-tabs/list'] = (_) => {
+ 'tabs': [
+ {'id': 'a', 'name': 'Swarm a', 'ownerId': me, 'lastChangedAt': version},
+ ],
+ 'next': null,
+ };
+ fake.routes['/api/super-tabs/a/parts'] = (_) => firstLoad(
+ tabId: 'a',
+ derived: hidden ? const {} : derived,
+ lastChangedAt: version,
+ groups: hidden ? const [] : groups,
+ );
+ fake.routes['/api/super-tabs/a/changes'] = (_) => reload
+ ? {'reload': true}
+ : changes(
+ cursor: 'c$version',
+ derived: derived,
+ lastChangedAt: version,
+ groups: [
+ for (final g in groups) part(g['id'] as String, version, g),
+ ],
+ );
+ fake.routes['/api/super-tabs/a/decisions?state=open'] = (_) => {
+ 'decisions': decisions,
+ };
+ fake.routes['/api/super-tabs/a/mentions?state=waiting'] = (_) => {
+ 'mentions': mentions,
+ };
+ }
+
+ void decision(String id) => decisions = [
+ ...decisions,
+ {
+ 'id': id,
+ 'conversationId': 'g9',
+ 'askerName': 'River',
+ 'question': 'Ship it?',
+ 'options': ['Yes', 'No'],
+ },
+ ];
+
+ void mention(String id) => mentions = [
+ ...mentions,
+ {'id': id, 'conversationId': 'g9', 'messageId': 'm-$id'},
+ ];
+
+ void stuck(String id) {
+ groups = [...groups, groupData(id, status: 'blocked')];
+ version++;
+ }
+
+ void needsYou(String id) {
+ groups = [...groups, groupData(id, status: 'needs_human')];
+ version++;
+ }
+}
diff --git a/mobile/test/swarm/swarm_notices_test.dart b/mobile/test/swarm/swarm_notices_test.dart
index a2733098c..5296bda10 100644
--- a/mobile/test/swarm/swarm_notices_test.dart
+++ b/mobile/test/swarm/swarm_notices_test.dart
@@ -136,8 +136,12 @@ void main() {
announcer.settle([decision(), mention()]);
expect(notices.cancelled, isEmpty);
- // Answered on the desktop: the lock screen must stop asking.
+ // Answered on the desktop: the lock screen stops asking once two reads
+ // of its Swarm in a row miss it.
announcer.settle([mention()]);
+ announcer.swarmRead('tab-b', [mention()]);
+ expect(notices.cancelled, isEmpty, reason: 'one read may miss it');
+ announcer.swarmRead('tab-b', [mention()]);
expect(notices.cancelled, [decision().key]);
// Signed out: nothing of the account stays on the lock screen.
@@ -145,6 +149,35 @@ void main() {
expect(notices.cancelled, [decision().key, mention().key]);
});
+ test('a need missed by one read and back at the next stays up', () {
+ final notices = _Recording();
+ final announcer = SwarmAnnouncer(notices, quiet: (_) => false);
+ announcer.announce(decision());
+ for (var i = 0; i < 6; i++) {
+ final needs = i.isOdd ? <SwarmNeed>[decision()] : <SwarmNeed>[];
+ announcer.settle(needs);
+ announcer.swarmRead('tab-b', needs);
+ }
+ expect(notices.cancelled, isEmpty);
+ });
+
+ test("another Swarm's reads take nothing down", () {
+ final notices = _Recording();
+ final announcer = SwarmAnnouncer(notices, quiet: (_) => false);
+ announcer.announce(decision());
+ announcer.swarmRead('tab-other', const []);
+ announcer.swarmRead('tab-other', const []);
+ expect(notices.cancelled, isEmpty);
+ });
+
+ test('a Swarm that can no longer be read takes its notices down at once', () {
+ final notices = _Recording();
+ final announcer = SwarmAnnouncer(notices, quiet: (_) => false);
+ announcer.announce(decision());
+ announcer.settle(const [], readable: {'tab-other'});
+ expect(notices.cancelled, [decision().key]);
+ });
+
test('a need never shown is never taken down', () {
final notices = _Recording();
final announcer = SwarmAnnouncer(notices, quiet: (_) => true);