news: feed reads R2 only (origin fallback removed)
- Commit
081b96f9026eb13134023a5331c26767b5d3a222- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-26 01:40 UTC (10 days ago)
- Parents
7bafa7b
Networking.fetchServerFeedText now reads only https://static.maproj.org/news/v1/news.json via StaticMirror.getStatic (1 h freshness acceptance); SERVER_FEED_URL and the origin fallback are deleted. Static missing/failing/stale throws IOException into the unchanged path: Room-cached feed stays visible and the on-device sitemap/RSS crawl takes over. Tests updated to the R2-only contract. Verified: :news:testDevUnitTest and :news:lint pass.
Diff
news/AGENTS.md
diff --git a/news/AGENTS.md b/news/AGENTS.mdindex b79c9303c6..2fda90c94f 100644--- a/news/AGENTS.md+++ b/news/AGENTS.md@@ -12,19 +12,20 @@ _Install: ./install news_ ## Overview **Purpose:** News reader. Primary feed is our server's merged-`news.json` snapshot, read first from its static copy on R2+`news.json` snapshot, distributed only as its static copy on R2 (`https://static.maproj.org/news/v1/news.json`, republished by the-server on every refresh) with the origin `GET /news.json`-(`https://api.maproj.org/news.json`, see `domain/ServerFeedParser` for-the contract + assumptions) as fallback when the static copy is-missing, failing, or older than 1 hour; the result is merged into Room. Every source is always in the+server's background refresh on every cycle; there is no news endpoint+on the origin — see `domain/ServerFeedParser` for the contract ++assumptions). When the static copy is missing, failing, or older+than 1 hour, refresh falls back to the on-device crawl below; the+result is merged into Room. Every source is always in the corpus (no per-source toggle); category + search are the filters, and `domain/FeedRanking` orders the story feed client-side by descending source count, then newest first (search keeps its relevance order). Every feed item is a story (`domain/Story`, mechanical grouping by exact server `storyId` only — singletons included), shown as a card labelled only with its source count ("1 source" / "N sources", no-lead-source name) and opening the story view. If the server fetch fails/times out/parses empty, refresh+lead-source name) and opening the story view. If the static feed fetch fails/times out/parses empty, refresh falls back to the on-device per-source sitemap/RSS crawl of all sources (cached feed stays visible either way). Article reading is always on-device: publisher HTML is fetched directly and extracted locally. No account.@@ -65,10 +66,10 @@ Japan Times (sitemap URL serves HTML, not XML). (DataStore owner) → `network/Networking` (the single networking entry point, `NetworkClient` with `TrustBundle.SYSTEM` — publisher hosts are arbitrary, so no reduced bundle can cover them; SYSTEM also covers-api.maproj.org and static.maproj.org, whereas FIRST_PARTY would break+static.maproj.org, whereas FIRST_PARTY would break publisher fetches; the server feed goes through-`Networking.fetchServerFeedText` → `StaticMirror.get`, static first,-origin fallback) → `domain/` parsers and extractor (pure, no Android+`Networking.fetchServerFeedText` → `StaticMirror.getStatic`, R2 only,+no origin fallback) → `domain/` parsers and extractor (pure, no Android imports). ## Entry points + reading order
news/src/main/java/com/vayunmathur/news/data/NewsRepository.kt
diff --git a/news/src/main/java/com/vayunmathur/news/data/NewsRepository.kt b/news/src/main/java/com/vayunmathur/news/data/NewsRepository.ktindex 89fbc36228..91a798f3b3 100644--- a/news/src/main/java/com/vayunmathur/news/data/NewsRepository.kt+++ b/news/src/main/java/com/vayunmathur/news/data/NewsRepository.kt@@ -31,8 +31,8 @@ import kotlinx.serialization.json.Json * defaults to [Networking] and is replaced by a fake in unit tests, so * no test touches the network; the server feed goes through the * [serverFeedFetch] seam (defaults to [Networking.fetchServerFeedText]:- * R2 static copy first, origin as fallback). Bodies are extracted on- * device only.+ * the R2 static copy only — there is no origin news endpoint). Bodies+ * are extracted on device only. * * Refresh topology (fixed 2026-11-23, was the ANR / "stuck feed" bug): * sources fetch in parallel, each on [feedDispatcher] (never Main —@@ -66,8 +66,7 @@ class NewsRepository internal constructor( /** * Primary path: one fetch of the server feed (its R2 static copy- * first, the origin `news.json` as fallback — see- * [Networking.fetchServerFeedText]), merged into+ * only — see [Networking.fetchServerFeedText]), merged into * Room exactly like a crawl result. Every source the server carries * is always included — there is no client-side enabled-source * filter; categories and search are the filters. [sources] only
news/src/main/java/com/vayunmathur/news/domain/ServerFeedParser.kt
diff --git a/news/src/main/java/com/vayunmathur/news/domain/ServerFeedParser.kt b/news/src/main/java/com/vayunmathur/news/domain/ServerFeedParser.ktindex 945ed107b5..fdc125226d 100644--- a/news/src/main/java/com/vayunmathur/news/domain/ServerFeedParser.kt+++ b/news/src/main/java/com/vayunmathur/news/domain/ServerFeedParser.kt@@ -9,7 +9,9 @@ import kotlinx.serialization.json.jsonArray import kotlinx.serialization.json.jsonObject /**- * Parser for the location_share_server `GET /news.json` contract:+ * Parser for the server-published static feed contract+ * (`https://static.maproj.org/news/v1/news.json`, written by+ * location_share_server's background refresh): * * ``` * { "generated_at": ..., "articles": [
news/src/main/java/com/vayunmathur/news/network/Networking.kt
diff --git a/news/src/main/java/com/vayunmathur/news/network/Networking.kt b/news/src/main/java/com/vayunmathur/news/network/Networking.ktindex d563150bb7..e03150eaa5 100644--- a/news/src/main/java/com/vayunmathur/news/network/Networking.kt+++ b/news/src/main/java/com/vayunmathur/news/network/Networking.kt@@ -8,34 +8,31 @@ import java.io.IOException * The news app's single networking entry point. Owns the client, the * browser-like request headers publisher CDNs expect, and status mapping. *- * Feed primary path is the server's static copy of `GET /news.json` on- * R2 at [STATIC_FEED_URL] (`https://static.maproj.org/news/v1/news.json`,+ * Feed path is the server's static copy of the feed on R2 at+ * [STATIC_FEED_URL] (`https://static.maproj.org/news/v1/news.json`, * republished by the server on every 12-minute refresh), read through- * [StaticMirror] with [SERVER_FEED_URL] — `https://api.maproj.org`, the- * same API host findfamily/everysync use (root AGENTS.md: "The server's- * canonical API host is api.maproj.org") — as the fallback when the- * static copy is missing, failing, or older than [STATIC_MAX_AGE_MS].- * Article bodies and the offline sitemap/RSS fallback still fetch+ * [StaticMirror]. There is no origin fallback: the origin serves+ * nothing for news. When the static copy is missing, failing, or older+ * than [STATIC_MAX_AGE_MS], [fetchServerFeedText] throws and the+ * repository falls back to its on-device sitemap/RSS crawl with the+ * Room-cached feed visible throughout. Article bodies still fetch * publisher URLs directly on-device. * * Trust stays SYSTEM (initialised in MainActivity), not FIRST_PARTY: * FIRST_PARTY pins only cover api.maproj.org and would break every- * publisher fetch, while SYSTEM (platform roots, incl. the public CA- * chain api.maproj.org serves) covers api.maproj.org,- * static.maproj.org, and the publisher hosts. Narrowing would need a+ * publisher fetch, while SYSTEM (platform roots) covers+ * static.maproj.org and the publisher hosts. Narrowing would need a * per-host client, which NetworkClient does not offer. */ object Networking {- /** Server feed (location_share_server `GET /news.json`); see ServerFeedParser for the contract. */- const val SERVER_FEED_URL = "https://api.maproj.org/news.json"-- /** The server's copy of the same feed on R2 (read first); key `news/v1/news.json` in the static bucket. */+ /** The server's feed on R2 (the only distribution copy); key `news/v1/news.json` in the static bucket. */ const val STATIC_FEED_URL = "${StaticMirror.BASE}/news/v1/news.json" /** * Older static copies mean the server stopped republishing them- * (refresh is every 12 min): ask the origin directly instead. Five- * missed refresh cycles of slack, then the origin wins.+ * (refresh is every 12 min): treat the feed as unavailable so the+ * repository crawls on-device instead. Five missed refresh cycles+ * of slack, then the crawl wins. */ const val STATIC_MAX_AGE_MS = 60L * 60 * 1000 private val headers = mapOf(@@ -45,16 +42,14 @@ object Networking { ) /**- * The merged server feed as text: the R2 static copy first- * ([StaticMirror.get]-style, fresh within [STATIC_MAX_AGE_MS]), the- * origin `GET /news.json` as fallback. Throws [IOException] when the- * fallback answers non-2xx, exactly like [fetchText], so the- * repository's failure handling (cached feed, then on-device crawl)- * is unchanged.+ * The merged server feed as text: the R2 static copy only, fresh+ * within [STATIC_MAX_AGE_MS]. Throws [IOException] when the copy is+ * missing, failing, or stale, so the repository's failure handling+ * (cached feed, then on-device crawl) takes over. */ suspend fun fetchServerFeedText(): String {- val response = StaticMirror.get(STATIC_FEED_URL, SERVER_FEED_URL, STATIC_MAX_AGE_MS)- if (!response.isSuccess) throw IOException("HTTP ${response.status} for $SERVER_FEED_URL")+ val response = StaticMirror.getStatic(STATIC_FEED_URL, STATIC_MAX_AGE_MS)+ ?: throw IOException("static news feed unavailable or stale: $STATIC_FEED_URL") return response.text }
news/src/test/java/com/vayunmathur/news/data/NewsServerFeedTest.kt
diff --git a/news/src/test/java/com/vayunmathur/news/data/NewsServerFeedTest.kt b/news/src/test/java/com/vayunmathur/news/data/NewsServerFeedTest.ktindex 9dfebbbaf1..ff659a95ea 100644--- a/news/src/test/java/com/vayunmathur/news/data/NewsServerFeedTest.kt+++ b/news/src/test/java/com/vayunmathur/news/data/NewsServerFeedTest.kt@@ -57,11 +57,12 @@ class NewsServerFeedTest { assertTrue(cached.any { it.title == "Server Alpha Volcano" }) } - @Test fun staticFeedUrlIsTheR2CopyWithOriginFallback() {+ @Test fun staticFeedUrlIsTheOnlyDistributionCopy() { // The contract the server publishes to (location_share_server- // NEWS_R2_KEY) and the app's fallback order.+ // NEWS_R2_KEY). There is no origin news endpoint and no origin+ // fallback URL: a missing/failing/stale static copy makes+ // fetchServerFeedText throw and the repository crawls on-device. assertEquals("https://static.maproj.org/news/v1/news.json", Networking.STATIC_FEED_URL)- assertEquals("https://api.maproj.org/news.json", Networking.SERVER_FEED_URL) assertTrue(Networking.STATIC_MAX_AGE_MS > 0) } @@ -90,12 +91,12 @@ class NewsServerFeedTest { val repo = NewsRepository( context, fetch = { url -> calls += url; fallbackUrlset },- serverFeedFetch = { calls += Networking.SERVER_FEED_URL; throw IOException("server unreachable") },+ serverFeedFetch = { calls += "server-feed"; throw IOException("static feed unavailable") }, ) val bbc = SourceCatalog.byId("bbc")!!.copy(feedUrl = "https://srv.example/fallback.xml") val failed = repo.refresh(listOf(bbc)) assertTrue(failed.isEmpty(), "fallback crawl success must not report failure")- assertTrue(calls.first() == Networking.SERVER_FEED_URL, "server must be tried first")+ assertTrue(calls.first() == "server-feed", "server feed must be tried first") assertTrue(calls.any { it.endsWith("fallback.xml") }, "fallback must crawl the given source") val cached = withTimeout(10_000) { repo.articles.first { a -> a.any { it.title == "Fallback Story" } } } assertTrue(cached.any { it.title == "Fallback Story" })