refactor: Implement unified search abstraction, MemoryState refactoring, error handling, and unit test expansion

This commit is contained in:
Riz Ashraf committed 2026-10-01 08:37:52 +01:00
1 parent a34554b7ff
commit 462f65f66d
21 files changed
+425 -535

No files matched your search

+14 -14
View File
@@ -59,7 +59,7 @@ impl McpResource for GraphEntitiesResource {
let data: Vec<_> = graph.entities.values().collect();
Ok(serde_json::to_string_pretty(&data)?)
})
.await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?
.await.unwrap()
}
}
@@ -82,7 +82,7 @@ impl McpResource for GraphRelationsResource {
let data = &graph.relations;
Ok(serde_json::to_string_pretty(&data)?)
})
.await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?
.await.unwrap()
}
}
@@ -108,7 +108,7 @@ impl McpResource for TasksActiveResource {
.collect();
Ok(serde_json::to_string_pretty(&data)?)
})
.await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?
.await.unwrap()
}
}
@@ -193,7 +193,7 @@ impl MemoryHandler {
let items = state_clone.telemetry.terminal_history.cache.read().unwrap();
Ok(serde_json::to_string_pretty(&*items)?)
})
.await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?
.await.unwrap()
}
}
struct PinnedFilesResource;
@@ -214,7 +214,7 @@ impl MemoryHandler {
let items = state_clone.project.pinned_files.cache.read().unwrap();
Ok(serde_json::to_string_pretty(&*items)?)
})
.await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?
.await.unwrap()
}
}
@@ -236,7 +236,7 @@ impl MemoryHandler {
let items = state_clone.project.milestones.cache.read().unwrap();
Ok(serde_json::to_string_pretty(&*items)?)
})
.await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?
.await.unwrap()
}
}
@@ -621,7 +621,7 @@ mod tests {
"params": {}
});
let res_list = handler.handle_request(list_tools_req).await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?;
let res_list = handler.handle_request(list_tools_req).await.unwrap();
assert_eq!(res_list["jsonrpc"], "2.0");
assert_eq!(res_list["id"], 1);
assert!(res_list["result"]["tools"].as_array().unwrap().len() > 10);
@@ -640,7 +640,7 @@ mod tests {
"method": "resources/list",
"params": {}
});
let res_list = handler.handle_request(req_list_res).await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?;
let res_list = handler.handle_request(req_list_res).await.unwrap();
let resources_arr = res_list["result"]["resources"].as_array().unwrap();
assert!(
resources_arr
@@ -662,7 +662,7 @@ mod tests {
"uri": "memory://tasks/active"
}
});
let res_read = handler.handle_request(req_read_res).await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?;
let res_read = handler.handle_request(req_read_res).await.unwrap();
assert_eq!(
res_read["result"]["contents"][0]["uri"],
"memory://tasks/active"
@@ -681,7 +681,7 @@ mod tests {
"method": "prompts/list",
"params": {}
});
let res_prompts = handler.handle_request(req_list_prompts).await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?;
let res_prompts = handler.handle_request(req_list_prompts).await.unwrap();
let prompts_arr = res_prompts["result"]["prompts"].as_array().unwrap();
assert!(prompts_arr.iter().any(|p| p["name"] == "handoff_routine"));
@@ -695,7 +695,7 @@ mod tests {
"arguments": {}
}
});
let res_get = handler.handle_request(req_get_prompt).await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?;
let res_get = handler.handle_request(req_get_prompt).await.unwrap();
let messages = res_get["result"]["messages"].as_array().unwrap();
assert_eq!(messages[0]["role"], "user");
assert!(
@@ -722,7 +722,7 @@ mod tests {
"arguments": {}
}
});
let res_success = handler.handle_request(req_success).await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?;
let res_success = handler.handle_request(req_success).await.unwrap();
assert_eq!(res_success["jsonrpc"], "2.0");
assert_eq!(res_success["id"], 2);
// A successful tool call should return a result with isError: false
@@ -742,7 +742,7 @@ mod tests {
}
}
});
let res_fail = handler.handle_request(req_fail).await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?;
let res_fail = handler.handle_request(req_fail).await.unwrap();
assert_eq!(res_fail["jsonrpc"], "2.0");
assert_eq!(res_fail["id"], 3);
// Semantic failures must explicitly return isError: true inside the result to halt the LLM
@@ -760,7 +760,7 @@ mod tests {
"id": 4,
"method": "unknown_method_xyz"
});
let res_unknown = handler.handle_request(req_unknown).await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?;
let res_unknown = handler.handle_request(req_unknown).await.unwrap();
assert!(res_unknown.get("error").is_some());
assert_eq!(res_unknown["error"]["code"], -32601);
}