Pip lets you move your progress to another device with no account: you copy a short code on one device and paste it on the other, or scan a QR. That lives in src/lib/transfer.ts, and it has no tests.
It is the path where a mistake costs someone their progress, so it deserves them.
The task
Add an AVA test file (tests/transfer.test.ts) covering encodeEnvelope() and decodeCode():
- Round trip. Encode an envelope, decode it, and check you get the same profile back. Build the envelope by hand in the test rather than through
profileCode(), which reads the live store.
- The prefixes. A gzipped code starts
pip1:, a raw one pip0:. Check the encoder produces the compressed form where CompressionStream exists, and that a pip0: code still decodes.
- The rejection paths, which are the point. All three of these must come back
{ ok: false } with a message and must never throw: a string with no prefix at all, a pip1: code with the base64 truncated, and a code whose payload decodes to valid JSON that is not a Pip envelope.
Everything decodes through validateEnvelope in src/lib/backup.ts, so read that first: it tells you what shape a valid envelope is and what a rejection looks like.
Getting started
pnpm install
pnpm test # the AVA suite
Both functions are async, so your tests will be too. tests/syncErrors.test.ts is a good one to copy the shape from.
A fair warning: this is the meatier of the two testing issues currently open (the other is #54, which is a gentler start). Nothing here is hard, but there is more to read before you write the first line.
Done when
pnpm test:all passes, a round trip is proven lossless, and all three bad-input paths are covered and return a message rather than throwing.
New here? See CONTRIBUTING.md. Merged work puts your name on playpip.io/credits.
Pip lets you move your progress to another device with no account: you copy a short code on one device and paste it on the other, or scan a QR. That lives in
src/lib/transfer.ts, and it has no tests.It is the path where a mistake costs someone their progress, so it deserves them.
The task
Add an AVA test file (
tests/transfer.test.ts) coveringencodeEnvelope()anddecodeCode():profileCode(), which reads the live store.pip1:, a raw onepip0:. Check the encoder produces the compressed form whereCompressionStreamexists, and that apip0:code still decodes.{ ok: false }with a message and must never throw: a string with no prefix at all, apip1:code with the base64 truncated, and a code whose payload decodes to valid JSON that is not a Pip envelope.Everything decodes through
validateEnvelopeinsrc/lib/backup.ts, so read that first: it tells you what shape a valid envelope is and what a rejection looks like.Getting started
Both functions are
async, so your tests will be too.tests/syncErrors.test.tsis a good one to copy the shape from.A fair warning: this is the meatier of the two testing issues currently open (the other is #54, which is a gentler start). Nothing here is hard, but there is more to read before you write the first line.
Done when
pnpm test:allpasses, a round trip is proven lossless, and all three bad-input paths are covered and return a message rather than throwing.New here? See CONTRIBUTING.md. Merged work puts your name on playpip.io/credits.