feat(watchlist): add company identity catalog
Embed a pinned FinanceDatabase equity snapshot, add authenticated company search and identity-based follows, preserve legacy assets, and map selected Yahoo symbols for collection. Refs #19 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
54
backend/internal/ai/company_identity_ticket19_test.go
Normal file
54
backend/internal/ai/company_identity_ticket19_test.go
Normal file
@ -0,0 +1,54 @@
|
||||
package ai
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/tradarr/backend/internal/generation"
|
||||
"github.com/tradarr/backend/internal/models"
|
||||
"github.com/tradarr/backend/internal/scraper"
|
||||
)
|
||||
|
||||
func TestTicket19LayaReceivesCompanyNameAndSelectedInternalIdentity(t *testing.T) {
|
||||
figi := "BBG00ZMFX1S5"
|
||||
var request struct {
|
||||
States []struct {
|
||||
Indices []map[string]string `json:"indices"`
|
||||
} `json:"states"`
|
||||
}
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/v1/systemone/batch" {
|
||||
t.Errorf("Laya path=%s", r.URL.Path)
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
|
||||
t.Errorf("decode Laya payload: %v", err)
|
||||
w.WriteHeader(400)
|
||||
return
|
||||
}
|
||||
fmt.Fprint(w, `{"results":[{"answers":{"relevance":{"type":"score","score":0.1,"answer_confidence":0.9}},"usage":{"truncated":false,"state_tokens_dropped":0,"truncated_questions":[]}}],"total_usage":{"input_tokens":10,"output_tokens":0}}`)
|
||||
}))
|
||||
defer srv.Close()
|
||||
ranker, err := NewLayaHTTPRanker(LayaHTTPConfig{BaseURL: srv.URL, Timeout: time.Second})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = ranker.Rank(context.Background(), "title", []models.UserAsset{{Name: "Baidu, Inc.", Symbol: "9888.HK", FIGI: &figi}}, []generation.Candidate{{ID: "candidate", Article: scraper.Article{Title: "synthetic market headline"}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(request.States) != 1 || len(request.States[0].Indices) != 1 {
|
||||
t.Fatalf("Laya indices payload=%+v", request.States)
|
||||
}
|
||||
index := request.States[0].Indices[0]
|
||||
if index["name"] != "Baidu, Inc." || index["symbol"] != "9888.HK" || index["figi"] != figi {
|
||||
t.Fatalf("Laya received wrong company identity: %+v", index)
|
||||
}
|
||||
if index["symbol"] == "SSAAPL INDEX" {
|
||||
t.Fatalf("Bloomberg identifier was sent to Laya as ticker: %+v", index)
|
||||
}
|
||||
}
|
||||
@ -102,6 +102,12 @@ func (r *LayaHTTPRanker) Rank(ctx context.Context, mode string, assets []models.
|
||||
indices := make([]map[string]string, 0, len(assets))
|
||||
for _, a := range assets {
|
||||
index := map[string]string{"name": a.Name, "symbol": a.Symbol}
|
||||
if a.CompanyID != nil {
|
||||
index["company_id"] = *a.CompanyID
|
||||
}
|
||||
if a.YahooSymbol != nil {
|
||||
index["yahoo_symbol"] = *a.YahooSymbol
|
||||
}
|
||||
if a.FIGI != nil {
|
||||
index["figi"] = *a.FIGI
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user