Skip to content

SnapshotAgent: Add normalizeBody and normalizeQuery#5121

Draft
GeoffreyBooth wants to merge 1 commit intonodejs:mainfrom
GeoffreyBooth:snapshot-agent-normalize-body-and-query-params
Draft

SnapshotAgent: Add normalizeBody and normalizeQuery#5121
GeoffreyBooth wants to merge 1 commit intonodejs:mainfrom
GeoffreyBooth:snapshot-agent-normalize-body-and-query-params

Conversation

@GeoffreyBooth
Copy link
Copy Markdown
Member

@GeoffreyBooth GeoffreyBooth commented Apr 26, 2026

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.

This relates to…

SnapshotAgent; #4114

Rationale

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 normalizeBody and normalizeQuery options to SnapshotAgent, 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 normalizeBody and normalizeQuery options to SnapshotAgent.

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.

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-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.14%. Comparing base (efae3da) to head (d047f55).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants