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.

fix(mobile): an emoji where a name is cut no longer crashes Focus or Settings

dee238c30d92ecc
diff --git a/mobile/lib/phone/settings_page.dart b/mobile/lib/phone/settings_page.dart
index 212b7400b..e436f7ddd 100644
--- a/mobile/lib/phone/settings_page.dart
+++ b/mobile/lib/phone/settings_page.dart
@@ -277,7 +277,12 @@ class _Avatar extends StatelessWidget {
final source = (user?.name?.trim().isNotEmpty ?? false)
? user!.name!.trim()
: (user?.email ?? '');
- final initial = source.isEmpty ? '?' : source.substring(0, 1).toUpperCase();
+ // ⚠️ The first CHARACTER, not the first code unit: a name that opens with an emoji starts on
+ // half of a surrogate pair, and a lone half is a string the text engine refuses — it threw,
+ // and took the whole Settings page down with it.
+ final initial = source.isEmpty
+ ? '?'
+ : source.characters.first.toUpperCase();
return Container(
// 34, matching the stepper beside it two rows down: both are the tallest thing in their row,
// and at 38 this one alone pushed its row past [kSettingsRowHeight] while the others sat on
diff --git a/mobile/lib/phone/terminal_page.dart b/mobile/lib/phone/terminal_page.dart
index 7be215d85..4b0842a46 100644
--- a/mobile/lib/phone/terminal_page.dart
+++ b/mobile/lib/phone/terminal_page.dart
@@ -1089,8 +1089,14 @@ class _TerminalPageState extends State<TerminalPage>
false;
/// A window name the way tmux shortens one: the first dozen characters.
- static String _windowName(String name) =>
- name.length <= 12 ? name : name.substring(0, 12);
+ ///
+ /// ⚠️ Characters as a person counts them, not UTF-16 units: cut by `substring`, a name with an
+ /// emoji near the twelfth unit kept half a surrogate pair, and the text engine throws on a string
+ /// like that — the title, and the page under it, went with it.
+ static String _windowName(String name) {
+ final characters = name.characters;
+ return characters.length <= 12 ? name : characters.take(12).toString();
+ }
/// Where the reader is while scrolled up in the history — see [_CopyModePosition].
final _scrollback = ValueNotifier<({int above, int total})?>(null);
diff --git a/mobile/lib/phone/terminal_title.dart b/mobile/lib/phone/terminal_title.dart
index 5dff25803..0492d48df 100644
--- a/mobile/lib/phone/terminal_title.dart
+++ b/mobile/lib/phone/terminal_title.dart
@@ -56,9 +56,15 @@ class TerminalTitle extends StatelessWidget {
/// A long branch shortened in the middle — `fix/login-refresh-token` → `fix/logi…sh-token` — where
/// both ends say which one it is.
- static String _short(String branch) => branch.length <= 30
- ? branch
- : '${branch.substring(0, 14)}…${branch.substring(branch.length - 14)}';
+ ///
+ /// Cut by characters, not UTF-16 units, for the reason `_windowName` in `terminal_page.dart`
+ /// gives: half an emoji is a string the text engine throws on.
+ static String _short(String branch) {
+ final characters = branch.characters;
+ return characters.length <= 30
+ ? branch
+ : '${characters.take(14)}…${characters.skip(characters.length - 14)}';
+ }
@override
Widget build(BuildContext context) {
diff --git a/mobile/test/phone_edge/edge_fixture.dart b/mobile/test/phone_edge/edge_fixture.dart
index b47f4a804..b09bb1f1a 100644
--- a/mobile/test/phone_edge/edge_fixture.dart
+++ b/mobile/test/phone_edge/edge_fixture.dart
@@ -328,6 +328,9 @@ Future<void> expectNoLayoutErrors(
}
}
}
+ // What the screens started — a machine being re-reached, a request's timeout — runs out here,
+ // before the test's end checks for timers left behind.
+ await tester.pump(const Duration(seconds: 30));
expect(failures, isEmpty, reason: failures.join('\n'));
}
diff --git a/mobile/test/phone_edge/find_layout_test.dart b/mobile/test/phone_edge/find_layout_test.dart
new file mode 100644
index 000000000..7bdc572bb
--- /dev/null
+++ b/mobile/test/phone_edge/find_layout_test.dart
@@ -0,0 +1,152 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness_mobile/core/models.dart';
+import 'package:harness_mobile/phone/terminal_search.dart';
+import 'package:harness_mobile/state/app_state.dart';
+import 'package:harness_mobile/state/pending_question.dart';
+
+import 'edge_fixture.dart';
+
+/// Find — every agent on every computer, over Focus — laid out at every phone, scale and
+/// brightness: none, one and two hundred agents, names that break layouts, each of its modes, and
+/// a machine that has gone away. None may report an overflow.
+void main() {
+ setUpAll(loadRealFontsIfAsked);
+
+ Future<void> pumpFind(
+ WidgetTester tester,
+ AppNotifier app,
+ double scale,
+ Brightness brightness, {
+ String? query,
+ }) async {
+ await tester.pumpWidget(
+ phoneApp(
+ Scaffold(
+ body: TerminalSearchOverlay(
+ notifier: app,
+ animation: const AlwaysStoppedAnimation(1),
+ onClose: () {},
+ showing: (machineId: 'm', agentId: 'a0'),
+ bottomInset: 34,
+ voice: edgeVoice().voice,
+ ),
+ ),
+ textScale: scale,
+ brightness: brightness,
+ ),
+ );
+ await frames(tester);
+ if (query != null) {
+ await tester.enterText(find.byType(TextField), query);
+ await frames(tester);
+ }
+ }
+
+ /// A few of [agents] asking, the way a busy account looks.
+ AppNotifier busyApp(List<Agent> agents, {String machineName = 'studio'}) {
+ final app = edgeApp(agents: agents, machineName: machineName);
+ final machine = app.stateOf('m')!;
+ for (final agent in agents.skip(1).take(3)) {
+ machine.blockedAgents[agent.id] = PendingQuestion(
+ machineId: 'm',
+ agentId: agent.id,
+ requestId: 'q-${agent.id}',
+ answerKey: '1',
+ prompt:
+ 'Run the migration on the test database, then drop the old '
+ 'table $longName?',
+ options: const ['Yes', 'No'],
+ multi: false,
+ since: DateTime.now(),
+ );
+ }
+ machine.processingAgentIds.add(agents.last.id);
+ return app;
+ }
+
+ testWidgets('no machine, nothing to find', (tester) async {
+ await expectNoLayoutErrors(tester, (scale, brightness) async {
+ final app = edgeApp(noMachines: true);
+ addTearDown(app.dispose);
+ await pumpFind(tester, app, scale, brightness);
+ expect(find.text('No harnesses running.'), findsOneWidget);
+ });
+ });
+
+ testWidgets('one agent, the one on screen', (tester) async {
+ await expectNoLayoutErrors(tester, (scale, brightness) async {
+ final app = edgeApp(agents: [edgeAgent('a0', name: emojiName)]);
+ addTearDown(app.dispose);
+ await pumpFind(tester, app, scale, brightness);
+ });
+ });
+
+ testWidgets('200 agents with long names, some asking, one working', (
+ tester,
+ ) async {
+ await expectNoLayoutErrors(tester, (scale, brightness) async {
+ final app = busyApp([
+ edgeAgent(
+ 'a0',
+ name: longName,
+ project: longProject,
+ branch: longBranch,
+ ),
+ edgeAgent('r', name: rtlName, project: longProject),
+ edgeAgent('e', name: emojiName, branch: longBranch),
+ ...manyAgents(197).map(
+ (agent) => edgeAgent('x${agent.id}', name: '$longName-${agent.id}'),
+ ),
+ ], machineName: longMachine);
+ addTearDown(app.dispose);
+ await pumpFind(tester, app, scale, brightness);
+ expect(find.text('needs you'), findsOneWidget);
+ });
+ });
+
+ for (final (mode, query) in [
+ ('typed', 'refactor'),
+ ('with no match', 'zzzz-nothing'),
+ ('commands', '>'),
+ ('help', '?'),
+ ('projects', '#'),
+ ('machines', '@'),
+ ('models', ':'),
+ ]) {
+ testWidgets('a query: $mode', (tester) async {
+ await expectNoLayoutErrors(tester, (scale, brightness) async {
+ final app = busyApp([
+ edgeAgent('a0', name: longName, project: longProject),
+ ...manyAgents(20),
+ ], machineName: longMachine);
+ addTearDown(app.dispose);
+ await pumpFind(tester, app, scale, brightness, query: query);
+ });
+ });
+ }
+
+ testWidgets('typing with the keyboard up', (tester) async {
+ await expectNoLayoutErrors(tester, (scale, brightness) async {
+ final app = busyApp([edgeAgent('a0', name: longName), ...manyAgents(30)]);
+ addTearDown(app.dispose);
+ await pumpFind(tester, app, scale, brightness, query: 'agent');
+ raiseKeyboard(tester);
+ await frames(tester);
+ lowerKeyboard(tester);
+ await frames(tester);
+ });
+ });
+
+ testWidgets('its machine offline', (tester) async {
+ await expectNoLayoutErrors(tester, (scale, brightness) async {
+ final app = edgeApp(
+ online: false,
+ machineName: longMachine,
+ agents: manyAgents(5, firstName: longName),
+ );
+ addTearDown(app.dispose);
+ await pumpFind(tester, app, scale, brightness);
+ });
+ });
+}
diff --git a/mobile/test/phone_edge/focus_edge_test.dart b/mobile/test/phone_edge/focus_edge_test.dart
new file mode 100644
index 000000000..fb11444fc
--- /dev/null
+++ b/mobile/test/phone_edge/focus_edge_test.dart
@@ -0,0 +1,105 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness_mobile/phone/terminal_page.dart';
+import 'package:harness_mobile/state/app_state.dart';
+import 'package:harness_mobile/state/pending_question.dart';
+
+import 'edge_fixture.dart';
+
+/// Focus's edge cases that are not about room: names cut short, machines that go away, taps that
+/// come twice, a keyboard and a mic at once.
+void main() {
+ Future<void> pumpFocus(
+ WidgetTester tester,
+ AppNotifier app, {
+ String agentId = 'a',
+ }) async {
+ setPhone(tester, largePhone);
+ await tester.pumpWidget(
+ phoneApp(
+ TerminalPage(
+ notifier: app,
+ machineId: 'm',
+ agentId: agentId,
+ voice: edgeVoice().voice,
+ ),
+ ),
+ );
+ await frames(tester);
+ }
+
+ void ask(AppNotifier app, String agentId) {
+ app.stateOf('m')!.blockedAgents[agentId] = PendingQuestion(
+ machineId: 'm',
+ agentId: agentId,
+ requestId: 'q-$agentId',
+ answerKey: '1',
+ prompt: 'Run the migration?',
+ options: const ['Yes', 'No'],
+ multi: false,
+ since: DateTime.now(),
+ );
+ }
+
+ bool wellFormed(String text) {
+ final units = text.codeUnits;
+ for (var i = 0; i < units.length; i++) {
+ final unit = units[i];
+ if (unit >= 0xD800 && unit <= 0xDBFF) {
+ if (i + 1 >= units.length ||
+ units[i + 1] < 0xDC00 ||
+ units[i + 1] > 0xDFFF) {
+ return false;
+ }
+ i++;
+ } else if (unit >= 0xDC00 && unit <= 0xDFFF) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ group('names cut short keep whole characters', () {
+ testWidgets('another harness asking, its emoji name cut at a dozen', (
+ tester,
+ ) async {
+ final app = edgeApp(
+ agents: [
+ edgeAgent('a'),
+ edgeAgent('b', name: emojiName),
+ ],
+ );
+ addTearDown(app.dispose);
+ ask(app, 'b');
+ await liveTerminal(app, 'a');
+ await pumpFocus(tester, app);
+
+ // Before: `substring(0, 12)` kept half of 👩, and the text engine threw on the title.
+ expect(tester.takeException(), isNull);
+ final asking = tester
+ .widgetList<Text>(find.byType(Text))
+ .map((text) => text.data ?? '')
+ .firstWhere((text) => text.endsWith(' asking'));
+ expect(asking, '🚀 ship it 👩‍💻🔥 asking');
+ expect(wellFormed(asking), isTrue);
+ await unmount(tester);
+ });
+
+ testWidgets('a long branch with emoji, shortened in the middle', (
+ tester,
+ ) async {
+ const branch = 'feat/🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀-launch-the-rocket';
+ final app = edgeApp(agents: [edgeAgent('a', branch: branch)]);
+ addTearDown(app.dispose);
+ await liveTerminal(app, 'a');
+ await pumpFocus(tester, app);
+
+ expect(tester.takeException(), isNull);
+ expect(
+ find.text('feat/🚀🚀🚀🚀🚀🚀🚀🚀🚀…nch-the-rocket'),
+ findsOneWidget,
+ );
+ await unmount(tester);
+ });
+ });
+}
diff --git a/mobile/test/phone_edge/settings_layout_test.dart b/mobile/test/phone_edge/settings_layout_test.dart
new file mode 100644
index 000000000..7e2836e8c
--- /dev/null
+++ b/mobile/test/phone_edge/settings_layout_test.dart
@@ -0,0 +1,72 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness_mobile/core/models.dart';
+import 'package:harness_mobile/demo/sample_mode.dart';
+import 'package:harness_mobile/phone/settings_page.dart';
+import 'package:harness_mobile/state/app_state.dart';
+
+import 'edge_fixture.dart';
+
+/// Settings laid out at every phone, scale and brightness — as the tab, as a page pushed from a
+/// terminal's menu, and inside the sample — for an account with every name long. None may report
+/// an overflow.
+void main() {
+ setUpAll(loadRealFontsIfAsked);
+
+ Future<void> pumpSettings(
+ WidgetTester tester,
+ AppNotifier app,
+ double scale,
+ Brightness brightness, {
+ bool large = true,
+ bool sample = false,
+ }) async {
+ final page = SettingsPage(notifier: app, large: large);
+ await tester.pumpWidget(
+ phoneApp(
+ sample ? SampleMode(session: FakeSample(app), child: page) : page,
+ textScale: scale,
+ brightness: brightness,
+ ),
+ );
+ await frames(tester);
+ // Every row, top to bottom: the list builds only what it shows.
+ await tester.drag(find.byType(ListView), const Offset(0, -3000));
+ await frames(tester);
+ }
+
+ for (final (label, name, email) in [
+ (
+ 'long',
+ longName,
+ ),
+ ('emoji', emojiName, '🦄@example.com'),
+ ('right-to-left', rtlName, 'مستخدم@example.com'),
+ ]) {
+ testWidgets('signed in with a $label name, the tab', (tester) async {
+ await expectNoLayoutErrors(tester, (scale, brightness) async {
+ final app = edgeApp(machineName: longMachine);
+ addTearDown(app.dispose);
+ app.currentUser = CurrentUserProfile(id: 'u', name: name, email: email);
+ await pumpSettings(tester, app, scale, brightness);
+ });
+ });
+ }
+
+ testWidgets('pushed from a terminal, with no machines', (tester) async {
+ await expectNoLayoutErrors(tester, (scale, brightness) async {
+ final app = edgeApp(noMachines: true);
+ addTearDown(app.dispose);
+ await pumpSettings(tester, app, scale, brightness, large: false);
+ });
+ });
+
+ testWidgets('inside the sample', (tester) async {
+ await expectNoLayoutErrors(tester, (scale, brightness) async {
+ final app = edgeApp();
+ addTearDown(app.dispose);
+ await pumpSettings(tester, app, scale, brightness, sample: true);
+ });
+ });
+}