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
Polish Swarm routing notes and remove inline reassignment (#1483)
Dee2291156f3c19
diff --git a/desktop/integration_test/super_tab_native_test.dart b/desktop/integration_test/super_tab_native_test.dartindex 175e2c80b..7b5ca5dff 100644--- a/desktop/integration_test/super_tab_native_test.dart+++ b/desktop/integration_test/super_tab_native_test.dart@@ -11,6 +11,7 @@ import 'package:harness/core/models.dart';import 'package:harness/shared/theme/app_theme.dart' as grid;import 'package:harness/state/new_harness.dart';import 'package:harness/super_tabs/workspace.dart';+import 'package:harness/super_tabs/message_text.dart';import 'package:harness/widgets/pane_grid.dart';import 'package:harness/widgets/agent_drag.dart';import 'package:harness/widgets/terminal_panel.dart';@@ -18,6 +19,7 @@ import 'package:harness/ws/local_cli_discovery.dart';import '../test/super_tab_launch_test.dart'show SuperTabFixtureConnection, SuperTabLaunchFixture, tabId;+import '../test/super_tab_route_test.dart' show routeRow, decision;import '../test/support/super_tab_fixture.dart'show projectFixture, conversationFixture;@@ -147,6 +149,9 @@ void main() {server.append('Keep changes on the device and sync when the connection returns.',);+ server.append('Routed to Multiply');+ server.messages.last['source'] = routeRow()['source'];+ server.routeDecisions['d1'] = decision();debugPrint('Swarm fixture: load conversation controller');final c = await tester.runAsync(() async {final controller = await f.app.superTabs@@ -212,6 +217,17 @@ void main() {}await shot('conversation');+ expect(+ tester.getTopLeft(find.text('Routed to Multiply')).dx,+ tester.getTopLeft(find.byType(SuperTabMessageText).first).dx,+ );+ expect(find.text('Change'), findsNothing);+ await tester.tap(find.text('Details'));+ await tester.pumpAndSettle();+ expect(find.text('schema change, high risk'), findsOneWidget);+ await shot('routing-details');+ await tester.tap(find.text('Hide details'));+ await tester.pumpAndSettle();await tester.tap(find.byTooltip('Project options'));await tester.pumpAndSettle();await shot('project-menu');diff --git a/desktop/lib/super_tabs/message_row.dart b/desktop/lib/super_tabs/message_row.dartindex 10a595486..ae51c6827 100644--- a/desktop/lib/super_tabs/message_row.dart+++ b/desktop/lib/super_tabs/message_row.dart@@ -43,6 +43,12 @@ class SuperTabMessageRow extends StatefulWidget {final VoidCallback onReturnToComposer;final List<Widget> receipts;+ // Routing notes share the message body column, including grouped messages.+ static const horizontalInset = 24.0;+ static const avatarSize = 28.0;+ static const avatarGap = 12.0;+ static const bodyInset = horizontalInset + avatarSize + avatarGap;+/// Compact only a few short updates. Reports and long runs retain their own/// speaker identity, so scrolling through agent output does not lose the who.static Set<String> consecutiveUpdates(List<SuperTabMessage> messages) {@@ -182,12 +188,15 @@ class _SuperTabMessageRowState extends State<SuperTabMessageRow> {child: Stack(children: [Padding(- padding: const EdgeInsets.fromLTRB(24, 6, 24, 6),+ padding: const EdgeInsets.symmetric(+ horizontal: SuperTabMessageRow.horizontalInset,+ vertical: 6,+ ),child: Row(crossAxisAlignment: CrossAxisAlignment.start,children: [SizedBox(- width: 28,+ width: SuperTabMessageRow.avatarSize,child: widget.grouped? null: ExcludeSemantics(@@ -201,12 +210,12 @@ class _SuperTabMessageRowState extends State<SuperTabMessageRow> {: superTabPersonName(message.authorName,),- size: 28,+ size: SuperTabMessageRow.avatarSize,),),),),- const SizedBox(width: 12),+ const SizedBox(width: SuperTabMessageRow.avatarGap),Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start,diff --git a/desktop/lib/super_tabs/route_row.dart b/desktop/lib/super_tabs/route_row.dartindex d16ffc09a..4718ad6e8 100644--- a/desktop/lib/super_tabs/route_row.dart+++ b/desktop/lib/super_tabs/route_row.dart@@ -7,12 +7,13 @@ import '../shared/widgets/app_dialog.dart';import '../widgets/desktop_chrome.dart';import 'controller.dart';import 'dialog_scope.dart';+import 'message_row.dart';import 'model.dart';import 'routing_policy.dart';import 'routing_policy_form.dart';-/// One routing decision in the conversation: who was chosen, how, and why.-/// Writers can change it afterwards; the Lead is told to hand the task over.+/// A read-only routing note. Reassignment belongs in the conversation with the+/// lead, rather than a control attached to an earlier routing decision.class SuperTabRouteRow extends StatefulWidget {const SuperTabRouteRow({super.key,@@ -29,298 +30,162 @@ class SuperTabRouteRow extends StatefulWidget {class _SuperTabRouteRowState extends State<SuperTabRouteRow> {Map<String, dynamic>? _details;- bool _expanded = false;- // Kept in the row, not a snackbar: a refusal must stay readable until the- // person tries again.- String? _problem;+ bool _expanded = false, _loading = false, _failed = false;++ String get _target {+ final title = widget.route.pick.title;+ // The CLI's titleOf writes "name · engine model effort · machine".+ // Preserve names containing separators, and unknown/legacy formats in full.+ final parts = RegExp(r'^(.*) · ((?:Claude|Codex) .*) · (.*)$')+ .firstMatch(title);+ if (parts == null) return title;+ final name = parts.group(1)!;+ return name == 'New agent'+ ? 'new ${parts.group(2)!.split(' ').first} agent'+ : name;+ }String get _how => switch (widget.route.via) {'jev' => 'Jev ${((widget.route.p ?? 0) * 100).round()}%',- 'only' => 'only candidate',+ 'only' => 'Only available candidate',_ => switch (widget.route.fallback) {- 'unavailable' => 'by policy order (Jev unavailable)',- 'unsure' => 'by policy order (Jev unsure)',- _ => 'by policy order',+ 'unavailable' => 'Policy order (Jev unavailable)',+ 'unsure' => 'Policy order (Jev unsure)',+ _ => 'Policy order',},};- /// The recorded decision, loaded once; null when it cannot be read.- Future<Map<String, dynamic>?> _load() async {- if (_details != null) return _details;+ Future<void> _load() async {+ if (_loading || _details != null) return;+ setState(() {+ _loading = true;+ _failed = false;+ });try {final answer = await widget.controller.request('GET','/api/super-tabs/${widget.controller.tabId}/route-decisions/${widget.route.decisionId}',);- if (mounted) _details = answer;- return answer;+ if (mounted) setState(() => _details = answer);} catch (_) {- return null;+ if (mounted) setState(() => _failed = true);+ } finally {+ if (mounted) setState(() => _loading = false);}}- Future<void> _toggle() async {+ void _toggle() {setState(() => _expanded = !_expanded);- if (!_expanded || _details != null) return;- final answer = await _load();- if (mounted) setState(() => _details = answer ?? const {'error': true});+ if (_expanded) unawaited(_load());}- Future<void> _change() async {- final c = widget.controller;- final choice = await showAppDialog<(String, String)>(- context: context,- builder: (_) => SuperTabDialogScope(- controller: c,- child: _ChangeDialog(route: widget.route, load: _load),- ),- );- if (choice == null || !mounted) return;- setState(() => _problem = null);- // command() answers null without trying when the controller is busy, so- // that case must not be reported as a refusal.- if (c.saving || c.hasPendingAction) {- setState(() => _problem = 'Finish the pending action first.');- return;- }- final result = await c.command({- 'type': 'route.override',- 'decisionId': widget.route.decisionId,- 'candidateId': choice.$1,- 'reason': choice.$2,- });- // An attempted command resets operationError first, so a value here is- // this attempt's refusal.- if (result == null && mounted) {- setState(- () => _problem = c.operationError ?? 'Could not change the route.',- );- return;- }- // The decision now names the new choice; a kept copy would offer it as an- // alternative on the next Change.- _details = null;- if (_expanded && mounted) {- final answer = await _load();- if (mounted) setState(() => _details = answer ?? const {'error': true});- }- }+ Widget _action(String label, VoidCallback onPressed) => TextButton(+ onPressed: onPressed,+ style:+ TextButton.styleFrom(+ foregroundColor: Theme.of(context).colorScheme.onSurfaceVariant,+ backgroundColor: Colors.transparent,+ side: BorderSide.none,+ minimumSize: const Size(0, 28),+ padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),+ tapTargetSize: MaterialTapTargetSize.shrinkWrap,+ textStyle: DesktopChrome.metadata(),+ ).copyWith(+ side: WidgetStateProperty.resolveWith(+ (states) => states.contains(WidgetState.focused)+ ? TextButtonTheme.of(context).style?.side?.resolve(states)+ : BorderSide.none,+ ),+ ),+ child: Text(label),+ );@overrideWidget build(BuildContext context) {+ grid.AppTheme.watch(context);final r = widget.route;+ final style = DesktopChrome.metadata(+ color: Theme.of(context).colorScheme.onSurfaceVariant,+ );return Padding(- padding: const EdgeInsets.symmetric(vertical: 4),+ padding: const EdgeInsets.fromLTRB(+ SuperTabMessageRow.bodyInset,+ 4,+ SuperTabMessageRow.horizontalInset,+ 4,+ ),child: Column(crossAxisAlignment: CrossAxisAlignment.start,children: [Wrap(- spacing: 8,+ spacing: 4,crossAxisAlignment: WrapCrossAlignment.center,children: [- InkWell(- onTap: _toggle,- child: Text(- 'Routed to ${r.pick.title} — $_how · "${r.why}"',- style: DesktopChrome.metadata(),- ),- ),+ Text('Routed to $_target', style: style),if (r.belowFloor)- Container(- padding: const EdgeInsets.symmetric(- horizontal: 6,- vertical: 2,- ),- decoration: BoxDecoration(- color: grid.AppPalette.warn.withValues(alpha: 0.12),- borderRadius: BorderRadius.circular(4),- ),+ Padding(+ padding: const EdgeInsets.only(left: 8),child: Text('Below quality floor',- style: DesktopChrome.metadata(color: grid.AppPalette.warn),+ style: style.copyWith(color: grid.AppPalette.warn),),),- if (widget.controller.canWrite && r.alternatives.isNotEmpty)- TextButton(- onPressed: () => unawaited(_change()),- child: const Text('Change'),- ),+ Semantics(+ expanded: _expanded,+ child: _action(_expanded ? 'Hide details' : 'Details', _toggle),+ ),],),- if (_problem != null)- Text(_problem!, style: DesktopChrome.metadata()),- if (_expanded) _detailsView(),+ if (_expanded)+ Padding(+ padding: const EdgeInsets.only(top: 4, bottom: 4),+ child: DefaultTextStyle(style: style, child: _detailsView()),+ ),],),);}Widget _detailsView() {- final d = _details;- if (d == null) {- return const Padding(- padding: EdgeInsets.all(8),- child: LinearProgressIndicator(),- );- }- if (d['error'] == true) {- return Text(- 'Could not load this decision.',- style: DesktopChrome.metadata(),- );- }- final record = superTabMap(d['record'] ?? const {});+ final r = widget.route;+ final record = superTabMap(_details?['record'] ?? const {});final candidates = (record['candidates'] as List? ?? const []).map(superTabMap,);final excluded = (record['excluded'] as List? ?? const []).map(superTabMap);- return Padding(- padding: const EdgeInsets.only(left: 12, top: 4),- child: Column(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- Text(- 'Quality floor ${record['floor']}${record['notes'] == true ? ' · policy notes applied' : ''}',- style: DesktopChrome.metadata(),+ return Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ spacing: 4,+ children: [+ Text(r.pick.title),+ if (r.why.isNotEmpty) Text(r.why),+ Text('Selection: $_how'),+ if (_loading) const Text('Loading details…'),+ if (_failed)+ Wrap(+ spacing: 4,+ crossAxisAlignment: WrapCrossAlignment.center,+ children: [+ const Text('Could not load this decision.'),+ _action('Retry', () => unawaited(_load())),+ ],),+ if (record['floor'] case final num floor) Text('Quality floor $floor'),+ if (record['notes'] == true) const Text('Policy notes applied'),+ if (candidates.isNotEmpty) ...[+ const SizedBox(height: 4),+ const Text('Considered'),for (final c in candidates)- Text('${c['id']}: ${c['label']}', style: DesktopChrome.metadata()),- for (final e in excluded)- Text(- 'Not possible: ${e['title']} — ${e['reason']}',- style: DesktopChrome.metadata(),- ),- ],- ),- );- }-}--class _Option {- const _Option(this.id, this.title, this.label);- final String id, title;- final String? label;-}--class _ChangeDialog extends StatefulWidget {- const _ChangeDialog({required this.route, required this.load});- final SuperTabRoute route;- final Future<Map<String, dynamic>?> Function() load;- @override- State<_ChangeDialog> createState() => _ChangeDialogState();-}--class _ChangeDialogState extends State<_ChangeDialog> {- String? _choice;- List<_Option>? _options;- bool _failed = false;- final _reason = TextEditingController();-- @override- void initState() {- super.initState();- unawaited(_open());- }-- @override- void dispose() {- _reason.dispose();- super.dispose();- }-- Future<void> _open() async {- final d = await widget.load();- if (!mounted) return;- if (d == null) {- setState(() => _failed = true);- return;- }- final record = superTabMap(d['record'] ?? const {});- final candidates = [- for (final c in record['candidates'] as List? ?? const [])- if (c is Map && c['id'] is String) superTabMap(c),- ];- final pick = record['pick'];- final current =- superTabMap(d['override'] ?? const {})['candidateId'] ??- (pick is Map ? pick['id'] : pick);- String? labelOf(String id) => candidates- .where((c) => c['id'] == id)- .map((c) => c['label'])- .whereType<String>()- .firstOrNull;- final options = <_Option>[- for (final a in widget.route.alternatives)- if (a.id != current) _Option(a.id, a.title, labelOf(a.id)),- ];- for (final c in candidates) {- final id = c['id'] as String;- if (id == current || options.any((o) => o.id == id)) continue;- options.add(- _Option(- id,- c['title'] as String? ?? id,- c['label'] is String ? c['label'] as String : null,- ),- );- }- setState(() => _options = options);- }-- @override- Widget build(BuildContext context) {- final reason = _reason.text.trim();- final ready = _choice != null && reason.isNotEmpty && reason.length <= 300;- final options = _options;- return AlertDialog(- title: const Text('Change who does this task'),- content: SizedBox(- width: 480,- child: Column(- mainAxisSize: MainAxisSize.min,- children: [- if (_failed)+ if (c['title'] case final String title)Text(- 'Could not load this decision. Close and try again.',- style: DesktopChrome.control(),- )- else if (options == null)- const LinearProgressIndicator()- else- RadioGroup<String>(- groupValue: _choice,- onChanged: (v) => setState(() => _choice = v),- child: Column(- children: [- for (final o in options)- RadioListTile<String>(- value: o.id,- title: Text(o.title),- subtitle: o.label == null ? null : Text(o.label!),- ),- ],- ),+ [+ title,+ if (c['label'] case final String label) label,+ ].join(' — '),),- TextField(- controller: _reason,- maxLength: 300,- decoration: const InputDecoration(labelText: 'Reason'),- onChanged: (_) => setState(() {}),- ),- ],- ),- ),- actions: [- TextButton(- onPressed: () => Navigator.of(context).pop(),- child: const Text('Cancel'),- ),- FilledButton(- onPressed: ready- ? () => Navigator.of(context).pop((_choice!, reason))- : null,- child: const Text('Change'),- ),+ ],+ for (final e in excluded)+ Text('Unavailable: ${e['title']} — ${e['reason']}'),],);}diff --git a/desktop/test/super_tab_route_test.dart b/desktop/test/super_tab_route_test.dartindex 925db9ee6..7b233c027 100644--- a/desktop/test/super_tab_route_test.dart+++ b/desktop/test/super_tab_route_test.dart@@ -1,9 +1,18 @@+import 'dart:async';+import 'dart:io';+import 'package:flutter/material.dart';+import 'package:flutter/services.dart';import 'package:flutter_test/flutter_test.dart';+import 'package:harness/shared/theme/app_theme.dart' as grid;+import 'package:harness/super_tabs/controller.dart';+import 'package:harness/super_tabs/message_row.dart';+import 'package:harness/super_tabs/message_text.dart';import 'package:harness/super_tabs/model.dart';import 'package:harness/super_tabs/route_row.dart';-import 'super_tab_launch_test.dart' show SuperTabLaunchFixture, tabId;+import 'support/capture.dart';+import 'support/super_tab_fixture.dart';Map<String, dynamic> routeRow({String via = 'jev',@@ -62,17 +71,66 @@ Map<String, dynamic> decision({String? overrideTo}) => {'override': overrideTo == null ? null : {'candidateId': overrideTo},};-Widget rowOf(SuperTabMessage message, controller) => MaterialApp(+Widget rowOf(+ SuperTabMessage message,+ SuperTabController controller, {+ Brightness brightness = Brightness.dark,+ double scale = 1,+ bool withMessage = false,+}) => MaterialApp(+ debugShowCheckedModeBanner: false,+ theme: grid.buildAppTheme(brightness: brightness),+ builder: (context, child) => MediaQuery(+ data: MediaQuery.of(+ context,+ ).copyWith(textScaler: TextScaler.linear(scale), highContrast: scale > 1),+ child: child!,+ ),home: Scaffold(- body: SuperTabRouteRow(- message: message,- route: message.route!,- controller: controller,+ body: ListView(+ children: [+ if (withMessage)+ SuperTabMessageRow(+ message: SuperTabMessage.fromJson({+ ...routeRow(),+ 'source': <String, dynamic>{},+ 'text': 'I’ll ask Multiply to review the schema change.',+ }),+ author: 'Lead',+ agent: SuperTabAgent.fromJson({+ 'id': 'lead',+ 'name': 'Lead',+ 'machineId': 'm',+ 'harnessId': 'h',+ 'contributorId': 'owner',+ 'configuration': {'engine': 'codex'},+ }),+ onReturnToComposer: () {},+ receipts: const [],+ ),+ SuperTabRouteRow(+ message: message,+ route: message.route!,+ controller: controller,+ ),+ ],),),);void main() {+ final captureDir = Platform.environment['HARNESS_ROUTE_CAPTURE_DIR'];+ setUpAll(() => loadCaptureFonts(captureDir));+ final originalBrightness = grid.AppTheme.brightness.value;+ setUp(() => grid.AppTheme.brightness.value = Brightness.dark);+ tearDown(() => grid.AppTheme.brightness.value = originalBrightness);++ SuperTabController controller(ConversationServer server) {+ final c = server.controller();+ addTearDown(c.dispose);+ return c;+ }+test('parses route sources', () {final message = SuperTabMessage.fromJson(routeRow());expect(message.route!.decisionId, 'd1');@@ -116,270 +174,179 @@ void main() {});for (final c in [- (via: 'jev', p: 0.82, below: false, fallback: null, text: 'Jev 82%'),+ (via: 'jev', fallback: null, text: 'Jev 82%'),+ (via: 'order', fallback: null, text: 'Policy order'),+ (via: 'order', fallback: 'unsure', text: 'Policy order (Jev unsure)'),(via: 'order',- p: null,- below: false,- fallback: null,- text: 'by policy order ·',- ),- (- via: 'order',- p: null,- below: false,- fallback: 'unsure',- text: 'by policy order (Jev unsure)',- ),- (- via: 'order',- p: null,- below: false,fallback: 'unavailable',- text: 'by policy order (Jev unavailable)',- ),- (- via: 'only',- p: null,- below: true,- fallback: null,- text: 'Below quality floor',+ text: 'Policy order (Jev unavailable)',),+ (via: 'only', fallback: null, text: 'Only available candidate'),]) {- testWidgets('renders ${c.via} ${c.fallback ?? ''}', (tester) async {- final f = SuperTabLaunchFixture();- final controller = await f.app.superTabs.open(tabId);+ testWidgets('keeps ${c.via} ${c.fallback ?? ''} explanation in Details', (+ tester,+ ) async {+ final server = ConversationServer();+ server.routeDecisions['d1'] = decision();final message = SuperTabMessage.fromJson(- routeRow(via: c.via, p: c.p, belowFloor: c.below, fallback: c.fallback),+ routeRow(via: c.via, fallback: c.fallback),);- await tester.pumpWidget(rowOf(message, controller));- expect(- find.textContaining('Routed to Multiply · Claude opus high · remote-1'),- findsOneWidget,- );- expect(find.textContaining(c.text), findsOneWidget);- // The row quotes the Lead's reason, never the verdict's own text.- expect(find.textContaining('"schema change, high risk"'), findsOneWidget);- f.app.superTabs.dispose();+ await tester.pumpWidget(rowOf(message, controller(server)));+ expect(find.text('Routed to Multiply'), findsOneWidget);+ expect(find.textContaining('schema change'), findsNothing);+ expect(find.textContaining('Claude opus'), findsNothing);+ expect(find.textContaining('Selection:'), findsNothing);+ expect(find.text('Change'), findsNothing);+ expect(find.text('Reassign'), findsNothing);+ await tester.tap(find.text('Details'));+ await tester.pumpAndSettle();+ expect(find.text('Selection: ${c.text}'), findsOneWidget);+ expect(find.text('schema change, high risk'), findsOneWidget);+ expect(find.text('Quality floor 3'), findsOneWidget);+ expect(find.textContaining('Opus, deepest review'), findsOneWidget);+ await tester.tap(find.text('Hide details'));+ await tester.pumpAndSettle();+ expect(find.textContaining('schema change'), findsNothing);+ expect(server.posts, isEmpty);});}- testWidgets('a second Change does not offer the choice just made', (- tester,- ) async {- final f = SuperTabLaunchFixture();- f.connection.server.routeDecisions['d1'] = decision();- final controller = await f.app.superTabs.open(tabId);- await controller.refresh();- final message = SuperTabMessage.fromJson(routeRow());- await tester.pumpWidget(rowOf(message, controller));- await tester.tap(find.text('Change'));- await tester.pumpAndSettle();- expect(find.text('Sonnet, fastest turnaround'), findsOneWidget);- await tester.tap(find.textContaining('New agent · Claude sonnet medium'));- await tester.pumpAndSettle();- await tester.enterText(find.byType(TextField), 'Because.');- await tester.pump();- // The backend now names the choice as the decision's override.- f.connection.server.routeDecisions['d1'] = decision(overrideTo: 'c1');- await tester.tap(find.widgetWithText(FilledButton, 'Change'));- await tester.pumpAndSettle();- await tester.tap(find.text('Change'));- await tester.pumpAndSettle();- expect(find.text('Sonnet, fastest turnaround'), findsNothing);- expect(find.text('Codex, cheapest'), findsOneWidget);- f.app.superTabs.dispose();- });-- testWidgets('an open details view is read again after a Change', (+ testWidgets('quality warning stays visible without opening Details', (tester,) async {- final f = SuperTabLaunchFixture();- f.connection.server.routeDecisions['d1'] = decision();- final controller = await f.app.superTabs.open(tabId);- await controller.refresh();- final message = SuperTabMessage.fromJson(routeRow());- await tester.pumpWidget(rowOf(message, controller));- await tester.tap(find.textContaining('Routed to'));- await tester.pumpAndSettle();- expect(find.textContaining('Quality floor 3'), findsOneWidget);- f.connection.server.routeDecisions['d1'] = {- ...decision(overrideTo: 'c1'),- 'record': {...(decision()['record'] as Map), 'floor': 2},- };- await tester.tap(find.text('Change'));- await tester.pumpAndSettle();- await tester.tap(find.textContaining('New agent · Claude sonnet medium'));- await tester.pumpAndSettle();- await tester.enterText(find.byType(TextField), 'Because.');- await tester.pump();- await tester.tap(find.widgetWithText(FilledButton, 'Change'));- await tester.pumpAndSettle();- expect(find.textContaining('Quality floor 2'), findsOneWidget);- f.app.superTabs.dispose();+ final message = SuperTabMessage.fromJson(routeRow(belowFloor: true));+ await tester.pumpWidget(rowOf(message, controller(ConversationServer())));+ expect(find.text('Below quality floor'), findsOneWidget);+ expect(find.text('schema change, high risk'), findsNothing);});- testWidgets(- 'Change needs write access and a reason, then sends route.override',- (tester) async {- final f = SuperTabLaunchFixture();- f.connection.server.routeDecisions['d1'] = decision();- final controller = await f.app.superTabs.open(tabId);- await controller.refresh();- final message = SuperTabMessage.fromJson(routeRow());- await tester.pumpWidget(rowOf(message, controller));- await tester.tap(find.text('Change'));- await tester.pumpAndSettle();- await tester.tap(- find.textContaining('New agent · Claude sonnet medium · mac'),- );- await tester.pumpAndSettle();- final confirm = find.widgetWithText(FilledButton, 'Change');- expect(tester.widget<FilledButton>(confirm).onPressed, isNull);- await tester.enterText(- find.byType(TextField),- 'Opus quota is needed elsewhere.',+ for (final c in [+ ('New agent · Codex default default · Studio Mac', 'new Codex agent'),+ ('Builder · UI · Claude opus high · Studio Mac', 'Builder · UI'),+ ('Custom route title', 'Custom route title'),+ ]) {+ testWidgets('keeps target identity for ${c.$1}', (tester) async {+ final json = routeRow();+ (json['source'] as Map)['pick'] = {'id': 'c0', 'title': c.$1};+ await tester.pumpWidget(+ rowOf(SuperTabMessage.fromJson(json), controller(ConversationServer())),);- await tester.pump();- await tester.tap(confirm);- await tester.pumpAndSettle();- final sent =- f.connection.calls- .where(- (call) =>- (call.$2['path'] as String?)?.endsWith('/commands') ==- true,- )- .last- .$2['body']- as Map;- expect(sent['command'], {- 'type': 'route.override',- 'decisionId': 'd1',- 'candidateId': 'c1',- 'reason': 'Opus quota is needed elsewhere.',- });- f.app.superTabs.dispose();- },- );-- testWidgets('a viewer sees no Change', (tester) async {- final f = SuperTabLaunchFixture();- (f.connection.server.state['people'] as List)[0]['role'] = 'viewer';- final controller = await f.app.superTabs.open(tabId);- await controller.refresh();- final message = SuperTabMessage.fromJson(routeRow());- await tester.pumpWidget(rowOf(message, controller));- expect(find.text('Change'), findsNothing);- f.app.superTabs.dispose();- });+ expect(find.text('Routed to ${c.$2}'), findsOneWidget);+ });+ }- testWidgets('Change shows the refusal', (tester) async {- final f = SuperTabLaunchFixture();- f.connection.server.routeDecisions['d1'] = decision();- f.connection.server.refuse = {- 'code': 'ROUTE_CLOSED',- 'message':- 'This routing decision is no longer open. Route the task again.',- };- final controller = await f.app.superTabs.open(tabId);- await controller.refresh();- final message = SuperTabMessage.fromJson(routeRow());- await tester.pumpWidget(rowOf(message, controller));- await tester.tap(find.text('Change'));- await tester.pumpAndSettle();- await tester.tap(find.textContaining('New agent · Claude sonnet'));+ testWidgets('Details opens and closes from the keyboard', (tester) async {+ final server = ConversationServer();+ server.routeDecisions['d1'] = decision();+ await tester.pumpWidget(+ rowOf(SuperTabMessage.fromJson(routeRow()), controller(server)),+ );+ await tester.sendKeyEvent(LogicalKeyboardKey.tab);+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);await tester.pumpAndSettle();- await tester.enterText(find.byType(TextField), 'Because.');- await tester.pump();- await tester.tap(find.widgetWithText(FilledButton, 'Change'));+ expect(find.text('Hide details'), findsOneWidget);+ expect(find.text('schema change, high risk'), findsOneWidget);+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);await tester.pumpAndSettle();- expect(find.textContaining('no longer open'), findsOneWidget);- f.app.superTabs.dispose();+ expect(find.text('Details'), findsOneWidget);+ expect(server.posts, isEmpty);});- testWidgets(- 'Change lists alternatives with criterion lines, minus the current choice',- (tester) async {- final f = SuperTabLaunchFixture();- f.connection.server.routeDecisions['d1'] = decision();- final controller = await f.app.superTabs.open(tabId);- await controller.refresh();- final message = SuperTabMessage.fromJson(routeRow());- await tester.pumpWidget(rowOf(message, controller));- await tester.tap(find.text('Change'));- await tester.pumpAndSettle();- expect(find.text('Sonnet, fastest turnaround'), findsOneWidget);- expect(find.text('Codex, cheapest'), findsOneWidget);- expect(find.text('Opus, deepest review'), findsNothing);- final order = [- tester.getTopLeft(find.text('Sonnet, fastest turnaround')).dy,- tester.getTopLeft(find.text('Codex, cheapest')).dy,- ];- expect(order[0], lessThan(order[1]));- f.app.superTabs.dispose();- },- );-- testWidgets('Change excludes an earlier override target', (tester) async {- final f = SuperTabLaunchFixture();- f.connection.server.routeDecisions['d1'] = decision(overrideTo: 'c1');- final controller = await f.app.superTabs.open(tabId);- await controller.refresh();- final message = SuperTabMessage.fromJson(routeRow());- await tester.pumpWidget(rowOf(message, controller));- await tester.tap(find.text('Change'));+ testWidgets('failed details preserve the reason and can retry', (+ tester,+ ) async {+ final server = ConversationServer();+ await tester.pumpWidget(+ rowOf(SuperTabMessage.fromJson(routeRow()), controller(server)),+ );+ await tester.tap(find.text('Details'));+ await tester.pumpAndSettle();+ expect(find.text('Could not load this decision.'), findsOneWidget);+ expect(find.text('schema change, high risk'), findsOneWidget);+ server.routeDecisions['d1'] = decision();+ await tester.tap(find.text('Retry'));await tester.pumpAndSettle();- expect(find.text('Sonnet, fastest turnaround'), findsNothing);- expect(find.text('Codex, cheapest'), findsOneWidget);- f.app.superTabs.dispose();+ expect(find.text('Could not load this decision.'), findsNothing);+ expect(find.text('Quality floor 3'), findsOneWidget);+ expect(server.posts, isEmpty);});- testWidgets('Change says so when the decision cannot be loaded', (+ testWidgets('a late details response does not reopen a collapsed row', (tester,) async {- final f = SuperTabLaunchFixture();- final controller = await f.app.superTabs.open(tabId);- await controller.refresh();- final message = SuperTabMessage.fromJson(routeRow());- await tester.pumpWidget(rowOf(message, controller));- await tester.tap(find.text('Change'));+ final response = Completer<Map<String, dynamic>>();+ var reads = 0;+ final c = SuperTabController(+ tabId: 'tab',+ accountId: 'owner',+ save: (_) async {},+ request: (method, path, {body}) {+ reads++;+ return response.future;+ },+ );+ addTearDown(c.dispose);+ await tester.pumpWidget(rowOf(SuperTabMessage.fromJson(routeRow()), c));+ expect(reads, 0);+ await tester.tap(find.text('Details'));+ await tester.pump();+ expect(find.text('Loading details…'), findsOneWidget);+ await tester.tap(find.text('Hide details'));+ await tester.pump();+ response.complete(decision());+ await tester.pumpAndSettle();+ expect(find.text('Details'), findsOneWidget);+ expect(find.text('Quality floor 3'), findsNothing);+ await tester.tap(find.text('Details'));await tester.pumpAndSettle();- expect(find.textContaining('Could not load this decision'), findsOneWidget);- expect(find.byType(RadioListTile<String>), findsNothing);- f.app.superTabs.dispose();+ expect(reads, 1);+ expect(find.text('Quality floor 3'), findsOneWidget);});- testWidgets(- 'Change while another action is pending is not reported as a refusal',- (tester) async {- final f = SuperTabLaunchFixture();- f.connection.server.routeDecisions['d1'] = decision();- final controller = await f.app.superTabs.open(tabId);- await controller.refresh();- f.connection.server.loseReply = true;- await controller.command({- 'type': 'conversation.create',- 'title': 'Other',- 'brief': '',- 'checks': <dynamic>[],+ for (final brightness in Brightness.values) {+ for (final scale in [1.0, 2.0]) {+ testWidgets('routing aligns with chat at ${brightness.name} ${scale}x', (+ tester,+ ) async {+ grid.AppTheme.brightness.value = brightness;+ await tester.binding.setSurfaceSize(Size(scale == 1 ? 800 : 400, 900));+ addTearDown(() => tester.binding.setSurfaceSize(null));+ final server = ConversationServer();+ server.routeDecisions['d1'] = decision();+ await tester.pumpWidget(+ rowOf(+ SuperTabMessage.fromJson(routeRow()),+ controller(server),+ brightness: brightness,+ scale: scale,+ withMessage: true,+ ),+ );+ await tester.pumpAndSettle();+ final messageX = tester.getTopLeft(find.byType(SuperTabMessageText)).dx;+ final routeX = tester.getTopLeft(find.text('Routed to Multiply')).dx;+ expect(routeX, messageX);+ expect(tester.takeException(), isNull);+ await captureWindow(+ tester,+ captureDir,+ 'route-${brightness.name}-${scale}x',+ );+ await tester.tap(find.text('Details'));+ await tester.pumpAndSettle();+ expect(+ tester.getTopLeft(find.text('schema change, high risk')).dx,+ messageX,+ );+ expect(tester.takeException(), isNull);+ await captureWindow(+ tester,+ captureDir,+ 'details-${brightness.name}-${scale}x',+ );+ expect(server.posts, isEmpty);});- expect(controller.hasPendingAction, isTrue);- final before = f.connection.server.posts.length;- final message = SuperTabMessage.fromJson(routeRow());- await tester.pumpWidget(rowOf(message, controller));- await tester.tap(find.text('Change'));- await tester.pumpAndSettle();- await tester.tap(find.textContaining('New agent · Claude sonnet'));- await tester.pumpAndSettle();- await tester.enterText(find.byType(TextField), 'Because.');- await tester.pump();- await tester.tap(find.widgetWithText(FilledButton, 'Change'));- await tester.pumpAndSettle();- expect(find.text('Finish the pending action first.'), findsOneWidget);- expect(find.textContaining('not confirmed'), findsNothing);- expect(f.connection.server.posts.length, before);- f.app.superTabs.dispose();- },- );+ }+ }}