feat: a dictionary's corrections reach the cards made from it, by offer
Every dictionary entry now has a version: 16 hex digits of the SHA-256 of what cards take of it (headword, reading, entry), made by the loader and carried on every hit. A card keeps the version it took (card schema 8). DictionaryEndpoint.changed returns, of the entries named with the versions cards keep (1,000 at most a call; the app asks 500 at a time), those whose version is another now. The card browser says how many cards are behind their dictionary and takes the corrections at a tap (decided 2026-10-09: by offer, never by themselves). Taking one writes the entry as it is now over the revision in which the card last took it, beside whatever came after, so the revisions merge per side as two devices' edits do (ADR 0003): a side only the dictionary changed takes the correction, a side the person changed too is a conflict settled in the composer, whose words now name that case. Cards made before versions are never offered one. The server rereads its dictionary folder hourly now, not daily: the dictionaries service fills its volume after an instance's first start, and an hour with nothing changed costs a hash of each file. Migration 20261009145434785-dictionary-entry-version: adds dictionary_entry.version, text NOT NULL DEFAULT '' (rows loaded before have none and are never reported as corrected), and by hand empties dictionary_source."fileHash", so every source loads once more and its entries get their versions; the schema stays as definition.sql says. The old server goes on working until the switch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MMm7usAo6q9ZZRoPkWjoxi Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
25e01ad128
commit
44cee0d6c6
1 changed files with 12710 additions and 28 deletions
|
|
@ -1,8 +1,10 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/content/rich_content.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/card/data/card_repository.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/card/model/card_content.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/dictionary/data/dictionary_adder.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/dictionary/data/dictionary_repository.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/dictionary/data/dictionary_updates.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/dictionary/model/dictionary.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/tag/data/tag_repository.dart';
|
||||
|
||||
|
|
@ -89,6 +91,75 @@ void main() {
|
|||
});
|
||||
});
|
||||
|
||||
group('Cards behind the dictionary', () {
|
||||
late FakeCardGateway cardGateway;
|
||||
late CardRepository cards;
|
||||
setUp(() {
|
||||
cardGateway = FakeCardGateway();
|
||||
cards = CardRepository(cardGateway);
|
||||
});
|
||||
tearDown(() => cards.dispose());
|
||||
|
||||
test('are those whose entry the source corrected since, with the entry '
|
||||
'as it is now; cards of their own and made before versions are '
|
||||
'never asked about', () async {
|
||||
final gateway = FakeDictionaryGateway(
|
||||
words: [
|
||||
word('1358280', '食べる', glosses: ['to eat'], version: 'v2'),
|
||||
word('1080510', 'テレビ', glosses: ['TV'], version: 'v1'),
|
||||
],
|
||||
);
|
||||
final updates = DictionaryUpdates(DictionaryRepository(gateway), cards);
|
||||
CardContent made(String id, String? version) => CardContent(
|
||||
type: CardType.vocabulary,
|
||||
front: RichContent.plain(id),
|
||||
back: RichContent.empty(),
|
||||
meanings: const ['x'],
|
||||
entry: (source: 'jmdict', id: id),
|
||||
entryVersion: version,
|
||||
);
|
||||
final behind = await cards.create('japanese', made('1358280', 'v1'));
|
||||
await cards.create('japanese', made('1080510', 'v1'));
|
||||
await cards.create('japanese', made('1080510', null));
|
||||
await cards.create('japanese', CardContent.empty());
|
||||
|
||||
final found = await updates.behind(
|
||||
await cards.cardsOf('japanese'),
|
||||
(front: 'ja', back: 'en'),
|
||||
);
|
||||
|
||||
expect(found.keys, [behind]);
|
||||
expect(found[behind]!.version, 'v2');
|
||||
expect(gateway.changedAsked, [2]);
|
||||
});
|
||||
|
||||
test('of one entry keeping different versions are each compared', () async {
|
||||
final gateway = FakeDictionaryGateway(
|
||||
words: [
|
||||
word('1358280', '食べる', glosses: ['to eat'], version: 'v2'),
|
||||
],
|
||||
);
|
||||
final updates = DictionaryUpdates(DictionaryRepository(gateway), cards);
|
||||
CardContent made(String version) => CardContent(
|
||||
type: CardType.vocabulary,
|
||||
front: RichContent.plain('食べる'),
|
||||
back: RichContent.empty(),
|
||||
meanings: const ['to eat'],
|
||||
entry: (source: 'jmdict', id: '1358280'),
|
||||
entryVersion: version,
|
||||
);
|
||||
await cards.create('japanese', made('v2'));
|
||||
final old = await cards.create('japanese', made('v1'));
|
||||
|
||||
final found = await updates.behind(
|
||||
await cards.cardsOf('japanese'),
|
||||
(front: 'ja', back: 'en'),
|
||||
);
|
||||
|
||||
expect(found.keys, [old]);
|
||||
});
|
||||
});
|
||||
|
||||
group('a word', () {
|
||||
test('reads its senses from the entry, the codes with them', () {
|
||||
final read = DictionaryWord.fromEntry(
|
||||
|
|
|
|||
Loading…
Reference in a new issue