Skip to content

Commit ee3cdf7

Browse files
committed
put staff picks in correct dirs
1 parent 00885da commit ee3cdf7

2 files changed

Lines changed: 73 additions & 1 deletion

File tree

src/redfetch/sync_discovery.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,11 @@ def _add_root_target(
192192
category_id = payload_category_id(payload)
193193
resolved_path = None
194194
settings_for_env = config.settings.from_env(settings_env)
195-
if str(resource_id) in settings_for_env.SPECIAL_RESOURCES or category_id is not None:
195+
special_resource = settings_for_env.SPECIAL_RESOURCES.get(str(resource_id))
196+
has_own_destination = bool(
197+
special_resource and (special_resource.get("custom_path") or special_resource.get("default_path"))
198+
)
199+
if has_own_destination or category_id is not None:
196200
resolved_path = resolve_root_path(resource_id, category_id, settings_env)
197201
target = DesiredInstallTarget(
198202
target_key=make_root_target_key(resource_id),

tests/test_sync_pipeline_regressions.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
from __future__ import annotations
44

55
import asyncio
6+
import os
67
import sqlite3
78
from pathlib import Path
9+
from types import SimpleNamespace
10+
from unittest.mock import MagicMock, patch
811

912
from redfetch import store
1013
from redfetch import sync_planner as planner
14+
from redfetch.sync_discovery import _add_root_target
1115
from redfetch.sync_types import (
1216
DesiredInstallTarget,
1317
DesiredSet,
@@ -257,3 +261,67 @@ def test_reset_download_date_for_resource_does_not_reset_unrelated_dependency_oc
257261
]
258262

259263

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

Comments
 (0)