test(crypto): add recovery + rotation coverage (rotation had zero tests) - #222
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes Phase 1 §1.6 of
.claude/plans/tech-debt-remediation.md.Summary
Dedicated coverage for
recovery.ts(55L) +rotation.ts(339L). Rotation had zero tests prior to this PR — highest-risk unit in Phase 1.New files
recovery.test.ts(207L) — 14 tests across 5 exports. Realbip39wordlist + real libsodium. CoversgenerateRecoveryPhrase(24-word BIP-39, valid checksum, 64-byte seed, uniqueness),validateRecoveryPhrase(valid/bad-checksum/non-wordlist/empty),phraseToSeeddeterminism,recoverMasterKeyFromPhraseroundtrip vsderiveMasterKey,validateKeyVerifier.rotation.test.ts(779L) — 13 tests across all rotation exports. Real crypto end-to-end.rewrapItemKey— file-key recovery via new vault key;encryptedData/dataNonce/signerDeviceId/originalId/clock/stateVector/deletedAtsurvive; new signature verifies; malformed key-nonce throws.rewrapCrdtSnapshot— Yjs body byte-identical pre/post, wrapped-key region differs, file key recovered matches, new signature verifies.performKeyRotation— happy path (phases: preparing → re-encrypting → finalizing → complete),processedItemsmonotonic tototalItems, pause+resume once, pushed items signed under new vault key, server keys + master-key store invoked.pushItemsexcludes failing id, error matches"Rotation aborted: 1 items failed re-wrap", server keys NOT advanced, sync resumed.Note on mid-rotation semantics
The spec envisioned "items 0..N-1 kept new key, N..end kept old key". The actual
rotation.ts:238-269,301-305catches per-item rewrap errors and aborts at the post-loop guard withRotation aborted: N items failed re-wrap. This PR tests the real behavior; the safety post-conditions that matter (server keys NOT updated, master key NOT stored, sync resumed) are asserted.Test plan
pnpm --filter desktop test --project main src/main/crypto/recovery.test.ts src/main/crypto/rotation.test.ts— 0 failurespnpm typecheck:node && pnpm typecheck:webcleanpnpm lintclean🤖 Generated with Claude Code