feat: add msglib display entity extraction
This commit is contained in:
@@ -55,6 +55,44 @@ func TestDisplaySourcesPassesConfiguredPathsAndDecodesMetadata(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDisplayEntitiesPassesBoundedArgsAndDecodesMetadata(t *testing.T) {
|
||||
cfg := Config{
|
||||
SQLiteDLLPath: `C:\fixture\System.Data.SQLite.dll`,
|
||||
DBPath: `C:\fixture\MsgLib.db`,
|
||||
Password: "123",
|
||||
}
|
||||
client := newFakeClient(t, "display_entities_ok", cfg)
|
||||
|
||||
got, err := client.DisplayEntities(context.Background(), DisplayEntitiesOptions{EntityType: "contacts", Query: "alice", Limit: 2})
|
||||
if err != nil {
|
||||
t.Fatalf("DisplayEntities returned error: %v", err)
|
||||
}
|
||||
if len(got) != 2 {
|
||||
t.Fatalf("len(DisplayEntities) = %d, want 2", len(got))
|
||||
}
|
||||
if got[0].EntityType != "contacts" || got[0].SourceTable != "TD_Roster" || got[0].JID != "alice@example" || got[0].DisplayName != "Alice" {
|
||||
t.Fatalf("unexpected first entity: %+v", got[0])
|
||||
}
|
||||
if got[0].Confidence <= 0 || strings.Join(got[0].MatchedColumns, ",") != "JId,Nick" {
|
||||
t.Fatalf("unexpected first entity metadata: %+v", got[0])
|
||||
}
|
||||
if got[1].SourceTable != "tblRecent" || got[1].JID != "recent@example" || got[1].DisplayName != "Recent Alice" {
|
||||
t.Fatalf("unexpected second entity: %+v", got[1])
|
||||
}
|
||||
}
|
||||
|
||||
func TestDisplayEntitiesRejectsUnsupportedEntityType(t *testing.T) {
|
||||
client := newFakeClient(t, "display_entities_ok", Config{})
|
||||
|
||||
_, err := client.DisplayEntities(context.Background(), DisplayEntitiesOptions{EntityType: "messages", Limit: 5})
|
||||
if err == nil {
|
||||
t.Fatal("DisplayEntities returned nil error, want unsupported entity_type error")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "entity_type") {
|
||||
t.Fatalf("DisplayEntities error = %v, want entity_type context", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientReturnsStructuredSidecarError(t *testing.T) {
|
||||
client := newFakeClient(t, "sidecar_error", Config{})
|
||||
|
||||
@@ -202,6 +240,31 @@ func fakeSidecarMain() int {
|
||||
"error": nil,
|
||||
"warnings": []any{},
|
||||
})
|
||||
case "display_entities":
|
||||
args, _ := req["args"].(map[string]any)
|
||||
if args["sqlite_dll_path"] != `C:\fixture\System.Data.SQLite.dll` || args["db_path"] != `C:\fixture\MsgLib.db` || args["password"] != "123" || args["entity_type"] != "contacts" || args["query"] != "alice" || args["limit"] != float64(2) {
|
||||
fmt.Fprintf(os.Stderr, "bad display_entities args: %#v\n", args)
|
||||
return 2
|
||||
}
|
||||
return writeFakeResponse(map[string]any{
|
||||
"protocol": Protocol,
|
||||
"request_id": requestID,
|
||||
"op": op,
|
||||
"ok": true,
|
||||
"data": map[string]any{
|
||||
"metadata_only": true,
|
||||
"read_only": true,
|
||||
"entity_type": "contacts",
|
||||
"limit": 2,
|
||||
"result_count": 2,
|
||||
"entities": []any{
|
||||
map[string]any{"entity_type": "contacts", "source_table": "TD_Roster", "jid": "alice@example", "display_name": "Alice", "confidence": 0.95, "matched_columns": []any{"JId", "Nick"}},
|
||||
map[string]any{"entity_type": "contacts", "source_table": "tblRecent", "jid": "recent@example", "display_name": "Recent Alice", "confidence": 0.70, "matched_columns": []any{"PersonId", "PersonName"}},
|
||||
},
|
||||
},
|
||||
"error": nil,
|
||||
"warnings": []any{},
|
||||
})
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "unexpected op: %s\n", op)
|
||||
return 2
|
||||
|
||||
Reference in New Issue
Block a user