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
Confirm tab session stops in one Cancel/Stop dialog (#609)
Dee4dfcea3af13b
diff --git a/desktop/CLAUDE.md b/desktop/CLAUDE.mdindex 03539d057..a9a850d48 100644--- a/desktop/CLAUDE.md+++ b/desktop/CLAUDE.md@@ -282,8 +282,12 @@ An owned idle session saves its native conversation and terminal snapshotbefore releasing its process, regardless of other viewers. A ready, unused Claude/Codex chat withan empty composer also closes directly, saving its terminal snapshot without requiring a nativeconversation. Missing activity evidence for an existing chat remains unknown. Working,-waiting-for-input, draft, or unknown sessions show one short sentence with Cancel and Close;-there is no title or deferred-close button. Cancel is the default. Previously queued daemon close+waiting-for-input, draft, or unknown sessions share one confirmation for the whole tab, with+their names, activity, and the number of sessions that will stop. Its only choices are Cancel+and Stop; Cancel is the default. Stop saves and stops every reviewed session before the tab+closes. Idle-only closes retain the daemon's activity guard; newly active work gets one review+of the remaining sessions. Failures keep the view and identify confirmed stops separately+from uncertain ones. Previously queued daemon closeplans remain compatible. Layout cleanup, moving panes, switching tabs, and sign-out retain their view-only behavior. A failed saveor unconfirmed close keeps the pane. Older daemons retain their existing behavior until updated.diff --git a/desktop/design/review/2026-10-02-tab-close.png b/desktop/design/review/2026-10-02-tab-close.pngnew file mode 100644index 000000000..09e7ea3e7Binary files /dev/null and b/desktop/design/review/2026-10-02-tab-close.png differdiff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dartindex dec6561ee..a173fb883 100644--- a/desktop/lib/screens/swarm_screen.dart+++ b/desktop/lib/screens/swarm_screen.dart@@ -2569,20 +2569,33 @@ class _SwarmScreenState extends State<SwarmScreen> {if (restoreEntry) await _ensureEmptyEntry();}- Future<bool> _reviewSessionClose(List<(String, Agent)> targets) async {- final choices =- <(Agent, Future<Map<String, dynamic>> Function(String), String)>[];- Future<String?> choose(- Agent agent,- String activity, {- String? error,- }) async {+ Future<bool> _reviewSessionClose(+ List<(String, Agent)> targets, {+ String? tabName,+ }) async {+ final requests = [+ for (final (machine, agent) in targets)+ app.prepareSessionClose(machine, agent),+ ];+ final activities = List.filled(targets.length, 'unknown');+ final showMachines = targets.map((target) => target.$1).toSet().length > 1;+ Future<String?> choose({String? error}) async {String? result;await _dialog(() async {result = await showSessionCloseDialog(context,- agent,- activity,+ [+ for (var i = 0; i < targets.length; i++)+ SessionCloseItem(+ name: targets[i].$2.displayName,+ activity: activities[i],+ machineName: showMachines+ ? app.stateOf(targets[i].$1)?.machine.displayName ??+ targets[i].$1+ : null,+ ),+ ],+ tabName: tabName,keymap: _keymap,error: error,);@@ -2590,51 +2603,54 @@ class _SwarmScreenState extends State<SwarmScreen> {return result;}- // Review every working session before stopping any member of a whole tab.- for (final (machine, agent) in targets) {- if (!mounted) return false;- final request = app.prepareSessionClose(machine, agent);- final state = await request('inspect');- if (!mounted) return false;- if (state['error'] != null) {- await choose(- agent,- 'unknown',- error:- state['detail'] as String? ??- 'Could not check this session. It has been kept open.',- );- return false;+ Future<bool> inspectFrom(int start) async {+ for (var i = start; i < requests.length; i++) {+ if (!mounted) return false;+ final state = await requests[i]('inspect');+ if (!mounted) return false;+ if (state['error'] != null) {+ await choose(+ error:+ state['detail'] as String? ??+ 'Could not check ${targets[i].$2.displayName}. Nothing else will be stopped.',+ );+ return false;+ }+ activities[i] = state['activity'] as String? ?? 'unknown';}- final activity = state['activity'] as String? ?? 'unknown';- final mode = activity == 'idle' ? 'idle' : await choose(agent, activity);- if (mode == null) return false;- choices.add((agent, request, mode));+ return true;}- for (final (agent, request, mode) in choices) {++ // Inspect the whole captured set before one decision, or any stop. Stop+ // approves every listed session, including idle ones that start work while+ // the prompt is open; an unprompted close keeps the daemon's idle guard.+ if (!await inspectFrom(0)) return false;+ var stopNow = activities.any((activity) => activity != 'idle');+ if (stopNow && await choose() != 'now') return false;+ for (var i = 0; i < requests.length; i++) {if (!mounted) return false;- var result = await request(mode);+ var result = await requests[i](stopNow ? 'now' : 'idle');if (!mounted) return false;- // Work may have begun while the person was reviewing another session.+ // An idle-only close may race with new work. Review every remaining+ // session together, and disclose any sessions that already stopped.if (result['error'] == 'SESSION_NOT_IDLE') {- final next = await choose(- agent,- result['activity'] as String? ?? 'unknown',- );- if (next == null) return false;- result = await request(next);+ activities[i] = result['activity'] as String? ?? 'unknown';+ if (!await inspectFrom(i + 1)) return false;+ if (await choose() != 'now') return false;+ stopNow = true;+ result = await requests[i]('now');}if (!mounted) return false;if (result['closed'] != true && result['deferred'] != true) {+ activities[i] = 'unconfirmed';await choose(- agent,- 'unknown',error:result['detail'] as String? ??- 'Could not close this session safely. Its saved history is kept.',+ 'Could not confirm that ${targets[i].$2.displayName} stopped. Its saved history is kept.',);return false;}+ activities[i] = result['closed'] == true ? 'stopped' : 'deferred';}return true;}diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dartindex 034f7f498..5b452ea51 100644--- a/desktop/lib/state/app_state.dart+++ b/desktop/lib/state/app_state.dart@@ -613,7 +613,8 @@ class AppNotifier extends ChangeNotifier {final _agentPauses = <(String, String), Future<String?>>{};/// The workspace supplies presentation; the model owns target identity and completion.- Future<bool> Function(List<(String, Agent)>)? reviewSessionClose;+ Future<bool> Function(List<(String, Agent)>, {String? tabName})?+ reviewSessionClose;final _viewCloseRequests = <String, Future<void>>{};final _closingViewAgents = <(String, String), int>{};final _agentForks = <(String, String), AgentForkAttempt>{};@@ -2087,7 +2088,7 @@ class AppNotifier extends ChangeNotifier {return;}await closeSwarm(id);- });+ }, tabName: tab.name);}Future<void> requestClosePane(int paneId) {@@ -2114,8 +2115,9 @@ class AppNotifier extends ChangeNotifier {String key,Swarm tab,List<TerminalPane> closing,- Future<void> Function() finish,- ) {+ Future<void> Function() finish, {+ String? tabName,+ }) {if (_disposed) return Future.value();if (_viewCloseRequests[key] case final pending?) return pending;final targets = <(String, Agent)>[];@@ -2150,7 +2152,7 @@ class AppNotifier extends ChangeNotifier {try {if (targets.isNotEmpty &&(reviewSessionClose == null ||- !await reviewSessionClose!(targets))) {+ !await reviewSessionClose!(targets, tabName: tabName))) {return;}if (!_authWorkCurrent(revision) || !swarms.contains(tab)) return;diff --git a/desktop/lib/widgets/session_close_dialog.dart b/desktop/lib/widgets/session_close_dialog.dartindex 055d82880..74e25833e 100644--- a/desktop/lib/widgets/session_close_dialog.dart+++ b/desktop/lib/widgets/session_close_dialog.dart@@ -1,34 +1,46 @@import 'package:flutter/material.dart';-import '../core/models.dart';import '../shortcuts/app_keymap.dart';import '../shared/theme/app_theme.dart' as grid;import 'desktop_chrome.dart';import 'desktop_prompt_surface.dart';import 'terminal_prompt.dart';-/// Only unfinished or uncertain work needs a decision. Cancel is the default.+class SessionCloseItem {+ const SessionCloseItem({+ required this.name,+ required this.activity,+ this.machineName,+ });++ final String name;+ final String activity;+ final String? machineName;++ bool get completed => activity == 'stopped' || activity == 'deferred';+}++/// One decision covers the captured sessions. Cancel is the default.Future<String?> showSessionCloseDialog(BuildContext context,- Agent agent,- String activity, {+ List<SessionCloseItem> sessions, {+ String? tabName,AppKeymap? keymap,String? error,}) => showTerminalPrompt<String>(context,keymap: keymap,- builder: (_) =>- _SessionClosePrompt(agent: agent, activity: activity, error: error),+ builder: (_) => _SessionClosePrompt(+ sessions: List.unmodifiable(sessions),+ tabName: tabName,+ error: error,+ ),);class _SessionClosePrompt extends StatefulWidget {- const _SessionClosePrompt({- required this.agent,- required this.activity,- this.error,- });- final Agent agent;- final String activity;+ const _SessionClosePrompt({required this.sessions, this.tabName, this.error});+ final List<SessionCloseItem> sessions;+ final String? tabName;final String? error;@overrideState<_SessionClosePrompt> createState() => _SessionClosePromptState();@@ -56,27 +68,97 @@ class _SessionClosePromptState extends State<_SessionClosePrompt> {void _choose([String? choice]) => Navigator.pop(context, choice);+ String _summary(List<SessionCloseItem> attention) {+ final count = attention.length;+ final subject = count == 1 ? '1 session' : '$count sessions';+ final activities = attention.map((item) => item.activity).toSet();+ if (activities.length != 1) {+ return '$subject ${count == 1 ? 'needs' : 'need'} attention.';+ }+ return switch (activities.single) {+ 'working' => '$subject ${count == 1 ? 'is' : 'are'} still working.',+ 'needs_input' =>+ '$subject ${count == 1 ? 'is' : 'are'} waiting for input.',+ 'draft' => '$subject ${count == 1 ? 'has' : 'have'} unsent text.',+ _ => '$subject may still be working.',+ };+ }++ String _activityLabel(String activity) => switch (activity) {+ 'working' => 'Working',+ 'needs_input' => 'Waiting for input',+ 'draft' => 'Unsent text',+ 'idle' => 'Idle',+ 'stopped' => 'Stopped',+ 'deferred' => 'Stopping after work finishes',+ 'unconfirmed' => 'Stop not confirmed',+ _ => 'Activity unknown',+ };+@overrideWidget build(BuildContext context) {grid.AppTheme.watch(context);- final description = switch (widget.activity) {- 'working' => 'Still working. Close anyway?',- 'needs_input' => 'Waiting for input. Close anyway?',- 'draft' => 'Unsent text. Close anyway?',- _ => 'May still be working. Close anyway?',- };+ final pending = widget.sessions.where((item) => !item.completed).toList();+ final attention = pending.where((item) => item.activity != 'idle').toList();+ final count = pending.length;+ final scope = widget.tabName == null+ ? 'this pane'+ : 'the tab “${widget.tabName}”';+ final description = widget.error ?? _summary(attention);+ final visible = widget.error == null ? attention : widget.sessions;+ final completed = widget.sessions.where((item) => item.completed).length;return TerminalPromptKeys(focusNode: _keys,cancel: _choose,child: Semantics(namesRoute: true,- label: widget.agent.displayName,+ label: widget.tabName ?? widget.sessions.first.name,child: DesktopPromptSurface(body: DesktopPromptScrollBody(controller: _scroll,- child: Text(- widget.error ?? description,- style: DesktopChrome.text(size: 13),+ child: Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ Text(description, style: DesktopChrome.text(size: 13)),+ const SizedBox(height: DesktopChrome.controlGap),+ Text(+ widget.error == null+ ? 'Stopping ${count == 1 ? 'this session' : 'all $count sessions'} will close $scope. History will be saved.'+ : '${widget.tabName == null ? 'This pane' : 'The tab'} stays open.',+ style: DesktopChrome.text(size: 13),+ ),+ const SizedBox(height: DesktopChrome.groupGap),+ for (final item in visible)+ Padding(+ padding: const EdgeInsets.only(+ bottom: DesktopChrome.controlGap,+ ),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(+ item.name,+ style: DesktopChrome.text(size: 13, medium: true),+ ),+ Text(+ [+ if (item.machineName != null) item.machineName!,+ _activityLabel(item.activity),+ ].join(' · '),+ style: DesktopChrome.text(size: 12),+ ),+ ],+ ),+ ),+ if (completed > 0 && widget.error == null) ...[+ const SizedBox(height: DesktopChrome.controlGap),+ Text(+ '$completed ${completed == 1 ? 'session has' : 'sessions have'} already closed.',+ style: DesktopChrome.text(size: 13),+ ),+ ],+ ],),),actions: [@@ -90,7 +172,7 @@ class _SessionClosePromptState extends State<_SessionClosePrompt> {key: const Key('session-close-now'),style: grid.dangerButtonStyle(),onPressed: () => _choose('now'),- child: const Text('Close'),+ child: const Text('Stop'),),],],diff --git a/desktop/test/session_close_dialog_test.dart b/desktop/test/session_close_dialog_test.dartindex 19b4656c2..bee1b5706 100644--- a/desktop/test/session_close_dialog_test.dart+++ b/desktop/test/session_close_dialog_test.dart@@ -1,11 +1,11 @@import 'dart:io';import 'dart:ui' as ui;+import 'package:flutter/foundation.dart';import 'package:flutter/material.dart';import 'package:flutter/rendering.dart';import 'package:flutter/services.dart';import 'package:flutter_test/flutter_test.dart';-import 'package:harness/core/models.dart';import 'package:harness/shared/theme/app_theme.dart' as grid;import 'package:harness/widgets/desktop_prompt_surface.dart';import 'package:harness/widgets/session_close_dialog.dart';@@ -13,96 +13,130 @@ import 'package:harness/widgets/session_close_dialog.dart';import 'box_render_preview_test.dart' show loadPreviewFonts;void main() {- final renderDir = Platform.environment['SESSION_CLOSE_RENDER_DIR'];+ final renderDir = kIsWeb+ ? null+ : Platform.environment['SESSION_CLOSE_RENDER_DIR'];setUpAll(() async {if (renderDir != null) await loadPreviewFonts();});for (final brightness in Brightness.values) {for (final scale in [1.0, 2.0]) {- testWidgets('${brightness.name} close prompt at ${scale}x', (- tester,- ) async {- final previousBrightness = grid.AppTheme.brightness.value;- grid.AppTheme.brightness.value = brightness;- addTearDown(() => grid.AppTheme.brightness.value = previousBrightness);- tester.view.devicePixelRatio = 1;- tester.view.physicalSize = scale == 1- ? const Size(800, 500)- : const Size(360, 320);- addTearDown(tester.view.resetPhysicalSize);- addTearDown(tester.view.resetDevicePixelRatio);- final picture = GlobalKey();- var dismissed = false;- await tester.pumpWidget(- MaterialApp(- debugShowCheckedModeBanner: false,- theme: grid.buildAppTheme(brightness: brightness),- builder: (context, child) => MediaQuery(- data: MediaQuery.of(context)- .copyWith(textScaler: TextScaler.linear(scale)),- child: RepaintBoundary(key: picture, child: child!),- ),- home: Builder(- builder: (context) => Scaffold(- body: Center(- child: TextButton(- onPressed: () async {- final result = await showSessionCloseDialog(- context,- Agent(- id: 'fixture',- name: 'Example session',- engine: 'codex',- ),- 'working',- );- expect(result, isNull);- dismissed = true;- },- child: const Text('Open'),+ for (final tab in [false, true]) {+ testWidgets(+ '${brightness.name} ${tab ? 'tab' : 'pane'} close prompt at ${scale}x',+ (tester) async {+ final previousBrightness = grid.AppTheme.brightness.value;+ grid.AppTheme.brightness.value = brightness;+ addTearDown(+ () => grid.AppTheme.brightness.value = previousBrightness,+ );+ tester.view.devicePixelRatio = 1;+ tester.view.physicalSize = scale == 1+ ? const Size(800, 500)+ : const Size(360, 320);+ addTearDown(tester.view.resetPhysicalSize);+ addTearDown(tester.view.resetDevicePixelRatio);+ final picture = GlobalKey();+ var dismissed = false;+ await tester.pumpWidget(+ MaterialApp(+ debugShowCheckedModeBanner: false,+ theme: grid.buildAppTheme(brightness: brightness),+ builder: (context, child) => MediaQuery(+ data: MediaQuery.of(context)+ .copyWith(textScaler: TextScaler.linear(scale)),+ child: RepaintBoundary(key: picture, child: child!),+ ),+ home: Builder(+ builder: (context) => Scaffold(+ body: Center(+ child: TextButton(+ onPressed: () async {+ final result = await showSessionCloseDialog(context, [+ const SessionCloseItem(+ name: 'Fix authentication',+ activity: 'working',+ ),+ if (tab) ...[+ const SessionCloseItem(+ name: 'Investigate the intermittent checkout failure on the staging machine',+ activity: 'working',+ ),+ const SessionCloseItem(+ name: 'Update documentation',+ activity: 'idle',+ ),+ const SessionCloseItem(+ name: 'Review changes',+ activity: 'idle',+ ),+ const SessionCloseItem(+ name: 'Check release notes',+ activity: 'idle',+ ),+ ],+ ], tabName: tab ? 'Release' : null);+ expect(result, isNull);+ dismissed = true;+ },+ child: const Text('Open'),+ ),+ ),),),),- ),- ),- );- await tester.tap(find.text('Open'));- await tester.pumpAndSettle();- final message = find.text('Still working. Close anyway?');- final cancel = find.widgetWithText(TextButton, 'Cancel');- final close = find.widgetWithText(FilledButton, 'Close');- expect(message, findsOneWidget);- expect(tester.widget<TextButton>(cancel).focusNode!.hasFocus, isTrue);- // Enlarged text can scroll; the visible body must stay above actions.- expect(- tester.getBottomLeft(find.byType(DesktopPromptScrollBody)).dy,- lessThan(tester.getTopLeft(cancel).dy),- );- expect(- tester.getBottomRight(close).dy,- lessThan(tester.view.physicalSize.height),- );- expect(tester.takeException(), isNull);+ );+ await tester.tap(find.text('Open'));+ await tester.pumpAndSettle();+ final message = find.text(+ tab+ ? '2 sessions are still working.'+ : '1 session is still working.',+ );+ final cancel = find.widgetWithText(TextButton, 'Cancel');+ final close = find.widgetWithText(FilledButton, 'Stop');+ expect(message, findsOneWidget);+ expect(find.byType(FilledButton), findsOneWidget);+ expect(find.widgetWithText(TextButton, 'Cancel'), findsOneWidget);+ expect(+ tester.widget<TextButton>(cancel).focusNode!.hasFocus,+ isTrue,+ );+ // Enlarged text can scroll; the visible body must stay above actions.+ expect(+ tester.getBottomLeft(find.byType(DesktopPromptScrollBody)).dy,+ lessThan(tester.getTopLeft(cancel).dy),+ );+ expect(+ tester.getBottomRight(close).dy,+ lessThan(tester.view.physicalSize.height),+ );+ expect(tester.takeException(), isNull);- if (renderDir != null) {- await tester.runAsync(() async {- final boundary =- picture.currentContext!.findRenderObject()!- as RenderRepaintBoundary;- final image = await boundary.toImage(pixelRatio: 2);- final data = await image.toByteData(format: ui.ImageByteFormat.png);- Directory(renderDir).createSync(recursive: true);- await File('$renderDir/${brightness.name}-${scale}x.png')- .writeAsBytes(data!.buffer.asUint8List());- image.dispose();- });- }- await tester.sendKeyEvent(LogicalKeyboardKey.escape);- await tester.pumpAndSettle();- expect(dismissed, isTrue);- expect(message, findsNothing);- });+ if (renderDir != null) {+ await tester.runAsync(() async {+ final boundary =+ picture.currentContext!.findRenderObject()!+ as RenderRepaintBoundary;+ final image = await boundary.toImage(pixelRatio: 2);+ final data = await image.toByteData(+ format: ui.ImageByteFormat.png,+ );+ Directory(renderDir).createSync(recursive: true);+ await File(+ '$renderDir/${brightness.name}-${tab ? 'tab' : 'pane'}-${scale}x.png',+ ).writeAsBytes(data!.buffer.asUint8List());+ image.dispose();+ });+ }+ await tester.sendKeyEvent(LogicalKeyboardKey.escape);+ await tester.pumpAndSettle();+ expect(dismissed, isTrue);+ expect(message, findsNothing);+ },+ );+ }}}}diff --git a/desktop/test/session_close_test.dart b/desktop/test/session_close_test.dartindex a84d34bf8..4cdcb63a1 100644--- a/desktop/test/session_close_test.dart+++ b/desktop/test/session_close_test.dart@@ -26,6 +26,7 @@ class _CloseConnection extends WsConn {final closes = <Map<String, dynamic>>[];final activities = <String, String>{};final failures = <String, Map<String, dynamic>>{};+ final targetedFailures = <(String, String), Map<String, dynamic>>{};final requests = <String>[];Completer<Map<String, dynamic>>? inspecting;@override@@ -37,8 +38,10 @@ class _CloseConnection extends WsConn {requests.add(type);if (type != 'agent_close') return {};closes.add(Map.of(payload));- final mode = payload['mode'];- if (failures[mode] case final failure?) {+ final mode = payload['mode'] as String;+ final agentId = payload['agentId'] as String;+ if (targetedFailures[(agentId, mode)] ?? failures[mode]+ case final failure?) {// Real WsConn throws refusals; returning a map would skip the production// error path and hide the bug that called every refusal a lost reply.throw WsRequestFailure(@@ -123,8 +126,8 @@ void main() {await mount(tester, app);unawaited(app.requestClosePane(pane.id));await tester.pumpAndSettle();- expect(find.text('Still working. Close anyway?'), findsOneWidget);- expect(find.widgetWithText(FilledButton, 'Close'), findsOneWidget);+ expect(find.text('1 session is still working.'), findsOneWidget);+ expect(find.widgetWithText(FilledButton, 'Stop'), findsOneWidget);expect(find.byType(FilledButton), findsOneWidget);expect(find.text('Close session'), findsNothing);expect(find.text('Stop after finishing'), findsNothing);@@ -192,16 +195,16 @@ void main() {expect(app.allPanes, isEmpty);expect(app.stateOf('m')!.agents.single.isStopped, isTrue);expect(app.closedHistory, hasLength(1));- expect(find.widgetWithText(FilledButton, 'Close'), findsNothing);+ expect(find.widgetWithText(FilledButton, 'Stop'), findsNothing);expect(tester.takeException(), isNull);await tester.pumpWidget(const SizedBox());});for (final entry in {- 'working': 'Still working. Close anyway?',- 'needs_input': 'Waiting for input. Close anyway?',- 'draft': 'Unsent text. Close anyway?',- 'unknown': 'May still be working. Close anyway?',+ 'working': '1 session is still working.',+ 'needs_input': '1 session is waiting for input.',+ 'draft': '1 session has unsent text.',+ 'unknown': '1 session may still be working.',}.entries) {testWidgets('${entry.key} Close sends only the reviewed action', (tester,@@ -213,7 +216,7 @@ void main() {await tester.pumpAndSettle();expect(find.text(entry.value), findsOneWidget);expect(modes(), ['inspect']);- await tester.tap(find.widgetWithText(FilledButton, 'Close'));+ await tester.tap(find.widgetWithText(FilledButton, 'Stop'));await tester.pumpAndSettle();expect(modes(), ['inspect', 'now']);expect(app.allPanes, isEmpty);@@ -263,7 +266,7 @@ void main() {: app.requestClosePane(pane.id),);await tester.pumpAndSettle();- expect(find.text('Still working. Close anyway?'), findsOneWidget);+ expect(find.text('1 session is still working.'), findsOneWidget);expect(app.panes, [pane]);expect(modes(), ['inspect', 'idle']);await tester.tap(find.byKey(const Key('session-close-now')));@@ -289,7 +292,7 @@ void main() {await mount(tester, app);unawaited(app.requestClosePane(pane.id));await tester.pumpAndSettle();- expect(find.text('Unsent text. Close anyway?'), findsOneWidget);+ expect(find.text('1 session has unsent text.'), findsOneWidget);await tester.tap(find.text('Cancel'));await tester.pumpAndSettle();expect(modes(), ['inspect', 'idle']);@@ -343,21 +346,197 @@ void main() {await tester.pumpWidget(const SizedBox());});+ for (final stop in [false, true]) {+ testWidgets(+ 'one mixed-tab review ${stop ? 'stops' : 'keeps'} all sessions',+ (tester) async {+ app.stateOf('m')!.agents.add(agent('a2'));+ connection.activities.addAll({'a0': 'working', 'a1': 'working'});+ for (final id in ['a0', 'a1', 'a2']) {+ app.adoptSessionForTest(terminal(id, []));+ }+ final tab = app.activeSwarm;+ app.renameSwarm(tab.id, 'Release');+ await mount(tester, app);+ unawaited(app.requestCloseSwarm(tab.id));+ // Repeated Close shares the same pending review.+ unawaited(app.requestCloseSwarm(tab.id));+ await tester.pumpAndSettle();+ expect(find.byType(Dialog), findsOneWidget);+ expect(find.text('2 sessions are still working.'), findsOneWidget);+ expect(+ find.text(+ 'Stopping all 3 sessions will close the tab “Release”. History will be saved.',+ ),+ findsOneWidget,+ );+ for (final id in ['a0', 'a1']) {+ expect(+ find.descendant(+ of: find.byType(Dialog),+ matching: find.text('Work $id'),+ ),+ findsOneWidget,+ );+ }+ expect(modes(), ['inspect', 'inspect', 'inspect']);+ expect(find.widgetWithText(FilledButton, 'Stop'), findsOneWidget);+ await tester.tap(find.text(stop ? 'Stop' : 'Cancel'));+ await tester.pumpAndSettle();+ expect(find.byType(Dialog), findsNothing);+ if (stop) {+ expect(modes(), [+ 'inspect',+ 'inspect',+ 'inspect',+ 'now',+ 'now',+ 'now',+ ]);+ expect(app.allPanes, isEmpty);+ expect(app.swarms, isNot(contains(tab)));+ expect(+ app.stateOf('m')!.agents.every((agent) => agent.isStopped),+ isTrue,+ );+ expect(app.closedHistory, hasLength(1));+ } else {+ expect(app.panes, hasLength(3));+ expect(modes(), ['inspect', 'inspect', 'inspect']);+ expect(+ app.stateOf('m')!.agents.any((agent) => agent.isStopped),+ isFalse,+ );+ }+ expect(tester.takeException(), isNull);+ await tester.pumpWidget(const SizedBox());+ },+ );+ }++ testWidgets('an idle tab closes every session without a prompt', (+ tester,+ ) async {+ app.adoptSessionForTest(terminal('a0', []));+ app.adoptSessionForTest(terminal('a1', []));+ final tab = app.activeSwarm;+ await mount(tester, app);+ await app.requestCloseSwarm(tab.id);+ await tester.pumpAndSettle();+ expect(find.byType(Dialog), findsNothing);+ expect(modes(), ['inspect', 'inspect', 'idle', 'idle']);+ expect(app.swarms, isNot(contains(tab)));+ expect(app.allPanes, isEmpty);+ await tester.pumpWidget(const SizedBox());+ });++ testWidgets('an inspection failure stops no member of the tab', (+ tester,+ ) async {+ connection.activities['a0'] = 'working';+ connection.targetedFailures[('a1', 'inspect')] = {+ 'error': 'CLOSE_UNCONFIRMED',+ 'detail': 'Could not reach the machine.',+ };+ app.adoptSessionForTest(terminal('a0', []));+ app.adoptSessionForTest(terminal('a1', []));+ await mount(tester, app);+ unawaited(app.requestCloseSwarm(app.activeSwarmId));+ await tester.pumpAndSettle();+ expect(find.text('Could not reach the machine.'), findsOneWidget);+ expect(find.widgetWithText(FilledButton, 'Stop'), findsNothing);+ expect(modes(), ['inspect', 'inspect']);+ await tester.tap(find.text('OK'));+ await tester.pumpAndSettle();+ expect(app.panes, hasLength(2));+ expect(app.stateOf('m')!.agents.any((agent) => agent.isStopped), isFalse);+ await tester.pumpWidget(const SizedBox());+ });++ testWidgets('a partial failure keeps the tab and names confirmed stops', (+ tester,+ ) async {+ connection.activities.addAll({'a0': 'working', 'a1': 'working'});+ connection.targetedFailures[('a1', 'now')] = {+ 'error': 'HISTORY_NOT_SAVED',+ 'detail': 'Not enough free disk space.',+ };+ app.adoptSessionForTest(terminal('a0', []));+ app.adoptSessionForTest(terminal('a1', []));+ final tab = app.activeSwarm;+ await mount(tester, app);+ unawaited(app.requestCloseSwarm(tab.id));+ await tester.pumpAndSettle();+ await tester.tap(find.text('Stop'));+ await tester.pumpAndSettle();+ expect(find.text('Not enough free disk space.'), findsOneWidget);+ expect(find.text('Stopped'), findsOneWidget);+ expect(find.text('Stop not confirmed'), findsOneWidget);+ expect(find.text('The tab stays open.'), findsOneWidget);+ expect(find.widgetWithText(FilledButton, 'Stop'), findsNothing);+ await tester.tap(find.text('OK'));+ await tester.pumpAndSettle();+ expect(app.swarms, contains(tab));+ expect(tab.panes, hasLength(2));+ expect(+ app.stateOf('m')!.agents.firstWhere((a) => a.id == 'a0').isStopped,+ isTrue,+ );+ expect(+ app.stateOf('m')!.agents.firstWhere((a) => a.id == 'a1').isStopped,+ isFalse,+ );+ expect(app.closedHistory, isEmpty);+ await tester.pumpWidget(const SizedBox());+ });+testWidgets(- 'Cancel on a later tab member does not stop an earlier approved member',+ 'new work during an idle close reviews all remaining sessions once',(tester) async {- connection.activities.addAll({'a0': 'working', 'a1': 'working'});- app.adoptSessionForTest(terminal('a0', []));- app.adoptSessionForTest(terminal('a1', []));+ app.stateOf('m')!.agents.add(agent('a2'));+ connection.targetedFailures[('a1', 'idle')] = {+ 'error': 'SESSION_NOT_IDLE',+ 'activity': 'working',+ };+ for (final id in ['a0', 'a1', 'a2']) {+ app.adoptSessionForTest(terminal(id, []));+ }+ final tab = app.activeSwarm;+ app.renameSwarm(tab.id, 'Release');await mount(tester, app);- unawaited(app.requestCloseSwarm(app.activeSwarmId));+ unawaited(app.requestCloseSwarm(tab.id));await tester.pumpAndSettle();- await tester.tap(find.byKey(const Key('session-close-now')));- await tester.pumpAndSettle();- await tester.tap(find.text('Cancel'));+ expect(find.text('1 session is still working.'), findsOneWidget);+ expect(+ find.text(+ 'Stopping all 2 sessions will close the tab “Release”. History will be saved.',+ ),+ findsOneWidget,+ );+ expect(find.text('1 session has already closed.'), findsOneWidget);+ expect(modes(), [+ 'inspect',+ 'inspect',+ 'inspect',+ 'idle',+ 'idle',+ 'inspect',+ ]);+ await tester.tap(find.text('Stop'));await tester.pumpAndSettle();- expect(app.panes, hasLength(2));- expect(modes(), ['inspect', 'inspect']);+ expect(modes(), [+ 'inspect',+ 'inspect',+ 'inspect',+ 'idle',+ 'idle',+ 'inspect',+ 'now',+ 'now',+ ]);+ expect(find.byType(Dialog), findsNothing);+ expect(app.allPanes, isEmpty);+ expect(app.swarms, isNot(contains(tab)));await tester.pumpWidget(const SizedBox());},);