-
Notifications
You must be signed in to change notification settings - Fork 1
test: add local patch application for verification #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: add local patch application for verification #40
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
a857791 to
fc6ce17
Compare
fe681e7 to
7c56fc3
Compare
fc6ce17 to
20fd215
Compare
7c56fc3 to
dda33fd
Compare
20fd215 to
1654acc
Compare
1654acc to
8f32025
Compare
rexxars
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this is testing the SDK patch application more than this module 😅
Can we make the integration suite run both the SDK tests and the actual API integration tests? I feel strongly that we should be testing both
dda33fd to
d4a9699
Compare
8f32025 to
c5e2f7f
Compare
- Move KeyedSanityObject interface to paths.ts to resolve circular imports - Add applyPatches helper and patchOperations reference implementation from SDK - Update all tests to verify patches can be applied correctly using local implementation - Make integration tests work with or without Sanity client configuration - Fix set-and-unset fixture to use null instead of undefined for array values This enables testing patch correctness without requiring Sanity client setup and provides candidates for future SDK extraction.
c5e2f7f to
e35e767
Compare
you know, i caught a few bugs while i threw this in there and there was some motivation to see what our compliance is like 😅. in the future, i'd like to move this file into its own repo (maybe |

This PR enhances the test suite by introducing a local patch application mechanism. This allows us to verify the correctness of the generated patches by applying them to the source document and comparing the result against the expected target document, all without needing to hit a live Sanity backend.
Key Changes:
test/helpers/patchOperations.ts:set,unset,insert,diffMatchPatch,ifRevisionID) that simulate the application of Sanity patch operations to a JavaScript object.@sanity/sdk(specificallycore/src/document/patchOperations.ts) to ensure consistency with how Sanity itself processes patches.jsonMatchand related path parsing utilities (also adapted from@sanity/sdk) to correctly target values within the document based on Sanity path expressions.KeyedSanityObjecttype andisKeyedObjectutility were moved fromsrc/diffPatch.tstosrc/paths.tsto be accessible by these helpers and the main library code.test/helpers/applyPatches.ts:applyPatches(source: DocumentStub, patches: SanityPatchMutation[]): DocumentStubhelper function.SanityPatchMutationobjects and uses the operations frompatchOperations.tsto apply them sequentially to a source document.*.test.tsfiles) have been updated to useapplyPatches.diffPatch, the tests now also callexpect(applyPatches(source, patches)).toEqual(target)to ensure the patches transform the source into the target correctly.integration.test.tsfile, which previously relied solely ondryRuncommits to a Sanity backend, can now also leverage the localapplyPatchesif Sanity client configuration is missing. This makes the integration tests more robust and runnable in environments without backend access.test/fixtures/set-and-unset.tsfixture (b.arr) was updated to usenullinstead ofundefinedto align with the newundefined-to-nullconversion behavior and ensure tests pass with the local patch application.Rationale:
dryRuncommits to a backend, speeding up the test suite.Note: While this PR adds significant value to the test suite, the introduction of the patch application logic (adapted from the SDK) does add a considerable amount of code to the test helpers. If this is deemed too complex or adds too much maintenance overhead for a testing utility within this specific library, this PR could potentially be omitted, and we could continue to rely on integration tests with a backend for end-to-end verification. However, the benefits of local verification are substantial for development speed and confidence.