mirror of
https://github.com/outbackdingo/optimclaw.git
synced 2026-09-02 17:49:20 +00:00
test: add 26 tests for multi-thread safety, db CRUD, concurrency, errors (#442)
* fix: use std::sync::RwLock in MessageTool to avoid runtime panic The `requires_approval` method is synchronous but was using `tokio::sync::RwLock` with `.await` which requires blocking the runtime. This caused a panic: "Cannot block the current thread from within a runtime" Changes: - Replace `tokio::sync::RwLock` with `std::sync::RwLock` for `default_channel` and `default_target` fields - Use `unwrap_or_else(|e| e.into_inner())` to gracefully handle poisoned locks (recovers instead of panicking) - Update all usages from `.read().await` to `.read().unwrap_or_else()` The locks are short-held (just cloning strings), making std::sync::RwLock appropriate for sync methods called from async contexts. Fixes: "Cannot block the current thread from within a runtime" panic when the LLM tries to send a message via the message tool. Co-Authored-By: Claude Opus 4.6 <[email protected]> * test: comprehensive testing improvements and fix MessageTool blocking_read panic Fix tokio::sync::RwLock::blocking_read() panic in MessageTool::requires_approval() under multi-threaded tokio runtimes by switching to std::sync::RwLock with poison recovery. Add 26 new tests across 4 tiers: Tier 1 - Multi-thread runtime safety: - Fix MessageTool to use std::sync::RwLock instead of tokio::sync::RwLock - 4 multi-thread tests for MessageTool::requires_approval() scenarios - 1 multi-thread test for HttpTool credential-dependent approval - 1 structural test exercising all core tool sync trait methods under multi-thread runtime Tier 2 - Database CRUD coverage: - Settings lifecycle (CRUD, bulk ops) - Tool failure tracking (record, broken list, repair) - Routine lifecycle (create, get, list, update, delete, runs) - LLM call recording - Sandbox job lifecycle (create, get, update, list, mode) - Job events (save, list, limit) - Estimation snapshot round-trip Tier 3 - Concurrency: - ToolRegistry concurrent register + read under 4-worker runtime Tier 4 - Error coverage: - Display tests for all 8 error variants - From conversion tests for top-level Error enum Supersedes the fix in PR #411 with the same bug fix plus comprehensive test coverage. Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix: remove trailing whitespace in registry.rs Co-Authored-By: Claude Opus 4.6 <[email protected]> --------- Co-authored-by: Jerome Revillard <[email protected]> Co-authored-by: Claude Opus 4.6 <[email protected]> Co-authored-by: Illia Polosukhin <[email protected]>
This commit is contained in:
co-authored by
Jerome Revillard
Claude Opus 4.6
Illia Polosukhin
parent
04c5c3fe9f
commit
06c84a5c77
@@ -138,3 +138,29 @@ fn shell_tool_schema_is_valid() {
|
||||
let errors = validate_tool_schema(&schema, "shell");
|
||||
assert!(errors.is_empty(), "shell tool schema errors: {errors:?}");
|
||||
}
|
||||
|
||||
/// Validates that all core tools work correctly under a multi-threaded tokio runtime.
|
||||
/// This catches sync-async boundary bugs like tokio::sync::RwLock::blocking_read()
|
||||
/// panicking when called from within a multi-threaded runtime context.
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn all_core_tools_work_in_multi_thread_runtime() {
|
||||
let registry = ToolRegistry::new();
|
||||
registry.register_builtin_tools();
|
||||
registry.register_dev_tools();
|
||||
|
||||
let tools = registry.all().await;
|
||||
assert!(
|
||||
!tools.is_empty(),
|
||||
"registry should have tools after registration"
|
||||
);
|
||||
|
||||
for tool in &tools {
|
||||
// These sync trait methods must not panic in multi-thread runtime
|
||||
let _ = tool.name();
|
||||
let _ = tool.description();
|
||||
let _ = tool.parameters_schema();
|
||||
let _ = tool.requires_approval(&serde_json::json!({}));
|
||||
let _ = tool.requires_sanitization();
|
||||
let _ = tool.domain();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user