gateway/tools: collapse ToolRegistry::new() and new_with_defaults() into one
Some checks failed
lakehouse/auditor 1 blocking issue: todo!() macro call in tests/real-world/scrum_master_pipeline.ts

Two constructors existed with a subtle trap:

  - `new()` had `#[allow(dead_code)]` and called `register_defaults()`
    via `tokio::task::block_in_place(...)` — a sync wrapper hack around
    an async method, fragile and unused.
  - `new_with_defaults()` was misleadingly named — it created the empty
    registry WITHOUT registering defaults, despite the name.

main.rs was doing the right thing: `new_with_defaults()` + explicit
`.register_defaults().await`. The misleading name was a landmine
for future callers.

Fix: delete the dead `new()` with its block_in_place hack, rename
`new_with_defaults()` → `new()` (Rust idiom — `new` is the canonical
constructor), add a docstring that says what you need to do after.
Single clear API.

Update the one caller in main.rs. Workspace warnings still at 0.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
root 2026-04-24 06:44:18 -05:00
parent 5df4d48109
commit 81bae108f4
2 changed files with 6 additions and 17 deletions

View File

@ -191,7 +191,7 @@ async fn main() {
.nest("/journal", journald::service::router(journal))
.nest("/access", access_service::router(access))
.nest("/tools", tools::service::router({
let tool_reg = tools::registry::ToolRegistry::new_with_defaults();
let tool_reg = tools::registry::ToolRegistry::new();
tool_reg.register_defaults().await;
tools::ToolState {
registry: tool_reg,

View File

@ -67,25 +67,14 @@ pub struct ToolRegistry {
}
impl ToolRegistry {
#[allow(dead_code)]
/// Build an empty registry. Callers in an async context should follow
/// this with `.register_defaults().await` if they want the built-in
/// staffing tools pre-installed — main.rs does exactly that.
pub fn new() -> Self {
let registry = Self {
Self {
tools: Arc::new(RwLock::new(HashMap::new())),
audit_log: Arc::new(RwLock::new(Vec::new())),
};
// Register built-in staffing tools
tokio::task::block_in_place(|| {
tokio::runtime::Handle::current().block_on(registry.register_defaults())
});
registry
}
pub fn new_with_defaults() -> Self {
let registry = Self {
tools: Arc::new(RwLock::new(HashMap::new())),
audit_log: Arc::new(RwLock::new(Vec::new())),
};
registry
}
/// Register default staffing tools.