Skip to content

fix(scripts): bound gittensor-impact-card's fetches with a request timeout#7280

Merged
loopover-orb[bot] merged 2 commits into
JSONbored:mainfrom
galuis116:fix/gittensor-impact-card-fetch-timeout-v2
Jul 19, 2026
Merged

fix(scripts): bound gittensor-impact-card's fetches with a request timeout#7280
loopover-orb[bot] merged 2 commits into
JSONbored:mainfrom
galuis116:fix/gittensor-impact-card-fetch-timeout-v2

Conversation

@galuis116

Copy link
Copy Markdown
Contributor

Summary

  • scripts/gittensor-impact-card.mjs's fetchJson (used for both the api.gittensor.io/repos/:repo/impact and .../prs calls) and the standalone gt-logo.svg fetch had no request timeout at all — unlike every other external-fetch script in this repo (scripts/check-mcp-release-due.mjs's GITHUB_REQUEST_TIMEOUT_MS, scripts/smoke-observability-metrics.mjs, src/github/client.ts's GITHUB_FETCH_TIMEOUT_MS, etc.). A hung api.gittensor.io/gittensor.io connection would block the README-card regeneration job (.github/workflows/gittensor-impact.yml) indefinitely.
  • Added a single shared GITTENSOR_IMPACT_CARD_FETCH_TIMEOUT_MS constant (10_000, exported) and passed signal: AbortSignal.timeout(...) on all three call sites (both via fetchJson, plus the extracted fetchGtLogoSvg helper for the logo fetch, which previously wasn't even wrapped in a named function).
  • Both functions now accept an injectable fetchImpl parameter (defaulting to global fetch) so they're independently unit-testable without a real network call — matching this repo's established pattern for testable fetch adapters (e.g. scripts/load-test-worker.mjs).
  • Added the CLI entry-point guard (if (import.meta.url === pathToFileURL(...).href)) every other script in this repo already has around its main() invocation (e.g. scripts/check-mcp-release-due.mjs) — this script was missing it, so simply importing the module (as the new test file needs to, to reach fetchJson/fetchGtLogoSvg) previously ran main() immediately and crashed via process.exit(1). This is a pure test-enablement fix: CLI usage (node scripts/gittensor-impact-card.mjs <owner/repo> <out-file.svg>) and output are byte-identical — confirmed by running the script directly post-change and seeing the same Usage: ... message on missing args.
  • No change to the generated SVG output shape, the script's non-error-path behavior, or any of the render/bucketWeekly/sparkline/meter pure helpers.

Scope

  • The PR title follows type(scope): short summary Conventional Commit format.
  • This PR is focused and does not mix unrelated backend, UI, MCP, docs, dependency, and deploy changes.
  • This follows CONTRIBUTING.md and does not reintroduce GitHub Pages, VitePress, site/, or CNAME.
  • I linked a currently open issue this PR resolves.

Closes #7231

Validation

  • git diff --check
  • npm run actionlint
  • node --check scripts/gittensor-impact-card.mjs — clean.
  • npm run typecheck — the whole-repo tsc --noEmit reliably OOMs on this shared, memory-constrained sandbox regardless of diff size (reproduced on a clean checkout too, documented pattern from prior PRs in this repo's history). A first push of this PR was closed by CI on a real tsc error (fetchImpl.mock.calls[0] destructured directly, but this project's noUncheckedIndexedAccess types an array index as T | undefined, which a destructuring assignment can't accept without a non-null assertion) — my first scoped tsc verification omitted that compiler option, so it missed the error CI's full-flag run caught. Root-caused and fixed (fetchImpl.mock.calls[0]!), then re-verified via a standalone scoped tsc --noEmit invocation using this project's exact tsconfig.json compiler options this time (--strict --exactOptionalPropertyTypes --noUncheckedIndexedAccess --noImplicitOverride --noFallthroughCasesInSwitch --forceConsistentCasingInFileNames), small enough to avoid the OOM — clean. The new .d.mts companion deliberately types fetchImpl as a narrow custom ImpactCardFetch shape rather than typeof fetch, since the latter (in this repo's Cloudflare-Workers-typed environment) is overloaded in a way a plainly-typed vi.fn() mock can't satisfy — the same pitfall a previous PR in this repo (feat(scripts): add load-testing tooling for the Worker's key endpoints #7184) hit and fixed the same way.
  • npx vitest run test/unit/gittensor-impact-card-script.test.ts — 7/7 passing: success path, non-2xx throw, the AbortSignal is passed on every request, a genuinely-hanging fetchImpl still resolves via the configured timeout (verified by stubbing AbortSignal.timeout itself rather than waiting out a real 10s, since Node's AbortSignal.timeout schedules an internal timer vi.useFakeTimers() doesn't intercept), the logo fetch's body-text return, and the documented default constant value.
  • scripts/** is in codecov.yml's ignore list (confirmed — matches the issue's own note), so this PR carries no Codecov patch-coverage obligation; the new dedicated test suite is the local coverage proxy.
  • npm run test:workers / npm run build:mcp / npm run test:mcp-pack / npm run ui:openapi:check (not applicable — this PR only touches one standalone script + its test + its .d.mts; no Worker route, MCP, UI, or OpenAPI surface changed)
  • npm audit --audit-level=moderate (no dependency changes)

If any required check was skipped, explain why:

  • The whole-repo npm run typecheck OOMs on this specific sandbox under current memory pressure regardless of diff size; a scoped tsc --noEmit against the new test file (with the same strict flags) is the local proxy, and CI's isolated runner performs the real whole-repo tsc --noEmit.

Safety

  • No secrets, wallet details, hotkeys, coldkeys, user PATs, private keys, raw trust scores, private rankings, or private maintainer evidence are exposed.
  • Public GitHub text stays sanitized, low-noise, and does not imply compensation guarantees or optimization tactics.
  • Auth, cookie, CORS, GitHub App, Cloudflare, or session changes include negative-path tests. (N/A — this script only issues unauthenticated GET requests against already-public endpoints; no auth/cookie/CORS/session changes.)
  • API/OpenAPI/MCP behavior is updated and tested where needed. (N/A — no route, schema, or MCP behavior changed.)
  • UI changes use live API data or real empty/error/loading states, not production mock/demo fallbacks. (N/A — no UI changes; the generated SVG's content/shape is unchanged.)
  • Visible UI changes include a UI Evidence section below with JPG/JPEG or PNG screenshots. (N/A — no UI changes; the generated README card's visual output is byte-for-byte unchanged, only the network layer underneath it gained a timeout.)
  • Public docs/changelogs are updated where needed; changelogs are only edited for release-prep PRs.

…meout

Two of the script's three outbound fetches (the two api.gittensor.io
calls via fetchJson, and the gt-logo.svg fetch) had no AbortSignal.timeout
at all, unlike every other external-fetch script in this repo -- a hung
connection would block the README-card regeneration job indefinitely.

Closes JSONbored#7231
…card test

fetchImpl.mock.calls[0] is typed as any[] | undefined under this
project's noUncheckedIndexedAccess, which array-destructuring
assignment can't accept without a non-null assertion.
@galuis116
galuis116 requested a review from JSONbored as a code owner July 19, 2026 12:10
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.81%. Comparing base (c743eca) to head (baf69ed).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7280   +/-   ##
=======================================
  Coverage   93.81%   93.81%           
=======================================
  Files         704      704           
  Lines       69458    69458           
  Branches    18896    18896           
=======================================
  Hits        65163    65163           
  Misses       3302     3302           
  Partials      993      993           
Flag Coverage Δ
shard-1 43.60% <ø> (ø)
shard-2 37.34% <ø> (+0.10%) ⬆️
shard-3 33.05% <ø> (-0.05%) ⬇️
shard-4 34.31% <ø> (-0.02%) ⬇️
shard-5 32.18% <ø> (+<0.01%) ⬆️
shard-6 45.78% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 19, 2026
@loopover-orb

loopover-orb Bot commented Jul 19, 2026

Copy link
Copy Markdown

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-19 12:22:29 UTC

3 files · 1 AI reviewer · no blockers · readiness 100/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This is a well-scoped, narrow operator-facing fix: it adds a shared 10s AbortSignal.timeout to all three external fetches in gittensor-impact-card.mjs (matching the timeout pattern used elsewhere in the repo), extracts fetchGtLogoSvg into a named/injectable function, and adds a CLI entry-point guard so the new unit tests can import the module without triggering main()/process.exit(1). The diff is internally consistent: fetchJson and fetchGtLogoSvg both accept fetchImpl defaulting to global fetch, both call sites in main() are updated, and the entry-point guard correctly gates main() behind direct-invocation detection. Tests cover the happy path, error path, timeout wiring, and the CLI guard indirectly (by importing without crashing); CI is green.

Nits — 5 non-blocking
  • The `.d.mts` companion type file introduces a hand-maintained parallel type surface (`ImpactCardFetch`) for a small script — worth confirming this matches the project's established pattern (referenced as `scripts/load-test-worker.d.mts`) rather than being a one-off.
  • scripts/gittensor-impact-card.mjs: the entry-point guard resolves `process.argv[1]` fresh via `path.resolve` on every module load; if this script is ever imported via symlink or a different invocation path, the equality check could subtly diverge — worth a comment confirming this mirrors `check-mcp-release-due.mjs` exactly.
  • The hardcoded `https:​//gittensor.io/gt-logo.svg` URL noted by the external brief predates this diff and isn't newly introduced, so it's not actionable here.
  • Consider whether GITTENSOR_IMPACT_CARD_FETCH_TIMEOUT_MS should be overridable via env var (like GITHUB_REQUEST_TIMEOUT_MS presumably is) for consistency with the cited sibling scripts.
  • The AbortSignal.timeout stubbing technique in the hanging-fetch test is a nice pattern — consider extracting it as a shared test helper if other scripts need the same treatment.

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #7231
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 1953 registered-repo PR(s), 1282 merged, 51 issue(s).
Contributor context ✅ Confirmed Gittensor contributor galuis116; Gittensor profile; 1953 PR(s), 51 issue(s).
Improvement ✅ Minor risk: clean · value: minor
Review context
  • Author: galuis116
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: JavaScript, Python, Dart, TypeScript, HTML, MDX, Rust, C++
  • Official Gittensor activity: 1953 PR(s), 51 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Keep the PR focused and include validation evidence before maintainer review.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@loopover-orb loopover-orb Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoopOver approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit 2372739 into JSONbored:main Jul 19, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gittensor-impact-card.mjs's two api.gittensor.io/gittensor.io fetches have no request timeout

1 participant