diff --git a/controller.py b/controller.py index 0f0bc6a..01a8a4b 100644 --- a/controller.py +++ b/controller.py @@ -77,7 +77,9 @@ class AutoDLClient: "/api/v1/dev/instance/pro/image/private/list", {"page_index": 1, "page_size": 100}, ) - return list(data.get("list", [])) + # AutoDL returns JSON null instead of [] when the account has no + # private images. Treat both representations as an empty result. + return list(data.get("list") or []) def create(self, spec: dict[str, Any]) -> str: return str(self.request("POST", "/api/v1/dev/instance/pro/create", spec)) diff --git a/tests/test_controller.py b/tests/test_controller.py index 6e7beec..8b8a5ca 100644 --- a/tests/test_controller.py +++ b/tests/test_controller.py @@ -8,6 +8,12 @@ import controller class ControllerTests(unittest.TestCase): + def test_list_images_accepts_null_for_an_empty_account(self): + client = controller.AutoDLClient("test-token") + client.request = lambda method, path, body: {"list": None} + + self.assertEqual(client.list_images(), []) + def test_runner_release_is_pinned(self): self.assertEqual(controller.RUNNER_VERSION, "3.5.0") self.assertEqual(len(controller.RUNNER_SHA256), 64)