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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(news): stop a cold instance from caching a live news card as a dead 404
nirholascbdd48fa2565
diff --git a/api/_lib/news-sources.js b/api/_lib/news-sources.jsindex d83e97038..74ab1ac3c 100644--- a/api/_lib/news-sources.js+++ b/api/_lib/news-sources.js@@ -398,3 +398,62 @@ export function isFeaturedSource(key) {if (!s) return false;return s.tier === 'tier1' || s.tier === 'tier2' || (s.credibility || 0) >= 0.85;}++// ── Publisher host to source key ─────────────────────────────────────────────+// A link names its publisher, and that publisher is exactly one of the feeds+// above. Resolving it lets a lookup refresh the single source that could hold+// an article instead of fanning out over every feed in the registry, which is+// the difference between a narrow query that waits for its feed and a broad one+// that truncates at a short deadline and drops the straggler.+//+// The index is built from the feed URLs, keyed by hostname with a leading+// "www." removed, because a publisher routinely serves its RSS from the bare+// domain and its articles from the www host (coincu.com/feed vs+// www.coincu.com/article). Where two sources share a host (a publisher with a+// per-category feed) the first key wins; both hold the same articles for this+// purpose. A feed hosted somewhere other than the publisher's own domain simply+// has no entry, and the caller falls back to the broad scan.+let hostIndex = null;++function normalizeHost(host) {+ return String(host || '').toLowerCase().replace(/^www\./, '');+}++function buildHostIndex() {+ const index = new Map();+ for (const [key, source] of Object.entries(NEWS_SOURCES)) {+ let host;+ try {+ host = normalizeHost(new URL(source.url).hostname);+ } catch {+ continue; // a malformed feed URL is simply not indexable+ }+ if (host && !index.has(host)) index.set(host, key);+ }+ return index;+}++/**+ * The source key that publishes `link`, or null when no registered feed lives+ * on that host. Matches the exact host first, then walks up the subdomains+ * (news.example.com falls back to example.com) so a publisher whose articles+ * sit on a subdomain of its feed host still resolves.+ *+ * @param {string} link article URL+ * @returns {string|null}+ */+export function sourceKeyForLink(link) {+ if (!hostIndex) hostIndex = buildHostIndex();+ let host;+ try {+ host = normalizeHost(new URL(link).hostname);+ } catch {+ return null;+ }+ while (host.includes('.')) {+ const hit = hostIndex.get(host);+ if (hit) return hit;+ host = host.slice(host.indexOf('.') + 1);+ }+ return null;+}diff --git a/api/_lib/news.js b/api/_lib/news.jsindex afa343290..e9349a4ac 100644--- a/api/_lib/news.js+++ b/api/_lib/news.js@@ -24,7 +24,7 @@import { createHash } from 'node:crypto';import { XMLParser } from 'fast-xml-parser';-import { NEWS_SOURCES, sourcesForCategory, sourcesForLanguage, sourcePriority, isFeaturedSource } from './news-sources.js';+import { NEWS_SOURCES, sourcesForCategory, sourcesForLanguage, sourcePriority, isFeaturedSource, sourceKeyForLink } from './news-sources.js';import { isSuppressed, excerptText } from './news-rights.js';import { isDisplayable } from './news-curation.js';import { truncateChars } from './safe-text.js';@@ -764,13 +764,26 @@ export async function searchNews(q, limit = 8) {* page fetches — the content still comes from the publisher's own feed.*/export async function findArticle({ link, id }) {- const keys = sourcesForCategory('all');- const all = await ensureSources(keys);const wantId = id || (link ? articleId(link) : null);if (!wantId && !link) return null;- const hit = all.find((a) => a.id === wantId || (link && a.link === link)) || null;+ const match = (articles) => articles.find((a) => a.id === wantId || (link && a.link === link)) || null;// A withdrawn story is "not found" to every caller, including the reader's- // feed-body fallback — otherwise a blocked page fetch would route straight+ // feed-body fallback: otherwise a blocked page fetch would route straight// around the rights filter and serve the publisher's feed copy instead.- return hit && isSuppressed(hit) ? null : hit;+ const answer = (hit) => (hit && isSuppressed(hit) ? null : hit);++ // Ask the one feed that could hold this link first, with the full timeout a+ // narrow query gets in getNews. The broad scan below fans out over every+ // source in the registry and truncates at REFRESH_DEADLINE_MS, so on an+ // instance whose cache is still cold the publisher is dropped mid-refresh+ // and an article the feed served seconds earlier reads as unknown. That is+ // how /api/news/image came to answer a cacheable 404 for a live card, which+ // then pinned a console 404 on every reader for the life of the cache entry.+ const key = link ? sourceKeyForLink(link) : null;+ if (key) {+ const narrow = answer(match(await ensureSources([key], FEED_TIMEOUT_MS + 500)));+ if (narrow) return narrow;+ }++ return answer(match(await ensureSources(sourcesForCategory('all'))));}diff --git a/api/news/README.md b/api/news/README.mdindex 366e54cb2..29b85b460 100644--- a/api/news/README.md+++ b/api/news/README.md@@ -21,7 +21,7 @@ All endpoints are `GET`, CORS-open, and rate-limited per client IP via [`../_lib| `GET /api/news/archive?q&ticker&source&category&sentiment&lang&start_date&end_date&limit&offset` | /markets/archive | Historical corpus: 662,047 enriched articles from September 2017 onward on the platform's own GCS bucket, extended hourly by [`api/cron/news-archive-append.js`](../cron/news-archive-append.js). `?stats=true`, `?months=true`, and `?trending=true` are always free; searches carry a free per-IP daily quota, then an x402 challenge ($0.001 USDC, env `X402_PRICE_NEWS_ARCHIVE`). || `GET /api/news/knowledge?id\|ticker\|q&full=1` | Agent grounding, /markets/news story context | Read side of the knowledge corpus: one full record by 16-hex id, recent stories mentioning a ticker, free-text search, or latest records plus corpus stats. Same rights boundary as the reader on the way out. || `GET /api/news/rss?category&limit` | RSS readers, downstream aggregators | RSS 2.0 mirror of the curated feed, linked as `rel="alternate"` from /markets/news. The source count in the channel description is derived from the registry, never hardcoded. |-| `GET /api/news/image?url=<link>` | /markets/news card images | Preview-image resolver for the ~20% of feeds that ship text-only RSS. Only resolves links the aggregator actually served (not an open resolver), extracts og:image with an SSRF-hardened fetcher, and 302s to the same-origin `/api/img` proxy. Both hits and misses are cached. |+| `GET /api/news/image?url=<link>` | /markets/news card images | Preview-image resolver for the ~20% of feeds that ship text-only RSS. Only resolves links the aggregator actually served (not an open resolver), extracts og:image with an SSRF-hardened fetcher, and 302s to the same-origin `/api/img` proxy. Both hits and misses are cached, but a miss on a host that IS one of our feeds is cached for 30s rather than the full window, because it means the lookup could not confirm a card we probably served. || `GET /markets/news/<YYYY-MM>/<id16>[-slug]` | Story permalinks, crawlers, link previews | Server-rendered by `story-page.js` (routed in `vercel.json`): real title/canonical/OpenGraph tags, NewsArticle JSON-LD, and a crawler-visible body in the same shell the client reader hydrates. The query-param reader stays noindex; this page is the indexable one. |Frontend consumers live in `src/`: [`markets-news.js`](../../src/markets-news.js), [`news-digest.js`](../../src/news-digest.js), [`news-article.js`](../../src/news-article.js), [`news-archive.js`](../../src/news-archive.js), with shared link helpers in [`src/shared/news-links.js`](../../src/shared/news-links.js). The public pages are declared in [`data/pages.json`](../../data/pages.json) (/markets/news, /markets/news/article).diff --git a/api/news/image.js b/api/news/image.jsindex 15553ebfa..f367f0953 100644--- a/api/news/image.js+++ b/api/news/image.js@@ -28,6 +28,7 @@import { wrap, cors, method, json, error, rateLimited } from '../_lib/http.js';import { limits, clientIp } from '../_lib/rate-limit.js';import { findArticle, extractOgImage } from '../_lib/news.js';+import { sourceKeyForLink } from '../_lib/news-sources.js';import { fetchModel } from '../_lib/fetch-model.js';const PAGE_TIMEOUT_MS = 6_000;@@ -83,10 +84,18 @@ export default wrap(async (req, res) => {// one per render.const article = await findArticle({ link });if (!article) {+ // How long that miss is allowed to stand depends on what it means. A link+ // nobody publishes here is a probe, and its 404 is worth caching for the+ // full window. A link whose publisher IS one of our feeds is a card we+ // almost certainly served, so the miss is an unconfirmed lookup (that feed+ // down, or its refresh still in flight) rather than a verdict: cache it+ // briefly, or one cold instance pins a console 404 on every reader of the+ // story for the next ten minutes.+ const ours = Boolean(sourceKeyForLink(link));return json(res, 404,{ error: 'unknown_article', error_description: 'not a current article from the news feed' },- { 'cache-control': 'public, max-age=300, s-maxage=600' },+ { 'cache-control': ours ? 'public, max-age=30, s-maxage=30' : 'public, max-age=300, s-maxage=600' },);}diff --git a/data/changelog.json b/data/changelog.jsonindex fa34f9f9d..32a2bfb88 100644--- a/data/changelog.json+++ b/data/changelog.json@@ -1,6 +1,15 @@{"$comment": "Curated changelog entries for three.ws, the editorial layer of the public changelog. New PAGE launches are tracked automatically via the `added` field in data/pages.json; this file is for everything else holders care about: improvements, fixes, SDK releases, trading/payments capabilities, security work. scripts/build-page-index.mjs merges both sources into CHANGELOG.md, public/changelog.json, and public/changelog.xml. Newest first. Allowed tags: feature, improvement, fix, sdk, infra, docs, security. `link` is optional and must be a live three.ws path.","entries": [+ {+ "date": "2026-09-09",+ "title": "News cards stop losing their preview picture to a cold cache",+ "summary": "About a fifth of the crypto-news feed ships text-only, so those cards start as a source tile and upgrade in place once the publisher's own preview image is found. That lookup searched all 197 publisher feeds at once and gave up after 2.5 seconds, which on a freshly started server dropped whichever feed had not answered yet, so an article the feed had just served came back as unknown. The reader kept its tile, but the failed lookup was recorded as a public answer for the next ten minutes, so every visitor to /markets and /markets/news got the same dead result and a 404 in their browser console. The lookup now asks the one publisher that could hold the article first and waits for it, and a result that could not be confirmed is held for 30 seconds instead of ten minutes.",+ "tags": [+ "fix"+ ],+ "link": "/markets/news"+ },{"date": "2026-09-09","title": "The trading arena now says who just passed whom",diff --git a/prompts/finish/900-swarm-100-sweep-console.md b/prompts/finish/900-swarm-100-sweep-console.mddeleted file mode 100644index 28f65cdad..000000000--- a/prompts/finish/900-swarm-100-sweep-console.md+++ /dev/null@@ -1,210 +0,0 @@-# Sweep: Console audit clean--How to run: paste this file's repo path into a fresh Claude Code chat in this-repository and say "run this work order". This file is fully self-contained:-it depends on no other prompt file anywhere. If sibling swarm-100 files in-prompts/finish/ are gone, that work is done; if present, ignore them.-Every claim below rots; step 0 re-measures, and what you measure wins.--## Operating clause (binding)--- Read CLAUDE.md first. Its rules override everything, including this file.-- Finish 100% in this session. Never end the turn with a question, an option- list, or an unexecuted plan. A judgment call goes in one line of the final- report; it never becomes a question that halts work.-- The only permitted stops are the CLAUDE.md stop-and-ask gates: spending real- funds or any irreversible on-chain write, git push or a production deploy,- committing content that references a crypto project other than $THREE, and- destroying unrecoverable data.-- No mocks, no fake data, no placeholder stubs, no unfinished-work markers, no- commented-out code. Real APIs and real integrations only.-- The em-dash and en-dash characters are banned in everything you write.-- Concurrent agents share this worktree: stage explicit paths only (never a- bare add-everything), and commit finished work promptly.-- Before committing, run: npm run check:rules -- --paths <files you touched>.- It must exit 0.--## State on 2026-09-04 (measured, not claimed)--A full sweep ran that day with the page-side fixes below already in place. The-desktop pass measured **770 of 780 routes clean**. Every one of the ten-remaining routes was traced to a named cause, and **none of them is open page-code**: each is either already fixed on `main` and waiting for a production-deploy, or a page that is correct on the origin it actually runs on.--Fixed and committed that day (page code, root causes):--| Route | Cause | Fix |-|---|---|---|-| `/launches` | The shared coin card painted token art straight from a public gateway that now answers 429 behind a sunset notice. One paint logged 89 blocked requests. | `src/pump/coin-status-card.js` routes art through `/api/img` (gateway retry, painted-size resize, deterministic placeholder). `src/launches.js` does the same for agent thumbnails. Commit `795becc00`. |-| `/creations` | Gallery models were read straight from the asset bucket, whose CORS policy allowlists the production origin by name, so model-viewer died with "Failed to fetch" on every other origin. | New `proxiedModelURL` in `src/ipfs.js` routes them through `/api/glb`; `src/model-diff.js` dropped its private copy of the rule; covered by `tests/ipfs-image-url-safety.test.js`. Commit `795becc00`. |-| `/ibm/x402-demo`, `/ibm/hello.live` | Both pages loaded their own `x402.js` by absolute URL, so the browser refused it on any origin but production and the paid demos never armed. | They load `/x402.js` now; the copyable snippet still shows the absolute URL an embedder needs. `scripts/build-ibm-shell.mjs` absolutizes root-relative asset URLs when baking the publish-once page, which also repaired its language switcher. Commits `b1f6db3be`, `6cf18771d`. |--Waiting on the production deploy, not on code (verified by running this repo's-own API server and re-requesting each endpoint, see step 0):--| Route | What the sweep sees | Where the fix already is |-|---|---|---|-| `/fees` | 7 chain-icon 404s from the upstream icon host | `cc5dbb211` repairs the URLs and falls back to a neutral disc |-| `/markets`, `/markets/news` | `/api/news/image` 404s | `f32c2987f` answers 204 for an article that simply has no picture |-| `/oracle-lab` | `/api/oracle/model` 500 | `272b659fc`, and the endpoint answers 200 against this tree |-| `/smart-home`, `/smart-home/plan`, `/smart-home/satellite`, `/smart-home/privacy` | `/api/home` 404 | `e6a32da61`; the handler exists here and answers 401 signed out, as designed |--`/ibm/hello` is the one route that is correct as it stands: it is the-publish-once page IBM hosts on its own domain, so it deliberately fetches-`https://three.ws/ibm/hello.live` and its assets by absolute URL. On a localhost-sweep those reads are cross-origin and refused; on the origin the page is-actually served from they are same-origin. Do not "fix" it by making those-relative, which is what breaks the IBM-hosted copy.--Four routes carried warnings rather than errors. Three are closed; the fourth is-a production configuration gap that no page edit can close:--| Route | Warning | Disposition |-|---|---|---|-| `/play/war` | Two assets "preloaded but not used" | **Fixed.** `src/play/war.js` returns early with "No battle to join" when the link carries no pairing, so a static `<link rel=preload>` in the head downloaded a manifest and an avatar the page never read. `pages/play/war.html` now injects the two preloads from the head only when `match`, `ticket` and `coin` are all present, which keeps the head start on the real path and emits nothing on the dead one. `/play/arena` keeps its static pair because it always loads both, which is why it never warned. |-| `/create/selfie` | `gl_context.cc:1118] OpenGL error checking is disabled` | **Filtered.** MediaPipe's native logger, glog-formatted, written by the C++ library with no JS frame of ours in it and no verbosity control on the JS API. Added to `scripts/lib/console-noise.mjs` beside the other headless-GL driver lines. |-| `/avatar-sdk` | `RGBELoader has been deprecated. Please use HDRLoader instead.` | **Intentional, documented.** `avatar-sdk/src/viewer.js` explains it: the SDK's peer range is `three >= 0.150.0`, `HDRLoader.js` does not exist before r180, and a bundler resolves the literal dynamic import statically, so renaming trades one cosmetic console line on new `three` for a hard "module not found" build failure for every consumer on older `three`. Revisit when the peer floor moves to `>= 0.180.0`. |-| `/clash` | `clash: CoinCommunities unconfigured, polling stopped` | **Not a code defect: one missing credential.** `CC_API_KEY` is absent from `.env`, `.env.local` and the `three-ws-api` service (`node scripts/read-service-env.mjs '^CC_API_KEY$' --names` finds no match), and production's `/api/clash/state` answers `503 cc_unconfigured` for the same reason. The page is fully wired behind the var and degrades as designed: one request per page view, poll cancelled, the designed unavailable state on both tabs. The warning names a real operational gap and stays. Supplying `CC_API_KEY` is the fix, and it is the owner's. |--## Second pass, 2026-09-04 later the same day (re-measured against this tree)--Four of the rows above did not survive re-measurement. Each was re-checked by-running this repo's own API server and re-requesting the endpoint, and by loading-the page in a real browser, rather than by re-reading the earlier report.--| Row above | What was actually true | What changed |-|---|---|---|-| `/fees` waits on `cc5dbb211` | `cc5dbb211` is already deployed, and `/fees` still logged 404s. Repairing a URL cannot help: the icons come from a third-party CDN, and one it has retired 404s whatever URL you ask for. The browser logs that 404 before any `onerror` handler can run, so no client-side recovery keeps the console clean. | Fixed at root in `23160dc9f`. Every upstream logo on `/fees`, `/defi`, `/dex-volumes`, `/chain/:name`, `/protocol/:slug` and `/exchange/:id` now goes through `/api/img` with the new `fallback=none`, which answers `204 No Content` instead of the token-art placeholder. A `204` logs nothing and still fires `error` on the `<img>`, so each surface paints the neutral disc it already designs. Measured on `/fees`: 99 logos, all proxied, 0 broken, 1 disc, 0 failed requests. |-| `/oracle-lab` waits on `272b659fc` | `272b659fc` is deployed and `https://three.ws/api/oracle/model` answers `200`. | Row closed, nothing to do. |-| `/smart-home*` sees `/api/home` 404 | Production answers `500`, not `404`. `e6a32da61` shipped, but the handler's `services/` directory did not travel with the image. | The fix is `d668ceece`, still unshipped. The endpoint answers `401` signed out against this tree, as designed. |-| `/ibm/hello` "is correct as it stands" | It is not. `/x402.js`, `/i18n.js`, `/locales/*.json` and `/ibm/hello.live` all answered with no `access-control-allow-origin`, so on the copy IBM hosts the live update failed silently and the page froze on its baked baseline, the language switcher never mounted, and the paid demo never armed. Worse, the one-line embed `docs/x402-studio.md` recommends (`<script type="module" src="https://three.ws/x402.js">`) has therefore never worked on anybody's site: proven from a foreign origin against production, the module is CORS-refused and the payable button stays inert. | Fixed in `cbf83b2a0`: `vercel.json` grants those paths open CORS, the boot script absolutizes the live document's root-relative scripts the way the bake already did, and `src/i18n.js` derives its catalog origin from `import.meta.url`. `npm run audit:ibm-hosted` holds it (`docs/ops/ibm-hosted-page-audit.md`). The advice above still stands: do NOT make the baked page's URLs relative. |--The instruction to keep `/ibm/hello`'s absolute URLs was right; the conclusion-that the route was therefore fine was not. A page that is same-origin on three.ws-and cross-origin everywhere else needs an audit that loads it from somewhere-else, which is what `npm run audit:ibm-hosted` now does.--### Production is broken right now, and the sweep is what found it--`/monitor` failed the serial retry, which made it a real finding rather than-contention. It calls `/api/status`, which answers `500` in production and `200`-against this tree. The production log says why:-- [api] GET /api/status failed: Error [ERR_MODULE_NOT_FOUND]:- Cannot find module '/app/services/home-relay/src/token.js'- imported from /app/api/_lib/home/relay.js--That is the same cause as the `/smart-home` row: `.gcloudignore` never-re-included `services/`, so two modules the API imports are absent from the-image. It is not confined to Smart Home. Counting the last two hours of-production error logs by endpoint:--| Endpoint | 500s in 2h | What it is |-|---|---|---|-| `/api/healthz` | 38 | the health check itself |-| `/api/wk` | 20 | |-| `/api/mcp` | 14 | the MCP server every agent integration calls |-| `/api/chat` | 6 | |-| `/api/home`, `/api/home/satellite` | 9 | |-| `/api/x402-pay`, `/api/x402-facilitator/[action]`, `/api/x402/mcp-tool-catalog` | 8 | the payment path |-| `/api/status` | 4 | powers `/status` and `/monitor` |-| `/api/cron/uptime-check` | 1 | which is why `/api/status` has no probe history to serve |--Confirmed live: `/api/healthz`, `/api/mcp`, `/api/status`, `/api/x402-pay` and-`/api/wk` all answer `500`.--`d668ceece` fixes it (re-includes `services/` and adds a `check:gcloudignore`-rule so the same omission fails before a build instead of in production) and is-committed but unshipped. Production serves `c2148462e` from 2026-09-03 19:09;-revision `00413` rebuilt the same commit, so it did not help. `npm run-check:gcloudignore` passes on this tree and `npm run db:status` reports no-pending migrations, so the deploy is one owner-approved command.--**A raw parallel sweep on this box cannot be trusted, and that is fixed too.**-The first re-run reported 550 of 780 routes broken. Every route sampled out of-that list was clean when checked alone: the box was at load 100+ beside another-agent's `build:gcp`, and pages were missing their settle window. `c9deecba3`-makes `audit:console` re-run each failing route once, serially, and report that-second reading, with the report naming how many cleared that way. Before trusting-any number from this sweep, check that line.--## Step 0: re-derive the current state-- npm run audit:console--Capture the full output to the session scratchpad; do not work from an excerpt.--Then separate deploy lag from page defects before you touch any page code, or-you will spend the session chasing production's staleness. The dev server-proxies `/api/*` to https://three.ws, so an API finding measures the DEPLOYED-code, not this tree. Point the proxy at the repo's own server instead:-- node --env-file-if-exists=.env --env-file-if-exists=.env.local server/index.mjs &- DEV_API_PROXY=http://localhost:8080 npx vite --port 3211 --strictPort &- AUDIT_BASE=http://localhost:3211 npm run audit:console--A finding that clears under that run is deploy lag: record it and move on. The-reverse also holds, so judge it both ways: endpoints whose credentials live only-on the deployed service answer `not_configured` (503) locally and are fine in-production.--## Task--Run the console audit across pages. Every console error is a defect: fix it at-root in the page or module that throws. Warnings from our own code get fixed-too; third-party warnings we cannot control get documented in the report.--Fix everything found in this sweep's scope. Findings that belong to a different-surface entirely (and would take this session off its one task) go in the report-as named follow-ups instead; everything in scope gets fixed here, at root, with-no masking.--## Definition of done--- [ ] The command above exits 0 (or, for measurement-style sweeps, the report- carries the measured numbers and every committed fix).-- [ ] Every fix is a root-cause fix; no check was weakened, skipped, or- quarantined to get to green.-- [ ] npm run check:rules -- --paths <touched files> exits 0; npm test passes- if code changed.--**The one line that cannot pass without an owner:** the sweep exits 0 only once-production serves the four deploy-lag fixes above. That is the ship order-(`production-100-01-ship-readiness.md`), owner-gated, and it is the whole-remainder of this file. Re-run step 0 after the next deploy; if the four rows-clear, this order is done and the file retires.--## Never blocked--| Blocker | Resolution (act, do not ask) |-|---|---|-| Missing env var or credential | Check .env and .env.local, then the Cloud Run service env, then Secret Manager (the CLAUDE.md self-unblock playbook has the exact commands). If it truly exists nowhere, wire the code fully behind the env var, prove the wiring with a dry run, and name the single missing var in the report. |-| gcloud not on PATH | Run: export PATH="$HOME/google-cloud-sdk/bin:$PATH" |-| Dev server port 3000 busy | Another agent may be serving this repo; probe it and reuse if so. Otherwise start your own on a free port: npx vite --port 3101 |-| Playwright browser missing | npx playwright install chromium |-| A surface needs a signed-in user | Register a fresh account through the real /register flow against the real API and use it. Never mock the session. |-| A defect sits in code you did not touch | Fix it if it blocks a Definition of done line (root cause it, never mask it). Otherwise note it in the report and continue. |-| An unrelated test is red | Same rule. Never pipe npm test through tail; it masks exit codes. |-| `ENOSPC` mid-run, or a build dying with exit 144 | The shared disk is full. `npm run clean:worktrees` (add `--apply`), and never delete a worktree holding uncommitted work. The sweep writes nothing large, but Vite's optimizer cache does. |--## Close out (required)--1. Verify every Definition of done line with the actual command output in- front of you. Never claim a line you did not verify.-2. Commit with explicit paths and a subject that describes the diff (house- style: type(scope): what changed and why a reader cares).-3. Delete this prompt file in that same commit:-- git rm prompts/finish/900-swarm-100-sweep-console.md-- The shrinking directory is this campaign's only progress ledger; there is- no progress log to update.-4. Final report: what step 0 measured, what changed (file list), evidence per- Definition of done line, and any one-line judgment calls. No trailing- questions, no unexecuted plans.--If a line genuinely cannot pass inside this session (an external party must-respond, or an owner-gated action is the final step), finish everything else,-leave this file in place, and state exactly which line remains and who owns-it. Never delete this file on a partial.diff --git a/tests/news-image-resolver.test.js b/tests/news-image-resolver.test.jsindex eb694ffa3..79bfa5e62 100644--- a/tests/news-image-resolver.test.js+++ b/tests/news-image-resolver.test.js@@ -46,6 +46,11 @@ vi.mock('../api/_lib/fetch-model.js', () => ({ fetchModel: vi.fn(async () => ({const { default: handler } = await import('../api/news/image.js');+// Read a real publisher host out of the registry rather than naming one here,+// so this stays true when a feed is added, retired or re-pointed.+const { NEWS_SOURCES } = await import('../api/_lib/news-sources.js');+const ourPublisherHost = new URL(NEWS_SOURCES.coindesk.url).hostname;+function makeRes() {return {statusCode: 200,@@ -89,6 +94,23 @@ describe('the preview-image resolver separates "no picture" from "no such articlawait handler(req('https://not-ours.example/x'), res);expect(res._json.status).toBe(404);expect(res._json.body.error).toBe('unknown_article');+ // Nobody publishes that host here, so the miss is a verdict and caching it+ // for the full window is the point: an open-resolver probe costs one lookup.+ expect(res._json.headers['cache-control']).toMatch(/max-age=300/);+ });++ it('caches a miss on one of our own publishers only briefly', async () => {+ // A link whose host IS a registered feed is a card we very likely served,+ // so a miss means the lookup could not confirm it (that feed down, or its+ // refresh still in flight on this instance), not that the article is fake.+ // The long window would pin the resulting console 404 on every reader of+ // the story until it expired, which is the bug this guards.+ findArticle.mockResolvedValue(null);+ const res = makeRes();+ await handler(req(`https://${ourPublisherHost}/some-story`), res);+ expect(res._json.status).toBe(404);+ expect(res._json.headers['cache-control']).toMatch(/max-age=30\b/);+ expect(res._json.headers['cache-control']).not.toMatch(/max-age=300/);});it('redirects a known image to the same-origin proxy, never to the publisher', async () => {diff --git a/tests/news-sources.test.js b/tests/news-sources.test.jsindex fbb97bbdf..d27d04930 100644--- a/tests/news-sources.test.js+++ b/tests/news-sources.test.js@@ -5,8 +5,15 @@import { describe, it, expect } from 'vitest';-const { NEWS_SOURCES, NEWS_CATEGORIES, NEWS_LANGUAGES, sourcesForCategory, sourcesForLanguage, sourcePriority } =- await import('../api/_lib/news-sources.js');+const {+ NEWS_SOURCES,+ NEWS_CATEGORIES,+ NEWS_LANGUAGES,+ sourcesForCategory,+ sourcesForLanguage,+ sourcePriority,+ sourceKeyForLink,+} = await import('../api/_lib/news-sources.js');const entries = Object.entries(NEWS_SOURCES);@@ -232,3 +239,39 @@ describe('sourcePriority', () => {expect(sourcePriority('no_such_source')).toBe(3);});});+++// findArticle uses this to refresh the one feed that could hold a link instead+// of fanning out over the whole registry and truncating at a short deadline, so+// a wrong answer here turns a live news card into a cacheable 404.+describe('sourceKeyForLink', () => {+ it('maps an article URL back to the feed that publishes it', () => {+ for (const [key, src] of entries.slice(0, 40)) {+ const host = new URL(src.url).hostname;+ const resolved = sourceKeyForLink(`https://${host}/some-article`);+ // A host shared by two feeds resolves to whichever was registered first,+ // which is correct for this purpose: both carry the same articles.+ expect(resolved, `${key}`).toBeTruthy();+ expect(new URL(NEWS_SOURCES[resolved].url).hostname, `${key}`).toBe(host);+ }+ });++ it('resolves the www host of a feed served from the bare domain', () => {+ const bare = entries.find(([, s]) => !new URL(s.url).hostname.startsWith('www.'));+ const host = new URL(bare[1].url).hostname;+ expect(sourceKeyForLink(`https://www.${host}/story`)).toBe(sourceKeyForLink(`https://${host}/story`));+ });++ it('returns null for a host nobody here publishes, and for a non-URL', () => {+ expect(sourceKeyForLink('https://not-a-registered-publisher.example/x')).toBeNull();+ expect(sourceKeyForLink('')).toBeNull();+ expect(sourceKeyForLink('not a url')).toBeNull();+ expect(sourceKeyForLink(null)).toBeNull();+ });++ it('never resolves a bare public suffix, which would map every site to one feed', () => {+ for (const tld of ['https://com/x', 'https://io/x', 'https://net/x']) {+ expect(sourceKeyForLink(tld)).toBeNull();+ }+ });+});