#![allow(dead_code)]
use serde_json::Value;
pub fn content_text(response: &Value) -> String {
response["result"]["content"]
.as_array()
.and_then(|arr| arr.first())
.and_then(|item| item["text"].as_str())
.unwrap_or("")
.to_owned()
}
pub fn assert_tool_ok(response: &Value) -> String {
let is_error = response["result"]["isError"].as_bool().unwrap_or(false);
assert!(
!is_error,
"Expected successful tool response, got isError=true: {}",
response["result"]["content"][0]["text"]
.as_str()
.unwrap_or("<no text>")
);
content_text(response)
}
pub fn assert_contains_symbol(symbols: &Value, name: &str) {
let arr = symbols
.as_array()
.unwrap_or_else(|| panic!("expected array of symbols, got {symbols}"));
let found = arr.iter().any(|s| s["name"].as_str().unwrap_or("") == name);
assert!(found, "symbol '{name}' not found in {symbols}");
}
pub fn assert_uri_ends_with(uri: &str, suffix: &str) {
assert!(
uri.ends_with(suffix),
"expected URI to end with '{suffix}', got '{uri}'"
);
}
pub fn file_uri(path: &std::path::Path) -> String {
url::Url::from_file_path(path)
.unwrap_or_else(|()| panic!("cannot convert path to file URI: {}", path.display()))
.to_string()
}