Repository navigation
fix: keep bytes mocks within Valimock's string bound - #5
Merged
Merged
Conversation
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.
|
The changes in this PR will be included in the next version bump.
|
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.
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.


Summary
Wallaby reported
lexiconMocks > should mock valid data for com.atproto.sync.subscribeRepos#committiming 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
blocksfield is a LexiconbyteswithmaxLength: 2000000. Thebytesformat 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 withonWarn: () => {}.Fix
bytesgenerator caps the decoded size at what fits inctx.bounds.maxbase64 characters. A LexiconmaxLengthis an upper bound, not a target, so a 2 MB CAR file limit now yields a few dozen bytes.min_decoded_byteswidensctx.bounds.maxwhen a Lexicon minimum would not otherwise fit, so such schemas stay satisfiable.Tests
subscribeRepos#commitandsubscribeRepos#sync, the latter having passed silently before.byteslimit mocks to at most 128 characters and aminLength: 200is honored without warnings.Coverage
Coverage went from 89% of statements and 84% of branches to 100% on every metric, and stays there:
base32,lexRefandparseAtUri, which had no direct tests.valimock.tsthat no fixture reaches, every object schema flavor and the empty open union inunion(), reference errors incompileLexicon, and the string, integer, array, XRPC anderrorModebranches oftoLexicon.src/__tests__/fixtures/synthetic.tscover 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 throughcompileLexiconsandtoLexiconlike the published ones and are rendered byfromLexicon.istanbul ignorehints with a one-line reason, which both the v8 remapper and Wallaby honor.vite.config.tssets a 100% coverage threshold and CI runsvp test --coverage, so a regression fails the build.