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
Store: cover every store file, and drop the branches nothing can reach
dee5cb0f80874d3
diff --git a/desktop/lib/store/store_screen.dart b/desktop/lib/store/store_screen.dartindex 5ef53af0f..33a983bf7 100644--- a/desktop/lib/store/store_screen.dart+++ b/desktop/lib/store/store_screen.dart@@ -66,25 +66,31 @@ class _Discover extends _Shelf {const _Discover();}-class _All extends _Shelf {- const _All();-}-class _Viewers extends _Shelf {const _Viewers();}-class _Search extends _Shelf {+/// The shelves drawn as a plain listing: everything but Discover's front page+/// and the Viewers page, which have views of their own.+sealed class _Listed extends _Shelf {+ const _Listed();+}++class _All extends _Listed {+ const _All();+}++class _Search extends _Listed {const _Search(this.query);final String query;}-class _Collection extends _Shelf {+class _Collection extends _Listed {const _Collection(this.collection);final StoreCollection collection;}-class _Category extends _Shelf {+class _Category extends _Listed {const _Category(this.name);final String name;}@@ -299,7 +305,7 @@ class _StoreTabState extends State<StoreTab> {installed.where((s) => s.nodeOnline == true && !s.needsLink).firstOrNull;- if (target == null || entry.isViewerPackage) {+ if (target == null) {_openPage(entry.id);return;}@@ -390,7 +396,7 @@ class _StoreTabState extends State<StoreTab> {onEngines: () => _show(const _Category('Code')),): _Shelf$View(- shelf: _shelf,+ shelf: _shelf as _Listed,entries: _shelved(_shelf),store: _store,installedOn: _installedOn,@@ -547,7 +553,7 @@ class _Shelf$View extends StatelessWidget {required this.onAction,});- final _Shelf shelf;+ final _Listed shelf;final List<DshEntry> entries;final StoreController store;final List<MachineState> Function(String id) installedOn;@@ -556,17 +562,14 @@ class _Shelf$View extends StatelessWidget {final ValueChanged<DshEntry> onAction;String get _title => switch (shelf) {- _Discover() => 'Discover',_All() => 'All harnesses',- _Viewers() => 'Viewers',_Search() => 'Search results',_Collection(:final collection) => collection.title,_Category(:final name) => name,};String get _subtitle => switch (shelf) {- _Discover() || _All() => 'Find something you have always wanted to make.',- _Viewers() => 'Shared previews and the agents that use them.',+ _All() => 'Find something you have always wanted to make.',_Search() => '${entries.length} result${entries.length == 1 ? '' : 's'}',_Collection(:final collection) => collection.subtitle,_Category() =>@@ -679,10 +682,6 @@ Future<void> _openStoreAgent() async {notifier.newSwarm(draft: true);final target = notifier.activeSwarmId;- if (!context.mounted) {- notifier.cancelSwarmDraft(target);- return;- }final result = await showNewAgentDialog(context,notifier,@@ -762,7 +761,9 @@ class _ProductPageState extends State<_ProductPage> {),);if (ok != true || !mounted) return;- if (!_busy.add(machineId)) return;+ // No second Remove can be in flight: the dialog above is modal, and while+ // one runs the row shows progress instead of the button.+ _busy.add(machineId);setState(() {});final failure = await widget.notifier.removeDsh(machineId, widget.entry.id);_busy.remove(machineId);@@ -889,9 +890,7 @@ class _ProductPageState extends State<_ProductPage> {const SizedBox(width: 8),Expanded(child: Text(- rating.isEmpty- ? 'No ratings yet'- : '${rating.average.toStringAsFixed(1)} · ${rating.count} rating${rating.count == 1 ? '' : 's'}',+ '${rating.average.toStringAsFixed(1)} · ${rating.count} rating${rating.count == 1 ? '' : 's'}',maxLines: 1,overflow: TextOverflow.ellipsis,style: TextStyle(@@ -1374,6 +1373,7 @@ class _LinkChip extends StatelessWidget {}}+/// Drawn only for a rating somebody has given.class _RatingSummary extends StatelessWidget {const _RatingSummary({required this.rating});final StoreRating rating;@@ -1388,7 +1388,7 @@ class _RatingSummary extends StatelessWidget {crossAxisAlignment: CrossAxisAlignment.start,children: [Text(- rating.isEmpty ? '–' : rating.average.toStringAsFixed(1),+ rating.average.toStringAsFixed(1),style: TextStyle(fontSize: 40,fontWeight: FontWeight.w700,diff --git a/desktop/test/store_controller_test.dart b/desktop/test/store_controller_test.dartnew file mode 100644index 000000000..e9411727d--- /dev/null+++ b/desktop/test/store_controller_test.dart@@ -0,0 +1,503 @@+// What the Harness Store reads from the control plane: a rating and a page of+// reviews, read defensively off the wire; and the controller the store screen+// holds, which turns every failure into a sentence — a control plane that+// predates the store (404) most of all, since the store is whole without it.+import 'package:dio/dio.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness/api/api_client.dart';+import 'package:harness/auth/auth_session.dart';+import 'package:harness/core/config.dart';+import 'package:harness/core/dsh_catalog.dart';+import 'package:harness/store/store_controller.dart';+import 'package:harness/store/store_models.dart';++/// The real client's store calls, answered by an envelope instead of a socket:+/// each goes through [unwrapApiResponse], so a 404 here is exactly the+/// [ApiException] a control plane without the store routes produces.+class _Api extends ApiClient {+ _Api() : super(config: AppConfig.dev, session: AuthSession());++ Response<Object?> Function(String path) answer = (_) => _ok(null);+ final calls = <(String, Object?)>[];++ static Response<Object?> _ok(Object? data) => Response(+ requestOptions: RequestOptions(),+ statusCode: 200,+ data: {'success': true, 'data': data},+ );++ static Response<Object?> _status(int status, [String? message]) => Response(+ requestOptions: RequestOptions(),+ statusCode: status,+ data: {+ 'success': false,+ 'error': {'message': ?message},+ },+ );++ @override+ Future<Map<String, dynamic>?> storeRatings() async {+ calls.add(('ratings', null));+ return unwrapApiResponse(answer('ratings')) as Map<String, dynamic>?;+ }++ @override+ Future<Map<String, dynamic>?> storeReviews(String harnessId) async {+ calls.add(('reviews', harnessId));+ return unwrapApiResponse(answer('reviews')) as Map<String, dynamic>?;+ }++ @override+ Future<Map<String, dynamic>?> putStoreReview(+ String harnessId, {+ required int rating,+ String? title,+ String? body,+ }) async {+ calls.add((+ 'put',+ {'id': harnessId, 'rating': rating, 'title': title, 'body': body},+ ));+ return unwrapApiResponse(answer('put')) as Map<String, dynamic>?;+ }++ @override+ Future<void> deleteStoreReview(String harnessId) async {+ calls.add(('delete', harnessId));+ unwrapApiResponse(answer('delete'));+ }+}++Map<String, Object?> _review({+ String id = 'r1',+ Object? rating = 4,+ Object? title,+ Object? body,+ Object? author = 'Ann Lee',+ Object? mine,+ Object? updatedAt = '2026-09-01T10:00:00.000Z',+}) => {+ 'id': id,+ 'harnessId': 'autonomous/marp',+ 'rating': rating,+ 'title': title,+ 'body': body,+ 'authorName': author,+ 'mine': mine,+ 'updatedAt': updatedAt,+};++void main() {+ group('StoreRating off the wire', () {+ test('a well-formed rating reads as sent', () {+ final rating = StoreRating.fromJson({+ 'harnessId': 'autonomous/marp',+ 'average': 4.25,+ 'count': 4,+ 'histogram': [0, 0, 1, 1, 2],+ })!;+ expect(rating.harnessId, 'autonomous/marp');+ expect(rating.average, 4.25);+ expect(rating.count, 4);+ expect(rating.histogram, [0, 0, 1, 1, 2]);+ expect(rating.isEmpty, isFalse);+ });++ test('anything that is not a rating is refused', () {+ expect(StoreRating.fromJson(null), isNull);+ expect(StoreRating.fromJson('autonomous/marp'), isNull);+ expect(StoreRating.fromJson({'count': 1}), isNull);+ expect(StoreRating.fromJson({'harnessId': '', 'count': 1}), isNull);+ expect(StoreRating.fromJson({'harnessId': 42, 'count': 1}), isNull);+ expect(+ StoreRating.fromJson({'harnessId': 'a/b', 'count': 'many'}),+ isNull,+ );+ });++ test(+ 'bad numbers are clamped and a short or odd histogram is five bars',+ () {+ final wild = StoreRating.fromJson({+ 'harnessId': 'a/b',+ 'average': 9.5,+ 'count': -3,+ 'histogram': [2, 'x', -1],+ })!;+ expect(wild.average, 5.0, reason: 'no more than five stars');+ expect(wild.count, 0, reason: 'never a negative count');+ expect(wild.histogram, [2, 0, 0, 0, 0]);+ expect(wild.isEmpty, isTrue);++ final long = StoreRating.fromJson({+ 'harnessId': 'a/b',+ 'average': 'high',+ 'count': 7.9,+ 'histogram': [1, 1, 1, 1, 1, 1, 1],+ })!;+ expect(+ long.average,+ 0.0,+ reason: 'an average that is not a number is none',+ );+ expect(long.count, 7);+ expect(long.histogram, [1, 1, 1, 1, 1]);++ final bare = StoreRating.fromJson({'harnessId': 'a/b', 'count': 2})!;+ expect(bare.histogram, [0, 0, 0, 0, 0]);+ },+ );++ test('the empty rating is what a page shows before anyone speaks', () {+ final none = StoreRating.none('autonomous/typst');+ expect(none.harnessId, 'autonomous/typst');+ expect(none.isEmpty, isTrue);+ expect(none.average, 0);+ expect(none.histogram, [0, 0, 0, 0, 0]);+ });+ });++ group('StoreReview off the wire', () {+ test(+ 'words are trimmed, blanks are none, and the author is never blank',+ () {+ final review = StoreReview.fromJson(+ _review(+ title: ' Sharp decks ',+ body: ' The pane is the deck. ',+ mine: true,+ ),+ )!;+ expect(review.id, 'r1');+ expect(review.harnessId, 'autonomous/marp');+ expect(review.rating, 4);+ expect(review.title, 'Sharp decks');+ expect(review.body, 'The pane is the deck.');+ expect(review.authorName, 'Ann Lee');+ expect(review.mine, isTrue);+ expect(review.updatedAt, DateTime.utc(2026, 9, 1, 10));++ final quiet = StoreReview.fromJson(+ _review(+ title: ' ',+ body: 7,+ author: ' ',+ mine: 'yes',+ updatedAt: 'last week',+ ),+ )!;+ expect(quiet.title, isNull);+ expect(quiet.body, isNull);+ expect(quiet.authorName, 'Harness user');+ expect(+ quiet.mine,+ isFalse,+ reason: 'only a literal true is the reader',+ );+ expect(quiet.updatedAt, DateTime.fromMillisecondsSinceEpoch(0));++ final undated = StoreReview.fromJson(+ _review(author: null, updatedAt: null),+ )!;+ expect(undated.authorName, 'Harness user');+ expect(undated.updatedAt, DateTime.fromMillisecondsSinceEpoch(0));+ },+ );++ test(+ 'a review without an id, a harness or one to five stars is refused',+ () {+ expect(StoreReview.fromJson(null), isNull);+ expect(StoreReview.fromJson([_review()]), isNull);+ expect(StoreReview.fromJson({..._review(), 'id': 1}), isNull);+ expect(StoreReview.fromJson({..._review(), 'harnessId': null}), isNull);+ expect(StoreReview.fromJson(_review(rating: 'five')), isNull);+ expect(StoreReview.fromJson(_review(rating: 0)), isNull);+ expect(StoreReview.fromJson(_review(rating: 6)), isNull);+ expect(StoreReview.fromJson(_review(rating: 5.0))!.rating, 5);+ },+ );+ });++ group('ApiStoreApi', () {+ test('ratings keep the rows that read and drop the rest', () async {+ final api = _Api()+ ..answer = (_) => _Api._ok({+ 'ratings': [+ {'harnessId': 'autonomous/marp', 'average': 4.5, 'count': 2},+ 'junk',+ {'harnessId': '', 'count': 1},+ ],+ });+ final ratings = await ApiStoreApi(api).ratings();+ expect(ratings.map((r) => r.harnessId), ['autonomous/marp']);++ api.answer = (_) => _Api._ok({'ratings': 'none'});+ expect(await ApiStoreApi(api).ratings(), isEmpty);+ api.answer = (_) => _Api._ok(null);+ expect(await ApiStoreApi(api).ratings(), isEmpty);+ });++ test(+ 'a page of reviews has its rating, its reviews and the reader\'s own',+ () async {+ final api = _Api()+ ..answer = (_) => _Api._ok({+ 'rating': {+ 'harnessId': 'autonomous/marp',+ 'average': 4,+ 'count': 1,+ },+ 'reviews': [_review(mine: true), 'junk'],+ 'mine': _review(mine: true),+ });+ final page = await ApiStoreApi(api).reviews('autonomous/marp');+ expect(api.calls.single, ('reviews', 'autonomous/marp'));+ expect(page.rating.count, 1);+ expect(page.reviews.map((r) => r.id), ['r1']);+ expect(page.mine?.mine, isTrue);++ api.answer = (_) => _Api._ok({'reviews': null, 'rating': 'x'});+ final empty = await ApiStoreApi(api).reviews('autonomous/typst');+ expect(empty.reviews, isEmpty);+ expect(empty.mine, isNull);+ expect(empty.rating.harnessId, 'autonomous/typst');+ expect(empty.rating.isEmpty, isTrue);+ },+ );++ test(+ 'a posted review is read back, and an answer without one is an error',+ () async {+ final api = _Api()+ ..answer = (_) =>+ _Api._ok({'review': _review(title: 'Sharp', mine: true)});+ final posted = await ApiStoreApi(+ api,+ ).putReview('autonomous/marp', rating: 4, title: 'Sharp', body: 'Yes');+ expect(posted.title, 'Sharp');+ expect(api.calls.single.$1, 'put');+ expect(api.calls.single.$2, {+ 'id': 'autonomous/marp',+ 'rating': 4,+ 'title': 'Sharp',+ 'body': 'Yes',+ });++ api.answer = (_) => _Api._ok({'review': 'x'});+ await expectLater(+ ApiStoreApi(api).putReview('autonomous/marp', rating: 4),+ throwsFormatException,+ );+ },+ );++ test('delete reaches the client for that harness', () async {+ final api = _Api();+ await ApiStoreApi(api).deleteReview('autonomous/marp');+ expect(api.calls.single, ('delete', 'autonomous/marp'));+ });+ });++ group('StoreController', () {+ test('keys: a harness by its id, an engine under engine/', () {+ expect(+ StoreController.keyFor(+ const DshEntry(id: 'autonomous/marp', name: 'Marp', engine: 'claude'),+ ),+ 'autonomous/marp',+ );+ expect(+ StoreController.keyFor(+ const DshEntry(+ id: 'codex',+ name: 'Codex',+ engine: 'codex',+ kind: 'engine',+ ),+ ),+ 'engine/codex',+ );+ });++ test(+ 'ratings load once at a time, and a harness with none reads empty',+ () async {+ final api = _Api()+ ..answer = (_) => _Api._ok({+ 'ratings': [+ {'harnessId': 'autonomous/marp', 'average': 4.5, 'count': 2},+ ],+ });+ final store = StoreController(ApiStoreApi(api));+ addTearDown(store.dispose);+ var notified = 0;+ store.addListener(() => notified++);+ final first = store.loadRatings();+ expect(store.ratingsLoading, isTrue);+ await store.loadRatings();+ await first;+ expect(+ api.calls,+ hasLength(1),+ reason: 'a second load while one runs is the same load',+ );+ expect(store.ratingsLoading, isFalse);+ expect(store.ratingsLoaded, isTrue);+ expect(store.ratingsError, isNull);+ expect(store.ratingOf('autonomous/marp').average, 4.5);+ expect(store.ratingOf('autonomous/typst').isEmpty, isTrue);+ expect(notified, 2);+ },+ );++ test('a control plane without the store (404) says so, and the store keeps going', () async {+ final api = _Api()..answer = (_) => _Api._status(404, 'Not Found');+ final store = StoreController(ApiStoreApi(api));+ addTearDown(store.dispose);+ await store.loadRatings();+ expect(+ store.ratingsError,+ 'Ratings and reviews are not on the Harness server yet; they arrive with its next release.',+ );+ expect(store.ratingsLoaded, isTrue);+ expect(store.ratings, isEmpty);+ expect(store.ratingOf('autonomous/marp').isEmpty, isTrue);++ await store.loadReviews('autonomous/marp');+ expect(+ store.reviewsError['autonomous/marp'],+ startsWith('Ratings and reviews are not on the Harness server yet'),+ );+ expect(store.reviews, isEmpty);+ });++ test('every other failure is a sentence too', () async {+ Future<String?> errorFor(Response<Object?> answer) async {+ final store = StoreController(+ ApiStoreApi(_Api()..answer = (_) => answer),+ );+ addTearDown(store.dispose);+ await store.loadRatings();+ return store.ratingsError;+ }++ expect(+ await errorFor(_Api._status(401)),+ 'Sign in to see ratings and reviews.',+ );+ expect(+ await errorFor(_Api._status(403)),+ 'Sign in to see ratings and reviews.',+ );+ expect(+ await errorFor(_Api._status(500, ' Database is down ')),+ 'Database is down',+ );+ expect(+ await errorFor(_Api._status(502)),+ 'Request failed (502)',+ reason: 'no server message: the envelope\'s own',+ );+ expect(+ await errorFor(_Api._status(500, ' ')),+ 'Ratings are not available right now',+ reason: 'a blank server message is no sentence',+ );++ final transport = StoreController(_Throwing(StateError('socket closed')));+ addTearDown(transport.dispose);+ await transport.loadRatings();+ expect(transport.ratingsError, 'Ratings are not available right now');+ await transport.loadReviews('autonomous/marp');+ expect(+ transport.reviewsError['autonomous/marp'],+ 'Reviews are not available right now',+ );+ expect(+ await transport.submit('autonomous/marp', rating: 5),+ 'Your review could not be posted',+ );+ expect(+ await transport.remove('autonomous/marp'),+ 'Your review could not be removed',+ );+ });++ test('a page of reviews replaces the row\'s rating, and a later success clears its error', () async {+ final api = _Api()..answer = (_) => _Api._status(503, 'Try later');+ final store = StoreController(ApiStoreApi(api));+ addTearDown(store.dispose);+ await store.loadReviews('autonomous/marp');+ expect(store.reviewsError['autonomous/marp'], 'Try later');++ api.answer = (_) => _Api._ok({+ 'rating': {'harnessId': 'autonomous/marp', 'average': 3, 'count': 1},+ 'reviews': [_review()],+ });+ final first = store.loadReviews('autonomous/marp');+ expect(store.reviewsLoading, contains('autonomous/marp'));+ await store.loadReviews('autonomous/marp');+ await first;+ expect(+ api.calls.where((c) => c.$1 == 'reviews'),+ hasLength(2),+ reason: 'a page already loading is not asked twice',+ );+ expect(store.reviewsError, isEmpty);+ expect(store.reviewsLoading, isEmpty);+ expect(store.reviews['autonomous/marp']!.reviews.single.id, 'r1');+ expect(store.ratingOf('autonomous/marp').average, 3);+ });++ test('submit and remove write, then read the page again', () async {+ final api = _Api();+ api.answer = (path) => switch (path) {+ 'put' => _Api._ok({'review': _review(mine: true)}),+ 'delete' => _Api._ok(null),+ _ => _Api._ok({'reviews': <Object>[]}),+ };+ final store = StoreController(ApiStoreApi(api));+ addTearDown(store.dispose);+ expect(+ await store.submit('autonomous/marp', rating: 4, title: 'T', body: 'B'),+ isNull,+ );+ expect(await store.remove('autonomous/marp'), isNull);+ expect(api.calls.map((c) => c.$1), [+ 'put',+ 'reviews',+ 'delete',+ 'reviews',+ ]);++ api.answer = (_) => _Api._status(401);+ expect(+ await store.submit('autonomous/marp', rating: 4),+ 'Sign in to see ratings and reviews.',+ );+ expect(+ await store.remove('autonomous/marp'),+ 'Sign in to see ratings and reviews.',+ );+ });+ });+}++class _Throwing implements StoreApi {+ _Throwing(this.error);+ final Object error;+ @override+ Future<List<StoreRating>> ratings() async => throw error;+ @override+ Future<StoreReviews> reviews(String harnessId) async => throw error;+ @override+ Future<StoreReview> putReview(+ String harnessId, {+ required int rating,+ String? title,+ String? body,+ }) async => throw error;+ @override+ Future<void> deleteReview(String harnessId) async => throw error;+}diff --git a/desktop/test/store_page_test.dart b/desktop/test/store_page_test.dartnew file mode 100644index 000000000..2755a5800--- /dev/null+++ b/desktop/test/store_page_test.dart@@ -0,0 +1,1149 @@+// A harness's page in the Harness Store, past the happy path the screen test+// pins: every machine's row and what its install is doing, Get/Open/Remove+// under double clicks and pages that vanish mid-dialog, engines as the probes+// saw them, viewer packages, links, pictures, reviews, the shelves around the+// page, and a store whose control plane has no ratings routes at all (404).+import 'dart:async';++import 'package:dio/dio.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/api/api_client.dart';+import 'package:harness/auth/auth_session.dart';+import 'package:harness/core/config.dart';+import 'package:harness/core/dsh_catalog.dart';+import 'package:harness/core/engine_availability.dart';+import 'package:harness/core/models.dart';+import 'package:harness/state/app_state.dart';+import 'package:harness/store/store_controller.dart';+import 'package:harness/store/store_models.dart';+import 'package:harness/store/store_screen.dart';++import 'support/real_fonts.dart';++const _marp = DshEntry(+ id: 'autonomous/marp',+ name: 'Marp',+ engine: 'claude',+ category: 'Slides',+ author: 'Yuki Hattori',+ description: 'Describe a talk; get a keynote.',+ installed: true,+ viewer: true,+ homepage: 'https://marp.app',+ upstream: 'https://github.com/marp-team/marp-cli',+ repo: 'https://github.com/autonomous-ai/autonomous-marp',+ license: 'MIT',+);+const _typst = DshEntry(+ id: 'autonomous/typst',+ name: 'Typst',+ engine: 'claude',+ category: 'Documents',+ author: 'Typst GmbH',+);+const _docViewer = DshEntry(+ id: 'autonomous/doc-viewer',+ name: 'Doc Viewer',+ engine: '',+ kind: 'viewer',+ installed: true,+ category: 'Documents',+ author: 'Autonomous',+);++class _Notifier extends AppNotifier {+ _Notifier()+ : super(+ config: AppConfig.dev,+ authSession: AuthSession(),+ configStore: null,+ );++ final installs = <(String, String)>[];+ final removals = <(String, String)>[];+ Completer<String?>? installGate;+ Completer<String?>? removeGate;+ int probes = 0;++ @override+ Future<void> probeEngines(String machineId, {bool force = false}) async {+ probes++;+ }++ @override+ Future<void> probeDsh(String machineId, {bool force = false}) async {+ probes++;+ }++ @override+ Future<String?> installDsh(String machineId, String id) async {+ installs.add((machineId, id));+ return installGate?.future;+ }++ @override+ Future<String?> removeDsh(String machineId, String id) async {+ removals.add((machineId, id));+ return removeGate?.future;+ }++ void changed() => notifyListeners();++ MachineState machine(+ String id, {+ String? name,+ bool local = false,+ bool? online,+ List<DshEntry>? dsh,+ List<EngineAvailability>? engines,+ }) {+ final state =+ MachineState(+ Machine(+ machineId: id,+ authMode: MachineAuthMode.remote,+ name: name ?? id,+ ),+ )+ ..localOnly = local+ ..nodeOnline = online;+ if (dsh != null) state.dsh.replace(dsh);+ if (engines != null) state.engines.replace(engines);+ machineStates[id] = state;+ return state;+ }+}++class _Store implements StoreApi {+ List<StoreRating> rated = const [];+ StoreReviews Function(String harnessId)? page;+ Object? failReviews;+ Object? failPut;+ final puts = <(String, int)>[];+ final deletes = <String>[];+ int ratingReads = 0;+ final reviewReads = <String>[];++ @override+ Future<List<StoreRating>> ratings() async {+ ratingReads++;+ return rated;+ }++ @override+ Future<StoreReviews> reviews(String harnessId) async {+ reviewReads.add(harnessId);+ if (failReviews case final error?) throw error;+ return page?.call(harnessId) ??+ StoreReviews(+ rating: StoreRating.none(harnessId),+ reviews: const [],+ mine: null,+ );+ }++ @override+ Future<StoreReview> putReview(+ String harnessId, {+ required int rating,+ String? title,+ String? body,+ }) async {+ if (failPut case final error?) throw error;+ puts.add((harnessId, rating));+ return StoreReview(+ id: 'mine',+ harnessId: harnessId,+ rating: rating,+ authorName: 'You',+ mine: true,+ updatedAt: DateTime.now(),+ );+ }++ @override+ Future<void> deleteReview(String harnessId) async => deletes.add(harnessId);+}++/// The store tab, opened with [seed]'s machines — by default this computer,+/// with Marp installed and Typst not.+Future<(_Notifier, _Store)> _open(+ WidgetTester tester, {+ String? initialHarness,+ void Function(_Notifier app)? seed,+ _Store? store,+ StoreApi? api,+ bool injectApi = true,+ bool settle = true,+ Size size = const Size(1280, 2400),+}) async {+ tester.view.devicePixelRatio = 1;+ tester.view.physicalSize = size;+ addTearDown(tester.view.reset);+ final notifier = _Notifier();+ addTearDown(notifier.dispose);+ (seed ??+ (app) => app.machine(+ 'machine-1',+ name: 'studio-mac',+ local: true,+ dsh: const [_marp, _typst, _docViewer],+ engines: const [EngineAvailability(engine: 'claude', installed: true)],+ ))(notifier);+ final fake = store ?? _Store();+ // The store lives in its own tab, as the start page's card opens it.+ notifier.openStore();+ await tester.pumpWidget(+ MaterialApp(+ home: Scaffold(+ body: StoreTab(+ notifier: notifier,+ api: injectApi ? (api ?? fake) : null,+ source: 'test',+ initialHarness: initialHarness,+ ),+ ),+ ),+ );+ // A spinner or a skeleton never settles; those tests pump frames instead.+ settle ? await tester.pumpAndSettle() : await tester.pump();+ await tester.pump();+ return (notifier, fake);+}++Finder _key(String key) => find.byKey(ValueKey(key));++Finder _in(String key, Finder matching) =>+ find.descendant(of: _key(key), matching: matching);++StoreReview _review(+ String id, {+ required int daysAgo,+ bool mine = false,+ String? title,+ String? body,+}) => StoreReview(+ id: id,+ harnessId: 'autonomous/marp',+ rating: 4,+ title: title,+ body: body,+ authorName: 'Reviewer $id',+ mine: mine,+ updatedAt: DateTime.now().subtract(Duration(days: daysAgo, minutes: 5)),+);++void main() {+ // Real glyph widths: the review dialog's buttons are laid out against Arial,+ // not against Ahem's squares, which overflow a row no person would see.+ setUpAll(loadRealFonts);++ group('Get, Open and Remove', () {+ testWidgets(+ 'Get installs on this machine once however fast the clicks, and a failure is said',+ (tester) async {+ final (app, _) = await _open(+ tester,+ initialHarness: 'autonomous/typst',+ );+ app.installGate = Completer<String?>();+ expect(_in('store-primary-action', find.text('Get')), findsOneWidget);+ await tester.tap(_key('store-primary-action'));+ await tester.tap(_key('store-get:machine-1'));+ expect(app.installs, [('machine-1', 'autonomous/typst')]);+ await tester.pump();+ expect(+ tester.widget<FilledButton>(_key('store-primary-action')).onPressed,+ isNull,+ reason: 'busy while the install runs',+ );+ expect(+ _in(+ 'store-machine:machine-1',+ find.byType(CircularProgressIndicator),+ ),+ findsOneWidget,+ );+ expect(_key('store-get:machine-1'), findsNothing);++ app.installGate!.complete('kicad-cli is not on studio-mac');+ await tester.pumpAndSettle();+ expect(find.text('kicad-cli is not on studio-mac'), findsOneWidget);+ expect(_key('store-get:machine-1'), findsOneWidget);+ expect(+ tester.widget<FilledButton>(_key('store-primary-action')).onPressed,+ isNotNull,+ );+ },+ );++ testWidgets('an install that ends after the page is gone says nothing', (+ tester,+ ) async {+ final (app, _) = await _open(tester, initialHarness: 'autonomous/typst');+ app.installGate = Completer<String?>();+ await tester.tap(_key('store-get:machine-1'));+ await tester.pump();+ await tester.tap(_key('store-back'));+ await tester.pumpAndSettle();+ expect(_key('store-page:autonomous/typst'), findsNothing);+ app.installGate!.complete('clone failed');+ await tester.pumpAndSettle();+ expect(find.text('clone failed'), findsNothing);+ expect(tester.takeException(), isNull);+ });++ testWidgets(+ 'Remove asks first, Cancel keeps it, and a linked install says only its link goes',+ (tester) async {+ final (app, _) = await _open(+ tester,+ initialHarness: 'autonomous/marp',+ seed: (app) => app.machine(+ 'machine-1',+ name: 'studio-mac',+ local: true,+ dsh: [+ DshEntry(+ id: _marp.id,+ name: _marp.name,+ engine: 'claude',+ installed: true,+ linked: true,+ ),+ ],+ ),+ );+ expect(+ _in(+ 'store-machine:machine-1',+ find.text('Installed · linked to a checkout'),+ ),+ findsOneWidget,+ );+ await tester.tap(_key('store-remove:machine-1'));+ await tester.pumpAndSettle();+ expect(+ find.text(+ 'This is linked to a checkout on that machine; only the link goes. Harnesses already open keep running.',+ ),+ findsOneWidget,+ );+ await tester.tap(find.widgetWithText(TextButton, 'Cancel'));+ await tester.pumpAndSettle();+ expect(app.removals, isEmpty);+ expect(find.textContaining('only the link goes'), findsNothing);+ },+ );++ testWidgets('Remove runs once at a time, and a refusal is said', (+ tester,+ ) async {+ final (app, _) = await _open(tester, initialHarness: 'autonomous/marp');+ app.removeGate = Completer<String?>();+ await tester.tap(_key('store-remove:machine-1'));+ await tester.pumpAndSettle();+ expect(find.text('Remove Marp from studio-mac?'), findsOneWidget);+ await tester.tap(_key('store-confirm'));+ await tester.pump();+ await tester.pump(const Duration(milliseconds: 200));+ expect(app.removals, [('machine-1', 'autonomous/marp')]);+ expect(+ _in('store-machine:machine-1', find.byType(CircularProgressIndicator)),+ findsOneWidget,+ );+ expect(_key('store-remove:machine-1'), findsNothing);+ app.removeGate!.complete(+ 'Update the harness CLI on studio-mac to remove harnesses',+ );+ await tester.pumpAndSettle();+ expect(+ find.text('Update the harness CLI on studio-mac to remove harnesses'),+ findsOneWidget,+ );+ expect(_key('store-remove:machine-1'), findsOneWidget);+ });++ testWidgets(+ 'a harness that leaves the catalog while Remove asks is not removed',+ (tester) async {+ final (app, _) = await _open(tester, initialHarness: 'autonomous/marp');+ await tester.tap(_key('store-remove:machine-1'));+ await tester.pumpAndSettle();+ app.machineStates['machine-1']!.dsh.replace(const [_typst]);+ app.changed();+ await tester.pumpAndSettle();+ expect(_key('store-page:autonomous/marp'), findsNothing);+ await tester.tap(_key('store-confirm'));+ await tester.pumpAndSettle();+ expect(app.removals, isEmpty);+ expect(tester.takeException(), isNull);+ },+ );++ testWidgets(+ 'Open, from the page or a machine row, opens New Harness on that machine in a tab of its own',+ (tester) async {+ final (app, _) = await _open(tester, initialHarness: 'autonomous/marp');+ final tabs = app.swarms.length;+ expect(_in('store-primary-action', find.text('Open')), findsOneWidget);+ await tester.tap(_key('store-primary-action'));+ await tester.pumpAndSettle();+ expect(find.text('New Harness'), findsOneWidget);+ expect(app.swarms.length, tabs + 1);+ await tester.sendKeyEvent(LogicalKeyboardKey.escape);+ await tester.pumpAndSettle();+ expect(+ app.swarms.length,+ tabs,+ reason: 'a dismissed dialog leaves no tab',+ );++ await tester.tap(_key('store-open:machine-1'));+ await tester.pumpAndSettle();+ expect(find.text('New Harness'), findsOneWidget);+ await tester.sendKeyEvent(LogicalKeyboardKey.escape);+ await tester.pumpAndSettle();+ expect(app.swarms.length, tabs);+ },+ );+ });++ testWidgets(+ 'every machine has a row — this computer first, then by name — saying where its install stands',+ (tester) async {+ DshInstallRun run(String phase, {String? line}) => DshInstallRun(+ _typst.id,+ )..apply(DshInstallProgress(id: _typst.id, phase: phase, line: line));+ final (app, _) = await _open(+ tester,+ initialHarness: 'autonomous/typst',+ settle: false,+ seed: (app) {+ app.machine('juliet', dsh: const [_typst]);+ app.machine('india').dsh.error =+ 'This machine could not report its harnesses';+ app.machine('hotel');+ app.machine('golf').dsh.error = 'UNSUPPORTED';+ app.machine(+ 'foxtrot',+ dsh: const [+ DshEntry(+ id: 'autonomous/typst',+ name: 'Typst',+ engine: 'claude',+ installed: true,+ linked: true,+ ),+ ],+ );+ app+ .machine('echo', dsh: const [_typst])+ .dsh+ .runs[_typst.id] = DshInstallRun(_typst.id)+ ..apply(DshInstallProgress(id: _typst.id, phase: 'clone'))+ ..apply(+ DshInstallProgress(+ id: _typst.id,+ phase: 'failed',+ detail: 'no space left',+ ),+ );+ app.machine('delta', dsh: const [_typst]).dsh.runs[_typst.id] = run(+ 'doctor',+ line: 'miss typst-cli (cargo install typst-cli)',+ )..apply(DshInstallProgress(id: _typst.id, phase: 'failed'));+ app.machine('charlie', dsh: const [_typst]).dsh.runs[_typst.id] = run(+ 'queued',+ );+ app.machine('Beta', dsh: const [_typst]).dsh.runs[_typst.id] = run(+ 'doctor',+ );+ app.machine('alpha', dsh: const [_typst]).dsh.runs[_typst.id] = run(+ 'setup',+ );+ app+ .machine(+ 'machine-1',+ name: 'zulu-mac',+ local: true,+ dsh: const [_typst],+ )+ .dsh+ .runs[_typst.id] = run(+ 'clone',+ );+ },+ );+ final order = [+ 'machine-1',+ 'alpha',+ 'Beta',+ 'charlie',+ 'delta',+ 'echo',+ 'foxtrot',+ 'golf',+ 'hotel',+ 'india',+ 'juliet',+ ];+ final tops = [+ for (final id in order) tester.getTopLeft(_key('store-machine:$id')).dy,+ ];+ expect(tops, [...tops]..sort(), reason: 'this computer, then by name');++ void says(String id, String status) => expect(+ _in('store-machine:$id', find.text(status)),+ findsOneWidget,+ reason: id,+ );+ says('machine-1', 'zulu-mac · this computer');+ says('machine-1', 'Fetching…');+ says('alpha', 'alpha');+ says('alpha', 'Setting up the toolchain…');+ says('Beta', 'Checking…');+ says('charlie', 'Installing…');+ for (final id in ['machine-1', 'alpha', 'Beta', 'charlie']) {+ expect(+ _in('store-machine:$id', find.byType(CircularProgressIndicator)),+ findsOneWidget,+ reason: id,+ );+ }+ says('delta', 'miss typst-cli (cargo install typst-cli)');+ says('echo', 'Install failed');+ final failed = tester.widget<Text>(+ _in('store-machine:echo', find.text('Install failed')),+ );+ expect(+ failed.style?.color,+ isNot(+ tester+ .widget<Text>(+ _in('store-machine:juliet', find.text('Not installed')),+ )+ .style+ ?.color,+ ),+ reason: 'a failure is not in the quiet colour',+ );+ expect(_in('store-get:delta', find.text('Try again')), findsOneWidget);+ says('foxtrot', 'Installed · linked to a checkout');+ expect(_key('store-open:foxtrot'), findsOneWidget);+ expect(_key('store-remove:foxtrot'), findsOneWidget);+ says(+ 'golf',+ 'Update the harness CLI on this machine to install harnesses',+ );+ says('hotel', 'Asking…');+ says('india', 'This machine could not report its harnesses');+ for (final id in ['golf', 'hotel', 'india']) {+ expect(+ tester.widget<FilledButton>(_key('store-get:$id')).onPressed,+ isNull,+ reason: '$id has not said it can install',+ );+ }+ says('juliet', 'Not installed');++ await tester.tap(_key('store-get:delta'));+ await tester.pump();+ await tester.tap(_key('store-get:juliet'));+ await tester.pump();+ expect(app.installs, [+ ('delta', 'autonomous/typst'),+ ('juliet', 'autonomous/typst'),+ ]);+ },+ );++ testWidgets(+ 'an engine page reads the probes: asking, installed with Open, installable with Get, or neither',+ (tester) async {+ // One rating, from a control plane that sent no bars for it.+ const rating = StoreRating(+ harnessId: 'engine/claude',+ average: 5,+ count: 1,+ histogram: [0, 0, 0, 0, 0],+ );+ final store = _Store()+ ..rated = const [rating]+ ..page = ((_) =>+ const StoreReviews(rating: rating, reviews: [], mine: null));+ final (app, _) = await _open(+ tester,+ store: store,+ initialHarness: 'claude',+ seed: (app) {+ app.machine('machine-1', name: 'studio-mac', local: true);+ app.machine(+ 'alpha',+ engines: const [+ EngineAvailability(engine: 'claude', installed: true),+ ],+ );+ app.machine(+ 'beta',+ engines: const [+ EngineAvailability(engine: 'claude', installed: false),+ ],+ );+ app.machine(+ 'gamma',+ engines: const [+ EngineAvailability(+ engine: 'claude',+ installed: false,+ installable: true,+ ),+ ],+ );+ },+ );+ expect(find.text('Anthropic · Code · Coding agent'), findsOneWidget);+ expect(store.reviewReads, [+ 'engine/claude',+ ], reason: 'an engine is rated under engine/');+ expect(+ _in('store-machine:machine-1', find.text('Asking…')),+ findsOneWidget,+ );+ expect(+ _in('store-machine:machine-1', find.byType(TextButton)),+ findsNothing,+ );+ expect(_in('store-machine:alpha', find.text('alpha')), findsOneWidget);+ expect(_key('store-open:alpha'), findsOneWidget);+ expect(+ _in('store-machine:beta', find.text('Not installed')),+ findsOneWidget,+ );+ expect(_key('store-get:beta'), findsNothing, reason: 'nothing to offer');+ expect(_key('store-get:gamma'), findsOneWidget);+ // A rating with no bars drawn still reads as its number.+ expect(find.text('5.0 · 1 rating'), findsOneWidget);+ expect(find.text('out of 5 · 1 rating'), findsOneWidget);++ final tabs = app.swarms.length;+ // Get on an engine is Open: the daemon installs it on the way.+ expect(_in('store-primary-action', find.text('Get')), findsOneWidget);+ await tester.tap(_key('store-primary-action'));+ await tester.pumpAndSettle();+ expect(find.text('New Harness'), findsOneWidget);+ expect(app.installs, isEmpty);+ await tester.sendKeyEvent(LogicalKeyboardKey.escape);+ await tester.pumpAndSettle();+ expect(app.swarms.length, tabs);+ },+ );++ testWidgets(+ 'a viewer package has a page but nothing to open, and a store with no machines says so',+ (tester) async {+ final (app, _) = await _open(+ tester,+ initialHarness: 'autonomous/doc-viewer',+ );+ expect(+ find.text('Autonomous · Documents · Viewer package'),+ findsOneWidget,+ );+ expect(_key('store-primary-action'), findsNothing);+ expect(_key('store-remove:machine-1'), findsOneWidget);+ expect(_key('store-open:machine-1'), findsNothing);++ // Its machine goes away, and the page with it.+ app.machineStates.clear();+ app.changed();+ await tester.pump();+ expect(_key('store-page:autonomous/doc-viewer'), findsNothing);+ },+ );++ testWidgets('with no machines an engine page has no action and says so', (+ tester,+ ) async {+ await _open(tester, initialHarness: 'codex', seed: (_) {});+ expect(find.text('No machines yet.'), findsOneWidget);+ expect(_key('store-primary-action'), findsNothing);+ });++ testWidgets(+ 'links open outside the app, the licence is only words, and pictures that fail leave no hole',+ (tester) async {+ final launched = <String>[];+ const channel = MethodChannel('plugins.flutter.io/url_launcher');+ tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, (+ call,+ ) async {+ if (call.method == 'launch') {+ launched.add((call.arguments as Map)['url'] as String);+ }+ return true;+ });+ addTearDown(+ () => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(+ channel,+ null,+ ),+ );+ await _open(+ tester,+ initialHarness: 'autonomous/marp',+ seed: (app) => app.machine(+ 'machine-1',+ local: true,+ dsh: const [+ DshEntry(+ id: 'autonomous/marp',+ name: 'Marp',+ engine: 'claude',+ upstream: 'https://github.com/marp-team/marp-cli',+ screenshots: [+ 'https://example.com/deck-1.png',+ 'https://example.com/deck-2.png',+ ],+ ),+ ],+ ),+ );+ expect(find.text('Website'), findsNothing);+ expect(find.text('Package source'), findsNothing);+ await tester.tap(find.text('Upstream project'));+ await tester.pump();+ expect(launched, ['https://github.com/marp-team/marp-cli']);++ final pictures = find.byWidgetPredicate(+ (widget) => widget is Image && widget.image is NetworkImage,+ );+ expect(pictures, findsWidgets);+ // The test HTTP client answers every request 400: both pictures fail.+ await tester.runAsync(+ () => Future<void>.delayed(const Duration(milliseconds: 50)),+ );+ await tester.pumpAndSettle();+ expect(tester.takeException(), isNull);+ expect(+ find.descendant(of: pictures, matching: find.byType(RawImage)),+ findsNothing,+ reason: 'a picture that failed draws nothing, not a broken frame',+ );+ },+ );++ testWidgets(+ 'every link the registry names is a chip, the licence without an arrow',+ (tester) async {+ await _open(tester, initialHarness: 'autonomous/marp');+ for (final label in [+ 'Website',+ 'Upstream project',+ 'Package source',+ 'Licence · MIT',+ ]) {+ expect(find.text(label), findsOneWidget, reason: label);+ }+ },+ );++ group('reviews', () {+ StoreReviews marpPage(+ String id, {+ bool withMine = true,+ bool empty = false,+ }) => StoreReviews(+ rating: const StoreRating(+ harnessId: 'autonomous/marp',+ average: 4,+ count: 7,+ histogram: [0, 1, 1, 2, 3],+ ),+ reviews: empty+ ? const []+ : [+ if (withMine)+ _review('mine', daysAgo: 0, mine: true, title: 'Sharp decks'),+ _review('r1', daysAgo: 1, body: 'Fast.'),+ _review('r5', daysAgo: 5),+ _review('r35', daysAgo: 35),+ _review('r70', daysAgo: 70),+ _review('r400', daysAgo: 400),+ _review('r800', daysAgo: 800),+ ],+ mine: withMine+ ? _review('mine', daysAgo: 0, mine: true, title: 'Sharp decks')+ : null,+ );++ testWidgets('each review says who and when, and yours can be edited', (+ tester,+ ) async {+ final store = _Store()..page = marpPage;+ await _open(tester, store: store, initialHarness: 'autonomous/marp');+ expect(find.text('4.0 · 7 ratings'), findsOneWidget);+ expect(+ _in('store-write-review', find.text('Edit your review')),+ findsOneWidget,+ );+ for (final (id, age) in [+ ('mine', 'You · today'),+ ('r1', 'Reviewer r1 · yesterday'),+ ('r5', 'Reviewer r5 · 5 days ago'),+ ('r35', 'Reviewer r35 · 1 month ago'),+ ('r70', 'Reviewer r70 · 2 months ago'),+ ('r400', 'Reviewer r400 · 1 year ago'),+ ('r800', 'Reviewer r800 · 2 years ago'),+ ]) {+ expect(+ _in('store-review:$id', find.text(age)),+ findsOneWidget,+ reason: id,+ );+ }+ expect(_in('store-review:mine', find.text('Edit')), findsOneWidget);+ expect(_in('store-review:r1', find.text('Edit')), findsNothing);+ expect(_in('store-review:r1', find.text('Fast.')), findsOneWidget);++ // Edit from the card: the dialog holds what was written, and can delete it.+ await tester.tap(_in('store-review:mine', find.text('Edit')));+ await tester.pumpAndSettle();+ expect(find.text('Your review of Marp'), findsOneWidget);+ expect(+ tester.widget<TextField>(_key('store-review-title')).controller!.text,+ 'Sharp decks',+ );+ expect(_in('store-review-post', find.text('Save')), findsOneWidget);+ final reads = store.reviewReads.length;+ await tester.tap(_key('store-review-delete'));+ await tester.pumpAndSettle();+ expect(store.deletes, ['autonomous/marp']);+ expect(+ store.reviewReads.length,+ reads + 1,+ reason: 'the page is read again',+ );+ });++ testWidgets('a dismissed review writes nothing, and a failed one is said', (+ tester,+ ) async {+ final store = _Store()+ ..page = ((id) => marpPage(id, withMine: false, empty: true))+ ..failPut = StateError('offline');+ await _open(tester, store: store, initialHarness: 'autonomous/marp');+ expect(find.text('No reviews yet. Be the first.'), findsOneWidget);+ await tester.tap(_key('store-write-review'));+ await tester.pumpAndSettle();+ await tester.tap(find.widgetWithText(TextButton, 'Cancel'));+ await tester.pumpAndSettle();+ expect(find.text('Rate Marp'), findsNothing);+ expect(store.puts, isEmpty);++ await tester.tap(_key('store-write-review'));+ await tester.pumpAndSettle();+ await tester.tap(+ find+ .descendant(+ of: _key('store-review-stars'),+ matching: find.byType(Icon),+ )+ .last,+ );+ await tester.pump();+ await tester.tap(_key('store-review-post'));+ await tester.pumpAndSettle();+ expect(find.text('Your review could not be posted'), findsOneWidget);+ });++ testWidgets(+ 'a rated harness whose reviews will not load still shows its stars',+ (tester) async {+ final store = _Store()+ ..rated = const [+ StoreRating(+ harnessId: 'autonomous/marp',+ average: 3.5,+ count: 2,+ histogram: [0, 0, 1, 1, 0],+ ),+ ]+ ..failReviews = StateError('offline');+ await _open(tester, store: store, initialHarness: 'autonomous/marp');+ expect(find.text('3.5 · 2 ratings'), findsOneWidget);+ expect(find.text('Reviews are unavailable right now.'), findsOneWidget);+ expect(find.text('No reviews yet. Be the first.'), findsNothing);+ },+ );+ });++ testWidgets(+ 'a control plane without ratings (404) leaves a store with no stars that still installs',+ (tester) async {+ final client = _NotFoundClient();+ final (app, _) = await _open(+ tester,+ api: ApiStoreApi(client),+ initialHarness: 'autonomous/typst',+ );+ expect(client.asked, containsAll(['ratings', 'reviews']));+ expect(find.text('Ratings and reviews'), findsNothing);+ expect(find.textContaining('not on the Harness server'), findsNothing);+ expect(find.textContaining('rating'), findsNothing);+ await tester.tap(_key('store-primary-action'));+ await tester.pumpAndSettle();+ expect(app.installs, [('machine-1', 'autonomous/typst')]);+ },+ );++ group('shelves', () {+ testWidgets(+ 'See all lists every harness, and the engines See all is Code',+ (tester) async {+ await _open(tester);+ await tester.tap(find.widgetWithText(TextButton, 'See all').first);+ await tester.pumpAndSettle();+ expect(_key('store-catalog:All harnesses'), findsOneWidget);+ expect(+ find.text('Find something you have always wanted to make.'),+ findsOneWidget,+ );+ expect(_key('store-card:autonomous/marp'), findsOneWidget);+ expect(_key('store-card:claude'), findsOneWidget);++ await tester.tap(_key('store-shelf-discover'));+ await tester.pumpAndSettle();+ await tester.tap(find.widgetWithText(TextButton, 'See all').last);+ await tester.pumpAndSettle();+ expect(_key('store-catalog:Code'), findsOneWidget);+ expect(_key('store-card:autonomous/marp'), findsNothing);+ expect(find.textContaining('harnesses to explore.'), findsOneWidget);+ },+ );++ testWidgets(+ 'a category counts what it holds, empties honestly, and a new domain is Other',+ (tester) async {+ final (app, _) = await _open(+ tester,+ seed: (app) => app.machine(+ 'machine-1',+ local: true,+ dsh: const [+ _typst,+ DshEntry(+ id: 'someone/loom',+ name: 'Loom',+ engine: 'codex',+ category: 'Knitting',+ ),+ ],+ ),+ );+ expect(_key('store-shelf-category:Other'), findsOneWidget);+ await tester.tap(_key('store-shelf-category:Other'));+ await tester.pumpAndSettle();+ expect(find.text('1 harness to explore.'), findsOneWidget);+ expect(_key('store-card:someone/loom'), findsOneWidget);++ await tester.tap(_key('store-shelf-category:Media'));+ await tester.pumpAndSettle();+ // The machine answers again without Typst while the shelf is open.+ app.machineStates['machine-1']!.dsh.replace(const []);+ app.changed();+ await tester.pumpAndSettle();+ expect(find.text('Nothing here yet.'), findsOneWidget);+ // And with no machine left to ask, it is still asking.+ app.machineStates.clear();+ app.changed();+ await tester.pumpAndSettle();+ expect(find.text('Asking your machines…'), findsOneWidget);+ },+ );++ testWidgets('search counts its results', (tester) async {+ await _open(tester);+ await tester.enterText(_key('store-search'), 'keynote');+ await tester.pumpAndSettle();+ expect(find.text('1 result'), findsOneWidget);+ await tester.enterText(_key('store-search'), 'autonomous');+ await tester.pumpAndSettle();+ expect(find.text('2 results'), findsOneWidget);+ await tester.enterText(_key('store-search'), ' ');+ await tester.pumpAndSettle();+ expect(+ _key('store-catalog:Search results'),+ findsNothing,+ reason: 'blank is Discover',+ );+ });++ testWidgets(+ 'a card\'s action opens where it is installed — here, else an online machine — else the page',+ (tester) async {+ final (app, _) = await _open(+ tester,+ seed: (app) {+ app.machine(+ 'machine-1',+ name: 'studio-mac',+ local: true,+ dsh: const [_typst],+ );+ app.machine(+ 'remote',+ online: true,+ dsh: const [+ DshEntry(+ id: 'autonomous/typst',+ name: 'Typst',+ engine: 'claude',+ installed: true,+ ),+ DshEntry(+ id: 'autonomous/marp',+ name: 'Marp',+ engine: 'claude',+ installed: true,+ ),+ ],+ );+ app.machine(+ 'offline',+ online: false,+ dsh: const [+ DshEntry(+ id: 'autonomous/manim',+ name: 'Manim',+ engine: 'claude',+ category: 'Math animation',+ installed: true,+ ),+ ],+ );+ },+ );+ await tester.tap(_key('store-shelf-category:Media'));+ await tester.pumpAndSettle();+ final tabs = app.swarms.length;++ expect(+ _in('store-action:autonomous/typst', find.text('Open')),+ findsOneWidget,+ );+ await tester.tap(_key('store-action:autonomous/typst'));+ await tester.pumpAndSettle();+ expect(find.text('New Harness'), findsOneWidget);+ await tester.sendKeyEvent(LogicalKeyboardKey.escape);+ await tester.pumpAndSettle();+ expect(app.swarms.length, tabs);++ // Installed only on a machine that is offline: nowhere to open it.+ await tester.tap(_key('store-action:autonomous/manim'));+ await tester.pumpAndSettle();+ expect(_key('store-page:autonomous/manim'), findsOneWidget);+ expect(app.swarms.length, tabs);+ },+ );+ });++ testWidgets('without an injected API nothing is asked under test', (+ tester,+ ) async {+ final (app, _) = await _open(tester, injectApi: false);+ expect(app.probes, 0);+ expect(_key('store-card:autonomous/marp'), findsOneWidget);+ });++ testWidgets('a store built and torn down in one frame asks nobody anything', (+ tester,+ ) async {+ final app = _Notifier();+ addTearDown(app.dispose);+ app.machine('machine-1', local: true, dsh: const [_marp]);+ final store = _Store();+ await tester.pumpWidget(+ MaterialApp(+ home: Scaffold(+ body: _WideThenNarrow(+ child: LayoutBuilder(+ builder: (context, box) => box.maxWidth > 400+ ? StoreTab(+ notifier: app,+ api: store,+ initialHarness: 'autonomous/marp',+ )+ : const SizedBox(),+ ),+ ),+ ),+ ),+ );+ await tester.pumpAndSettle();+ expect(find.byType(StoreTab), findsNothing);+ expect(app.probes, 0);+ expect(store.ratingReads, 0);+ expect(store.reviewReads, isEmpty);+ expect(tester.takeException(), isNull);+ });+}++/// The store's calls against a control plane that predates the store: every+/// store route answers 404, through the real envelope unwrap.+class _NotFoundClient extends ApiClient {+ _NotFoundClient() : super(config: AppConfig.dev, session: AuthSession());++ final asked = <String>[];++ Never _notFound(String what) {+ asked.add(what);+ unwrapApiResponse(+ Response(+ requestOptions: RequestOptions(),+ statusCode: 404,+ data: {+ 'success': false,+ 'error': {'message': 'Route not found'},+ },+ ),+ );+ throw StateError('unreachable');+ }++ @override+ Future<Map<String, dynamic>?> storeRatings() async => _notFound('ratings');++ @override+ Future<Map<String, dynamic>?> storeReviews(String harnessId) async =>+ _notFound('reviews');+}++/// Lays its child out twice in its first layout — wide, then narrow — so a+/// [LayoutBuilder] below it mounts a subtree and removes it within one frame,+/// before that frame's post-frame callbacks run. What a window resize across a+/// breakpoint can do to a widget in the frame it was built.+class _WideThenNarrow extends SingleChildRenderObjectWidget {+ const _WideThenNarrow({required super.child});++ @override+ RenderObject createRenderObject(BuildContext context) =>+ _RenderWideThenNarrow();+}++class _RenderWideThenNarrow extends RenderProxyBox {+ bool _first = true;++ @override+ void performLayout() {+ if (_first) {+ _first = false;+ child!.layout(constraints);+ }+ child!.layout(BoxConstraints.loose(Size(100, constraints.maxHeight)));+ size = constraints.biggest;+ }+}diff --git a/desktop/test/store_viewers_test.dart b/desktop/test/store_viewers_test.dartnew file mode 100644index 000000000..79cbebe6b--- /dev/null+++ b/desktop/test/store_viewers_test.dart@@ -0,0 +1,215 @@+// The store's quieter surfaces, as widgets on their own: the Viewers page+// (shared previews and the agents that use them), a listing row for a viewer+// package, and a Discover collection whose harnesses have no artwork.+import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness/core/dsh_catalog.dart';+import 'package:harness/store/store_discover.dart';+import 'package:harness/store/store_editorial.dart';+import 'package:harness/store/store_models.dart';+import 'package:harness/store/store_viewers.dart';+import 'package:harness/widgets/engine_identity.dart';++const _cadViewer = DshEntry(+ id: 'autonomous/cad-viewer',+ name: 'CAD Viewer',+ engine: '',+ kind: 'viewer',+ description: 'STEP, STL and URDF, in a pane.',+);++Future<void> _show(WidgetTester tester, Widget child) =>+ tester.pumpWidget(MaterialApp(home: Scaffold(body: child)));++void main() {+ testWidgets('no viewers: still asking, or asked and none', (tester) async {+ Widget page({required bool loaded}) => StoreViewers(+ viewers: const [],+ agents: const [],+ installedOn: (_) => const [],+ onOpenAgent: (_) {},+ loaded: loaded,+ );+ await _show(tester, page(loaded: false));+ expect(find.text('Asking your machines…'), findsOneWidget);+ await _show(tester, page(loaded: true));+ expect(find.text('No viewers reported by your machines.'), findsOneWidget);+ });++ testWidgets(+ 'a viewer says what it is, where it is, and which agents use it, once each and by name',+ (tester) async {+ final opened = <String>[];+ const docViewer = DshEntry(+ id: 'autonomous/doc-viewer',+ name: 'Doc Viewer',+ engine: '',+ kind: 'viewer',+ );+ await _show(+ tester,+ StoreViewers(+ viewers: const [_cadViewer, docViewer],+ agents: const [+ DshEntry(+ id: 'someone/zeta-arm',+ name: 'Zeta arm',+ engine: 'claude',+ viewerUse: 'autonomous/cad-viewer',+ ),+ DshEntry(+ id: 'autonomous/text-to-cad',+ name: 'text-to-cad',+ engine: 'claude',+ viewerUse: 'autonomous/cad-viewer',+ ),+ // The same agent as another machine reported it.+ DshEntry(+ id: 'autonomous/text-to-cad',+ name: 'text-to-cad',+ engine: 'claude',+ viewerUse: 'autonomous/cad-viewer',+ ),+ // A viewer never uses a viewer.+ DshEntry(+ id: 'autonomous/web-viewer',+ name: 'Web Viewer',+ engine: '',+ kind: 'viewer',+ viewerUse: 'autonomous/cad-viewer',+ ),+ ],+ installedOn: (id) =>+ id == _cadViewer.id ? const ['studio-mac', 'lab-box'] : const [],+ onOpenAgent: opened.add,+ loaded: true,+ ),+ );+ final cad = find.byKey(+ const ValueKey('store-viewer:autonomous/cad-viewer'),+ );+ expect(+ find.descendant(+ of: cad,+ matching: find.text('STEP, STL and URDF, in a pane.'),+ ),+ findsOneWidget,+ );+ expect(+ find.descendant(+ of: cad,+ matching: find.text('Installed on studio-mac, lab-box'),+ ),+ findsOneWidget,+ );+ final users = tester+ .widgetList<TextButton>(+ find.descendant(of: cad, matching: find.byType(TextButton)),+ )+ .map((button) => (button.child! as Text).data)+ .toList();+ expect(users, ['text-to-cad', 'Zeta arm']);+ await tester.tap(+ find.byKey(+ const ValueKey(+ 'store-viewer-agent:autonomous/cad-viewer:someone/zeta-arm',+ ),+ ),+ );+ expect(opened, ['someone/zeta-arm']);++ final doc = find.byKey(+ const ValueKey('store-viewer:autonomous/doc-viewer'),+ );+ expect(+ find.descendant(of: doc, matching: find.text('Not installed')),+ findsOneWidget,+ );+ expect(+ find.descendant(+ of: doc,+ matching: find.text('No agents reported in this catalog.'),+ ),+ findsOneWidget,+ );+ },+ );++ testWidgets('a viewer package in a listing is viewed, never got or opened', (+ tester,+ ) async {+ final opened = <String>[];+ final acted = <String>[];+ await _show(+ tester,+ StoreListing(+ entries: const [_cadViewer],+ ratingFor: (entry) => StoreRating.none(entry.id),+ installed: (_) => true,+ onOpen: opened.add,+ onAction: (entry) => acted.add(entry.id),+ ),+ );+ final action = find.byKey(+ const ValueKey('store-action:autonomous/cad-viewer'),+ );+ expect(+ find.descendant(of: action, matching: find.text('View')),+ findsOneWidget,+ );+ await tester.tap(action);+ expect(opened, ['autonomous/cad-viewer']);+ expect(acted, isEmpty);+ });++ testWidgets(+ 'a collection whose harnesses have no artwork wears the first one\'s mark',+ (tester) async {+ tester.view.devicePixelRatio = 1;+ tester.view.physicalSize = const Size(1200, 1400);+ addTearDown(tester.view.reset);+ StoreCollection? picked;+ await _show(+ tester,+ StoreDiscover(+ entries: const [+ DshEntry(+ id: 'autonomous/strudel',+ name: 'Strudel',+ engine: 'claude',+ category: 'Music',+ ),+ ],+ loaded: true,+ ratingFor: (entry) => StoreRating.none(entry.id),+ installed: (_) => false,+ onOpen: (_) {},+ onAction: (_) {},+ onCollection: (collection) => picked = collection,+ onAll: () {},+ onEngines: () {},+ ),+ );+ final play = find.byKey(const ValueKey('store-collection:play'));+ expect(play, findsOneWidget);+ expect(+ find.descendant(of: play, matching: find.byType(EngineMark)),+ findsOneWidget,+ );+ expect(+ tester+ .widget<EngineMark>(+ find.descendant(of: play, matching: find.byType(EngineMark)),+ )+ .engine,+ 'autonomous/strudel',+ );+ expect(+ find.descendant(of: play, matching: find.text('1 harness to explore')),+ findsOneWidget,+ );+ await tester.tap(play);+ expect(picked?.id, 'play');+ },+ );+}