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.

fix(audit-upstreams): register the guard, and stop its own file filter hiding 42 call sites

nirholasd89ae3746637
diff --git a/data/guards.json b/data/guards.json
index 1a38e042d..f3ba1b938 100644
--- a/data/guards.json
+++ b/data/guards.json
@@ -1048,6 +1048,27 @@
},
"expect": "app icon"
}
+ },
+ {
+ "id": "audit-upstreams",
+ "script": "scripts/audit-upstreams.mjs",
+ "npm": "audit:upstreams",
+ "title": "Upstream resilience ratchet",
+ "protects": "No new call to a third-party service can be added without a deadline, and no existing one can quietly get weaker.",
+ "why": "Adding a fallback is easy; knowing it made things better is not. An AST pass grades every outbound call site on five protections (deadline, retry, failover, last-good, breaker) and compares it against data/upstream-baseline.json. A ratchet rather than a threshold: a threshold gets rounded up until it means nothing, while a baseline lets the existing tail be paid down at its own pace and makes adding to it by accident impossible. Improving a call site lowers the baseline automatically; raising it back needs an explicit --accept, which is one reviewable line in a diff. It measures what check:fetch-timeouts cannot: that guard enforces the deadline floor, this one measures everything above it.",
+ "stages": [
+ "gate"
+ ],
+ "needs": "none",
+ "proof": {
+ "summary": "A new outbound call to a third-party host with no deadline behind it.",
+ "violation": {
+ "write": {
+ "api/_lib/guard-proof-upstream.js": "// Guard proof fixture: an unbounded third-party call.\nexport async function probeStatus() {\n\treturn fetch('https://guard-proof.example.com/status');\n}\n"
+ }
+ },
+ "expect": "guard-proof.example.com"
+ }
}
],
"exempt": [
diff --git a/data/upstream-baseline.json b/data/upstream-baseline.json
index bd5164334..b077861af 100644
--- a/data/upstream-baseline.json
+++ b/data/upstream-baseline.json
@@ -1,20 +1,20 @@
{
"generated": "scripts/audit-upstreams.mjs",
"summary": {
- "total": 183,
+ "total": 224,
"grades": {
"A": 0,
- "B": 46,
- "C": 84,
- "D": 53,
+ "B": 54,
+ "C": 91,
+ "D": 79,
"F": 0
},
"protections": {
- "deadline": 183,
- "retry": 88,
- "failover": 42,
- "lastGood": 4,
- "breaker": 79
+ "deadline": 224,
+ "retry": 96,
+ "failover": 49,
+ "lastGood": 5,
+ "breaker": 87
}
},
"sites": {
@@ -145,7 +145,6 @@
"src/home-bento.js::lite-api.jup.ag::fetch": "D",
"src/kol/kolscan-live.js::kolscan.io::fetch": "D",
"src/pinning/pinata.js::api.pinata.cloud::fetch": "C",
- "src/privy-login.js::auth.privy.io::fetch": "D",
"src/shared/leaflet-loader.js::esm.sh::loadModule": "B",
"src/shared/leaflet-loader.js::nominatim.openstreetmap.org::fetchFirstOrNull": "B",
"src/shared/leaflet-loader.js::photon.komoot.io::fetchFirstOrNull": "B",
@@ -162,6 +161,39 @@
"src/swap-jupiter.js::lite-api.jup.ag::fetch": "D",
"workers/agent-sniper/intel/learn.js::frontend-api-v3.pump.fun::fetch": "D",
"workers/agent-sniper/llm-judge.js::openrouter.ai::fetch": "D",
- "workers/okx-chat-bot/state.js::storage.googleapis.com::fetch": "D"
+ "workers/okx-chat-bot/state.js::storage.googleapis.com::fetch": "D",
+ "api/_lib/ai-image-lanes.js::ai.api.nvidia.com::fetch": "D",
+ "api/_lib/ai-image-lanes.js::api.replicate.com::fetch": "D",
+ "api/_lib/ai-image-lanes.js::huggingface.co::fetch": "D",
+ "api/_lib/ai-image-lanes.js::image.pollinations.ai::fetch": "D",
+ "api/_lib/alert-delivery.js::api.telegram.org::fetchUpstream": "C",
+ "api/_lib/bake-garments.js::storage.googleapis.com::fetchUpstream": "C",
+ "api/_lib/coin-fallbacks.js::coins.llama.fi::fetchFirstOrNull": "B",
+ "api/_lib/coin-fallbacks.js::api.coinpaprika.com::paprikaGet": "D",
+ "api/_lib/coin-fallbacks.js::coins.llama.fi::fetchFirst": "B",
+ "api/_lib/commit-feed-push.js::api.telegram.org::fetchUpstream": "C",
+ "api/_lib/market-fallbacks.js::api.coingecko.com::fetchFirst": "B",
+ "api/_lib/market-fallbacks.js::coins.llama.fi::fetchFirst": "B",
+ "api/_lib/market-fallbacks.js::api.coinpaprika.com::paprikaGet": "D",
+ "api/_lib/market-fallbacks.js::api.coinlore.com::fetchFirst": "B",
+ "api/_lib/news-archive-store.js::storage.googleapis.com::fetchUpstream": "B",
+ "api/_lib/pump-claims-push.js::api.telegram.org::fetchUpstream": "C",
+ "api/_lib/pump-curve-view.js::lite-api.jup.ag::fetchUpstreamJson": "C",
+ "api/_lib/treasury-autopilot.js::lite-api.jup.ag::fetchUpstream": "C",
+ "api/_lib/trust/subject-reputation.js::api.dexscreener.com::fetch": "D",
+ "api/_lib/voice-providers.js::api.openai.com::fetch": "D",
+ "api/_lib/voice-providers.js::api.elevenlabs.io::fetch": "D",
+ "api/_lib/wallet-activity.js::api.etherscan.io::fetchUpstream": "C",
+ "api/_lib/x402-spending-price.js::api.coinbase.com::fetchFirst": "B",
+ "api/_mcp3d/text-to-image.js::ai.api.nvidia.com::fetch": "D",
+ "api/cron/garment-catalog-audit.js::storage.googleapis.com::fetch": "D",
+ "api/cron/news-archive-append.js::storage.googleapis.com::fetch": "D",
+ "api/cron/news-archive-append.js::api.alternative.me::fetch": "D",
+ "api/cron/x402-directory-registrar.js::402index.io::fetch": "D",
+ "api/zauth-reposcan.js::api.zauth.inc::fetch": "D",
+ "src/agent-skills-pumpfun-compose.js::pump-fun-sdk.modelcontextprotocol.name::fetch": "D",
+ "src/erc8004/agent-registry.js::api.pinata.cloud::fetch": "D",
+ "src/shared/wallet-networth.js::lite-api.jup.ag::fetch": "D",
+ "src/social/x-post-impact.js::publish.twitter.com::fetch": "D"
}
}
diff --git a/docs/guards.md b/docs/guards.md
index e14da0800..a078185d2 100644
--- a/docs/guards.md
+++ b/docs/guards.md
@@ -115,6 +115,7 @@ Run `npm run audit:guards` to print the current count and per-stage breakdown. T
| Guard | Command | Protects |
|---|---|---|
| Documentation integrity | `npm run audit:docs` | No dead relative link, no command naming a missing script, no package without a README. |
+| Upstream resilience ratchet | `npm run audit:upstreams` | No new call to a third-party service without a deadline, and no existing one quietly getting weaker. |
| Tutorial reachability | `npm run check:tutorials` | Every tutorial appears in the library manifest, has its markdown on disk, and is registered in `data/pages.json`. |
| Runnable doc samples | `npm run check:runnable-docs` | Every sample a reader can press Run on still returns what the doc says it returns. |
| Doc figures | `npm run check:doc-media` | Every figure a doc points at was really captured, still matches its recipe, and carries alt text. |
diff --git a/docs/resilience.md b/docs/resilience.md
index 04896c43a..a52e60846 100644
--- a/docs/resilience.md
+++ b/docs/resilience.md
@@ -20,11 +20,11 @@ no other protection ever gets a turn.
## Totals
-183 outbound call sites across 72 upstreams.
+224 outbound call sites across 79 upstreams.
| A | B | C | D | F |
|---|---|---|---|---|
-| 0 | 46 | 84 | 53 | 0 |
+| 0 | 54 | 91 | 79 | 0 |
## Weakest upstreams
@@ -33,58 +33,63 @@ the list to work down, worst first.
| Upstream | Call sites | Worst grade |
|---|---|---|
-| `api.telegram.org` | 10 | D |
-| `lite-api.jup.ag` | 9 | D |
-| `api.dexscreener.com` | 8 | D |
+| `api.telegram.org` | 13 | D |
+| `lite-api.jup.ag` | 12 | D |
+| `api.dexscreener.com` | 9 | D |
+| `storage.googleapis.com` | 8 | D |
+| `api.coinpaprika.com` | 8 | D |
+| `api.coingecko.com` | 8 | D |
| `api.github.com` | 7 | D |
-| `api.coingecko.com` | 6 | D |
| `frontend-api-v3.pump.fun` | 6 | D |
+| `api.replicate.com` | 5 | D |
+| `api.elevenlabs.io` | 5 | D |
+| `api.pinata.cloud` | 5 | D |
| `openrouter.ai` | 5 | D |
| `api.geckoterminal.com` | 5 | D |
-| `api.elevenlabs.io` | 4 | D |
-| `api.pinata.cloud` | 4 | D |
+| `ai.api.nvidia.com` | 4 | D |
| `api.web3.storage` | 4 | D |
-| `api.replicate.com` | 4 | D |
+| `api.alternative.me` | 4 | D |
+| `api.openai.com` | 3 | D |
| `integrate.api.nvidia.com` | 2 | D |
-| `api.openai.com` | 2 | D |
-| `auth.privy.io` | 2 | D |
-| `ai.api.nvidia.com` | 2 | D |
| `api.sketchfab.com` | 2 | D |
-| `storage.googleapis.com` | 2 | D |
| `api.nvcf.nvidia.com` | 2 | D |
| `sns-api.bonfida.com__expr__` | 2 | D |
| `api.anthropic.com` | 2 | D |
| `raw.githubusercontent.com` | 2 | D |
-| `api.developer.coinbase.com` | 1 | D |
-| `bigquery.googleapis.com` | 1 | D |
-| `api.indexnow.org` | 1 | D |
+| `publish.twitter.com` | 2 | D |
+| `api.zauth.inc` | 2 | D |
## Every upstream
| Upstream | Call sites | Worst grade | A | B | C | D | F |
|---|---|---|---|---|---|---|---|
-| `api.telegram.org` | 10 | D | 0 | 0 | 7 | 3 | 0 |
-| `lite-api.jup.ag` | 9 | D | 0 | 5 | 0 | 4 | 0 |
-| `api.dexscreener.com` | 8 | D | 0 | 4 | 2 | 2 | 0 |
+| `api.telegram.org` | 13 | D | 0 | 0 | 10 | 3 | 0 |
+| `lite-api.jup.ag` | 12 | D | 0 | 5 | 2 | 5 | 0 |
+| `api.dexscreener.com` | 9 | D | 0 | 4 | 2 | 3 | 0 |
+| `storage.googleapis.com` | 8 | D | 0 | 1 | 2 | 5 | 0 |
+| `api.coinpaprika.com` | 8 | D | 0 | 0 | 0 | 8 | 0 |
+| `api.coingecko.com` | 8 | D | 0 | 7 | 0 | 1 | 0 |
| `api.github.com` | 7 | D | 0 | 0 | 5 | 2 | 0 |
-| `api.coingecko.com` | 6 | D | 0 | 5 | 0 | 1 | 0 |
| `frontend-api-v3.pump.fun` | 6 | D | 0 | 0 | 5 | 1 | 0 |
+| `api.replicate.com` | 5 | D | 0 | 0 | 2 | 3 | 0 |
+| `api.elevenlabs.io` | 5 | D | 0 | 0 | 2 | 3 | 0 |
+| `api.pinata.cloud` | 5 | D | 0 | 0 | 3 | 2 | 0 |
| `openrouter.ai` | 5 | D | 0 | 0 | 0 | 5 | 0 |
| `api.geckoterminal.com` | 5 | D | 0 | 3 | 0 | 2 | 0 |
-| `api.elevenlabs.io` | 4 | D | 0 | 0 | 2 | 2 | 0 |
-| `api.pinata.cloud` | 4 | D | 0 | 0 | 3 | 1 | 0 |
+| `ai.api.nvidia.com` | 4 | D | 0 | 0 | 0 | 4 | 0 |
| `api.web3.storage` | 4 | D | 0 | 0 | 3 | 1 | 0 |
-| `api.replicate.com` | 4 | D | 0 | 0 | 2 | 2 | 0 |
+| `api.alternative.me` | 4 | D | 0 | 0 | 3 | 1 | 0 |
+| `api.openai.com` | 3 | D | 0 | 0 | 0 | 3 | 0 |
| `integrate.api.nvidia.com` | 2 | D | 0 | 0 | 0 | 2 | 0 |
-| `api.openai.com` | 2 | D | 0 | 0 | 0 | 2 | 0 |
-| `auth.privy.io` | 2 | D | 0 | 0 | 1 | 1 | 0 |
-| `ai.api.nvidia.com` | 2 | D | 0 | 0 | 0 | 2 | 0 |
| `api.sketchfab.com` | 2 | D | 0 | 0 | 0 | 2 | 0 |
-| `storage.googleapis.com` | 2 | D | 0 | 0 | 1 | 1 | 0 |
| `api.nvcf.nvidia.com` | 2 | D | 0 | 0 | 0 | 2 | 0 |
| `sns-api.bonfida.com__expr__` | 2 | D | 0 | 0 | 1 | 1 | 0 |
| `api.anthropic.com` | 2 | D | 0 | 0 | 1 | 1 | 0 |
| `raw.githubusercontent.com` | 2 | D | 0 | 1 | 0 | 1 | 0 |
+| `publish.twitter.com` | 2 | D | 0 | 0 | 0 | 2 | 0 |
+| `api.zauth.inc` | 2 | D | 0 | 0 | 0 | 2 | 0 |
+| `huggingface.co` | 1 | D | 0 | 0 | 0 | 1 | 0 |
+| `image.pollinations.ai` | 1 | D | 0 | 0 | 0 | 1 | 0 |
| `api.developer.coinbase.com` | 1 | D | 0 | 0 | 0 | 1 | 0 |
| `bigquery.googleapis.com` | 1 | D | 0 | 0 | 0 | 1 | 0 |
| `api.indexnow.org` | 1 | D | 0 | 0 | 0 | 1 | 0 |
@@ -92,17 +97,16 @@ the list to work down, worst first.
| `speech.platform.bing.com` | 1 | D | 0 | 0 | 0 | 1 | 0 |
| `api.upstash.com` | 1 | D | 0 | 0 | 0 | 1 | 0 |
| `qstash.upstash.io` | 1 | D | 0 | 0 | 0 | 1 | 0 |
+| `402index.io` | 1 | D | 0 | 0 | 0 | 1 | 0 |
| `api.resend.com` | 1 | D | 0 | 0 | 0 | 1 | 0 |
-| `publish.twitter.com` | 1 | D | 0 | 0 | 0 | 1 | 0 |
| `api.exchange.coinbase.com` | 1 | D | 0 | 0 | 0 | 1 | 0 |
-| `api.coinpaprika.com` | 1 | D | 0 | 0 | 0 | 1 | 0 |
+| `pump-fun-sdk.modelcontextprotocol.name` | 1 | D | 0 | 0 | 0 | 1 | 0 |
| `kolscan.io` | 1 | D | 0 | 0 | 0 | 1 | 0 |
| `api.twitter.com` | 8 | C | 0 | 0 | 8 | 0 | 0 |
| `api.llama.fi` | 5 | C | 0 | 0 | 5 | 0 | 0 |
| `api.x.com` | 4 | C | 0 | 0 | 4 | 0 | 0 |
| `api.hyper3d.com` | 3 | C | 0 | 0 | 3 | 0 | 0 |
| `api.tripo3d.ai` | 3 | C | 0 | 0 | 3 | 0 | 0 |
-| `api.alternative.me` | 3 | C | 0 | 0 | 3 | 0 | 0 |
| `yields.llama.fi` | 3 | C | 0 | 0 | 3 | 0 | 0 |
| `api.meshy.ai__expr__` | 2 | C | 0 | 0 | 2 | 0 | 0 |
| `stablecoins.llama.fi` | 2 | C | 0 | 0 | 2 | 0 | 0 |
@@ -113,9 +117,11 @@ the list to work down, worst first.
| `oauth2.googleapis.com` | 1 | C | 0 | 0 | 1 | 0 | 0 |
| `api.github.com__expr__` | 1 | C | 0 | 0 | 1 | 0 | 0 |
| `sns-api.bonfida.com` | 1 | C | 0 | 0 | 1 | 0 | 0 |
+| `auth.privy.io` | 1 | C | 0 | 0 | 1 | 0 | 0 |
| `livestream-api.pump.fun__expr__` | 1 | C | 0 | 0 | 1 | 0 | 0 |
| `pump.fun` | 1 | C | 0 | 0 | 1 | 0 | 0 |
| `api.rugcheck.xyz` | 1 | C | 0 | 0 | 1 | 0 | 0 |
+| `api.etherscan.io` | 1 | C | 0 | 0 | 1 | 0 | 0 |
| `api.stability.ai` | 1 | C | 0 | 0 | 1 | 0 | 0 |
| `github.com` | 1 | C | 0 | 0 | 1 | 0 | 0 |
| `pro-api.coinmarketcap.com` | 1 | C | 0 | 0 | 1 | 0 | 0 |
@@ -124,13 +130,14 @@ the list to work down, worst first.
| `api.helius.xyz` | 1 | C | 0 | 0 | 1 | 0 | 0 |
| `api.llama.fi__expr__` | 1 | C | 0 | 0 | 1 | 0 | 0 |
| `www.deribit.com` | 1 | C | 0 | 0 | 1 | 0 | 0 |
-| `coins.llama.fi` | 6 | B | 0 | 6 | 0 | 0 | 0 |
+| `coins.llama.fi` | 9 | B | 0 | 9 | 0 | 0 | 0 |
+| `api.coinbase.com` | 5 | B | 0 | 5 | 0 | 0 | 0 |
| `esm.sh` | 5 | B | 0 | 5 | 0 | 0 | 0 |
| `api.kraken.com` | 4 | B | 0 | 4 | 0 | 0 | 0 |
-| `api.coinbase.com` | 4 | B | 0 | 4 | 0 | 0 | 0 |
| `nominatim.openstreetmap.org` | 2 | B | 0 | 2 | 0 | 0 | 0 |
| `photon.komoot.io` | 2 | B | 0 | 2 | 0 | 0 | 0 |
| `api.hyperliquid.xyz` | 1 | B | 0 | 1 | 0 | 0 | 0 |
+| `api.coinlore.com` | 1 | B | 0 | 1 | 0 | 0 | 0 |
| `api.diadata.org` | 1 | B | 0 | 1 | 0 | 0 | 0 |
| `api-pub.bitfinex.com` | 1 | B | 0 | 1 | 0 | 0 | 0 |
| `api.bigdatacloud.net` | 1 | B | 0 | 1 | 0 | 0 | 0 |
diff --git a/public/guards.json b/public/guards.json
index 1a38e042d..f3ba1b938 100644
--- a/public/guards.json
+++ b/public/guards.json
@@ -1048,6 +1048,27 @@
},
"expect": "app icon"
}
+ },
+ {
+ "id": "audit-upstreams",
+ "script": "scripts/audit-upstreams.mjs",
+ "npm": "audit:upstreams",
+ "title": "Upstream resilience ratchet",
+ "protects": "No new call to a third-party service can be added without a deadline, and no existing one can quietly get weaker.",
+ "why": "Adding a fallback is easy; knowing it made things better is not. An AST pass grades every outbound call site on five protections (deadline, retry, failover, last-good, breaker) and compares it against data/upstream-baseline.json. A ratchet rather than a threshold: a threshold gets rounded up until it means nothing, while a baseline lets the existing tail be paid down at its own pace and makes adding to it by accident impossible. Improving a call site lowers the baseline automatically; raising it back needs an explicit --accept, which is one reviewable line in a diff. It measures what check:fetch-timeouts cannot: that guard enforces the deadline floor, this one measures everything above it.",
+ "stages": [
+ "gate"
+ ],
+ "needs": "none",
+ "proof": {
+ "summary": "A new outbound call to a third-party host with no deadline behind it.",
+ "violation": {
+ "write": {
+ "api/_lib/guard-proof-upstream.js": "// Guard proof fixture: an unbounded third-party call.\nexport async function probeStatus() {\n\treturn fetch('https://guard-proof.example.com/status');\n}\n"
+ }
+ },
+ "expect": "guard-proof.example.com"
+ }
}
],
"exempt": [
diff --git a/scripts/audit-upstreams.mjs b/scripts/audit-upstreams.mjs
index bbfdf06b2..28db94a70 100644
--- a/scripts/audit-upstreams.mjs
+++ b/scripts/audit-upstreams.mjs
@@ -38,8 +38,16 @@ const accept = args.has('--accept');
const SCAN_DIRS = ['api', 'src', 'server', 'workers', 'mcp-server/src', 'avatar-sdk/src', 'public'];
// Built output is not source: grading a bundled asset reports findings nobody
// can act on, because the fix belongs in the module it was compiled from.
+//
+// The content-hash suffix has to be matched precisely. An earlier version of
+// this pattern was `-[A-Za-z0-9_-]{8,}\.js$`, which also matched perfectly
+// ordinary kebab-case source names (`market-fallbacks.js`,
+// `guard-proof-upstream.js`) and silently dropped them from the audit. A
+// bundler hash always carries an uppercase letter or a digit; a hand-written
+// filename in this repo is lowercase words, so requiring one of those in the
+// final segment separates them without excluding real source.
const SKIP_RE =
- /(?:^|\/)(?:node_modules|dist|dist-lib|build|coverage|\.deploy-wt|assets|vendor)(?:\/|$)|\.min\.js$|\.test\.js$|\.spec\.js$|-[A-Za-z0-9_-]{8,}\.js$/;
+ /(?:^|\/)(?:node_modules|dist|dist-lib|build|coverage|\.deploy-wt|assets|vendor)(?:\/|$)|\.min\.js$|\.test\.js$|\.spec\.js$|-[a-z0-9_-]*[A-Z0-9][A-Za-z0-9_-]{7,}\.js$/;
function sourceFiles() {
const out = [];
@@ -215,19 +223,30 @@ function main() {
if (GRADE_RANK[grade] < GRADE_RANK[was]) regressed.push({ site, grade, was });
}
- // Improvements ratchet the baseline down on their own, so the floor only
- // ever rises. Nobody has to remember to re-record a fix.
+ // Improvements ratchet the baseline down on their own, so the floor only ever
+ // rises and nobody has to remember to re-record a fix. New call sites are
+ // recorded at whatever grade they arrive with: a bounded one that goes in
+ // unrecorded could later weaken to D without tripping anything, because an
+ // unknown key is only checked against the F floor.
let improved = 0;
+ let added = 0;
+ let removed = 0;
const nextSites = { ...(baseline.sites || {}) };
for (const [key, grade] of Object.entries(index)) {
const was = nextSites[key];
- if (was === undefined || GRADE_RANK[grade] > GRADE_RANK[was]) {
- if (was !== undefined) improved += 1;
+ if (was === undefined) {
+ added += 1;
+ nextSites[key] = grade;
+ } else if (GRADE_RANK[grade] > GRADE_RANK[was]) {
+ improved += 1;
nextSites[key] = grade;
}
}
for (const key of Object.keys(nextSites)) {
- if (!(key in index)) delete nextSites[key]; // call site removed
+ if (!(key in index)) {
+ delete nextSites[key]; // call site removed
+ removed += 1;
+ }
}
console.log(
@@ -259,12 +278,16 @@ function main() {
return 1;
}
- if (improved) {
+ if (improved || added || removed) {
writeFileSync(
BASELINE,
`${JSON.stringify({ generated: 'scripts/audit-upstreams.mjs', summary, sites: nextSites }, null, '\t')}\n`,
);
- console.log(`audit:upstreams: ${improved} call site(s) improved, baseline ratcheted up`);
+ const parts = [];
+ if (improved) parts.push(`${improved} improved`);
+ if (added) parts.push(`${added} new`);
+ if (removed) parts.push(`${removed} removed`);
+ console.log(`audit:upstreams: baseline updated (${parts.join(', ')})`);
}
console.log('audit:upstreams: no regressions');
return 0;
diff --git a/tests/failover-fetch.test.js b/tests/failover-fetch.test.js
index c0ec2d1e3..0f5ee63ec 100644
--- a/tests/failover-fetch.test.js
+++ b/tests/failover-fetch.test.js
@@ -90,8 +90,15 @@ describe('fetchFirst — ordered multi-provider failover', () => {
const ctrl = new AbortController();
const a = provider({ init: { signal: ctrl.signal } });
const b = provider({ init: { signal: ctrl.signal } });
+ // Real fetch rejects straight away when handed an already-aborted signal,
+ // and only fires the listener for an abort that arrives later. The stub has
+ // to do both: fetchFirst now awaits the fault lookup before calling fetch,
+ // so a caller that aborts immediately gets here with the signal already
+ // set, and a listen-only stub would simply never settle.
global.fetch = vi.fn((url, { signal }) => new Promise((_, reject) => {
- signal.addEventListener('abort', () => reject(new DOMException('aborted', 'AbortError')));
+ const fail = () => reject(new DOMException('aborted', 'AbortError'));
+ if (signal.aborted) return fail();
+ signal.addEventListener('abort', fail, { once: true });
}));
const pending = fetchFirst([a, b]);
ctrl.abort();
@@ -107,7 +114,9 @@ describe('fetchFirst — ordered multi-provider failover', () => {
global.fetch = vi.fn((url, { signal }) => {
if (url === a.url) {
return new Promise((_, reject) => {
- signal.addEventListener('abort', () => reject(new DOMException('aborted', 'AbortError')));
+ const fail = () => reject(new DOMException('aborted', 'AbortError'));
+ if (signal.aborted) return fail();
+ signal.addEventListener('abort', fail, { once: true });
});
}
return Promise.resolve(json({ v: 'fast' }));
diff --git a/tests/src/ipfs.test.js b/tests/src/ipfs.test.js
index 94d4bc4fe..841317991 100644
--- a/tests/src/ipfs.test.js
+++ b/tests/src/ipfs.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest';
-import { isDecentralizedURI, resolveURI, normalizeGatewayURL } from '../../src/ipfs.js';
+import { isDecentralizedURI, resolveURI, normalizeGatewayURL, IPFS_GATEWAYS } from '../../src/ipfs.js';
describe('isDecentralizedURI', () => {
it('matches ipfs:// URIs', () => {
@@ -66,9 +66,13 @@ describe('resolveURI', () => {
});
it('wraps gateway index modulo', () => {
+ // Derive the wrap point from the exported list rather than hardcoding it:
+ // adding a gateway is a routine improvement and should not need this test
+ // edited to stay true.
const zero = resolveURI('ipfs://QmCID', 0);
- const three = resolveURI('ipfs://QmCID', 3);
- expect(zero).toBe(three);
+ const wrapped = resolveURI('ipfs://QmCID', IPFS_GATEWAYS.length);
+ expect(zero).toBe(wrapped);
+ expect(resolveURI('ipfs://QmCID', 1)).not.toBe(zero);
});
it('is case-insensitive on the scheme', () => {