chore: sprint cleanup — language unification, parser unification, fossils removal

Several weeks of work accumulated without being committed. Grouped here for
clarity; see CHANGELOG.md [Unreleased] for the user-facing summary.

Highlights
----------

P1 #2 — ISO 639-2/B canonical migration
- New Language VO + LanguageRegistry (alfred/domain/shared/knowledge/).
- iso_languages.yaml as single source of truth for language codes.
- SubtitleKnowledgeBase now delegates lookup to LanguageRegistry; subtitles.yaml
  only declares subtitle-specific tokens (vostfr, vf, vff, …).
- SubtitlePreferences default → ["fre", "eng"]; subtitle filenames written as
  {iso639_2b}.srt (legacy fr.srt still read via alias).
- Scanner: dropped _LANG_KEYWORDS / _SDH_TOKENS / _FORCED_TOKENS /
  SUBTITLE_EXTENSIONS hardcoded dicts.
- Fixed: 'hi' token no longer marks SDH (conflicted with Hindi alias).
- Added settings.min_movie_size_bytes (was a module constant).

P1 #3 — Release parser unification + data-driven tokenizer
- parse_release() is now the single source of truth for release-name parsing.
- alfred/knowledge/release/separators.yaml declares the token separators used
  by the tokenizer (., space, [, ], (, ), _). New conventions can be added
  without code changes.
- Tokenizer now splits on any configured separator instead of name.split('.').
  Releases like 'The Father (2020) [1080p] [WEBRip] [5.1] [YTS.MX]' parse via
  the direct path without sanitization fallback.
- Site-tag extraction always runs first; well-formedness only rejects truly
  forbidden chars.
- _parse_season_episode() extended with NxNN / NxNNxNN alt forms.
- Removed dead helpers: _sanitize, _normalize.

Domain cleanup
- Deleted fossil services with zero production callers:
    alfred/domain/movies/services.py
    alfred/domain/tv_shows/services.py
    alfred/domain/subtitles/services.py (replaced by subtitles/services/ package)
    alfred/domain/subtitles/repositories.py
- Split monolithic subtitle services into a package (identifier, matcher,
  placer, pattern_detector, utils) + dedicated knowledge/ package.
- MediaInfo split into dedicated package (alfred/domain/shared/media/:
  audio, video, subtitle, info, matching).

Persistence cleanup
- Removed dead JSON repositories (movie/subtitle/tvshow_repository.py).

Tests
- Major expansion of the test suite organized to mirror the source tree.
- Removed obsolete *_edge_cases test files superseded by structured tests.
- Suite: 990 passed, 8 skipped.

Misc
- .gitignore: exclude env_backup/ and *.bak.
- Adjustments across agent/llm, app.py, application/filesystem, and
  infrastructure/filesystem to align with the new domain layout.
This commit is contained in:
2026-05-17 23:38:00 +02:00
parent ba6f016d49
commit e07c9ec77b
99 changed files with 8833 additions and 6533 deletions
+59 -20
View File
@@ -1,5 +1,20 @@
"""
Tests for alfred.agent.workflows.loader.WorkflowLoader
"""Tests for ``alfred.agent.workflows.loader.WorkflowLoader``.
Two layers of coverage:
1. **TestRealWorkflows** — Asserts on the YAML files that ship in the repo
(``alfred/agent/workflows/``). These tests act as a structural contract:
if a step id, tool name, or naming convention is renamed, the test
surfaces the change immediately. They use the real loader with no
monkeypatching.
2. **TestLoaderMechanics** — Loader behavior in isolation, using a
monkeypatched workflows directory. Covers ``get`` / ``names`` / ``all``,
YAML ``name`` precedence over filename, malformed-file resilience,
deterministic ordering on name collision, and the empty-directory case.
Current workflow naming convention is ``<domain>.<workflow_name>``
(e.g. ``media.organize_media``), not the legacy bare ``organize_media``.
"""
import pytest
@@ -7,6 +22,10 @@ import yaml
from alfred.agent.workflows.loader import WorkflowLoader
ORGANIZE_MEDIA = "media.organize_media"
MANAGE_SUBTITLES = "media.manage_subtitles"
# ---------------------------------------------------------------------------
# Fixtures
# ---------------------------------------------------------------------------
@@ -42,51 +61,69 @@ def loader_from_dir(workflows_dir, monkeypatch):
class TestRealWorkflows:
"""Contract tests against the workflows shipped in ``alfred/agent/workflows``."""
def test_organize_media_loaded(self):
loader = WorkflowLoader()
assert "organize_media" in loader.names()
assert ORGANIZE_MEDIA in loader.names()
def test_manage_subtitles_loaded(self):
loader = WorkflowLoader()
assert MANAGE_SUBTITLES in loader.names()
def test_organize_media_has_required_keys(self):
loader = WorkflowLoader()
wf = loader.get("organize_media")
assert "name" in wf
wf = loader.get(ORGANIZE_MEDIA)
assert wf is not None
assert wf["name"] == ORGANIZE_MEDIA
assert "steps" in wf
assert "tools" in wf
def test_organize_media_tools_list(self):
loader = WorkflowLoader()
wf = loader.get("organize_media")
wf = loader.get(ORGANIZE_MEDIA)
tools = wf["tools"]
assert "list_folder" in tools
assert "move_media" in tools
assert "manage_subtitles" in tools
assert "create_seed_links" in tools
assert "resolve_destination" in tools
# The four required tools that compose the move pipeline.
for required in (
"list_folder",
"move_to_destination",
"manage_subtitles",
"create_seed_links",
):
assert required in tools, f"missing tool: {required}"
# There is no single ``resolve_destination`` tool anymore — the
# workflow declares the four media-type-specific resolvers.
for resolver in (
"resolve_season_destination",
"resolve_episode_destination",
"resolve_movie_destination",
"resolve_series_destination",
):
assert resolver in tools, f"missing resolver: {resolver}"
def test_organize_media_steps_order(self):
loader = WorkflowLoader()
wf = loader.get("organize_media")
wf = loader.get(ORGANIZE_MEDIA)
step_ids = [s["id"] for s in wf["steps"]]
# resolve_destination must come before move_file
# resolve_destination is the *step id* (not tool name) that fans
# out to the four resolvers.
assert step_ids.index("resolve_destination") < step_ids.index("move_file")
# move_file before handle_subtitles
assert step_ids.index("move_file") < step_ids.index("handle_subtitles")
# ask_seeding before create_seed_links
assert step_ids.index("ask_seeding") < step_ids.index("create_seed_links")
def test_ask_seeding_has_yes_no_answers(self):
loader = WorkflowLoader()
wf = loader.get("organize_media")
wf = loader.get(ORGANIZE_MEDIA)
ask_step = next(s for s in wf["steps"] if s["id"] == "ask_seeding")
answers = ask_step["ask_user"]["answers"]
# PyYAML parses yes/no as booleans — we normalise to str in runtime
answer_keys = {str(k) for k in answers.keys()}
# PyYAML parses bare yes/no as booleans, quoted as strings — normalize.
answer_keys = {str(k).lower() for k in answers.keys()}
assert "yes" in answer_keys
assert "no" in answer_keys
def test_naming_convention_present(self):
loader = WorkflowLoader()
wf = loader.get("organize_media")
wf = loader.get(ORGANIZE_MEDIA)
assert "naming_convention" in wf
assert "tv_show" in wf["naming_convention"]
assert "movie" in wf["naming_convention"]
@@ -98,6 +135,8 @@ class TestRealWorkflows:
class TestLoaderMechanics:
"""Loader behavior driven by YAML files in a temp directory."""
def test_get_returns_workflow(self, loader_from_dir):
wf = loader_from_dir.get("test_workflow")
assert wf is not None
@@ -117,7 +156,7 @@ class TestLoaderMechanics:
assert "test_workflow" in all_wf
def test_uses_yaml_name_field(self, tmp_path, monkeypatch):
"""name from YAML content takes priority over filename stem."""
"""Name from YAML content takes priority over filename stem."""
import alfred.agent.workflows.loader as loader_module
monkeypatch.setattr(loader_module, "_WORKFLOWS_DIR", tmp_path)