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
+23 -6
View File
@@ -1,4 +1,19 @@
"""Edge case tests for FastAPI endpoints."""
"""Edge-case tests for the FastAPI endpoints.
Covers adversarial and unusual inputs across each endpoint group:
- **TestChatCompletionsEdgeCases** — malformed payloads, missing roles,
null / empty content, system-or-assistant-only conversations, streaming
with tool-calls.
- **TestModelsEndpointEdgeCases** — response shape conformance.
- **TestMemoryEndpointsEdgeCases** — unicode in LTM paths, special chars
and quotes in stored search results, idempotency of clear-session, and
LTM preservation across clears.
- **TestHealthEndpointEdgeCases** — query-param tolerance, version string.
Uses the current LTM API (``ltm.workspace.download``); JSON assertions
target the new persisted shape (``data["ltm"]["workspace"]["download"]``).
"""
from unittest.mock import Mock, patch
@@ -337,7 +352,7 @@ class TestChatCompletionsEdgeCases:
from alfred.infrastructure.persistence import get_memory
mem = get_memory()
mem.ltm.download_folder = str(real_folder["downloads"])
mem.ltm.workspace.download = str(real_folder["downloads"])
call_count = [0]
@@ -453,7 +468,7 @@ class TestMemoryEndpointsEdgeCases:
mock_llm.return_value = Mock()
from alfred.app import app
memory.ltm.download_folder = "/path/日本語テスト"
memory.ltm.workspace.download = "/path/日本語テスト"
memory.stm.add_message("user", "🎬 Movie request")
client = TestClient(app)
@@ -461,7 +476,8 @@ class TestMemoryEndpointsEdgeCases:
assert response.status_code == 200
data = response.json()
assert "日本語" in str(data)
# Unicode must survive the JSON roundtrip in workspace paths.
assert data["ltm"]["workspace"]["download"] == "/path/日本語テスト"
def test_search_results_with_special_chars(self, memory):
"""Should handle special characters in search results."""
@@ -501,7 +517,7 @@ class TestMemoryEndpointsEdgeCases:
mock_llm.return_value = Mock()
from alfred.app import app
memory.ltm.download_folder = "/important/data"
memory.ltm.workspace.download = "/important/data"
memory.stm.add_message("user", "Hello")
client = TestClient(app)
@@ -510,7 +526,8 @@ class TestMemoryEndpointsEdgeCases:
response = client.get("/memory/state")
data = response.json()
assert data["ltm"]["download_folder"] == "/important/data"
# LTM survives the clear; STM is reset.
assert data["ltm"]["workspace"]["download"] == "/important/data"
assert data["stm"]["conversation_history"] == []