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.

test(mobile): bring pager agents live with a real keyframe

Dev jacob15f9956d07d1
diff --git a/mobile/test/agent_pager_fixture.dart b/mobile/test/agent_pager_fixture.dart
index d3a7d5a92..c00aba6f1 100644
--- a/mobile/test/agent_pager_fixture.dart
+++ b/mobile/test/agent_pager_fixture.dart
@@ -1,9 +1,13 @@
+import 'dart:convert';
+import 'dart:typed_data';
+
import 'package:harness_mobile/auth/auth_session.dart';
import 'package:harness_mobile/core/config.dart';
import 'package:harness_mobile/core/models.dart';
import 'package:harness_mobile/phone/agent_index.dart';
import 'package:harness_mobile/phone/agent_swipe_list.dart';
import 'package:harness_mobile/state/app_state.dart';
+import 'package:harness_mobile/terminal/terminal_binary.dart';
import 'package:harness_mobile/terminal/terminal_session.dart';
import 'package:harness_mobile/viewer/viewer_key_store.dart';
import 'package:harness_mobile/viewer/viewer_services.dart';
@@ -103,7 +107,7 @@ AgentSwipeList pagerList(AppNotifier app) => AgentSwipeList([
]);
/// The agent on screen, live at a phone's size.
-TerminalSession liveAgent(AppNotifier app, String agentId) {
+Future<TerminalSession> liveAgent(AppNotifier app, String agentId) async {
final session = TerminalSession(
machineId: 'm',
agentId: agentId,
@@ -113,17 +117,31 @@ TerminalSession liveAgent(AppNotifier app, String agentId) {
sendBinary: (_) async => true,
);
app.adoptSessionForTest(session);
- goLive(session);
+ await goLive(session);
return session;
}
-/// What a keyframe arriving does to a session, without a machine to send one: controlling, at the
-/// phone's size, and the notifier told — which is the signal the pager waits on.
-void goLive(TerminalSession session) {
- session
- ..status = TerminalSessionStatus.controlling
- ..streamId = 'stream-${session.agentId}'
- ..cols = 46
- ..rows = 38
- ..renameAgent('${session.agentName} (live)');
+/// The machine's first keyframe landing on [session]: a screen, at a phone's size.
+///
+/// ⚠️ **A keyframe, not fields set by hand.** Only a keyframe gives a session a screen
+/// (`hasRenderedFrame`); until then the page lays its skeleton over the terminal, and that skeleton
+/// breathes for ever — no `pumpAndSettle` would return. It also disarms the open's watchdog and
+/// notifies, which is the signal the pager waits on.
+///
+/// ⚠️ **`terminal_ready` is skipped on purpose.** It starts the session's heartbeat, a periodic
+/// timer `testWidgets` fails on before `addTearDown` has disposed the app.
+Future<void> goLive(TerminalSession session) async {
+ final streamId = 'stream-${session.agentId}';
+ session.streamId = streamId;
+ await session.handleBinary(
+ TerminalBinaryFrame(
+ kind: TerminalBinaryKind.keyframe,
+ streamId: streamId,
+ seq: 0,
+ bytes: Uint8List.fromList(utf8.encode('prompt> ')),
+ compressed: false,
+ cols: 46,
+ rows: 38,
+ ),
+ );
}
diff --git a/mobile/test/agent_preattach_test.dart b/mobile/test/agent_preattach_test.dart
index ea4fbc1ca..e4a34f5a1 100644
--- a/mobile/test/agent_preattach_test.dart
+++ b/mobile/test/agent_preattach_test.dart
@@ -12,7 +12,7 @@ void main() {
final conn = PagerConn();
final app = pagerApp(conn);
addTearDown(app.dispose);
- liveAgent(app, 'a');
+ await liveAgent(app, 'a');
final focused = app.focusedPaneId;
await app.preattachAgent('m', 'b', cols: 46, rows: 38);
@@ -58,7 +58,7 @@ void main() {
final app = pagerApp(conn);
addTearDown(app.dispose);
final list = pagerList(app);
- liveAgent(app, 'b');
+ await liveAgent(app, 'b');
await tester.pumpWidget(
MaterialApp(
home: AgentSwipeHost(
@@ -97,12 +97,12 @@ void main() {
await tester.pump(AgentNeighbourWarmer.delay);
await tester.pump();
expect(app.paneOfAgent('m', 'a'), isNotNull);
+ // c was warmed; its keyframe lands before the swipe reaches it, as in use.
+ await goLive(app.paneOfAgent('m', 'c')!.session!);
// One swipe right: from b to c, whose neighbours are b and d.
await tester.fling(find.byType(PageView), const Offset(-400, 0), 1000);
await tester.pumpAndSettle();
- // c was warmed; its keyframe lands.
- goLive(app.paneOfAgent('m', 'c')!.session!);
await tester.pump(AgentNeighbourWarmer.delay);
await tester.pump();
diff --git a/mobile/test/agent_swipe_keyboard_test.dart b/mobile/test/agent_swipe_keyboard_test.dart
index 66ab502bd..3dacae8e0 100644
--- a/mobile/test/agent_swipe_keyboard_test.dart
+++ b/mobile/test/agent_swipe_keyboard_test.dart
@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
+import 'package:harness_mobile/phone/agent_neighbour_warmer.dart';
import 'package:harness_mobile/phone/agent_swipe.dart';
+import 'package:harness_mobile/state/app_state.dart';
import 'package:xterm/xterm.dart';
import 'agent_pager_fixture.dart';
@@ -12,11 +14,10 @@ void main() {
?.findAncestorWidgetOfExactType<TerminalView>() !=
null;
- Future<void> pumpPager(WidgetTester tester) async {
- final conn = PagerConn();
- final app = pagerApp(conn);
+ Future<AppNotifier> pumpPager(WidgetTester tester) async {
+ final app = pagerApp(PagerConn());
addTearDown(app.dispose);
- final session = liveAgent(app, 'b');
+ final session = await liveAgent(app, 'b');
for (var line = 0; line < 400; line++) {
session.terminal.write('output line $line\r\n');
}
@@ -31,6 +32,7 @@ void main() {
),
);
await tester.pump();
+ return app;
}
/// The software keyboard sliding up, as the platform reports it.
@@ -61,7 +63,11 @@ void main() {
testWidgets('a swipe with no keyboard up does not swallow the next one', (
tester,
) async {
- await pumpPager(tester);
+ final app = await pumpPager(tester);
+ // The neighbour opens and answers before the swipe reaches it, as in use.
+ await tester.pump(AgentNeighbourWarmer.delay);
+ await tester.pump();
+ await goLive(app.paneOfAgent('m', 'c')!.session!);
await tester.fling(find.byType(PageView), const Offset(-400, 0), 1000);
await tester.pumpAndSettle();
diff --git a/mobile/test/app_state_events_test.dart b/mobile/test/app_state_events_test.dart
index 4d7c722a4..75b5ce023 100644
--- a/mobile/test/app_state_events_test.dart
+++ b/mobile/test/app_state_events_test.dart
@@ -45,7 +45,7 @@ void main() {
announced.add(agentId);
return true;
};
- liveAgent(app, 'b');
+ await liveAgent(app, 'b');
app.focusPane(app.paneOfAgent('m', 'b')!.id);
diff --git a/mobile/test/phone_socket_drop_test.dart b/mobile/test/phone_socket_drop_test.dart
index d9630a7f7..709e6d326 100644
--- a/mobile/test/phone_socket_drop_test.dart
+++ b/mobile/test/phone_socket_drop_test.dart
@@ -10,10 +10,10 @@ import 'agent_pager_fixture.dart';
/// The phone's socket to the relay drops every time the app is backgrounded. That is the phone's
/// line going, not the machine — and the screen must read it that way.
void main() {
- test('a viewer keeps the machine online and its agents on screen', () {
+ test('a viewer keeps the machine online and its agents on screen', () async {
final app = pagerApp(PagerConn(), viewer: true);
addTearDown(app.dispose);
- final session = liveAgent(app, 'b');
+ final session = await liveAgent(app, 'b');
app.connectionStatusForTest('m', ConnectionStatus.reconnecting);
@@ -30,10 +30,10 @@ void main() {
expect(machine.pendingOfflineAgentId, 'b');
});
- test('a desktop still reads its CLI socket dropping as offline', () {
+ test('a desktop still reads its CLI socket dropping as offline', () async {
final app = pagerApp(PagerConn());
addTearDown(app.dispose);
- liveAgent(app, 'b');
+ await liveAgent(app, 'b');
app.connectionStatusForTest('m', ConnectionStatus.reconnecting);