refactor(threads, tool_timeout): extract pure helpers for testability#784
Conversation
Split out previously-private helpers that were buried inside larger RPC-heavy modules so they can be unit-tested in isolation: - threads/ops.rs: move title parsing/sanitising (`is_auto_generated_thread_title`, `sanitize_generated_title`, `collapse_whitespace`, `build_title_prompt`, `title_log_fingerprint`) into new threads/title.rs. Drops ops.rs from 502 to 416 lines (under the 500-line guideline) and adds 24 targeted tests covering placeholder detection, LLM completion sanitising, multi-byte truncation, and prompt shape. - tool_timeout/mod.rs: expose `parse_tool_timeout_secs(Option<&str>) -> u64` so the bounds/parse fallback logic is exercisable without racing on the `OnceLock`-cached resolved value or mutating process env. 7 tests cover missing, non-numeric, zero, over-max, negative, and boundary values. Pure refactor — no call sites or behaviour change. https://claude.ai/code/session_01M6wEiCdh2XH555NigCSfYc
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 40 minutes and 2 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…tinyhumansai#784) Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Jwalin Shah <jshah1331@gmail.com>
Summary
Pure refactor — no behavior change. Extracts two bodies of pure logic into isolated, unit-testable units:
threads::title(new module) — movesTHREAD_TITLE_*constants and thetitle_log_fingerprint,is_auto_generated_thread_title,collapse_whitespace,sanitize_generated_title,build_title_prompthelpers out ofthreads::opsso the parsing/sanitisation rules can be exercised withoutConfig, provider runtime, or RPC wiring.tool_timeout::parse_tool_timeout_secs— splits the env-var parsing out ofresolved_secsso it's pure (noOnceLock, no process env mutation) and every branch can be tested.threads::opsnow imports the helpers fromthreads::titleand keeps the same call sites / call signatures;tool_execution_timeout_secs()behavior is preserved (resolved_secsnow delegates to the pure parser).Tests added
threads::title— 24 tests covering fingerprint stability, all accept/reject paths for the auto-generated placeholder shape (single/two-digit day + hour, AM/PM, user-renamed titles, malformed minutes, numeric month, missing suffix), whitespace collapse edge cases, sanitiser rules (quote/backtick stripping, trailing punctuation, first non-empty line selection, empty handling, char-count truncation including multi-byte UTF-8), and prompt construction.tool_timeout— 7 tests covering default fallback, non-numeric values, zero, above-max, negative/signed, valid boundary (1 andMAX_SECS), and midrange.Validation
cargo test -p openhuman --lib threads::title→ 24 passedcargo test -p openhuman --lib tool_timeout→ 7 passedRisk
Minimal. Logic is byte-for-byte identical to what was inline; only the module boundary changed. Constants are re-exported from the new module and referenced by their original names in
threads::ops.