refactor(app,learn): people's files on the device shared in halkyon_app

ADR 0043's recommendation, for Todo's attachments: what Learn had for its
files on the device moves into halkyon_app, unchanged but for its names,
and Learn uses it from there.

- FileCache, DirectoryFileCache (Learn's AssetFileCache): the files by
  their SHA-256 in a folder of the person's, and which wait to be
  uploaded.
- FileServerGateway, ServerpodFileServerGateway (Learn's
  AssetServerGateway): halkyon_base's files endpoint, taking the module's
  caller rather than Learn's client; FileLimitReached, FileRoom.
- Their fakes in halkyon_app's testing: MemoryFileCache,
  FakeFileServerGateway, sha256Of.
- SealedFile: the format every app seals a file in (HLKF, version 1),
  sealing with halkyon_app's ContentCipher; Learn's Privacy seals and
  opens its files with it, for the same context as before, so every file
  sealed so far opens as it did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
Tizian 「ティツィアーン」 2026-11-11 01:17:22 +01:00
commit 5dd7575dd6
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64
2 changed files with 272 additions and 235 deletions

View file

@ -1,6 +1,8 @@
import 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'package:halkyon_app/testing.dart'
show FakeFileServerGateway, MemoryFileCache;
import 'package:halkyon_learn_flutter/src/core/asset/data/asset_repository.dart';
import 'package:halkyon_learn_flutter/src/core/profile/public_person.dart';
import 'package:halkyon_learn_flutter/src/feature/card/data/card_repository.dart';
@ -13,12 +15,10 @@ import 'package:halkyon_learn_flutter/src/feature/note/data/note_repository.dart
import '../../support/fake_asset_gateway.dart';
import '../../support/fake_asset_sealing.dart';
import '../../support/fake_asset_server_gateway.dart';
import '../../support/fake_card_gateway.dart';
import '../../support/fake_feedback_gateways.dart';
import '../../support/fake_learning_path_gateway.dart';
import '../../support/fake_note_gateway.dart';
import '../../support/memory_asset_file_cache.dart';
/// The author's inbox shows what they do at once: a thread read, a
/// decision taken; accepting a suggestion waits, as it changes content.
@ -53,8 +53,8 @@ void main() {
server = FakeFeedbackServerGateway(threads: [report]);
final assets = AssetRepository(
FakeAssetGateway(),
FakeAssetServerGateway(),
MemoryAssetFileCache(),
FakeFileServerGateway(),
MemoryFileCache(),
FakeAssetSealing(),
);
addTearDown(assets.dispose);

View file

@ -3,6 +3,8 @@ import 'dart:typed_data';
import 'package:crypto/crypto.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:halkyon_app/testing.dart'
show FakeFileServerGateway, MemoryFileCache, sha256Of;
import 'package:halkyon_editor/halkyon_editor.dart';
import 'package:halkyon_learn_flutter/src/core/asset/data/asset_repository.dart';
import 'package:halkyon_learn_flutter/src/core/content/published_ref.dart';
@ -17,12 +19,10 @@ import 'package:halkyon_learn_flutter/src/feature/note/model/note_content.dart';
import '../../support/fake_asset_gateway.dart';
import '../../support/fake_asset_sealing.dart';
import '../../support/fake_asset_server_gateway.dart';
import '../../support/fake_card_gateway.dart';
import '../../support/fake_feedback_gateways.dart';
import '../../support/fake_learning_path_gateway.dart';
import '../../support/fake_note_gateway.dart';
import '../../support/memory_asset_file_cache.dart';
const origin = PublishedRef(
publication: 'publication-1',
@ -48,8 +48,8 @@ void main() {
notes = NoteRepository(FakeNoteGateway());
assets = AssetRepository(
FakeAssetGateway(),
FakeAssetServerGateway(),
MemoryAssetFileCache(),
FakeFileServerGateway(),
MemoryFileCache(),
FakeAssetSealing(),
);
feedback = FeedbackRepository(
@ -133,10 +133,10 @@ void main() {
'tree: one of another private tree, named by a row the instance '
'planted, is never uploaded', () async {
final rows = FakeAssetGateway();
final cache = MemoryAssetFileCache();
final cache = MemoryFileCache();
final sealedAssets = AssetRepository(
rows,
FakeAssetServerGateway(),
FakeFileServerGateway(),
cache,
FakeAssetSealing(
keys: {'own-tree': 'k-own', 'other-tree': 'k-other'},