SnapshotAgent: Add normalizeBody and normalizeQuery#5121
Draft
GeoffreyBooth wants to merge 1 commit intonodejs:mainfrom
Draft
SnapshotAgent: Add normalizeBody and normalizeQuery#5121GeoffreyBooth wants to merge 1 commit intonodejs:mainfrom
SnapshotAgent: Add normalizeBody and normalizeQuery#5121GeoffreyBooth wants to merge 1 commit intonodejs:mainfrom
Conversation
Adds two new options to SnapshotAgent and SnapshotRecorder for partial request matching: - `normalizeBody(body)` — normalizes the request body before hashing, e.g. to strip volatile fields like timestamps from JSON payloads - `normalizeQuery(params)` — normalizes query parameters (as URLSearchParams) before hashing, e.g. to strip cache-busting params Both options pair with the existing `matchBody`/`matchQuery` boolean toggles and run at both record and playback time so hashes stay consistent across both sides. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5121 +/- ##
=======================================
Coverage 93.14% 93.14%
=======================================
Files 110 110
Lines 35908 35945 +37
=======================================
+ Hits 33446 33482 +36
- Misses 2462 2463 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Adds two new options to
SnapshotAgentandSnapshotRecorderfor partial request matching:normalizeBody(body)— normalizes the request body before hashing, e.g. to strip volatile fields like timestamps from JSON payloadsnormalizeQuery(params)— normalizes query parameters (asURLSearchParams) before hashing, e.g. to strip cache-busting paramsBoth options pair with the existing
matchBody/matchQueryboolean toggles and run at both record and playback time so hashes stay consistent across both sides.This relates to…
SnapshotAgent; #4114Rationale
When recording snapshots, sometimes we don’t want to match on the body or query params exactly; there might be volatile parts of the body or query params to exclude such as timestamps or cache-busters. In my case I want to match on the system prompt of an LLM call, ignoring the rest of the body.
Changes
Adds
normalizeBodyandnormalizeQueryoptions toSnapshotAgent, for users to define functions to simplify the recorded request body or query params before saving; and to run again when computing the hash for matching.Features
Adds
normalizeBodyandnormalizeQueryoptions toSnapshotAgent.Bug Fixes
N/A
Breaking Changes and Deprecations
N/A
Status
I want to test this in my project for which these changes are intended, after which I’ll update this from a draft PR to being ready for review.