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.
This commit is contained in:
@@ -1,31 +1,31 @@
|
||||
"""Tests for ListFolderUseCase and MoveMediaUseCase."""
|
||||
|
||||
import pytest
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from alfred.application.filesystem.list_folder import ListFolderUseCase
|
||||
from alfred.application.filesystem.move_media import MoveMediaUseCase
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# ListFolderUseCase
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
class TestListFolderUseCase:
|
||||
|
||||
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,
|
||||
})
|
||||
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"
|
||||
@@ -34,11 +34,13 @@ class TestListFolderUseCase:
|
||||
assert resp.count == 2
|
||||
|
||||
def test_error_propagates(self):
|
||||
uc = self._use_case({
|
||||
"status": "error",
|
||||
"error": "folder_not_set",
|
||||
"message": "Download folder not configured.",
|
||||
})
|
||||
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"
|
||||
@@ -60,30 +62,37 @@ class TestListFolderUseCase:
|
||||
def test_default_path_is_dot(self):
|
||||
fm = MagicMock()
|
||||
fm.list_folder.return_value = {
|
||||
"status": "ok", "folder_type": "download",
|
||||
"path": ".", "entries": [], "count": 0,
|
||||
"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,
|
||||
})
|
||||
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",
|
||||
})
|
||||
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
|
||||
@@ -93,8 +102,8 @@ class TestListFolderUseCase:
|
||||
# MoveMediaUseCase
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
class TestMoveMediaUseCase:
|
||||
|
||||
class TestMoveMediaUseCase:
|
||||
def _use_case(self, fm_result):
|
||||
fm = MagicMock()
|
||||
fm.move_file.return_value = fm_result
|
||||
@@ -103,13 +112,15 @@ class TestMoveMediaUseCase:
|
||||
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,
|
||||
})
|
||||
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
|
||||
@@ -118,11 +129,13 @@ class TestMoveMediaUseCase:
|
||||
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",
|
||||
})
|
||||
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"
|
||||
@@ -132,19 +145,24 @@ class TestMoveMediaUseCase:
|
||||
dst = "/movies/Movie.2024/movie.mkv"
|
||||
fm = MagicMock()
|
||||
fm.move_file.return_value = {
|
||||
"status": "ok", "source": src, "destination": dst,
|
||||
"filename": "movie.mkv", "size": 1,
|
||||
"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",
|
||||
})
|
||||
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
|
||||
@@ -153,13 +171,15 @@ class TestMoveMediaUseCase:
|
||||
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,
|
||||
})
|
||||
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"
|
||||
@@ -167,11 +187,13 @@ class TestMoveMediaUseCase:
|
||||
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",
|
||||
})
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user