authoravatarclover caruso<git@paperclover.net>2026-11-16 21:23:52-08:00
committeravatarclover caruso<git@paperclover.net>2026-11-22 00:44:02-08:00
loga746c1188b774c0869822dd0dad345d919cbc037
treea24a5ee93ad2af50a64e56360363f40f37db8755
parent3d5465351dc36ac4fb16ecafa72be90d1e5d1ec8
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

Report guest-agent readiness before desktop probes

Distinguish an unavailable agent, missing command support, and desktop worker startup. Keep ASCII console input usable on Linux as well as Windows when the agent is unavailable. Assisted-by: gpt-6.1-sol

2 files changed, 47 insertions(+), 13 deletions(-)

tools/computer-test.py+39-10
...@@ -135,18 +135,47 @@ class GuestCancellation(unittest.TestCase):...@@ -135,18 +135,47 @@ class GuestCancellation(unittest.TestCase):
135 finally:135 finally:
136 computer.DEADLINE.reset(token)136 computer.DEADLINE.reset(token)
137137
138 def test_windows_console_remains_available_without_guest_agent(self):138 def test_console_remains_available_without_guest_agent(self):
139 for platform in ['windows', 'linux']:
140 def virsh(action, *args, **kwargs):
141 return 'running' if action == 'domstate' else '<domain><metadata><vm xmlns="https://paperclover.net/snowglobe"><platform>'+platform+'</platform></vm></metadata></domain>'
142 with self.subTest(platform=platform), patch.object(computer.vms, 'virsh', virsh), patch.object(computer, 'qga', side_effect=ValueError('Disconnected')), patch.object(computer, 'worker') as work:
143 status = computer.handle('fixture', {'action': 'status'})
144 self.assertEqual(status['readiness'], 'agent_unavailable')
145 self.assertEqual(status['capabilities'], ['shot', 'input'])
146 self.assertEqual(status['text_encoding'], 'ascii')
147 actions = [{'type': 'text', 'text': 'recovery console'}]
148 with patch.object(computer, 'desktop', new_callable=AsyncMock, return_value={'completed': 1}) as desktop:
149 self.assertEqual(computer.handle('fixture', {'action': 'input', 'actions': actions, 'screenshot': False}), {'completed': 1})
150 desktop.assert_awaited_once_with('fixture', actions, platform, False, False)
151 work.assert_not_called()
152 self.assertFalse((computer.vms.DISKS / 'fixture' / 'computer-operation.json').exists())
153
154 def test_status_distinguishes_disabled_commands_from_a_starting_worker(self):
139 def virsh(action, *args, **kwargs):155 def virsh(action, *args, **kwargs):
140 return 'running' if action == 'domstate' else '<domain><metadata><vm xmlns="https://paperclover.net/snowglobe"><platform>windows</platform></vm></metadata></domain>'156 return 'running' if action == 'domstate' else '<domain/>'
141 with patch.object(computer.vms, 'virsh', virsh), patch.object(computer, 'qga', side_effect=ValueError('Disconnected')), patch.object(computer, 'worker') as work:157 with patch.object(computer.vms, 'virsh', virsh), patch.object(computer, 'worker') as work:
142 status = computer.handle('fixture', {'action': 'status'})158 with patch.object(computer, 'qga', return_value={'supported_commands':[{'name':'guest-exec','enabled':False}]}):
143 self.assertEqual(status['capabilities'], ['shot', 'input'])159 status = computer.handle('fixture', {'action':'status'})
144 self.assertEqual(status['text_encoding'], 'ascii')160 self.assertEqual(status['readiness'], 'agent_unsupported')
145 actions = [{'type': 'text', 'text': 'recovery console'}]
146 with patch.object(computer, 'desktop', new_callable=AsyncMock, return_value={'completed': 1}) as desktop:
147 self.assertEqual(computer.handle('fixture', {'action': 'input', 'actions': actions, 'screenshot': False}), {'completed': 1})
148 desktop.assert_awaited_once_with('fixture', actions, 'windows', False, False)
149 work.assert_not_called()161 work.assert_not_called()
162 with patch.object(computer, 'qga', return_value={'supported_commands':[{'name':'guest-exec','enabled':True}]}):
163 work.side_effect = ValueError('Sign in to the VM desktop before using this tool.')
164 status = computer.handle('fixture', {'action':'status'})
165 self.assertEqual(status['readiness'], 'worker_starting')
166 self.assertIn('Sign in', status['worker_error'])
167 work.side_effect = None
168 work.return_value = {'runtimes':['bash']}
169 status = computer.handle('fixture', {'action':'status'})
170 self.assertEqual(status['readiness'], 'ready')
171 self.assertEqual(status['runtimes'], ['bash'])
172
173 def test_legacy_mac_status_keeps_its_private_transport(self):
174 def virsh(action, *args, **kwargs):
175 return 'running' if action == 'domstate' else '<domain><metadata><vm xmlns="https://paperclover.net/snowglobe"><platform>macos</platform></vm></metadata></domain>'
176 with patch.object(computer.vms, 'virsh', virsh), patch.object(computer, 'qga', side_effect=AssertionError('This Mac has no QGA channel')), patch.object(computer, 'worker', return_value={'runtimes':['bash']}) as work:
177 self.assertEqual(computer.handle('fixture', {'action':'status'})['readiness'], 'ready')
178 work.assert_called_once_with('fixture', 'macos', {'action':'status'})
150179
151 def test_failed_cleanup_keeps_status_available_and_blocks_later_control(self):180 def test_failed_cleanup_keeps_status_available_and_blocks_later_control(self):
152 for platform, identity in [('linux', 'snowglobe-computer-request-' + 'a' * 32), ('windows', 'a' * 32)]:181 for platform, identity in [('linux', 'snowglobe-computer-request-' + 'a' * 32), ('windows', 'a' * 32)]:
tools/vm-computer.py+8-3
...@@ -214,7 +214,7 @@ async def capture(name, actions, platform, screenshot=True, native_text=True):...@@ -214,7 +214,7 @@ async def capture(name, actions, platform, screenshot=True, native_text=True):
214 else:214 else:
215 text = action['text']215 text = action['text']
216 if any(not (32 <= ord(char) <= 126 or char in '\n\r\t') for char in text):216 if any(not (32 <= ord(char) <= 126 or char in '\n\r\t') for char in text):
217 raise ValueError('This legacy guest supports ASCII text only. Use key actions for other keyboard input.')217 raise ValueError('This connection supports ASCII text only. Use key actions for other keyboard input.')
218 shifted = dict(zip('~!@#$%^&*()_+{}|:"<>?', '`1234567890-=[]\\;\',./'))218 shifted = dict(zip('~!@#$%^&*()_+{}|:"<>?', '`1234567890-=[]\\;\',./'))
219 for char in text.replace('\r\n', '\n'):219 for char in text.replace('\r\n', '\n'):
220 shift = char in shifted220 shift = char in shifted
...@@ -600,15 +600,20 @@ def handle(name, request):...@@ -600,15 +600,20 @@ def handle(name, request):
600 'worker_error': 'The previous operation needs cleanup. Inspect its screenshot or restart the VM before retrying.'}600 'worker_error': 'The previous operation needs cleanup. Inspect its screenshot or restart the VM before retrying.'}
601 finish_operation(name, unfinished)601 finish_operation(name, unfinished)
602 native_text = True602 native_text = True
603 if platform == 'windows' and (request['action'] == 'status' or request['action'] == 'input' and any(a['type'] == 'text' for a in request['actions'])):603 if platform in ('windows', 'linux') and (request['action'] == 'status' or request['action'] == 'input' and any(a['type'] == 'text' for a in request['actions'])):
604 try:604 try:
605 info = qga(name, 'guest-info')605 info = qga(name, 'guest-info')
606 native_text = any(command['name'] == 'guest-exec' and command['enabled'] for command in info['supported_commands'])606 native_text = any(command['name'] == 'guest-exec' and command['enabled'] for command in info['supported_commands'])
607 except (ValueError, subprocess.TimeoutExpired):607 except (ValueError, subprocess.TimeoutExpired):
608 native_text = False608 native_text = False
609 if request['action'] == 'status':
610 return {**status, 'readiness': 'agent_unavailable', 'text_encoding': 'ascii',
611 'worker_error': 'The guest agent is unavailable. Wait for startup or ask an administrator to check its installation.'}
609 if request['action'] == 'status':612 if request['action'] == 'status':
610 if not native_text:613 if not native_text:
611 return {**status, 'text_encoding': 'ascii', 'worker_error': 'Desktop input is available. Commands, Unicode text and UI actions need a working guest agent with command support.'}614 return {**status, 'readiness': 'agent_unsupported', 'text_encoding': 'ascii',
615 'worker_error': 'The guest agent does not support commands. Use console input or ask an administrator to update the agent.'}
616 status['readiness'] = 'worker_starting'
612 try:617 try:
613 status.update(worker(name,platform,request))618 status.update(worker(name,platform,request))
614 status['readiness'] = 'ready'619 status['readiness'] = 'ready'