Skip to content

feat: XHR-hook captures + calibrate command - #16

Merged
KeyCode17 merged 1 commit into
mainfrom
v1.8.0/p2-p3-capture-calibrate
May 19, 2026
Merged

feat: XHR-hook captures + calibrate command#16
KeyCode17 merged 1 commit into
mainfrom
v1.8.0/p2-p3-capture-calibrate

Conversation

@KeyCode17

Copy link
Copy Markdown
Owner

Summary

v1.8.0 P2 + P3 (ADR-0024). Gives the operator the tools to capture ground-truth sensor payloads from a real browser session and compare them against what px-native::events::default_batch synthesises today.

What's new

P2 — pxsolver-camoufox::capture_sensor

capture_sensor(config, proxy, url, wait_ms) -> CaptureResult:

  • Spawns a fresh Camoufox session.
  • Navigates to about:blank and injects a monkey-patch that hooks JSON.stringify (records [{t, d}, …] shapes) + XMLHttpRequest.prototype.send (records URL + body for /b/s).
  • Navigates to the target, waits, extracts the captures.

Live test:

CAPTURE_PX=1 PX_PROXIES=socks5://… \
  cargo test -p pxsolver-camoufox --test capture_sensor -- --ignored --nocapture

Writes to px-research/captures/eT15wiaE/<unix-ts>.json.

P3 — px-native::events::calibrate + px-cli calibrate

  • calibrate(observed, synthesised) -> CalibrationReport (missing_tags, extra_tags, per_tag observed/synth/missing keys).
  • px-cli calibrate <capture.json> prints the diff:
    Observed events: 2
    Synthetic events: 3
    Missing tags: PXNEW
    Extra tags: PX11978, PX12457
    [PX561] observed=3 synth=3 missing=1
      + need: NEW_KEY
    
  • --json flag for machine consumption.

Tests

  • 132 workspace tests pass, 0 failures.
  • New: 3 in calibrate unit tests, smoke test of px-cli calibrate against a synthetic fixture.
  • cargo clippy --workspace --all-targets --all-features -- -D warnings -D clippy::unwrap_used -D clippy::expect_used -D clippy::panic clean.
  • All files ≤200 LOC.

What this still doesn't prove

P4 is the live throughput test against a real PX-fronted target. That requires the operator to:

  1. Run the CAPTURE_PX=1 test through a working AR residential proxy.
  2. Run px-cli calibrate against the resulting JSON to see which default_batch fields lie.
  3. Patch default_batch until missing/extra tags converge.
  4. Re-enable PX_NATIVE_PROFILES (added in feat(server): wire SensorNativeSolver into solve dispatcher #15) and measure /v1/solve throughput.

🤖 Generated with Claude Code

ADR-0024 v1.8.0 P2 + P3.

P2 — px-camoufox::capture_sensor:
- Spawns a fresh session, navigates to about:blank, injects a small
  monkey-patch that wraps `JSON.stringify` (logging `[{t,d},…]` event
  batches) and `XMLHttpRequest.prototype.send` (logging URL + body
  for /b/s targets).
- Navigates to the target URL, waits, extracts captures back to Rust
  as a `CaptureResult` (plaintext_events, xhr_sends, cookies, ua).
- Live test gated by `CAPTURE_PX=1` writes JSON to
  `px-research/captures/eT15wiaE/<unix-ts>.json`.

P3 — px-native::events::calibrate + `px-cli calibrate`:
- `calibrate(observed, synthesised)` returns a `CalibrationReport`:
  missing_tags, extra_tags, per_tag observed/synth/missing keys.
- New CLI subcommand: `px-cli calibrate <capture.json> [--json]`
  prints a human-readable diff for operators.
- `SensorEvent` + `EventField` derive `Deserialize` so captures
  round-trip back into the calibrator.

Operator workflow:
  CAPTURE_PX=1 PX_PROXIES=... cargo test -p pxsolver-camoufox \
    --test capture_sensor -- --ignored --nocapture
  px-cli calibrate px-research/captures/eT15wiaE/<ts>.json

132 workspace tests pass; clippy clean; all files ≤200 LOC.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@KeyCode17
KeyCode17 merged commit 3c85668 into main May 19, 2026
6 checks passed
@KeyCode17
KeyCode17 deleted the v1.8.0/p2-p3-capture-calibrate branch May 19, 2026 20:22
@KeyCode17 KeyCode17 mentioned this pull request May 19, 2026
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.

1 participant