Skip to content

test(web): cover base64 encode/decode roundtrip and chunking boundary - #211

Open
dirtybits wants to merge 1 commit into
mainfrom
fix/add-base64-unit-tests
Open

dirtybits wants to merge 1 commit into
mainfrom
fix/add-base64-unit-tests

Conversation

@dirtybits

Copy link
Copy Markdown
Owner

Summary

Adds a dedicated unit test for web/lib/base64.ts — the bytes-only base64
helpers used on the auth and transaction path (wallet signatures, serialized
base64 transactions, account data). These had no dedicated test file despite
being security- and money-adjacent, while sibling boundary helpers
(chainAddress.ts, registeredAt.ts) are pinned with behavioral tests
(AGENTS.md §3.24: pure helpers get real behavioral tests, not grep-tests).

The test pins:

  • encodeBase64(new Uint8Array(0)) → ""
  • known-value roundtrips, including 0x00/0xff/0x80 and 12-byte input
  • encodeBase64 output is byte-identical to the Buffer.from(...).toString( "base64") reference across 0, 1_000, and 10_000-byte inputs
  • roundtrips across the 0x8000 String.fromCharCode chunk boundary
    (the chunkSize = 0x8000 constant exists to keep btoa spreads under the
    argument limit; sizes at and past the boundary are pinned explicitly)
  • the btoa and Buffer fallback branches agree on a 2048-byte input (the
    btoa branch is hidden and restored in a finally block)

Tests / verification

  • npm test --workspace @agentvouch/web -- base64 → 1 file, 5 tests passed
  • Full web suite: 142 files / 1187 tests passed (no regressions)
  • npm run format:check → pass
  • npm run typecheck (web) → pass
  • npm run lint:web → pass
  • Webpack compile + TS typecheck pass. The static-generation/prerender phase
    fails in the local Linux sandbox because DATABASE_URL (a gitignored Vercel
    env secret) is absent — a pre-existing environment condition, not this change
    (the PR adds only a test file under web/__tests__, never compiled into the
    build). Vercel is the authoritative web build gate.

Not verified

  • Vercel production build (gated by the platform's env); local webpack build
    is blocked on missing DATABASE_URL, attributed to the sandbox, not the diff.

Scope

One new file: web/__tests__/lib/base64.test.ts. No source changes.

Adds a dedicated unit test for web/lib/base64.ts, which was previously
uncovered (no base64 test file) despite sitting on the auth and transaction
path (signatures, serialized base64 transactions, account data).

Covered behavior:
- empty -> empty encoding
- known-value roundtrips (including 0x00/0xff/0x80)
- encode output byte-identical to the Buffer reference across many lengths
- roundtrips across the 0x8000 String.fromCharCode chunk boundary (the
  chunkSize constant keeps btoa spreads under the argument limit)
- btoa and Buffer fallback branches agree

Verified locally:
- npm test --workspace @agentvouch/web -- base64  (5 passed)
- full web suite: 142 files / 1187 tests passed
- format:check, typecheck, lint:web all pass

This branch was successfully deployed

1 active deployment
Preview — f1df641c Deployed Sep 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant