mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-17 21:25:05 +01:00
main was red on file length, the noqa ban, codespell, test naming and dart coverage; this change touches every one of those jobs. - sickdays: set_enabled is keyword-only; the panel test splits in two with shared probes; the sync wire format moves to DOCS-sync.md. - earned_time: _focus types the project as a Protocol, no noqa; the gate-maturity section moves to DOCS-maturity.md; codespell knows the `checkin` event name. - focus_project: real fixes for every noqa (local-day clocks, typed fakes, logged broad catches, split helpers). The public API that focus-guard calls keeps its signatures; their PLR0913 exemption lives in pyproject with the reason, not in noqa. - crdt-sync: pylint gets nacl/argon2, docstrings, and allows the public E2eLayout.of; _blobs moves to _e2e_blobs.py. - crdt_sync_dart: Argon2Params and the header errors move to e2e_params.dart (re-exported); tests split and reach 100% lines. - sql_drills: test helpers get a leading underscore, as in earned_time. Todo: fda71ed1 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
113 lines
3.4 KiB
Dart
113 lines
3.4 KiB
Dart
/// openEncryptedStore must not pay Argon2id or a full copy on every tick.
|
|
library;
|
|
|
|
import 'package:crdt_sync/crdt_sync.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'e2e_fakes.dart';
|
|
|
|
const _old = 'app/notes';
|
|
|
|
void main() {
|
|
setUp(resetE2eCopyMemo);
|
|
|
|
test('a cached key skips Argon2 and still unlocks', () async {
|
|
final remote = MemoryRemote();
|
|
List<int>? cached;
|
|
var derived = 0;
|
|
Future<E2eState> open() => openEncryptedStore(
|
|
store: remote,
|
|
oldPrefix: _old,
|
|
readPassphrase: () async => 'pw',
|
|
params: cheapArgon,
|
|
keyCache: E2eKeyCache(
|
|
read: () async => cached,
|
|
write: (bytes) async => cached = bytes,
|
|
),
|
|
onDerive: () => derived++,
|
|
);
|
|
expect(await open(), isA<E2eReady>());
|
|
expect(cached, hasLength(32));
|
|
expect(await open(), isA<E2eReady>());
|
|
expect(derived, 1);
|
|
});
|
|
|
|
test('a stale cached key falls back to the passphrase', () async {
|
|
final remote = MemoryRemote();
|
|
List<int>? cached = List<int>.filled(32, 9);
|
|
final state = await openEncryptedStore(
|
|
store: remote,
|
|
oldPrefix: _old,
|
|
readPassphrase: () async => 'pw',
|
|
params: cheapArgon,
|
|
keyCache: E2eKeyCache(
|
|
read: () async => cached,
|
|
write: (bytes) async => cached = bytes,
|
|
),
|
|
);
|
|
expect(state, isA<E2eReady>());
|
|
expect(cached, isNot(List<int>.filled(32, 9)));
|
|
});
|
|
|
|
test('the copy reruns only when old revisions change', () async {
|
|
final remote = MemoryRemote({
|
|
'$_old/pc/log.json': encodeLog(logOf({'a': 'x'})),
|
|
'app/revs/pc': 'r1',
|
|
});
|
|
Future<void> open() => openEncryptedStore(
|
|
store: remote,
|
|
oldPrefix: _old,
|
|
readPassphrase: () async => 'pw',
|
|
params: cheapArgon,
|
|
);
|
|
await open();
|
|
remote.reads.clear();
|
|
await open();
|
|
expect(remote.reads.where((p) => p.startsWith('app/notes-e2e/')), isEmpty);
|
|
remote.files['$_old/pc/log.json'] = encodeLog(logOf({'a': 'x', 'b': 'y'}));
|
|
remote.files['app/revs/pc'] = 'r2';
|
|
await open();
|
|
final state =
|
|
await openEncryptedStore(
|
|
store: remote,
|
|
oldPrefix: _old,
|
|
readPassphrase: () async => 'pw',
|
|
params: cheapArgon,
|
|
)
|
|
as E2eReady;
|
|
final text = await state.store.getFileText('app/notes-e2e/pc/log.json');
|
|
expect(decodeLog(text!).keys, unorderedEquals(['a', 'b']));
|
|
});
|
|
|
|
test('bulk reads of a data dir come back decrypted', () async {
|
|
final remote = MemoryRemote();
|
|
final state =
|
|
await openEncryptedStore(
|
|
store: remote,
|
|
oldPrefix: _old,
|
|
readPassphrase: () async => 'pw',
|
|
params: cheapArgon,
|
|
)
|
|
as E2eReady;
|
|
final log = encodeLog(logOf({'k': 'secret'}));
|
|
await state.store.putFileText('app/notes-e2e/k1', log, message: 'm');
|
|
expect(remote.files['app/notes-e2e/k1'], isNot(contains('secret')));
|
|
final map = await state.store.getStringMap('app/notes-e2e');
|
|
expect(map['k1'], log);
|
|
});
|
|
|
|
test('a cache that reports a bad header locks as badHeader', () async {
|
|
final state = await openEncryptedStore(
|
|
store: MemoryRemote(),
|
|
oldPrefix: _old,
|
|
readPassphrase: () async => 'pw',
|
|
params: cheapArgon,
|
|
keyCache: E2eKeyCache(
|
|
read: () async => throw E2eHeaderError('bad header'),
|
|
write: (_) async {},
|
|
),
|
|
);
|
|
expect((state as E2eLocked).reason, E2eLockReason.badHeader);
|
|
});
|
|
}
|