Skip to content

feat(badge): add metric=apis — a callable-API-count badge#2172

Merged
JSONbored merged 3 commits into
JSONbored:mainfrom
glorydavid03023:feat/badge-apis-metric
Jun 28, 2026
Merged

feat(badge): add metric=apis — a callable-API-count badge#2172
JSONbored merged 3 commits into
JSONbored:mainfrom
glorydavid03023:feat/badge-apis-metric

Conversation

@glorydavid03023

Copy link
Copy Markdown
Contributor

Summary

Adds a new metric=apis option to the embeddable SVG badge (/api/v1/subnets/{netuid}/badge.svg and /providers/{slug}/badge.svg), alongside the existing readiness / uptime / grade metrics. It shows how many callable API surfaces a subnet exposes — the core machine-integrability signal the registry is built to surface.

Closes #2171

Behavior

  • Message: the count of callable surfaces — kinds subnet-api, openapi, sse, data-artifact (mirrors the build's callable-service set) — counted from the per-subnet /metagraph/surfaces/{netuid}.json artifact. "3 apis", singular "1 api", "0 apis" when none.
  • Color: shields-style informational blue (#007ec6) for >0, gray for 0, and "n/a" (gray, still 200) when there's no surfaces artifact — so an <img> never breaks, consistent with the other metrics.
  • Providers: the sum across the provider's subnets, mirroring how readiness/reliability aggregate.

Scope

  • Self-contained in src/badge.mjs — no schema/contract/artifact change (badges aren't part of the typed OpenAPI envelope), so nothing to regenerate.
  • Reuses the existing readData / findProvider helpers and the established n/a-fallback pattern.

Tests (tests/badge.test.mjs)

New cases: subnet count (callable-only), singular "1 api", the "0 apis" gray case, provider sum across subnets, and the n/a fallback when a subnet has no surfaces artifact. Plus the metric=apis allow-list assertion.

✓ tests/badge.test.mjs (36 tests)

eslint and prettier --check clean on both changed files. Full local vitest run shows no new failures (the only failures are pre-existing Windows-only env issues — spawning binaries / DNS — that pass on Linux CI).

Add a new `metric=apis` option to the embeddable badge: the message is the
count of a subnet's callable API surfaces (subnet-api / openapi / sse /
data-artifact, mirroring the build's callable-service set), counted from the
per-subnet surfaces artifact.

- "3 apis" (singular "1 api"), "0 apis" when none; informational blue for >0,
  gray for 0, "n/a" (still 200) when there's no surfaces artifact — so an <img>
  never breaks, consistent with the existing metrics.
- Providers sum the count across their subnets, mirroring how readiness and
  reliability aggregate.

Self-contained in src/badge.mjs (no schema/contract/artifact change); badges
aren't part of the typed OpenAPI envelope. Covered by tests for subnet/provider
counts, the singular form, the zero case, and the n/a fallback.

Closes JSONbored#2171
@superagent-security

Copy link
Copy Markdown

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

@codecov

codecov Bot commented Jun 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.17%. Comparing base (4ca0577) to head (d73343e).

Files with missing lines Patch % Lines
src/badge.mjs 87.50% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2172      +/-   ##
==========================================
- Coverage   93.18%   93.17%   -0.01%     
==========================================
  Files          52       52              
  Lines        8272     8294      +22     
  Branches     3035     3043       +8     
==========================================
+ Hits         7708     7728      +20     
  Misses         96       96              
- Partials      468      470       +2     
Files with missing lines Coverage Δ
src/badge.mjs 88.72% <87.50%> (+0.43%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gittensory-orb

gittensory-orb Bot commented Jun 27, 2026

Copy link
Copy Markdown

Tip

🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩

✅ Gittensory review — safe to merge

2 files · 1 AI reviewers · no blockers · readiness 55/100 · CI green · clean

✅ Approved — safe to merge

Review summary
Adds `metric=apis` to the badge handler — a callable-surface count from the per-subnet surfaces artifact, informational blue for >0, gray for 0, n/a when the artifact is absent. The implementation is self-contained in `src/badge.mjs`, correctly reuses `readData`/`findProvider`, mirrors the `CALLABLE_SURFACE_KINDS` set from the build, and the n/a-fallback pattern is applied consistently. Provider aggregation filters nulls before summing, which is the right approach and matches how `averageReadiness` handles missing scores. No blockers.

Signal Result Evidence
Code review ✅ No blockers 1 reviewers, synthesized
Linked issue ✅ Linked #2171
Related work ⚠️ 3 scoped overlaps Top overlaps are listed below; lower-confidence bulk is hidden.
Review load ❌ 8/20 Readiness component derived from cached public PR metadata and labels.
Validation evidence ❌ 5/25 Cached preflight status is hold.
Open PR queue ❌ 3/10 15 open PR(s), 13 likely reviewable, 2 unlinked.
Contributor context ✅ Confirmed Gittensor contributor glorydavid03023; Gittensor profile; 188 PR(s), 7 issue(s).
Gate result ✅ Passing No configured blocker found.
Nits — 6 non-blocking
  • src/badge.mjs `apisContent` provider path: when some (but not all) of a provider's subnet artifacts are missing, nulls are filtered and the remaining counts are summed, silently returning a partial total; this is consistent with `averageReadiness` behavior but is undocumented and has no test coverage for the mixed case.
  • tests/badge.test.mjs: the provider n/a case (`byid`, netuid 9) is not exercised under `metric=apis` — only the subnet n/a case is — so the `netuids.length === 0 → null` branch and the `counts.length === 0 → null` branch are untested for providers.
  • src/badge.mjs `callableApiCount` comment says 'Returns null when the artifact is missing/malformed' but doesn't note that 0 is returned (not null) when the artifact is present but has no callable surfaces — a subtle distinction that matters for the gray vs n/a rendering.
  • Add a provider apis test using `byid` (netuid 9, no surfaces artifact) to cover the `counts.length === 0 → NA_CONTENT` branch: `await badge('/api/v1/providers/byid/badge.svg?metric=apis')` should match `n/a`.
  • Consider adding a mixed-artifact provider fixture (e.g. netuids [7, 9] where 9 has no artifact) to document and pin the partial-sum behavior.
  • PR author also opened the linked issue — Link an issue that was opened by a different contributor, or provide a rationale for why this self-authored issue represents genuine discovery work.
Review context
Contributor next steps
  • Review top overlaps.
  • Add scope summary.
  • Fix blocker.
  • Expect slower review.
  • Refresh registry data or choose a registered active repo.
  • Check active issues and PRs before submitting.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Review load = cached public PR metadata such as size labels, changed paths, and preflight status.
  • Open PR queue = repo-wide review pressure; it is not a PR quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
Review details

Generated from public PR metadata and the diff. Advisory only; deterministic signals remain authoritative.

Adds `metric=apis` to the badge handler — a callable-surface count from the per-subnet surfaces artifact, informational blue for >0, gray for 0, n/a when the artifact is absent. The implementation is self-contained in `src/badge.mjs`, correctly reuses `readData`/`findProvider`, mirrors the `CALLABLE_SURFACE_KINDS` set from the build, and the n/a-fallback pattern is applied consistently. Provider aggregation filters nulls before summing, which is the right approach and matches how `averageReadiness` handles missing scores. No blockers.

Nits (5)

  • src/badge.mjs `apisContent` provider path: when some (but not all) of a provider's subnet artifacts are missing, nulls are filtered and the remaining counts are summed, silently returning a partial total; this is consistent with `averageReadiness` behavior but is undocumented and has no test coverage for the mixed case.
  • tests/badge.test.mjs: the provider n/a case (`byid`, netuid 9) is not exercised under `metric=apis` — only the subnet n/a case is — so the `netuids.length === 0 → null` branch and the `counts.length === 0 → null` branch are untested for providers.
  • src/badge.mjs `callableApiCount` comment says 'Returns null when the artifact is missing/malformed' but doesn't note that 0 is returned (not null) when the artifact is present but has no callable surfaces — a subtle distinction that matters for the gray vs n/a rendering.
  • Add a provider apis test using `byid` (netuid 9, no surfaces artifact) to cover the `counts.length === 0 → NA_CONTENT` branch: `await badge('/api/v1/providers/byid/badge.svg?metric=apis')` should match `n/a`.
  • Consider adding a mixed-artifact provider fixture (e.g. netuids [7, 9] where 9 has no artifact) to document and pin the partial-sum behavior.

🟩 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 Gittensory, a quiet PR intelligence layer for OSS maintainers.

  • Re-run Gittensory review

@JSONbored JSONbored merged commit 42e799b into JSONbored:main Jun 28, 2026
7 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Metagraphed - Blocksploratory v1 Jun 28, 2026
@github-actions github-actions Bot mentioned this pull request Jun 28, 2026
kiannidev added a commit to kiannidev/metagraphed that referenced this pull request Jun 28, 2026
Accept main's metric=apis implementation from JSONbored#2172 and retain the
additional edge-case tests from this branch (unknown provider, empty
netuids, readArtifact failures).

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:feature Feature / enhancement gittensor Gittensor contributor context

Development

Successfully merging this pull request may close these issues.

feat(badge): add metric=apis — a callable-API-count badge

2 participants