Skip to content

test(rust): move fake integration backend tests to extracted file#1960

Merged
senamakel merged 3 commits into
tinyhumansai:mainfrom
senamakel:codex/rust-tool-integration-mocks
May 16, 2026
Merged

test(rust): move fake integration backend tests to extracted file#1960
senamakel merged 3 commits into
tinyhumansai:mainfrom
senamakel:codex/rust-tool-integration-mocks

Conversation

@senamakel
Copy link
Copy Markdown
Member

@senamakel senamakel commented May 16, 2026

Summary

  • moves the fake integration backend tests out of inline #[cfg(test)] blocks into src/openhuman/integrations/test_support_test.rs
  • updates src/openhuman/tools/ops_tests.rs to include the fake backend directly for Rust-only tool integration coverage
  • removes the extra test-only module exposure from src/openhuman/integrations/mod.rs
  • keeps the existing dynamic backend mock coverage intact while matching the requested *_test.rs file split

Problem

  • the fake backend coverage added for Rust integration tools was still partly organized as inline module tests
  • that made the test support wiring less consistent with the requested extracted test-file layout and forced an unnecessary test-only export from integrations/mod.rs

Solution

  • load the extracted tests from test_support.rs via #[path = "test_support_test.rs"] mod tests;
  • include ../integrations/test_support.rs directly inside ops_tests.rs for integration-family execution tests
  • keep the change Rust-only and avoid touching Tauri or React codepaths

Submission Checklist

  • Tests added or updated (happy path + at least one failure / edge case) per Testing Strategy
  • Diff coverage ≥ 80% — changed lines (Vitest + cargo-llvm-cov merged via diff-cover) meet the gate enforced by .github/workflows/coverage.yml. Validated locally for the changed Rust files and enforced again by CI.
  • N/A: Coverage matrix updated — added/removed/renamed feature rows in docs/TEST-COVERAGE-MATRIX.md reflect this change. Behaviour-only Rust test organization change.
  • N/A: All affected feature IDs from the matrix are listed in the PR description under ## Related. No product feature behavior changed.
  • No new external network dependencies introduced (mock backend used per Testing Strategy)
  • N/A: Manual smoke checklist updated if this touches release-cut surfaces (docs/RELEASE-MANUAL-SMOKE.md). Rust test-only change.
  • N/A: Linked issue closed via Closes #NNN in the ## Related section. No issue was provided for this change.

Impact

  • no runtime behavior change
  • Rust test harness only
  • no security, migration, or compatibility impact expected

Related

  • Closes: N/A
  • Follow-up PR(s)/TODOs:
    • if CI flags diff coverage, run the full merged coverage workflow and adjust test scope further

AI Authored PR Metadata (required for Codex/Linear PRs)

Keep this section for AI-authored PRs. For human-only PRs, mark each field N/A.

Linear Issue

  • Key: N/A
  • URL: N/A

Commit & Branch

  • Branch: codex/rust-tool-integration-mocks
  • Commit SHA: ca127a7a

Validation Run

  • pnpm --filter openhuman-app format:check
  • pnpm typecheck
  • Focused tests:
    • cargo test --manifest-path Cargo.toml all_tools_executes_apify_family_against_fake_backend -- --nocapture
    • cargo test --manifest-path Cargo.toml fake_backend_records_requests_and_applies_route_defaults -- --nocapture
  • Rust fmt/check (if changed):
    • cargo fmt --all --check
  • Tauri fmt/check (if changed):
    • cargo check --manifest-path app/src-tauri/Cargo.toml

Validation Blocked

  • command: pnpm test:coverage
  • error: not run in this shipping pass
  • impact: CI remains the source of truth for merged diff-coverage gate

Behavior Changes

  • Intended behavior change: none; test organization only
  • User-visible effect: none

Parity Contract

  • Legacy behavior preserved: yes
  • Guard/fallback/dispatch parity checks: existing fake backend execution coverage remains intact after the file split

Duplicate / Superseded PR Handling

  • Duplicate PR(s): none known
  • Canonical PR: this PR
  • Resolution (closed/superseded/updated): updated

Summary by CodeRabbit

  • Tests
    • Added comprehensive test infrastructure for integration testing with mock backend support
    • Expanded test coverage for agent tool execution, tool registry configuration, and agent harness behavior verification

Review Change Stack

@senamakel senamakel requested a review from a team May 16, 2026 19:45
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2c2a10c3-a14e-4717-a720-e8f4286bf910

📥 Commits

Reviewing files that changed from the base of the PR and between ca127a7 and 474f8ac.

📒 Files selected for processing (1)
  • src/openhuman/agent/harness/test_support_test.rs

📝 Walkthrough

Walkthrough

This PR introduces comprehensive test infrastructure for OpenHuman integrations: a fake HTTP backend with axum, harness tests for native tool chains, backend validation tests, and integration execution tests verifying tool registry setup and output against the fake backend.

Changes

Test Infrastructure and Coverage

Layer / File(s) Summary
Harness tool execution tests
src/openhuman/agent/harness/test_support_test.rs
Two tokio tests verify multi-step native tool chains: one asserts the harness uses the latest tool result to drive subsequent tool calls with expected arguments and provider turn ordering; another confirms single-turn emission of multiple tool calls executes all tools in order.
Fake integration backend infrastructure
src/openhuman/integrations/test_support.rs
RecordedRequest and FakeIntegrationBackend types expose base_url and requests() history. spawn_fake_integration_backend() creates a shared request queue, wires an axum Router with POST/GET routes for Apify, Google Places, Parallel, financial-apis, and Twilio integrations, binds an ephemeral TCP port, and returns a configured backend.
Backend test coverage and validation
src/openhuman/integrations/test_support_test.rs
HTTP helpers get_json and post_json send requests and deserialize JSON. Tests validate as_string_array filtering, fake backend request recording with pagination parameters, response shapes across Apify/Twilio/Parallel/financial-apis endpoints, and Google Places/commodity/exchange-rate result fields.
Tool registry and integration execution tests
src/openhuman/tools/ops_tests.rs
Test helpers build in-memory backends, extract tool names, assert expected tool presence, store session tokens, and build integration-enabled configs. Regression tests verify baseline tool registry content and detect duplicates. Integration tests confirm integration-family tools register when signed in, verify seltz/learning/LSP env toggling, and execute Apify/Google Places/Parallel/Stock/Twilio tools against the fake backend, asserting output strings and request ordering/paths/bodies.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A test-backend born from axum's song,
Records each request that passes along,
Harnesses chain their tool calls with grace,
While registries bloom in their proper place!
Integration tests dance, both swift and true,
Fake routes respond as expected—who knew? 🚀

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: moving fake integration backend tests to an extracted file (test_support_test.rs), which aligns with the primary refactoring objective shown in the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

@senamakel
Copy link
Copy Markdown
Member Author

@coderabbitai reivew

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 16, 2026

@senamakel Sure, I'll review this PR now!

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot added the working A PR that is being worked on by the team. label May 16, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/openhuman/tools/ops_tests.rs (1)

349-1217: 🛠️ Refactor suggestion | 🟠 Major | 🏗️ Heavy lift

This test module should be split; it is significantly beyond the repo’s size limit.

The new additions further increase an already very large test file. Please move integration-family suites into dedicated sibling modules/files (e.g., registry baseline vs backend execution suites) to keep test maintenance tractable.

As per coding guidelines: “Keep Rust source files to ≤ ~500 lines; split modules when growing larger.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openhuman/tools/ops_tests.rs` around lines 349 - 1217, The test module
ops_tests.rs is too large and should be split: extract the long
"integration-family" suites (tests named
all_tools_executes_apify_family_against_fake_backend,
all_tools_executes_google_places_family_against_fake_backend,
all_tools_executes_parallel_and_web_search_family_against_fake_backend,
all_tools_executes_stock_and_twilio_family_against_fake_backend and any helpers
they use such as integration_tools_for_config and integration_test_support
usage) into one or more dedicated sibling test modules/files (e.g.,
ops_integration_apify.rs, ops_integration_parallel.rs,
ops_integration_financial.rs) and leave the registry/baseline tests
(all_tools_default_registry_contains_expected_baseline_surface,
all_tools_default_registry_has_no_duplicate_tool_names, default_tools_* etc.) in
ops_tests.rs; preserve #[tokio::test] and #[test] attributes, re-export or
import shared helpers with use crate::... or super:: as needed, add mod
declarations so the new files are compiled as tests, and ensure any environment
setup (TEST_ENV_LOCK, env vars) and store_test_session_token calls are still
available to the moved tests.
🧹 Nitpick comments (2)
src/openhuman/agent/harness/test_support_tests.rs (1)

227-297: 🏗️ Heavy lift

Split these new tests into a dedicated sibling test module to stop growing this oversized file.

These additions are solid, but appending them here grows an already very large module further. Please move these two new scenarios into a separate _test.rs sibling (or feature-focused test module) to keep this file maintainable.

As per coding guidelines, "Keep Rust source files to ≤ ~500 lines; split modules when growing larger."

Also applies to: 299-353

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openhuman/agent/harness/test_support_tests.rs` around lines 227 - 297,
Split the two new test functions (including
keyword_provider_uses_latest_tool_result_to_drive_the_next_tool_call and the
other test around lines 299-353) out of the oversized test module into a new
sibling test file (a dedicated _test.rs file) and move all their
dependencies/imports into that file; ensure you copy or re-export the required
symbols (KeywordScriptedProvider, KeywordRule, ScriptedToolCall, RecordingTool,
run_tool_call_loop, ChatMessage, mm, etc.) via use super::* or explicit crate
paths so the tests compile, add the new file to the crate (no additional runtime
code changes), and run cargo test to verify everything passes.
src/openhuman/tools/ops_tests.rs (1)

905-930: ⚡ Quick win

Make LSP env-var cleanup panic-safe to avoid cross-test contamination.

If any assertion panics after set_var and before the explicit remove_var, later tests can observe stale LSP_ENABLED_ENV. Please switch to a small drop guard so cleanup always runs.

Suggested fix
+    struct LspEnvGuard;
+    impl Drop for LspEnvGuard {
+        fn drop(&mut self) {
+            unsafe {
+                std::env::remove_var(crate::openhuman::tools::implementations::LSP_ENABLED_ENV);
+            }
+        }
+    }
+
     let _env_guard = crate::openhuman::config::TEST_ENV_LOCK
         .lock()
         .unwrap_or_else(|e| e.into_inner());
+    let _lsp_env_guard = LspEnvGuard;
     unsafe {
         std::env::set_var(
             crate::openhuman::tools::implementations::LSP_ENABLED_ENV,
             "1",
         );
     }
@@
-    unsafe {
-        std::env::remove_var(crate::openhuman::tools::implementations::LSP_ENABLED_ENV);
-    }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openhuman/tools/ops_tests.rs` around lines 905 - 930, Replace the current
unsafe set_var/remove_var pair with a panic-safe drop guard: after acquiring
TEST_ENV_LOCK and calling
std::env::set_var(crate::openhuman::tools::implementations::LSP_ENABLED_ENV,
"1"), immediately create a small RAII guard (e.g., LspEnvGuard) whose Drop
implementation calls std::env::remove_var for the same LSP_ENABLED_ENV; keep the
rest of the test using all_tools(...) and assertions unchanged so the guard will
always run even if assertions panic. Ensure the guard is created in the same
scope as the set_var so it lives long enough for the test and is dropped
automatically at scope exit.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/openhuman/integrations/test_support.rs`:
- Around line 56-678: spawn_fake_integration_backend currently contains all
route handlers and is too large; split the file by integration family and make
this function compose smaller route-builder helpers. Extract route groups into
separate functions/ modules (e.g., build_apify_routes,
build_google_places_routes, build_parallel_routes, build_financial_apis_routes,
build_twilio_routes) that return Router or IntoRouter, move their handler
closures into those modules (preserving symbols like FakeIntegrationState,
record, as_string_array), then in spawn_fake_integration_backend compose them
(Router::new().merge(build_apify_routes(state.clone())).merge(...)) so
src/openhuman/integrations/test_support.rs becomes a small coordinator while
each integration family lives in its own file/module.

---

Outside diff comments:
In `@src/openhuman/tools/ops_tests.rs`:
- Around line 349-1217: The test module ops_tests.rs is too large and should be
split: extract the long "integration-family" suites (tests named
all_tools_executes_apify_family_against_fake_backend,
all_tools_executes_google_places_family_against_fake_backend,
all_tools_executes_parallel_and_web_search_family_against_fake_backend,
all_tools_executes_stock_and_twilio_family_against_fake_backend and any helpers
they use such as integration_tools_for_config and integration_test_support
usage) into one or more dedicated sibling test modules/files (e.g.,
ops_integration_apify.rs, ops_integration_parallel.rs,
ops_integration_financial.rs) and leave the registry/baseline tests
(all_tools_default_registry_contains_expected_baseline_surface,
all_tools_default_registry_has_no_duplicate_tool_names, default_tools_* etc.) in
ops_tests.rs; preserve #[tokio::test] and #[test] attributes, re-export or
import shared helpers with use crate::... or super:: as needed, add mod
declarations so the new files are compiled as tests, and ensure any environment
setup (TEST_ENV_LOCK, env vars) and store_test_session_token calls are still
available to the moved tests.

---

Nitpick comments:
In `@src/openhuman/agent/harness/test_support_tests.rs`:
- Around line 227-297: Split the two new test functions (including
keyword_provider_uses_latest_tool_result_to_drive_the_next_tool_call and the
other test around lines 299-353) out of the oversized test module into a new
sibling test file (a dedicated _test.rs file) and move all their
dependencies/imports into that file; ensure you copy or re-export the required
symbols (KeywordScriptedProvider, KeywordRule, ScriptedToolCall, RecordingTool,
run_tool_call_loop, ChatMessage, mm, etc.) via use super::* or explicit crate
paths so the tests compile, add the new file to the crate (no additional runtime
code changes), and run cargo test to verify everything passes.

In `@src/openhuman/tools/ops_tests.rs`:
- Around line 905-930: Replace the current unsafe set_var/remove_var pair with a
panic-safe drop guard: after acquiring TEST_ENV_LOCK and calling
std::env::set_var(crate::openhuman::tools::implementations::LSP_ENABLED_ENV,
"1"), immediately create a small RAII guard (e.g., LspEnvGuard) whose Drop
implementation calls std::env::remove_var for the same LSP_ENABLED_ENV; keep the
rest of the test using all_tools(...) and assertions unchanged so the guard will
always run even if assertions panic. Ensure the guard is created in the same
scope as the set_var so it lives long enough for the test and is dropped
automatically at scope exit.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5efb8ce5-4263-4ad6-af47-8da707bbabea

📥 Commits

Reviewing files that changed from the base of the PR and between 36a0e73 and ca127a7.

📒 Files selected for processing (4)
  • src/openhuman/agent/harness/test_support_tests.rs
  • src/openhuman/integrations/test_support.rs
  • src/openhuman/integrations/test_support_test.rs
  • src/openhuman/tools/ops_tests.rs

Comment thread src/openhuman/integrations/test_support.rs
@senamakel senamakel merged commit 6707d3f into tinyhumansai:main May 16, 2026
25 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request May 18, 2026
17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

working A PR that is being worked on by the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant