feat(summary): send complete articles within user budget (#39)

This commit is contained in:
2026-11-24 17:39:26 +01:00
parent d0c7cb7cae
commit 79953ce49f
73 changed files with 1688 additions and 288 deletions

View File

@ -50,7 +50,7 @@ func TestLegacyNullFIGIAssetStillContributesToGenerationPostgres(t *testing.T) {
})
const userID = "00000000-0000-0000-0000-000000000401"
for _, statement := range []string{
`CREATE TABLE users (id UUID PRIMARY KEY, language TEXT NOT NULL DEFAULT 'fr', ranking_mode TEXT NOT NULL DEFAULT 'title',summary_model_id UUID NULL)`,
`CREATE TABLE users (id UUID PRIMARY KEY, language TEXT NOT NULL DEFAULT 'fr', ranking_mode TEXT NOT NULL DEFAULT 'title',summary_prompt_token_budget INT NOT NULL DEFAULT 250000,summary_model_id UUID NULL)`,
`CREATE TABLE user_assets (id UUID PRIMARY KEY, user_id UUID NOT NULL, symbol VARCHAR(20) NOT NULL, name TEXT NOT NULL DEFAULT '', figi TEXT NULL, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW())`,
`CREATE TABLE sources (id UUID PRIMARY KEY, name TEXT NOT NULL, type TEXT NOT NULL, enabled BOOLEAN NOT NULL, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), article_limit INT NOT NULL DEFAULT 20, source_key TEXT)`,
`CREATE TABLE settings (key TEXT PRIMARY KEY, value TEXT NOT NULL)`,
@ -58,7 +58,7 @@ func TestLegacyNullFIGIAssetStillContributesToGenerationPostgres(t *testing.T) {
`INSERT INTO user_assets(id,user_id,symbol,name,figi) VALUES ('00000000-0000-0000-0000-000000000411','` + userID + `','LEGACY','Historic asset',NULL)`,
`INSERT INTO sources(id,name,type,enabled,article_limit,source_key) VALUES ('00000000-0000-0000-0000-000000000421','test source','ticket4',TRUE,20,'yahoo_finance')`,
`INSERT INTO sources(id,name,type,enabled,article_limit,source_key) VALUES ('00000000-0000-0000-0000-000000000422','Historic enabled','reuters',TRUE,42,NULL),('00000000-0000-0000-0000-000000000423','Disabled target','bloomberg',FALSE,77,'bloomberg')`,
`INSERT INTO settings(key,value) VALUES ('summary_max_articles','50')`,
`INSERT INTO settings(key,value) VALUES ('summary_max_articles','50'),('ai_system_prompt','Configured generation context')`,
} {
if _, err := db.Exec(statement); err != nil {
t.Fatal(err)
@ -69,6 +69,9 @@ func TestLegacyNullFIGIAssetStillContributesToGenerationPostgres(t *testing.T) {
if err != nil {
t.Fatalf("load legacy generation input from PostgreSQL: %v", err)
}
if input.SummaryContext != "Configured generation context" {
t.Fatal("existing generation context lost")
}
if len(input.Sources) != 1 || input.Sources[0].SourceKey == nil || *input.Sources[0].SourceKey != models.SourceYahooFinance || input.Sources[0].ArticleLimit != 20 {
t.Fatalf("LoadUserInput must exclude unsupported/disabled sources, preserving target caps: %+v", input.Sources)
}