diff --git a/core/computer_use_linux/desktop.py b/core/computer_use_linux/desktop.py index 564c6cf..a68bd53 100644 --- a/core/computer_use_linux/desktop.py +++ b/core/computer_use_linux/desktop.py @@ -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, diff --git a/tests/test_desktop_scope.py b/tests/test_desktop_scope.py index 2bdf018..33ff4fb 100644 --- a/tests/test_desktop_scope.py +++ b/tests/test_desktop_scope.py @@ -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()