From 1a7392339721595ea71d9969e4a73e584dfa07bf Mon Sep 17 00:00:00 2001 From: shiny-code-bot Date: Tue, 16 Jun 2026 14:44:38 -0400 Subject: [PATCH] Fix live browser witness screenshot byte metadata --- .../tests/fixtures/live_browser_witness.html | 11 ++++++++- .../tests/live_browser_witness.rs | 23 +++++++++++-------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/codex-rs/code-bridge-client/tests/fixtures/live_browser_witness.html b/codex-rs/code-bridge-client/tests/fixtures/live_browser_witness.html index be11d71c28f9..8b41aa135513 100644 --- a/codex-rs/code-bridge-client/tests/fixtures/live_browser_witness.html +++ b/codex-rs/code-bridge-client/tests/fixtures/live_browser_witness.html @@ -171,6 +171,15 @@ }; } + function decodedBase64ByteLength(dataBase64) { + const padding = dataBase64.endsWith("==") + ? 2 + : dataBase64.endsWith("=") + ? 1 + : 0; + return Math.floor((dataBase64.length * 3) / 4) - padding; + } + async function handleScreenshotRequest(config, body) { const screenshot = screenshotPayload(); await postMessage(config, { @@ -195,7 +204,7 @@ width: screenshot.width, height: screenshot.height, mediaType: screenshot.mediaType, - bytes: screenshot.dataBase64.length, + bytes: decodedBase64ByteLength(screenshot.dataBase64), }, }, }, diff --git a/codex-rs/code-bridge-client/tests/live_browser_witness.rs b/codex-rs/code-bridge-client/tests/live_browser_witness.rs index 195685bfb145..db96e868b068 100644 --- a/codex-rs/code-bridge-client/tests/live_browser_witness.rs +++ b/codex-rs/code-bridge-client/tests/live_browser_witness.rs @@ -140,21 +140,25 @@ async fn live_browser_witness_round_trips_events_screenshot_and_control() { panic!("expected screenshot response"); }; assert_eq!(request_id, "live-browser-shot-1"); - assert_nonblank_png(&screenshot); + let screenshot_bytes = assert_nonblank_png(&screenshot); let screenshot_event = next_message(&mut events, "screenshot event").await; let control_cursor = screenshot_event.sequence; - assert!(matches!( - screenshot_event.envelope.payload, - BridgePayload::Event(EventPublishMessage { - event: BridgeEvent::Screenshot(ScreenshotEvent { + let BridgePayload::Event(EventPublishMessage { + event: + BridgeEvent::Screenshot(ScreenshotEvent { screenshot_id, media_type: ScreenshotMediaType::Png, + bytes, .. }), - .. - }) if screenshot_id == "live-browser-shot-1" - )); + .. + }) = screenshot_event.envelope.payload + else { + panic!("expected screenshot event"); + }; + assert_eq!(screenshot_id, "live-browser-shot-1"); + assert_eq!(bytes, screenshot_bytes); drop(events); client @@ -195,7 +199,7 @@ async fn next_message( .unwrap_or_else(|error| panic!("failed waiting for {label}: {error}")) } -fn assert_nonblank_png(screenshot: &ScreenshotPayload) { +fn assert_nonblank_png(screenshot: &ScreenshotPayload) -> usize { assert_eq!(screenshot.media_type, ScreenshotMediaType::Png); let bytes = BASE64_STANDARD .decode(screenshot.data_base64.as_bytes()) @@ -210,6 +214,7 @@ fn assert_nonblank_png(screenshot: &ScreenshotPayload) { .next() .expect("screenshot has at least one pixel"); assert!(image.pixels().any(|pixel| pixel != first)); + bytes.len() } fn descriptor_from_path(path: &std::path::Path) -> BridgeDescriptor {