Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/server/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,13 +447,20 @@ struct DetailQuery {
async fn trace(
State(state): State<AppState>,
Query(query): Query<TraceQuery>,
) -> Result<impl IntoResponse, StatusCode> {
) -> Json<Value> {
let store = state.store();
let matches = store.search_nodes(&query.from);
let graph = state.graph();

if matches.is_empty() {
return Err(StatusCode::NOT_FOUND);
return Json(serde_json::json!({
"target": null,
"callers": [],
"callees": [],
"caller_count": 0,
"callee_count": 0,
"truncated": false,
}));
}

let (start_idx, _) = &matches[0];
Expand All @@ -475,7 +482,7 @@ async fn trace(
"truncated": visited >= max_nodes,
});

Ok(Json(result))
Json(result)
}

async fn execute_query(
Expand Down
20 changes: 20 additions & 0 deletions tests/serve_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,24 @@ mod tests {
let json: serde_json::Value = serde_json::from_str(&body).unwrap();
assert_eq!(json["total"], 0);
}

#[test]
fn test_serve_trace_empty_match_returns_200() {
let port = 19883;
let mut child = start_server(port);

let (status, body) = get(
port,
"/api/v1/trace?from=nonexistent_symbol_xyz_123",
);
stop_server(&mut child);

assert_eq!(status, 200);
let json: serde_json::Value = serde_json::from_str(&body).unwrap();
assert!(json["target"].is_null());
assert_eq!(json["callers"], serde_json::json!([]));
assert_eq!(json["callees"], serde_json::json!([]));
assert_eq!(json["caller_count"], 0);
assert_eq!(json["callee_count"], 0);
}
}