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:
@@ -1,4 +1,20 @@
|
||||
"""Edge case tests for the Agent."""
|
||||
"""Edge-case tests for ``alfred.agent.agent.Agent``.
|
||||
|
||||
Covers pathological tool-call inputs and unusual control flow:
|
||||
|
||||
- **TestExecuteToolCallEdgeCases** — malformed JSON arguments, unknown
|
||||
tools, extra/wrong-typed args, and propagation of ``KeyboardInterrupt``
|
||||
(must not be swallowed by the tool executor).
|
||||
- **TestStepEdgeCases** — empty input, oversize input, unicode input.
|
||||
- **TestAgentConcurrencyEdgeCases** — mid-step memory mutations through
|
||||
``set_path_for_folder``.
|
||||
- **TestAgentErrorRecovery** — recovery from tool errors during the loop.
|
||||
|
||||
The KeyboardInterrupt test patches ``visible_tool_names`` so the injected
|
||||
test tool is in scope; otherwise the agent's workflow-scope guard would
|
||||
short-circuit before ``tool.func()`` runs and the exception would never be
|
||||
raised.
|
||||
"""
|
||||
|
||||
from unittest.mock import Mock
|
||||
|
||||
@@ -31,8 +47,8 @@ class TestExecuteToolCallEdgeCases:
|
||||
|
||||
assert result is None or isinstance(result, dict)
|
||||
|
||||
def test_tool_raises_keyboard_interrupt(self, memory, mock_llm):
|
||||
"""Should propagate KeyboardInterrupt."""
|
||||
def test_tool_raises_keyboard_interrupt(self, memory, mock_llm, monkeypatch):
|
||||
"""KeyboardInterrupt raised by a tool must propagate up, not be swallowed."""
|
||||
agent = Agent(settings=settings, llm=mock_llm)
|
||||
|
||||
from alfred.agent.registry import Tool
|
||||
@@ -43,6 +59,12 @@ class TestExecuteToolCallEdgeCases:
|
||||
agent.tools["test_tool"] = Tool(
|
||||
name="test_tool", description="Test", func=raise_interrupt, parameters={}
|
||||
)
|
||||
# The scope guard (``visible_tool_names``) would otherwise short-circuit
|
||||
# the call before reaching ``tool.func()``. Make our injected tool
|
||||
# visible to reach the exception path under test.
|
||||
monkeypatch.setattr(
|
||||
agent.prompt_builder, "visible_tool_names", lambda: ["test_tool"]
|
||||
)
|
||||
|
||||
tool_call = {
|
||||
"id": "call_123",
|
||||
@@ -55,7 +77,7 @@ class TestExecuteToolCallEdgeCases:
|
||||
def test_tool_with_extra_args(self, memory, mock_llm, real_folder):
|
||||
"""Should handle extra arguments gracefully."""
|
||||
agent = Agent(settings=settings, llm=mock_llm)
|
||||
memory.ltm.download_folder = str(real_folder["downloads"])
|
||||
memory.ltm.workspace.download = str(real_folder["downloads"])
|
||||
|
||||
tool_call = {
|
||||
"id": "call_123",
|
||||
@@ -243,8 +265,8 @@ class TestAgentConcurrencyEdgeCases:
|
||||
assert len(history) == 4
|
||||
|
||||
def test_tool_modifies_memory_during_step(self, memory, mock_llm, real_folder):
|
||||
"""Should handle memory modifications during step."""
|
||||
memory.ltm.download_folder = str(real_folder["downloads"])
|
||||
"""A tool invocation must persist its mutation into LTM."""
|
||||
memory.ltm.workspace.download = str(real_folder["downloads"])
|
||||
|
||||
call_count = [0]
|
||||
|
||||
@@ -259,7 +281,7 @@ class TestAgentConcurrencyEdgeCases:
|
||||
"id": "call_1",
|
||||
"function": {
|
||||
"name": "set_path_for_folder",
|
||||
"arguments": f'{{"folder_name": "movie", "path_value": "{str(real_folder["movies"])}"}}',
|
||||
"arguments": f'{{"folder_name": "movies", "path_value": "{str(real_folder["movies"])}"}}',
|
||||
},
|
||||
}
|
||||
],
|
||||
@@ -272,7 +294,9 @@ class TestAgentConcurrencyEdgeCases:
|
||||
agent.step("Set movie folder")
|
||||
|
||||
mem = get_memory()
|
||||
assert mem.ltm.movie_folder == str(real_folder["movies"])
|
||||
# ``movies`` is a library collection (not download/torrent) → stored in
|
||||
# library_paths, not as a flat attribute.
|
||||
assert mem.ltm.library_paths.get("movies") == str(real_folder["movies"])
|
||||
|
||||
|
||||
class TestAgentErrorRecovery:
|
||||
|
||||
Reference in New Issue
Block a user