Conversation
…ated call patterns (closes #23) Three layers of duplication around exclusion-rule filtering: 1. `_session_text_for_exclusion(session)` was defined twice — byte-identical bodies (only docstring differs) in scripts/export.py:476 and api/export_api.py:43. Two maintenance points for one function. 2. Six call sites repeated the same `if rules: build_searchable_text(...) → is_excluded_by_rules(...) → skip` pattern across api/sessions.py, api/projects.py, api/search.py, api/export_api.py (×2), and scripts/export.py. ~60 lines of near-identical wrapping. 3. Latent inconsistency: the helper rejected whitespace-only message text (`isinstance(text, str) and text.strip()`); the 4 inline call sites did not (`if msg.get("text")`). Bug surface small but real, and there was no reason for the difference. Consolidated into utils/exclusion_rules.py: - session_text_for_exclusion(session) — moved from the duplicate-defined private helpers; now the single source of truth. - is_session_excluded(rules, session, project_name) — wraps the full pattern. Returns False when rules is empty/falsy, so callers don't have to gate on `if rules:` before calling. Six call sites collapsed to one line each. After: one definition of the extraction logic, one definition of the wrapping pattern, the whitespace-handling inconsistency disappears (everyone uses the helper), and ~20 net lines removed across 6 files. Tests: tests/test_exclusion_helpers.py adds 16 unit cases for the new helpers — text-extraction edge cases (empty, whitespace-only, non-string, mixed) and rule-matching across all four haystack fields (project_name, session_title, model_names, content) plus AND/OR/quoted-phrase grammar plus defensive cases (no metadata key, project_name=None). 91/91 pytest pass (was 75; +16 new).
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughThe PR consolidates duplicate session exclusion filtering logic from six scattered call sites into two centralized helpers ( ChangesExclusion Rule Consolidation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Problem
Three layers of duplication around exclusion-rule filtering:
_session_text_for_exclusion(session)defined twice — byte-identical bodies (only docstring differs) inscripts/export.py:476andapi/export_api.py:43. Two maintenance points for one function.api/sessions.py,api/projects.py,api/search.py,api/export_api.py(×2), andscripts/export.pyrepeated the sameif rules: build_searchable_text(...) → is_excluded_by_rules(...) → skippattern (~10 lines each, ~60 lines total).isinstance(text, str) and text.strip()); the 4 inline call sites didn't (if msg.get("text")). Bug surface small but real.Change
Consolidated into
utils/exclusion_rules.py:session_text_for_exclusion(session)— moved from the duplicate-defined private helpers. Single source of truth; both old copies deleted.is_session_excluded(rules, session, project_name) -> bool— wraps the full pattern. ReturnsFalsewhenrulesis empty/falsy, so callers don't gate onif rules:first.Six call sites collapsed to one line each. Whitespace-handling inconsistency disappears.
Test plan
Unit (
pytest tests/): 91/91 OK (was 75 + 16 new intests/test_exclusion_helpers.py).The 16 new cases:
session_text_for_exclusion(6 cases): empty session, no messages, joins with blank lines, skips messages without text, skips whitespace-only text (the regression-of-the-old-bug guard), skips non-string text.is_session_excluded(10 cases): empty/None rules →False; matches across each haystack field (project_name / session_title / model_names / message content); AND vs OR rule grammar; quoted-phrase exact match; defensive against missingmetadatakey; defensive againstproject_name=None.Net diff: +228 / −90 lines across 7 files (the +228 is mostly the 165-line new test file; the helper itself is +44 lines, and the 5 application files net −20 lines after removing the duplicate helper defs and the 6 inlined wrapping blocks).
Closes #23.
Summary by CodeRabbit
Refactor
Tests