Files
eleith dd82382bed feat: implement Phases 2, 3, and 4 (Filter Engine, Processor Refactor, LLM Categories)
This commit delivers the core logic for the Multi-Digest Architecture.

Phase 2 (Filter Engine):
- Implemented 'internal/filter' with exact/prefix/regex matching.
- Implemented 'internal/manager' for digest priority assignment.
- Updated 'models.Entry' to include 'SiteURL'.

Phase 3 (Processor Refactor):
- Updated 'ProcessDigest' to filter entries using 'DigestManager'.
- Updated 'main.go' to schedule jobs per digest index.

Phase 4 (LLM & Categorization):
- Added 'DefaultCategories' in 'internal/config'.
- Updated LLM prompts and service flow to respect user-defined or default categories.
- Updated mocks and tests across the board.

The application now supports configuring multiple digests with distinct filters and categories, and correctly assigns entries and prompts the LLM accordingly.
2025-12-16 11:00:38 -08:00

85 lines
1.6 KiB
Go

package manager
import (
"testing"
"miniflux-digest/internal/config"
"miniflux-digest/internal/models"
)
func TestGetOwningDigest(t *testing.T) {
digests := []config.ConfigDigest{
{
Title: "High Priority Tech",
Filters: config.ConfigFilters{
FeedTitles: []string{"Tech News"},
},
},
{
Title: "General News",
Filters: config.ConfigFilters{
// Empty filters match everything (catch-all)
},
},
}
dm, err := NewDigestManager(digests)
if err != nil {
t.Fatalf("Failed to create DigestManager: %v", err)
}
tests := []struct {
name string
entry *models.Entry
wantIndex int
}{
{
name: "Match first digest",
entry: &models.Entry{
FeedTitle: "Tech News",
SiteURL: "http://technews.com",
},
wantIndex: 0,
},
{
name: "Match second digest (catch-all)",
entry: &models.Entry{
FeedTitle: "Cooking Weekly",
SiteURL: "http://cooking.com",
},
wantIndex: 1,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := dm.GetOwningDigest(tt.entry)
if got != tt.wantIndex {
t.Errorf("GetOwningDigest() = %v, want %v", got, tt.wantIndex)
}
})
}
}
func TestGetOwningDigest_NoMatch(t *testing.T) {
digests := []config.ConfigDigest{
{
Title: "Exclusive Club",
Filters: config.ConfigFilters{
FeedTitles: []string{"VIP"},
},
},
}
dm, err := NewDigestManager(digests)
if err != nil {
t.Fatalf("Failed to create DigestManager: %v", err)
}
entry := &models.Entry{FeedTitle: "Plebeian News"}
got := dm.GetOwningDigest(entry)
if got != -1 {
t.Errorf("GetOwningDigest() = %v, want -1", got)
}
}