@@ -157,6 +157,37 @@ async def test_list_file_subtitles_supports_prefix_language_suffixes(client, tes
157157 )
158158
159159
160+ @pytest .mark .asyncio
161+ async def test_list_file_subtitles_supports_duplicate_leading_prefixes (client , test_run_dir ):
162+ subtitle_root = test_run_dir / "subtitles-duplicate-prefix"
163+ _write_subtitle_file (
164+ subtitle_root , "260503 260503 Rajira! Sunday 川﨑桜、梅澤美波 [REQUEST].ass" , "[Script Info]\n Title: Duplicate Prefix\n "
165+ )
166+
167+ with (
168+ patch ("backend.app.config.settings.subtitle_path" , str (subtitle_root )),
169+ patch ("backend.app.security.settings.allow_public_downloads" , True ),
170+ ):
171+ token_data = await create_token (client , max_uploads = 1 )
172+ upload_token = token_data ["token" ]
173+ download_token = token_data ["download_token" ]
174+
175+ upload_data = await initiate_upload (client , upload_token , "260503 Rajira! Sunday 川﨑桜、梅澤美波.mp4" , 5 , "video/mp4" )
176+ upload_id = upload_data ["upload_id" ]
177+ status_code = await upload_file_via_tus (client , upload_id , b"hello" , upload_token )
178+
179+ assert status_code == status .HTTP_200_OK , "Upload should complete successfully"
180+
181+ response = await client .get (
182+ app .url_path_for ("get_file_subtitle" , download_token = download_token , upload_id = upload_id , source_format = "ass" )
183+ )
184+
185+ assert response .status_code == status .HTTP_200_OK , "Repeated leading prefixes should still allow subtitle matching"
186+ assert "Title: Duplicate Prefix" in response .text , (
187+ "Subtitle matching should tolerate duplicate leading date prefixes before the shared filename stem"
188+ )
189+
190+
160191@pytest .mark .asyncio
161192async def test_list_file_subtitles_prefers_exact_stem_over_prefix_matches (client , test_run_dir ):
162193 subtitle_root = test_run_dir / "subtitles-exact-first"
@@ -185,6 +216,31 @@ async def test_list_file_subtitles_prefers_exact_stem_over_prefix_matches(client
185216 assert "Title: Exact" in response .text , "Exact stem matches should win over language-suffixed prefix matches"
186217
187218
219+ @pytest .mark .asyncio
220+ async def test_list_file_subtitles_ignores_midword_contains_matches (client , test_run_dir ):
221+ subtitle_root = test_run_dir / "subtitles-midword"
222+ _write_subtitle_file (subtitle_root , "myepisode.ass" , "[Script Info]\n Title: Midword\n " )
223+
224+ with (
225+ patch ("backend.app.config.settings.subtitle_path" , str (subtitle_root )),
226+ patch ("backend.app.security.settings.allow_public_downloads" , True ),
227+ ):
228+ token_data = await create_token (client , max_uploads = 1 )
229+ upload_token = token_data ["token" ]
230+ download_token = token_data ["download_token" ]
231+
232+ upload_data = await initiate_upload (client , upload_token , "episode.mkv" , 5 , "video/mp4" )
233+ upload_id = upload_data ["upload_id" ]
234+ status_code = await upload_file_via_tus (client , upload_id , b"hello" , upload_token )
235+
236+ assert status_code == status .HTTP_200_OK , "Upload should complete successfully"
237+
238+ response = await client .get (app .url_path_for ("list_file_subtitles" , download_token = download_token , upload_id = upload_id ))
239+
240+ assert response .status_code == status .HTTP_200_OK , "Subtitle manifest should still be returned"
241+ assert response .json ()["subtitles" ] == [], "Contains matching should not match unrelated mid-word stems"
242+
243+
188244@pytest .mark .asyncio
189245async def test_list_file_subtitles_skips_ambiguous_extension_matches (client , test_run_dir ):
190246 subtitle_root = test_run_dir / "subtitles-ambiguous"
0 commit comments