-
Notifications
You must be signed in to change notification settings - Fork 353
fix: Storyline 自动提取后无法匹配已有故事线 #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
liaoyl830
wants to merge
1
commit into
shenminglinyi:master
Choose a base branch
from
liaoyl830:fix/issue-187
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
tests/unit/application/services/test_state_updater_storyline_resolution.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| """Test storyline name resolution and auto-creation logic in StateUpdater.""" | ||
| import pytest | ||
| from unittest.mock import Mock | ||
| from application.analyst.services.state_updater import StateUpdater | ||
| from domain.novel.value_objects.novel_id import NovelId | ||
| from domain.novel.entities.storyline import Storyline | ||
| from domain.novel.value_objects.storyline_type import StorylineType | ||
| from domain.novel.value_objects.storyline_status import StorylineStatus | ||
| from domain.novel.repositories.storyline_repository import StorylineRepository | ||
| from domain.bible.repositories.bible_repository import BibleRepository | ||
| from domain.novel.repositories.foreshadowing_repository import ForeshadowingRepository | ||
|
|
||
|
|
||
| class TestStorylineResolution: | ||
| """Test _resolve_storyline_by_name fuzzy matching logic.""" | ||
|
|
||
| def setup_method(self): | ||
| """Set up test fixtures.""" | ||
| self.storyline_repository = Mock(spec=StorylineRepository) | ||
| self.updater = StateUpdater( | ||
| bible_repository=Mock(spec=BibleRepository), | ||
| foreshadowing_repository=Mock(spec=ForeshadowingRepository), | ||
| storyline_repository=self.storyline_repository, | ||
| ) | ||
| self.novel_id = NovelId("novel-test") | ||
|
|
||
| def _make_storyline(self, id: str, name: str) -> Storyline: | ||
| return Storyline( | ||
| id=id, | ||
| novel_id=self.novel_id, | ||
| storyline_type=StorylineType.GROWTH, | ||
| status=StorylineStatus.ACTIVE, | ||
| estimated_chapter_start=1, | ||
| estimated_chapter_end=50, | ||
| name=name, | ||
| ) | ||
|
|
||
| def test_exact_match(self): | ||
| """Exact name match should return the storyline.""" | ||
| sl = self._make_storyline("sl-1", "盲眼老人的阵盘") | ||
| self.storyline_repository.get_by_novel_id.return_value = [sl] | ||
|
|
||
| result = self.updater._resolve_storyline_by_name(self.novel_id, "盲眼老人的阵盘") | ||
| assert result is not None | ||
| assert result.id == "sl-1" | ||
|
|
||
| def test_normalized_match(self): | ||
| """Normalized match (case/whitespace insensitive) should work.""" | ||
| sl = self._make_storyline("sl-2", "收割教廷阴谋") | ||
| self.storyline_repository.get_by_novel_id.return_value = [sl] | ||
|
|
||
| # Different whitespace/case | ||
| result = self.updater._resolve_storyline_by_name(self.novel_id, " 收割教廷阴谋 ") | ||
| assert result is not None | ||
| assert result.id == "sl-2" | ||
|
|
||
| def test_substring_match_unique(self): | ||
| """Unique substring match should return the storyline.""" | ||
| sl = self._make_storyline("sl-3", "碎片之谜") | ||
| self.storyline_repository.get_by_novel_id.return_value = [sl] | ||
|
|
||
| # LLM might extract a partial name | ||
| result = self.updater._resolve_storyline_by_name(self.novel_id, "碎片") | ||
| assert result is not None | ||
| assert result.id == "sl-3" | ||
|
|
||
| def test_substring_match_ambiguous_returns_none(self): | ||
| """Ambiguous substring match should return None.""" | ||
| sl1 = self._make_storyline("sl-4", "碎片之谜") | ||
| sl2 = self._make_storyline("sl-5", "碎片的秘密") | ||
| self.storyline_repository.get_by_novel_id.return_value = [sl1, sl2] | ||
|
|
||
| result = self.updater._resolve_storyline_by_name(self.novel_id, "碎片") | ||
| assert result is None | ||
|
|
||
| def test_no_match_returns_none(self): | ||
| """No match should return None.""" | ||
| sl = self._make_storyline("sl-6", "主线剧情") | ||
| self.storyline_repository.get_by_novel_id.return_value = [sl] | ||
|
|
||
| result = self.updater._resolve_storyline_by_name(self.novel_id, "完全无关的名称") | ||
| assert result is None | ||
|
|
||
| def test_empty_storyline_list_returns_none(self): | ||
| """Empty storyline list should return None.""" | ||
| self.storyline_repository.get_by_novel_id.return_value = [] | ||
|
|
||
| result = self.updater._resolve_storyline_by_name(self.novel_id, "任何名称") | ||
| assert result is None | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename parameter to avoid shadowing Python builtin.
The parameter name
idshadows the Python builtin function. Consider using a more specific name likestoryline_idorsl_id.🛠️ Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 Ruff (0.15.15)
[error] 27-27: Function argument
idis shadowing a Python builtin(A002)
🤖 Prompt for AI Agents
Source: Linters/SAST tools