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.

Web: saved Super Tab view follow-ups (missing tabs, lock wait, account, signed-out boot); a restored Super Tab draws its saved view first again (#1791)

Jacob Pham6df49ca0ba93
diff --git a/desktop/lib/super_tabs/client.dart b/desktop/lib/super_tabs/client.dart
index 9d0f29b0f..9aa86b995 100644
--- a/desktop/lib/super_tabs/client.dart
+++ b/desktop/lib/super_tabs/client.dart
@@ -116,11 +116,17 @@ class SuperTabClient {
final _viewSavedAt = <String, DateTime>{};
final _viewVersions = <String, int>{};
+ /// The web's forgets beyond Desktop's: the Swarms a discovery no longer
+ /// lists, and the account leaving. Desktop forgets as it did with #1803.
+ bool get _forgetsWebOnly => _reading.drawsSaved && !_reading.confirmsSaved;
+
/// Only the account using this device keeps views on it: any other one,
/// after a reload too, is forgotten ([SuperTabSavedViews.claim]).
- void _claimViews() {
+ void _claimViews({String? leaving}) {
if (!_reading.drawsSaved) return;
- unawaited(_views.claim(_account).catchError((Object _) {}));
+ unawaited(
+ _views.claim(_account, leaving: leaving).catchError((Object _) {}),
+ );
}
/// Moves each time a Swarm's view is kept on this device: Settings' Clear
@@ -245,9 +251,10 @@ class SuperTabClient {
_viewSaves.clear();
_viewSavedAt.clear();
_viewVersions.clear();
+ final leaving = _account;
_account = account;
// Nothing of an account that left stays on this device.
- _claimViews();
+ _claimViews(leaving: _forgetsWebOnly ? leaving : null);
_generation++;
_discoveryTimer?.cancel();
_discovering = null;
@@ -366,6 +373,15 @@ class SuperTabClient {
discoveryError = null;
final hidden = Set<String>.unmodifiable({..._hidden, ..._creating});
onTabs!(tabs.values.toList(), hidden);
+ // Every page read: a Swarm not listed is no longer this account's.
+ // In the background: the lock another tab holds never delays tags.
+ if (_forgetsWebOnly) {
+ unawaited(
+ _views
+ .keepOnly(account, {...tabs.keys, ..._creating})
+ .catchError((Object _) {}),
+ );
+ }
await _readTags([
for (final id in tabs.keys)
if (!hidden.contains(id) &&
@@ -492,24 +508,30 @@ class SuperTabClient {
..onArrived = onMention;
_tagCounts.remove(id);
_loaded[id] = controller;
- Future<void> drawSaved() async {
- // Behind the lock shared with this browser's other tabs: one iOS has
- // suspended may hold it. Past a short wait, open with no saved view.
- final view = await _views
- .read(account, id)
- .timeout(_viewLockWait, onTimeout: () => null);
+ void drawSaved(Map<String, dynamic>? view) {
if (view != null && generation == _generation) {
controller.drawSaved(view);
}
}
// Desktop's saved view is a local file, read before the first read so
- // that read asks only for what changed since it.
- if (_reading.drawsSaved && _reading.confirmsSaved) await drawSaved();
+ // that read asks only for what changed since it. It waits its turn
+ // behind the views' other work; past a short wait, it opens with none.
+ if (_reading.drawsSaved && _reading.confirmsSaved) {
+ drawSaved(
+ await _views
+ .readInTurn(account, id)
+ .timeout(_viewLockWait, onTimeout: () => null),
+ );
+ }
controller.start();
// After the first read is asked for: reading and drawing a saved view
// takes the main thread a moment a phone's first read need not wait on.
- if (_reading.drawsSaved && !_reading.confirmsSaved) await drawSaved();
+ // Drawn when it is read, unless that read landed first; the open waits
+ // for neither.
+ if (_reading.drawsSaved && !_reading.confirmsSaved) {
+ unawaited(_views.read(account, id).then(drawSaved));
+ }
return controller;
}
diff --git a/desktop/lib/super_tabs/controller.dart b/desktop/lib/super_tabs/controller.dart
index 21c806dc9..aa3c616ed 100644
--- a/desktop/lib/super_tabs/controller.dart
+++ b/desktop/lib/super_tabs/controller.dart
@@ -571,11 +571,16 @@ class SuperTabController extends ChangeNotifier {
/// Draws a [savedView] kept from an earlier visit while the first read is
/// on its way, and holds its parts: the first read asks only for what
/// changed since, and replaces it. With [SuperTabReading.confirmsSaved] it
- /// only holds them, for that read to draw. One for another Swarm, one too old for
- /// its cursor, one that no longer parses, or one after a read has landed,
- /// draws nothing.
+ /// only holds them, for that read to draw. One for another Swarm, one too
+ /// old for its cursor, one that no longer parses, or one after a read has
+ /// landed or been refused, draws nothing.
void drawSaved(Map<String, dynamic> view) {
- if (!_policy.drawsSaved || snapshot != null || stateReads > 0) return;
+ if (!_policy.drawsSaved ||
+ accessRevoked ||
+ snapshot != null ||
+ stateReads > 0) {
+ return;
+ }
try {
if (view['format'] != superTabReadFormat) return;
final savedAt = DateTime.fromMillisecondsSinceEpoch(
diff --git a/desktop/lib/super_tabs/saved_view.dart b/desktop/lib/super_tabs/saved_view.dart
index 93be11022..d2026c982 100644
--- a/desktop/lib/super_tabs/saved_view.dart
+++ b/desktop/lib/super_tabs/saved_view.dart
@@ -1,3 +1,4 @@
+import 'dart:async';
import 'dart:convert';
import '../core/local_key_value_store.dart';
@@ -47,8 +48,7 @@ class SuperTabSavedViews {
}
}
- /// Puts [tabId] first in the account's index. Best effort when reading: a
- /// storage that refuses must not fail the open.
+ /// Puts [tabId] first in the account's index.
Future<void> _use(String account, String tabId) async {
final tabs = (await _tabs(account))..remove(tabId);
tabs.insert(0, tabId);
@@ -62,29 +62,54 @@ class SuperTabSavedViews {
}
/// The view saved for [tabId], or null: none, unreadable, another shape,
- /// or a storage that refuses (full, private mode). It never throws.
- Future<Map<String, dynamic>?> read(String account, String tabId) =>
+ /// or a storage that refuses (full, private mode). It never throws, and
+ /// never waits for this browser's lock: another tab may hold it (one iOS
+ /// suspended), and a phone's busy boot grants it a second late. One value
+ /// reads whole; only the index update after it takes the lock, best effort.
+ Future<Map<String, dynamic>?> read(String account, String tabId) async {
+ final view = await _readView(account, tabId);
+ if (view == null) return null;
+ // Unless it was forgotten meanwhile (lost access, another account).
+ unawaited(
_serial(() async {
- try {
- final raw = await storage.read(_key(account, tabId));
- if (raw == null) return null;
- final view = jsonDecode(raw);
- // A view an older build kept (a whole state, not parts) is none.
- if (view is! Map<String, dynamic> ||
- view['format'] != superTabReadFormat ||
- view['parts'] is! Map<String, dynamic> ||
- view['lastChangedAt'] is! int) {
- return null;
- }
- try {
- await _use(account, tabId);
- } catch (_) {}
- return view;
- } catch (_) {
- return null;
+ if (await storage.read(_key(account, tabId)) != null) {
+ await _use(account, tabId);
}
+ }).catchError((Object _) {}),
+ );
+ return view;
+ }
+
+ /// [read] in turn, after the saved-view work already queued, with the
+ /// index update in that turn: Desktop's, as #1803 made it.
+ Future<Map<String, dynamic>?> readInTurn(String account, String tabId) =>
+ _serial(() async {
+ final view = await _readView(account, tabId);
+ if (view == null) return null;
+ try {
+ await _use(account, tabId);
+ } catch (_) {}
+ return view;
});
+ Future<Map<String, dynamic>?> _readView(String account, String tabId) async {
+ try {
+ final raw = await storage.read(_key(account, tabId));
+ if (raw == null) return null;
+ final view = jsonDecode(raw);
+ // A view an older build kept (a whole state, not parts) is none.
+ if (view is! Map<String, dynamic> ||
+ view['format'] != superTabReadFormat ||
+ view['parts'] is! Map<String, dynamic> ||
+ view['lastChangedAt'] is! int) {
+ return null;
+ }
+ return view;
+ } catch (_) {
+ return null;
+ }
+ }
+
/// Keeps [view] for [tabId], and says whether it was kept; one over the
/// cap is not kept, and the older one goes with it rather than staying
/// behind, older still.
@@ -117,6 +142,15 @@ class SuperTabSavedViews {
await storage.write(_index(account), jsonEncode(tabs));
}
+ /// A complete discovery listed [tabIds]: the views of the account's other
+ /// Swarms go, one it lost while not open included.
+ Future<void> keepOnly(String account, Set<String> tabIds) =>
+ _serial(() async {
+ for (final tab in await _tabs(account)) {
+ if (!tabIds.contains(tab)) await _forget(account, tab);
+ }
+ });
+
/// Signing out, or another account: nothing of this one stays behind.
Future<void> forgetAccount(String account) =>
_serial(() => _forgetAccount(account));
@@ -139,9 +173,14 @@ class SuperTabSavedViews {
});
/// [account] (null when signed out) is the one using this device now: the
- /// views of any other account that used it, before a reload too, go.
- Future<void> claim(String? account) => _serial(() async {
+ /// views of any other account that used it, before a reload too, go, and
+ /// those of [leaving]: another tab may have kept one after it cleared
+ /// whose device this is.
+ Future<void> claim(String? account, {String? leaving}) => _serial(() async {
final owner = await storage.read(_owner);
+ if (leaving != null && leaving != account && leaving != owner) {
+ await _forgetAccount(leaving);
+ }
if (owner == account) return;
if (owner != null) await _forgetAccount(owner);
if (account == null) {
diff --git a/desktop/lib/web/onboarding/saved_computers.dart b/desktop/lib/web/onboarding/saved_computers.dart
index 69d9eb4e6..dde482ace 100644
--- a/desktop/lib/web/onboarding/saved_computers.dart
+++ b/desktop/lib/web/onboarding/saved_computers.dart
@@ -143,7 +143,14 @@ class SavedComputersWatch extends ChangeNotifier {
// Booting, nobody is known yet and nothing is forgotten; signed out (by
// hand, or a session that expired, at boot too), the last account's go.
final account = signedOut ? null : app.currentUser?.id;
- if (account != _account || (signedOut && !_forgotten)) _bind(account);
+ if (account != _account || (signedOut && !_forgotten)) {
+ _bind(account);
+ // The Super Tab views too, as Clear now: a boot signed out never binds
+ // the account they were kept for.
+ if (signedOut) {
+ unawaited(app.superTabs.clearSavedViews().catchError((Object _) {}));
+ }
+ }
// The list answering takes the kept computers off the page.
if (!identical(shown, _wasShown)) {
_wasShown = shown;
diff --git a/desktop/test/super_tab_saved_view_test.dart b/desktop/test/super_tab_saved_view_test.dart
index 07018e51e..4b7a45625 100644
--- a/desktop/test/super_tab_saved_view_test.dart
+++ b/desktop/test/super_tab_saved_view_test.dart
@@ -46,6 +46,7 @@ void main() {
group('the client', _clientTests);
group('review of #1723', _reviewTests);
group('re-review of #1727', _reReviewTests);
+ group('follow-ups of #1727', _followUpTests);
group('Clear now', _clearTests);
group('Desktop', _desktopTests);
@@ -282,6 +283,30 @@ void _controllerTests() {
});
});
+ // Review of #1791, 2: the saved read is no longer bounded.
+ test('a saved view read after the Swarm was refused draws nothing', () {
+ final server = ConversationServer()..append('Hello');
+ final view = _saved(server);
+ fakeAsync((async) {
+ final c = SuperTabController(
+ tabId: 'tab',
+ accountId: 'owner',
+ request: (method, path, {body}) => Future.error(
+ const SuperTabFailure('FORBIDDEN', 'You no longer have access.'),
+ ),
+ save: server.save,
+ initial: {'tabId': 'tab', 'accountId': 'owner', 'selectedId': 'lead'},
+ reading: _web,
+ )..start();
+ async.flushMicrotasks();
+ expect(c.accessRevoked, isTrue);
+ c.drawSaved(view);
+ expect(c.snapshot, isNull);
+ expect(c.showingSaved, isFalse);
+ c.dispose();
+ });
+ });
+
test('with no machine yet the saved view stays, without the error', () {
final server = ConversationServer()..append('Hello');
final view = _saved(server);
@@ -368,12 +393,16 @@ class _Transport {
final ConversationServer server;
Completer<void>? hold;
SuperTabFailure? refuse;
+
+ /// How long the backend takes to answer each read.
+ Duration delay = Duration.zero;
Future<Object?> call(
String method,
String path, {
Map<String, dynamic>? body,
}) async {
if (hold case final wait?) await wait.future;
+ if (delay > Duration.zero) await Future<void>.delayed(delay);
if (refuse case final failure?) throw failure;
if (Uri.parse(path).path == '/api/super-tabs/list') {
return {
@@ -657,6 +686,16 @@ class _TouchStore extends MemoryStore {
}
}
+/// A computer whose saved views read slowly: a busy disk, or the views'
+/// work queued ahead of this read.
+class _SlowViewStore extends MemoryStore {
+ @override
+ Future<String?> read(String key) => key.startsWith('super_tab.view.')
+ ? Future<void>.delayed(const Duration(seconds: 5))
+ .then((_) => super.read(key))
+ : super.read(key);
+}
+
/// Saves [server]'s Swarm as `owner` through a client on [store], then
/// leaves it, as a person does before closing the page.
void _visit(FakeAsync async, ConversationServer server, MemoryStore store) {
@@ -680,29 +719,72 @@ class _StuckLockStore extends MemoryStore
release.future.then((_) => action());
}
+/// A browser store whose lock nobody holds, granted late: a phone's boot
+/// keeps the main thread busy, and the fixture measured 0.2 to 1.5 s.
+class _SlowLockStore extends MemoryStore
+ implements SynchronizedLocalKeyValueStore {
+ @override
+ Future<T> synchronized<T>(String scope, Future<T> Function() action) =>
+ Future<void>.delayed(const Duration(milliseconds: 600))
+ .then((_) => action());
+}
+
void _reReviewTests() {
- // Minor a.
- test('a lock another tab holds delays the open no more than 250 ms', () {
+ // Minor a: no wait at all, rather than a bounded one.
+ test('a lock another tab holds neither delays the open nor hides its saved '
+ 'view, and the index stays whole', () {
fakeAsync((async) {
final server = ConversationServer()..append('Hello');
- final store = _StuckLockStore();
- final client = _client(_Transport(server), store)
+ final kept = MemoryStore();
+ _visit(async, server, kept);
+ // Two Swarms opened since: this one is the least recent.
+ for (final tab in ['b', 'c']) {
+ SuperTabSavedViews(kept).write('owner', tab, _view(tab: tab));
+ async.flushMicrotasks();
+ }
+ final store = _StuckLockStore()..values.addAll(kept.values);
+ final transport = _Transport(server)..hold = Completer<void>();
+ final client = _client(transport, store)
..bind('owner')
..show('tab');
SuperTabController? c;
client.open('tab').then((opened) => c = opened);
- async.elapse(const Duration(milliseconds: 249));
- expect(c, isNull);
- async.elapse(const Duration(milliseconds: 2));
- expect(c, isNotNull);
- expect(c!.showingSaved, isFalse);
+ async.flushMicrotasks();
+ expect(c!.showingSaved, isTrue);
expect(c!.messages('lead').single.text, 'Hello');
+ // Nothing is changed outside the lock: the index waits for it.
+ expect(store.values, kept.values);
+ // The other tab lets go: what waited for it runs, one at a time.
store.release.complete();
async.flushMicrotasks();
+ expect(store.values[_viewKey], kept.values[_viewKey]);
+ expect(jsonDecode(store.values['super_tab.views.owner']!), [
+ 'tab',
+ 'c',
+ 'b',
+ ]);
client.dispose();
});
});
+ test('a view read while its Swarm is being forgotten is not listed '
+ 'again', () async {
+ final kept = MemoryStore();
+ final before = SuperTabSavedViews(kept);
+ await before.claim('owner');
+ await before.write('owner', 'tab', _view());
+ final store = _StuckLockStore()..values.addAll(kept.values);
+ final views = SuperTabSavedViews(store);
+ // Lost access: the forget waits for the lock, the read does not.
+ final forgot = views.forget('owner', 'tab');
+ expect(await views.read('owner', 'tab'), isNotNull);
+ store.release.complete();
+ await forgot;
+ await pumpEventQueue();
+ expect(store.values[_viewKey], isNull);
+ expect(jsonDecode(store.values['super_tab.views.owner']!), isEmpty);
+ });
+
// Minor b.
test('after a sign-out elsewhere, a late write keeps nothing', () async {
final store = MemoryStore();
@@ -722,6 +804,264 @@ void _reReviewTests() {
});
}
+/// An account's Swarm list in two pages, the second refused until a test
+/// lets it answer: a discovery that fails partway.
+class _Pages {
+ bool refuseLast = true;
+ Future<Object?> call(
+ String method,
+ String path, {
+ Map<String, dynamic>? body,
+ }) async {
+ final uri = Uri.parse(path);
+ if (uri.path.endsWith('/mentions')) return {'mentions': <Object>[]};
+ if (uri.queryParameters['after'] == null) {
+ return {
+ 'tabs': [
+ {'id': 'tab', 'name': 'Pilot'},
+ ],
+ 'next': 'second',
+ };
+ }
+ if (refuseLast) {
+ throw const SuperTabFailure(
+ 'MACHINE_UNAVAILABLE',
+ 'Connect one of your machines to open Swarm.',
+ );
+ }
+ return {'tabs': <Object>[], 'next': null};
+ }
+}
+
+void _followUpTests() {
+ // Finding 7.
+ test('a complete discovery forgets the views of Swarms it no longer lists, '
+ 'a failed one forgets none', () async {
+ final store = MemoryStore();
+ final views = SuperTabSavedViews(store);
+ await views.claim('owner');
+ await views.write('owner', 'gone', _view(tab: 'gone'));
+ await views.write('owner', 'tab', _view());
+ final pages = _Pages();
+ final client = SuperTabClient(
+ transport: pages.call,
+ storage: store,
+ onTabs: (tabs, hidden) {},
+ discoveryInterval: Duration.zero,
+ )..reading = _web;
+ addTearDown(client.dispose);
+ client.bind('owner');
+ // A slow network fails the second page: the list is not known.
+ await client.refreshTabs();
+ expect(client.discoveryError, isNotNull);
+ expect(store.values['super_tab.view.owner.gone'], isNotNull);
+ pages.refuseLast = false;
+ await client.refreshTabs();
+ await pumpEventQueue();
+ expect(client.discoveryError, isNull);
+ expect(store.values['super_tab.view.owner.gone'], isNull);
+ expect(store.values[_viewKey], isNotNull);
+ expect(jsonDecode(store.values['super_tab.views.owner']!), ['tab']);
+ });
+
+ // Review of #1791, 1: an iPhone suspending the tab that holds the lock.
+ test('a lock another tab holds neither delays a discovery nor its tags, '
+ 'and the forget runs once it is free', () async {
+ final kept = MemoryStore();
+ final before = SuperTabSavedViews(kept);
+ await before.claim('owner');
+ await before.write('owner', 'gone', _view(tab: 'gone'));
+ final store = _StuckLockStore()..values.addAll(kept.values);
+ final pages = _Pages()..refuseLast = false;
+ final paths = <String>[];
+ final client = SuperTabClient(
+ transport: (method, path, {body}) {
+ paths.add(path);
+ return pages(method, path, body: body);
+ },
+ storage: store,
+ onTabs: (tabs, hidden) {},
+ discoveryInterval: Duration.zero,
+ )..reading = _web;
+ addTearDown(client.dispose);
+ client.bind('owner');
+ await client.refreshTabs().timeout(const Duration(seconds: 1));
+ expect(client.discoveryError, isNull);
+ expect(paths, contains('/api/super-tabs/tab/mentions?state=waiting'));
+ expect(store.values['super_tab.view.owner.gone'], isNotNull);
+ store.release.complete();
+ await pumpEventQueue();
+ expect(store.values['super_tab.view.owner.gone'], isNull);
+ });
+
+ // Review of #1791, 3.
+ test('a Swarm being created keeps its view through a discovery that does '
+ 'not list it yet', () async {
+ final store = MemoryStore();
+ final views = SuperTabSavedViews(store);
+ await views.claim('owner');
+ await views.write('owner', 'new', _view(tab: 'new'));
+ final client = SuperTabClient(
+ transport: (_Pages()..refuseLast = false).call,
+ storage: store,
+ onTabs: (tabs, hidden) {},
+ discoveryInterval: Duration.zero,
+ )..reading = _web;
+ addTearDown(client.dispose);
+ client
+ ..bind('owner')
+ ..deferTabDiscovery('new');
+ await client.refreshTabs();
+ await pumpEventQueue();
+ expect(client.discoveryError, isNull);
+ expect(store.values['super_tab.view.owner.new'], isNotNull);
+ expect(jsonDecode(store.values['super_tab.views.owner']!), ['new']);
+ });
+
+ // As main since #1803: Desktop's read waits its turn, at most 250 ms.
+ test('Desktop: a slow saved-view read still starts the open within '
+ '250 ms', () {
+ fakeAsync((async) {
+ final server = ConversationServer()..append('Hello');
+ final kept = MemoryStore();
+ _visit(async, server, kept);
+ final store = _SlowViewStore()..values.addAll(kept.values);
+ final paths = <String>[];
+ final transport = _Transport(server);
+ final client = SuperTabClient(
+ transport: (method, path, {body}) {
+ paths.add(path);
+ return transport.call(method, path, body: body);
+ },
+ storage: store,
+ discoveryInterval: Duration.zero,
+ )..reading = SuperTabReading.desktop;
+ client
+ ..bind('owner')
+ ..show('tab');
+ SuperTabController? c;
+ client.open('tab').then((opened) => c = opened);
+ async.elapse(const Duration(milliseconds: 250));
+ expect(c, isNotNull);
+ expect(
+ paths,
+ contains('/api/super-tabs/tab/conversations/lead/messages'),
+ );
+ client.dispose();
+ async.elapse(const Duration(seconds: 5));
+ });
+ });
+
+ // The web's forgets only: Desktop forgets as main does since #1803.
+ test(
+ 'Desktop keeps the view of a Swarm a discovery no longer lists',
+ () async {
+ final store = MemoryStore();
+ final views = SuperTabSavedViews(store);
+ await views.claim('owner');
+ await views.write('owner', 'gone', _view(tab: 'gone'));
+ final client = SuperTabClient(
+ transport: (_Pages()..refuseLast = false).call,
+ storage: store,
+ onTabs: (tabs, hidden) {},
+ discoveryInterval: Duration.zero,
+ )..reading = SuperTabReading.desktop;
+ addTearDown(client.dispose);
+ client.bind('owner');
+ await client.refreshTabs();
+ await pumpEventQueue();
+ expect(client.discoveryError, isNull);
+ expect(store.values['super_tab.view.owner.gone'], isNotNull);
+ },
+ );
+
+ test('Desktop keeps the view of the account leaving when the device names '
+ 'nobody', () async {
+ final store = MemoryStore();
+ final views = SuperTabSavedViews(store);
+ await views.claim('owner');
+ await views.write('owner', 'tab', _view());
+ final client = SuperTabClient(
+ transport: (_Pages()..refuseLast = false).call,
+ storage: store,
+ discoveryInterval: Duration.zero,
+ )..reading = SuperTabReading.desktop;
+ addTearDown(client.dispose);
+ client.bind('owner');
+ await pumpEventQueue();
+ store.values.remove('super_tab.saved_by');
+ client.bind(null);
+ await pumpEventQueue();
+ expect(store.values[_viewKey], isNotNull);
+ });
+
+ test('Desktop: a discovery reads and deletes no saved view', () async {
+ final store = _TouchStore();
+ final client =
+ SuperTabClient(
+ transport: (_Pages()..refuseLast = false).call,
+ storage: store,
+ onTabs: (tabs, hidden) {},
+ discoveryInterval: Duration.zero,
+ )
+ ..reading = SuperTabReading.desktop
+ ..bind('owner');
+ addTearDown(client.dispose);
+ await client.refreshTabs();
+ expect(client.discoveryError, isNull);
+ expect(store.touched.where((k) => k.contains('super_tab.view')), isEmpty);
+ });
+
+ // Minor b, left of it.
+ test('signing out forgets the account leaving, whoever the device names', () {
+ fakeAsync((async) {
+ final server = ConversationServer()..append('Hello');
+ final store = MemoryStore();
+ final client = _client(_Transport(server), store)
+ ..bind('owner')
+ ..show('tab');
+ client.open('tab');
+ async.elapse(const Duration(seconds: 1));
+ client.show(null);
+ async.flushMicrotasks();
+ expect(store.values[_viewKey], isNotNull);
+ // Another browser tab signed out, and this view was kept after it
+ // cleared whose device this is.
+ store.values.remove('super_tab.saved_by');
+ client.bind(null);
+ async.flushMicrotasks();
+ expect(
+ store.values.keys.where((k) => k.startsWith('super_tab.view')),
+ isEmpty,
+ );
+ });
+ });
+
+ // The 1.3.76 re-score: a warm boot waited for the server.
+ test('a lock a busy boot grants late still draws the saved view before a '
+ '5 s first read', () {
+ fakeAsync((async) {
+ final server = ConversationServer()..append('Hello');
+ final kept = MemoryStore();
+ _visit(async, server, kept);
+ final store = _SlowLockStore()..values.addAll(kept.values);
+ final transport = _Transport(server)..delay = const Duration(seconds: 5);
+ final client = _client(transport, store)
+ ..bind('owner')
+ ..show('tab');
+ SuperTabController? c;
+ client.open('tab').then((opened) => c = opened);
+ async.flushMicrotasks();
+ expect(c!.showingSaved, isTrue);
+ expect(c!.messages('lead').single.text, 'Hello');
+ // The fresh state, then its conversation, 5 s each, replace it.
+ async.elapse(const Duration(seconds: 10));
+ expect(c!.showingSaved, isFalse);
+ client.dispose();
+ });
+ });
+}
+
void _reviewTests() {
// Finding 1.
test('more than a page since the save leaves no gap in the transcript', () {
diff --git a/desktop/test/web_saved_computers_test.dart b/desktop/test/web_saved_computers_test.dart
index 5a652e1af..d0624d312 100644
--- a/desktop/test/web_saved_computers_test.dart
+++ b/desktop/test/web_saved_computers_test.dart
@@ -7,10 +7,12 @@ import 'package:harness/core/local_key_value_store.dart';
import 'package:harness/core/models.dart';
import 'package:harness/shared/theme/app_theme.dart' as grid;
import 'package:harness/state/app_state.dart';
+import 'package:harness/super_tabs/saved_view.dart';
import 'package:harness/web/onboarding/saved_computers.dart';
import 'package:harness/web/onboarding/web_first_machine.dart';
import 'package:harness/web/shell/web_workspace.dart';
+import 'super_tab_saved_view_test.dart' show savedViewForTest;
import 'swarm_state_test.dart' show MemoryStore, createApp;
/// Storage a full or private-mode browser hands out: every call throws.
@@ -290,6 +292,26 @@ void main() {
expect(storage.values['web.computers.saved_by'], isNull);
});
+ test('a browser that boots signed out forgets the last account\'s Super Tab views too', () async {
+ final storage = MemoryStore();
+ final views = SuperTabSavedViews(storage);
+ await views.claim('ann');
+ await views.write('ann', 'tab', savedViewForTest());
+ final app = createApp(store: storage);
+ addTearDown(app.dispose);
+ savedComputersOf(app);
+ await pumpEventQueue();
+ // Booting: who signed in is not known yet, so nothing is forgotten.
+ expect(storage.values['super_tab.view.ann.tab'], isNotNull);
+
+ app
+ ..status = AppStatus.unauthenticated
+ ..notifyListeners();
+ await pumpEventQueue();
+
+ expect(storage.values.keys.where((k) => k.startsWith('super_tab.view')), isEmpty);
+ });
+
testWidgets('the web frame keeps the computers from the app\'s start, before any workspace', (
tester,
) async {