Przeglądaj źródła

har_audit: check booking header drift across all captured calls

_audit_booking compared only found[key][0], so a single stale/transient
header value in one captured call (e.g. a frontend bundle reload
mid-session) flagged false drift even when every other call — and our
client — agreed. A header now only counts as stale if the client's
value never appears in any capture of that endpoint.

Confirmed against two HARs from different times that the flagged
conversationMessages mismatch was exactly this: an older capture has
only the stale value, a newer one is mostly the current value with one
straggler, so our client was already correct.
ZiB 5 dni temu
rodzic
commit
06d093d294
1 zmienionych plików z 12 dodań i 9 usunięć
  1. 12 9
      scripts/har_audit.py

+ 12 - 9
scripts/har_audit.py

@@ -222,15 +222,18 @@ def _audit_booking(entries: list[dict], har_name: str) -> bool:
       print(f'       {"":>{col}}   → {spec["hint"]}')
       continue
 
-    entry = found[key][0]
-    hdrs = _req_headers(entry)
+    # Check every captured call of this endpoint, not just the first — the
+    # same endpoint can show more than one header value within one HAR (e.g.
+    # a stale value from a frontend bundle reload mid-capture), so a mismatch
+    # only means something if the client's value never shows up at all.
     expected_headers = spec.get('headers', {})
+    all_hdrs = [_req_headers(e) for e in found[key]]
 
-    mismatches: list[tuple[str, str, str]] = []
+    mismatches: list[tuple[str, str, list[str]]] = []
     for hname, hexpected in expected_headers.items():
-      hactual = hdrs.get(hname, '')
-      if hactual != hexpected:
-        mismatches.append((hname, hexpected, hactual))
+      observed = [h.get(hname, '') for h in all_hdrs]
+      if hexpected not in observed:
+        mismatches.append((hname, hexpected, sorted(set(observed))))
 
     if not mismatches:
       print(f'    ✓  {key:<{col}} found')
@@ -238,10 +241,10 @@ def _audit_booking(entries: list[dict], har_name: str) -> bool:
       all_ok = False
       print(f'    ✗  {key:<{col}} found with stale headers')
       src = spec.get('source', 'the client headers')
-      for hname, hexpected, hactual in mismatches:
+      for hname, hexpected, observed in mismatches:
         print(f'       {hname}')
-        print(f'         client: {hexpected}')
-        print(f'         HAR:    {hactual}   ← update {src}')
+        print(f'         client:   {hexpected}')
+        print(f'         HAR saw:  {observed}   ← update {src}')
 
   missing = [k for k in _BOOKING_ENDPOINTS if k not in found]
   if not missing: