Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Remove unreachable chunking-config disabled fallback and close naming-template precedence + speaker auto-filter mutation survivors
Murtaza Nasirc22167fa9fcb
diff --git a/src/audio_chunking.py b/src/audio_chunking.pyindex b5d9a569..093a380c 100644--- a/src/audio_chunking.py+++ b/src/audio_chunking.py@@ -202,24 +202,16 @@ def get_effective_chunking_config(source='connector_recommended')- # App defaults- if enable_chunking_env != 'false':- logger.info("Chunking: Using app defaults (20MB size-based)")- return EffectiveChunkingConfig(- enabled=True,- mode='size',- limit_value=20.0,- overlap_seconds=overlap_seconds,- source='app_default'- )-- # Final fallback: disabled+ # App defaults. The ENABLE_CHUNKING=false case has already returned a+ # 'disabled' config above, so this is the only remaining path (the previous+ # 'final fallback: disabled' return here was unreachable dead code).+ logger.info("Chunking: Using app defaults (20MB size-based)")return EffectiveChunkingConfig(- enabled=False,- mode='none',- limit_value=0,+ enabled=True,+ mode='size',+ limit_value=20.0,overlap_seconds=overlap_seconds,- source='disabled'+ source='app_default')class AudioChunkingService:diff --git a/tests/test_cov_inquire.py b/tests/test_cov_inquire.pyindex ae5f579f..9e984f89 100644--- a/tests/test_cov_inquire.py+++ b/tests/test_cov_inquire.py@@ -1080,3 +1080,59 @@ def test_available_filters_error_500(client):resp = client.get('/api/inquire/available_filters')assert resp.status_code == 500assert 'error' in resp.get_json()+++def test_chat_rag_present_speaker_not_auto_filtered(client):+ """inquire.py:433 — a mentioned speaker who is ALREADY present in the initial+ chunk results must NOT trigger the auto speaker-filter re-search.++ The user message mentions 'Alice', who is an available speaker (a recording+ lists her as a participant) AND whose chunks are already in the results. So+ `speaker_in_results` becomes True, Alice is NOT appended to+ `mentioned_speakers`, and no speaker-filtered re-search is run.++ MUTATION-VERIFIED: line 433 `speaker_in_results = True`->`False` makes the+ present speaker look missing, so Alice is appended and the auto speaker+ filter fires — semantic_search_chunks gets called with+ filters['speaker_names'] == ['Alice'] and a 'filtering' status event is+ emitted -> this test FAILS.+ """+ user_id = _make_user()+ # alice_rec's participants make 'Alice' an available speaker for this user.+ alice_rec = _make_recording(user_id, title="Alice Rec", participants="Alice")++ a1 = "ALICEPRESENTONE_" + _suffix()+ a2 = "ALICEPRESENTTWO_" + _suffix()+ a1_id = _make_chunk(user_id, alice_rec, content=a1,+ speaker_name="Alice", chunk_index=0)+ a2_id = _make_chunk(user_id, alice_rec, content=a2,+ speaker_name="Alice", chunk_index=1)++ search_filters = []++ def search_se(uid, query, filters, top_k):+ # Record the filters of every search so we can assert no speaker re-search.+ search_filters.append(dict(filters) if filters else {})+ # Alice is already present in the initial results (two distinct chunks so+ # len >= 2 skips the downstream "<2 results" broader re-search).+ return [_get_chunk_pair(a1_id, 0.9), _get_chunk_pair(a2_id, 0.8)]++ captured = {}+ with _login(client, user_id), \+ patch('src.api.inquire.ENABLE_INQUIRE_MODE', True), \+ patch('src.api.inquire.client', MagicMock()), \+ patch('src.api.inquire.EMBEDDINGS_AVAILABLE', True), \+ patch('src.api.inquire.call_llm_completion', side_effect=_rag_router_then('[]')), \+ patch('src.api.inquire.semantic_search_chunks', side_effect=search_se), \+ patch('src.api.inquire.call_chat_completion',+ side_effect=_capturing_chat_completion(captured)):+ resp = client.post('/api/inquire/chat', json={'message': 'what did Alice say?'})+ assert resp.status_code == 200+ events = _sse_events(resp)++ # No search call may carry a speaker filter — the auto re-search never runs.+ assert all(not f.get('speaker_names') for f in search_filters), \+ f"unexpected speaker-filtered re-search: {search_filters}"+ # And no 'filtering' status event should be emitted for a present speaker.+ statuses = [e.get('status') for e in events]+ assert 'filtering' not in statuses, f"unexpected filtering event: {events}"diff --git a/tests/test_cov_processing.py b/tests/test_cov_processing.pyindex ae52bb5f..391f6a03 100644--- a/tests/test_cov_processing.py+++ b/tests/test_cov_processing.py@@ -830,5 +830,53 @@ def test_title_uses_user_default_naming_template():assert out.status == "COMPLETED"+def test_title_tag_template_takes_precedence_over_owner_default():+ """A tag-supplied naming template must override the owner's default template+ (processing.py:276).++ MUTATION-VERIFIED: line 276 `and recording.owner`->`or recording.owner` turns+ the guard into `if (not naming_template) or (recording.owner and ...)`, which+ is True even once the tag template is set, so the owner default WRONGLY+ overwrites the tag template and the title becomes "Owner cov" -> this test+ FAILS.+ """+ with app.app_context():+ user = _make_user("title_tagprec")++ # Two distinct templates, neither needing an AI title (no LLM call).+ tag_tmpl = NamingTemplate(user_id=user.id, name="Tag template",+ template="Tag {{filename}}")+ owner_tmpl = NamingTemplate(user_id=user.id, name="Owner template",+ template="Owner {{filename}}")+ db.session.add_all([tag_tmpl, owner_tmpl])+ db.session.commit()++ # Owner has a default template that differs from the tag's template.+ user.default_naming_template_id = owner_tmpl.id+ db.session.commit()++ rec = _make_recording(user.id, title="Recording - cov.mp3")++ # Attach a tag that carries its own naming template.+ tag = Tag(user_id=user.id, name=f"tagprec_{uuid.uuid4().hex[:8]}",+ naming_template_id=tag_tmpl.id)+ db.session.add(tag)+ db.session.commit()+ db.session.add(RecordingTag(recording_id=rec.id, tag_id=tag.id, order=0))+ db.session.commit()++ rid = rec.id+ with patch.object(proc, "client", None), \+ patch.object(proc, "ENABLE_INQUIRE_MODE", False):+ proc.generate_title_task(app.app_context(), rid, will_auto_summarize=False)++ db.session.expire_all()+ out = db.session.get(Recording, rid)+ # The TAG template must win, not the owner default.+ assert out.title == "Tag cov"+ assert out.title != "Owner cov"+ assert out.status == "COMPLETED"++if __name__ == "__main__":sys.exit(pytest.main([__file__, "-q"]))