// 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) } }