Files
alfred/tests/application/test_list_folder_move_media.py
francwa e45465d52d feat: split resolve_destination, persona-driven prompts, qBittorrent relocation
Destination resolution
- Replace the single ResolveDestinationUseCase with four dedicated
  functions, one per release type:
    resolve_season_destination    (pack season, folder move)
    resolve_episode_destination   (single episode, file move)
    resolve_movie_destination     (movie, file move)
    resolve_series_destination    (multi-season pack, folder move)
- Each returns a dedicated DTO carrying only the fields relevant to
  that release type — no more polymorphic ResolvedDestination with
  half the fields unused depending on the case.
- Looser series folder matching: exact computed-name match is reused
  silently; any deviation (different group, multiple candidates) now
  prompts the user with all options including the computed name.

Agent tools
- Four new tools wrapping the use cases above; old resolve_destination
  removed from the registry.
- New move_to_destination tool: create_folder + move, chained — used
  after a resolve_* call to perform the actual relocation.
- Low-level filesystem_operations module (create_folder, move via mv)
  for instant same-FS renames (ZFS).

Prompt & persona
- New PromptBuilder (alfred/agent/prompt.py) replacing prompts.py:
  identity + personality block, situational expressions, memory
  schema, episodic/STM/config context, tool catalogue.
- Per-user expression system: knowledge/users/common.yaml +
  {username}.yaml are merged at runtime; one phrase per situation
  (greeting/success/error/...) is sampled into the system prompt.

qBittorrent integration
- Credentials now come from settings (qbittorrent_url/username/password)
  instead of hardcoded defaults.
- New client methods: find_by_name, set_location, recheck — the trio
  needed to update a torrent's save path and re-verify after a move.
- Host→container path translation settings (qbittorrent_host_path /
  qbittorrent_container_path) for docker-mounted setups.

Subtitles
- Identifier: strip parenthesized qualifiers (simplified, brazil…) at
  tokenization; new _tokenize_suffix used for the episode_subfolder
  pattern so episode-stem tokens no longer pollute language detection.
- Placer: extract _build_dest_name so it can be reused by the new
  dry_run path in ManageSubtitlesUseCase.
- Knowledge: add yue, ell, ind, msa, rus, vie, heb, tam, tel, tha,
  hin, ukr; add 'fre' to fra; add 'simplified'/'traditional' to zho.

Misc
- LTM workspace: add 'trash' folder slot.
- Default LLM provider switched to deepseek.
- testing/debug_release.py: CLI to parse a release, hit TMDB, and
  dry-run the destination resolution end-to-end.
2026-05-14 05:01:59 +02:00

202 lines
6.1 KiB
Python

"""Tests for ListFolderUseCase and MoveMediaUseCase."""
from unittest.mock import MagicMock
from alfred.application.filesystem.list_folder import ListFolderUseCase
from alfred.application.filesystem.move_media import MoveMediaUseCase
# ---------------------------------------------------------------------------
# ListFolderUseCase
# ---------------------------------------------------------------------------
class TestListFolderUseCase:
def _use_case(self, fm_result):
fm = MagicMock()
fm.list_folder.return_value = fm_result
return ListFolderUseCase(fm)
def test_success_returns_response(self):
uc = self._use_case(
{
"status": "ok",
"folder_type": "download",
"path": ".",
"entries": ["movie.mkv", "show/"],
"count": 2,
}
)
resp = uc.execute("download")
assert resp.status == "ok"
assert resp.folder_type == "download"
assert resp.path == "."
assert resp.entries == ["movie.mkv", "show/"]
assert resp.count == 2
def test_error_propagates(self):
uc = self._use_case(
{
"status": "error",
"error": "folder_not_set",
"message": "Download folder not configured.",
}
)
resp = uc.execute("download")
assert resp.status == "error"
assert resp.error == "folder_not_set"
assert resp.message == "Download folder not configured."
def test_delegates_folder_type_and_path(self):
fm = MagicMock()
fm.list_folder.return_value = {
"status": "ok",
"folder_type": "tv_show",
"path": "Breaking Bad",
"entries": [],
"count": 0,
}
uc = ListFolderUseCase(fm)
uc.execute("tv_show", "Breaking Bad")
fm.list_folder.assert_called_once_with("tv_show", "Breaking Bad")
def test_default_path_is_dot(self):
fm = MagicMock()
fm.list_folder.return_value = {
"status": "ok",
"folder_type": "download",
"path": ".",
"entries": [],
"count": 0,
}
uc = ListFolderUseCase(fm)
uc.execute("download")
fm.list_folder.assert_called_once_with("download", ".")
def test_success_response_has_no_error(self):
uc = self._use_case(
{
"status": "ok",
"folder_type": "movie",
"path": ".",
"entries": [],
"count": 0,
}
)
resp = uc.execute("movie")
assert resp.error is None
def test_error_response_has_no_entries(self):
uc = self._use_case(
{
"status": "error",
"error": "not_found",
"message": "Path does not exist",
}
)
resp = uc.execute("download", "some/path")
assert resp.entries is None
assert resp.count is None
# ---------------------------------------------------------------------------
# MoveMediaUseCase
# ---------------------------------------------------------------------------
class TestMoveMediaUseCase:
def _use_case(self, fm_result):
fm = MagicMock()
fm.move_file.return_value = fm_result
return MoveMediaUseCase(fm)
def test_success_returns_response(self, tmp_path):
src = str(tmp_path / "src.mkv")
dst = str(tmp_path / "dst.mkv")
uc = self._use_case(
{
"status": "ok",
"source": src,
"destination": dst,
"filename": "dst.mkv",
"size": 1024,
}
)
resp = uc.execute(src, dst)
assert resp.status == "ok"
assert resp.source == src
assert resp.destination == dst
assert resp.filename == "dst.mkv"
assert resp.size == 1024
def test_error_propagates(self, tmp_path):
uc = self._use_case(
{
"status": "error",
"error": "source_not_found",
"message": "Source does not exist: /ghost.mkv",
}
)
resp = uc.execute("/ghost.mkv", str(tmp_path / "dst.mkv"))
assert resp.status == "error"
assert resp.error == "source_not_found"
def test_delegates_to_file_manager(self, tmp_path):
src = "/downloads/movie.mkv"
dst = "/movies/Movie.2024/movie.mkv"
fm = MagicMock()
fm.move_file.return_value = {
"status": "ok",
"source": src,
"destination": dst,
"filename": "movie.mkv",
"size": 1,
}
uc = MoveMediaUseCase(fm)
uc.execute(src, dst)
fm.move_file.assert_called_once_with(src, dst)
def test_error_response_has_no_paths(self):
uc = self._use_case(
{
"status": "error",
"error": "destination_exists",
"message": "File already exists",
}
)
resp = uc.execute("/src.mkv", "/dst.mkv")
assert resp.source is None
assert resp.destination is None
assert resp.filename is None
def test_to_dict_success(self, tmp_path):
src = "/downloads/movie.mkv"
dst = "/movies/movie.mkv"
uc = self._use_case(
{
"status": "ok",
"source": src,
"destination": dst,
"filename": "movie.mkv",
"size": 2048,
}
)
resp = uc.execute(src, dst)
d = resp.to_dict()
assert d["status"] == "ok"
assert d["filename"] == "movie.mkv"
assert d["size"] == 2048
def test_to_dict_error(self):
uc = self._use_case(
{
"status": "error",
"error": "link_failed",
"message": "Cross-device link not permitted",
}
)
resp = uc.execute("/src.mkv", "/dst.mkv")
d = resp.to_dict()
assert d["status"] == "error"
assert "error" in d
assert "message" in d