authoravatarclover caruso<git@paperclover.net>2026-11-17 04:57:51-08:00
committeravatarclover caruso<git@paperclover.net>2026-11-22 00:44:02-08:00
log6f8ec57f945851d1989b77d1e949a5daa7588fdc
treebfa21d22c57db1e493a618ad435f53903dc9ad14
parentae780a97cef655e25547c8351b3d3cb730b6370c
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

Reject unsupported fallback text before desktop input

Validate the entire batch for unsupported text before opening the console so earlier clicks cannot run before a later text rejection. Keep native Unicode input and supported fallback typing available. Assisted-by: gpt-6.1-sol

2 files changed, 19 insertions(+), 4 deletions(-)

tools/computer-test.py+14
...@@ -593,6 +593,20 @@ class DesktopBounds(unittest.IsolatedAsyncioTestCase):...@@ -593,6 +593,20 @@ class DesktopBounds(unittest.IsolatedAsyncioTestCase):
593 item.start()593 item.start()
594 self.addCleanup(item.stop)594 self.addCleanup(item.stop)
595595
596 async def test_unsupported_fallback_text_cannot_partially_execute_a_batch(self):
597 for text in ['雪', '\x1b']:
598 actions = [{'type': 'click', 'x': 1, 'y': 1}, {'type': 'text', 'text': text}]
599 with self.subTest(text=text), self.assertRaisesRegex(ValueError, 'ASCII text only'):
600 await computer.desktop('fixture', actions, 'linux', False, False)
601 self.screen.input.assert_not_called()
602
603 async def test_native_text_still_accepts_unicode(self):
604 action = {'type': 'text', 'text': '雪🦊'}
605 with patch.object(computer, 'worker') as worker:
606 result = await computer.desktop('fixture', [action], 'windows', False)
607 self.assertEqual(result, {'completed': 1})
608 worker.assert_called_once_with('fixture', 'windows', {'action': 'input', 'actions': [action], 'screenshot': False})
609
596 async def test_input_without_screenshot_never_encodes_or_requests_another_frame(self):610 async def test_input_without_screenshot_never_encodes_or_requests_another_frame(self):
597 with patch.object(computer.rfb, 'png', side_effect=AssertionError('No capture requested')):611 with patch.object(computer.rfb, 'png', side_effect=AssertionError('No capture requested')):
598 result = await computer.desktop('fixture', [{'type': 'click', 'x': 1, 'y': 1}], 'linux', False)612 result = await computer.desktop('fixture', [{'type': 'click', 'x': 1, 'y': 1}], 'linux', False)
tools/vm-computer.py+5-4
...@@ -176,6 +176,10 @@ async def desktop(name, actions=None, platform=None, screenshot=True, native_tex...@@ -176,6 +176,10 @@ async def desktop(name, actions=None, platform=None, screenshot=True, native_tex
176176
177177
178async def capture(name, actions, platform, screenshot=True, native_text=True):178async def capture(name, actions, platform, screenshot=True, native_text=True):
179 if not native_text:
180 for action in actions or ():
181 if action['type'] == 'text' and any(not (32 <= ord(char) <= 126 or char in '\n\r\t') for char in action['text']):
182 raise ValueError('This connection supports ASCII text only. Use key actions for other keyboard input.')
179 target = vms.console_target(name, timeout=remaining(10))183 target = vms.console_target(name, timeout=remaining(10))
180 reader, writer = await asyncio.wait_for(asyncio.open_connection('127.0.0.1', target['port']), 10)184 reader, writer = await asyncio.wait_for(asyncio.open_connection('127.0.0.1', target['port']), 10)
181 screen = rfb.Desktop(reader, writer, lambda _: None)185 screen = rfb.Desktop(reader, writer, lambda _: None)
...@@ -234,11 +238,8 @@ async def capture(name, actions, platform, screenshot=True, native_text=True):...@@ -234,11 +238,8 @@ async def capture(name, actions, platform, screenshot=True, native_text=True):
234 with contextlib.suppress(Exception):238 with contextlib.suppress(Exception):
235 await pending239 await pending
236 else:240 else:
237 text = action['text']
238 if any(not (32 <= ord(char) <= 126 or char in '\n\r\t') for char in text):
239 raise ValueError('This connection supports ASCII text only. Use key actions for other keyboard input.')
240 shifted = dict(zip('~!@#$%^&*()_+{}|:"<>?', '`1234567890-=[]\\;\',./'))241 shifted = dict(zip('~!@#$%^&*()_+{}|:"<>?', '`1234567890-=[]\\;\',./'))
241 for char in text.replace('\r\n', '\n'):242 for char in action['text'].replace('\r\n', '\n'):
242 shift = char in shifted243 shift = char in shifted
243 base = shifted.get(char, char)244 base = shifted.get(char, char)
244 key = {'\n': 0xff0d, '\r': 0xff0d, '\t': 0xff09}.get(base, ord(base))245 key = {'\n': 0xff0d, '\r': 0xff0d, '\t': 0xff09}.get(base, ord(base))