Skip to content

refactor(threads, tool_timeout): extract pure helpers for testability#784

Merged
senamakel merged 2 commits into
tinyhumansai:mainfrom
jwalin-shah:refactor-testability-1
Apr 23, 2026
Merged

refactor(threads, tool_timeout): extract pure helpers for testability#784
senamakel merged 2 commits into
tinyhumansai:mainfrom
jwalin-shah:refactor-testability-1

Conversation

@jwalin-shah
Copy link
Copy Markdown
Contributor

Summary

Pure refactor — no behavior change. Extracts two bodies of pure logic into isolated, unit-testable units:

  • threads::title (new module) — moves THREAD_TITLE_* constants and the title_log_fingerprint, is_auto_generated_thread_title, collapse_whitespace, sanitize_generated_title, build_title_prompt helpers out of threads::ops so the parsing/sanitisation rules can be exercised without Config, provider runtime, or RPC wiring.
  • tool_timeout::parse_tool_timeout_secs — splits the env-var parsing out of resolved_secs so it's pure (no OnceLock, no process env mutation) and every branch can be tested.

threads::ops now imports the helpers from threads::title and keeps the same call sites / call signatures; tool_execution_timeout_secs() behavior is preserved (resolved_secs now 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 and MAX_SECS), and midrange.

Validation

  • cargo test -p openhuman --lib threads::title → 24 passed
  • cargo test -p openhuman --lib tool_timeout → 7 passed

Risk

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.

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
@jwalin-shah jwalin-shah requested a review from a team April 22, 2026 14:35
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 22, 2026

Warning

Rate limit exceeded

@jwalin-shah has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 40 minutes and 2 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ba784268-d738-4b95-8dfe-a49666af90fc

📥 Commits

Reviewing files that changed from the base of the PR and between b3b451f and 7cc42ab.

📒 Files selected for processing (4)
  • src/openhuman/threads/mod.rs
  • src/openhuman/threads/ops.rs
  • src/openhuman/threads/title.rs
  • src/openhuman/tool_timeout/mod.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@senamakel senamakel merged commit 1d62d1c into tinyhumansai:main Apr 23, 2026
7 of 8 checks passed
@jwalin-shah jwalin-shah deleted the refactor-testability-1 branch April 23, 2026 21:13
AusAgentSmith pushed a commit to AusAgentSmith/openhuman that referenced this pull request May 23, 2026
…tinyhumansai#784)

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Jwalin Shah <jshah1331@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants