Skip to content

test(ui): add coverage for use-api-session.ts (#7903)#7955

Merged
JSONbored merged 1 commit into
JSONbored:mainfrom
xfodev:test/use-api-session-coverage-7903
Jul 24, 2026
Merged

test(ui): add coverage for use-api-session.ts (#7903)#7955
JSONbored merged 1 commit into
JSONbored:mainfrom
xfodev:test/use-api-session-coverage-7903

Conversation

@xfodev

@xfodev xfodev commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Closes #7903

What

apps/ui/src/hooks/use-api-session.ts — the wallet-signature challenge → sign → verify session hook (sessionStorage-persisted, address-scoped, expiry-checked) — had zero test coverage. This adds it.

How

This suite is plain-node (no DOM, no renderHook — see apps/ui/vitest.config.ts, and no hook test in the repo renders), so I cover the hook's real logic through its two extracted, exported pure pieces — matching the repo's "test the extracted pure function" convention (e.g. use-move-stake-flow):

  • readStoredSession / writeStoredSession — the address-scoped, expiry-checked sessionStorage helpers (added export).
  • performWalletSignIn(wallet, deps) — the challenge → sign → verify → session-shape orchestration, split out of signIn with apiFetch / signMessage / now dependency-injected so it's testable without a DOM. The hook's signIn now delegates to it; behavior is unchanged.

Tests — apps/ui/src/hooks/use-api-session.test.ts (10 cases)

  • performWalletSignIn: the full challenge→sign→verify flow (asserts the POST paths/bodies, the signer call, and the shaped session incl. expiresAtMs = now + expires_in*1000); ApiError propagation.
  • readStoredSession / writeStoredSession: round-trip, wrong-address rejection, expired rejection, empty, malformed-JSON (never throws), storage-throws (never throws), clear-on-null, and the SSR no-window no-op.

Scoped to apps/ui/src/hooks/ — no visual/component change, so it follows the normal (non-screenshot-gated) review path per the frontend contribution rules.

  • npx vitest run src/hooks/use-api-session.test.ts — 10 passed
  • eslint + prettier clean; typecheck clean for these files
  • Links a tracked, currently-open issue (Closes #7903)

use-api-session.ts (the wallet-signature challenge->sign->verify session hook)
had zero coverage. This suite is plain-node (no DOM/renderHook per
apps/ui/vitest.config.ts), so extract the hook's two pure pieces as named
exports and cover them directly: the address-scoped, expiry-checked
sessionStorage read/write helpers, and performWalletSignIn -- the
challenge->sign->verify orchestration with its deps (apiFetch/signMessage/now)
injectable for the test. The hook's signIn now delegates to performWalletSignIn;
behavior is unchanged.

Covers: the full challenge->sign->verify flow and session shape, ApiError
propagation, and readStoredSession's round-trip / wrong-address / expired /
malformed-JSON / storage-throws / SSR-no-window paths.
@superagent-security

Copy link
Copy Markdown

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

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.58%. Comparing base (487ef64) to head (778d1e0).
⚠️ Report is 17 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7955   +/-   ##
=======================================
  Coverage   97.58%   97.58%           
=======================================
  Files         204      204           
  Lines       26365    26365           
  Branches    10452    10452           
=======================================
  Hits        25729    25729           
  Misses        150      150           
  Partials      486      486           
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

loopover-orb Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Warning

⏸️ LoopOver review result - manual review recommended

Review updated: 2026-07-24 16:21:17 UTC

2 files · 1 AI reviewer · no blockers · CI green · clean

⏸️ Suggested Action - Manual Review

  • Touches a guarded path — held for manual review: This PR changes guardrail-protected path(s): apps/ui/src/hooks/use-api-session.test.ts (matched apps/ui/**), apps/ui/src/hooks/use-api-session.ts (matched apps/ui/**).

Review summary
The AI review returned non-blocking notes for this change but did not include a separate narrative summary. Review the nits below before deciding this PR.

Nits — 4 non-blocking
  • `beforeEach` is imported in the test file but never used, which is dead import clutter.
  • Remove the unused `beforeEach` import in apps/ui/src/hooks/use-api-session.test.ts:1.
  • Consider a test asserting `writeStoredSession`'s catch-swallow path (setItem throwing) mirrors the read-side 'storage throws' coverage for full symmetry.
  • Touches a guarded path — held for manual review — A maintainer must review and merge this change.

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ⚠️ Gate result — Not blocking (Advisory; not blocking this PR.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #7903
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: 64 registered-repo PR(s), 29 merged, 0 issue(s).
Contributor context ✅ Confirmed Gittensor contributor xfodev; Gittensor profile; 64 PR(s), 0 issue(s).
Review context
  • Author: xfodev
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: JavaScript, TypeScript
  • Official Gittensor activity: 64 PR(s), 0 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Triage stale or unlinked PRs.
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 <question> answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat <question> 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 added the manual-review Gittensor contributor context label Jul 24, 2026
@JSONbored
JSONbored merged commit afb689a into JSONbored:main Jul 24, 2026
10 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 or unsolicited PR — scores a 0.05x multiplier. manual-review Gittensor contributor context

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(ui): add coverage for use-api-session.ts (wallet-signature session flow)

2 participants