aboutsummaryrefslogtreecommitdiff
path: root/cmds/retrostar_test.go
diff options
context:
space:
mode:
authorSam Scholten2026-08-30 12:50:24 +1000
committerSam Scholten2026-08-30 12:52:39 +1000
commit96ab2fcb2ff442698465389d75390afa91629165 (patch)
treeb36ef45dccaa791b0fce4dcad99d564635663c10 /cmds/retrostar_test.go
downloadfluxrec-96ab2fcb2ff442698465389d75390afa91629165.tar.gz
fluxrec-96ab2fcb2ff442698465389d75390afa91629165.zip
fluxrec: personal Miniflux article recommender
Diffstat (limited to 'cmds/retrostar_test.go')
-rw-r--r--cmds/retrostar_test.go64
1 files changed, 64 insertions, 0 deletions
diff --git a/cmds/retrostar_test.go b/cmds/retrostar_test.go
new file mode 100644
index 0000000..3ad6dca
--- /dev/null
+++ b/cmds/retrostar_test.go
@@ -0,0 +1,64 @@
+// Test for `fluxrec retrostar` against an httptest fake Miniflux: the
+// printed candidates are model-ranked and anything already in labels.jsonl
+// is excluded. Helpers (testEntry, makeEntries, pagedServer) come from
+// export_test.go.
+package cmds
+
+import (
+ "encoding/json"
+ "net/http/httptest"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+ "time"
+
+ "fluxrec/core"
+)
+
+func TestRetrostar(t *testing.T) {
+ // pool has 20 read+unstarred candidates (IDs 100-119)
+ fake := &pagedServer{read: makeEntries(20, 100, false, 1)}
+ srv := httptest.NewServer(fake.handler())
+ defer srv.Close()
+ t.Setenv("MINIFLUX_URL", srv.URL)
+ t.Setenv("MINIFLUX_TOKEN", "test-token")
+
+ dir := t.TempDir()
+
+ // Two candidates are already labeled and must be excluded.
+ labelsPath := filepath.Join(dir, "labels.jsonl")
+ now := time.Date(2024, 3, 1, 0, 0, 0, 0, time.UTC)
+ if err := core.AppendLabels(labelsPath, []core.LabelRow{
+ {EntryID: 105, URL: "https://example.com/post/105", Title: "Title 105",
+ FeedID: 1, FeedTitle: "Fixture Feed", Label: core.LabelPos, CapturedAt: now},
+ {EntryID: 110, URL: "https://example.com/post/110", Title: "Title 110",
+ FeedID: 1, FeedTitle: "Fixture Feed", Label: core.LabelNeg, CapturedAt: now},
+ }); err != nil {
+ t.Fatalf("AppendLabels: %v", err)
+ }
+
+ modelPath := filepath.Join(dir, "model.json")
+ body, _ := json.Marshal(testModel())
+ if err := os.WriteFile(modelPath, body, 0o644); err != nil {
+ t.Fatalf("writing model: %v", err)
+ }
+
+ cmd := &RetrostarCommand{ModelPath: modelPath, Labels: labelsPath, Days: 100000, Limit: 5}
+ var out strings.Builder
+ if err := cmd.Run(nil, &out); err != nil {
+ t.Fatalf("retrostar: %v", err)
+ }
+ got := out.String()
+ if !strings.Contains(got, "entry 100") {
+ t.Errorf("output missing top candidate 100:\n%s", got)
+ }
+ for _, excluded := range []string{"entry 105", "entry 110"} {
+ if strings.Contains(got, excluded) {
+ t.Errorf("output contains already-labeled %s:\n%s", excluded, got)
+ }
+ }
+ if !strings.Contains(got, "scanned 18 unlabeled candidates, showing 5") {
+ t.Errorf("summary line wrong:\n%s", got)
+ }
+}