revert(tests): drop the temp per-episode body-hash diagnostic

Removed now that 1c51ad13 has confirmed the root cause (vcrpy's
sticky ``_was_iter`` flag making the body getter re-wrap stored
bytes in ``iter()`` on every access). The hash dump did its job --
the post-1c51ad13 image_gen_testing run shows all five async
image-edit tests as ``[VCR HIT]`` with stable entry counts and
zero billing errors -- and is too noisy to keep on by default
(over 100 lines per session at steady state).

Kept permanently:

* ``_safe_body_matcher`` mismatch diagnostic in
  ``_vcr_conftest_common.py``. Only fires on a body mismatch,
  which is signal worth surfacing whenever it happens.
* ``_normalize_multipart_boundary`` "skipped" log line. Same
  rationale -- only fires when the body shape is something the
  normalizer cannot rewrite in place.
* The ``test-results/vcr-diagnostics/<pid>.log`` per-PID file
  plumbing (``vcr_diag_write_line`` /
  ``emit_vcr_diagnostic_log``). Useful for any future diagnostic
  that needs to bypass xdist stdout/stderr capture; cheap to keep.
This commit is contained in:
Mateo Wang 2026-05-17 07:48:25 +00:00
parent 1c51ad1335
commit 927c5548f9
No known key found for this signature in database

View file

@ -168,7 +168,6 @@ def make_redis_persister(
key = redis_key_for(cassette_path)
passed = _passed_by_cassette_key.pop(key, True)
episode_count = len(cassette_dict.get("requests", []) or [])
_maybe_log_episode_body_hashes(key, cassette_dict)
if episode_count > MAX_EPISODES_PER_CASSETTE:
_log.warning(
"VCR redis save refused for %s; cassette has %d episodes "
@ -211,49 +210,6 @@ def make_redis_persister(
return _RedisPersister
# TEMP DIAGNOSTIC -- intended to be reverted once the async image-edit
# cassette variance is root-caused. Logs a per-episode body SHA-256
# at save time so two consecutive CI runs can be diffed: if the same
# test records ``sha=abc`` on run 1 and ``sha=def`` on run 2, the live
# request body genuinely varies; if both runs record the same hash
# but the matcher still misses, the bug is in the matcher (e.g. it is
# comparing a bytes object to a stream object). Always-on for any
# session that loads this persister -- ungated because we are
# specifically trying to capture data from CI right now.
def _maybe_log_episode_body_hashes(key: str, cassette_dict) -> None:
import hashlib
# Imported lazily to avoid a circular import at module load.
from tests._vcr_conftest_common import vcr_diag_write_line
requests = cassette_dict.get("requests", []) or []
if not requests:
return
for i, req in enumerate(requests):
body = getattr(req, "body", None)
if body is None:
body_bytes = b""
elif isinstance(body, (bytes, bytearray)):
body_bytes = bytes(body)
elif isinstance(body, str):
body_bytes = body.encode("utf-8")
else:
vcr_diag_write_line(
f"[vcr-episode-body-hash] {key} episode[{i}]: body type="
f"{type(body).__name__!r} is not bytes/bytearray/str -- "
"cannot hash. This is the smoking gun for matcher-side "
"bugs on async multipart."
)
continue
method = getattr(req, "method", "?")
uri = getattr(req, "uri", getattr(req, "url", "?"))
vcr_diag_write_line(
f"[vcr-episode-body-hash] {key} episode[{i}] {method} {uri} "
f"body sha256={hashlib.sha256(body_bytes).hexdigest()} "
f"len={len(body_bytes)} preview={body_bytes[:120]!r}"
)
def filter_non_2xx_response(response):
if not isinstance(response, dict):
return response