e45465d52d
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.
126 lines
4.0 KiB
Python
126 lines
4.0 KiB
Python
"""
|
|
Tests for alfred.application.filesystem.create_seed_links.CreateSeedLinksUseCase
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from alfred.application.filesystem.create_seed_links import CreateSeedLinksUseCase
|
|
from alfred.infrastructure.filesystem.file_manager import FileManager
|
|
|
|
|
|
@pytest.fixture
|
|
def fm():
|
|
return FileManager()
|
|
|
|
|
|
@pytest.fixture
|
|
def use_case(fm):
|
|
return CreateSeedLinksUseCase(fm)
|
|
|
|
|
|
@pytest.fixture
|
|
def seed_env(tmp_path_factory):
|
|
"""
|
|
Realistic post-move environment (uses its own tmp dir, independent of app_temp):
|
|
- library video file (hard-linked from original)
|
|
- original download folder with remaining files
|
|
- torrents root folder
|
|
"""
|
|
d = tmp_path_factory.mktemp("seed_env")
|
|
|
|
lib_dir = (
|
|
d
|
|
/ "tv"
|
|
/ "Oz.1997.1080p.WEBRip.x265-KONTRAST"
|
|
/ "Oz.S01.1080p.WEBRip.x265-KONTRAST"
|
|
)
|
|
lib_dir.mkdir(parents=True)
|
|
lib_video = lib_dir / "Oz.S01E01.1080p.WEBRip.x265-KONTRAST.mp4"
|
|
lib_video.write_bytes(b"video")
|
|
|
|
dl = d / "downloads" / "Oz.S01.1080p.WEBRip.x265-KONTRAST"
|
|
dl.mkdir(parents=True)
|
|
(dl / "KONTRAST.txt").write_text("release notes")
|
|
(dl / "[TGx]info.txt").write_text("tgx")
|
|
subs = dl / "Subs" / "Oz.S01E01.1080p.WEBRip.x265-KONTRAST"
|
|
subs.mkdir(parents=True)
|
|
(subs / "2_eng,English [CC][SDH].srt").write_text(
|
|
"1\n00:00:01 --> 00:00:02\nHello\n"
|
|
)
|
|
|
|
torrents = d / "torrents"
|
|
torrents.mkdir()
|
|
|
|
return lib_video, dl, torrents
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Happy path
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
class TestCreateSeedLinksHappyPath:
|
|
def test_ok_when_torrent_folder_configured(
|
|
self, use_case, seed_env, memory_configured
|
|
):
|
|
from alfred.infrastructure.persistence import get_memory
|
|
|
|
mem = get_memory()
|
|
lib_video, dl, torrents = seed_env
|
|
mem.ltm.workspace.torrent = str(torrents)
|
|
mem.save()
|
|
|
|
result = use_case.execute(str(lib_video), str(dl))
|
|
|
|
assert result.status == "ok"
|
|
assert result.torrent_subfolder is not None
|
|
assert result.linked_file is not None
|
|
assert result.copied_count > 0
|
|
|
|
def test_to_dict_ok(self, use_case, seed_env, memory_configured):
|
|
from alfred.infrastructure.persistence import get_memory
|
|
|
|
mem = get_memory()
|
|
lib_video, dl, torrents = seed_env
|
|
mem.ltm.workspace.torrent = str(torrents)
|
|
mem.save()
|
|
|
|
d = use_case.execute(str(lib_video), str(dl)).to_dict()
|
|
assert d["status"] == "ok"
|
|
assert "torrent_subfolder" in d
|
|
assert "copied_files" in d
|
|
assert isinstance(d["copied_files"], list)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Error: torrent folder not configured
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
class TestCreateSeedLinksErrors:
|
|
def test_error_when_torrent_not_configured(self, use_case, seed_env, memory):
|
|
lib_video, dl, _ = seed_env
|
|
result = use_case.execute(str(lib_video), str(dl))
|
|
|
|
assert result.status == "error"
|
|
assert result.error == "torrent_folder_not_set"
|
|
assert result.message is not None
|
|
|
|
def test_to_dict_error(self, use_case, seed_env, memory):
|
|
lib_video, dl, _ = seed_env
|
|
d = use_case.execute(str(lib_video), str(dl)).to_dict()
|
|
assert d["status"] == "error"
|
|
assert "error" in d
|
|
assert "message" in d
|
|
|
|
def test_error_delegates_to_file_manager(self, memory_configured):
|
|
"""FileManager errors are propagated correctly."""
|
|
from alfred.infrastructure.persistence import get_memory
|
|
|
|
mem = get_memory()
|
|
# torrent already configured by memory_configured fixture
|
|
# library_file does not exist → should propagate error from FileManager
|
|
uc = CreateSeedLinksUseCase(FileManager())
|
|
result = uc.execute("/nonexistent/lib.mkv", "/nonexistent/dl")
|
|
assert result.status == "error"
|