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
4 changed files with 12710 additions and 28 deletions
|
|
@ -208,7 +208,7 @@ void main() {
|
|||
entry: (source: 'kanjidic', id: '食'),
|
||||
);
|
||||
|
||||
expect(cardSchemaVersion, 7);
|
||||
expect(cardSchemaVersion, greaterThanOrEqualTo(7));
|
||||
expect(decodeCardPayload(encodeCardPayload(content)), content);
|
||||
expect(
|
||||
decodePayload(
|
||||
|
|
@ -229,6 +229,33 @@ void main() {
|
|||
expect(before.kunReadings, isEmpty);
|
||||
});
|
||||
|
||||
test('a card keeps the version of the entry it took (schema 8); one from '
|
||||
'before has none', () {
|
||||
final content = CardContent(
|
||||
type: CardType.vocabulary,
|
||||
front: text('食べる'),
|
||||
back: RichContent.empty(),
|
||||
meanings: const ['to eat'],
|
||||
entry: (source: 'jmdict', id: '1358280'),
|
||||
entryVersion: '0123456789abcdef',
|
||||
);
|
||||
|
||||
expect(cardSchemaVersion, 8);
|
||||
expect(decodeCardPayload(encodeCardPayload(content)), content);
|
||||
expect(
|
||||
decodeCardPayload(
|
||||
bytes({
|
||||
'schemaVersion': 7,
|
||||
'type': 'vocabulary',
|
||||
'front': text('食べる').toJson(),
|
||||
'back': RichContent.empty().toJson(),
|
||||
'dictionary': {'source': 'jmdict', 'id': '1358280'},
|
||||
}),
|
||||
).entryVersion,
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
|
||||
test('reads a report of a category it does not know as "other"', () {
|
||||
final content = decodeCardPayload(
|
||||
bytes({
|
||||
|
|
|
|||
|
|
@ -191,6 +191,114 @@ void main() {
|
|||
});
|
||||
});
|
||||
|
||||
group("A dictionary's correction", () {
|
||||
/// The word 食べる, made from JMdict's entry at [version], meaning
|
||||
/// [glosses].
|
||||
CardContent taberu(String version, List<String> glosses) => CardContent(
|
||||
type: CardType.vocabulary,
|
||||
front: RichContent.plain('食べる'),
|
||||
back: RichContent.empty(),
|
||||
reading: 'たべる',
|
||||
senses: [VocabularySense(glosses: glosses)],
|
||||
entry: (source: 'jmdict', id: '1358280'),
|
||||
entryVersion: version,
|
||||
).normalized;
|
||||
|
||||
/// The correction: the senses and version of [taberu].
|
||||
CardContent Function(CardContent) corrected(List<String> glosses) =>
|
||||
(base) => base
|
||||
.copyWith(
|
||||
senses: [VocabularySense(glosses: glosses)],
|
||||
entryVersion: 'v2',
|
||||
)
|
||||
.normalized;
|
||||
|
||||
test('goes whole into a card nobody changed since', () async {
|
||||
final id = await repository.create('japanese', taberu('v1', ['to eat']));
|
||||
|
||||
expect(
|
||||
await repository.takeDictionaryUpdate(
|
||||
id,
|
||||
corrected(['to eat', 'to consume']),
|
||||
),
|
||||
UpdateTaken.taken,
|
||||
);
|
||||
|
||||
final now = (await repository.cardsOf('japanese')).single;
|
||||
expect(now.content.meanings, ['to eat', 'to consume']);
|
||||
expect(now.content.entryVersion, 'v2');
|
||||
expect(now.heads, hasLength(1));
|
||||
});
|
||||
|
||||
test('merges with what the person changed on another side', () async {
|
||||
final id = await repository.create('japanese', taberu('v1', ['to eat']));
|
||||
final made = (await repository.cardsOf('japanese')).single;
|
||||
await repository.save(
|
||||
made,
|
||||
made.content.copyWith(hints: [RichContent.plain('ichidan')]),
|
||||
);
|
||||
|
||||
expect(
|
||||
await repository.takeDictionaryUpdate(
|
||||
id,
|
||||
corrected(['to eat', 'to consume']),
|
||||
),
|
||||
UpdateTaken.taken,
|
||||
);
|
||||
|
||||
final now = (await repository.cardsOf('japanese')).single;
|
||||
expect(now.content.meanings, ['to eat', 'to consume']);
|
||||
expect(now.content.hints, [RichContent.plain('ichidan')]);
|
||||
expect(now.hasConflict, isFalse);
|
||||
});
|
||||
|
||||
test(
|
||||
'is a conflict to settle where the person changed the same side',
|
||||
() async {
|
||||
final id = await repository.create(
|
||||
'japanese',
|
||||
taberu('v1', ['to eat']),
|
||||
);
|
||||
final made = (await repository.cardsOf('japanese')).single;
|
||||
await repository.save(
|
||||
made,
|
||||
made.content
|
||||
.copyWith(
|
||||
senses: [
|
||||
const VocabularySense(glosses: ['to dine']),
|
||||
],
|
||||
)
|
||||
.normalized,
|
||||
);
|
||||
|
||||
expect(
|
||||
await repository.takeDictionaryUpdate(
|
||||
id,
|
||||
corrected(['to eat', 'to consume']),
|
||||
),
|
||||
UpdateTaken.toSettle,
|
||||
);
|
||||
expect(
|
||||
(await repository.cardsOf('japanese')).single.conflicts.keys,
|
||||
contains(CardField.senses),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test('is nothing to a card made before versions', () async {
|
||||
final id = await repository.create(
|
||||
'japanese',
|
||||
taberu('v1', ['to eat']).withField(CardField.entryVersion, null),
|
||||
);
|
||||
|
||||
expect(
|
||||
await repository.takeDictionaryUpdate(id, corrected(['to consume'])),
|
||||
UpdateTaken.none,
|
||||
);
|
||||
expect(gateway.written.where((row) => row.cardId == id), hasLength(1));
|
||||
});
|
||||
});
|
||||
|
||||
test('a card not on this device has no heads', () async {
|
||||
expect(await repository.headsOf('card-9999'), isEmpty);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import 'package:halkyon_learn_flutter/src/feature/studyset/model/studyset_conten
|
|||
import 'package:material_ui/material_ui.dart';
|
||||
|
||||
import '../../../support/fake_card_gateway.dart';
|
||||
import '../../../support/fake_dictionary_gateway.dart';
|
||||
import '../../../support/fake_studyset_gateway.dart';
|
||||
import '../../../support/pump_app.dart';
|
||||
import '../../../support/test_dependencies.dart';
|
||||
|
|
@ -155,6 +156,76 @@ void main() {
|
|||
expect(answer, findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('cards behind the dictionary say so, and take its '
|
||||
'corrections at a tap', (tester) async {
|
||||
tester.view.physicalSize = const Size(1400, 1600);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await cards.create(
|
||||
'words',
|
||||
CardContent(
|
||||
type: CardType.vocabulary,
|
||||
front: RichContent.plain('食べる'),
|
||||
back: RichContent.empty(),
|
||||
reading: 'たべる',
|
||||
senses: const [
|
||||
VocabularySense(glosses: ['to eat']),
|
||||
],
|
||||
entry: (source: 'jmdict', id: '1358280'),
|
||||
entryVersion: 'v1',
|
||||
).normalized,
|
||||
);
|
||||
await pumpApp(
|
||||
tester,
|
||||
testDependencies(
|
||||
studysetGateway: FakeStudysetGateway()
|
||||
..receiveRemoteChange(
|
||||
'words',
|
||||
encodeStudysetPayload(
|
||||
StudysetContent(
|
||||
title: 'Words',
|
||||
description: RichContent.empty(),
|
||||
frontLanguage: 'ja',
|
||||
backLanguage: 'en',
|
||||
),
|
||||
),
|
||||
),
|
||||
cardGateway: cardGateway,
|
||||
dictionaryGateway: FakeDictionaryGateway(
|
||||
words: [
|
||||
word(
|
||||
'1358280',
|
||||
'食べる',
|
||||
reading: 'たべる',
|
||||
glosses: ['to eat', 'to consume'],
|
||||
version: 'v2',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
location: RoutePaths.cardBrowser('words'),
|
||||
);
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
find.text(
|
||||
'1 card is behind the dictionary: its entry was corrected since it '
|
||||
'was made.',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.tap(find.text('Take the corrections'));
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('1 card updated.'), findsOneWidget);
|
||||
expect(find.text('Take the corrections'), findsNothing);
|
||||
final updated = (await cards.cardsOf('words')).single.content;
|
||||
expect(updated.meanings, ['to eat', 'to consume']);
|
||||
expect(updated.entryVersion, 'v2');
|
||||
});
|
||||
|
||||
testWidgets('cards chosen are deleted together, and Undo brings them '
|
||||
'back', (tester) async {
|
||||
await show(tester);
|
||||
|
|
|
|||
|
|
@ -494,7 +494,7 @@ void main() {
|
|||
await open(tester, '猫');
|
||||
|
||||
expect(
|
||||
find.textContaining('changed differently on two devices'),
|
||||
find.textContaining('changed in two ways at once'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Keep this'), findsNWidgets(2));
|
||||
|
|
|
|||
Loading…
Reference in a new issue