|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import asyncio |
| 6 | +import os |
6 | 7 | import sqlite3 |
7 | 8 | from pathlib import Path |
| 9 | +from types import SimpleNamespace |
| 10 | +from unittest.mock import MagicMock, patch |
8 | 11 |
|
9 | 12 | from redfetch import store |
10 | 13 | from redfetch import sync_planner as planner |
| 14 | +from redfetch.sync_discovery import _add_root_target |
11 | 15 | from redfetch.sync_types import ( |
12 | 16 | DesiredInstallTarget, |
13 | 17 | DesiredSet, |
@@ -257,3 +261,67 @@ def test_reset_download_date_for_resource_does_not_reset_unrelated_dependency_oc |
257 | 261 | ] |
258 | 262 |
|
259 | 263 |
|
| 264 | +def test_staff_pick_without_default_path_gets_category_subfolder(): |
| 265 | + """Staff picks (opt_in=True, no default_path) should be placed in the |
| 266 | + category subfolder under VanillaMQ (e.g. VanillaMQ_LIVE/lua), not dumped |
| 267 | + at the VanillaMQ root. |
| 268 | +
|
| 269 | + Regression: discovery was eagerly calling resolve_root_path with |
| 270 | + category_id=None for these resources, baking in a path that lacked the |
| 271 | + category subfolder. The planner then short-circuited because |
| 272 | + resolved_path was already set.""" |
| 273 | + download_folder = "C:/test/Downloads" |
| 274 | + special_resources = { |
| 275 | + "1974": {"default_path": "VanillaMQ_LIVE", "custom_path": "", "opt_in": True}, |
| 276 | + "2539": {"opt_in": True, "staff_pick": True}, |
| 277 | + } |
| 278 | + mock_settings = MagicMock() |
| 279 | + mock_settings.ENV = "LIVE" |
| 280 | + mock_settings.from_env.return_value = SimpleNamespace( |
| 281 | + DOWNLOAD_FOLDER=download_folder, |
| 282 | + SPECIAL_RESOURCES=special_resources, |
| 283 | + PROTECTED_FILES_BY_RESOURCE={}, |
| 284 | + ) |
| 285 | + |
| 286 | + with patch("redfetch.config.settings", mock_settings), \ |
| 287 | + patch("redfetch.config.VANILLA_MAP", {1974: "LIVE"}), \ |
| 288 | + patch("redfetch.config.CATEGORY_MAP", {8: "macros", 11: "plugins", 25: "lua"}): |
| 289 | + |
| 290 | + # Discovery: staff pick added from config only (no API payload) |
| 291 | + desired_set = DesiredSet(mode="full") |
| 292 | + target = _add_root_target( |
| 293 | + desired_set, |
| 294 | + resource_id="2539", |
| 295 | + sources={"special"}, |
| 296 | + payload=None, |
| 297 | + settings_env="LIVE", |
| 298 | + ) |
| 299 | + |
| 300 | + assert target.resolved_path is None, ( |
| 301 | + f"Discovery should defer path resolution for staff picks without " |
| 302 | + f"default_path, got {target.resolved_path}" |
| 303 | + ) |
| 304 | + |
| 305 | + # Planner resolves using remote state's category_id |
| 306 | + remote_snapshot = RemoteSnapshot( |
| 307 | + resources={ |
| 308 | + "2539": _downloadable_state("2539", category_id=25), |
| 309 | + } |
| 310 | + ) |
| 311 | + |
| 312 | + plan = planner.build_execution_plan( |
| 313 | + desired_set=desired_set, |
| 314 | + remote_snapshot=remote_snapshot, |
| 315 | + local_snapshot=LocalSnapshot(), |
| 316 | + settings_env="LIVE", |
| 317 | + ) |
| 318 | + |
| 319 | + action = plan.actions["/2539/"] |
| 320 | + assert action.action == "download" |
| 321 | + expected = os.path.normpath(os.path.join(download_folder, "VanillaMQ_LIVE", "lua")) |
| 322 | + assert action.resolved_path == expected, ( |
| 323 | + f"Expected {expected}, got {action.resolved_path}. " |
| 324 | + "Staff pick should land in VanillaMQ_LIVE/lua, not at the VanillaMQ root." |
| 325 | + ) |
| 326 | + |
| 327 | + |
0 commit comments