Skip to content

Computer use CLI for AI agents

fix: guard the debug viewer image sink and unpin a flaky test deadline

Lahfirfca24f2b0259
diff --git a/crates/core/src/ref_action_focus_order_tests.rs b/crates/core/src/ref_action_focus_order_tests.rs
index ab5689d25..db0da2b58 100644
--- a/crates/core/src/ref_action_focus_order_tests.rs
+++ b/crates/core/src/ref_action_focus_order_tests.rs
@@ -120,6 +120,14 @@ impl SystemOps for FocusAdapter {
}
fn execute(adapter: &FocusAdapter, headed: bool) -> Result<ActionResult, AdapterError> {
+ execute_within(adapter, headed, 2_000)
+}
+
+fn execute_within(
+ adapter: &FocusAdapter,
+ headed: bool,
+ timeout_ms: u64,
+) -> Result<ActionResult, AdapterError> {
let entry: RefEntry = serde_json::from_value(serde_json::json!({
"pid": 1, "process_instance": "test-instance", "role": "button", "name": "Run",
"source_window_id": "w-test", "source_surface": "window", "path": [0],
@@ -130,7 +138,7 @@ fn execute(adapter: &FocusAdapter, headed: bool) -> Result<ActionResult, Adapter
} else {
ActionRequest::headless(Action::Click)
};
- crate::ref_action::execute_entry(adapter, &entry, request.with_timeout_ms(Some(150)))
+ crate::ref_action::execute_entry(adapter, &entry, request.with_timeout_ms(Some(timeout_ms)))
}
fn adapter(persistent_occlusion: bool, enabled: bool) -> FocusAdapter {
@@ -161,7 +169,7 @@ fn headed_target_still_occluded_after_focus_never_receives_input() {
#[test]
fn disabled_target_does_not_trigger_early_focus() {
let adapter = adapter(false, false);
- execute(&adapter, true).unwrap_err();
+ execute_within(&adapter, true, 150).unwrap_err();
assert!(!adapter.focused.load(Ordering::SeqCst));
assert_eq!(adapter.dispatched.load(Ordering::SeqCst), 0);
}
diff --git a/src/visual_debug/viewer.js b/src/visual_debug/viewer.js
index 05318c4e1..09bfbf925 100644
--- a/src/visual_debug/viewer.js
+++ b/src/visual_debug/viewer.js
@@ -1,6 +1,6 @@
(() => {
const data = JSON.parse(document.getElementById('debug-data').textContent);
- const {groupNodes, matchesRole, visibleRect} = DebugViewerFilter;
+ const {groupNodes, imageSource, matchesRole, visibleRect} = DebugViewerFilter;
const byId = id => document.getElementById(id);
const ns = 'http://www.w3.org/2000/svg';
const roles = new Set();
@@ -150,7 +150,7 @@
byId('phase').textContent = frame ? (phase === 'before' ? 'Before dispatch: requested target' : data.mode === 'click' ? 'After command: observed window' : 'Returned tree over captured window') : 'Screenshot unavailable';
if (frame) {
byId('summary').textContent = `${data.mode} · ${frame.window.app} · ${frame.window.title || frame.window.id} · ${data.ok ? 'command succeeded' : 'command failed'}`;
- byId('capture').src = frame.image;
+ byId('capture').src = imageSource(frame.image);
byId('capture').alt = `${frame.window.app} window, ${phase} command capture`;
byId('list-title').textContent = `${frame.nodes.length} ${data.mode === 'click' ? 'target elements' : 'returned nodes'}`;
}
diff --git a/src/visual_debug/viewer_filter.js b/src/visual_debug/viewer_filter.js
index 93df913bd..f256bd996 100644
--- a/src/visual_debug/viewer_filter.js
+++ b/src/visual_debug/viewer_filter.js
@@ -17,6 +17,9 @@ const DebugViewerFilter = (() => {
return [...groups.values()];
}
function matchesRole(node, roles) { return roles.size === 0 || roles.has(node.role); }
+ function imageSource(value) {
+ return typeof value === 'string' && /^data:image\/png;base64,[A-Za-z0-9+/]+=*$/.test(value) ? value : '';
+ }
function visibleRect(bounds, window) {
if (!bounds || ![bounds.x, bounds.y, bounds.width, bounds.height].every(Number.isFinite)) return null;
const x = Math.max(0, bounds.x - window.x);
@@ -25,6 +28,6 @@ const DebugViewerFilter = (() => {
const bottom = Math.min(window.height, bounds.y + bounds.height - window.y);
return right > x && bottom > y ? {x, y, width: right - x, height: bottom - y} : null;
}
- return {groupNodes, matchesRole, visibleRect};
+ return {groupNodes, imageSource, matchesRole, visibleRect};
})();
if (typeof module !== 'undefined') module.exports = DebugViewerFilter;
diff --git a/src/visual_debug/viewer_filter.test.js b/src/visual_debug/viewer_filter.test.js
index 0c0e132d1..fd6eeb36f 100644
--- a/src/visual_debug/viewer_filter.test.js
+++ b/src/visual_debug/viewer_filter.test.js
@@ -1,6 +1,6 @@
const {test} = require('node:test');
const assert = require('node:assert/strict');
-const {groupNodes, matchesRole, visibleRect} = require('./viewer_filter.js');
+const {groupNodes, imageSource, matchesRole, visibleRect} = require('./viewer_filter.js');
const nodes = [{role: 'window'}, {role: 'treeitem'}, {role: 'button'}, {role: 'treeitem'}];
@@ -32,3 +32,18 @@ test('geometry clips to the window and handles negative monitor origins', () =>
assert.equal(visibleRect(null, window), null);
assert.equal(visibleRect({x: NaN, y: 60, width: 30, height: 20}, window), null);
});
+
+test('only a base64 PNG data URI is accepted as an image source', () => {
+ const png = 'data:image/png;base64,iVBORw0KGgo=';
+ assert.equal(imageSource(png), png);
+ for (const rejected of [
+ 'javascript:alert(1)',
+ 'data:text/html;base64,PHNjcmlwdD4=',
+ 'data:image/svg+xml;base64,PHN2Zz4=',
+ ' data:image/png;base64,iVBORw0KGgo=',
+ 'data:image/png;base64,iVBORw0KGgo=<script>',
+ undefined,
+ ]) {
+ assert.equal(imageSource(rejected), '');
+ }
+});
diff --git a/tools/inspector/public/screenshot.js b/tools/inspector/public/screenshot.js
index cf1761b94..76c2c2a8c 100644
--- a/tools/inspector/public/screenshot.js
+++ b/tools/inspector/public/screenshot.js
@@ -19,7 +19,8 @@ export function renderScreenshot(view, selection, items, matchRefs, onSelect) {
return;
}
const image = byId('capture');
- if (image.getAttribute('src') !== frame.image) image.src = frame.image;
+ const source = DebugViewerFilter.imageSource(frame.image);
+ if (image.getAttribute('src') !== source) image.src = source;
image.alt = `${view.app}: ${frame.window.title || 'window'}`;
if (!byId('highlights').checked) return;
const bounds = frame.window.bounds;