Skip to content

fix: keep bytes mocks within Valimock's string bound - #5

Merged
Saeris merged 2 commits into
mainfrom
fix/bytes-mock-bounds
Nov 5, 2026
Merged

Saeris merged 2 commits into
mainfrom
fix/bytes-mock-bounds

Conversation

@Saeris

@Saeris Saeris commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Summary

Wallaby reported lexiconMocks > should mock valid data for com.atproto.sync.subscribeRepos#commit timing out at 5 seconds. It was not flaky in the random sense but deterministically slow: about 1.1 seconds per mock, three mocks per test, plus Wallaby's instrumentation overhead.

Cause

The blocks field is a Lexicon bytes with maxLength: 2000000. The bytes format generator picked a random decoded size up to that limit and emitted up to 2.7 MB of base64. Valimock caps strings at 128 characters unless the schema says otherwise, so it rejected the value and regenerated it sixteen times before surfacing a warning, which the test silenced with onWarn: () => {}.

Fix

  • The bytes generator caps the decoded size at what fits in ctx.bounds.max base64 characters. A Lexicon maxLength is an upper bound, not a target, so a 2 MB CAR file limit now yields a few dozen bytes.
  • min_decoded_bytes widens ctx.bounds.max when a Lexicon minimum would not otherwise fit, so such schemas stay satisfiable.

Tests

  • The integration test now collects Valimock warnings and asserts none per schema. Without the fix this fails for both subscribeRepos#commit and subscribeRepos#sync, the latter having passed silently before.
  • A focused test checks a 2 MB bytes limit mocks to at most 128 characters and a minLength: 200 is honored without warnings.
  • The valimock test file drops from several seconds to about 600 ms.

Coverage

Coverage went from 89% of statements and 84% of branches to 100% on every metric, and stays there:

  • New unit tests for base32, lexRef and parseAtUri, which had no direct tests.
  • Tests for the generators and fallbacks in valimock.ts that no fixture reaches, every object schema flavor and the empty open union in union(), reference errors in compileLexicon, and the string, integer, array, XRPC and errorMode branches of toLexicon.
  • Six synthetic Lexicon documents under src/__tests__/fixtures/synthetic.ts cover the spec features the published fixtures do not use (enums, constants, byte and grapheme minimums, nullable optionals, open unions without variants, top-level primitives, and every optional XRPC part). They round-trip through compileLexicons and toLexicon like the published ones and are rendered by fromLexicon.
  • Ten defensive branches that Valibot's own types make unreachable carry istanbul ignore hints with a one-line reason, which both the v8 remapper and Wallaby honor.
  • vite.config.ts sets a 100% coverage threshold and CI runs vp test --coverage, so a regression fails the build.

Mocking `com.atproto.sync.subscribeRepos#commit` took over a second and timed out under Wallaby. Its `blocks` field is a Lexicon `bytes` with `maxLength: 2000000`, and the `bytes` format generator picked a random size up to that limit, producing megabytes of base64 that Valimock rejected against its 128 character string bound and regenerated sixteen times before giving up with a warning. The generator now caps the decoded size at what fits in `ctx.bounds.max`, and `min_decoded_bytes` widens the bound when a Lexicon minimum would not otherwise fit. The integration test no longer silences Valimock warnings and asserts there are none, since a retry-budget warning is both a generator that disagrees with the schema and the slow path.
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

bumpy-frog

The changes in this PR will be included in the next version bump.

patch Patch releases

  • @saeris/valicon 0.2.0 → 0.2.1

Bump files in this PR

Click here if you want to add another bump file to this PR


This comment is maintained by bumpy.

Adds tests for the paths no published Lexicon fixture exercises: base32 decoding, Lexicon reference spelling, AT URI fragments, the unused mock generators and their fallbacks, every object schema flavor and the empty open union, XRPC and reference errors in compileLexicon, and the string, integer, array, XRPC and errorMode branches of toLexicon. Synthetic Lexicon documents cover the spec features the fixtures do not use and are round-tripped like the published ones. The handful of defensive branches that Valibot types make unreachable carry istanbul ignore hints with a reason. Coverage is configured with a 100% threshold and CI now runs the tests with coverage.
@Saeris
Saeris merged commit 40a3ca0 into main Nov 5, 2026
4 checks passed
@Saeris
Saeris deleted the fix/bytes-mock-bounds branch November 5, 2026 00:23
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