95195daff8
- feeds.preview_feed(): fetch + score a sample WITHOUT persisting; returns freshness, acceptance rate, cortisol/ragebait/PR averages, and example accepted/rejected items. With an LLM client it also returns topic/flavor mix and the model's (accurate) acceptance view. - CLI 'preview-source URL [--sample] [--classify]'. - API 'GET /api/source-preview?url=&sample=&classify=' with an http(s)-only guard (SSRF note left for go-public hardening). - Site 'Suggest a source' panel with Quick check (heuristic, instant) and Deep check (model, accurate), rendered DOM-safely. - Tests: network-free preview_feed tests via monkeypatched fetch (45 total). - README documents the command, endpoint, and updated roadmap. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
import goodnews.feeds as feeds
|
|
|
|
RSS = b"""<?xml version="1.0"?>
|
|
<rss><channel>
|
|
<item>
|
|
<title>Volunteers restore creek and rescue stranded wildlife</title>
|
|
<description>A hopeful recovery effort</description>
|
|
<link>http://example.com/1</link>
|
|
<pubDate>Sat, 30 May 2026 10:00:00 GMT</pubDate>
|
|
</item>
|
|
<item>
|
|
<title>Quarterly tax filing deadline reminder</title>
|
|
<description>routine notice</description>
|
|
<link>http://example.com/2</link>
|
|
<pubDate>Sat, 30 May 2026 09:00:00 GMT</pubDate>
|
|
</item>
|
|
</channel></rss>"""
|
|
|
|
|
|
def test_preview_feed_scores_sample_without_network(monkeypatch):
|
|
monkeypatch.setattr(feeds, "fetch_feed", lambda url, **kw: RSS)
|
|
p = feeds.preview_feed("http://example.com/feed")
|
|
|
|
assert p["sampled"] == 2
|
|
assert p["classified"] is False
|
|
assert 0.0 <= p["acceptance_rate"] <= 1.0
|
|
assert p["accepted"] >= 1 # the restore/rescue story should pass the heuristic
|
|
assert p["newest_published"] is not None
|
|
assert isinstance(p["topic_mix"], dict) and p["topic_mix"] == {} # empty without a model
|
|
assert all("reason" in ex and "title" in ex for ex in p["examples_rejected"])
|
|
|
|
|
|
def test_preview_feed_respects_sample_cap(monkeypatch):
|
|
monkeypatch.setattr(feeds, "fetch_feed", lambda url, **kw: RSS)
|
|
p = feeds.preview_feed("http://example.com/feed", sample=1)
|
|
assert p["sampled"] == 1
|