Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -195,7 +204,7 @@
width: screenshot.width,
height: screenshot.height,
mediaType: screenshot.mediaType,
bytes: screenshot.dataBase64.length,
bytes: decodedBase64ByteLength(screenshot.dataBase64),
},
},
},
Expand Down
23 changes: 14 additions & 9 deletions codex-rs/code-bridge-client/tests/live_browser_witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand All @@ -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 {
Expand Down
Loading