forked from openai/codex
-
Notifications
You must be signed in to change notification settings - Fork 228
fix(browser): ignore transient CDP decode errors #566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cbusillo
wants to merge
3
commits into
just-every:main
Choose a base branch
from
cbusillo:fix/browser-handler-decode-error
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| use code_browser::BrowserConfig; | ||
| use code_browser::BrowserManager; | ||
| use std::env; | ||
| use std::io::Read; | ||
| use std::io::Write; | ||
| use std::net::TcpListener; | ||
| use std::sync::Arc; | ||
| use std::sync::atomic::AtomicBool; | ||
| use std::sync::atomic::Ordering; | ||
| use std::thread; | ||
| use std::time::Duration; | ||
|
|
||
| fn spawn_http_server() -> (String, Arc<AtomicBool>, thread::JoinHandle<()>) { | ||
| let listener = TcpListener::bind("127.0.0.1:0").expect("bind test server"); | ||
| listener | ||
| .set_nonblocking(true) | ||
| .expect("set non-blocking listener"); | ||
| let addr = listener.local_addr().expect("listener addr"); | ||
| let stop = Arc::new(AtomicBool::new(false)); | ||
| let stop_thread = Arc::clone(&stop); | ||
|
|
||
| let handle = thread::spawn(move || { | ||
| while !stop_thread.load(Ordering::Relaxed) { | ||
| match listener.accept() { | ||
| Ok((mut stream, _)) => { | ||
| let mut buf = [0_u8; 2048]; | ||
| let _ = stream.read(&mut buf); | ||
| let body = "<html><head><title>Code Browser Local Test</title></head><body><h1>browser-ok</h1></body></html>"; | ||
| let response = format!( | ||
| "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{}", | ||
| body.len(), body | ||
| ); | ||
| let _ = stream.write_all(response.as_bytes()); | ||
| let _ = stream.flush(); | ||
| } | ||
| Err(err) if err.kind() == std::io::ErrorKind::WouldBlock => { | ||
| thread::sleep(Duration::from_millis(25)); | ||
| } | ||
| Err(_) => break, | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| (format!("http://127.0.0.1:{}", addr.port()), stop, handle) | ||
| } | ||
|
|
||
| async fn assert_manager_can_open_local_http_server(headless: bool) { | ||
| let (url, stop, handle) = spawn_http_server(); | ||
|
|
||
| let mut config = BrowserConfig::default(); | ||
| config.enabled = true; | ||
| config.headless = headless; | ||
| config.idle_timeout_ms = 300_000; | ||
|
|
||
| let manager = BrowserManager::new(config); | ||
| manager.goto(&url).await.expect("navigate to local server"); | ||
|
|
||
| let current_url = manager | ||
| .get_current_url() | ||
| .await | ||
| .expect("manager current url after goto"); | ||
| assert!(current_url == url || current_url == format!("{url}/")); | ||
|
|
||
| let page = manager.get_or_create_page().await.expect("page after goto"); | ||
| let href = page.inject_js("location.href").await.expect("raw href"); | ||
| let href_text = href.as_str().unwrap_or_default(); | ||
| assert!(href_text == url || href_text == format!("{url}/")); | ||
|
|
||
| let body = page | ||
| .execute_javascript("document.body && document.body.innerText") | ||
| .await | ||
| .expect("read page body"); | ||
| let body_text = body | ||
| .get("value") | ||
| .and_then(|value| value.as_str()) | ||
| .unwrap_or_default(); | ||
| assert!(body_text.contains("browser-ok"), "unexpected page body: {body_text}"); | ||
|
|
||
| stop.store(true, Ordering::Relaxed); | ||
| let _ = handle.join(); | ||
| let _ = manager.stop().await; | ||
| } | ||
|
|
||
| fn can_run_headed_browser_test() -> bool { | ||
| if !cfg!(target_os = "linux") { | ||
| return true; | ||
| } | ||
|
|
||
| env::var_os("DISPLAY").is_some() || env::var_os("WAYLAND_DISPLAY").is_some() | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
| async fn internal_browser_can_open_local_http_server() { | ||
| assert_manager_can_open_local_http_server(true).await; | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
| async fn headed_internal_browser_can_open_local_http_server() { | ||
| if !can_run_headed_browser_test() { | ||
| eprintln!( | ||
| "skipping headed browser regression test: no DISPLAY or WAYLAND_DISPLAY available" | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| assert_manager_can_open_local_http_server(false).await; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new headed test always executes
assert_manager_can_open_local_http_server(false), which requires launching Chrome without headless mode. In environments whereDISPLAY/Wayland is unavailable (common for CI and dev containers), browser launch fails before navigation, socargo test -p code-browserfails due to environment rather than a product regression. Please gate this test (or skip it) when no display server is present.Useful? React with 👍 / 👎.