Repository navigation
test(vault): pin the on-disk vault format across Android and iOS (PRD Phase 2) - #238
Merged
Merged
Conversation
core:vaultcrypto (Kotlin) and Sources/VaultCrypto (Swift) are two independent implementations of one on-disk format, and nothing verified they agree. A vault written on one platform had never been proven to open on the other, in CI or anywhere else. Every existing test on both sides is a round-trip against itself. A round-trip structurally cannot catch the failure that matters: a wrong-but-deterministic implementation round-trips perfectly and still cannot read the other platform's vaults. Worse, iOS's VaultCryptoTestSupport.swift was written to mirror the *shape* of Android's tests, so a shared misunderstanding of the format would have been invisible on both sides at once. Adds testdata/vault-format/v1/golden.vault — 228 bytes, generated by the Android writer, committed. Both platforms now assert: - the writer reproduces the fixture BYTE FOR BYTE, and - the reader recovers the exact plaintext from it. Byte equality is available because the format is fully deterministic: nonces are derived rather than random, and there is no per-file random IV or salt in the blob. That makes this far stronger than "each platform can read its own output". One fixture transitively pins a lot. HKDF has no known-answer test of its own on either platform — Hkdf.kt had zero test references before this — but any change to it moves the file content key, which moves every chunk's ciphertext, which fails here. Same for the AAD layout, header layout, chunk-count rule and final-chunk flag. Hkdf goes 0% -> 100% covered, and core:vaultcrypto 90.3% -> 91.0% (baseline raised accordingly). Fixture parameters are deliberate: a 64-byte chunk over 150 bytes of plaintext spans three chunks (64 + 64 + 22), so multi-chunk nonce derivation and a partial final chunk are exercised rather than a single-chunk happy path. Plaintext is defined by formula, not shipped as a second file, so both languages reproduce it exactly with no text-encoding ambiguity. testdata/vault-format/** is added to agent-policy.yml's sensitive_paths. The failure mode here is silent: regenerating a fixture makes a failing interop test pass while actually recording the break. A changed byte means either a deliberate format version bump or every existing vault just became unreadable — never something to auto-merge. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
📱 iOS Build Status: PASSED✅ iOS Simulator Build & Unit Tests - success iOS UI tests run in a separate, informational job and are not reflected above — check "iOS UI Tests (informational)" for those. |
…ixture Principal review of this PR, on my own code. Three of the four Kotlin tests used Assumptions.assumeTrue(fixture.isFile), so a missing fixture turned them green-by-skipping while only the writer test went red. A silently skipped interop test is indistinguishable from a passing one on a CI dashboard — which is exactly the failure mode this class exists to prevent, reintroduced by the class's own scaffolding. The Swift side already asserted; the two were inconsistent. Making them assert exposed a second problem: JUnit gives no ordering guarantee between test methods, so regenerating the fixture inside the writer test let the reader tests run first and fail against a file that did not exist yet — a deliberate regeneration came out red despite producing a correct file. Regeneration now happens once in @BeforeAll, so every per-test assertion stays strict and a regeneration run is still green. Also corrects the documented regeneration command, which was wrong in two ways that would each have wasted someone's time: it named the lifecycle task (which rejects --tests on an Android module) and passed -D (which Gradle does not forward to the forked test JVM). Verified both paths: normal run 4/4 pass 0 skipped; regeneration from a deleted fixture also 4/4 pass and reproduces the committed file byte-for-byte. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
📱 iOS Build Status: PASSED✅ iOS Simulator Build & Unit Tests - success iOS UI tests run in a separate, informational job and are not reflected above — check "iOS UI Tests (informational)" for those. |
libravault-xyz
added a commit
that referenced
this pull request
Aug 17, 2026
…869 (PRD Phase 3a) (#243) * fix(ci): clear stale status labels on dev-agent/principal-review crash dev-agent.yml's triage-crash branch (no PR found yet) only stripped status:in-progress, leaving status:ready-for-dev in place if the crash happened after triage self-applied it. Re-triggering the pipeline by clearing status:needs-info alone would then silently re-fire triage without a human ever having looked at the issue. principal-review.yml's crash branch had the same gap for a re-review round: it stripped status:needs-review but never cleared a stale status:approved-auto-merge/status:needs-human-merge left over from an earlier round on the same PR (the verdict path below already does this cleanup, but crashes skip that path entirely). Both branches now clear every stale outcome label alongside adding status:needs-info. Closes #236 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * fix(vaultcrypto): HKDF rejected a zero-length salt, contrary to RFC 5869 PRD Phase 3. Hkdf.kt had zero test references anywhere in the repo (an S1 gap) — exercised only indirectly through vault round-trips, which is exactly the coverage shape that hides a broken KDF: a wrong-but-deterministic HKDF round-trips perfectly and every existing test still passes. Adding RFC 5869 Appendix A known-answer tests found a real conformance bug. `Hkdf.extract` passed the salt straight to SecretKeySpec, which rejects a zero-length key with `IllegalArgumentException: Empty key`, so vector A.3 (zero-length salt and info) threw instead of deriving. RFC 5869 §2.2 requires an absent salt be treated as HashLen zero bytes. Not exploitable, and not a behaviour change for this app: the only production caller (deriveFileContentKey) passes a fixed non-empty salt, and the empty-salt path previously *threw* rather than returning a value, so no stored key material can depend on the old behaviour. The golden vault fixture proves it: its sha256 is byte-identical before and after this change, and all 224 tests across the four vault modules still pass. iOS never had this gap — it calls CryptoKit.HKDF, which does the substitution itself. Which is the point of testing against the standard rather than only against the other platform: PR #238's golden fixture proves Android and iOS agree with each other, and by construction cannot notice both of them (or, as here, the hand-rolled one) diverging from the spec on a path neither exercises. Also adds direct tests for deriveFileContentKey on both platforms, and for the iOS primitives that had zero references — BigEndian, SecureRandom, secureZero. The file-content-key vector is a shared constant asserted identically in Kotlin and Swift, pinning the salt/info composition across two different HKDF implementations (hand-rolled vs CryptoKit). All expected values were computed independently (Python hmac/hashlib) from the documented inputs, not captured from our own output, so they are genuine known-answers rather than regression snapshots. core:vaultcrypto 91.0% -> 91.3%; baseline raised. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * test(database): run the whole v1 -> v7 migration chain against real SQLite PRD Phase 3, Room half. Six migrations exist; two had execution coverage. MIGRATION_4_5 was tested against a *mocked* SupportSQLiteDatabase asserting SQL substrings — which verifies the string looks right, not that SQLite accepts it — and only MIGRATION_6_7 ran for real. Migrations 1→2, 2→3, 3→4 and 5→6 had none. Adds MigrationChainTest: builds a real v1 database, seeds every v1 table, and lets Room apply all six migrations in sequence, then asserts - the chain completes and passes Room's own schema validation (via a real query, since Room only validates when one runs — merely opening the database would pass against a broken schema), - v1 rows survive with correct values, and columns added mid-chain carry their declared defaults, - tables introduced mid-chain (highlights at 1→2, collections at 2→3) exist and accept writes at v7, - the CASCADE deletes on those tables are actually in force afterwards, not merely present in the DDL text. A chain rather than four isolated tests, deliberately: the sequence is what users execute — someone opening an old install after a long gap — and isolated tests cannot catch an interaction between migrations. Also fixes exportSchema being a no-op. LibravaultDatabase declares exportSchema = true, but without room.schemaLocation Room had nowhere to write and silently exported nothing, which is why core/database/schemas/ did not exist. 7.json is now generated and committed, so from v7 onward Room validates migration end-states at build time and MigrationTestHelper can construct any exported version. It cannot help retroactively for v1..v6 — those schemas were never exported — which is exactly why the chain test derives v1 instead. The v1 DDL is derived, not guessed: migrations are the complete record of schema change, so v1 = the verbatim v6 capture already in Migration6To7RealExecutionTest minus precisely what migrations 1→6 add. Writing this caught one of my own wrong assumptions rather than a product bug: markdownScrollOffset is transient. 5→6 adds it as INTEGER pixels, 6→7 replaces it with markdownScrollFraction (REAL) and sets it NULL for every migrated row, because a pixel offset cannot be converted to a fraction without the document height. The test now asserts that deliberate behaviour, verified against the newly-exported schema. core:database 63.3% -> 67.4%. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * docs: mark PRD Phase 3 complete All five S1 gaps from the original inventory are now closed: cross-platform vault interop (#238), HKDF known-answer coverage (this PR), the dead emulator gate and the never-run TTS gate (#222/#226), and dev branch protection (#222). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This was referenced Aug 17, 2026
Closed
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.
Phase 2 of
docs/TEST_COVERAGE_PRD.md— the highest-severity gap in the inventory.The gap
core:vaultcrypto(Kotlin) andSources/VaultCrypto(Swift, merged 2026-08-16 in #220) are two independent implementations of one on-disk format, and nothing verified they agree. A vault written on one platform had never been proven to open on the other — not in CI, not anywhere.Every existing test on both sides is a round-trip against itself: encrypt, decrypt, assert you got back what you put in. A round-trip structurally cannot catch the failure that matters here. A wrong-but-deterministic implementation round-trips perfectly and still cannot read the other platform's vaults.
Worse, iOS's
VaultCryptoTestSupport.swiftdescribes itself as centralising "what Android's" tests do — it mirrors the shape of Android's tests. So a shared misunderstanding of the format would have been invisible on both sides simultaneously.The fix
testdata/vault-format/v1/golden.vault— 228 bytes, generated by the Android writer, committed. Both platforms now assert two things against it:Byte equality is available because the format is fully deterministic — nonces are derived, not random, and there is no per-file random IV or salt in the blob. That makes this materially stronger than "each platform can read its own output".
What one fixture transitively pins
Hkdf/deriveFileContentKey)VaultFormat.chunkAad)Hkdf.kthad zero test references before this (an S1 item in the PRD). It is now at 100% line coverage, andcore:vaultcryptowent 90.3% → 91.0% — baseline raised in this PR so the gain is locked in by the Phase 1 gate.A standalone RFC 5869 known-answer test is still worth having (Phase 3) — the fixture proves the two platforms agree, but not that they agree with the RFC.
Fixture design
p[i] = (i*7+11) % 251), not a second binary file — both languages reproduce it exactly with no text-encoding ambiguity.Review notes
testdata/vault-format/**added toagent-policy.ymlsensitive_paths. The failure mode is silent: regenerating a fixture makes a failing interop test pass while recording the break. A changed byte means either a deliberate version bump or every existing vault just became unreadable — never auto-mergeable.VAULTCRYPTO_REGENERATE_GOLDEN=true) and lands in review as a changed binary.testdata/vault-format/README.mddocuments what to do when a test against the fixture fails.Build & Test iOS (Simulator)on this PR is its first execution and is the check to watch.🤖 Generated with Claude Code