Skip to content

test(encrypt): cover encryptPipeline, sealRaw and awaitAllOrAbort#117

Merged
rubenhensen merged 1 commit into
mainfrom
test/encrypt-pipeline
Jul 21, 2026
Merged

test(encrypt): cover encryptPipeline, sealRaw and awaitAllOrAbort#117
rubenhensen merged 1 commit into
mainfrom
test/encrypt-pipeline

Conversation

@dobby-coder

@dobby-coder dobby-coder Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

What

Adds unit tests for the encrypt/upload pipeline in src/crypto/encrypt.ts, which previously had no direct coverage.

  • awaitAllOrAbort — the subtle concurrency helper (src/crypto/encrypt.ts:143):
    • resolves without aborting when both sides succeed
    • aborts the controller and re-throws the first error when either the seal side or the pipe side fails first
    • re-throws only the first error and swallows the loser's later rejection (no unhandled rejection)
    • falls back to a parameterless abort() when abort(reason) throws
  • encryptPipeline — happy path (seal → chunk → upload) returns the upload uuid and carries the ZIP bytes through to the sink; an upload-sink failure aborts the shared signal driving the stream graph and re-throws.
  • sealRaw — seals a Uint8Array payload and returns the concatenated ciphertext.

sealStream/loadWasm, fetchMPK, resolveSigningKeys, createZipReadable and the Cryptify upload sink are mocked; the real Chunker/withTransform and policy builders run.

Notes

  • awaitAllOrAbort is now exported so the concurrency logic can be unit-tested directly and deterministically. It is not re-exported from src/index.ts, so the package's public API is unchanged.
  • Each abort-related test was confirmed to fail when the abort/swallow logic is removed.
  • Full suite green locally (npm test: 230 passed) and npm run typecheck clean.

Closes #109

The encrypt/upload pipeline in src/crypto/encrypt.ts had no direct test
coverage. Add unit tests with sealStream/loadWasm and the Cryptify upload
sink mocked:

- awaitAllOrAbort: happy path (no abort), first-failure abort + re-throw
  of the first error from either side, loser-rejection is swallowed (no
  unhandled rejection), and the abort(reason)-throws fallback.
- encryptPipeline: seal -> chunk -> upload happy path returning the uuid,
  and upload-sink failure aborting the shared signal and re-throwing.
- sealRaw: seals a Uint8Array payload and returns concatenated ciphertext.

awaitAllOrAbort is exported for direct testing; it is not re-exported from
src/index.ts, so the package's public API is unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dobby-coder
dobby-coder Bot requested a review from rubenhensen July 17, 2026 17:09

@dobby-coder dobby-coder Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: approve

Rules + review sign-off — clean. No blocking or style findings.

Checked the encrypt-pipeline test PR against the relevant TypeScript / test / PR-process rules:

  • vitest-mock-hoisting ✓ — shared mocks are wrapped in vi.hoisted(() => ({...})) and referenced from the vi.mock factories, so no "cannot access before initialization" hazard.
  • conventional-commit-pr-titles ✓ — test(encrypt): … is valid; pr-title.yml runs on this repo.
  • pr-close-issue-keywords ✓ — Closes #109 on its own line will auto-close the tracking issue on merge.
  • tests-required-on-fixes ✓ — this PR is the coverage; each abort-path test was confirmed to fail when the logic is removed.
  • Exporting awaitAllOrAbort for testability is scoped correctly (not re-exported from src/index.ts), so the public API is unchanged.

Test suite green (230 passed) and typecheck clean per the prior step. Signing off and flipping to ready.

@rubenhensen
rubenhensen merged commit 6c0f554 into main Jul 21, 2026
5 checks passed
@rubenhensen
rubenhensen deleted the test/encrypt-pipeline branch July 21, 2026 14:56
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 2.3.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add test coverage for the encrypt pipeline (encryptPipeline / awaitAllOrAbort)

1 participant