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.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Desktop Swarm: tests for a send during a cut and the saved view after one (#2075)
0xken152e61b490270c
diff --git a/desktop/lib/super_tabs/controller.dart b/desktop/lib/super_tabs/controller.dartindex 9759623b7..cc6d2d576 100644--- a/desktop/lib/super_tabs/controller.dart+++ b/desktop/lib/super_tabs/controller.dart@@ -1471,15 +1471,17 @@ class SuperTabController extends ChangeNotifier {max(_readAt[id] ?? 0, snapshot?.readMarks[id] ?? 0);/// What the reader missed in [id] after [after] (backend catchUp.ts).- Future<SuperTabCatchUp> readCatchUp(String id, int after) async =>- SuperTabCatchUp.fromJson(- superTabMap(- await request(- 'GET',- '$_path/conversations/${Uri.encodeComponent(id)}/catch-up?after=$after',- ),- ),- );+ Future<SuperTabCatchUp> readCatchUp(+ String id,+ int after,+ ) async => SuperTabCatchUp.fromJson(+ superTabMap(+ await request(+ 'GET',+ '$_path/conversations/${Uri.encodeComponent(id)}/catch-up?after=$after',+ ),+ ),+ );late final _serverMarks = SuperTabReadMarkSender((id, sequence) => request(@@ -1583,6 +1585,10 @@ class SuperTabController extends ChangeNotifier {});}+ /// How many rows of [id] are kept for the saved view.+ @visibleForTesting+ int heldRows(String id) => _rows[id]?.length ?? 0;+void _keepRows(String id, List rows) {if (!_policy.drawsSaved) return;final kept = _rows[id] ??= {};diff --git a/desktop/test/super_tab_message_cap_test.dart b/desktop/test/super_tab_message_cap_test.dartindex 44132f131..c4fc7e4bb 100644--- a/desktop/test/super_tab_message_cap_test.dart+++ b/desktop/test/super_tab_message_cap_test.dart@@ -1,8 +1,10 @@import 'dart:async';+import 'dart:convert';import 'package:clock/clock.dart';import 'package:flutter_test/flutter_test.dart';import 'package:harness/super_tabs/controller.dart';+import 'package:harness/super_tabs/reading.dart';import 'support/super_tab_fixture.dart';@@ -83,6 +85,102 @@ void main() {expect(c.hasOlder('lead'), isTrue);});+ test('a message sent while a poll cuts shows once, newest, and leaves '+ 'nothing outgoing', () async {+ final server = ConversationServer();+ Completer<void>? post;+ final c = SuperTabController(+ tabId: 'tab',+ accountId: 'owner',+ save: server.save,+ initial: const {},+ pollInterval: Duration.zero,+ request: (method, path, {body}) async {+ if (method == 'POST') await post?.future;+ return server.request(method, path, body: body);+ },+ );+ addTearDown(c.dispose);+ await c.refresh();+ await pollThrough(server, c, 500);+ c.setDraft('lead', 'Please check the arm64 build');+ post = Completer<void>();++ final sending = c.send();+ await pumpEventQueue();+ // While it is on its way, a poll brings 50 more and cuts as many.+ await pollThrough(server, c, 50);+ expect(c.messages('lead'), hasLength(500));+ final outgoing = c.outgoing('lead');+ expect(outgoing, hasLength(1));+ expect(outgoing.single.state, SuperTabOutgoingState.sending);+ expect(outgoing.single.text, 'Please check the arm64 build');+ post.complete();+ await sending;++ final held = c.messages('lead');+ expect(held.last.text, 'Please check the arm64 build');+ expect(held.where((m) => m.text == 'Please check the arm64 build'), [+ held.last,+ ]);+ expect(held, hasLength(500));+ expect(c.outgoing('lead'), isEmpty);+ expect(c.hasOlder('lead'), isTrue);+ });++ test('the view saved right after a cut draws its last page and reads on '+ 'from it', () async {+ final server = ConversationServer();+ const reading = SuperTabReading(drawsSaved: true);+ final c = server.controller(reading: reading);+ addTearDown(c.dispose);+ await c.refresh();+ await pollThrough(server, c, 2000);++ final view = jsonDecode(jsonEncode(c.savedView)) as Map<String, dynamic>;+ final rows = (view['messages'] as List).cast<Map<String, dynamic>>();+ expect(rows.map((r) => r['sequence']), List.generate(100, (i) => i + 1901));+ expect(view['next'], {'sequence': 1901, 'id': 'message-1901'});++ final again = server.controller(reading: reading);+ addTearDown(again.dispose);+ again.drawSaved(view);+ expect(+ again.messages('lead').map((m) => m.sequence),+ List.generate(100, (i) => i + 1901),+ );+ expect(again.hasOlder('lead'), isTrue);++ // The Earlier row, pressed before any read has answered: the cursor is+ // the one the view saved.+ final reads = <String>[];+ server.onRead = reads.add;+ await again.loadMessages('lead', older: true);++ expect(+ reads.single,+ endsWith('messages?before=1901&beforeId=message-1901'),+ );+ expect(+ again.messages('lead').map((m) => m.sequence),+ List.generate(200, (i) => i + 1801),+ );+ });++ test('the rows kept for the saved view are cut with the messages', () async {+ final server = ConversationServer();+ final c = server.controller(+ reading: const SuperTabReading(drawsSaved: true),+ );+ addTearDown(c.dispose);+ await c.refresh();++ await pollThrough(server, c, 2000);++ expect(c.messages('lead'), hasLength(500));+ expect(c.heldRows('lead'), 500);+ });+test('rows from where the view lays its list out are never cut', () async {final server = ConversationServer();final c = server.controller();