refactor: Implement unified search abstraction, MemoryState refactoring, error handling, and unit test expansion
This commit is contained in:
1 parent
a34554b7ff
commit
462f65f66d
21 files changed
+425
-535
No files matched your search
@@ -671,7 +671,7 @@ mod tests {
|
||||
]
|
||||
});
|
||||
|
||||
let res = create_handler.execute(args, state.clone()).await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?;
|
||||
let res = create_handler.execute(args, state.clone()).await.map_err(|e| crate::error::AppError::Internal(e.to_string())).unwrap();
|
||||
assert_eq!(res, "Entities created");
|
||||
|
||||
// Ensure graph contains the entity
|
||||
@@ -716,7 +716,7 @@ mod tests {
|
||||
{"from": "A", "to": "B", "relation_type": "knows"}
|
||||
]
|
||||
});
|
||||
let res = handler.execute(args, state.clone()).await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?;
|
||||
let res = handler.execute(args, state.clone()).await.map_err(|e| crate::error::AppError::Internal(e.to_string())).unwrap();
|
||||
assert_eq!(res, "Relations created");
|
||||
|
||||
// Test semantic LLM schema feedback (User request)
|
||||
@@ -725,7 +725,7 @@ mod tests {
|
||||
{"source": "A", "target": "B", "relationType": "knows"}
|
||||
]
|
||||
});
|
||||
let err_res = handler.execute(bad_args, state.clone()).await.unwrap_err();
|
||||
let err_res = handler.execute(bad_args, state.clone()).await.unwrap_err().to_string();
|
||||
assert!(err_res.contains("Schema error:"));
|
||||
assert!(err_res.contains("strictly uses 'from', 'to', and 'relation_type'"));
|
||||
}
|
||||
@@ -755,25 +755,25 @@ mod tests {
|
||||
{"entity_name": "A", "contents": ["Obs 1", "Obs 2"]}
|
||||
]
|
||||
});
|
||||
let res1 = add_obs.execute(args_obs, state.clone()).await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?;
|
||||
let res1 = add_obs.execute(args_obs, state.clone()).await.map_err(|e| crate::error::AppError::Internal(e.to_string())).unwrap();
|
||||
assert_eq!(res1, "Observations added");
|
||||
|
||||
let read_graph = ReadGraphHandler;
|
||||
let res2 = read_graph
|
||||
.execute(json!({"namespace": "global"}), state.clone())
|
||||
.await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?;
|
||||
.await.map_err(|e| crate::error::AppError::Internal(e.to_string())).unwrap();
|
||||
assert!(res2.contains("Obs 1"));
|
||||
assert!(res2.contains("Obs 2"));
|
||||
|
||||
let del_entity = DeleteEntitiesHandler;
|
||||
let res4 = del_entity
|
||||
.execute(json!({"entity_names": ["A"]}), state.clone())
|
||||
.await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?;
|
||||
.await.map_err(|e| crate::error::AppError::Internal(e.to_string())).unwrap();
|
||||
assert_eq!(res4, "Entities deleted");
|
||||
|
||||
let res5 = read_graph
|
||||
.execute(json!({"namespace": "global"}), state.clone())
|
||||
.await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?;
|
||||
.await.map_err(|e| crate::error::AppError::Internal(e.to_string())).unwrap();
|
||||
assert!(!res5.contains("A"));
|
||||
}
|
||||
|
||||
@@ -791,7 +791,7 @@ mod tests {
|
||||
});
|
||||
create_handler
|
||||
.execute(args_ent, state.clone())
|
||||
.await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?;
|
||||
.await.map_err(|e| crate::error::AppError::Internal(e.to_string())).unwrap();
|
||||
|
||||
let rel_handler = CreateRelationsHandler;
|
||||
let args_rel = json!({
|
||||
@@ -799,25 +799,25 @@ mod tests {
|
||||
{"from": "X", "to": "Y", "relation_type": "depends_on", "namespace": "global"}
|
||||
]
|
||||
});
|
||||
rel_handler.execute(args_rel, state.clone()).await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?;
|
||||
rel_handler.execute(args_rel, state.clone()).await.map_err(|e| crate::error::AppError::Internal(e.to_string())).unwrap();
|
||||
|
||||
let read_handler = ReadGraphHandler;
|
||||
let res_read = read_handler
|
||||
.execute(json!({"namespace": "global"}), state.clone())
|
||||
.await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?;
|
||||
.await.map_err(|e| crate::error::AppError::Internal(e.to_string())).unwrap();
|
||||
assert!(res_read.contains("X"));
|
||||
assert!(res_read.contains("depends_on"));
|
||||
|
||||
let open_handler = OpenNodesHandler;
|
||||
let res_open = open_handler
|
||||
.execute(json!({"names": ["X"]}), state.clone())
|
||||
.await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?;
|
||||
.await.map_err(|e| crate::error::AppError::Internal(e.to_string())).unwrap();
|
||||
assert!(res_open.contains("Y"));
|
||||
|
||||
let viz_handler = VisualizeGraphHandler;
|
||||
let res_viz = viz_handler
|
||||
.execute(json!({"query": "X"}), state.clone())
|
||||
.await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?;
|
||||
.await.map_err(|e| crate::error::AppError::Internal(e.to_string())).unwrap();
|
||||
assert!(!res_viz.is_empty());
|
||||
|
||||
let condense = CondenseEntityHandler;
|
||||
@@ -826,7 +826,7 @@ mod tests {
|
||||
json!({"entity_name": "X", "summarized_observations": ["X condensed"]}),
|
||||
state.clone(),
|
||||
)
|
||||
.await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?;
|
||||
.await.map_err(|e| crate::error::AppError::Internal(e.to_string())).unwrap();
|
||||
assert_eq!(res_cond, "Entity condensed");
|
||||
|
||||
let merge = MergeEntitiesHandler;
|
||||
@@ -835,11 +835,11 @@ mod tests {
|
||||
json!({"source_entity": "X", "target_entity": "Y"}),
|
||||
state.clone(),
|
||||
)
|
||||
.await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?;
|
||||
.await.map_err(|e| crate::error::AppError::Internal(e.to_string())).unwrap();
|
||||
assert_eq!(res_merge, "Entities merged");
|
||||
|
||||
let orphans = FindOrphansHandler;
|
||||
let res_orphans = orphans.execute(json!({}), state.clone()).await.map_err(|e| crate::error::AppError::Internal(e.to_string()))?;
|
||||
let res_orphans = orphans.execute(json!({}), state.clone()).await.map_err(|e| crate::error::AppError::Internal(e.to_string())).unwrap();
|
||||
assert!(!res_orphans.contains("Y"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user