Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat(news): ingest six crypto subreddits keyless, JSON-first with an Atom fallback

nirholas57b8988f8b48
diff --git a/api/_lib/news-sources.js b/api/_lib/news-sources.js
index 6ec219030..5325a0824 100644
--- a/api/_lib/news-sources.js
+++ b/api/_lib/news-sources.js
@@ -21,9 +21,12 @@
// re-probed slowly before any verdict. Regenerate and re-validate with
// scripts/news-sources-probe.mjs, which exits non-zero when a source has died.
//
-// Fields: name, url, category. Optional: kind ('json' — shaped by an adapter in
-// news.js rather than parsed as a feed), tier + credibility (upstream editorial
-// tiering, drives refresh priority), language + region (international feeds).
+// Fields: name, url, category. Optional: kind ('json', shaped by an adapter in
+// news.js rather than parsed as a feed), fallback_url (an alternate feed
+// representation of the same listing, retried by the aggregator when the
+// primary URL fails; see the reddit_* sources), tier + credibility (upstream
+// editorial tiering, drives refresh priority), language + region
+// (international feeds).
export const NEWS_SOURCES = {
// ── General newsrooms (66) ───────────────────────────────────────────────
@@ -278,6 +281,27 @@ export const NEWS_SOURCES = {
bitpinas: { name: 'BitPinas', url: 'https://bitpinas.com/feed/', category: 'asia' },
blockhead_tech: { name: 'Blockhead', url: 'https://www.blockhead.co/latest/rss/', category: 'asia' },
forkast: { name: 'Forkast News', url: 'https://forkast.news/feed/', category: 'asia' },
+
+ // ── Reddit community listings (6) ────────────────────────────────────────
+ // Keyless JSON listings (r/<sub>/hot.json), no OAuth. Two facts shape these
+ // entries, both verified with paced curl probes on 2026-08-05/06: Reddit's
+ // JSON API answers a constant 403 to datacenter egress (every UA, every
+ // host variant), while the SAME hot listing served as an Atom feed
+ // (hot.rss) answers 200 to a polite, identifying bot UA. So each source
+ // declares the Atom mirror as fallback_url: the aggregator (fetchSource in
+ // news.js) retries it whenever the JSON rung fails, and the JSON adapters
+ // (redditListing in news.js) do the score/stickied noise filtering the
+ // richer payload allows. Requests are paced to one in-flight fetch for the
+ // whole www.reddit.com domain (DOMAIN_CONCURRENCY_OVERRIDES in news.js),
+ // because a burst of six paced-1s requests already earns a 429.
+ // reddit_solana is listed first on purpose: refresh order follows registry
+ // order within a priority band, and Solana leads on this platform.
+ reddit_solana: { name: 'r/solana', url: 'https://www.reddit.com/r/solana/hot.json?limit=40&raw_json=1', fallback_url: 'https://www.reddit.com/r/solana/hot.rss?limit=40', category: 'solana', kind: 'json' },
+ reddit_cryptocurrency: { name: 'r/CryptoCurrency', url: 'https://www.reddit.com/r/CryptoCurrency/hot.json?limit=40&raw_json=1', fallback_url: 'https://www.reddit.com/r/CryptoCurrency/hot.rss?limit=40', category: 'general', kind: 'json' },
+ reddit_cryptomarkets: { name: 'r/CryptoMarkets', url: 'https://www.reddit.com/r/CryptoMarkets/hot.json?limit=40&raw_json=1', fallback_url: 'https://www.reddit.com/r/CryptoMarkets/hot.rss?limit=40', category: 'trading', kind: 'json' },
+ reddit_defi: { name: 'r/defi', url: 'https://www.reddit.com/r/defi/hot.json?limit=40&raw_json=1', fallback_url: 'https://www.reddit.com/r/defi/hot.rss?limit=40', category: 'defi', kind: 'json' },
+ reddit_bitcoin: { name: 'r/Bitcoin', url: 'https://www.reddit.com/r/Bitcoin/hot.json?limit=40&raw_json=1', fallback_url: 'https://www.reddit.com/r/Bitcoin/hot.rss?limit=40', category: 'bitcoin', kind: 'json' },
+ reddit_ethereum: { name: 'r/ethereum', url: 'https://www.reddit.com/r/ethereum/hot.json?limit=40&raw_json=1', fallback_url: 'https://www.reddit.com/r/ethereum/hot.rss?limit=40', category: 'ethereum', kind: 'json' },
};
// Canonical category order for filter UIs. 'all' is implicit.
diff --git a/api/_lib/news.js b/api/_lib/news.js
index ec8f21601..72d66eaea 100644
--- a/api/_lib/news.js
+++ b/api/_lib/news.js
@@ -314,12 +314,87 @@ export function parseFeed(xml, sourceKey) {
// ── Non-RSS sources ──────────────────────────────────────────────────────────
// A source with `kind: 'json'` is shaped by an adapter here instead of by
-// parseFeed. The bar for adding one is high: free, keyless, and reachable from
-// a datacenter IP (which is what Cloud Run is). Three of cryptocurrency.cv's
-// four JSON sources no longer clear it and are deliberately absent —
-// CryptoCompare now answers 401, DeFiLlama's /raises answers 402, and Reddit
-// answers 403 to cloud egress. Shipping them would mean four sources that fail
-// forever.
+// parseFeed. The bar for adding one is high: free, keyless, and serviceable
+// from a datacenter IP (which is what Cloud Run is). Two of cryptocurrency.cv's
+// four JSON sources no longer clear it and are deliberately absent:
+// CryptoCompare now answers 401 and DeFiLlama's /raises answers 402. Reddit's
+// keyless JSON listings also answer a constant 403 to datacenter egress, which
+// is why they were excluded for a long time; they ship now because Reddit
+// serves the SAME hot listing as an Atom feed (hot.rss) to a polite bot UA
+// (verified with paced probes, 2026-08-05/06), and the reddit_* sources declare
+// that mirror as `fallback_url`. fetchSource retries the mirror whenever the
+// JSON rung fails, so the source degrades to Atom instead of failing forever.
+
+// Reddit listing shaping (r/<sub>/hot.json, keyless, no OAuth). Community
+// feeds are noisy, so the adapter drops what the JSON payload lets it see:
+// pinned/stickied posts, NSFW posts, recurring megathreads, and anything under
+// a small score floor.
+const REDDIT_MIN_SCORE = 5;
+const REDDIT_NOISE_TITLE = /\b(?:daily (?:discussion|general|thread)|weekly (?:discussion|thread|roundup)|megathread|open discussion)\b/i;
+// Reddit's Atom mirror wraps every entry body in "submitted by /u/x [link]
+// [comments]" boilerplate; none of it is post text.
+const REDDIT_ATOM_BOILERPLATE = /submitted by\s+\/?u\/\S+.*$/i;
+
+function redditListing(data, key) {
+ const src = NEWS_SOURCES[key];
+ const children = data?.data?.children;
+ if (!Array.isArray(children)) throw new Error(`${key} unexpected payload`);
+ return children
+ .map((c) => {
+ const d = c?.data;
+ if (!d || d.stickied || d.over_18) return null;
+ if ((Number(d.score) || 0) < REDDIT_MIN_SCORE) return null;
+ const title = stripHtml(str(d.title) || '');
+ if (!title || !str(d.permalink)) return null;
+ if (REDDIT_NOISE_TITLE.test(title)) return null;
+ // The permalink (the discussion thread) is the canonical link: d.url on
+ // a link post can be a bare image or video, and the thread is where the
+ // score and the community context live.
+ const link = `https://www.reddit.com${d.permalink}`;
+ const iso = clampFuturePubDate(
+ Number.isFinite(d.created_utc) ? new Date(d.created_utc * 1000).toISOString() : null,
+ );
+ const selftext = stripHtml(str(d.selftext) || '');
+ const description = truncateWords(selftext, 320);
+ // raw_json=1 in the source URL keeps preview URLs unescaped; thumbnail
+ // placeholders ('self', 'default', 'nsfw') are not https and fall out in
+ // cleanImageUrl.
+ const image =
+ [str(d.preview?.images?.[0]?.source?.url), str(d.thumbnail)].map(cleanImageUrl).find(Boolean) || null;
+ return {
+ id: articleId(link),
+ title,
+ link,
+ description,
+ image,
+ author: str(d.author) ? `u/${d.author}` : null,
+ source: src.name,
+ source_key: key,
+ category: src.category,
+ pub_date: iso,
+ score: Number(d.score) || 0,
+ tickers: extractTickers(`${title} ${selftext}`),
+ sentiment: lexiconSentiment(`${title} ${selftext}`),
+ content_text: selftext.length > (description || '').length + 80 ? selftext.slice(0, 8000) : null,
+ };
+ })
+ .filter(Boolean);
+}
+
+// The Atom mirror carries no score/stickied metadata, so the noise gates are
+// re-applied from the only signal it has (the title), and the "submitted by"
+// wrapper is stripped from body text. Non-reddit fallbacks pass through as-is.
+function shapeFallbackArticles(key, articles) {
+ if (!key.startsWith('reddit_')) return articles;
+ const clean = (s) => stripHtml(String(s || '').replace(REDDIT_ATOM_BOILERPLATE, ''));
+ return articles
+ .filter((a) => !REDDIT_NOISE_TITLE.test(a.title))
+ .map((a) => ({
+ ...a,
+ description: truncateWords(clean(a.description), 320),
+ content_text: a.content_text ? clean(a.content_text) || null : null,
+ }));
+}
const JSON_ADAPTERS = {
// Exchange listing/delisting notices. Market-moving, and published to no RSS
@@ -353,6 +428,16 @@ const JSON_ADAPTERS = {
})
.filter(Boolean);
},
+
+ // Reddit community listings, one adapter per subreddit source (the registry
+ // guard in tests/news-sources.test.js requires a named adapter per key);
+ // the shaping lives in redditListing above.
+ reddit_solana(data, key) { return redditListing(data, key); },
+ reddit_cryptocurrency(data, key) { return redditListing(data, key); },
+ reddit_cryptomarkets(data, key) { return redditListing(data, key); },
+ reddit_defi(data, key) { return redditListing(data, key); },
+ reddit_bitcoin(data, key) { return redditListing(data, key); },
+ reddit_ethereum(data, key) { return redditListing(data, key); },
};
// ── Concurrency control ──────────────────────────────────────────────────────
@@ -394,13 +479,41 @@ function semaphore(limit) {
const globalGate = semaphore(GLOBAL_CONCURRENCY);
const domainGates = new Map();
+// Hosts stricter than the default per-domain cap. reddit.com rate-limits
+// keyless clients aggressively (a burst of six requests spaced 1s apart earned
+// a blanket 429, probed 2026-08-05), so its six listings fetch strictly one at
+// a time; the 5-minute source TTL keeps the steady state at about one request
+// per subreddit per 5 minutes.
+const DOMAIN_CONCURRENCY_OVERRIDES = { 'www.reddit.com': 1 };
+
function domainGate(domain) {
- if (!domainGates.has(domain)) domainGates.set(domain, semaphore(DOMAIN_CONCURRENCY));
+ if (!domainGates.has(domain)) {
+ domainGates.set(domain, semaphore(DOMAIN_CONCURRENCY_OVERRIDES[domain] || DOMAIN_CONCURRENCY));
+ }
return domainGates.get(domain);
}
// ── Per-source fetch ─────────────────────────────────────────────────────────
+function requestFeed(url, json) {
+ return fetch(url, {
+ headers: {
+ accept: json
+ ? 'application/json'
+ : 'application/rss+xml, application/atom+xml, application/xml, text/xml;q=0.9, */*;q=0.8',
+ // A polite, identifying bot UA gets through more publisher WAFs than a
+ // spoofed browser UA does: a fake Chrome string without the matching
+ // TLS/header fingerprint reads as a scraper and earns a 403. Reddit in
+ // particular rejects default library UAs outright; this descriptive one
+ // is what its keyless endpoints expect.
+ 'user-agent': 'Mozilla/5.0 (compatible; three.ws-news/1.0; +https://three.ws)',
+ 'accept-language': 'en-US,en;q=0.9',
+ },
+ signal: AbortSignal.timeout(FEED_TIMEOUT_MS),
+ redirect: 'follow',
+ });
+}
+
async function fetchSource(key) {
const src = NEWS_SOURCES[key];
const gate = domainGate(feedDomain(src.url));
@@ -410,27 +523,35 @@ async function fetchSource(key) {
await globalGate.acquire();
try {
const json = src.kind === 'json';
- const resp = await fetch(src.url, {
- headers: {
- accept: json
- ? 'application/json'
- : 'application/rss+xml, application/atom+xml, application/xml, text/xml;q=0.9, */*;q=0.8',
- // A polite, identifying bot UA gets through more publisher WAFs than a
- // spoofed browser UA does — a fake Chrome string without the matching
- // TLS/header fingerprint reads as a scraper and earns a 403.
- 'user-agent': 'Mozilla/5.0 (compatible; three.ws-news/1.0; +https://three.ws)',
- 'accept-language': 'en-US,en;q=0.9',
- },
- signal: AbortSignal.timeout(FEED_TIMEOUT_MS),
- redirect: 'follow',
- });
- if (!resp.ok) {
- const err = new Error(`${key} ${resp.status}`);
- err.status = resp.status;
- throw err;
+ const resp = await requestFeed(src.url, json);
+ if (resp.ok) {
+ if (json) return JSON_ADAPTERS[key](await resp.json(), key);
+ return parseFeed(await resp.text(), key);
+ }
+ const err = new Error(`${key} ${resp.status}`);
+ err.status = resp.status;
+ // Failover rung: a source may declare an alternate feed representation of
+ // the same listing (reddit's Atom mirror of its datacenter-blocked JSON
+ // API). Fetched sequentially under the same domain + global slots, so the
+ // per-domain pacing still holds.
+ if (src.fallback_url) {
+ let fb = null;
+ try {
+ fb = await requestFeed(src.fallback_url, false);
+ } catch {
+ // transport failure on the fallback: the primary error stands
+ }
+ if (fb?.ok) return shapeFallbackArticles(key, parseFeed(await fb.text(), key));
+ if (fb) {
+ // The fallback's verdict drives the backoff: reddit's JSON answers a
+ // constant 403 while its Atom mirror 429s transiently, and letting the
+ // 403 pick the 6h hard ceiling would mute a source whose fallback
+ // recovers within minutes.
+ err.status = fb.status;
+ err.message = `${key} ${resp.status} (fallback ${fb.status})`;
+ }
}
- if (json) return JSON_ADAPTERS[key](await resp.json(), key);
- return parseFeed(await resp.text(), key);
+ throw err;
} finally {
globalGate.release();
gate.release();
diff --git a/tests/api/reddit-news-sources.test.js b/tests/api/reddit-news-sources.test.js
new file mode 100644
index 000000000..f39ecc72e
--- /dev/null
+++ b/tests/api/reddit-news-sources.test.js
@@ -0,0 +1,293 @@
+// Coverage for the Reddit community listings in the news pipeline: the
+// reddit_* registry entries (api/_lib/news-sources.js) and the keyless-JSON
+// adapters plus the Atom-mirror fallback in api/_lib/news.js.
+//
+// No live network here, matching the house style for news coverage (liveness
+// is scripts/news-sources-probe.mjs's concern; see tests/news-sources.test.js).
+// The fixtures are real-shaped against Reddit's keyless listing schema, and
+// the Atom fixture mirrors a capture from the live r/solana hot.rss taken
+// 2026-08-06. That capture session is also why the fallback exists at all: the
+// JSON endpoint answered a constant 403 to datacenter egress (every UA, every
+// host variant) while the Atom mirror of the same listing answered 200 to the
+// aggregator's bot UA, which is exactly the split these tests exercise.
+
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
+
+const { getNews } = await import('../../api/_lib/news.js');
+const { NEWS_SOURCES } = await import('../../api/_lib/news-sources.js');
+
+const NOW_S = Math.floor(Date.now() / 1000);
+
+// A keyless hot.json listing, shaped exactly like Reddit's (kind/data/children
+// envelope, t3 posts with score / stickied / over_18 / permalink /
+// created_utc). The lead post is a real r/solana front-page item from the
+// 2026-08-06 capture.
+const LISTING_FIXTURE = {
+ kind: 'Listing',
+ data: {
+ after: 't3_after',
+ children: [
+ {
+ kind: 't3',
+ data: {
+ title: 'Read this before posting (rules and resources)',
+ permalink: '/r/solana/comments/aaa111/read_this_before_posting/',
+ score: 950,
+ stickied: true,
+ over_18: false,
+ author: 'solana-mods',
+ selftext: 'Subreddit rules.',
+ created_utc: NOW_S - 86400 * 30,
+ },
+ },
+ {
+ kind: 't3',
+ data: {
+ title: 'Solana Proposals Enter Preliminary Vote to Raise Fee Burn and Speed Inflation Decline',
+ permalink: '/r/solana/comments/1vegh2l/solana_proposals_enter_preliminary_vote_to_raise/',
+ score: 812,
+ stickied: false,
+ over_18: false,
+ author: 'ansi09',
+ selftext: '',
+ url: 'https://governance.example.com/proposal',
+ thumbnail: 'default',
+ preview: {
+ images: [
+ {
+ source: {
+ url: 'https://preview.redd.it/6dzf9dsekchh1.png?width=1400&height=530&auto=webp&s=97d8c185204126e7752ff957c7dc3fe573d3aa15',
+ width: 1400,
+ height: 530,
+ },
+ },
+ ],
+ },
+ created_utc: NOW_S - 3600,
+ },
+ },
+ {
+ kind: 't3',
+ data: {
+ title: 'How do validators handle the new fee burn split?',
+ permalink: '/r/solana/comments/bbb222/how_do_validators_handle_the_new_fee_burn_split/',
+ score: 57,
+ stickied: false,
+ over_18: false,
+ author: 'validator-curious',
+ selftext:
+ 'Trying to understand how the burn interacts with priority fees on Solana. If the proposal passes, does the validator share of priority fees change too, or only the base fee burn? Links to the actual SIMD text welcome.',
+ thumbnail: 'self',
+ created_utc: NOW_S - 7200,
+ },
+ },
+ {
+ kind: 't3',
+ data: {
+ title: 'my wallet screenshot',
+ permalink: '/r/solana/comments/ccc333/my_wallet_screenshot/',
+ score: 2,
+ stickied: false,
+ over_18: false,
+ author: 'shillbot9000',
+ selftext: '',
+ created_utc: NOW_S - 600,
+ },
+ },
+ {
+ kind: 't3',
+ data: {
+ title: 'Daily Discussion - August 6, 2026 (GMT+0)',
+ permalink: '/r/solana/comments/ddd444/daily_discussion/',
+ score: 410,
+ stickied: false,
+ over_18: false,
+ author: 'AutoModerator',
+ selftext: 'Talk about anything.',
+ created_utc: NOW_S - 1800,
+ },
+ },
+ {
+ kind: 't3',
+ data: {
+ title: 'NSFW chart art',
+ permalink: '/r/solana/comments/eee555/nsfw_chart_art/',
+ score: 90,
+ stickied: false,
+ over_18: true,
+ author: 'degen',
+ selftext: '',
+ created_utc: NOW_S - 900,
+ },
+ },
+ ],
+ },
+};
+
+// The same listing as Reddit's Atom mirror serves it (hot.rss): single
+// link-with-href entries, html content wrapped in the "submitted by /u/x
+// [link] [comments]" boilerplate. Structure mirrors the live 2026-08-06
+// r/solana capture.
+const ATOM_FIXTURE = `<?xml version="1.0" encoding="UTF-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">
+ <category term="solana" label="r/solana"/>
+ <updated>2026-08-06T00:03:01+00:00</updated>
+ <id>/r/solana/hot.rss?limit=40</id>
+ <title>Solana</title>
+ <entry>
+ <author><name>/u/ansi09</name><uri>https://www.reddit.com/user/ansi09</uri></author>
+ <category term="solana" label="r/solana"/>
+ <content type="html">&lt;div class="md"&gt;&lt;p&gt;Preliminary vote is live on the governance portal.&lt;/p&gt;&lt;/div&gt; submitted by &lt;a href="https://www.reddit.com/user/ansi09"&gt; /u/ansi09 &lt;/a&gt; [link] [comments]</content>
+ <id>t3_1vegh2l</id>
+ <link href="https://www.reddit.com/r/solana/comments/1vegh2l/solana_proposals_enter_preliminary_vote_to_raise/" />
+ <updated>2026-08-05T21:03:33+00:00</updated>
+ <published>2026-08-05T21:03:33+00:00</published>
+ <title>Solana Proposals Enter Preliminary Vote to Raise Fee Burn and Speed Inflation Decline</title>
+ </entry>
+ <entry>
+ <author><name>/u/AutoModerator</name><uri>https://www.reddit.com/user/AutoModerator</uri></author>
+ <category term="solana" label="r/solana"/>
+ <content type="html">Talk about anything. submitted by &lt;a href="https://www.reddit.com/user/AutoModerator"&gt; /u/AutoModerator &lt;/a&gt; [link] [comments]</content>
+ <id>t3_ddd444</id>
+ <link href="https://www.reddit.com/r/solana/comments/ddd444/daily_discussion/" />
+ <updated>2026-08-05T22:00:00+00:00</updated>
+ <published>2026-08-05T22:00:00+00:00</published>
+ <title>Daily Discussion - August 6, 2026 (GMT+0)</title>
+ </entry>
+</feed>`;
+
+describe('reddit registry entries', () => {
+ const redditKeys = Object.keys(NEWS_SOURCES).filter((k) => k.startsWith('reddit_'));
+
+ it('registers the six subreddit listings as keyless JSON sources', () => {
+ expect([...redditKeys].sort()).toEqual(
+ ['reddit_solana', 'reddit_cryptocurrency', 'reddit_cryptomarkets', 'reddit_defi', 'reddit_bitcoin', 'reddit_ethereum'].sort(),
+ );
+ for (const key of redditKeys) {
+ const src = NEWS_SOURCES[key];
+ expect(src.kind, key).toBe('json');
+ const url = new URL(src.url);
+ expect(url.hostname, key).toBe('www.reddit.com');
+ expect(url.pathname, key).toMatch(/^\/r\/[A-Za-z]+\/hot\.json$/);
+ // raw_json=1 keeps preview URLs unescaped; no OAuth params anywhere
+ expect(url.searchParams.get('raw_json'), key).toBe('1');
+ expect(src.url, key).not.toMatch(/oauth|token|key=/i);
+ }
+ });
+
+ it('maps each subreddit to its home category', () => {
+ expect(NEWS_SOURCES.reddit_solana.category).toBe('solana');
+ expect(NEWS_SOURCES.reddit_cryptocurrency.category).toBe('general');
+ expect(NEWS_SOURCES.reddit_cryptomarkets.category).toBe('trading');
+ expect(NEWS_SOURCES.reddit_defi.category).toBe('defi');
+ expect(NEWS_SOURCES.reddit_bitcoin.category).toBe('bitcoin');
+ expect(NEWS_SOURCES.reddit_ethereum.category).toBe('ethereum');
+ });
+
+ it('lists reddit_solana first, honouring the chain priority (refresh follows registry order)', () => {
+ expect(redditKeys[0]).toBe('reddit_solana');
+ });
+
+ it('declares the Atom mirror of the SAME subreddit listing as the fallback', () => {
+ for (const key of redditKeys) {
+ const src = NEWS_SOURCES[key];
+ const sub = src.url.match(/\/r\/([^/]+)\/hot\.json/)[1];
+ const fb = new URL(src.fallback_url);
+ expect(fb.hostname, key).toBe('www.reddit.com');
+ expect(fb.pathname, key).toBe(`/r/${sub}/hot.rss`);
+ }
+ });
+});
+
+describe('reddit JSON adapter (hot.json)', () => {
+ const originalFetch = global.fetch;
+ afterEach(() => {
+ global.fetch = originalFetch;
+ vi.restoreAllMocks();
+ });
+
+ it('normalizes posts into the article shape and drops stickied, low-score, megathread, and NSFW noise', async () => {
+ global.fetch = vi.fn(async () => ({ ok: true, json: async () => LISTING_FIXTURE }));
+ const res = await getNews({ source: 'reddit_solana', limit: 20 });
+
+ expect(res.sources_ok).toBe(1);
+ const titles = res.articles.map((a) => a.title);
+ expect(titles).toContain('Solana Proposals Enter Preliminary Vote to Raise Fee Burn and Speed Inflation Decline');
+ expect(titles).toContain('How do validators handle the new fee burn split?');
+ // stickied, score < 5, Daily Discussion megathread, over_18: all filtered
+ expect(titles).not.toContain('Read this before posting (rules and resources)');
+ expect(titles).not.toContain('my wallet screenshot');
+ expect(titles.join(' ')).not.toMatch(/Daily Discussion/);
+ expect(titles).not.toContain('NSFW chart art');
+
+ const lead = res.articles.find((a) => a.title.startsWith('Solana Proposals'));
+ expect(lead.link).toBe(
+ 'https://www.reddit.com/r/solana/comments/1vegh2l/solana_proposals_enter_preliminary_vote_to_raise/',
+ );
+ expect(lead.id).toMatch(/^[0-9a-f]{16}$/);
+ expect(lead.source).toBe('r/solana');
+ expect(lead.source_key).toBe('reddit_solana');
+ expect(lead.category).toBe('solana');
+ expect(lead.author).toBe('u/ansi09');
+ expect(lead.score).toBe(812);
+ expect(lead.pub_date).toBe(new Date((NOW_S - 3600) * 1000).toISOString());
+ expect(lead.image).toBe(
+ 'https://preview.redd.it/6dzf9dsekchh1.png?width=1400&height=530&auto=webp&s=97d8c185204126e7752ff957c7dc3fe573d3aa15',
+ );
+ expect(lead.tickers).toContain('SOL');
+ expect(lead.sentiment).toHaveProperty('label');
+
+ const selfPost = res.articles.find((a) => a.title.startsWith('How do validators'));
+ expect(selfPost.description).toContain('priority fees');
+ expect(selfPost.score).toBe(57);
+ // the 'self' thumbnail placeholder is not an image
+ expect(selfPost.image).toBeNull();
+ });
+});
+
+describe('reddit Atom-mirror fallback (hot.rss)', () => {
+ const originalFetch = global.fetch;
+ afterEach(() => {
+ global.fetch = originalFetch;
+ vi.restoreAllMocks();
+ });
+
+ it('serves the listing from the Atom mirror when the JSON rung answers 403', async () => {
+ const urls = [];
+ global.fetch = vi.fn(async (url) => {
+ urls.push(String(url));
+ if (String(url).includes('hot.json')) return { ok: false, status: 403 };
+ return { ok: true, text: async () => ATOM_FIXTURE.replace(/\/r\/solana\//g, '/r/ethereum/') };
+ });
+ const res = await getNews({ source: 'reddit_ethereum', limit: 20 });
+
+ expect(urls[0]).toBe(NEWS_SOURCES.reddit_ethereum.url);
+ expect(urls[1]).toBe(NEWS_SOURCES.reddit_ethereum.fallback_url);
+ expect(res.sources_ok).toBe(1);
+ const titles = res.articles.map((a) => a.title);
+ expect(titles).toContain('Solana Proposals Enter Preliminary Vote to Raise Fee Burn and Speed Inflation Decline');
+ // the Atom mirror carries no stickied/score metadata, so the megathread
+ // gate re-applies from the title
+ expect(titles.join(' ')).not.toMatch(/Daily Discussion/);
+
+ const a = res.articles[0];
+ expect(a.link).toBe('https://www.reddit.com/r/ethereum/comments/1vegh2l/solana_proposals_enter_preliminary_vote_to_raise/');
+ expect(a.author).toBe('/u/ansi09');
+ expect(a.pub_date).toBe('2026-08-05T21:03:33.000Z');
+ // Reddit's "submitted by /u/x [link] [comments]" wrapper is boilerplate,
+ // not post text
+ expect(a.description).toContain('Preliminary vote is live');
+ expect(a.description).not.toMatch(/submitted by/i);
+ expect(a.description).not.toMatch(/\[comments\]/);
+ });
+
+ it('degrades to an empty (not thrown) round when both rungs fail, keeping backoff soft on a transient 429', async () => {
+ global.fetch = vi.fn(async (url) =>
+ String(url).includes('hot.json') ? { ok: false, status: 403 } : { ok: false, status: 429 },
+ );
+ const res = await getNews({ source: 'reddit_defi', limit: 20 });
+ expect(res.articles).toEqual([]);
+ expect(res.sources_ok).toBe(0);
+ expect(global.fetch).toHaveBeenCalledTimes(2);
+ });
+});