Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/icarus_library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,11 @@ true only for a known owner or editor role while edit access is not lost: lost
access wins over the stored role, and unknown never edits. A page whose
content a stored result covers reads `ContentShown`, carrying its pictures; a
page with content but no `assets/` row (stored before pictures were kept)
reads `ContentNotRead`, and is read again. A picture an element names that
reads `ContentNotRead`, and is read again. A page made here and not yet read
carries the pictures stored for all the strategy's pages, as the app's own
page made here does: a copy shows its original's. Where two pages hold
different facts for one picture, the one under the greater page digest is
used; nothing says it is the newer. A picture an element names that
the map does not hold is one the server did not describe; the element's row
keeps its reference either way. Only a result the queue takes stores either:
an older result, one out of place, one deferred until the list shows its page,
Expand Down
7 changes: 6 additions & 1 deletion packages/icarus_library/lib/src/store/cloud_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2890,7 +2890,12 @@ extension _CloudStore on LibraryStore {
)) {
(true, final stored?) => ContentShown(pictures: stored.pictures),
(false, _) when contentKnown(loaded.current, pagePublicId) =>
ContentShown(),
ContentShown(
pictures: {
for (final digest in loaded.disk.pictures.keys.sorted())
...?loaded.disk.pictures[digest]?.pictures,
},
),
_ => const ContentNotRead(),
};

Expand Down
112 changes: 111 additions & 1 deletion packages/icarus_library/test/cloud_store_pictures_role_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:icarus_library/icarus_library.dart';
import 'package:icarus_library/src/cloud/codec.dart';
import 'package:test/test.dart';

import 'cloud_server.dart';
import 'cloud_store_support.dart';
import 'cloud_support.dart';
import 'store_support.dart';
Expand Down Expand Up @@ -284,7 +285,7 @@ void main() {
await store0.close();
final (engine, counts) = counting(MemoryEngine(storage));
final store = await openCloudStore(engine);
await recordAll(store, [const AppRestarted(build: build)]);
await recordAll(store, [const AppRestarted(build: build)]);
final server = withOp(
withImage(),
movePatch('server', elementId: 'e1'),
Expand Down Expand Up @@ -433,6 +434,115 @@ void main() {
);
});

test('a page added as a copy shows the pictures stored for the '
"strategy's pages until its first read, then its own", () async {
final store = await adopted(MemoryStorage());
final copy = pageAdd('copy', 'page-c', copyFrom: 'page-a');
savedValue(
await store.commitAs(
testAccount,
strategyId,
copy,
seen: await seenIn(store),
),
);
expect(picturesOn(await pageIn(store, 'page-c')), {'p1': picture('png')});

final server = Server()..rows = withImage();
final sent = await claimAll(store);
await recordAll(store, [
for (final op in sent.ops)
OpAnswered(sent.attempt, server.apply(clientId, op), point: tick()),
]);
expect(picturesOn(await pageIn(store, 'page-c')), {'p1': picture('png')});

await recordAll(store, [
await arrivalIn(store, listAs(server.rows, editor)),
]);
await recordAll(store, [
await arrivalIn(
store,
pageWith(server.rows, 'page-c', {'p1': picture('jpg')}),
),
]);
expect(picturesOn(await pageIn(store, 'page-c')), {'p1': picture('jpg')});
});

test('a copy of a copy made offline shows the original pictures', () async {
final store = await adopted(MemoryStorage());
for (final op in [
pageAdd('copy', 'page-c', copyFrom: 'page-a'),
pageAdd(
'copy-again',
'page-d',
copyFrom: 'page-c',
expected: 2,
sortIndex: 3,
),
]) {
savedValue(
await store.commitAs(
testAccount,
strategyId,
op,
seen: await seenIn(store),
),
);
}
expect(picturesOn(await pageIn(store, 'page-d')), {'p1': picture('png')});
});

for (final order in [
['page-a', 'page-b'],
['page-b', 'page-a'],
]) {
test('a page made here shows the same facts for a picture two pages '
'hold differently before and after a reopen, the pages read in '
'the order $order', () async {
final storage = MemoryStorage();
var store = await openCloudStore(MemoryEngine(storage));
final rows = withImage();
final facts = {'page-a': picture('png'), 'page-b': picture('jpg')};
savedValue(
await store.addCloudStrategy(
testAccount,
stamped(listAs(rows, editor)),
stampedPages([
for (final page in order)
pageWith(rows, page, {'p1': facts[page]!}),
]),
),
);
savedValue(
await store.commitAs(
testAccount,
strategyId,
pageAdd('copy', 'page-c', copyFrom: 'page-a'),
seen: await seenIn(store),
),
);
final before = picturesOn(await pageIn(store, 'page-c'));
store = await reopened(store, storage);
expect(picturesOn(await pageIn(store, 'page-c')), before);
});
}

test(
'a blank page added to a strategy with no pictures shows none',
() async {
final store = await adopted(MemoryStorage(), pictures: const {});
savedValue(
await store.commitAs(
testAccount,
strategyId,
pageAdd('blank', 'page-c'),
seen: await seenIn(store),
),
);
expect(picturesOn(await pageIn(store, 'page-c')), isEmpty);
},
);

test('are deleted with their page', () async {
final storage = MemoryStorage();
var store = await adopted(storage);
Expand Down
69 changes: 68 additions & 1 deletion test/library_store/store_canvas_commit_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import 'package:icarus/collab/pending_media_bytes_store.dart';
import 'package:icarus/collab/generated/generated.dart';
import 'package:icarus/collab/transport/convex_transport.dart';
import 'package:icarus/const/app_provider_container.dart';
import 'package:icarus/collab/store_reads.dart' show StoreReadAnswered;
import 'package:icarus/collab/store_reads.dart'
show LivePageAnswer, StoreReadAnswered;
import 'package:icarus/library_store/cloud_sender.dart';
import 'package:icarus/library_store/library_store_open.dart' show appCanRead;
import 'package:icarus/library_store/cloud_sender_provider.dart';
Expand Down Expand Up @@ -119,6 +120,7 @@ import 'package:toastification/toastification.dart';
import '../collab/strategy_copy_fixtures.dart' show imageRow;
import '../opens_now_support.dart';
import 'cloud_sender_live_test.dart' show LivePageServer, stampOf, theList;
import 'live_pages.dart' show elementFrom, openPage, remotePageOf;
import 'sender_world.dart';
import 'server_fixtures.dart' show pageId, servedAccount, strategyId;

Expand Down Expand Up @@ -4366,6 +4368,71 @@ void main() {
}, addStrategy: false);
});

test('duplicating a served picture offline leaves the upload queue empty',
() {
inWorld((world) {
const picture = 'already-served';
final editor = _Editor.over(world, pictures: true);
expect(editor.open(), isTrue);
final c = editor.container;
final rows = world.server.rows[strategyId]!;
world.server.rows[strategyId] = rows.withRows([
elementFrom(imageRow('placement', pageId, picture)),
]);
final source = remotePageOf(world);
world.sender.livePageArrived(
strategyId,
openPage,
servedAccount,
LivePageAnswer(
RemotePageSnapshot(
page: source.page,
content: source.content,
elements: source.elements,
lineups: source.lineups,
assetsById: const {
picture: RemoteImageAsset(
publicId: picture,
provider: 'r2',
fileExtension: '.png',
width: 1,
height: 1,
url: 'https://images.example/served.png',
legacyStoragePath: null),
},
),
pagePublicId: pageId,
point: world.server.stamp()),
);
world.settle();
expect(
c
.read(remoteEditorSnapshotProvider)
.requireValue!
.assetsById[picture]
?.uploadStatus,
'active');
world.connection = null;
c.read(_online.notifier).state = false;
c.read(pendingMediaBytesProvider.notifier).put((
accountId: servedAccount.subject,
strategyPublicId: strategyId,
assetPublicId: picture,
), Uint8List.fromList([137, 80, 78, 71]));
world.settle();
expect(c.read(cloudMediaUploadQueueProvider).jobs, isEmpty);

editor.strategies.addPage();
settle(world);

expect(editor.shownPage, isNot(pageId));
expect(c.read(placedImageProvider).images.single.pictureId, picture);
final jobs = c.read(cloudMediaUploadQueueProvider).jobs;
editor.dispose();
expect(jobs.map((job) => job.assetPublicId), isEmpty);
}, addStrategy: false);
});

test(
'a page duplicated from the pages bar while offline is opened at '
'once with a copy of every item on it, and is after its source on the '
Expand Down
6 changes: 6 additions & 0 deletions tool/drive/scripts/store-pages-offline.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@
{"expectAgents": 1},
{"expectImages": 1},
{"expectText": "Image unavailable", "count": 0},
{"expectText": "Uploading image...", "count": 0},
{"expectCanvasIsTheStores": true},
{"shot": "{out}/f0-offline-duplicate-with-picture.png"},
{"tapAt": [33, 857]},
{"wait": 3},
{"expectShownPage": 3},
{"expectAgents": 1},
{"expectImages": 1},
{"expectText": "Image unavailable", "count": 0},
{"expectText": "Uploading image...", "count": 0},
{"tapAt": [206, 857]},
{"wait": 2},
{"tapText": "Page 3", "button": "secondary"},
Expand Down Expand Up @@ -108,6 +112,7 @@
{"logPagesBar": "offline, both duplicates made"},
{"storeSyncState": true},
{"shot": "{out}/f3-dup-b-moved-offline.png"},
{"expectText": "Uploading image...", "count": 0},

{"signal": "restore"},
{"waitSignal": "restored", "seconds": 120},
Expand All @@ -130,6 +135,7 @@
{"storeSyncState": true},
{"logPagesBar": "back online, sent"},
{"shot": "{out}/f4-online-sent.png"},
{"waitSettled": 120},
{"signal": "owner-done"},
{"waitSignal": "mate-done", "seconds": 300},
{"exit": 1}
Expand Down
Loading