mirror of
https://github.com/stablyai/orca.git
synced 2026-11-03 10:37:35 +00:00
fix(computer-use): probe Linux editables via get_editable_text_iface (#10586)
set_value looked up node.is_editable_text before attempt() ran. GI bindings from at-spi2-core < 2.53 (e.g. Ubuntu 24.04) do not expose that function, so the AttributeError escaped and every set-value failed. Probe with get_editable_text_iface, which has been bound since 2.9.2 and checks the same interface. Closes #10569 Co-authored-by: bbingz <zzb@gxsmjx.com>
This commit is contained in:
@@ -53,6 +53,12 @@ const checks = [
|
||||
],
|
||||
enabled: process.platform === 'linux'
|
||||
},
|
||||
{
|
||||
name: 'Linux set_value tests',
|
||||
command: 'python3',
|
||||
args: ['native/computer-use-linux/set_value_test.py'],
|
||||
enabled: true
|
||||
},
|
||||
{
|
||||
name: 'Windows provider PowerShell parse',
|
||||
command: process.platform === 'win32' ? 'powershell.exe' : 'pwsh',
|
||||
|
||||
@@ -1047,10 +1047,9 @@ def write_clipboard(value):
|
||||
|
||||
|
||||
def set_value(node, value):
|
||||
if node is not None and bool(attempt(node.is_editable_text, False)):
|
||||
editable = attempt(node.get_editable_text_iface)
|
||||
if editable is not None and attempt(lambda: Atspi.EditableText.set_text_contents(editable, str(value)), False):
|
||||
return True
|
||||
editable = attempt(node.get_editable_text_iface) if node is not None else None
|
||||
if editable is not None and attempt(lambda: Atspi.EditableText.set_text_contents(editable, str(value)), False):
|
||||
return True
|
||||
value_iface = attempt(node.get_value_iface) if node is not None else None
|
||||
if value_iface is not None:
|
||||
return bool(attempt(lambda: Atspi.Value.set_current_value(value_iface, float(value)), False))
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import importlib.util
|
||||
import sys
|
||||
import types
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
|
||||
def load_runtime():
|
||||
editable_text = types.SimpleNamespace(set_text_contents=lambda editable, value: editable.update(text=value) or True)
|
||||
repository = types.ModuleType("gi.repository")
|
||||
repository.Atspi = types.SimpleNamespace(EditableText=editable_text)
|
||||
gi = types.ModuleType("gi")
|
||||
gi.repository = repository
|
||||
gi.require_version = lambda *_: None
|
||||
path = Path(__file__).with_name("runtime.py")
|
||||
with mock.patch.dict(sys.modules, {"gi": gi, "gi.repository": repository}):
|
||||
spec = importlib.util.spec_from_file_location("orca_linux_runtime_set_value_test", path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
class SetValueTest(unittest.TestCase):
|
||||
def test_sets_text_on_bindings_without_is_editable_text(self):
|
||||
# Why: at-spi2-core < 2.53 (e.g. Ubuntu 24.04) does not expose Accessible.is_editable_text to GI.
|
||||
editable = {"text": ""}
|
||||
node = types.SimpleNamespace(get_editable_text_iface=lambda: editable, get_value_iface=lambda: None)
|
||||
|
||||
self.assertTrue(load_runtime().set_value(node, "hello"))
|
||||
self.assertEqual(editable["text"], "hello")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user