Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions core/computer_use_linux/desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,9 +812,11 @@ def screen_point(self, x: float, y: float, from_shot: bool) -> tuple[int, int]:
return shot.to_screen(x, y)

def move(self, x: float, y: float, from_shot: bool = False) -> bool:
sx, sy = self.screen_point(x, y, from_shot)
with self._lease():
self.desktop.move(sx, sy)
with self._scope():
sx, sy = self.screen_point(x, y, from_shot)
with self._lease():
self.desktop.move(sx, sy)
self._forget()
return True

def scroll(self, dy: int, dx: int = 0, at: Optional[tuple[int, int]] = None,
Expand Down
35 changes: 35 additions & 0 deletions tests/test_desktop_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,40 @@ def move(self, x, y): moved.append((x, y))
self.assertTrue(cul.move(12.8, 34.2)); self.assertEqual(moved[-1], (13, 34))


def test_move_enters_scope_and_forgets_memoized_state(self):
import contextlib

cul = ComputerUseLinux.__new__(ComputerUseLinux)
moved = []
pumped = []

class FakeDesktop:
def move(self, x, y):
moved.append((x, y))

cul.desktop = FakeDesktop()
cul._lease = lambda: contextlib.nullcontext()
cul._pump = lambda: pumped.append(True)

self.assertTrue(cul.move(10, 20))
self.assertEqual(moved, [(10, 20)])
self.assertEqual(len(pumped), 1)
self.assertIsNone(cul._memo)

calls = 0

def compute():
nonlocal calls
calls += 1
return calls

with cul._scope():
self.assertEqual(cul._m("k", compute), 1)
self.assertEqual(cul._m("k", compute), 1)
self.assertTrue(cul.move(30, 40))
self.assertEqual(cul._m("k", compute), 2)
self.assertIsNone(cul._memo)


if __name__ == "__main__":
unittest.main()
Loading