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:
53
backend/internal/companycatalog/embedded_test.go
Normal file
53
backend/internal/companycatalog/embedded_test.go
Normal file
@ -0,0 +1,53 @@
|
||||
package companycatalog
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"encoding/csv"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEmbeddedSnapshotIsCompletePinnedAndResolvable(t *testing.T) {
|
||||
data, err := os.ReadFile("data/manifest.json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var manifest struct {
|
||||
Records int `json:"records"`
|
||||
SHA256 string `json:"sha256"`
|
||||
Commit string `json:"upstream_commit"`
|
||||
}
|
||||
if err = json.Unmarshal(data, &manifest); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sum := sha256.Sum256(embeddedSnapshot)
|
||||
rows, err := csv.NewReader(bytes.NewReader(embeddedSnapshot)).ReadAll()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if manifest.Records != 47735 || len(rows)-1 != manifest.Records || hex.EncodeToString(sum[:]) != manifest.SHA256 || manifest.Commit != "93b872f0e4b4e05e8d35b7f0a39efe9245bcc2c1" {
|
||||
t.Fatal("incomplete or unpinned embedded snapshot")
|
||||
}
|
||||
catalog, err := Default()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(catalog.companies) != 43126 {
|
||||
t.Fatalf("resolved identities=%d", len(catalog.companies))
|
||||
}
|
||||
for id, want := range map[string]string{"isin:US67066G1040": "NVDA", "isin:US0378331005": "AAPL", "isin:KYG070341048": "9888.HK", "isin:CNE100001526": "002594.SZ", "isin:HK0285041858": "0285.HK"} {
|
||||
company, err := catalog.ResolveCompany(id)
|
||||
if err != nil || company.YahooSymbol != want {
|
||||
t.Fatalf("%s resolved to %+v, %v", id, company, err)
|
||||
}
|
||||
}
|
||||
for _, query := range []string{"QQQ", "ES=F", "AAPL260117C00200000"} {
|
||||
result, err := catalog.SearchCompanies(query, 20)
|
||||
if err != nil || len(result) != 0 {
|
||||
t.Fatalf("unexpected non-company search result %q: %+v", query, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user