From 9d1c6aaa33851c1399eb1aa52598867f5a183636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20R=2E=20H=C3=B6lzlwimmer?= Date: Sat, 21 Nov 2026 01:44:12 +0100 Subject: [PATCH 1/4] fix(plugin): answer /api/v1/appplugin with the requested products only The Android app (4.60.06) posts {"apilevel": 10046, "productids": [id], "type": 2} as JSON. It installs the first record of the answer and does not check its productid. The route ignored the requested ids and always answered the whole catalog. Without a cloud snapshot, every model then got the a87 plugin, and other models failed to load it. The route now keeps only the records whose productid is in the request's productids. It reads the ids from the JSON body and from form fields. Without ids, or when no record matches, it answers the full list as before. The filter also applies to a cloud snapshot catalog. --- .../https_server/routes/api/v1/appplugin.py | 26 +++++- tests/test_plugin_routes.py | 83 +++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) diff --git a/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/appplugin.py b/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/appplugin.py index 6f1b74a5..3537a06a 100644 --- a/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/appplugin.py +++ b/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/appplugin.py @@ -4,6 +4,7 @@ from typing import Any from shared.context import ServerContext +from shared.data_helpers import as_int from ...auth.service import ok from ...plugin.common import APPPLUGIN_LIST, plugin_records_with_snapshot_fallback, proxied_plugin_records @@ -30,6 +31,25 @@ def _request_app_type(body_params: dict[str, list[str]]) -> int | None: return None +def _requested_product_ids(body_params: dict[str, list[str]]) -> set[int]: + # The app posts JSON like {"apilevel": 10046, "productids": [263], "type": 2}. + # Form bodies may repeat the field or join the ids with commas. + values: list[Any] = [] + for raw in body_params.get("__json") or []: + try: + parsed = json.loads(raw) + except (TypeError, ValueError): + continue + if isinstance(parsed, dict): + requested = parsed.get("productids") + values.extend(requested if isinstance(requested, list) else [requested]) + for raw in body_params.get("productids") or []: + values.extend(str(raw).strip("[] ").split(",")) + product_ids = {as_int(value, 0) for value in values if value is not None} + product_ids.discard(0) + return product_ids + + def build( ctx: ServerContext, _query_params: dict[str, list[str]], @@ -41,4 +61,8 @@ def build( # Same plugin version, different zip: the iOS app cannot load the Android # one. Imports from before the iOS catalog existed fall back to Android. records = plugin_records_with_snapshot_fallback(ctx, "appplugin_ios", records) - return ok(proxied_plugin_records(ctx, records)) + product_ids = _requested_product_ids(body_params) + # The app installs the first record without checking its productid, so a + # device must only get the records for the product ids it asked for. + matching = [record for record in records if as_int(record.get("productid"), 0) in product_ids] + return ok(proxied_plugin_records(ctx, matching or records)) diff --git a/tests/test_plugin_routes.py b/tests/test_plugin_routes.py index 686a59ea..17fc9354 100644 --- a/tests/test_plugin_routes.py +++ b/tests/test_plugin_routes.py @@ -128,6 +128,89 @@ def test_app_plugin_endpoints_return_proxied_urls(tmp_path: Path) -> None: assert str(item["url"]).startswith("https://api-roborock.example.com/plugin/proxy/") +def _app_plugin_product_ids(payload: dict) -> list[int]: + assert payload["code"] == 200 + return [item["productid"] for item in payload["data"]] + + +def test_app_plugin_answers_only_requested_product_ids(tmp_path: Path) -> None: + supervisor = _build_supervisor(tmp_path) + client = TestClient(supervisor.app) + + # The app posts this JSON body and installs the first record it gets back. + response = client.post("/api/v1/appplugin", json={"apilevel": 10046, "productids": [23], "type": 2}) + + assert response.status_code == 200 + assert _app_plugin_product_ids(response.json()) == [23] + [record] = response.json()["data"] + assert record["url"].startswith("https://api-roborock.example.com/plugin/proxy/") + + +def test_app_plugin_reads_product_ids_from_form_body(tmp_path: Path) -> None: + supervisor = _build_supervisor(tmp_path) + client = TestClient(supervisor.app) + + repeated = client.post("/api/v1/appplugin", data={"type": "2", "productids": ["23", "10001"]}) + joined = client.post("/api/v1/appplugin", data={"type": "2", "productids": "23,10001"}) + + assert _app_plugin_product_ids(repeated.json()) == [23, 10001] + assert _app_plugin_product_ids(joined.json()) == [23, 10001] + + +def test_app_plugin_answers_full_list_without_matching_product_ids(tmp_path: Path) -> None: + from https_server.routes.plugin import common as plugin_common + + supervisor = _build_supervisor(tmp_path) + client = TestClient(supervisor.app) + full_list = [record["productid"] for record in plugin_common.APPPLUGIN_LIST] + + no_body = client.post("/api/v1/appplugin") + no_ids = client.post("/api/v1/appplugin", json={"apilevel": 10046, "type": 2}) + empty_ids = client.post("/api/v1/appplugin", json={"apilevel": 10046, "productids": [], "type": 2}) + unknown_id = client.post("/api/v1/appplugin", json={"apilevel": 10046, "productids": [659231], "type": 2}) + + assert _app_plugin_product_ids(no_body.json()) == full_list + assert _app_plugin_product_ids(no_ids.json()) == full_list + assert _app_plugin_product_ids(empty_ids.json()) == full_list + assert _app_plugin_product_ids(unknown_id.json()) == full_list + + +def test_app_plugin_filters_cloud_snapshot_catalog(tmp_path: Path) -> None: + supervisor = _build_supervisor(tmp_path) + snapshot = { + "web_api_cache": { + "plugin_catalogs": { + "appplugin": { + "data": [ + { + "version": 8888, + "url": "https://rrpkg-us.roborock.com/iot/plugin/cloud-first.zip", + "pluginLevel": 3001, + "productid": 110, + "apilevel": 10043, + }, + { + "version": 7777, + "url": "https://rrpkg-us.roborock.com/iot/plugin/cloud-second.zip", + "pluginLevel": 3002, + "productid": 4242, + "apilevel": 10043, + }, + ] + }, + } + } + } + supervisor.paths.cloud_snapshot_path.write_text(json.dumps(snapshot) + "\n", encoding="utf-8") + client = TestClient(supervisor.app) + + response = client.post("/api/v1/appplugin", json={"apilevel": 10046, "productids": [4242], "type": 2}) + + [record] = response.json()["data"] + assert record["version"] == 7777 + assert _source_from_proxied_url(record["url"]) == "https://rrpkg-us.roborock.com/iot/plugin/cloud-second.zip" + + def test_plugin_category_zip_uses_expected_source_and_cache(tmp_path: Path, monkeypatch) -> None: from https_server.routes.plugin import common as plugin_common From b46aff17f5a112255f233b42b81861aca117241a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20R=2E=20H=C3=B6lzlwimmer?= Date: Sat, 21 Nov 2026 19:42:16 +0100 Subject: [PATCH 2/4] fix(plugin): fall back to the built-in plugin list per product id With a cloud snapshot present, the route only searched the snapshot records. A device added after the snapshot import then never got its built-in APPPLUGIN_LIST record. Each requested id now uses the snapshot records if the snapshot has that id, and the built-in records otherwise. --- .../https_server/routes/api/v1/appplugin.py | 21 +++++-- tests/test_plugin_routes.py | 57 +++++++++++++++++++ 2 files changed, 73 insertions(+), 5 deletions(-) diff --git a/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/appplugin.py b/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/appplugin.py index 3537a06a..ff028ba4 100644 --- a/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/appplugin.py +++ b/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/appplugin.py @@ -7,7 +7,7 @@ from shared.data_helpers import as_int from ...auth.service import ok -from ...plugin.common import APPPLUGIN_LIST, plugin_records_with_snapshot_fallback, proxied_plugin_records +from ...plugin.common import APPPLUGIN_LIST, proxied_plugin_records, snapshot_plugin_records # Request "type" of the iOS app; Android sends 2. IOS_APP_TYPE = 1 @@ -50,19 +50,30 @@ def _requested_product_ids(body_params: dict[str, list[str]]) -> set[int]: return product_ids +def _product_id(record: dict[str, Any]) -> int: + return as_int(record.get("productid"), 0) + + def build( ctx: ServerContext, _query_params: dict[str, list[str]], body_params: dict[str, list[str]], _clean_path: str, ) -> dict[str, Any]: - records = plugin_records_with_snapshot_fallback(ctx, "appplugin", APPPLUGIN_LIST) + snapshot_records = snapshot_plugin_records(ctx, "appplugin") if _request_app_type(body_params) == IOS_APP_TYPE: # Same plugin version, different zip: the iOS app cannot load the Android # one. Imports from before the iOS catalog existed fall back to Android. - records = plugin_records_with_snapshot_fallback(ctx, "appplugin_ios", records) + snapshot_records = snapshot_plugin_records(ctx, "appplugin_ios") or snapshot_records product_ids = _requested_product_ids(body_params) # The app installs the first record without checking its productid, so a # device must only get the records for the product ids it asked for. - matching = [record for record in records if as_int(record.get("productid"), 0) in product_ids] - return ok(proxied_plugin_records(ctx, matching or records)) + matching = [record for record in snapshot_records if _product_id(record) in product_ids] + # A device added after the snapshot import has no snapshot record, so the + # ids that the snapshot lacks come from the built-in list. The built-in list + # is the same for both platforms. So an iOS request can get an Android zip + # here, which the iOS app cannot load. The fallback to the Android catalog + # above has the same limitation if the snapshot has no iOS catalog. + missing_ids = product_ids - {_product_id(record) for record in snapshot_records} + matching += [record for record in APPPLUGIN_LIST if _product_id(record) in missing_ids] + return ok(proxied_plugin_records(ctx, matching or snapshot_records or APPPLUGIN_LIST)) diff --git a/tests/test_plugin_routes.py b/tests/test_plugin_routes.py index 17fc9354..4d533efe 100644 --- a/tests/test_plugin_routes.py +++ b/tests/test_plugin_routes.py @@ -211,6 +211,63 @@ def test_app_plugin_filters_cloud_snapshot_catalog(tmp_path: Path) -> None: assert _source_from_proxied_url(record["url"]) == "https://rrpkg-us.roborock.com/iot/plugin/cloud-second.zip" +def _write_android_app_plugin_snapshot(supervisor: ReleaseSupervisor, records: list[dict]) -> None: + _write_app_plugin_snapshot(supervisor, {"appplugin": {"data": records}}) + + +def test_app_plugin_falls_back_to_built_in_list_for_ids_missing_from_snapshot(tmp_path: Path) -> None: + supervisor = _build_supervisor(tmp_path) + # A device added after the snapshot import has no record in the snapshot. + _write_android_app_plugin_snapshot( + supervisor, + [ + { + "version": 7777, + "url": "https://rrpkg-us.roborock.com/iot/plugin/cloud-only.zip", + "pluginLevel": 3001, + "productid": 4242, + "apilevel": 10043, + } + ], + ) + client = TestClient(supervisor.app) + + missing = client.post("/api/v1/appplugin", json={"apilevel": 10046, "productids": [23], "type": 2}) + mixed = client.post("/api/v1/appplugin", json={"apilevel": 10046, "productids": [23, 4242], "type": 2}) + + [record] = missing.json()["data"] + assert record["productid"] == 23 + assert record["version"] == 5208 + assert _source_from_proxied_url(record["url"]) == ( + "https://cdn.awsusor0.fds.api.mi-img.com/resources/iot/plugin/7cf4eb4c705c420483741189be389927.zip" + ) + # Snapshot records come first, built-in records after them. + assert _app_plugin_product_ids(mixed.json()) == [4242, 23] + + +def test_app_plugin_prefers_snapshot_record_over_built_in_record(tmp_path: Path) -> None: + supervisor = _build_supervisor(tmp_path) + _write_android_app_plugin_snapshot( + supervisor, + [ + { + "version": 9999, + "url": "https://rrpkg-us.roborock.com/iot/plugin/cloud-23.zip", + "pluginLevel": 3001, + "productid": 23, + "apilevel": 10043, + } + ], + ) + client = TestClient(supervisor.app) + + response = client.post("/api/v1/appplugin", json={"apilevel": 10046, "productids": [23, 10001], "type": 2}) + + records = response.json()["data"] + assert [(item["productid"], item["version"]) for item in records] == [(23, 9999), (10001, 90)] + assert _source_from_proxied_url(records[0]["url"]) == "https://rrpkg-us.roborock.com/iot/plugin/cloud-23.zip" + + def test_plugin_category_zip_uses_expected_source_and_cache(tmp_path: Path, monkeypatch) -> None: from https_server.routes.plugin import common as plugin_common From 069e21524b4c0c23836a48ab43f5a7842631dc52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20R=2E=20H=C3=B6lzlwimmer?= Date: Sat, 21 Nov 2026 19:46:28 +0100 Subject: [PATCH 3/4] fix(plugin): answer no plugin for product ids that match nothing If the request sent product ids and neither the snapshot nor the built-in list had them, the route answered the full list. The app then installed its first record, which is the plugin of another model (the a87 plugin for an a307), and crashed when it opened the device. The route now answers an empty list in that case and keeps the full list for requests without ids. --- .../https_server/routes/api/v1/appplugin.py | 21 ++++-- tests/test_plugin_routes.py | 66 +++++++++++++------ 2 files changed, 61 insertions(+), 26 deletions(-) diff --git a/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/appplugin.py b/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/appplugin.py index ff028ba4..4df6a990 100644 --- a/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/appplugin.py +++ b/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/appplugin.py @@ -31,9 +31,11 @@ def _request_app_type(body_params: dict[str, list[str]]) -> int | None: return None -def _requested_product_ids(body_params: dict[str, list[str]]) -> set[int]: +def _requested_product_ids(body_params: dict[str, list[str]]) -> set[int] | None: # The app posts JSON like {"apilevel": 10046, "productids": [263], "type": 2}. - # Form bodies may repeat the field or join the ids with commas. + # Form bodies may repeat the field or join the ids with commas. None means + # that the request sent no ids. An empty set means that it sent only ids + # that are not valid product ids. values: list[Any] = [] for raw in body_params.get("__json") or []: try: @@ -45,7 +47,10 @@ def _requested_product_ids(body_params: dict[str, list[str]]) -> set[int]: values.extend(requested if isinstance(requested, list) else [requested]) for raw in body_params.get("productids") or []: values.extend(str(raw).strip("[] ").split(",")) - product_ids = {as_int(value, 0) for value in values if value is not None} + values = [value for value in values if value is not None and str(value).strip()] + if not values: + return None + product_ids = {as_int(value, 0) for value in values} product_ids.discard(0) return product_ids @@ -66,8 +71,12 @@ def build( # one. Imports from before the iOS catalog existed fall back to Android. snapshot_records = snapshot_plugin_records(ctx, "appplugin_ios") or snapshot_records product_ids = _requested_product_ids(body_params) - # The app installs the first record without checking its productid, so a - # device must only get the records for the product ids it asked for. + if product_ids is None: + return ok(proxied_plugin_records(ctx, snapshot_records or APPPLUGIN_LIST)) + # When the app opens a device, it installs the first record without + # checking its productid. So a device must only get the records for the + # product ids it asked for. If no record matches, the answer is an empty + # list. matching = [record for record in snapshot_records if _product_id(record) in product_ids] # A device added after the snapshot import has no snapshot record, so the # ids that the snapshot lacks come from the built-in list. The built-in list @@ -76,4 +85,4 @@ def build( # above has the same limitation if the snapshot has no iOS catalog. missing_ids = product_ids - {_product_id(record) for record in snapshot_records} matching += [record for record in APPPLUGIN_LIST if _product_id(record) in missing_ids] - return ok(proxied_plugin_records(ctx, matching or snapshot_records or APPPLUGIN_LIST)) + return ok(proxied_plugin_records(ctx, matching)) diff --git a/tests/test_plugin_routes.py b/tests/test_plugin_routes.py index 4d533efe..f68b1528 100644 --- a/tests/test_plugin_routes.py +++ b/tests/test_plugin_routes.py @@ -157,22 +157,63 @@ def test_app_plugin_reads_product_ids_from_form_body(tmp_path: Path) -> None: assert _app_plugin_product_ids(joined.json()) == [23, 10001] -def test_app_plugin_answers_full_list_without_matching_product_ids(tmp_path: Path) -> None: +def _write_android_app_plugin_snapshot(supervisor: ReleaseSupervisor, records: list[dict]) -> None: + _write_app_plugin_snapshot(supervisor, {"appplugin": {"data": records}}) + + +_SNAPSHOT_APP_PLUGIN_RECORD = { + "version": 7777, + "url": "https://rrpkg-us.roborock.com/iot/plugin/cloud-only.zip", + "pluginLevel": 3001, + "productid": 4242, + "apilevel": 10043, +} + +# Run each case once with the built-in list and once with a cloud snapshot catalog. +_APP_PLUGIN_CATALOGS = pytest.mark.parametrize( + "snapshot_records", + [None, [_SNAPSHOT_APP_PLUGIN_RECORD]], + ids=["built_in", "snapshot"], +) + + +@_APP_PLUGIN_CATALOGS +def test_app_plugin_answers_full_list_without_product_ids(tmp_path: Path, snapshot_records: list[dict] | None) -> None: from https_server.routes.plugin import common as plugin_common supervisor = _build_supervisor(tmp_path) + if snapshot_records is not None: + _write_android_app_plugin_snapshot(supervisor, snapshot_records) client = TestClient(supervisor.app) - full_list = [record["productid"] for record in plugin_common.APPPLUGIN_LIST] + full_list = [record["productid"] for record in snapshot_records or plugin_common.APPPLUGIN_LIST] no_body = client.post("/api/v1/appplugin") no_ids = client.post("/api/v1/appplugin", json={"apilevel": 10046, "type": 2}) empty_ids = client.post("/api/v1/appplugin", json={"apilevel": 10046, "productids": [], "type": 2}) - unknown_id = client.post("/api/v1/appplugin", json={"apilevel": 10046, "productids": [659231], "type": 2}) assert _app_plugin_product_ids(no_body.json()) == full_list assert _app_plugin_product_ids(no_ids.json()) == full_list assert _app_plugin_product_ids(empty_ids.json()) == full_list - assert _app_plugin_product_ids(unknown_id.json()) == full_list + + +@_APP_PLUGIN_CATALOGS +def test_app_plugin_answers_no_plugin_for_unmatched_product_ids( + tmp_path: Path, snapshot_records: list[dict] | None +) -> None: + supervisor = _build_supervisor(tmp_path) + if snapshot_records is not None: + _write_android_app_plugin_snapshot(supervisor, snapshot_records) + client = TestClient(supervisor.app) + + # The app would install the first record of a full list, which is the plugin of another model. + unknown_id = client.post("/api/v1/appplugin", json={"apilevel": 10046, "productids": [659231], "type": 2}) + # Ids that are no valid product ids match nothing either. + invalid_ids = client.post("/api/v1/appplugin", json={"apilevel": 10046, "productids": ["abc", 0], "type": 2}) + invalid_form_id = client.post("/api/v1/appplugin", data={"productids": "abc"}) + + assert _app_plugin_product_ids(unknown_id.json()) == [] + assert _app_plugin_product_ids(invalid_ids.json()) == [] + assert _app_plugin_product_ids(invalid_form_id.json()) == [] def test_app_plugin_filters_cloud_snapshot_catalog(tmp_path: Path) -> None: @@ -211,25 +252,10 @@ def test_app_plugin_filters_cloud_snapshot_catalog(tmp_path: Path) -> None: assert _source_from_proxied_url(record["url"]) == "https://rrpkg-us.roborock.com/iot/plugin/cloud-second.zip" -def _write_android_app_plugin_snapshot(supervisor: ReleaseSupervisor, records: list[dict]) -> None: - _write_app_plugin_snapshot(supervisor, {"appplugin": {"data": records}}) - - def test_app_plugin_falls_back_to_built_in_list_for_ids_missing_from_snapshot(tmp_path: Path) -> None: supervisor = _build_supervisor(tmp_path) # A device added after the snapshot import has no record in the snapshot. - _write_android_app_plugin_snapshot( - supervisor, - [ - { - "version": 7777, - "url": "https://rrpkg-us.roborock.com/iot/plugin/cloud-only.zip", - "pluginLevel": 3001, - "productid": 4242, - "apilevel": 10043, - } - ], - ) + _write_android_app_plugin_snapshot(supervisor, [_SNAPSHOT_APP_PLUGIN_RECORD]) client = TestClient(supervisor.app) missing = client.post("/api/v1/appplugin", json={"apilevel": 10046, "productids": [23], "type": 2}) From 0775e38c86453a0980c1c84f165b7d1a8b071d86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20R=2E=20H=C3=B6lzlwimmer?= Date: Sat, 21 Nov 2026 20:06:08 +0100 Subject: [PATCH 4/4] test(plugin): cover iOS app plugin requests with product ids The route picks the iOS catalog for type 1 requests and then keeps only the requested product ids. The new tests check that an iOS request gets the iOS record of the requested id, and the full iOS list without ids. An id that only the Android catalog has gets the built-in record or nothing, and an unmatched id gets an empty list. --- tests/test_plugin_routes.py | 75 +++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/tests/test_plugin_routes.py b/tests/test_plugin_routes.py index f68b1528..1c65e70b 100644 --- a/tests/test_plugin_routes.py +++ b/tests/test_plugin_routes.py @@ -454,3 +454,78 @@ def test_app_plugin_ios_falls_back_to_android_catalog_from_older_imports(tmp_pat [record] = response.json()["data"] assert _source_from_proxied_url(record["url"]) == ANDROID_ZIP + + +def _app_plugin_record(product_id: int, url: str) -> dict: + return {"version": 6846, "url": url, "pluginLevel": 3002, "productid": product_id, "apilevel": 10030} + + +IOS_ONLY_ZIP = "https://app-files.roborock.com/iot/plugin/ios-only.zip" +ANDROID_ONLY_ZIP = "https://app-files.roborock.com/iot/plugin/android-only.zip" +ANDROID_23_ZIP = "https://app-files.roborock.com/iot/plugin/android-23.zip" + + +def _ios_app_plugin_client(tmp_path: Path) -> TestClient: + # Product 199 is in both catalogs, and 300 is only in the iOS catalog. Products 23 + # and 4242 are only in the Android catalog. The built-in list also has 23. + supervisor = _build_supervisor(tmp_path) + _write_app_plugin_snapshot( + supervisor, + { + "appplugin": { + "data": [ + _app_plugin_record(199, ANDROID_ZIP), + _app_plugin_record(23, ANDROID_23_ZIP), + _app_plugin_record(4242, ANDROID_ONLY_ZIP), + ] + }, + "appplugin_ios": {"data": [_app_plugin_record(199, IOS_ZIP), _app_plugin_record(300, IOS_ONLY_ZIP)]}, + }, + ) + return TestClient(supervisor.app) + + +def _app_plugin_sources(payload: dict) -> list[tuple[int, str]]: + assert payload["code"] == 200 + return [(item["productid"], _source_from_proxied_url(item["url"])) for item in payload["data"]] + + +def test_app_plugin_ios_answers_requested_ids_from_ios_catalog(tmp_path: Path) -> None: + client = _ios_app_plugin_client(tmp_path) + + response = client.post("/api/v1/appplugin", json={"apilevel": 10046, "productids": [199], "type": 1}) + + assert _app_plugin_sources(response.json()) == [(199, IOS_ZIP)] + + +def test_app_plugin_ios_ignores_android_catalog_if_ios_catalog_exists(tmp_path: Path) -> None: + from https_server.routes.plugin import common as plugin_common + + client = _ios_app_plugin_client(tmp_path) + [built_in_23] = [record for record in plugin_common.APPPLUGIN_LIST if record["productid"] == 23] + + # The iOS catalog replaces the whole Android catalog. So an id that only the + # Android catalog has gets the built-in record, or nothing. + android_only = client.post("/api/v1/appplugin", json={"apilevel": 10046, "productids": [4242], "type": 1}) + built_in = client.post("/api/v1/appplugin", json={"apilevel": 10046, "productids": [23], "type": 1}) + + assert _app_plugin_sources(android_only.json()) == [] + assert _app_plugin_sources(built_in.json()) == [(23, built_in_23["url"])] + + +def test_app_plugin_ios_answers_no_plugin_for_unmatched_product_ids(tmp_path: Path) -> None: + client = _ios_app_plugin_client(tmp_path) + + response = client.post("/api/v1/appplugin", json={"apilevel": 10046, "productids": [659231], "type": 1}) + + assert _app_plugin_sources(response.json()) == [] + + +def test_app_plugin_ios_answers_full_ios_catalog_without_product_ids(tmp_path: Path) -> None: + client = _ios_app_plugin_client(tmp_path) + + no_ids = client.post("/api/v1/appplugin", json={"apilevel": 10046, "type": 1}) + empty_ids = client.post("/api/v1/appplugin", json={"apilevel": 10046, "productids": [], "type": 1}) + + assert _app_plugin_sources(no_ids.json()) == [(199, IOS_ZIP), (300, IOS_ONLY_ZIP)] + assert _app_plugin_sources(empty_ids.json()) == [(199, IOS_ZIP), (300, IOS_ONLY_ZIP)]