diff --git a/lib/dev/drive/drive.dart b/lib/dev/drive/drive.dart index 650410f8a..a18fd2c43 100644 --- a/lib/dev/drive/drive.dart +++ b/lib/dev/drive/drive.dart @@ -1269,6 +1269,13 @@ Offset _point(Map step, String key, [int at = 0]) { return Offset(xy[at].toDouble(), xy[at + 1].toDouble()); } +String? _textOf(Widget widget) => switch (widget) { + Text(:final data?) => data, + Text(:final textSpan?) => textSpan.toPlainText(), + RichText(:final text) => text.toPlainText(), + _ => null, + }; + bool _isText(Widget widget, String text) => (widget is Text && (widget.data ?? widget.textSpan?.toPlainText()) == text) || @@ -2273,9 +2280,12 @@ Future _run(Map step) async { } case 'waitText': final gone = step['gone'] == true; + final containing = step['containing'] == true; await _waitFor(() { try { - _centerOf((w) => _isText(w, value as String)); + _centerOf((w) => containing + ? _textOf(w)?.contains(value as String) ?? false + : _isText(w, value as String)); return !gone; } on StateError { return gone; diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index fba1c028d..5c922c38d 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -7137,7 +7137,7 @@ }, "storeBannerHeld": "{strategyName}: {reason}", "@storeBannerHeld": { - "description": "Draft for Dara. Library banner button for a strategy whose work the store holds for the player. {reason} is one of the storeHeld\u2026 phrases.", + "description": "Draft for Dara. Library banner button for a strategy whose work the store holds for the player. {reason} is one of the storeHeld… phrases.", "placeholders": { "strategyName": { "type": "String" @@ -7193,7 +7193,7 @@ } } }, - "storeEditUnsentConflict": "This changed before your change was sent. Yours is still on the page and waits in the sync button.", + "storeEditUnsentConflict": "This changed before your change was sent. Yours is still on the page; the sync button asks whether to send it.", "@storeEditUnsentConflict": { "description": "Draft for Dara. Toast when a change is held before it was sent because a teammate changed the same thing." }, @@ -7222,6 +7222,34 @@ } } }, + "syncButtonPutMineBack": "Put mine back", + "@syncButtonPutMineBack": { + "description": "Draft for Dara. Sync popover button: send the player's held change over the teammate's version the page shows, and draw it." + }, + "syncButtonSendMine": "Send mine", + "@syncButtonSendMine": { + "description": "Draft for Dara. Sync popover button: send the player's unsent change over the teammate's." + }, + "syncButtonGoToPage": "Go to that page", + "@syncButtonGoToPage": { + "description": "Draft for Dara. Sync popover button when the held change is on another page: open that page so the player can see what they are choosing between." + }, + "storeKeepNotYet": "Waiting for the latest version of this page. You can put yours back once it arrives.", + "@storeKeepNotYet": { + "description": "Draft for Dara. Sync popover sentence when Put mine back has to wait for the page's latest version; the button is disabled until it arrives." + }, + "storeKeepNotYetOffline": "Waiting for the connection to come back. You can put yours back once the page's latest version arrives.", + "@storeKeepNotYetOffline": { + "description": "Draft for Dara. Sync popover sentence when Put mine back waits for the page's latest version while offline." + }, + "storeKeepChangedAgain": "It changed again while you were choosing. The page shows the newer version; choose again.", + "@storeKeepChangedAgain": { + "description": "Draft for Dara. Sync popover sentence when a teammate changed the item again after the popover showed it; nothing was written." + }, + "storeHeldOnOtherPage": "It's on another page. Go to that page to choose with it in front of you.", + "@storeHeldOnOtherPage": { + "description": "Draft for Dara. Sync popover sentence when the held change is on a page the player is not looking at." + }, "syncButtonDontSend": "Don't send", "@syncButtonDontSend": { "description": "Draft for Dara. Sync popover button for a change held before it was sent: drop it; the page will show the saved version." @@ -7242,5 +7270,40 @@ "type": "int" } } + }, + "storeHeldChangedAgainAfter": "You changed it again after this. Discard mine gives up both; then make your change again.", + "@storeHeldChangedAgainAfter": { + "description": "Draft for Dara. Sync popover sentence when the player's own later change to the held item is drawn over it, so Put mine back is not offered." + }, + "storeHeldSomeKeepable": "Some of these can be put back and some can't. Discard mine gives up all of them, including the ones you could put back.", + "@storeHeldSomeKeepable": { + "description": "Draft for Dara. Sync popover sentence when only some of the held changes can be put back; Discard mine applies to all of them." + }, + "storeHeldConflictKeepBody": "{count, plural, =1{A teammate changed the same thing first. The page shows their version; yours is kept here. Put yours back to replace theirs, or discard it.} other{A teammate changed the same things first. The page shows their versions; your {count} changes are kept here. Put yours back to replace theirs, or discard them.}}", + "@storeHeldConflictKeepBody": { + "description": "Draft for Dara. Sync popover body for a change a teammate changed first, when Put mine back is offered for it.", + "placeholders": { + "count": { + "type": "int" + } + } + }, + "storeHeldUnsentConflictSendBody": "{count, plural, =1{This changed before yours was sent. The page shows yours; it hasn't been sent. Send yours, or don't send it and the page will show the saved version.} other{This changed before your {count} changes were sent. The page shows yours; they haven't been sent. Send yours, or don't send them and the page will show the saved version.}}", + "@storeHeldUnsentConflictSendBody": { + "description": "Draft for Dara. Sync popover body, when Send mine is offered, for a change held before it was sent because a teammate changed the same thing; the page still shows the player's version.", + "placeholders": { + "count": { + "type": "int" + } + } + }, + "storeHeldPageBackSendBody": "{count, plural, =1{A page you changed was deleted and has come back. Your change on it wasn't sent; it stays on this computer until you send it or discard it. Discard it and the page shows the saved version.} other{A page you changed was deleted and has come back. Your {count} changes on it weren't sent; they stay on this computer until you send them or discard them. Discard them and the page shows the saved version.}}", + "@storeHeldPageBackSendBody": { + "description": "Draft for Dara. Sync popover body for changes on a page that was deleted and has come back, when Send mine is offered for them.", + "placeholders": { + "count": { + "type": "int" + } + } } } diff --git a/lib/l10n/app_ja.arb b/lib/l10n/app_ja.arb index 17a93a078..8c1976615 100644 --- a/lib/l10n/app_ja.arb +++ b/lib/l10n/app_ja.arb @@ -1520,7 +1520,7 @@ "storeHeldWaitingBehindBody": "その後にあなたが加えた変更も待機中で、表示されたままです。破棄すると、それらも破棄されます。", "storeHeldUnsentConflict": "あなたの変更が送信される前にこれが変更されました", "storeHeldUnsentConflictBody": "{count, plural, other{あなたの{count}件の変更が送信される前にこれが変更されました。ページにはあなたの版が表示されていますが、まだ送信されていません。送信しなければ、ページには保存済みの版が表示されます。}}", - "storeEditUnsentConflict": "あなたの変更が送信される前に、これは変更されました。あなたの変更はページに表示されたまま、同期ボタンで待機しています。", + "storeEditUnsentConflict": "あなたの変更が送信される前にこれが変更されました。あなたの版はページに残っています。送信するかどうかは同期ボタンで選べます。", "storeHeldBothConflicts": "あなたの変更の一部はページから外れ、一部はまだページに残っています。選択はすべてに適用されます。", "storeHeldItemGone": "変更したものは削除されたため、あなたの変更は破棄のみ可能です。", "storeUndoHeld": "この変更は同期ボタンで待機しているため、ここでは元に戻せません。同期ボタンで破棄してください。", @@ -1529,5 +1529,17 @@ "syncButtonDontSend": "送信しない", "deletedPageRestoreQueued": "ページを復元しています。このページの変更は同期ボタンで待機しています。", "storeHeldPageBack": "このページが戻りました。変更は送信を待っています", - "storeHeldPageBackBody": "{count, plural, other{変更したページが削除され、その後戻りました。このページの{count}件の変更は送信されておらず、破棄するまでこのPCに残ります。破棄すると、ページには保存された版が表示されます。}}" + "storeHeldPageBackBody": "{count, plural, other{変更したページが削除され、その後戻りました。このページの{count}件の変更は送信されておらず、破棄するまでこのPCに残ります。破棄すると、ページには保存された版が表示されます。}}", + "syncButtonPutMineBack": "自分の変更に戻す", + "syncButtonSendMine": "自分の版を送信", + "syncButtonGoToPage": "そのページに移動", + "storeKeepNotYet": "このページの最新版を待っています。届いたら自分の変更に戻せます。", + "storeKeepNotYetOffline": "接続の回復を待っています。ページの最新版が届いたら自分の変更に戻せます。", + "storeKeepChangedAgain": "選択している間に再び変更されました。ページには新しい版が表示されています。もう一度選んでください。", + "storeHeldOnOtherPage": "別のページにあります。そのページに移動して、見ながら選んでください。", + "storeHeldChangedAgainAfter": "この後でもう一度変更しています。破棄すると両方の変更が破棄されます。その後でもう一度変更してください。", + "storeHeldSomeKeepable": "一部の変更は元に戻せますが、戻せないものもあります。破棄すると、元に戻せた変更も含めてすべて破棄されます。", + "storeHeldConflictKeepBody": "チームメイトが先に同じものを変更しました。ページにはチームメイトの版が表示されています。{count, plural, other{あなたの{count}件の変更}}はここに保管されています。自分の変更に戻すか、破棄してください。", + "storeHeldUnsentConflictSendBody": "{count, plural, other{あなたの{count}件の変更が送信される前にこれが変更されました。ページにはあなたの版が表示されていますが、まだ送信されていません。送信するか、送信しなければページには保存済みの版が表示されます。}}", + "storeHeldPageBackSendBody": "{count, plural, other{変更したページが削除され、その後戻りました。このページの{count}件の変更は送信されておらず、送信するか破棄するまでこのPCに残ります。破棄すると、ページには保存された版が表示されます。}}" } diff --git a/lib/l10n/app_zh.arb b/lib/l10n/app_zh.arb index 25712c8d2..1f815d2fd 100644 --- a/lib/l10n/app_zh.arb +++ b/lib/l10n/app_zh.arb @@ -1520,7 +1520,7 @@ "storeHeldWaitingBehindBody": "你之后对它所做的更改也在等待,并仍然显示。放弃会同时放弃这些更改。", "storeHeldUnsentConflict": "在你的更改发送之前,这里已被修改", "storeHeldUnsentConflictBody": "{count, plural, other{在你的 {count} 项更改发送之前,这里已被修改。页面显示的是你的版本,但尚未发送。不发送的话,页面将显示已保存的版本。}}", - "storeEditUnsentConflict": "在你的更改发送之前,这里已被更改。你的更改仍显示在页面上,并在同步按钮中等待。", + "storeEditUnsentConflict": "在你的更改发送之前,这里已被修改。页面上仍是你的版本,同步按钮会询问是否发送。", "storeHeldBothConflicts": "你的部分更改已不在页面上,部分仍在页面上;你的选择会应用于全部更改。", "storeHeldItemGone": "你更改的内容已被删除,因此你的更改只能放弃。", "storeUndoHeld": "此更改正在同步按钮中等待,因此无法在这里撤销。请在同步按钮中放弃它。", @@ -1529,5 +1529,17 @@ "syncButtonDontSend": "不发送", "deletedPageRestoreQueued": "正在恢复页面。你在其中的更改正在同步按钮中等待。", "storeHeldPageBack": "此页面已恢复,你的更改正在等待发送", - "storeHeldPageBackBody": "{count, plural, other{你更改过的页面曾被删除,现已恢复。你在其中的 {count} 项更改尚未发送,在你丢弃之前会保留在这台电脑上。丢弃后,页面会显示已保存的版本。}}" + "storeHeldPageBackBody": "{count, plural, other{你更改过的页面曾被删除,现已恢复。你在其中的 {count} 项更改尚未发送,在你丢弃之前会保留在这台电脑上。丢弃后,页面会显示已保存的版本。}}", + "syncButtonPutMineBack": "恢复我的更改", + "syncButtonSendMine": "发送我的版本", + "syncButtonGoToPage": "前往该页面", + "storeKeepNotYet": "正在等待此页面的最新版本。收到后即可恢复你的更改。", + "storeKeepNotYetOffline": "正在等待连接恢复。收到页面的最新版本后即可恢复你的更改。", + "storeKeepChangedAgain": "在你选择时它又被修改了。页面显示的是较新的版本,请重新选择。", + "storeHeldOnOtherPage": "它在另一个页面上。前往该页面,对照着内容进行选择。", + "storeHeldChangedAgainAfter": "你在此之后又修改过它。丢弃我的更改会放弃两次更改;之后请重新修改。", + "storeHeldSomeKeepable": "其中一些可以放回,另一些不能。丢弃我的更改会放弃全部更改,包括可以放回的那些。", + "storeHeldConflictKeepBody": "队友先修改了同一内容。页面显示队友的版本,你的{count, plural, other{{count} 项更改}}保存在这里。你可以恢复你的更改来替换队友的版本,或放弃它。", + "storeHeldUnsentConflictSendBody": "{count, plural, other{在你的 {count} 项更改发送之前,这里已被修改。页面显示的是你的版本,但尚未发送。你可以发送,或者不发送,页面将显示已保存的版本。}}", + "storeHeldPageBackSendBody": "{count, plural, other{你更改过的页面曾被删除,现已恢复。你在其中的 {count} 项更改尚未发送,在你发送或丢弃之前会保留在这台电脑上。丢弃后,页面会显示已保存的版本。}}" } diff --git a/lib/providers/collab/cloud_sync_status_provider.dart b/lib/providers/collab/cloud_sync_status_provider.dart index 5308c853c..360d36185 100644 --- a/lib/providers/collab/cloud_sync_status_provider.dart +++ b/lib/providers/collab/cloud_sync_status_provider.dart @@ -10,6 +10,8 @@ import 'package:icarus/providers/collab/cloud_media_upload_queue_provider.dart'; import 'package:icarus/providers/collab/convex_connection_provider.dart'; import 'package:icarus/providers/collab/remote_strategy_snapshot_provider.dart'; import 'package:icarus/providers/collab/strategy_op_queue_provider.dart'; +import 'package:icarus/providers/strategy_page_session_provider.dart' + show strategyPageSessionProvider; import 'package:icarus/providers/strategy_save_state_provider.dart'; import 'package:icarus/providers/strategy_provider.dart'; import 'package:icarus/providers/text_draft_provider.dart'; @@ -254,20 +256,12 @@ final storeWorkPagesProvider = StreamProvider?>( ), ); -final storeHeldGoneProvider = StreamProvider.autoDispose((ref) { - final owned = ref.watch(storeOwnedProvider); - if (owned == null) return Stream.value(false); - return storeFactOf( +final storeHeldGoneProvider = StreamProvider.autoDispose?>( + (ref) => _storeRows( ref, - owned, - () async => - (await heldConflicts(owned.store, owned.strategyId)) - ?.any((conflict) => conflict.itemGone) ?? - false, - same: (before, now) => before == now, - ).values; -}); - + (owned) => heldGone(owned.store, owned.strategyId), + ), +); final storePageBackProvider = StreamProvider((ref) { final owned = ref.watch(storeOwnedProvider); if (owned == null) return Stream.value(0); @@ -413,3 +407,25 @@ final openStrategyUnsentChangesProvider = Provider((ref) { String offlineSyncLabel(AppLocalizations l10n, int waiting) => waiting == 0 ? l10n.syncStatusOfflineNothingWaiting : l10n.syncStatusOfflineChangesSaved(waiting); + +final storeConflictRowsProvider = Provider>((ref) { + final drawn = ref.watch(remoteEditorSnapshotProvider).valueOrNull; + if (drawn == null) return const []; + return conflictRowsAsDrawn( + ref.read(remoteEditorSnapshotProvider.notifier).storeReadOf(drawn), + ref.watch( + strategyPageSessionProvider.select((state) => state.activePageId), + ), + ); +}); + +final storeKeepProvider = + Provider Function(List rows)>( + (ref) => (rows) async { + final owned = ref.read(storeOwnedProvider); + if (owned == null) return const KeepNotSaved('the store owns no strategy'); + return ref.read(storeOwnedProvider.notifier).inTurn( + () => putMineBack(owned.store, owned.reader, owned.strategyId, rows), + ); + }, +); diff --git a/lib/strategy/store_choices.dart b/lib/strategy/store_choices.dart index ee1b7ee1e..46d979ed9 100644 --- a/lib/strategy/store_choices.dart +++ b/lib/strategy/store_choices.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:icarus_library/icarus_library.dart'; +import 'package:uuid/uuid.dart'; sealed class HeldChoice { const HeldChoice(); @@ -63,6 +64,33 @@ typedef HeldConflict = ({PendingOp entry, bool itemGone}); Future?> heldConflicts( LibraryStore store, String strategyId, +) => + _held(store, strategyId, _conflict); + +Future?> heldGone(LibraryStore store, String strategyId) async => + switch (await _held(store, strategyId, _offered)) { + null => null, + final held => { + for (final row in held) + if (row.itemGone) row.entry.id, + }, + }; + +bool _conflict(UserReason reason) => switch (reason) { + ChangedUnseen() || + ChangedSinceDrawn() || + RefusedByServer(refusal: RejectedByServer()) => + true, + _ => false, + }; + +bool _offered(UserReason reason) => + _conflict(reason) || reason is RefusedAsPageDeleted; + +Future?> _held( + LibraryStore store, + String strategyId, + bool Function(UserReason reason) counts, ) async { final StrategyContent content; switch (await store.readStrategy(strategyId)) { @@ -93,16 +121,8 @@ Future?> heldConflicts( final held = []; for (final entry in cloud.queue.entries) { if (entry is! PendingOp) continue; - final conflict = switch (cloud.views[entry.id]?.state) { - NeedsUser( - reason: ChangedUnseen() || - ChangedSinceDrawn() || - RefusedByServer(refusal: RejectedByServer()) - ) => - true, - _ => false, - }; - if (!conflict) continue; + final state = cloud.views[entry.id]?.state; + if (state is! NeedsUser || !counts(state.reason)) continue; for (final pageId in pagesNeeded(entry.op)) { if (read.add(pageId)) await readRows(pageId); } @@ -315,3 +335,284 @@ Future discardPageBack( back.length, ); } + +enum HeldKind { conflict, unsentConflict, pageBack } + +typedef ConflictRow = ({ + String opId, + String? pageId, + bool onScreen, + HeldKind kind, + bool coveredByMine, + Version? shown, +}); + +List conflictRowsAsDrawn( + StrategyRead? drawn, + String? activePageId, +) { + if (drawn + case StrategyContent( + :final pages, + sync: CloudStrategy(:final queue, :final views), + )) { + final entries = queue.entries.toList(growable: false); + bool coveredAfter(int index, PendingOp held) => [ + for (final later in entries.skip(index + 1)) + if (later case final PendingOp mine + when targetOf(mine.op) == targetOf(held.op) && + views[mine.id]?.state is! NeedsUser) + mine, + ].isNotEmpty; + bool live(String pageId) => + pages.any((page) => page.publicId == pageId && page is! TrashedPage); + return [ + for (final (index, entry) in entries.indexed) + if (entry case final PendingOp pending) + if (views[pending.id]?.state case NeedsUser(:final reason) + when switch (reason) { + ChangedUnseen() || + ChangedSinceDrawn() || + RefusedByServer(refusal: RejectedByServer()) => + true, + RefusedAsPageDeleted() => pagesNeeded(pending.op).isNotEmpty && + pagesNeeded(pending.op).every(live), + _ => false, + }) + ( + opId: pending.id, + pageId: pagesNeeded(pending.op).firstOrNull, + onScreen: pagesNeeded(pending.op).isEmpty || + pagesNeeded(pending.op).contains(activePageId), + kind: switch (reason) { + ChangedUnseen() => HeldKind.unsentConflict, + RefusedAsPageDeleted() => HeldKind.pageBack, + _ => HeldKind.conflict, + }, + coveredByMine: coveredAfter(index, pending), + shown: serverVersionAsDrawn(queue, targetOf(pending.op)), + ), + ]; + } + return const []; +} + +List keepableRows( + List rows, { + Set gone = const {}, +}) => + [ + for (final row in rows) + if (row.onScreen && !row.coveredByMine && !gone.contains(row.opId)) row, + ]; + +enum LastKeepAnswer { none, notYet, notYetOffline, changedAgain, gone } + +final class KeepChoice { + const KeepChoice(this.rows, {this.lastAnswer = LastKeepAnswer.none}); + + final List rows; + final LastKeepAnswer lastAnswer; + + bool get waitsForRead => + lastAnswer == LastKeepAnswer.notYet || + lastAnswer == LastKeepAnswer.notYetOffline; + + bool shows(List drawn) => + drawn.length == rows.length && + [ + for (final (index, row) in rows.indexed) row == drawn[index], + ].every((same) => same); + + KeepChoice answered(KeepOutcome outcome, {required bool connected}) => + switch (outcome) { + KeepNotYet() => KeepChoice( + rows, + lastAnswer: connected + ? LastKeepAnswer.notYet + : LastKeepAnswer.notYetOffline, + ), + KeepChangedAgain() => + KeepChoice(rows, lastAnswer: LastKeepAnswer.changedAgain), + KeepGone() => KeepChoice(rows, lastAnswer: LastKeepAnswer.gone), + Kept() || KeepNotSaved() || KeepOutOfScope() || KeepInDoubt() => this, + }; +} + +enum KeepButton { none, putMineBack, sendMine } + +enum KeepNote { + itemGone, + changedAgainAfter, + someKeepable, + onOtherPage, + notYet, + notYetOffline, + changedAgain, +} + +typedef KeepOffer = ({ + List rows, + Set kinds, + KeepButton button, + bool enabled, + String? goToPage, + List notes, +}); + +KeepOffer keepOfferOf(KeepChoice choice, Set gone) { + final rows = choice.rows; + final keepable = choice.lastAnswer == LastKeepAnswer.gone + ? const [] + : keepableRows(rows, gone: gone); + final offScreen = rows.where((row) => !row.onScreen).firstOrNull; + return ( + rows: keepable, + kinds: {for (final row in keepable) row.kind}, + button: switch (keepable) { + [] => KeepButton.none, + _ when keepable.any((row) => row.kind == HeldKind.conflict) => + KeepButton.putMineBack, + _ => KeepButton.sendMine, + }, + enabled: !choice.waitsForRead, + goToPage: offScreen?.pageId, + notes: [ + if (rows.any((row) => gone.contains(row.opId)) || + choice.lastAnswer == LastKeepAnswer.gone) + KeepNote.itemGone, + if (rows.any((row) => row.onScreen && row.coveredByMine)) + KeepNote.changedAgainAfter, + if (keepable.isNotEmpty && keepable.length < rows.length) + KeepNote.someKeepable, + if (offScreen != null) KeepNote.onOtherPage, + ...switch (choice.lastAnswer) { + LastKeepAnswer.notYet => [KeepNote.notYet], + LastKeepAnswer.notYetOffline => [KeepNote.notYetOffline], + LastKeepAnswer.changedAgain => [KeepNote.changedAgain], + LastKeepAnswer.gone || LastKeepAnswer.none => const [], + }, + ], + ); +} + +sealed class KeepOutcome { + const KeepOutcome(); +} + +final class Kept extends KeepOutcome { + const Kept(); +} + +final class KeepNotYet extends KeepOutcome { + const KeepNotYet(); +} + +final class KeepChangedAgain extends KeepOutcome { + const KeepChangedAgain(); +} + +final class KeepGone extends KeepOutcome { + const KeepGone(); +} + +final class KeepNotSaved extends KeepOutcome { + const KeepNotSaved(this.why); + + final String why; +} + +final class KeepOutOfScope extends KeepOutcome { + const KeepOutOfScope(this.why); + + final String why; +} + +final class KeepInDoubt extends KeepOutcome { + const KeepInDoubt(); +} + +Future putMineBack( + LibraryStore store, + Account reader, + String strategyId, + List rows, +) async { + final cloud = switch (await store.readStrategy(strategyId)) { + Found(value: StrategyContent(sync: final CloudStrategy cloud)) => cloud, + _ => null, + }; + if (cloud == null) return const KeepNotSaved('the strategy is not stored'); + final events = []; + for (final row in rows) { + if (!row.onScreen) continue; + final entry = cloud.queue.entry(row.opId); + if (entry is! PendingOp) return const KeepChangedAgain(); + if (cloud.views[entry.id]?.state + case NeedsUser(reason: RefusedAsPageDeleted()) + when !readSinceRefusal(cloud.queue, entry)) { + return const KeepNotYet(); + } + events.add(UserKeptMine( + row.opId, + renamed(entry.op, const Uuid().v4()), + authored: const AuthoredNoRow(), + shownVersion: row.shown, + )); + } + if (events.isEmpty) return const KeepNotSaved('nothing held is on screen'); + return switch (await store.record(reader, strategyId, events)) { + Saved(:final value) => _keepOutcomeOf([ + for (final outcome in value.outcomes) + if (outcome case ReportNotApplicable(:final why)) why, + ]), + NothingToSave() => const KeepNotSaved('nothing to save'), + Refused(:final reason) => KeepNotSaved('$reason'), + NotSaved(:final failure) => KeepNotSaved('$failure'), + SaveInDoubt() => const KeepInDoubt(), + }; +} + +KeepOutcome _keepOutcomeOf(List why) { + final outcomes = why.map(_keepOutcomeOfOne).toList(); + for (final first in [ + (KeepOutcome outcome) => outcome is KeepOutOfScope, + (KeepOutcome outcome) => outcome is KeepGone, + (KeepOutcome outcome) => outcome is KeepChangedAgain, + (KeepOutcome outcome) => outcome is KeepNotYet, + (KeepOutcome outcome) => outcome is KeepNotSaved, + ]) { + if (outcomes.where(first).firstOrNull case final outcome?) return outcome; + } + return const Kept(); +} + +KeepOutcome _keepOutcomeOfOne(Inapplicable why) => switch (why) { + RowNotReadYet() => const KeepNotYet(), + RowChangedAgain() => const KeepChangedAgain(), + RowGone() => const KeepGone(), + ReplacementOutOfScope() => KeepOutOfScope('$why'), + NoSuchOp() || + NotInThatState() || + HeldBack() || + NoSuchAttempt() || + NotInAttempt() || + NotOfAnotherLife() || + OpIdTaken() || + AlreadyHeld() || + NotJson() || + StandingBlocks() || + OutOfOrder() || + OtherClient() || + OtherEntity() || + PageBeingRestored() || + StartedInAnotherLife() || + OlderResult() || + SameResult() || + AnswerAlreadyHandled() || + NothingSetAsideToDiscard() || + NothingClaimed() || + ConnectionAlreadyEnded() || + FromAnEndedSession() => + KeepNotSaved('$why'), + }; diff --git a/lib/widgets/cloud_sync_button.dart b/lib/widgets/cloud_sync_button.dart index 7cd5d2c7d..3f6366722 100644 --- a/lib/widgets/cloud_sync_button.dart +++ b/lib/widgets/cloud_sync_button.dart @@ -25,7 +25,10 @@ import 'package:icarus/providers/strategy_provider.dart'; import 'package:icarus/providers/strategy_save_state_provider.dart'; import 'package:icarus/strategy/lineup_group_changes.dart'; import 'package:icarus/strategy/strategy_page_models.dart'; +import 'package:icarus/const/transition_data.dart'; +import 'package:icarus/providers/collab/convex_connection_provider.dart'; import 'package:icarus/strategy/store_choices.dart'; +import 'package:icarus/services/app_error_reporter.dart'; import 'package:icarus/strategy/store_save_facts.dart'; import 'package:icarus/strategy/strategy_page_source.dart' show storeOwnedProvider; @@ -147,8 +150,12 @@ class _CloudSyncButtonState extends ConsumerState { ref.read(strategyConflictProvider.notifier).clearAll(); } + List _drawnRows = const []; + KeepChoice? _choice; + Future _handlePressed(_SyncStatus status) async { if (status == _SyncStatus.attention) { + _choice = _popoverController.isOpen ? null : KeepChoice(_drawnRows); _popoverController.toggle(); return; } @@ -181,6 +188,49 @@ class _CloudSyncButtonState extends ConsumerState { } } + Future _keep(List rows) async { + if (_isResolving || + !(_choice?.shows(ref.read(storeConflictRowsProvider)) ?? false)) { + return; + } + final connected = ref.read(convexConnectionSnapshotProvider); + setState(() { + _isResolving = true; + _resolutionError = null; + }); + KeepOutcome kept = const KeepInDoubt(); + try { + kept = await ref.read(storeKeepProvider)(rows); + } finally { + if (mounted) _keepAnswered(kept, connected); + } + } + + void _keepAnswered(KeepOutcome kept, bool? connected) { + final l10n = context.l10n; + if (kept case KeepOutOfScope(:final why)) { + AppErrorReporter.reportWarning( + 'Put mine back built a change for another page: $why', + source: 'cloud_sync_button:keep', + ); + } + setState(() { + _isResolving = false; + _choice = (_choice ?? KeepChoice(_drawnRows)) + .answered(kept, connected: connected ?? false); + switch (kept) { + case Kept(): + _popoverController.hide(); + case KeepNotSaved() || KeepOutOfScope(): + _resolutionError = l10n.storeChoiceFailed; + case KeepInDoubt(): + _resolutionError = l10n.storeChoiceInDoubt; + case KeepNotYet() || KeepChangedAgain() || KeepGone(): + break; + } + }); + } + Future _storeChoice( Future Function( LibraryStore store, @@ -408,6 +458,13 @@ class _CloudSyncButtonState extends ConsumerState { shownPageListeningProvider.select((listening) => listening.onChip), ); final storeFace = ref.watch(storeSyncFaceProvider); + ref.listen(storeConflictRowsProvider, (_, next) { + if (_choice case final choice? when !choice.shows(next)) { + _popoverController.hide(); + setState(() => _choice = null); + } + }); + final conflictRows = _drawnRows = ref.watch(storeConflictRowsProvider); ref.watch(storeUndoBlockedProvider); ref.watch(storeWorkPagesProvider); final syncTooltip = storeFace != null @@ -474,9 +531,22 @@ class _CloudSyncButtonState extends ConsumerState { resolutionError: _resolutionError, onRetry: _retry, onRetryPictures: _retryPictures, - heldGone: ref.watch(storeHeldGoneProvider).valueOrNull ?? false, onDiscardMine: () => _storeChoice(discardMine), onDiscardPageBack: () => _storeChoice(discardPageBack), + offer: keepOfferOf( + _choice ?? KeepChoice(conflictRows), + ref.watch(storeHeldGoneProvider).valueOrNull ?? const {}, + ), + onKeep: (rows) => _keep(rows), + onGoToPage: (pageId) { + _popoverController.hide(); + unawaited(ref + .read(strategyPageSessionProvider.notifier) + .setActivePageAnimated( + pageId, + direction: PageTransitionDirection.forward, + )); + }, onUseCloudVersions: _useCloudVersions, onKeepBoth: _keepBoth, onKeepHeldPages: () => _keepHeldPages(heldDeletes), @@ -653,9 +723,11 @@ class _SyncStatusPopover extends StatelessWidget { required this.resolutionError, required this.onRetry, required this.onRetryPictures, - required this.heldGone, required this.onDiscardMine, required this.onDiscardPageBack, + required this.offer, + required this.onKeep, + required this.onGoToPage, required this.onUseCloudVersions, required this.onKeepBoth, required this.onKeepHeldPages, @@ -699,9 +771,11 @@ class _SyncStatusPopover extends StatelessWidget { final String? resolutionError; final Future Function() onRetry; final Future Function() onRetryPictures; - final bool heldGone; final Future Function() onDiscardMine; final Future Function() onDiscardPageBack; + final KeepOffer offer; + final Future Function(List rows) onKeep; + final void Function(String pageId) onGoToPage; final Future Function() onUseCloudVersions; final Future Function() onKeepBoth; final Future Function() onKeepHeldPages; @@ -780,11 +854,24 @@ class _SyncStatusPopover extends StatelessWidget { context, explanation: switch (face) { HeldForYou(:final held) => [ - storeSyncExplanation(l10n, face), + storeSyncExplanation( + l10n, + face, + offered: offer.kinds, + ), if (held.containsKey(HeldFor.conflict) && held.containsKey(HeldFor.unsentConflict)) l10n.storeHeldBothConflicts, - if (heldGone) l10n.storeHeldItemGone, + for (final note in offer.notes) + switch (note) { + KeepNote.itemGone => l10n.storeHeldItemGone, + KeepNote.changedAgainAfter => l10n.storeHeldChangedAgainAfter, + KeepNote.someKeepable => l10n.storeHeldSomeKeepable, + KeepNote.onOtherPage => l10n.storeHeldOnOtherPage, + KeepNote.notYet => l10n.storeKeepNotYet, + KeepNote.notYetOffline => l10n.storeKeepNotYetOffline, + KeepNote.changedAgain => l10n.storeKeepChangedAgain, + }, ].join(l10n.commonSentenceSpace), _ => storeSyncExplanation(l10n, face), }, @@ -819,6 +906,27 @@ class _SyncStatusPopover extends StatelessWidget { child: Text(l10n.syncButtonRetrySync), ), }, + if (offer.goToPage case final pageId?) + ShadButton( + size: ShadButtonSize.sm, + expands: false, + onPressed: isResolving ? null : () => onGoToPage(pageId), + child: Text(l10n.syncButtonGoToPage), + ), + if (offer.button != KeepButton.none) + ShadButton( + size: ShadButtonSize.sm, + expands: false, + onPressed: isResolving || !offer.enabled + ? null + : () => onKeep(offer.rows), + child: Text(switch (offer.button) { + KeepButton.putMineBack => l10n.syncButtonPutMineBack, + KeepButton.sendMine || + KeepButton.none => + l10n.syncButtonSendMine, + }), + ), ], ), _ => null, diff --git a/lib/widgets/store_sync_words.dart b/lib/widgets/store_sync_words.dart index 4f55ce168..51b6e22ab 100644 --- a/lib/widgets/store_sync_words.dart +++ b/lib/widgets/store_sync_words.dart @@ -1,6 +1,7 @@ import 'package:icarus/l10n/l10n.dart'; import 'package:icarus/strategy/store_save_facts.dart'; import 'package:icarus/strategy/store_sync_face.dart'; +import 'package:icarus/strategy/store_choices.dart' show HeldKind; String heldReasonWords(AppLocalizations l10n, HeldFor why) => switch (why) { HeldFor.notConfirmedHere => l10n.storeHeldNotConfirmed, @@ -24,7 +25,13 @@ String heldReasonWords(AppLocalizations l10n, HeldFor why) => switch (why) { HeldFor.elsewhere => l10n.storeHeldElsewhere, }; -String heldBody(AppLocalizations l10n, HeldFor why, int count) => switch (why) { +String heldBody( + AppLocalizations l10n, + HeldFor why, + int count, { + Set offered = const {}, +}) => + switch (why) { HeldFor.notConfirmedHere => l10n.storeHeldNotConfirmedBody, HeldFor.unreadable => l10n.storeHeldUnreadableBody, HeldFor.upgradeRequired => l10n.storeHeldUpgradeBody, @@ -34,10 +41,16 @@ String heldBody(AppLocalizations l10n, HeldFor why, int count) => switch (why) { HeldFor.replaced => l10n.storeHeldReplacedBody(count), HeldFor.otherAccount => l10n.storeHeldOtherAccountBody, HeldFor.pageDeleted => l10n.storeHeldPageDeletedBody(count), - HeldFor.pageBack => l10n.storeHeldPageBackBody(count), + HeldFor.pageBack => offered.contains(HeldKind.pageBack) + ? l10n.storeHeldPageBackSendBody(count) + : l10n.storeHeldPageBackBody(count), HeldFor.pageDeleteWaits => l10n.storeHeldPageDeleteWaitsBody, - HeldFor.conflict => l10n.storeHeldConflictBody(count), - HeldFor.unsentConflict => l10n.storeHeldUnsentConflictBody(count), + HeldFor.conflict => offered.contains(HeldKind.conflict) + ? l10n.storeHeldConflictKeepBody(count) + : l10n.storeHeldConflictBody(count), + HeldFor.unsentConflict => offered.contains(HeldKind.unsentConflict) + ? l10n.storeHeldUnsentConflictSendBody(count) + : l10n.storeHeldUnsentConflictBody(count), HeldFor.refused => l10n.storeHeldRefusedBody(count), HeldFor.cannotTell => l10n.storeHeldCannotTellBody(count), HeldFor.waitingBehind => l10n.storeHeldWaitingBehindBody, @@ -46,7 +59,11 @@ String heldBody(AppLocalizations l10n, HeldFor why, int count) => switch (why) { HeldFor.elsewhere => l10n.syncButtonOtherStrategyNeedsAttention, }; -String storeSyncExplanation(AppLocalizations l10n, StoreSyncFace face) => +String storeSyncExplanation( + AppLocalizations l10n, + StoreSyncFace face, { + Set offered = const {}, +}) => switch (face) { AllOnServer() => l10n.syncButtonSyncedExplanation, StillTyping() => l10n.syncButtonEditingExplanation, @@ -58,6 +75,6 @@ String storeSyncExplanation(AppLocalizations l10n, StoreSyncFace face) => SavingStopped() => l10n.storeSavingStoppedBody, HeldForYou(:final held) => [ for (final MapEntry(key: why, value: count) in held.entries) - heldBody(l10n, why, count), + heldBody(l10n, why, count, offered: offered), ].join(l10n.commonSentenceSpace), }; diff --git a/packages/icarus_library/lib/icarus_library.dart b/packages/icarus_library/lib/icarus_library.dart index 186336414..5d20aac44 100644 --- a/packages/icarus_library/lib/icarus_library.dart +++ b/packages/icarus_library/lib/icarus_library.dart @@ -93,6 +93,7 @@ export 'src/cloud/op_facts.dart' sendForm, expectedOf, pagesNeeded, + renamed, checkKindOf, CheckKind, entityOf, diff --git a/packages/icarus_library/test/cloud_keep_mine_base_test.dart b/packages/icarus_library/test/cloud_keep_mine_base_test.dart index 172fb6e22..d1fea1f69 100644 --- a/packages/icarus_library/test/cloud_keep_mine_base_test.dart +++ b/packages/icarus_library/test/cloud_keep_mine_base_test.dart @@ -1,5 +1,4 @@ import 'package:icarus_library/icarus_library.dart'; -import 'package:icarus_library/src/cloud/op_facts.dart' show renamed; import 'package:test/test.dart'; import 'cloud_server.dart'; diff --git a/packages/icarus_library/test/cloud_moved_off_gone_page_test.dart b/packages/icarus_library/test/cloud_moved_off_gone_page_test.dart index be074487c..5ad4a4a59 100644 --- a/packages/icarus_library/test/cloud_moved_off_gone_page_test.dart +++ b/packages/icarus_library/test/cloud_moved_off_gone_page_test.dart @@ -1,5 +1,4 @@ import 'package:icarus_library/icarus_library.dart'; -import 'package:icarus_library/src/cloud/op_facts.dart' show renamed; import 'package:test/test.dart'; import 'cloud_live_basis_test.dart' show claimAt, heldAt, hold, quietClient; diff --git a/packages/icarus_library/test/cloud_page_deleted_refusal_test.dart b/packages/icarus_library/test/cloud_page_deleted_refusal_test.dart index 65e29954b..506eb75e1 100644 --- a/packages/icarus_library/test/cloud_page_deleted_refusal_test.dart +++ b/packages/icarus_library/test/cloud_page_deleted_refusal_test.dart @@ -1,5 +1,4 @@ import 'package:icarus_library/icarus_library.dart'; -import 'package:icarus_library/src/cloud/op_facts.dart' show renamed; import 'package:test/test.dart'; import 'cloud_server.dart'; diff --git a/test/library_store/store_keep_offer_test.dart b/test/library_store/store_keep_offer_test.dart new file mode 100644 index 000000000..5fbfbaeaf --- /dev/null +++ b/test/library_store/store_keep_offer_test.dart @@ -0,0 +1,223 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:icarus/strategy/store_choices.dart'; +import 'package:icarus_library/icarus_library.dart' show Version; + +ConflictRow _row( + String opId, { + HeldKind kind = HeldKind.conflict, + bool onScreen = true, + bool covered = false, + String pageId = 'p1', + Version? shown, +}) => + ( + opId: opId, + pageId: pageId, + onScreen: onScreen, + kind: kind, + coveredByMine: covered, + shown: shown, + ); + +KeepChoice _opened(List rows, [LastKeepAnswer? answer]) => + KeepChoice(rows, lastAnswer: answer ?? LastKeepAnswer.none); + +void main() { + test('what the popover offers for each held change and each last answer', () { + for (final (name, choice, gone, button, kinds, enabled, goTo, notes) in [ + ( + 'a conflict on screen', + _opened([_row('a')]), + {}, + KeepButton.putMineBack, + {HeldKind.conflict}, + true, + null, + [], + ), + ( + 'a conflict on another page', + _opened([_row('a', onScreen: false, pageId: 'p2')]), + {}, + KeepButton.none, + {}, + true, + 'p2', + [KeepNote.onOtherPage], + ), + ( + 'a conflict my later change is drawn over', + _opened([_row('a', covered: true)]), + {}, + KeepButton.none, + {}, + true, + null, + [KeepNote.changedAgainAfter], + ), + ( + 'a conflict whose item is gone', + _opened([_row('a')]), + {'a'}, + KeepButton.none, + {}, + true, + null, + [KeepNote.itemGone], + ), + ( + 'a change that changed before it was sent', + _opened([_row('a', kind: HeldKind.unsentConflict)]), + {}, + KeepButton.sendMine, + {HeldKind.unsentConflict}, + true, + null, + [], + ), + ( + 'a change on a page that came back', + _opened([_row('a', kind: HeldKind.pageBack)]), + {}, + KeepButton.sendMine, + {HeldKind.pageBack}, + true, + null, + [], + ), + ( + 'one gone and one live', + _opened([_row('a'), _row('b')]), + {'a'}, + KeepButton.putMineBack, + {HeldKind.conflict}, + true, + null, + [KeepNote.itemGone, KeepNote.someKeepable], + ), + ( + 'a conflict on screen and an unsent change on another page', + _opened([ + _row('a'), + _row('b', + kind: HeldKind.unsentConflict, onScreen: false, pageId: 'p2'), + ]), + {}, + KeepButton.putMineBack, + {HeldKind.conflict}, + true, + 'p2', + [KeepNote.someKeepable, KeepNote.onOtherPage], + ), + ( + 'a conflict and an unsent change on screen: the stronger label', + _opened([_row('a'), _row('b', kind: HeldKind.unsentConflict)]), + {}, + KeepButton.putMineBack, + {HeldKind.conflict, HeldKind.unsentConflict}, + true, + null, + [], + ), + ( + 'a page-back change and an unsent change: Send mine', + _opened([ + _row('a', kind: HeldKind.pageBack), + _row('b', kind: HeldKind.unsentConflict), + ]), + {}, + KeepButton.sendMine, + {HeldKind.pageBack, HeldKind.unsentConflict}, + true, + null, + [], + ), + ( + 'waiting for the read', + _opened([_row('a')], LastKeepAnswer.notYet), + {}, + KeepButton.putMineBack, + {HeldKind.conflict}, + false, + null, + [KeepNote.notYet], + ), + ( + 'waiting for the connection', + _opened([_row('a')], LastKeepAnswer.notYetOffline), + {}, + KeepButton.putMineBack, + {HeldKind.conflict}, + false, + null, + [KeepNote.notYetOffline], + ), + ( + 'changed again while choosing', + _opened([_row('a')], LastKeepAnswer.changedAgain), + {}, + KeepButton.putMineBack, + {HeldKind.conflict}, + true, + null, + [KeepNote.changedAgain], + ), + ( + 'answered gone, though the gone set does not say so: only the discard', + _opened([_row('a')], LastKeepAnswer.gone), + {}, + KeepButton.none, + {}, + true, + null, + [KeepNote.itemGone], + ), + ]) { + final offer = keepOfferOf(choice, gone); + expect(offer.button, button, reason: name); + expect(offer.kinds, kinds, reason: name); + expect(offer.enabled, enabled, reason: name); + expect(offer.goToPage, goTo, reason: name); + expect(offer.notes, notes, reason: name); + } + }); + + test( + 'the popover still shows the rows it opened with only while the rows ' + 'drawn now are the same', () { + final opened = [_row('a', shown: const Version(1))]; + final choice = _opened(opened, LastKeepAnswer.notYet); + for (final (name, drawn, shows) in [ + ( + 'nothing about the rows changed', + [_row('a', shown: const Version(1))], + true, + ), + ( + 'the page was switched', + [_row('a', onScreen: false, shown: const Version(1))], + false, + ), + ( + 'the item was edited again', + [_row('a', covered: true, shown: const Version(1))], + false, + ), + ( + 'a teammate changed it again, or the read after not yet arrived', + [_row('a', shown: const Version(2))], + false, + ), + ( + 'a page was restored with a held change on it', + [ + _row('a', shown: const Version(1)), + _row('b', kind: HeldKind.pageBack), + ], + false, + ), + ]) { + expect(choice.shows(drawn), shows, reason: name); + } + }); +} diff --git a/test/library_store/store_keep_test.dart b/test/library_store/store_keep_test.dart new file mode 100644 index 000000000..fa1b8a207 --- /dev/null +++ b/test/library_store/store_keep_test.dart @@ -0,0 +1,222 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:icarus/strategy/store_choices.dart'; +import 'package:icarus_library/icarus_library.dart'; + +import 'live_pages.dart' show deliver; +import 'sender_world.dart'; +import 'server_fixtures.dart' show pageId, servedAccount, strategyId; + +void main() { + test( + 'Put mine back is not offered over a version the player never saw: ' + 'their own later change is drawn over the item', () { + inWorld((world) { + world.settle(); + world.sender.hold('the first move waits'); + world.commitMove(1); + world.teammateMoves(1); + world.sender.release(); + world.settle(const Duration(seconds: 30)); + world.commitMove(2); + world.teammateMoves(2); + deliver(world); + world.settle(const Duration(seconds: 30)); + final element = world.firstElement().publicId; + final teammates = + world.server.rows[strategyId]!.element(element)! as LiveElement; + + final rows = conflictRowsAsDrawn(world.seenNow(), null); + expect( + rows + .where((row) => row.opId == 'move-1') + .map((row) => row.coveredByMine), + [isTrue], + ); + final offered = keepableRows(rows); + if (offered.isNotEmpty) { + putMineBack(world.store, servedAccount, strategyId, offered); + world.settle(const Duration(seconds: 30)); + } + + expect( + (world.server.rows[strategyId]!.element(element)! as LiveElement) + .payload + .data + .toJson()['position'], + teammates.payload.data.toJson()['position'], + ); + expect(offered, isEmpty); + }); + }); + + ConflictRow row(String opId, {bool covered = false, Version? shown}) => ( + opId: opId, + pageId: 'p1', + onScreen: true, + kind: HeldKind.conflict, + coveredByMine: covered, + shown: shown, + ); + + test( + '"not yet" leaves the button waiting until the read changes the rows, ' + 'which closes the popover; reopened, it offers the version that read drew', + () { + final open = [row('held', shown: const Version(1))]; + final read = [row('held', shown: const Version(2))]; + final choice = + KeepChoice(open).answered(const KeepNotYet(), connected: true); + expect(keepOfferOf(choice, const {}).enabled, isFalse); + expect(choice.shows(open), isTrue); + expect(choice.shows(read), isFalse); + + final reopened = keepOfferOf(KeepChoice(read), const {}); + expect(reopened.enabled, isTrue); + expect(reopened.rows.single.shown, const Version(2)); + }); + + test( + 'a held change whose item is gone is offered only the discard; the ' + 'other held change on the page keeps Put mine back', () { + final rows = [row('gone-item'), row('live-item')]; + expect( + keepableRows(rows, gone: {'gone-item'}).map((each) => each.opId), + ['live-item'], + ); + expect(keepableRows([row('mine-over', covered: true)]), isEmpty); + }); + + test( + 'after the read the waiting press was missing, Put mine back lands with ' + 'the version that read drew', () { + inWorld((world) { + world.settle(); + world.sender.hold('the move waits'); + world.commitMove(1); + world.teammateMoves(1); + world.sender.release(); + world.settle(const Duration(seconds: 30)); + final open = conflictRowsAsDrawn(world.seenNow(), null); + final choice = + KeepChoice(open).answered(const KeepNotYet(), connected: true); + expect(keepOfferOf(choice, const {}).rows, isNotEmpty); + expect(choice.waitsForRead, isTrue); + + deliver(world); + final drawn = conflictRowsAsDrawn(world.seenNow(), null); + expect(choice.shows(drawn), isFalse); + + KeepOutcome? kept; + putMineBack( + world.store, + servedAccount, + strategyId, + keepOfferOf(KeepChoice(drawn), const {}).rows, + ).then((value) => kept = value); + world.settle(const Duration(seconds: 30)); + expect(kept, isA()); + final element = world.firstElement().publicId; + expect( + (world.server.rows[strategyId]!.element(element)! as LiveElement) + .payload + .data + .toJson()['position'], + {'dx': 101, 'dy': 51}, + ); + }); + }); + + test( + 'Send for a change on a page that came back writes nothing until the ' + 'page is read since the refusal, and says it waits for that read', () { + inWorld((world) { + world.sender.hold('the move waits'); + final element = world.firstElement(); + final move = World.moveOf(element, 1, 'move-1'); + world.commit([ + ElementPatchOp( + opId: move.opId, + elementPublicId: move.elementPublicId, + pagePublicId: pageId, + expectedElementRevision: move.expectedElementRevision, + payload: move.payload, + ), + ]); + world.secondPageOnServer(); + world.server.teammate( + strategyId, + PageDeleteOp( + opId: 'teammate-deletes', + pagePublicId: pageId, + expectedStrategyRevision: + world.server.rows[strategyId]!.strategy.revision, + ), + ); + world.sender.release(); + world.settle(const Duration(seconds: 30)); + + var changes = 0; + final counting = world.store.changes.listen((_) => changes++); + KeepOutcome? outcome; + putMineBack(world.store, servedAccount, strategyId, [ + ( + opId: move.opId, + pageId: pageId, + onScreen: true, + kind: HeldKind.pageBack, + coveredByMine: false, + shown: Version(element.revision), + ), + ]).then((value) => outcome = value); + world.settle(); + counting.cancel(); + + expect(outcome, isA()); + expect(changes, 0); + }); + }); + + test( + 'a keep answered changed again closes the popover once the newer ' + 'version is drawn, and the keep from the reopened popover goes through ' + 'with it', () { + inWorld((world) { + world.settle(); + world.sender.hold('the move waits'); + world.commitMove(1); + world.teammateMoves(1); + world.sender.release(); + world.settle(const Duration(seconds: 30)); + deliver(world); + final open = conflictRowsAsDrawn(world.seenNow(), null); + world.teammateMoves(2); + deliver(world); + + KeepOutcome? first; + putMineBack( + world.store, + servedAccount, + strategyId, + keepOfferOf(KeepChoice(open), const {}).rows, + ).then((value) => first = value); + world.settle(const Duration(seconds: 30)); + expect(first, isA()); + + final drawn = conflictRowsAsDrawn(world.seenNow(), null); + expect( + KeepChoice(open).answered(first!, connected: true).shows(drawn), + isFalse, + ); + + KeepOutcome? again; + putMineBack( + world.store, + servedAccount, + strategyId, + keepOfferOf(KeepChoice(drawn), const {}).rows, + ).then((value) => again = value); + world.settle(const Duration(seconds: 30)); + expect(again, isA()); + }); + }); +} diff --git a/test/widgets/cloud_sync_button_test.dart b/test/widgets/cloud_sync_button_test.dart index 6440cd9f7..1dd3ac9b6 100644 --- a/test/widgets/cloud_sync_button_test.dart +++ b/test/widgets/cloud_sync_button_test.dart @@ -36,7 +36,10 @@ import 'package:icarus/strategy/store_page_structure.dart' show OfferedPage, StorePageStructure, storePageStructureProvider; import 'package:icarus/strategy/strategy_page_source.dart' show storeOwnedOpenProvider; -import 'package:icarus_library/icarus_library.dart' show DeletedByYou; +import 'package:icarus_library/icarus_library.dart' show DeletedByYou, Version; +import 'package:icarus/strategy/store_sync_face.dart' show HeldForYou; +import 'package:icarus/strategy/store_choices.dart' + show ConflictRow, HeldKind, Kept; import 'package:icarus/widgets/client_upgrade_button.dart'; import 'package:icarus/widgets/cloud_sync_button.dart'; import 'package:icarus/widgets/editor_toolbar.dart'; @@ -2609,6 +2612,90 @@ void main() { expect(find.text('This page was deleted'), findsOneWidget); }); }); + + group('a held change the store owns', () { + ConflictRow held({bool onScreen = true, int shown = 1}) => ( + opId: 'held-move', + pageId: 'page-1', + onScreen: onScreen, + kind: HeldKind.conflict, + coveredByMine: false, + shown: Version(shown), + ); + + Future<(StateController>, List>)> + pumpHeld(WidgetTester tester) async { + final rows = StateProvider>((ref) => [held()]); + final kept = >[]; + final container = ProviderContainer(overrides: [ + strategyProvider.overrideWith(_CloudStrategyProvider.new), + strategyOpQueueProvider.overrideWith(_SettledOpQueue.new), + strategyPageSessionProvider + .overrideWith(() => _DeletedPageSession(leaves: true)), + cloudMediaUploadQueueProvider.overrideWith(_EmptyMediaQueue.new), + convexConnectionProvider.overrideWith((ref) => Stream.value(true)), + storeSyncFaceProvider.overrideWithValue( + HeldForYou(const {HeldFor.conflict: 1}), + ), + storeConflictRowsProvider.overrideWith((ref) => ref.watch(rows)), + storeHeldGoneProvider.overrideWith((ref) => Stream.value({})), + convexConnectionSnapshotProvider.overrideWithValue(true), + storeKeepProvider.overrideWithValue((pressed) async { + kept.add(pressed); + return const Kept(); + }), + ]); + addTearDown(container.dispose); + await tester.pumpWidget( + UncontrolledProviderScope( + container: container, + child: const ShadApp( + home: Scaffold( + body: CloudSyncButton(style: kEditorToolbarButtonStyle), + ), + ), + ), + ); + await tester.pump(); + await tester.tap(_syncButton('attention')); + await tester.pumpAndSettle(); + return (container.read(rows.notifier), kept); + } + + testWidgets( + 'a held change on screen offers Put mine back, and the press hands ' + 'that change to the keep', (tester) async { + final (_, kept) = await pumpHeld(tester); + expect(find.text('Put mine back'), findsOneWidget); + await tester.tap(find.text('Put mine back')); + await tester.pumpAndSettle(); + expect(kept.single.single.opId, 'held-move'); + }); + + testWidgets( + 'a page switch while the popover is open closes it, and nothing is ' + 'kept', (tester) async { + final (rows, kept) = await pumpHeld(tester); + expect(find.text('Discard mine'), findsOneWidget); + rows.state = [held(onScreen: false)]; + await tester.pumpAndSettle(); + expect(find.text('Discard mine'), findsNothing); + expect(find.text('Put mine back'), findsNothing); + expect(kept, isEmpty); + }); + + testWidgets( + 'a press after the rows changed under the open popover keeps nothing', + (tester) async { + final (rows, kept) = await pumpHeld(tester); + final button = find.text('Put mine back'); + expect(button, findsOneWidget); + rows.state = [held(shown: 2)]; + await tester.tap(button); + await tester.pumpAndSettle(); + expect(kept, isEmpty); + }); + }); } class _FixedSessionAuth extends AuthProvider { diff --git a/tool/drive/README.md b/tool/drive/README.md index 2d2ac415d..dea801730 100644 --- a/tool/drive/README.md +++ b/tool/drive/README.md @@ -190,10 +190,12 @@ Its steps: - `{"storeAdd": …, "page": n}` adds to the store's live page `n`, counting from 0 by place, instead of the first. - `{"expectItem": id, "at": [x, y]}` waits (with `seconds`) for the item to be within half a unit of `(x, y)`, and fails if it never is. - `{"signOut": true, "says": text?, "shot": path?}` signs out through the guarded sign-out; with `says` it fails unless the confirmation shows exactly that text, and with `shot` it takes a screenshot of the confirmation before confirming. `store-signout-held-owner.json` with `store-signout-held-mate.json`, under `--cloud-store own`: the owner's move is held behind the teammate's; leaving the editor says what the held work waits on and offers no retry; the library banner names the strategy and why; signing out says the change stays on this computer for this account; after signing back in the chip still says what the work waits on, and after Use cloud it says Synced, each against the server. +- `{"waitText": text, "containing": true}` waits for a text that contains `text`, for words inside a longer block such as the sync popover. - `{"storeChoose": "discardMine"}` makes the same store call as the sync popover's Discard mine / Use theirs and logs what the store answered. `{"storeLeavesHeld": item}` declares that the run may end with the item's held changes still waiting on the player, so the end-of-run check reports them as expected rather than failing. `{"expectAgents": n, "seconds": s?}` waits up to `s` seconds for `n` agents. Positions written and compared by `writePositions`, `expectPositions` and `waitPositions` include lineup origins. - `{"storeHoldReads": true}` and `{"storeReleaseReads": true}` model a read that is slow to arrive: while held, every live result handed to the sender (page list or page) waits, in the order it arrived, while answers to what the sender sends, and reads the sender fetches itself, go through; on release the waiting results reach the sender in that order, nothing dropped or merged. The hold is behind `driveBuild`, so release builds do not have it. `{"storeTimeWire": true}` logs, until `false`, a `WIRE` line for each answer and each live result the sender records, with its time, connection and snapshot, to show which arrives first. - `store-race-held-owner.json` with `store-race-held-mate.json`, under `--cloud-store own`: the owner drags a1 with its sender held, the teammate drags a1, the sender is released and the server refuses the owner's move. The owner sees the toast, the teammate's position and the chip's conflict; Ctrl+Z and Ctrl+Shift+Z move nothing and say why; b1, moved meanwhile, reaches the teammate; a second move of a1 is drawn and waits behind the held one; Discard mine gives up both, and both sides end on the teammate's position. `store-race-delete-owner.json` with `store-race-delete-mate.json`: the same race with the owner deleting a1, ended with Discard mine. `store-edits-held-*` ends its held conflict with Discard mine from the popover. - `store-unseen-rename-owner.json` with `store-unseen-rename-mate.json`: the owner renames a page and it lands while its reads are held, renames it again with its sender held, the teammate renames it once its pages bar shows the owner's name (a step that depends on the other side's state waits for that state, not for a signal), and the reads are released: the store asks before sending (changed unseen); the page keeps the owner's name; Don't send gives the teammate's name on both sides. `store-side-all-held-owner.json` with `store-side-all-held-mate.json`: the owner holds its reads and stays on page 1, the teammate renames page 2, and the owner switches the side on every page: page 1 lands, page 2's switch is held, and the owner is told once that a change is held; Discard mine ends synced. `store-deleted-page-owner.json` with `store-deleted-page-restore-mate.json` or `store-deleted-page-discard-mate.json`: the owner deletes the page the teammate is moving an item on; the teammate is kept on the page and asked. Discard leaves for the first page. Restore saves the restore in the store, closes the dialog with a toast that the page is being restored, and stays on the page, with the teammate's move still drawn there and unsent; once the page is back and read, the held move shows as on a page that came back, and Discard changes from the sync button ends synced. `store-deleted-page-moved-owner.json` with `store-deleted-page-moved-mate.json`: the owner moves the item after the teammate did and before deleting the page; Restore ends the same way, with the owner's position on both sides. +- Put mine back and Send mine, under `--cloud-store own`, each pair ending with both sides and the server on the same version: `store-keep-*` puts a held agent move back over the teammate's; `store-rename-held-*` for a page rename, with the teammate's name shown while held; `store-map-keep-*` for the strategy's map; `store-keep-again-*` has the teammate move it again while the popover is open, so Put mine back writes nothing, says it changed again and shows the newer version, and the owner ends with Discard mine; `store-keep-follow-*` moves the held agent again, so the player's own later move is drawn over the teammate's: the popover offers no Put mine back, says why, and Discard mine ends on the teammate's position; `store-unseen-send-*` is the changed-unseen rename ended with Send mine. `store-deleted-page-moved-owner.json` with `store-deleted-page-moved-send-mate.json`: on the page that came back, the teammate's held move offers Send mine, which sends it over the owner's later move; both sides end on the teammate's position. - `{"expectChipTellsServer": true}` reads the sync chip's tooltip and what the open store-owned strategy's work is waiting on, then reads the server's copy of the strategy as the signed-in account and compares it with what the store shows. It fails if the chip's state or the words it shows say synced while the server lacks something the store shows, except an item the script marked with `storeMayLag`, and logs both otherwise. `{"expectImages": n, "seconds": s?}` waits up to `s` seconds for `n` placed pictures. `store-chip-offline-owner.json` with `store-chip-offline-mate.json`, run through `linux-cut-network.sh` with the owner cut: the owner moves an agent, places a picture, then selects all, copies and pastes, all offline; its chip says Offline while the teammate's server copy has neither; once back online the move, both agents and both pictures are on both canvases and both chips say Synced. `store-chip-held-owner.json` with `store-chip-held-mate.json`, under `--cloud-store own`: a held conflict ended with Use cloud, and a move refused because the teammate deleted its page, ended by restoring the page and keeping the move; the chip's words are checked in each held state and after each ends, each against the server. - `{"expectOldQueueEmpty": true}` fails if the old cloud queue holds or refused any work for the open strategy: the store is its one writer. `{"expectServerUnchanged": name}` remembers the server's rows of the open strategy on the first call with a name (each page's name, place, side and revision, each page's content revision and settings, each element's revision and payload, each lineup group's revision); a later call with the same name fails unless they are exactly as remembered. `cloud-store-own-open.json`, under `--library-store store --cloud-store own`, adds an item through the store, then uses the page controls the screen shows (add page, which copies the page on screen, the page menu's rename, the page list's rename icon, add page again, the page list's delete icon and the page menu's delete) and requires each change in the store, on the server and in the pages bar (`storeExpectPageOrder`), the canvas drawn from the store, and the old queue empty. It then renames the strategy from its title, presses the all-pages side shortcut, and turns on neutral team colours through `{"tapCheckboxBeside": title}`, which taps the checkbox in the row of that title, and requires each in the store, on the server and on screen (`storeExpectStrategyName`, `storeExpectEveryPage`). It then makes canvas edits (the side toggle, which turns every page, delete, undo, redo, copy and paste on the agent, the map and the theme) and a drag, waits for the store to hold each, and requires the old queue empty after each; then it moves the item through the store. - `{"storeExpect": true}` waits until the store holds the open strategy (60 s, or `"within": seconds`) and names it as one the end-of-run comparisons must judge; `{"storeExpect": "held"}` names the one cloud strategy the store holds, for a run that opens no editor. diff --git a/tool/drive/scripts/store-deleted-page-moved-send-mate.json b/tool/drive/scripts/store-deleted-page-moved-send-mate.json new file mode 100644 index 000000000..8e1e48b13 --- /dev/null +++ b/tool/drive/scripts/store-deleted-page-moved-send-mate.json @@ -0,0 +1,51 @@ +[ + {"wait": 10}, + {"tapIcon": "x", "optional": true}, + {"resize": [1600, 900]}, + {"signIn": true}, + {"wait": 4}, + {"waitSignal": "owner-ready", "seconds": 300}, + {"openShareLink": "{out}/edit-code.txt"}, + {"wait": 10}, + {"tapIcon": "x", "optional": true}, + {"storeExpect": true}, + {"expectStoreEditable": true}, + {"storeTimeWire": true}, + {"key": "keyD"}, + {"wait": 3}, + {"expectShownPage": 2}, + {"expectItem": "d1-{run}", "at": [600, 400], "seconds": 30}, + {"holdSender": true}, + {"dragAgent": "d1-{run}", "by": [100, 40]}, + {"waitCanvasInStore": 30}, + {"writePositions": "{out}/mate-dragged.json"}, + {"signal": "mate-holding"}, + {"waitSignal": "owner-deleted", "seconds": 300}, + {"wait": 5}, + {"releaseSender": true}, + {"waitText": "This page was deleted", "seconds": 30}, + {"shot": "{out}/mate-1-dialog.png"}, + {"tapText": "Restore page"}, + {"waitText": "The page is being restored. Your changes on it are waiting in the sync button.", "seconds": 30}, + {"shot": "{out}/mate-2-restoring-toast.png"}, + {"waitText": "This page was deleted", "seconds": 20, "gone": true}, + {"expectItem": "d1-{run}", "at": [600, 480], "seconds": 10}, + {"expectStoreNeedsYou": true}, + {"storeSyncState": true}, + {"expectSyncTooltip": "Sync needs attention · this page came back; your change waits to be sent", "seconds": 10}, + {"expectChipTellsServer": true}, + {"tapAt": [28, 142]}, + {"waitText": "Send mine", "seconds": 10}, + {"shot": "{out}/mate-3-page-back-send.png"}, + {"tapText": "Send mine"}, + {"waitStoreSent": 60, "landed": "may wait"}, + {"waitPositions": "{out}/mate-dragged.json", "seconds": 30}, + {"expectSyncTooltip": "Synced", "seconds": 60}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/mate-4-sent.png"}, + {"hoverAt": [800, 450]}, + {"signal": "mate-done"}, + {"exit": 1} +] diff --git a/tool/drive/scripts/store-keep-again-mate.json b/tool/drive/scripts/store-keep-again-mate.json new file mode 100644 index 000000000..29c275b45 --- /dev/null +++ b/tool/drive/scripts/store-keep-again-mate.json @@ -0,0 +1,37 @@ +[ + {"wait": 10}, + {"tapIcon": "x", "optional": true}, + {"resize": [1600, 900]}, + {"signIn": true}, + {"wait": 4}, + {"waitSignal": "owner-ready", "seconds": 300}, + {"openShareLink": "{out}/edit-code.txt"}, + {"wait": 10}, + {"tapIcon": "x", "optional": true}, + {"storeExpect": true}, + {"expectStoreEditable": true}, + {"expectItem": "a1-{run}", "seconds": 30}, + {"signal": "mate-ready"}, + {"waitSignal": "owner-queued", "seconds": 300}, + {"dragAgent": "a1-{run}", "by": [120, 30]}, + {"waitCanvasInStore": 30}, + {"waitStoreSent": 60, "landed": "may wait"}, + {"writePositions": "{out}/mate-moved.json"}, + {"signal": "mate-moved"}, + {"waitSignal": "owner-popover-open", "seconds": 300}, + {"dragAgent": "a1-{run}", "by": [0, -80]}, + {"waitCanvasInStore": 30}, + {"waitStoreSent": 60, "landed": "may wait"}, + {"writePositions": "{out}/mate-again.json"}, + {"signal": "mate-moved-again"}, + {"waitSignal": "owner-done", "seconds": 600}, + {"waitPositions": "{out}/mate-again.json", "seconds": 30}, + {"expectSyncTooltip": "Synced", "seconds": 60}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/mate-end.png"}, + {"hoverAt": [800, 450]}, + {"signal": "mate-done"}, + {"exit": 1} +] diff --git a/tool/drive/scripts/store-keep-again-owner.json b/tool/drive/scripts/store-keep-again-owner.json new file mode 100644 index 000000000..49c59d4c4 --- /dev/null +++ b/tool/drive/scripts/store-keep-again-owner.json @@ -0,0 +1,73 @@ +[ + {"wait": 10}, + {"tapIcon": "x", "optional": true}, + {"resize": [1600, 900]}, + {"signIn": true}, + {"wait": 4}, + {"newCloudFolder": "Keep again folder {run}"}, + {"openCloudFolder": "Keep again folder {run}"}, + {"wait": 3}, + {"newCloud": "Keep again {run}", "map": "bind"}, + {"wait": 4}, + {"tapText": "Keep again {run}"}, + {"wait": 12}, + {"tapIcon": "x", "optional": true}, + {"waitSettled": 60}, + {"storeExpect": true}, + {"expectStoreEditable": true}, + {"addAgent": "a1-{run}"}, + {"waitCanvasInStore": 30}, + {"waitStoreSent": 60, "landed": "may wait"}, + {"expectSyncTooltip": "Synced", "seconds": 60}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/owner-1-synced.png"}, + {"hoverAt": [800, 450]}, + {"shareLink": "editor", "file": "{out}/edit-code.txt"}, + {"signal": "owner-ready"}, + {"waitSignal": "mate-ready", "seconds": 300}, + {"holdSender": true}, + {"dragAgent": "a1-{run}", "by": [-60, 80]}, + {"writePositions": "{out}/owner-dragged.json"}, + {"waitCanvasInStore": 30}, + {"signal": "owner-queued"}, + {"waitSignal": "mate-moved", "seconds": 120}, + {"releaseSender": true}, + {"waitText": "A teammate changed the same thing first, so your change wasn't sent. The sync button holds it, and the page shows their version once your latest edits are saved.", "seconds": 15}, + {"wait": 5}, + {"expectStoreNeedsYou": true}, + {"expectPositions": "{out}/mate-moved.json"}, + {"expectSyncTooltip": "Sync needs attention · a teammate changed the same thing first", "seconds": 30}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/owner-2-held.png"}, + {"hoverAt": [800, 450]}, + {"tapAt": [28, 142]}, + {"waitText": "Put mine back", "seconds": 10}, + {"shot": "{out}/owner-3-popover.png"}, + {"signal": "owner-popover-open"}, + {"waitSignal": "mate-moved-again", "seconds": 120}, + {"wait": 5}, + {"tapText": "Put mine back"}, + {"wait": 5}, + {"waitText": "It changed again while you were choosing.", "seconds": 10, "containing": true}, + {"shot": "{out}/owner-4-changed-again.png"}, + {"waitPositions": "{out}/mate-again.json", "seconds": 20}, + {"key": "escape"}, + {"tapAt": [28, 142]}, + {"waitText": "Discard mine", "seconds": 10}, + {"tapText": "Discard mine"}, + {"waitStoreSent": 60, "landed": "may wait"}, + {"waitPositions": "{out}/mate-again.json", "seconds": 20}, + {"expectSyncTooltip": "Synced", "seconds": 60}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/owner-5-discarded.png"}, + {"hoverAt": [800, 450]}, + {"signal": "owner-done"}, + {"waitSignal": "mate-done", "seconds": 300}, + {"exit": 1} +] diff --git a/tool/drive/scripts/store-keep-follow-mate.json b/tool/drive/scripts/store-keep-follow-mate.json new file mode 100644 index 000000000..fab2648ae --- /dev/null +++ b/tool/drive/scripts/store-keep-follow-mate.json @@ -0,0 +1,31 @@ +[ + {"wait": 10}, + {"tapIcon": "x", "optional": true}, + {"resize": [1600, 900]}, + {"signIn": true}, + {"wait": 4}, + {"waitSignal": "owner-ready", "seconds": 300}, + {"openShareLink": "{out}/edit-code.txt"}, + {"wait": 10}, + {"tapIcon": "x", "optional": true}, + {"storeExpect": true}, + {"expectStoreEditable": true}, + {"expectItem": "a1-{run}", "seconds": 30}, + {"signal": "mate-ready"}, + {"waitSignal": "owner-queued", "seconds": 300}, + {"dragAgent": "a1-{run}", "by": [120, 30]}, + {"waitCanvasInStore": 30}, + {"waitStoreSent": 60, "landed": "may wait"}, + {"writePositions": "{out}/mate-moved.json"}, + {"signal": "mate-moved"}, + {"waitSignal": "owner-done", "seconds": 600}, + {"waitPositions": "{out}/mate-moved.json", "seconds": 30}, + {"expectSyncTooltip": "Synced", "seconds": 60}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/mate-end.png"}, + {"hoverAt": [800, 450]}, + {"signal": "mate-done"}, + {"exit": 1} +] diff --git a/tool/drive/scripts/store-keep-follow-owner.json b/tool/drive/scripts/store-keep-follow-owner.json new file mode 100644 index 000000000..2472e9f73 --- /dev/null +++ b/tool/drive/scripts/store-keep-follow-owner.json @@ -0,0 +1,69 @@ +[ + {"wait": 10}, + {"tapIcon": "x", "optional": true}, + {"resize": [1600, 900]}, + {"signIn": true}, + {"wait": 4}, + {"newCloudFolder": "Keep follow folder {run}"}, + {"openCloudFolder": "Keep follow folder {run}"}, + {"wait": 3}, + {"newCloud": "Keep follow {run}", "map": "bind"}, + {"wait": 4}, + {"tapText": "Keep follow {run}"}, + {"wait": 12}, + {"tapIcon": "x", "optional": true}, + {"waitSettled": 60}, + {"storeExpect": true}, + {"expectStoreEditable": true}, + {"addAgent": "a1-{run}"}, + {"waitCanvasInStore": 30}, + {"waitStoreSent": 60, "landed": "may wait"}, + {"expectSyncTooltip": "Synced", "seconds": 60}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/owner-1-synced.png"}, + {"hoverAt": [800, 450]}, + {"shareLink": "editor", "file": "{out}/edit-code.txt"}, + {"signal": "owner-ready"}, + {"waitSignal": "mate-ready", "seconds": 300}, + {"holdSender": true}, + {"dragAgent": "a1-{run}", "by": [-60, 80]}, + {"writePositions": "{out}/owner-dragged.json"}, + {"waitCanvasInStore": 30}, + {"signal": "owner-queued"}, + {"waitSignal": "mate-moved", "seconds": 120}, + {"releaseSender": true}, + {"waitText": "A teammate changed the same thing first, so your change wasn't sent. The sync button holds it, and the page shows their version once your latest edits are saved.", "seconds": 15}, + {"wait": 5}, + {"expectStoreNeedsYou": true}, + {"expectPositions": "{out}/mate-moved.json"}, + {"expectSyncTooltip": "Sync needs attention · a teammate changed the same thing first", "seconds": 30}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/owner-2-held.png"}, + {"hoverAt": [800, 450]}, + {"dragAgent": "a1-{run}", "by": [0, 60]}, + {"waitCanvasInStore": 30}, + {"writePositions": "{out}/owner-again.json"}, + {"tapAt": [28, 142]}, + {"waitText": "You changed it again after this. Discard mine gives up both; then make your change again.", "seconds": 10, "containing": true}, + {"waitText": "Put mine back", "seconds": 3, "gone": true}, + {"waitText": "yours is kept here until you discard it.", "seconds": 3, "containing": true}, + {"waitText": "Put yours back to replace theirs", "seconds": 3, "containing": true, "gone": true}, + {"shot": "{out}/owner-3-no-put-back.png"}, + {"tapText": "Discard mine"}, + {"waitStoreSent": 60, "landed": "may wait"}, + {"waitPositions": "{out}/mate-moved.json", "seconds": 20}, + {"expectCanvasIsTheStores": true}, + {"expectSyncTooltip": "Synced", "seconds": 60}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/owner-4-discarded.png"}, + {"hoverAt": [800, 450]}, + {"signal": "owner-done"}, + {"waitSignal": "mate-done", "seconds": 300}, + {"exit": 1} +] diff --git a/tool/drive/scripts/store-keep-mate.json b/tool/drive/scripts/store-keep-mate.json new file mode 100644 index 000000000..5987ec241 --- /dev/null +++ b/tool/drive/scripts/store-keep-mate.json @@ -0,0 +1,31 @@ +[ + {"wait": 10}, + {"tapIcon": "x", "optional": true}, + {"resize": [1600, 900]}, + {"signIn": true}, + {"wait": 4}, + {"waitSignal": "owner-ready", "seconds": 300}, + {"openShareLink": "{out}/edit-code.txt"}, + {"wait": 10}, + {"tapIcon": "x", "optional": true}, + {"storeExpect": true}, + {"expectStoreEditable": true}, + {"expectItem": "a1-{run}", "seconds": 30}, + {"signal": "mate-ready"}, + {"waitSignal": "owner-queued", "seconds": 300}, + {"dragAgent": "a1-{run}", "by": [120, 30]}, + {"waitCanvasInStore": 30}, + {"waitStoreSent": 60, "landed": "may wait"}, + {"writePositions": "{out}/mate-moved.json"}, + {"signal": "mate-moved"}, + {"waitSignal": "owner-done", "seconds": 600}, + {"waitPositions": "{out}/owner-dragged.json", "seconds": 30}, + {"expectSyncTooltip": "Synced", "seconds": 60}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/mate-end.png"}, + {"hoverAt": [800, 450]}, + {"signal": "mate-done"}, + {"exit": 1} +] diff --git a/tool/drive/scripts/store-keep-owner.json b/tool/drive/scripts/store-keep-owner.json new file mode 100644 index 000000000..02b9996ec --- /dev/null +++ b/tool/drive/scripts/store-keep-owner.json @@ -0,0 +1,64 @@ +[ + {"wait": 10}, + {"tapIcon": "x", "optional": true}, + {"resize": [1600, 900]}, + {"signIn": true}, + {"wait": 4}, + {"newCloudFolder": "Keep folder {run}"}, + {"openCloudFolder": "Keep folder {run}"}, + {"wait": 3}, + {"newCloud": "Keep {run}", "map": "bind"}, + {"wait": 4}, + {"tapText": "Keep {run}"}, + {"wait": 12}, + {"tapIcon": "x", "optional": true}, + {"waitSettled": 60}, + {"storeExpect": true}, + {"expectStoreEditable": true}, + {"addAgent": "a1-{run}"}, + {"waitCanvasInStore": 30}, + {"waitStoreSent": 60, "landed": "may wait"}, + {"expectSyncTooltip": "Synced", "seconds": 60}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/owner-1-synced.png"}, + {"hoverAt": [800, 450]}, + {"shareLink": "editor", "file": "{out}/edit-code.txt"}, + {"signal": "owner-ready"}, + {"waitSignal": "mate-ready", "seconds": 300}, + {"holdSender": true}, + {"dragAgent": "a1-{run}", "by": [-60, 80]}, + {"writePositions": "{out}/owner-dragged.json"}, + {"waitCanvasInStore": 30}, + {"signal": "owner-queued"}, + {"waitSignal": "mate-moved", "seconds": 120}, + {"releaseSender": true}, + {"waitText": "A teammate changed the same thing first, so your change wasn't sent. The sync button holds it, and the page shows their version once your latest edits are saved.", "seconds": 15}, + {"wait": 5}, + {"expectStoreNeedsYou": true}, + {"expectPositions": "{out}/mate-moved.json"}, + {"expectSyncTooltip": "Sync needs attention · a teammate changed the same thing first", "seconds": 30}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/owner-2-held.png"}, + {"hoverAt": [800, 450]}, + {"tapAt": [28, 142]}, + {"waitText": "Put mine back", "seconds": 10}, + {"waitText": "Put yours back to replace theirs, or discard it.", "seconds": 3, "containing": true}, + {"shot": "{out}/owner-3-popover.png"}, + {"tapText": "Put mine back"}, + {"waitStoreSent": 60, "landed": "may wait"}, + {"waitPositions": "{out}/owner-dragged.json", "seconds": 20}, + {"expectCanvasIsTheStores": true}, + {"expectSyncTooltip": "Synced", "seconds": 60}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/owner-4-put-back.png"}, + {"hoverAt": [800, 450]}, + {"signal": "owner-done"}, + {"waitSignal": "mate-done", "seconds": 300}, + {"exit": 1} +] diff --git a/tool/drive/scripts/store-map-keep-mate.json b/tool/drive/scripts/store-map-keep-mate.json new file mode 100644 index 000000000..d3b328db9 --- /dev/null +++ b/tool/drive/scripts/store-map-keep-mate.json @@ -0,0 +1,35 @@ +[ + {"wait": 10}, + {"tapIcon": "x", "optional": true}, + {"resize": [1600, 900]}, + {"signIn": true}, + {"wait": 4}, + {"waitSignal": "owner-ready", "seconds": 300}, + {"openShareLink": "{out}/edit-code.txt"}, + {"wait": 10}, + {"tapIcon": "x", "optional": true}, + {"storeExpect": true}, + {"expectStoreEditable": true}, + {"storeExpectMapTheme": "bind", "theme": "immutable-default-map-theme", "seconds": 60}, + {"signal": "mate-ready"}, + {"waitSignal": "owner-picked", "seconds": 300}, + {"tapAt": [102, 80]}, + {"wait": 2}, + {"tapText": "LOTUS"}, + {"wait": 2}, + {"key": "escape"}, + {"wait": 2}, + {"waitCanvasInStore": 30}, + {"waitStoreSent": 60, "landed": "may wait"}, + {"signal": "mate-picked"}, + {"waitSignal": "owner-done", "seconds": 600}, + {"storeExpectMapTheme": "haven", "theme": "immutable-default-map-theme", "seconds": 30}, + {"expectSyncTooltip": "Synced", "seconds": 60}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/mate-end.png"}, + {"hoverAt": [800, 450]}, + {"signal": "mate-done"}, + {"exit": 1} +] diff --git a/tool/drive/scripts/store-map-keep-owner.json b/tool/drive/scripts/store-map-keep-owner.json new file mode 100644 index 000000000..4df8b6e17 --- /dev/null +++ b/tool/drive/scripts/store-map-keep-owner.json @@ -0,0 +1,66 @@ +[ + {"wait": 10}, + {"tapIcon": "x", "optional": true}, + {"resize": [1600, 900]}, + {"signIn": true}, + {"wait": 4}, + {"newCloudFolder": "Map keep folder {run}"}, + {"openCloudFolder": "Map keep folder {run}"}, + {"wait": 3}, + {"newCloud": "Map keep {run}", "map": "bind"}, + {"wait": 4}, + {"tapText": "Map keep {run}"}, + {"wait": 12}, + {"tapIcon": "x", "optional": true}, + {"waitSettled": 60}, + {"storeExpect": true}, + {"expectStoreEditable": true}, + {"storeExpectMapTheme": "bind", "theme": "immutable-default-map-theme", "seconds": 60}, + {"expectSyncTooltip": "Synced", "seconds": 60}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/owner-1-synced.png"}, + {"hoverAt": [800, 450]}, + {"shareLink": "editor", "file": "{out}/edit-code.txt"}, + {"signal": "owner-ready"}, + {"waitSignal": "mate-ready", "seconds": 300}, + {"holdSender": true}, + {"tapAt": [102, 80]}, + {"wait": 2}, + {"tapText": "HAVEN"}, + {"wait": 2}, + {"key": "escape"}, + {"wait": 2}, + {"waitCanvasInStore": 30}, + {"storeQueueRecord": true}, + {"signal": "owner-picked"}, + {"waitSignal": "mate-picked", "seconds": 180}, + {"releaseSender": true}, + {"wait": 15}, + {"storeQueueRecord": true}, + {"storeSyncState": true}, + {"expectStoreNeedsYou": true}, + {"storeExpectMapTheme": "lotus", "theme": "immutable-default-map-theme", "seconds": 30}, + {"expectSyncTooltip": "Sync needs attention · a teammate changed the same thing first", "seconds": 30}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/owner-2-held.png"}, + {"hoverAt": [800, 450]}, + {"tapAt": [28, 142]}, + {"waitText": "Put mine back", "seconds": 10}, + {"shot": "{out}/owner-3-popover.png"}, + {"tapText": "Put mine back"}, + {"waitStoreSent": 60, "landed": "may wait"}, + {"storeExpectMapTheme": "haven", "theme": "immutable-default-map-theme", "seconds": 30}, + {"expectSyncTooltip": "Synced", "seconds": 60}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/owner-4-put-back.png"}, + {"hoverAt": [800, 450]}, + {"signal": "owner-done"}, + {"waitSignal": "mate-done", "seconds": 300}, + {"exit": 1} +] diff --git a/tool/drive/scripts/store-rename-held-mate.json b/tool/drive/scripts/store-rename-held-mate.json new file mode 100644 index 000000000..4a468723d --- /dev/null +++ b/tool/drive/scripts/store-rename-held-mate.json @@ -0,0 +1,28 @@ +[ + {"wait": 10}, + {"tapIcon": "x", "optional": true}, + {"resize": [1600, 900]}, + {"signIn": true}, + {"wait": 4}, + {"waitSignal": "owner-ready", "seconds": 300}, + {"openShareLink": "{out}/edit-code.txt"}, + {"wait": 10}, + {"tapIcon": "x", "optional": true}, + {"storeExpect": true}, + {"expectStoreEditable": true}, + {"signal": "mate-ready"}, + {"waitSignal": "owner-holding", "seconds": 300}, + {"storeRenamePage": "Mate page {run}", "page": 0}, + {"waitStoreSent": 60, "landed": "may wait"}, + {"signal": "mate-moved"}, + {"waitSignal": "owner-done", "seconds": 600}, + {"waitText": "Owner page {run}", "seconds": 30}, + {"expectSyncTooltip": "Synced", "seconds": 60}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/mate-end.png"}, + {"hoverAt": [800, 450]}, + {"signal": "mate-done"}, + {"exit": 1} +] diff --git a/tool/drive/scripts/store-rename-held-owner.json b/tool/drive/scripts/store-rename-held-owner.json new file mode 100644 index 000000000..bf313f6c0 --- /dev/null +++ b/tool/drive/scripts/store-rename-held-owner.json @@ -0,0 +1,58 @@ +[ + {"wait": 10}, + {"tapIcon": "x", "optional": true}, + {"resize": [1600, 900]}, + {"signIn": true}, + {"wait": 4}, + {"newCloudFolder": "Rename held folder {run}"}, + {"openCloudFolder": "Rename held folder {run}"}, + {"wait": 3}, + {"newCloud": "Rename held {run}", "map": "bind"}, + {"wait": 4}, + {"tapText": "Rename held {run}"}, + {"wait": 12}, + {"tapIcon": "x", "optional": true}, + {"waitSettled": 60}, + {"storeExpect": true}, + {"expectStoreEditable": true}, + {"waitStoreSent": 60, "landed": "may wait"}, + {"expectSyncTooltip": "Synced", "seconds": 60}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/owner-1-synced.png"}, + {"hoverAt": [800, 450]}, + {"shareLink": "editor", "file": "{out}/edit-code.txt"}, + {"signal": "owner-ready"}, + {"waitSignal": "mate-ready", "seconds": 300}, + {"holdSender": true}, + {"storeRenamePage": "Owner page {run}", "page": 0}, + {"signal": "owner-holding"}, + {"waitSignal": "mate-moved", "seconds": 120}, + {"releaseSender": true}, + {"wait": 15}, + {"storeQueueRecord": true}, + {"expectStoreNeedsYou": true}, + {"waitText": "Mate page {run}", "seconds": 20}, + {"expectSyncTooltip": "Sync needs attention · a teammate changed the same thing first", "seconds": 30}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/owner-2-held.png"}, + {"hoverAt": [800, 450]}, + {"tapAt": [28, 142]}, + {"waitText": "Put mine back", "seconds": 10}, + {"shot": "{out}/owner-3-popover.png"}, + {"tapText": "Put mine back"}, + {"waitStoreSent": 60, "landed": "may wait"}, + {"waitText": "Owner page {run}", "seconds": 20}, + {"expectSyncTooltip": "Synced", "seconds": 60}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/owner-4-put-back.png"}, + {"hoverAt": [800, 450]}, + {"signal": "owner-done"}, + {"waitSignal": "mate-done", "seconds": 300}, + {"exit": 1} +] diff --git a/tool/drive/scripts/store-unseen-send-mate.json b/tool/drive/scripts/store-unseen-send-mate.json new file mode 100644 index 000000000..60dd37401 --- /dev/null +++ b/tool/drive/scripts/store-unseen-send-mate.json @@ -0,0 +1,28 @@ +[ + {"wait": 10}, + {"tapIcon": "x", "optional": true}, + {"resize": [1600, 900]}, + {"signIn": true}, + {"wait": 4}, + {"waitSignal": "owner-ready", "seconds": 300}, + {"openShareLink": "{out}/edit-code.txt"}, + {"wait": 10}, + {"tapIcon": "x", "optional": true}, + {"storeExpect": true}, + {"expectStoreEditable": true}, + {"signal": "mate-ready"}, + {"waitSignal": "owner-renamed", "seconds": 300}, + {"storeRenamePage": "Mate {run}", "page": 0}, + {"waitStoreSent": 60, "landed": "may wait"}, + {"signal": "mate-renamed"}, + {"waitSignal": "owner-done", "seconds": 600}, + {"waitText": "Owner third {run}", "seconds": 30}, + {"expectSyncTooltip": "Synced", "seconds": 60}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/mate-end.png"}, + {"hoverAt": [800, 450]}, + {"signal": "mate-done"}, + {"exit": 1} +] diff --git a/tool/drive/scripts/store-unseen-send-owner.json b/tool/drive/scripts/store-unseen-send-owner.json new file mode 100644 index 000000000..c27c4fa1e --- /dev/null +++ b/tool/drive/scripts/store-unseen-send-owner.json @@ -0,0 +1,72 @@ +[ + {"wait": 10}, + {"tapIcon": "x", "optional": true}, + {"resize": [1600, 900]}, + {"signIn": true}, + {"wait": 4}, + {"newCloudFolder": "Unseen folder {run}"}, + {"openCloudFolder": "Unseen folder {run}"}, + {"wait": 3}, + {"newCloud": "Unseen {run}", "map": "bind"}, + {"wait": 4}, + {"tapText": "Unseen {run}"}, + {"wait": 12}, + {"tapIcon": "x", "optional": true}, + {"waitSettled": 60}, + {"storeExpect": true}, + {"expectStoreEditable": true}, + {"waitStoreSent": 60, "landed": "may wait"}, + {"expectSyncTooltip": "Synced", "seconds": 60}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/owner-1-synced.png"}, + {"hoverAt": [800, 450]}, + {"shareLink": "editor", "file": "{out}/edit-code.txt"}, + {"signal": "owner-ready"}, + {"waitSignal": "mate-ready", "seconds": 300}, + {"storeTimeWire": true}, + {"storeRenamePage": "Owner first {run}", "page": 0}, + {"waitStoreSent": 60, "landed": "may wait"}, + {"wait": 3}, + {"storeTimeWire": false}, + {"storeHoldReads": true}, + {"storeRenamePage": "Owner second {run}", "page": 0}, + {"waitStoreSent": 60, "landed": "may wait"}, + {"holdSender": true}, + {"storeRenamePage": "Owner third {run}", "page": 0}, + {"storeQueueRecord": true}, + {"signal": "owner-renamed"}, + {"waitSignal": "mate-renamed", "seconds": 180}, + {"wait": 3}, + {"storeReleaseReads": true}, + {"wait": 5}, + {"storeQueueRecord": true}, + {"storeSyncState": true}, + {"releaseSender": true}, + {"wait": 10}, + {"storeQueueRecord": true}, + {"storeSyncState": true}, + {"waitText": "Owner third {run}", "seconds": 5, "optional": true}, + {"expectSyncTooltip": "Sync needs attention · this changed before yours was sent", "seconds": 30}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/owner-2-unsent.png"}, + {"hoverAt": [800, 450]}, + {"tapAt": [28, 142]}, + {"waitText": "Send mine", "seconds": 10}, + {"shot": "{out}/owner-3-popover.png"}, + {"tapText": "Send mine"}, + {"waitStoreSent": 60, "landed": "may wait"}, + {"waitText": "Owner third {run}", "seconds": 30}, + {"expectSyncTooltip": "Synced", "seconds": 60}, + {"expectChipTellsServer": true}, + {"hoverAt": [28, 142]}, + {"wait": 1}, + {"shot": "{out}/owner-4-sent-mine.png"}, + {"hoverAt": [800, 450]}, + {"signal": "owner-done"}, + {"waitSignal": "mate-done", "seconds": 300}, + {"exit": 1} +]