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.

feat(phone_desk): add polling mechanism for desk updates and enhance test coverage

Dev jacob73abbb3d7296
diff --git a/mobile/test/phone_desk_test.dart b/mobile/test/phone_desk_test.dart
index 63b9bc284..f72ac04ae 100644
--- a/mobile/test/phone_desk_test.dart
+++ b/mobile/test/phone_desk_test.dart
@@ -68,10 +68,13 @@ void main() {
late PhoneDesk desk;
var changes = 0;
- PhoneDesk deskOver(_Backend backend) => PhoneDesk(
+ PhoneDesk deskOver(_Backend backend, {Duration? poll}) => PhoneDesk(
read: backend.read,
write: backend.write,
onChanged: () => changes++,
+ // Fifteen seconds is the shipped beat; a test that waited one out would be
+ // fifteen seconds long.
+ pollInterval: poll ?? const Duration(seconds: 15),
);
setUp(() {
@@ -236,6 +239,38 @@ void main() {
expect(backend.received, hasLength(1));
});
+ test('a foreground phone keeps reading the desk on its own', () async {
+ // ⚠️ The regression this is here for: a phone left on one screen never saw
+ // a tab made on a computer. `desk_changed` reaches a phone only over a
+ // machine's relay socket, so a backend that does not forward it — or a
+ // moment with no machine connected — delivered nothing, and the reading of
+ // the desk this app made at launch was the last one it ever made.
+ desk = deskOver(backend, poll: const Duration(milliseconds: 10));
+ await join();
+ expect(desk.tabs, hasLength(2));
+
+ backend.edit([
+ {'op': 'tab.create', 'id': 't3', 'name': 'test', 'index': 2},
+ ]);
+ await Future<void>.delayed(const Duration(milliseconds: 40));
+
+ expect([for (final tab in desk.tabs) tab.name], [
+ 'Desktop',
+ 'Docker',
+ 'test',
+ ]);
+
+ // And nothing while the app is in somebody's pocket.
+ desk.pause();
+ backend.edit([
+ {'op': 'tab.close', 'id': 't3'},
+ ]);
+ final reads = backend.reads;
+ await Future<void>.delayed(const Duration(milliseconds: 40));
+ expect(backend.reads, reads);
+ expect(desk.tabs, hasLength(3));
+ });
+
test(
'a tab picked by hand is remembered, with where the phone was in it',
() async {