feat(block1): inventory walking skeleton + first quick-add slice
Stand up the Tanemaki monorepo and the first end-to-end vertical slice of Block 1 (offline, encrypted inventory): add a seed → see it in a categorized, searchable list → it persists → reopen and it's still there. Architecture (state management like G1nkgo, adapted to Tane's reality): - flutter_bloc (Cubit-first), but the encrypted Drift DB is the single source of truth; cubits stream from repositories (no hydrated_bloc/Hive, which would write plaintext at rest). - get_it composition root; go_router; slang i18n (ES/EN, Weblate-friendly JSON). Workspace & core: - pub workspace: packages/commons_core (pure Dart) + apps/app_seeds (Flutter). - commons_core primitives: UUIDv7 IdGen, Hybrid Logical Clock, Quantity value type (+ plant-aware QuantityKind), IdentityService root-seed stub. Data & security: - Drift schemaVersion=1 with all 10 Block-1 tables + common CRDT columns (HLC updated_at, last_author, tombstones); Movement append-only. - SQLCipher via an injectable executor that refuses to open a plaintext DB; DB key + root seed in the OS keystore (separate secrets). - Exported drift_schema_v1.json + migration scaffold. Tests (near-TDD; nothing merges without tests): - commons_core units (24), Drift migration test, "no plaintext at rest" security guard (runs where SQLCipher is present, skips otherwise), repository, widget, full quick-add flow, file-reopen persistence, and a no-hardcoded-strings i18n guard. GitLab CI: format + analyze + test + coverage. Follow-on Block-1 stories (item detail/edit, species catalog, germination UI) and all of Block 2 remain out of scope.
This commit is contained in:
parent
57c0eeadaf
commit
040f15a898
131 changed files with 19855 additions and 20 deletions
37
apps/app_seeds/test/data/persistence_test.dart
Normal file
37
apps/app_seeds/test/data/persistence_test.dart
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:commons_core/commons_core.dart';
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:tane/data/variety_repository.dart';
|
||||
import 'package:tane/db/database.dart';
|
||||
|
||||
/// Proves the "reopen and it's still there" half of the sprint's definition of
|
||||
/// done at the persistence layer, on a real on-disk file (unencrypted here so
|
||||
/// it runs on any host — encryption at rest is covered by no_plaintext_test).
|
||||
void main() {
|
||||
test('a seed survives closing and reopening the database file', () async {
|
||||
final dir = await Directory.systemTemp.createTemp('tane_persist');
|
||||
addTearDown(() => dir.delete(recursive: true));
|
||||
final file = File(p.join(dir.path, 'inventory.sqlite'));
|
||||
|
||||
var db = AppDatabase(NativeDatabase(file));
|
||||
await VarietyRepository(
|
||||
db,
|
||||
idGen: IdGen(),
|
||||
nodeId: 'n',
|
||||
).addQuickVariety(label: 'Persisted tomato');
|
||||
await db.close();
|
||||
|
||||
db = AppDatabase(NativeDatabase(file));
|
||||
final items = await VarietyRepository(
|
||||
db,
|
||||
idGen: IdGen(),
|
||||
nodeId: 'n',
|
||||
).watchInventory().first;
|
||||
await db.close();
|
||||
|
||||
expect(items.map((i) => i.label), ['Persisted tomato']);
|
||||
});
|
||||
}
|
||||
76
apps/app_seeds/test/data/variety_repository_test.dart
Normal file
76
apps/app_seeds/test/data/variety_repository_test.dart
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:commons_core/commons_core.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tane/data/variety_repository.dart';
|
||||
import 'package:tane/db/database.dart';
|
||||
import 'package:tane/db/enums.dart';
|
||||
|
||||
import '../support/test_support.dart';
|
||||
|
||||
void main() {
|
||||
late AppDatabase db;
|
||||
late VarietyRepository repo;
|
||||
|
||||
setUp(() {
|
||||
db = newTestDatabase();
|
||||
repo = newTestRepository(db);
|
||||
});
|
||||
tearDown(() => db.close());
|
||||
|
||||
test(
|
||||
'addQuickVariety persists a variety that appears in the stream',
|
||||
() async {
|
||||
await repo.addQuickVariety(
|
||||
label: 'Grandma tomato',
|
||||
category: 'Solanaceae',
|
||||
);
|
||||
final items = await repo.watchInventory().first;
|
||||
expect(items.single.label, 'Grandma tomato');
|
||||
expect(items.single.category, 'Solanaceae');
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'a quantity creates a Lot and a photo creates an encrypted-BLOB Attachment',
|
||||
() async {
|
||||
final id = await repo.addQuickVariety(
|
||||
label: 'Maize',
|
||||
quantity: const Quantity(kind: QuantityKind.cob),
|
||||
photoBytes: Uint8List.fromList([1, 2, 3]),
|
||||
);
|
||||
|
||||
final lot = await db.select(db.lots).getSingle();
|
||||
expect(lot.varietyId, id);
|
||||
expect(lot.quantityKind, 'cob');
|
||||
|
||||
final attachment = await db.select(db.attachments).getSingle();
|
||||
expect(attachment.parentType, ParentType.variety);
|
||||
expect(attachment.parentId, id);
|
||||
expect(attachment.kind, AttachmentKind.photo);
|
||||
expect(attachment.bytes, [1, 2, 3]);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'stream is ordered by category then label and excludes soft-deleted rows',
|
||||
() async {
|
||||
await repo.addQuickVariety(label: 'Bean', category: 'Fabaceae');
|
||||
await repo.addQuickVariety(label: 'Apple', category: 'Rosaceae');
|
||||
await repo.addQuickVariety(label: 'Almond', category: 'Rosaceae');
|
||||
|
||||
final items = await repo.watchInventory().first;
|
||||
expect(items.map((i) => i.label), ['Bean', 'Almond', 'Apple']);
|
||||
},
|
||||
);
|
||||
|
||||
test('writes stamp a monotonic HLC into updated_at', () async {
|
||||
await repo.addQuickVariety(label: 'First');
|
||||
await repo.addQuickVariety(label: 'Second');
|
||||
final rows = await db.select(db.varieties).get();
|
||||
final stamps = rows.map((r) => r.updatedAt).toList()..sort();
|
||||
// Distinct, parseable, ordered HLC stamps.
|
||||
expect(stamps.toSet().length, 2);
|
||||
expect(() => stamps.map(Hlc.parse).toList(), returnsNormally);
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue