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
test(mobile): skeletons, appearance prefs, theme adapters, the remote folder picker, engine marks, transfer badges
dee195bff98d2e9
diff --git a/mobile/test/shared/appearance_prefs_store_test.dart b/mobile/test/shared/appearance_prefs_store_test.dartnew file mode 100644index 000000000..64cbd09ca--- /dev/null+++ b/mobile/test/shared/appearance_prefs_store_test.dart@@ -0,0 +1,213 @@+import 'dart:async';++import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/core/local_key_value_store.dart';+import 'package:harness_mobile/shared/theme/appearance_prefs_store.dart';+import 'package:harness_mobile/shared/theme/color_palette.dart';++/// `state.json`, in memory. Writes can be held at a gate so a test can stage+/// the person tapping again while the disk is still busy with the last tap.+class _Memory implements LocalKeyValueStore {+ _Memory([Map<String, String>? values]) : values = values ?? {};++ final Map<String, String> values;+ final writes = <(String, String)>[];+ Completer<void>? gate;+ bool failing = false;++ @override+ Future<String?> read(String key) async {+ if (failing) throw StateError('state.json is unreadable');+ return values[key];+ }++ @override+ Future<void> write(String key, String value) async {+ final held = gate;+ if (held != null) await held.future;+ if (failing) throw StateError('disk full');+ writes.add((key, value));+ values[key] = value;+ }++ @override+ Future<void> delete(String key) async {+ if (failing) throw StateError('disk full');+ values.remove(key);+ }+}++/// The phone's Settings ▸ Appearance: the palette and the UI size, remembered+/// across launches.+void main() {+ group('load', () {+ test('reads back what was chosen', () async {+ final store = AppearancePrefsStore(+ storage: _Memory({+ 'app_ui_font_family': ' Inter ',+ 'app_ui_font_size': '16',+ 'app_color_palette': 'forest',+ }),+ );+ await store.load();+ expect(+ store.value,+ const AppearancePrefs(+ uiFamily: 'Inter',+ uiSize: 16,+ palette: HarnessPalette.forest,+ ),+ );+ });++ test('nothing saved is the shipped look', () async {+ final store = AppearancePrefsStore(storage: _Memory());+ await store.load();+ expect(store.value, const AppearancePrefs());+ expect(store.value.palette, HarnessPalette.graphite);+ expect(store.value.uiSize, AppearancePrefs.uiSizeDefault);+ expect(store.value.uiFamily, isNull);+ });++ test('a hand-edited file lands on something that still draws', () async {+ final store = AppearancePrefsStore(+ storage: _Memory({+ // A blank family would render no text at all.+ 'app_ui_font_family': ' ',+ // `NaN` parses, and clamps to the maximum if let through.+ 'app_ui_font_size': 'NaN',+ 'app_color_palette': 'neon',+ }),+ );+ await store.load();+ expect(store.value, const AppearancePrefs());++ final huge = AppearancePrefsStore(+ storage: _Memory({'app_ui_font_size': '400'}),+ );+ await huge.load();+ expect(huge.value.uiSize, AppearancePrefs.uiSizeMax);++ final garbage = AppearancePrefsStore(+ storage: _Memory({'app_ui_font_size': 'big'}),+ );+ await garbage.load();+ expect(garbage.value.uiSize, AppearancePrefs.uiSizeDefault);+ });++ test(+ 'an unreadable file is the shipped look, not a failed launch',+ () async {+ final store = AppearancePrefsStore(storage: _Memory()..failing = true);+ store.value = const AppearancePrefs(palette: HarnessPalette.ember);+ await store.load();+ expect(store.value, const AppearancePrefs());+ },+ );+ });++ group('palette', () {+ test('moves the app at once, and is written behind it', () async {+ final storage = _Memory()..gate = Completer<void>();+ final store = AppearancePrefsStore(storage: storage);+ var repaints = 0;+ store.addListener(() => repaints++);++ final saved = store.setPalette(HarnessPalette.midnight);+ expect(store.value.palette, HarnessPalette.midnight);+ expect(repaints, 1, reason: 'the tap repaints, not the disk');+ expect(storage.writes, isEmpty);++ storage.gate!.complete();+ await saved;+ expect(storage.values['app_color_palette'], 'midnight');+ });++ test('taps faster than the disk end on the LAST one', () async {+ final storage = _Memory()..gate = Completer<void>();+ final store = AppearancePrefsStore(storage: storage);++ final first = store.setPalette(HarnessPalette.dusk);+ final second = store.setPalette(HarnessPalette.slate);+ final third = store.setPalette(HarnessPalette.ember);+ // One save in flight, which the later taps ride on.+ expect(identical(first, second) && identical(second, third), isTrue);++ storage.gate!.complete();+ await third;+ expect(storage.values['app_color_palette'], 'ember');+ expect(store.value.palette, HarnessPalette.ember);+ // The stale `dusk` went first; the loop wrote the newest after it.+ expect(storage.writes.last, ('app_color_palette', 'ember'));+ });++ test('the palette already on is no write at all', () async {+ final storage = _Memory();+ final store = AppearancePrefsStore(storage: storage);+ await store.setPalette(HarnessPalette.graphite);+ expect(storage.writes, isEmpty);+ });++ test('a disk that fails keeps the choice for this run', () async {+ final store = AppearancePrefsStore(storage: _Memory()..failing = true);+ await store.setPalette(HarnessPalette.forest);+ expect(store.value.palette, HarnessPalette.forest);+ // And the next choice is still attempted, not stuck behind the failure.+ await store.setPalette(HarnessPalette.dusk);+ expect(store.value.palette, HarnessPalette.dusk);+ });++ test('every palette is found again by the id it is saved under', () {+ for (final palette in HarnessPalette.values) {+ expect(HarnessPalette.fromId(palette.name), palette);+ expect(palette.label, isNotEmpty);+ }+ expect(HarnessPalette.fromId(null), HarnessPalette.graphite);+ });+ });++ group('UI size', () {+ test('steps by the button, written as a number', () async {+ final storage = _Memory();+ final store = AppearancePrefsStore(storage: storage);+ await store.setUiSize(15);+ expect(store.value.uiSize, 15);+ expect(storage.values['app_ui_font_size'], '15.0');+ });++ test('snaps to its ends instead of refusing', () async {+ final store = AppearancePrefsStore(storage: _Memory());+ await store.setUiSize(50);+ expect(store.value.uiSize, AppearancePrefs.uiSizeMax);+ await store.setUiSize(2);+ expect(store.value.uiSize, AppearancePrefs.uiSizeMin);+ await store.setUiSize(double.nan);+ expect(store.value.uiSize, AppearancePrefs.uiSizeDefault);+ });++ test('the size already on is no write', () async {+ final storage = _Memory();+ final store = AppearancePrefsStore(storage: storage);+ await store.setUiSize(AppearancePrefs.uiSizeDefault);+ expect(storage.writes, isEmpty);+ });++ test('a disk that fails keeps the size for this run', () async {+ final store = AppearancePrefsStore(storage: _Memory()..failing = true);+ await store.setUiSize(12);+ expect(store.value.uiSize, 12);+ });+ });++ test('prefs compare by value, so an unchanged load repaints nothing', () {+ const a = AppearancePrefs(uiFamily: 'Inter', uiSize: 15);+ expect(a, const AppearancePrefs(uiFamily: 'Inter', uiSize: 15));+ expect(+ a.hashCode,+ const AppearancePrefs(uiFamily: 'Inter', uiSize: 15).hashCode,+ );+ expect(a == const AppearancePrefs(uiSize: 15), isFalse);+ expect(a.copyWith(clearUiFamily: true).uiFamily, isNull);+ expect(a.copyWith(palette: HarnessPalette.dusk).uiFamily, 'Inter');+ });+}diff --git a/mobile/test/shared/skeleton_test.dart b/mobile/test/shared/skeleton_test.dartnew file mode 100644index 000000000..703ca1277--- /dev/null+++ b/mobile/test/shared/skeleton_test.dart@@ -0,0 +1,230 @@+import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/shared/theme/app_theme.dart';+import 'package:harness_mobile/shared/widgets/empty_state.dart';+import 'package:harness_mobile/shared/widgets/pulse.dart';+import 'package:harness_mobile/shared/widgets/skeleton.dart';++/// What the phone draws while a list has not answered — the agents list, the+/// folder picker, a terminal still attaching — and what it draws when the+/// answer is "nothing".+void main() {+ Widget app(Widget child, {bool reduceMotion = false}) => MaterialApp(+ home: MediaQuery(+ data: MediaQueryData(disableAnimations: reduceMotion),+ child: Scaffold(body: child),+ ),+ );++ group('Pulse', () {+ testWidgets('breathes up and back while it is on screen', (tester) async {+ final seen = <double>[];+ await tester.pumpWidget(+ app(+ Pulse(+ duration: const Duration(milliseconds: 100),+ builder: (context, t, _) {+ seen.add(t);+ return const SizedBox.shrink();+ },+ ),+ ),+ );+ await tester.pump(const Duration(milliseconds: 100));+ await tester.pump(const Duration(milliseconds: 50));+ expect(seen.first, 0);+ expect(seen, contains(1.0), reason: 'reaches its peak');+ expect(seen.last, lessThan(1), reason: 'and comes back down');+ });++ testWidgets('Reduce Motion holds it at the peak, not half-faded', (+ tester,+ ) async {+ final seen = <double>[];+ await tester.pumpWidget(+ app(+ reduceMotion: true,+ Pulse(+ builder: (context, t, _) {+ seen.add(t);+ return const SizedBox.shrink();+ },+ ),+ ),+ );+ await tester.pump(const Duration(seconds: 1));+ expect(seen.toSet(), {1.0});+ expect(tester.hasRunningAnimations, isFalse);++ // Turned back on, it breathes again.+ await tester.pumpWidget(+ app(+ Pulse(+ builder: (context, t, _) {+ seen.add(t);+ return const SizedBox.shrink();+ },+ ),+ ),+ );+ expect(tester.hasRunningAnimations, isTrue);+ });++ testWidgets('a new tempo takes over without stopping the beat', (+ tester,+ ) async {+ Widget pulse(int ms) => app(+ Pulse(+ duration: Duration(milliseconds: ms),+ builder: (context, t, child) => child!,+ child: const Text('kept'),+ ),+ );+ await tester.pumpWidget(pulse(400));+ await tester.pumpWidget(pulse(800));+ expect(tester.hasRunningAnimations, isTrue);+ expect(find.text('kept'), findsOneWidget);+ });+ });++ group('Skeleton', () {+ testWidgets('fills between the recess and its hover, on its own radius', (+ tester,+ ) async {+ await tester.pumpWidget(+ app(const Skeleton(width: 120, height: 64, radius: 12)),+ );+ final box = tester.widget<Container>(find.byType(Container));+ final decoration = box.decoration! as BoxDecoration;+ expect(decoration.color, AppSurface.recess);+ expect(decoration.borderRadius, BorderRadius.circular(12));+ expect(tester.getSize(find.byType(Container)), const Size(120, 64));+ });++ testWidgets('a round one takes no corner radius', (tester) async {+ await tester.pumpWidget(+ app(const Skeleton(width: 18, height: 18, shape: BoxShape.circle)),+ );+ final decoration =+ tester.widget<Container>(find.byType(Container)).decoration!+ as BoxDecoration;+ expect(decoration.shape, BoxShape.circle);+ expect(decoration.borderRadius, isNull);+ });+ });++ group('SkeletonText', () {+ testWidgets('reserves exactly the line the real text will take', (+ tester,+ ) async {+ const style = TextStyle(fontSize: 14, height: 1.4);+ await tester.pumpWidget(+ app(+ const Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ SizedBox(+ width: 200,+ child: SkeletonText(style: style, widthFactor: 0.5),+ ),+ Text('Real row', style: style),+ ],+ ),+ ),+ );+ final placeholder = tester.getSize(find.byType(SkeletonText));+ final real = tester.getSize(find.text('Real row'));+ expect(placeholder.height, real.height);+ // The bar is the x-height of the line, and half the row wide.+ final bar = tester.getSize(find.byType(Skeleton));+ expect(bar.height, (14 * 0.72).roundToDouble());+ expect(bar.width, 100);+ });++ testWidgets('a fixed width, and a thin line, still read as a line', (+ tester,+ ) async {+ await tester.pumpWidget(+ app(+ const Align(+ alignment: Alignment.topLeft,+ child: SkeletonText(style: TextStyle(fontSize: 4), width: 60),+ ),+ ),+ );+ final bar = tester.getSize(find.byType(Skeleton));+ expect(bar.width, 60);+ expect(bar.height, 6, reason: 'never thinner than a readable bar');+ });+ });++ group('SkeletonList', () {+ testWidgets('fades toward its foot, says "loading" once, and takes no '+ 'touches', (tester) async {+ final handle = tester.ensureSemantics();+ var tapped = 0;+ await tester.pumpWidget(+ app(+ SkeletonList(+ rows: 4,+ semanticsLabel: 'Loading folders',+ itemBuilder: (context, i) => GestureDetector(+ onTap: () => tapped++,+ child: const SizedBox(height: 30, child: Skeleton.text()),+ ),+ ),+ ),+ );+ final opacities = tester+ .widgetList<Opacity>(find.byType(Opacity))+ .map((o) => o.opacity)+ .toList();+ expect(opacities, hasLength(4));+ expect(opacities.first, 1);+ for (var i = 1; i < opacities.length; i++) {+ expect(opacities[i], lessThan(opacities[i - 1]));+ }+ expect(find.bySemanticsLabel('Loading folders'), findsOneWidget);++ await tester.tap(find.byType(SkeletonList), warnIfMissed: false);+ expect(tapped, 0, reason: 'a placeholder is not content');+ handle.dispose();+ });++ test('an empty list is not faded at all', () {+ expect(skeletonFade(0, 0), 1);+ expect(skeletonFade(3, 3, depth: 0.3), closeTo(0.7, 1e-9));+ });+ });++ group('EmptyState', () {+ testWidgets('nothing yet: the title, one line, and the way out', (+ tester,+ ) async {+ await tester.pumpWidget(+ app(+ EmptyState(+ icon: Icons.computer,+ title: 'No computers yet',+ message: 'Link one to see its agents here.',+ action: FilledButton(onPressed: () {}, child: const Text('Link')),+ ),+ ),+ );+ expect(find.text('No computers yet'), findsOneWidget);+ expect(find.text('Link one to see its agents here.'), findsOneWidget);+ expect(find.text('Link'), findsOneWidget);+ expect(tester.widget<Icon>(find.byType(Icon)).size, 32);+ });++ testWidgets('nothing matched: compact, and no action to take', (+ tester,+ ) async {+ await tester.pumpWidget(app(const EmptyState.noMatches()));+ expect(find.text('No matches'), findsOneWidget);+ expect(find.byIcon(Icons.search_off_rounded), findsOneWidget);+ expect(tester.widget<Icon>(find.byType(Icon)).size, 24);+ expect(find.byType(FilledButton), findsNothing);+ });+ });+}diff --git a/mobile/test/theme/app_theme_test.dart b/mobile/test/theme/app_theme_test.dartnew file mode 100644index 000000000..8440fe696--- /dev/null+++ b/mobile/test/theme/app_theme_test.dart@@ -0,0 +1,137 @@+import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/shared/theme/app_theme.dart' as grid;+import 'package:harness_mobile/shared/theme/color_palette.dart';+import 'package:harness_mobile/theme/app_theme.dart';++/// The two token layers the phone paints with: `lib/theme`'s [AppColors] and+/// [AppFonts], which are adapters, and the design system under them, which+/// follows the palette picked in Settings ▸ Appearance and the UI size.+void main() {+ tearDown(() {+ grid.AppTheme.palette.value = HarnessPalette.graphite;+ grid.AppFont.reset();+ });++ test('the adapters are the design system, not a second palette', () {+ expect(AppColors.background, grid.AppPalette.windowBg);+ expect(AppColors.sidebar, grid.AppPalette.panelBg);+ expect(AppColors.surface, grid.AppPalette.cardBg);+ expect(AppColors.hover, grid.AppPalette.cardBgHover);+ expect(AppColors.selected, grid.AppSurface.selectedFill);+ expect(AppColors.border, grid.AppPalette.divider);+ expect(AppColors.borderStrong, grid.AppPalette.guide);+ expect(AppColors.text, grid.AppPalette.textPrimary);+ expect(AppColors.textSoft, grid.AppPalette.textSecondary);+ expect(AppColors.muted, grid.AppPalette.textFaint);+ expect(AppColors.mutedStrong, grid.AppPalette.textSecondary);+ expect(AppColors.accent, grid.AppPalette.accentOnSurface);+ expect(AppColors.success, grid.AppPalette.online);+ expect(AppColors.warning, grid.AppPalette.warn);+ // Dark-only on the phone: the error ink tuned for a dark card.+ expect(grid.AppTheme.isDark, isTrue);+ expect(AppColors.danger, const Color(0xFFF2544B));+ });++ test(+ 'the tokens only the phone reaches for resolve to their dark values',+ () {+ // The status line's "bad" dot, the account avatar, a card under a thumb.+ expect(grid.AppPalette.offline, const Color(0xFF6E6E6E));+ expect(grid.AppPalette.avatarFill, const Color(0xFF4B5F9B));+ // A pressed card moves AWAY from the page, never toward it.+ expect(+ grid.AppGlass.rowHoverFill.computeLuminance(),+ greaterThan(grid.AppGlass.rowFill.computeLuminance()),+ );+ expect(+ grid.AppGlass.rowFill.computeLuminance(),+ greaterThan(grid.AppPalette.windowBg.computeLuminance()),+ );+ },+ );++ test('a palette chosen in Settings reaches the surfaces the phone draws', () {+ grid.AppTheme.palette.value = HarnessPalette.midnight;+ expect(grid.AppPalette.cardBg, HarnessPalette.midnight.card);+ expect(grid.AppPalette.cardBgHover, HarnessPalette.midnight.hover);+ expect(AppColors.surface, HarnessPalette.midnight.card);++ grid.AppTheme.palette.value = HarnessPalette.ember;+ expect(AppColors.surface, HarnessPalette.ember.card);+ expect(AppColors.hover, HarnessPalette.ember.hover);+ });++ test('the UI size moves the type settings once, and only on a change', () {+ var notified = 0;+ void count() => notified++;+ grid.AppTheme.fonts.addListener(count);+ addTearDown(() => grid.AppTheme.fonts.removeListener(count));++ // What `HarnessApp` does on every appearance change.+ grid.AppTheme.fonts.apply(+ uiScale: 16 / 14,+ codeSize: grid.AppFont.codeSize,+ );+ expect(notified, 1);+ expect(grid.AppFont.uiScale, closeTo(16 / 14, 1e-9));+ // The same settings again must not dirty the tree.+ grid.AppTheme.fonts.apply(+ uiScale: 16 / 14,+ codeSize: grid.AppFont.codeSize,+ );+ expect(notified, 1);++ grid.AppTheme.fonts.apply(uiScale: 1, codeSize: grid.AppFont.codeSize);+ expect(notified, 2);+ });++ test('the font adapters follow the settings, with the system face behind a '+ 'chosen one', () {+ expect(AppFonts.sans, grid.AppFont.sansDefault);+ expect(AppFonts.mono, grid.AppFont.monoDefault);+ expect(AppFonts.monoFallback, isNotEmpty);+ expect(AppFonts.sansFallback, isNot(contains(grid.AppFont.sansDefault)));++ grid.AppFont.apply(+ uiFamily: 'Inter',+ codeFamily: 'JetBrains Mono',+ uiScale: 1,+ codeSize: 13,+ );+ expect(AppFonts.sans, 'Inter');+ expect(AppFonts.sansFallback.first, grid.AppFont.sansDefault);+ expect(AppFonts.mono, 'JetBrains Mono');+ // One missing glyph falls to the system mono, not a proportional face.+ expect(AppFonts.monoFallback.first, grid.AppFont.monoDefault);+ expect(grid.AppFont.codeSize, 13);+ });++ testWidgets('a widget that watches the theme rebuilds when the palette or '+ 'the type changes', (tester) async {+ var builds = 0;+ await tester.pumpWidget(+ grid.BrightnessScope(child: _Watcher(onBuild: () => builds++)),+ );+ expect(builds, 1);+ grid.AppTheme.palette.value = HarnessPalette.forest;+ await tester.pump();+ expect(builds, 2);+ grid.AppTheme.fonts.apply(uiScale: 1.2, codeSize: grid.AppFont.codeSize);+ await tester.pump();+ expect(builds, 3);+ });+}++class _Watcher extends StatelessWidget {+ const _Watcher({required this.onBuild});++ final VoidCallback onBuild;++ @override+ Widget build(BuildContext context) {+ grid.AppTheme.watch(context);+ onBuild();+ return const SizedBox.shrink();+ }+}diff --git a/mobile/test/widgets/engine_identity_test.dart b/mobile/test/widgets/engine_identity_test.dartnew file mode 100644index 000000000..0be752a6c--- /dev/null+++ b/mobile/test/widgets/engine_identity_test.dart@@ -0,0 +1,133 @@+import 'package:flutter/material.dart';+import 'package:flutter/services.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/theme/app_theme.dart';+import 'package:harness_mobile/widgets/engine_identity.dart';++/// An asset bundle with nothing in it: what an engine logo that failed to+/// load looks like to [Image.asset].+class _EmptyBundle extends CachingAssetBundle {+ @override+ Future<ByteData> load(String key) async =>+ throw FlutterError('no asset $key');+}++/// The engine's name and mark, wherever an agent is listed on the phone — its+/// card, the model sheet, the usage page, the New agent picker.+void main() {+ group('engineIdentity', () {+ test('a known engine is itself, however its id was spelled', () {+ final codex = engineIdentity(' Codex ');+ expect(codex.id, 'codex');+ expect(codex.label, 'Codex');+ expect(codex.asset, 'assets/engine-icons/codex.png');+ // A daemon's display name does not rename an engine this app knows.+ expect(+ engineIdentity('claude', displayName: 'claude-code').label,+ 'Claude',+ );+ });++ test('an engine this build has never heard of is named by the daemon, '+ 'then by its id, then as an agent', () {+ final named = engineIdentity('gemini', displayName: ' gemini CLI ');+ expect(named.id, 'gemini');+ expect(named.label, 'Gemini CLI');+ expect(named.asset, isNull);+ expect(named.color, AppColors.mutedStrong);++ expect(engineIdentity('gemini', displayName: ' ').label, 'Gemini');+ final nothing = engineIdentity(null);+ expect(nothing.id, 'unknown');+ expect(nothing.label, 'Agent');+ expect(engineIdentity('').label, 'Agent');+ });++ test('the New agent picker offers every engine, each with a mark', () {+ final ids = allEngines.map((engine) => engine.id).toList();+ expect(ids.first, 'claude');+ expect(ids.toSet(), hasLength(ids.length), reason: 'no engine twice');+ for (final engine in allEngines) {+ // Claude alone is drawn rather than loaded.+ expect(+ engine.asset != null || engine.id == 'claude',+ isTrue,+ reason: engine.id,+ );+ expect(engine.label, isNotEmpty);+ }+ });+ });++ group('EngineMark', () {+ Future<void> pump(WidgetTester tester, Widget mark, {AssetBundle? bundle}) {+ Widget child = Center(child: mark);+ if (bundle != null) {+ child = DefaultAssetBundle(bundle: bundle, child: child);+ }+ return tester.pumpWidget(MaterialApp(home: child));+ }++ testWidgets('an engine with a logo draws the logo', (tester) async {+ await pump(tester, const EngineMark(engine: 'codex', size: 18));+ final image = tester.widget<Image>(+ find.byKey(const ValueKey('engine-icon-codex')),+ );+ expect(image.width, 18);+ expect(image.height, 18);+ });++ testWidgets('Claude is painted, not loaded', (tester) async {+ await pump(tester, const EngineMark(engine: 'claude', size: 32));+ final paint = tester.widget<CustomPaint>(+ find.byKey(const ValueKey('engine-icon-claude')),+ );+ expect(paint.size, const Size.square(32));+ final painter = paint.painter!;+ // Same colour, same drawing: nothing to repaint for.+ expect(painter.shouldRepaint(painter), isFalse);+ });++ testWidgets('an engine with no logo is its initial, unscaled', (+ tester,+ ) async {+ await pump(+ tester,+ const MediaQuery(+ data: MediaQueryData(textScaler: TextScaler.linear(1.4)),+ child: EngineMark(engine: 'gemini', size: 17),+ ),+ );+ expect(+ find.byKey(const ValueKey('engine-fallback-gemini')),+ findsOneWidget,+ );+ final initial = tester.widget<Text>(find.text('G'));+ // Sized from its fixed box: the app's UI scale would clip the letter+ // out of its own 17px square.+ expect(initial.textScaler, TextScaler.noScaling);+ expect(initial.style!.fontSize, closeTo(17 * 0.68, 0.001));+ expect(initial.style!.fontFamilyFallback, AppFonts.monoFallback);+ });++ testWidgets('a logo that fails to load falls back to the initial', (+ tester,+ ) async {+ await pump(+ tester,+ const EngineMark(engine: 'amp', size: 18),+ bundle: _EmptyBundle(),+ );+ await tester.pumpAndSettle();+ expect(find.byKey(const ValueKey('engine-fallback-amp')), findsOneWidget);+ expect(find.text('A'), findsOneWidget);+ });++ testWidgets('a disabled mark is dimmed', (tester) async {+ await pump(tester, const EngineMark(engine: 'pi', enabled: false));+ expect(tester.widget<Opacity>(find.byType(Opacity)).opacity, 0.45);+ await pump(tester, const EngineMark(engine: 'pi'));+ expect(tester.widget<Opacity>(find.byType(Opacity)).opacity, 1);+ });+ });+}diff --git a/mobile/test/widgets/remote_folder_picker_test.dart b/mobile/test/widgets/remote_folder_picker_test.dartnew file mode 100644index 000000000..fdcb3cd8d--- /dev/null+++ b/mobile/test/widgets/remote_folder_picker_test.dart@@ -0,0 +1,513 @@+import 'dart:async';++import 'package:flutter/foundation.dart';+import 'package:flutter/material.dart';+import 'package:flutter/services.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/auth/auth_session.dart';+import 'package:harness_mobile/core/config.dart';+import 'package:harness_mobile/core/models.dart';+import 'package:harness_mobile/state/app_state.dart';+import 'package:harness_mobile/widgets/remote_folder_picker.dart';++/// A machine whose folders are answered by the test, one `fs_list_dir` at a+/// time: each ask waits on a completer the test settles, in whatever order it+/// likes — which is how a slow answer arriving after a newer one is staged.+class _Folders extends AppNotifier {+ _Folders()+ : super(+ config: AppConfig.dev,+ authSession: AuthSession(),+ configStore: null,+ ) {+ const studio = Machine(+ machineId: 'm',+ authMode: MachineAuthMode.remote,+ name: 'Studio',+ );+ machines = [studio];+ machineStates['m'] = MachineState(studio);+ }++ /// Every ask, in order, with the completer that answers it.+ final asks = <({String? path, Completer<Map<String, dynamic>> reply})>[];++ @override+ Future<Map<String, dynamic>> listRemoteFolder(+ String machineId,+ String? path,+ ) {+ final reply = Completer<Map<String, dynamic>>();+ asks.add((path: path, reply: reply));+ return reply.future;+ }++ /// Answers the newest ask not yet answered for [path].+ void answer(String? path, Map<String, dynamic> reply) => asks+ .lastWhere((ask) => ask.path == path && !ask.reply.isCompleted)+ .reply+ .complete(reply);+}++Map<String, dynamic> _listing(+ String path,+ List<String> folders, {+ bool truncated = false,+}) => {+ 'path': path,+ 'entries': [+ for (final name in folders) {'name': name, 'isDir': true},+ ],+ if (truncated) 'truncated': true,+};++void main() {+ late _Folders app;++ setUp(() => app = _Folders());+ tearDown(() => app.dispose());++ /// Opens the picker from a page, the way the New agent form does, and hands+ /// back what it resolved to — or `'<open>'` while it is still up.+ Future<ValueNotifier<String?>> open(+ WidgetTester tester, {+ String? initialPath,+ double height = 900,+ }) async {+ tester.view.physicalSize = Size(430, height);+ tester.view.devicePixelRatio = 1;+ addTearDown(tester.view.reset);+ final result = ValueNotifier<String?>('<closed>');+ await tester.pumpWidget(+ MaterialApp(+ home: Builder(+ builder: (context) => Scaffold(+ body: Center(+ child: TextButton(+ onPressed: () async {+ result.value = '<open>';+ result.value = await showRemoteFolderPicker(+ context,+ notifier: app,+ machineId: 'm',+ initialPath: initialPath,+ );+ },+ child: const Text('Browse'),+ ),+ ),+ ),+ ),+ ),+ );+ await tester.tap(find.text('Browse'));+ // Not `pumpAndSettle`: while a folder loads, its skeleton breathes for as+ // long as the machine takes, which here is until the test answers.+ await tester.pump();+ await tester.pump(const Duration(milliseconds: 200));+ return result;+ }++ FilledButton selectButton(WidgetTester tester) =>+ tester.widget<FilledButton>(find.byType(FilledButton));++ TextField pathField(WidgetTester tester) =>+ tester.widget<TextField>(find.byKey(const Key('remote-folder-path')));++ Future<void> settle(WidgetTester tester) async {+ await tester.pump();+ await tester.pump();+ }++ testWidgets('opens on the folder it was given, lists only folders, and '+ 'Select hands that folder back', (tester) async {+ final result = await open(tester, initialPath: '/home/me/code');+ expect(app.asks.single.path, '/home/me/code');+ expect(find.text('On Studio'), findsOneWidget);+ // Still asking: a skeleton stands in, and nothing can be chosen yet.+ expect(find.bySemanticsLabel('Loading folders'), findsOneWidget);+ expect(selectButton(tester).onPressed, isNull);++ app.answer('/home/me/code', {+ 'path': '/home/me/code',+ 'entries': [+ {'name': 'app', 'isDir': true},+ // A file is not somewhere an agent can be started.+ {'name': 'notes.txt', 'isDir': false},+ // An older CLI says nothing about the kind: taken as a folder.+ {'name': 'site'},+ // Nameless and malformed entries are dropped, not drawn blank.+ {'name': '', 'isDir': true},+ {'isDir': true},+ 42,+ ],+ });+ await settle(tester);++ expect(find.text('app'), findsOneWidget);+ expect(find.text('site'), findsOneWidget);+ expect(find.text('notes.txt'), findsNothing);+ expect(pathField(tester).controller!.text, '/home/me/code');+ expect(find.text('Folders'), findsOneWidget);++ await tester.tap(find.text('Select this folder'));+ await tester.pumpAndSettle();+ expect(result.value, '/home/me/code');+ });++ testWidgets('a row opens that folder, and Up comes back to the parent', (+ tester,+ ) async {+ await open(tester, initialPath: '/home/me');+ app.answer('/home/me', _listing('/home/me', ['code', 'docs']));+ await settle(tester);++ await tester.tap(find.text('code'));+ await settle(tester);+ expect(app.asks.last.path, '/home/me/code');+ app.answer('/home/me/code', _listing('/home/me/code', []));+ await settle(tester);+ expect(find.text('No subfolders here.'), findsOneWidget);+ expect(pathField(tester).controller!.text, '/home/me/code');++ await tester.tap(find.byTooltip('Up one folder (Alt+↑)'));+ await settle(tester);+ expect(app.asks.last.path, '/home/me');+ app.answer('/home/me', _listing('/home/me', ['code', 'docs']));+ await settle(tester);+ expect(pathField(tester).controller!.text, '/home/me');+ });++ testWidgets('Up stops at the root', (tester) async {+ await open(tester, initialPath: '/');+ app.answer('/', _listing('/', ['home']));+ await settle(tester);+ final up = tester.widget<IconButton>(+ find.widgetWithIcon(IconButton, Icons.arrow_upward),+ );+ expect(up.onPressed, isNull, reason: 'a root has no parent to go up to');+ });++ testWidgets('a Windows machine is walked with its own separators', (+ tester,+ ) async {+ await open(tester, initialPath: r'C:\Users\me');+ app.answer(r'C:\Users\me', _listing(r'C:\Users\me', ['Documents']));+ await settle(tester);++ await tester.tap(find.text('Documents'));+ await settle(tester);+ // Not `C:\Users\me/Documents`: the path is the far machine's, not this+ // phone's.+ expect(app.asks.last.path, r'C:\Users\me\Documents');+ app.answer(+ r'C:\Users\me\Documents',+ _listing(r'C:\Users\me\Documents', []),+ );+ await settle(tester);++ await tester.tap(find.byTooltip('Up one folder (Alt+↑)'));+ await settle(tester);+ expect(app.asks.last.path, r'C:\Users\me');+ });++ testWidgets('Home asks the machine for its own home folder', (tester) async {+ await open(tester, initialPath: '/srv/app');+ app.answer('/srv/app', _listing('/srv/app', []));+ await settle(tester);++ await tester.tap(find.byKey(const Key('remote-folder-home')));+ await settle(tester);+ expect(app.asks.last.path, isNull);+ expect(pathField(tester).controller!.text, isEmpty);+ app.answer(null, _listing('/Users/me', ['code']));+ await settle(tester);+ expect(pathField(tester).controller!.text, '/Users/me');+ expect(find.text('code'), findsOneWidget);+ });++ for (final (code, sentence) in [+ ('FORBIDDEN', 'Choose a folder inside your home directory'),+ ('PERMISSION_DENIED', 'permission to open this folder'),+ ('NOT_A_DIRECTORY', 'That path is not a folder.'),+ ('NOT_FOUND', 'This folder could not be found.'),+ ('INVALID_PATH', 'Enter a full folder path on this machine.'),+ ('UNREACHABLE', 'reach this machine'),+ ('SOMETHING_NEW', 'open this folder. Try again.'),+ ]) {+ testWidgets('$code is said in words, with a Retry', (tester) async {+ await open(tester, initialPath: '/x');+ app.answer('/x', {'error': code});+ await settle(tester);+ expect(find.textContaining(sentence), findsOneWidget);+ expect(selectButton(tester).onPressed, isNull);+ expect(+ find.text('Enter a path or open your home folder.'),+ findsOneWidget,+ reason: 'nothing has loaded yet, so the list says how to begin',+ );++ await tester.tap(find.text('Retry'));+ await settle(tester);+ expect(app.asks.last.path, '/x');+ app.answer('/x', _listing('/x', ['a']));+ await settle(tester);+ expect(find.textContaining(sentence), findsNothing);+ expect(selectButton(tester).onPressed, isNotNull);+ });+ }++ testWidgets('an answer with no path, or a machine that throws, is an error '+ 'too', (tester) async {+ await open(tester, initialPath: '/x');+ app.answer('/x', const {});+ await settle(tester);+ expect(find.textContaining('open this folder. Try again.'), findsOneWidget);++ await tester.tap(find.text('Retry'));+ await settle(tester);+ app.asks.last.reply.completeError(StateError('socket closed'));+ await settle(tester);+ expect(find.textContaining('reach this machine'), findsOneWidget);+ });++ testWidgets('a long listing says there is more than it shows', (+ tester,+ ) async {+ await open(tester, initialPath: '/big');+ app.answer('/big', _listing('/big', ['a', 'b'], truncated: true));+ await settle(tester);+ expect(+ find.text(+ 'More folders are available. Enter their full path to open them.',+ ),+ findsOneWidget,+ );+ });++ testWidgets('a typed path opens on submit, and Select waits for it to load', (+ tester,+ ) async {+ await open(tester, initialPath: '/home/me');+ app.answer('/home/me', _listing('/home/me', ['code']));+ await settle(tester);++ await tester.enterText(+ find.byKey(const Key('remote-folder-path')),+ '/srv/site ',+ );+ await tester.pump();+ // The field no longer names what the list shows: say which folder that is,+ // and do not let Select pick a folder the person has typed their way off.+ expect(find.text('Showing /home/me'), findsOneWidget);+ expect(selectButton(tester).onPressed, isNull);++ await tester.tap(find.byTooltip('Open path'));+ await settle(tester);+ expect(app.asks.last.path, '/srv/site');+ // Asked twice while that ask is in flight: still one ask.+ await tester.testTextInput.receiveAction(TextInputAction.done);+ await settle(tester);+ expect(app.asks.where((ask) => ask.path == '/srv/site'), hasLength(1));++ app.answer('/srv/site', _listing('/srv/site', []));+ await settle(tester);+ expect(pathField(tester).controller!.text, '/srv/site');+ expect(selectButton(tester).onPressed, isNotNull);+ });++ testWidgets('a slower, older answer does not replace a newer one', (+ tester,+ ) async {+ final result = await open(tester, initialPath: '/slow');+ // Before /slow answers, the person types another folder and opens it.+ await tester.enterText(find.byKey(const Key('remote-folder-path')), '/b');+ await tester.testTextInput.receiveAction(TextInputAction.done);+ await settle(tester);+ expect(app.asks.map((ask) => ask.path), ['/slow', '/b']);++ app.answer('/b', _listing('/b', ['from-b']));+ await settle(tester);+ app.answer('/slow', _listing('/slow', ['from-slow']));+ await settle(tester);++ expect(find.text('from-b'), findsOneWidget);+ expect(find.text('from-slow'), findsNothing);+ expect(pathField(tester).controller!.text, '/b');+ await tester.tap(find.text('Select this folder'));+ await tester.pumpAndSettle();+ expect(result.value, '/b');+ });++ testWidgets('an edit made while a folder loads is kept, and its failure is '+ 'not blamed on the draft', (tester) async {+ await open(tester, initialPath: '/a');+ await tester.enterText(find.byKey(const Key('remote-folder-path')), '/dra');+ await tester.pump();+ app.answer('/a', _listing('/a', ['one']));+ await settle(tester);+ // The listing lands; the draft stays exactly as typed.+ expect(pathField(tester).controller!.text, '/dra');+ expect(find.text('Showing /a'), findsOneWidget);+ expect(selectButton(tester).onPressed, isNull);++ await tester.enterText(find.byKey(const Key('remote-folder-path')), '/x');+ await tester.testTextInput.receiveAction(TextInputAction.done);+ await settle(tester);+ await tester.enterText(find.byKey(const Key('remote-folder-path')), '/xy');+ await tester.pump();+ app.answer('/x', {'error': 'NOT_FOUND'});+ await settle(tester);+ expect(+ find.textContaining('could not be found'),+ findsNothing,+ reason: 'the failure was about /x, and the field says /xy now',+ );+ });++ testWidgets('Cancel hands back nothing and puts the keyboard away', (+ tester,+ ) async {+ final result = await open(tester, initialPath: '/a');+ app.answer('/a', _listing('/a', []));+ await settle(tester);+ tester.testTextInput.log.clear();++ await tester.tap(find.text('Cancel'));+ await tester.pumpAndSettle();+ expect(result.value, isNull);+ expect(+ tester.testTextInput.log.map((call) => call.method),+ contains('TextInput.hide'),+ );+ });++ testWidgets('a tap on the veil closes it too', (tester) async {+ final result = await open(tester, initialPath: '/a');+ app.answer('/a', _listing('/a', []));+ await settle(tester);+ await tester.tapAt(const Offset(4, 4));+ await tester.pumpAndSettle();+ expect(result.value, isNull);+ expect(find.text('Choose a folder'), findsNothing);+ });++ testWidgets('on a phone the path field does not raise the keyboard over the '+ 'list it opens on', (tester) async {+ debugDefaultTargetPlatformOverride = TargetPlatform.iOS;+ await open(tester, initialPath: '/a');+ app.answer('/a', _listing('/a', ['one']));+ await settle(tester);+ expect(pathField(tester).autofocus, isFalse);+ expect(tester.testTextInput.hasAnyClients, isFalse);+ // The field and the buttons under it are sized for a thumb, to one height.+ expect(+ tester.getSize(find.byKey(const Key('remote-folder-path'))).height,+ 44,+ );+ for (final label in ['Cancel', 'Select this folder']) {+ expect(+ tester+ .getSize(+ find.ancestor(+ of: find.text(label),+ matching: find.byWidgetPredicate((w) => w is ButtonStyleButton),+ ),+ )+ .height,+ greaterThanOrEqualTo(44),+ reason: label,+ );+ }+ debugDefaultTargetPlatformOverride = null;+ });++ testWidgets('with a hardware keyboard the list is walked by its keys', (+ tester,+ ) async {+ final result = await open(tester, initialPath: '/p');+ app.answer('/p', _listing('/p', ['a', 'b', 'c']));+ await settle(tester);++ // From the field, ↓ steps into the list.+ await tester.tap(find.byKey(const Key('remote-folder-path')));+ await tester.pump();+ await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);+ await tester.pump();++ bool selected(String name) => tester+ .widgetList<Semantics>(+ find.ancestor(of: find.text(name), matching: find.byType(Semantics)),+ )+ .any((row) => row.properties.selected == true);+ expect(selected('a'), isTrue);++ await tester.sendKeyEvent(LogicalKeyboardKey.end);+ await tester.pump();+ expect(selected('c'), isTrue);+ await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);+ await tester.pump();+ expect(selected('b'), isTrue);+ await tester.sendKeyEvent(LogicalKeyboardKey.home);+ await tester.pump();+ await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);+ await tester.pump();+ expect(selected('b'), isTrue);+ // A key the list has no use for is left to whoever else wants it.+ await tester.sendKeyEvent(LogicalKeyboardKey.keyQ);+ // A chord is somebody else's shortcut, not a step through the list.+ await tester.sendKeyDownEvent(LogicalKeyboardKey.shiftLeft);+ await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);+ await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);+ await tester.pump();+ expect(selected('b'), isTrue);++ await tester.sendKeyEvent(LogicalKeyboardKey.enter);+ await settle(tester);+ expect(app.asks.last.path, '/p/b');+ app.answer('/p/b', _listing('/p/b', ['deep']));+ await settle(tester);++ // ← goes back up, with the folder we came out of still the one picked.+ await tester.sendKeyEvent(LogicalKeyboardKey.arrowLeft);+ await settle(tester);+ expect(app.asks.last.path, '/p');+ app.answer('/p', _listing('/p', ['a', 'b', 'c']));+ await settle(tester);+ expect(selected('b'), isTrue);++ // Alt+↑ is Up from anywhere in the sheet.+ await tester.sendKeyDownEvent(LogicalKeyboardKey.altLeft);+ await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);+ await tester.sendKeyUpEvent(LogicalKeyboardKey.altLeft);+ await settle(tester);+ expect(app.asks.last.path, '/');+ app.answer('/', _listing('/', ['p']));+ await settle(tester);++ // Ctrl+Enter picks the folder on show.+ await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);+ await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);+ await tester.pumpAndSettle();+ expect(result.value, '/');+ });++ testWidgets('a folder picked far down a long list is scrolled into view', (+ tester,+ ) async {+ final names = [+ for (var i = 0; i < 40; i++) 'f${i.toString().padLeft(2, '0')}',+ ];+ await open(tester, initialPath: '/p/f35');+ app.answer('/p/f35', _listing('/p/f35', []));+ await settle(tester);+ await tester.tap(find.byTooltip('Up one folder (Alt+↑)'));+ await settle(tester);+ app.answer('/p', _listing('/p', names));+ await settle(tester);+ await tester.pump();+ // The row we came out of is on screen, not thirty rows below the fold.+ expect(find.text('f35').hitTestable(), findsOneWidget);+ });+}diff --git a/mobile/test/widgets/terminal_pane_badges_test.dart b/mobile/test/widgets/terminal_pane_badges_test.dartnew file mode 100644index 000000000..a6feb637c--- /dev/null+++ b/mobile/test/widgets/terminal_pane_badges_test.dart@@ -0,0 +1,68 @@+import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/widgets/terminal_pane_badges.dart';++/// The bar in a terminal's corner while a pasted image goes up to the machine,+/// or a linked file comes down for a preview.+void main() {+ Future<void> pump(WidgetTester tester, TransferProgressBadge badge) =>+ tester.pumpWidget(+ MaterialApp(+ home: Scaffold(body: SizedBox(width: 300, child: badge)),+ ),+ );++ testWidgets('says how far along it is, and fills the bar that far', (+ tester,+ ) async {+ await pump(+ tester,+ TransferProgressBadge(+ label: 'Uploading screenshot.png',+ fraction: 0.426,+ onCancel: () {},+ ),+ );+ expect(find.text('Uploading screenshot.png · 43%'), findsOneWidget);+ expect(+ tester+ .widget<LinearProgressIndicator>(find.byType(LinearProgressIndicator))+ .value,+ 0.426,+ );+ });++ testWidgets('before the size is known it gives no figure, and the bar runs '+ 'on its own', (tester) async {+ await pump(+ tester,+ TransferProgressBadge(+ label: 'Preparing preview…',+ fraction: null,+ onCancel: () {},+ ),+ );+ // A made-up "0%" would read as stalled.+ expect(find.text('Preparing preview…'), findsOneWidget);+ expect(+ tester+ .widget<LinearProgressIndicator>(find.byType(LinearProgressIndicator))+ .value,+ isNull,+ );+ });++ testWidgets('Cancel stops the transfer', (tester) async {+ var cancelled = 0;+ await pump(+ tester,+ TransferProgressBadge(+ label: 'Downloading clip.mp4',+ fraction: 0.5,+ onCancel: () => cancelled++,+ ),+ );+ await tester.tap(find.text('CANCEL'));+ expect(cancelled, 1);+ });+}