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
fix(desktop): a Store review posted during a load is read back (#1856)
0xken158cb6e638225f
diff --git a/desktop/lib/store/store_controller.dart b/desktop/lib/store/store_controller.dartindex e5020800b..0a7a0e0e7 100644--- a/desktop/lib/store/store_controller.dart+++ b/desktop/lib/store/store_controller.dart@@ -1,3 +1,5 @@+import 'dart:async';+import 'package:flutter/foundation.dart';import '../api/api_client.dart';@@ -119,19 +121,48 @@ class StoreController extends ChangeNotifier {if (reviewsLoading.contains(harnessId)) return;reviewsLoading.add(harnessId);notifyListeners();+ final done = Completer<void>();+ _reviewsReads[harnessId] = done.future;try {- final page = await api.reviews(harnessId);- reviews[harnessId] = page;- ratings[harnessId] = page.rating;- reviewsError.remove(harnessId);- } catch (error) {- reviewsError[harnessId] = _sentence(error, 'Reviews are not available right now');+ do {+ _readAgain.remove(harnessId);+ try {+ final page = await api.reviews(harnessId);+ // Asked before a write landed: its answer is older than the page.+ if (_readAgain.contains(harnessId)) continue;+ reviews[harnessId] = page;+ ratings[harnessId] = page.rating;+ reviewsError.remove(harnessId);+ } catch (error) {+ reviewsError[harnessId] = _sentence(+ error,+ 'Reviews are not available right now',+ );+ }+ } while (_readAgain.contains(harnessId));} finally {reviewsLoading.remove(harnessId);+ _reviewsReads.remove(harnessId);+ done.complete();notifyListeners();}}+ /// The reads under way, so a write can wait for the one that reads it back.+ final Map<String, Future<void>> _reviewsReads = {};++ /// Pages written to while a read of them was under way: that read goes again.+ final Set<String> _readAgain = {};++ /// Read [harnessId]'s page after a write. A read already under way was asked+ /// before the write, so it reads once more rather than answering for it.+ Future<void> _readBack(String harnessId) {+ final pending = _reviewsReads[harnessId];+ if (pending == null) return loadReviews(harnessId);+ _readAgain.add(harnessId);+ return pending;+ }+/// Write the signed-in person's review. Null on success, else a sentence.Future<String?> submit(String harnessId, {@@ -144,7 +175,7 @@ class StoreController extends ChangeNotifier {} catch (error) {return _sentence(error, 'Your review could not be posted');}- await loadReviews(harnessId);+ await _readBack(harnessId);return null;}@@ -155,7 +186,7 @@ class StoreController extends ChangeNotifier {} catch (error) {return _sentence(error, 'Your review could not be removed');}- await loadReviews(harnessId);+ await _readBack(harnessId);return null;}diff --git a/desktop/test/store_controller_test.dart b/desktop/test/store_controller_test.dartindex e9411727d..c4755845d 100644--- a/desktop/test/store_controller_test.dart+++ b/desktop/test/store_controller_test.dart@@ -2,6 +2,8 @@// 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 'dart:async';+import 'package:dio/dio.dart';import 'package:flutter_test/flutter_test.dart';import 'package:harness/api/api_client.dart';@@ -481,9 +483,67 @@ void main() {'Sign in to see ratings and reviews.',);});++ test('submit re-reads reviews while a load is pending', () async {+ final api = _Held();+ final store = StoreController(api);+ addTearDown(store.dispose);+ final opened = store.loadReviews('autonomous/marp');++ var answered = false;+ final posted = store.submit('autonomous/marp', rating: 5)+ ..then((_) => answered = true);+ await pumpEventQueue();+ // The page's first read was asked before the post, and answers so.+ api.reads.first.complete(api.page());+ await pumpEventQueue();+ expect(api.reads, hasLength(2), reason: 'the post is read back');+ expect(+ store.reviews['autonomous/marp'],+ isNull,+ reason: 'an answer from before the post is dropped',+ );+ expect(answered, isFalse, reason: 'submit waits for the read-back');++ api.reads.last.complete(api.page(mine: api.posted));+ expect(await posted, isNull);+ await opened;+ expect(store.reviews['autonomous/marp']!.mine!.id, 'mine');+ expect(store.reviewsLoading, isEmpty);+ });});}+/// Reviews that land when the test says, to order a read against a write.+class _Held implements StoreApi {+ final reads = <Completer<StoreReviews>>[];+ final posted = StoreReview.fromJson(_review(id: 'mine', mine: true))!;++ StoreReviews page({StoreReview? mine}) => StoreReviews(+ rating: StoreRating.none('autonomous/marp'),+ reviews: [?mine],+ mine: mine,+ );++ @override+ Future<List<StoreRating>> ratings() async => const [];+ @override+ Future<StoreReviews> reviews(String harnessId) {+ reads.add(Completer());+ return reads.last.future;+ }++ @override+ Future<StoreReview> putReview(+ String harnessId, {+ required int rating,+ String? title,+ String? body,+ }) async => posted;+ @override+ Future<void> deleteReview(String harnessId) async {}+}+class _Throwing implements StoreApi {_Throwing(this.error);final Object error;