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.

Polish harness sharing and verify desktop recovery paths

Dee876a97629c8b
diff --git a/backend/package.json b/backend/package.json
index 6e1155b44..dd1d9e7e4 100644
--- a/backend/package.json
+++ b/backend/package.json
@@ -19,6 +19,7 @@
"start:local": "concurrently -k -n server,worker -c cyan,magenta \"node dist/server.js\" \"node dist/worker.js\"",
"test": "NODE_ENV=test HARNESS_CREDENTIAL_ENCRYPTION_KEY=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= vitest run",
"test:watch": "vitest",
+ "test:sharing": "NODE_ENV=test HARNESS_CREDENTIAL_ENCRYPTION_KEY=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= vitest run src/routes/harnessShares.test.ts src/lib/observerWs.test.ts --coverage --coverage.include=src/routes/harnessShares.ts --coverage.include=src/lib/observerWs.ts --coverage.thresholds.lines=100 --coverage.thresholds.statements=100 --coverage.thresholds.branches=100 --coverage.thresholds.functions=100",
"postinstall": "prisma generate"
},
"dependencies": {
diff --git a/cli/package.json b/cli/package.json
index 254a08be5..f12d9b722 100644
--- a/cli/package.json
+++ b/cli/package.json
@@ -12,6 +12,8 @@
"typecheck": "tsc --noEmit",
"start": "node dist/cli.js",
"test": "vitest run",
+ "test:sharing": "vitest run src/sharing --coverage --coverage.include='src/sharing/**' --coverage.thresholds.lines=100 --coverage.thresholds.statements=100 --coverage.thresholds.branches=100 --coverage.thresholds.functions=100",
+ "test:sharing-e2e": "tsx scripts/share-harness-e2e.ts",
"test:cursor-e2e": "RUN_CURSOR_E2E=1 vitest run src/engines/cursor/localE2e.spec.ts",
"test:tmux-real": "RUN_REAL_TMUX_DISCOVERY=1 vitest run src/lib/tmuxAgentDiscovery.real.spec.ts --reporter=verbose",
"test:herdr-real": "RUN_REAL_HERDR=1 vitest run src/lib/herdrBackend.real.spec.ts --reporter=verbose",
diff --git a/desktop/lib/sharing/share_harness_dialog.dart b/desktop/lib/sharing/share_harness_dialog.dart
index 7f8ed6eaf..65bc9751e 100644
--- a/desktop/lib/sharing/share_harness_dialog.dart
+++ b/desktop/lib/sharing/share_harness_dialog.dart
@@ -217,6 +217,7 @@ class _ShareHarnessDialogState extends State<ShareHarnessDialog> {
),
onSubmitted: (_) => _invite(),
+ onChanged: (_) => setState(() {}),
),
const SizedBox(height: 12),
Row(
@@ -241,7 +242,9 @@ class _ShareHarnessDialogState extends State<ShareHarnessDialog> {
),
const SizedBox(height: 12),
FilledButton(
- onPressed: _busy || _loading ? null : _invite,
+ onPressed: _busy || _loading || _emails.text.trim().isEmpty
+ ? null
+ : _invite,
child: Text(_busy ? 'Saving…' : 'Share harness'),
),
if (_error != null)
@@ -314,7 +317,8 @@ class _ShareHarnessDialogState extends State<ShareHarnessDialog> {
Widget _recipient(Map<String, dynamic> share) {
final email = share['email'] as String;
final watching = (share['watching'] as num? ?? 0) > 0;
- final expires = DateTime.tryParse(share['expiresAt'] as String? ?? '');
+ final expires = DateTime.tryParse(share['expiresAt'] as String? ?? '')
+ ?.toLocal();
final subtitle =
share['error'] as String? ??
(share['pending'] == true
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dart
index 6bf69f226..4bb0903bf 100644
--- a/desktop/lib/state/app_state.dart
+++ b/desktop/lib/state/app_state.dart
@@ -3026,11 +3026,19 @@ class AppNotifier extends ChangeNotifier {
) async {
if (_disposed ||
status != AppStatus.authenticated ||
- _sharingDiscoveryBusy)
+ _sharingDiscoveryBusy ||
+ machinesRefreshing) {
return;
+ }
+ final discoveryRevision = _authRevision;
_sharingDiscoveryBusy = true;
try {
await refreshMachines();
+ } catch (error) {
+ if (_authWorkCurrent(discoveryRevision)) {
+ _reportMachineLoadError(error, automatic: true);
+ notifyListeners();
+ }
} finally {
_sharingDiscoveryBusy = false;
}
diff --git a/desktop/test/api_client_test.dart b/desktop/test/api_client_test.dart
index 14874ed58..77ee61ec7 100644
--- a/desktop/test/api_client_test.dart
+++ b/desktop/test/api_client_test.dart
@@ -1,4 +1,3 @@
-import 'dart:async';
import 'dart:convert';
import 'dart:io';
@@ -104,36 +103,87 @@ void main() {
final server = await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
var shareStatus = 200;
var shares = <Map<String, dynamic>>[
- {'machineId': 'shared', 'shared': true, 'authMode': 'remote', 'status': 'offline', 'ownerName': 'D', 'name': 'Studio',
- 'shares': [{'id': 'grant', 'agentId': 'agent', 'name': 'Climate dashboard', 'engine': 'codex', 'expiresAt': '2027-01-01T00:00:00Z'}]},
- {'machineId': 'owned', 'shared': true, 'authMode': 'remote', 'shares': []},
+ {
+ 'machineId': 'shared',
+ 'shared': true,
+ 'authMode': 'remote',
+ 'status': 'offline',
+ 'ownerName': 'D',
+ 'name': 'Studio',
+ 'shares': [
+ {
+ 'id': 'grant',
+ 'agentId': 'agent',
+ 'name': 'Climate dashboard',
+ 'engine': 'codex',
+ 'expiresAt': '2027-01-01T00:00:00Z',
+ },
+ ],
+ },
+ {
+ 'machineId': 'owned',
+ 'shared': true,
+ 'authMode': 'remote',
+ 'shares': [],
+ },
];
server.listen((request) async {
final sharing = request.uri.path == '/api/harness-shares';
request.response.statusCode = sharing ? shareStatus : 200;
request.response.headers.contentType = ContentType.json;
- request.response.write(jsonEncode({'success': shareStatus == 200 || !sharing, 'data': {'machines': sharing ? shares : [
- {'machineId': 'owned', 'authMode': 'remote', 'name': 'This computer'},
- ]}, 'error': {'code': 'UNAVAILABLE', 'message': 'Temporary outage'}}));
+ request.response.write(
+ jsonEncode({
+ 'success': shareStatus == 200 || !sharing,
+ 'data': {
+ 'machines': sharing
+ ? shares
+ : [
+ {
+ 'machineId': 'owned',
+ 'authMode': 'remote',
+ 'name': 'This computer',
+ },
+ ],
+ },
+ 'error': {'code': 'UNAVAILABLE', 'message': 'Temporary outage'},
+ }),
+ );
await request.response.close();
});
try {
- final api = ApiClient(config: AppConfig(apiBaseUrl: 'http://unused.invalid', localCliBaseUrl: 'http://127.0.0.1:${server.port}'), session: AuthSession());
+ final api = ApiClient(
+ config: AppConfig(
+ apiBaseUrl: 'http://unused.invalid',
+ localCliBaseUrl: 'http://127.0.0.1:${server.port}',
+ ),
+ session: AuthSession(),
+ );
final first = await api.machines();
expect(first.map((m) => m.machineId), ['owned', 'shared']);
final shared = first.last;
- expect(shared.isShared, isTrue); expect(shared.status, 'offline'); expect(shared.ownerName, 'D');
+ expect(shared.isShared, isTrue);
+ expect(shared.status, 'offline');
+ expect(shared.ownerName, 'D');
expect(shared.sharedHarnesses.single.agentId, 'agent');
- expect(shared.copyWith(name: 'Updated').sharedHarnesses.single.id, 'grant');
+ expect(
+ shared.copyWith(name: 'Updated').sharedHarnesses.single.id,
+ 'grant',
+ );
shareStatus = 503;
- expect((await api.machines()).last.machineId, 'shared'); expect(api.lastMachinesStale, isTrue);
- shareStatus = 200; shares = [];
- expect((await api.machines()).map((m) => m.machineId), ['owned']); expect(api.lastMachinesStale, isFalse);
+ expect((await api.machines()).last.machineId, 'shared');
+ expect(api.lastMachinesStale, isTrue);
+ shareStatus = 200;
+ shares = [];
+ expect((await api.machines()).map((m) => m.machineId), ['owned']);
+ expect(api.lastMachinesStale, isFalse);
shareStatus = 404;
- expect((await api.machines()).single.machineId, 'owned'); expect(api.lastMachinesStale, isFalse);
+ expect((await api.machines()).single.machineId, 'owned');
+ expect(api.lastMachinesStale, isFalse);
shareStatus = 401;
await expectLater(api.machines(), throwsA(isA<ApiException>()));
- } finally { await server.close(force: true); }
+ } finally {
+ await server.close(force: true);
+ }
});
group('describeApiError', () {
diff --git a/desktop/test/machines_menu_test.dart b/desktop/test/machines_menu_test.dart
index 4545f935a..8281f663b 100644
--- a/desktop/test/machines_menu_test.dart
+++ b/desktop/test/machines_menu_test.dart
@@ -27,32 +27,82 @@ class _RecordingApi extends ApiClient {
}
void main() {
- testWidgets('shared machines expose only invited agents and carry a view-only owner label', (tester) async {
- const channel = MethodChannel('harness/swarm_tabs');
- final messages = <MethodCall>[];
- tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, (call) async { messages.add(call); return true; });
- addTearDown(() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, null));
- final app = createApp();
- final grant = SharedHarness(id: 'grant', agentId: 'shared-agent', name: 'Climate dashboard', expiresAt: DateTime(2027));
- final shared = Machine(machineId: 'shared', authMode: MachineAuthMode.remote, name: 'Studio', isShared: true, ownerName: 'D', sharedHarnesses: [grant]);
- app.machines.add(shared);
- app.machineStates['shared'] = MachineState(shared)
- ..nodeOnline = true
- ..agentLoadStatus = AgentLoadStatus.loaded
- ..agents = [const Agent(id: 'shared-agent', name: 'Climate dashboard', terminalAvailable: true)];
- final projects = SwarmProjectStore();
- await tester.pumpWidget(MaterialApp(home: SwarmScreen(notifier: app, nativeTabs: true, projectStore: projects)));
- await tester.pump();
- final state = messages.lastWhere((m) => m.method == 'machinesState').arguments as Map;
- final machines = state['machines'] as List;
- final row = machines.cast<Map>().firstWhere((m) => m['id'] == 'shared');
- expect(row['shared'], isTrue); expect(row['ownerName'], 'D');
- expect(row['linkRequired'], isFalse);
- expect((row['agents'] as List).single, containsPair('id', 'shared-agent'));
- expect((row['agents'] as List).single, containsPair('canOpen', true));
- expect(app.machineStates['shared']!.connectionStatus, ConnectionStatus.disconnected);
- await tester.pumpWidget(const SizedBox()); app.dispose(); projects.dispose();
- });
+ testWidgets(
+ 'shared machines expose only invited agents and carry a view-only owner label',
+ (tester) async {
+ const channel = MethodChannel('harness/swarm_tabs');
+ final messages = <MethodCall>[];
+ tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, (
+ call,
+ ) async {
+ messages.add(call);
+ return true;
+ });
+ addTearDown(
+ () => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
+ channel,
+ null,
+ ),
+ );
+ final app = createApp();
+ final grant = SharedHarness(
+ id: 'grant',
+ agentId: 'shared-agent',
+ name: 'Climate dashboard',
+ expiresAt: DateTime(2027),
+ );
+ final shared = Machine(
+ machineId: 'shared',
+ authMode: MachineAuthMode.remote,
+ name: 'Studio',
+ isShared: true,
+ ownerName: 'D',
+ sharedHarnesses: [grant],
+ );
+ app.machines.add(shared);
+ app.machineStates['shared'] = MachineState(shared)
+ ..nodeOnline = true
+ ..agentLoadStatus = AgentLoadStatus.loaded
+ ..agents = [
+ const Agent(
+ id: 'shared-agent',
+ name: 'Climate dashboard',
+ terminalAvailable: true,
+ ),
+ ];
+ final projects = SwarmProjectStore();
+ await tester.pumpWidget(
+ MaterialApp(
+ home: SwarmScreen(
+ notifier: app,
+ nativeTabs: true,
+ projectStore: projects,
+ ),
+ ),
+ );
+ await tester.pump();
+ final state =
+ messages.lastWhere((m) => m.method == 'machinesState').arguments
+ as Map;
+ final machines = state['machines'] as List;
+ final row = machines.cast<Map>().firstWhere((m) => m['id'] == 'shared');
+ expect(row['shared'], isTrue);
+ expect(row['ownerName'], 'D');
+ expect(row['linkRequired'], isFalse);
+ expect(
+ (row['agents'] as List).single,
+ containsPair('id', 'shared-agent'),
+ );
+ expect((row['agents'] as List).single, containsPair('canOpen', true));
+ expect(
+ app.machineStates['shared']!.connectionStatus,
+ ConnectionStatus.disconnected,
+ );
+ await tester.pumpWidget(const SizedBox());
+ app.dispose();
+ projects.dispose();
+ },
+ );
testWidgets('tab navigation does not resend the agent inventory', (
tester,
) async {
@@ -371,10 +421,10 @@ void main() {
Map machine() =>
((messages.lastWhere((c) => c.method == 'machinesState').arguments
- as Map)['machines']
- as List)
- .single
- as Map;
+ as Map)['machines']
+ as List)
+ .single
+ as Map;
// Online + linked: presence shows "Online", trailing status drops out so
// the agent count can fill the slot.
diff --git a/desktop/test/pane_machine_unknown_test.dart b/desktop/test/pane_machine_unknown_test.dart
index 6446a6153..c7062d24b 100644
--- a/desktop/test/pane_machine_unknown_test.dart
+++ b/desktop/test/pane_machine_unknown_test.dart
@@ -123,6 +123,7 @@ void main() {
await _pump(tester, app);
expect(find.text(_waiting), findsOneWidget);
expect(find.text('RETRY'), findsNothing);
+ end();
});
testWidgets('says the machine is unknown, and offers a retry, once the list fails', (
@@ -164,5 +165,6 @@ void main() {
// The list is readable again; this machine is merely absent from it.
expect(find.text(_waiting), findsOneWidget);
expect(find.text('RETRY'), findsNothing);
+ end();
});
}
diff --git a/desktop/test/profile_startup_test.dart b/desktop/test/profile_startup_test.dart
index c697ea14c..bf6c991ef 100644
--- a/desktop/test/profile_startup_test.dart
+++ b/desktop/test/profile_startup_test.dart
@@ -263,7 +263,48 @@ void main() {
expect(app.machineStates['fixture']!.agents, hasLength(1));
expect(app.daemonChecks, 2);
await tester.pump(const Duration(seconds: 35));
+ // Invitation discovery continues after recovery without probing the daemon again.
+ // Its pending poll is coalesced across subsequent ticks.
+ expect(api.lists, hasLength(3));
+ api.lists.last.complete([_machine]);
+ await tester.pump();
+ expect(app.daemonChecks, 2);
+ disposeApp();
+ },
+ );
+
+ testWidgets(
+ 'invitation discovery recovers from network failures without losing machines',
+ (tester) async {
+ final start = app.bootstrap();
+ await tester.pump();
+ api.profiles.single.complete(_profile('current'));
+ api.lists.single.complete([_machine]);
+ await tester.pump();
+ await start;
+
+ await tester.pump(const Duration(seconds: 15));
expect(api.lists, hasLength(2));
+ api.lists.last.completeError(
+ ApiException('Backend unreachable', status: 502),
+ );
+ await tester.pump();
+ expect(tester.takeException(), isNull);
+ expect(app.machines.map((m) => m.machineId), ['fixture']);
+ expect(app.lastError, isNull);
+
+ await tester.pump(const Duration(seconds: 2));
+ expect(api.lists, hasLength(3));
+ // Discovery must not duplicate a recovery request that is still pending.
+ await tester.pump(const Duration(seconds: 30));
+ expect(api.lists, hasLength(3));
+ api.lists.last.complete([_machine]);
+ await tester.pump();
+ expect(app.machinesRefreshing, isFalse);
+ await tester.pump(const Duration(seconds: 15));
+ expect(api.lists, hasLength(4));
+ api.lists.last.complete([_machine]);
+ await tester.pump();
disposeApp();
},
);
diff --git a/desktop/test/share_harness_test.dart b/desktop/test/share_harness_test.dart
index adfc7f163..3f9f9ed6d 100644
--- a/desktop/test/share_harness_test.dart
+++ b/desktop/test/share_harness_test.dart
@@ -9,9 +9,32 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:harness/sharing/share_harness_dialog.dart';
import 'package:harness/shared/theme/app_theme.dart' as grid;
import 'package:harness/ws/ws_conn.dart';
+import 'package:harness/auth/auth_session.dart';
+import 'package:harness/core/config.dart';
+import 'package:harness/state/app_state.dart';
import 'support/real_fonts.dart';
+class SharingApp extends AppNotifier {
+ SharingApp()
+ : super(
+ config: AppConfig.dev,
+ authSession: AuthSession(),
+ configStore: null,
+ );
+ final calls = <(String, String, String)>[];
+ @override
+ Future<Map<String, dynamic>> manageHarnessShares(
+ String machineId,
+ String agentId,
+ String action, [
+ Map<String, dynamic> payload = const {},
+ ]) async {
+ calls.add((machineId, agentId, action));
+ return {'shares': []};
+ }
+}
+
void main() {
setUpAll(() async {
await loadRealFonts();
@@ -76,6 +99,81 @@ void main() {
};
final submit = find.widgetWithText(FilledButton, 'Share harness');
+ testWidgets('agent-pane entry point manages the exact selected harness', (
+ tester,
+ ) async {
+ final app = SharingApp();
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: grid.buildAppTheme(brightness: Brightness.dark),
+ home: Scaffold(
+ body: Builder(
+ builder: (context) => TextButton(
+ onPressed: () => showShareHarnessDialog(
+ context,
+ app,
+ 'machine',
+ 'agent',
+ 'Climate dashboard',
+ ),
+ child: const Text('Share'),
+ ),
+ ),
+ ),
+ ),
+ );
+ await tester.tap(find.text('Share'));
+ await tester.pumpAndSettle();
+ expect(app.calls, [('machine', 'agent', 'list')]);
+ expect(find.text('Climate dashboard'), findsOneWidget);
+ await tester.tap(find.text('Done'));
+ await tester.pumpAndSettle();
+ app.dispose();
+ });
+
+ testWidgets(
+ 'invite and remove errors remain actionable and expiry can be changed',
+ (tester) async {
+ var removing = false;
+ final invites = <Map<String, dynamic>>[];
+ await show(tester, (action, payload) async {
+ if (action == 'invite') {
+ invites.add(payload);
+ throw const WsRequestFailure(
+ responseType: 'harness_share_invite_result',
+ code: 'DENIED',
+ detail: 'This harness cannot be shared yet.',
+ );
+ }
+ if (action == 'remove') {
+ removing = true;
+ throw StateError('offline');
+ }
+ return {
+ 'shares': [person('[email protected]')],
+ };
+ });
+ await tester.tap(find.text('Expires in 30 days'));
+ await tester.pumpAndSettle();
+ await tester.tap(find.text('Expires in 7 days').last);
+ await tester.pumpAndSettle();
+ await tester.enterText(find.byType(TextField), '[email protected]');
+ tester
+ .widget<TextField>(find.byType(TextField))
+ .onSubmitted
+ ?.call('[email protected]');
+ await tester.pump();
+ expect(invites.single['days'], 7);
+ expect(find.text('This harness cannot be shared yet.'), findsOneWidget);
+ await tester.tap(find.widgetWithText(TextButton, 'Remove'));
+ await tester.pump();
+ expect(removing, isTrue);
+ expect(find.textContaining('Check the connection'), findsOneWidget);
+ expect(find.text('[email protected]'), findsOneWidget);
+ await tester.pumpWidget(const SizedBox());
+ },
+ );
+
testWidgets(
'invites normalized emails, shows live presence and immediately removes access',
(tester) async {
@@ -83,13 +181,15 @@ void main() {
final calls = <(String, Map<String, dynamic>)>[];
await show(tester, (action, payload) async {
calls.add((action, payload));
- if (action == 'invite')
+ if (action == 'invite') {
shares = [
person('[email protected]', watching: 1),
person('[email protected]'),
];
- if (action == 'remove')
+ }
+ if (action == 'remove') {
shares.removeWhere((row) => row['id'] == payload['id']);
+ }
return {'shares': shares};
});
expect(find.text('Only you have access.'), findsOneWidget);
@@ -98,6 +198,7 @@ void main() {
find.byType(TextField),
);
+ await tester.pump();
await tester.tap(submit);
await tester.pump();
expect(calls.last.$1, 'invite');
@@ -115,7 +216,7 @@ void main() {
final boundary = tester.renderObject<RenderRepaintBoundary>(
find.byKey(const Key('sharing-dialog-preview')),
);
- await tester.pump();
+ await tester.pump(const Duration(milliseconds: 300));
await tester.runAsync(() async {
final image = await boundary.toImage();
final png = await image.toByteData(format: ui.ImageByteFormat.png);
@@ -149,18 +250,23 @@ void main() {
}
return {'shares': []};
});
+ expect(
+ tester.widget<FilledButton>(find.byType(FilledButton)).onPressed,
+ isNull,
+ );
for (final invalid in [
- '',
'bad',
List.generate(21, (i) => '[email protected]').join(','),
]) {
await tester.enterText(find.byType(TextField), invalid);
+ await tester.pump();
await tester.tap(submit);
await tester.pump();
expect(find.textContaining('Enter up to 20 valid'), findsOneWidget);
}
expect(invites, 0);
await tester.enterText(find.byType(TextField), '[email protected]');
+ await tester.pump();
await tester.tap(submit);
await tester.pump();
expect(find.text('Saving…'), findsOneWidget);
@@ -208,11 +314,12 @@ void main() {
(tester) async {
var fails = true;
await show(tester, (_, _) async {
- if (fails)
+ if (fails) {
throw const WsRequestFailure(
responseType: 'harness_share_list_result',
code: 'UNSUPPORTED',
);
+ }
return {'shares': []};
});
expect(
@@ -248,6 +355,7 @@ void main() {
});
await tester.pump(const Duration(seconds: 5));
await tester.enterText(find.byType(TextField), '[email protected]');
+ await tester.pump();
await tester.tap(submit);
await tester.pump();
stale.complete({'shares': []});
diff --git a/desktop/test/shared_harness_panel_test.dart b/desktop/test/shared_harness_panel_test.dart
index 56c3a66db..0073ccb54 100644
--- a/desktop/test/shared_harness_panel_test.dart
+++ b/desktop/test/shared_harness_panel_test.dart
@@ -88,8 +88,8 @@ void main() {
tester.view.physicalSize = Size(width, 760);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
- final sockets = <WebSocket>[], requests = <Map<String, dynamic>>[];
- final closingSockets = <WebSocket>{};
+ final sockets = <WebSocket>[], requests = <Map<String, dynamic>>[];
+ final closingSockets = <WebSocket>{};
late HttpServer server;
await tester.runAsync(() async {
server = await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
@@ -97,10 +97,12 @@ void main() {
final ws = await WebSocketTransformer.upgrade(request);
sockets.add(ws);
ws.listen((raw) {
- if (closingSockets.contains(ws) || ws.readyState != WebSocket.open) return;
+ if (closingSockets.contains(ws) ||
+ ws.readyState != WebSocket.open) {
+ return;
+ }
if (raw is! String) {
fail('An observer sent terminal bytes');
- return;
}
final frame = jsonDecode(raw) as Map<String, dynamic>;
requests.add(frame);
@@ -216,6 +218,35 @@ void main() {
isNot(contains('terminal_resize')),
);
expect(tester.takeException(), isNull);
+ void viewer(Map<String, dynamic> payload) => sockets.last.add(
+ jsonEncode({'type': 'observer_viewer', 'payload': payload}),
+ );
+ viewer({'state': 'loading'});
+ await settleNetwork(
+ () => find.text('Opening the viewer…').evaluate().isNotEmpty,
+ );
+ viewer({'state': 'live', 'data': 'not-base64!'});
+ await tester.runAsync(
+ () => Future<void>.delayed(const Duration(milliseconds: 30)),
+ );
+ await tester.pump();
+ expect(tester.takeException(), isNull);
+ viewer({'state': 'live', 'data': 'aW52YWxpZC1pbWFnZQ=='});
+ await settleNetwork(
+ () => find
+ .text('Waiting for the next viewer frame.')
+ .evaluate()
+ .isNotEmpty,
+ );
+ viewer({
+ 'state': 'live',
+ 'data': 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/lZkAAAAASUVORK5CYII=',
+ });
+ await settleNetwork(() => find.byType(Image).evaluate().isNotEmpty);
+ if (width < 880) {
+ await tester.tap(find.text('Terminal'));
+ await tester.pump();
+ }
await tester.runAsync(() async {
closingSockets.add(sockets.last);
await sockets.last.close(1001, 'Owner disconnected');
@@ -244,6 +275,12 @@ void main() {
await settleNetwork(
() => sockets.length == 3 && find.text('Live').evaluate().isNotEmpty,
);
+ hasAccess = false;
+ await draw();
+ expect(
+ find.text('Access removed or invitation expired.'),
+ findsOneWidget,
+ );
await tester.tap(find.byTooltip('Close shared harness'));
expect(closePressed, isTrue);
await tester.pumpWidget(const SizedBox());
@@ -259,4 +296,44 @@ void main() {
},
);
}
+ testWidgets(
+ 'a restored pane without an invitation opens in the ended state',
+ (tester) async {
+ final app = AppNotifier(
+ config: const AppConfig(
+ apiBaseUrl: 'http://127.0.0.1:9',
+ localCliBaseUrl: 'http://127.0.0.1:9',
+ ),
+ authSession: AuthSession(),
+ configStore: null,
+ );
+ final grant = SharedHarness(
+ id: 'expired',
+ agentId: 'agent',
+ name: 'Demo',
+ expiresAt: DateTime(2000),
+ );
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: SharedHarnessPanel(
+ notifier: app,
+ pane: TerminalPane(id: 1, machineId: 'shared', agentId: 'agent'),
+ grant: grant,
+ hasAccess: false,
+ visible: true,
+ onClose: () {},
+ ),
+ ),
+ ),
+ );
+ expect(find.text('Sharing ended'), findsOneWidget);
+ expect(
+ find.text('Access removed or invitation expired.'),
+ findsOneWidget,
+ );
+ await tester.pumpWidget(const SizedBox());
+ app.dispose();
+ },
+ );
}
diff --git a/desktop/test/swarm_interactions_test.dart b/desktop/test/swarm_interactions_test.dart
index 114bd4193..f9b273c69 100644
--- a/desktop/test/swarm_interactions_test.dart
+++ b/desktop/test/swarm_interactions_test.dart
@@ -243,7 +243,7 @@ void main() {
final controls = find.byType(PaneHeaderActions).first;
expect(
find.descendant(of: controls, matching: find.byType(IconButton)),
- findsNWidgets(5),
+ findsNWidgets(6),
);
expect(find.byTooltip('Stop Harness').first.hitTestable(), findsNothing);
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
diff --git a/desktop/test/terminal_panel_presentation_test.dart b/desktop/test/terminal_panel_presentation_test.dart
index 59aaf4f9c..3ad1f7421 100644
--- a/desktop/test/terminal_panel_presentation_test.dart
+++ b/desktop/test/terminal_panel_presentation_test.dart
@@ -164,13 +164,14 @@ void main() {
expect(find.byTooltip('Stop Harness').hitTestable(), findsNothing);
expect(
find.descendant(of: controls, matching: find.byType(IconButton)),
- findsNWidgets(local ? 4 : 5),
+ findsNWidgets(local ? 5 : 6),
);
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
await mouse.addPointer(location: tester.getCenter(title));
await tester.pump(const Duration(milliseconds: 120));
expect(tester.widget<AnimatedOpacity>(details).opacity, 0);
expect(find.byTooltip('Stop Harness').hitTestable(), findsOneWidget);
+ expect(find.byTooltip('Share harness').hitTestable(), findsOneWidget);
expect(tester.getRect(title), titleBounds);
expect(
tester.widget<TerminalView>(find.byType(TerminalView)),