Skip to content

test(extension): cover background.js message routing and options.js session UI#7497

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
bitfathers94:fix/issue-7461
Jul 20, 2026
Merged

test(extension): cover background.js message routing and options.js session UI#7497
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
bitfathers94:fix/issue-7461

Conversation

@bitfathers94

Copy link
Copy Markdown
Contributor

test(extension): cover background.js message routing and options.js session UI

background.js (the service-worker onMessage router) and options.js (the
options-page controller) had no unit tests, unlike auth.js and content.js.
A regression in either -- background.js returning false instead of true and
silently breaking every async response, or refreshSettings() misclassifying an
expired session as valid -- would only surface by manually loading the unpacked
extension.

Add extension-background.test.ts and extension-options.test.ts using the vm
Script/createContext technique extension-content.test.ts established. Both files
statically import from auth.js, which a plain vm Script cannot execute, so the
import line is stripped and the handlers/auth helpers are injected as context
globals (the host Error is shared so 'error instanceof Error' matches the
single-realm extension). Covers background.js's pull-context/logout dispatch,
its Error-vs-stringified error mapping, and the unrecognized/nullish return
false paths; and options.js's refreshSettings() three display branches, the
conditional token-store submit path, and the logout error-recovery fallback.

Closes #7461

…ession UI

background.js (the service-worker onMessage router) and options.js (the
options-page controller) had no unit tests, unlike auth.js and content.js.
A regression in either -- background.js returning false instead of true and
silently breaking every async response, or refreshSettings() misclassifying an
expired session as valid -- would only surface by manually loading the unpacked
extension.

Add extension-background.test.ts and extension-options.test.ts using the vm
Script/createContext technique extension-content.test.ts established. Both files
statically import from auth.js, which a plain vm Script cannot execute, so the
import line is stripped and the handlers/auth helpers are injected as context
globals (the host Error is shared so 'error instanceof Error' matches the
single-realm extension). Covers background.js's pull-context/logout dispatch,
its Error-vs-stringified error mapping, and the unrecognized/nullish return
false paths; and options.js's refreshSettings() three display branches, the
conditional token-store submit path, and the logout error-recovery fallback.

Closes JSONbored#7461
@bitfathers94
bitfathers94 requested a review from JSONbored as a code owner July 20, 2026 13:06
@superagent-security

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.40%. Comparing base (c18b123) to head (afd2d88).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7497      +/-   ##
==========================================
- Coverage   91.41%   91.40%   -0.02%     
==========================================
  Files         717      717              
  Lines       73035    73035              
  Branches    21635    21638       +3     
==========================================
- Hits        66765    66754      -11     
- Misses       5227     5234       +7     
- Partials     1043     1047       +4     
Flag Coverage Δ
shard-1 34.51% <ø> (+2.57%) ⬆️
shard-2 41.03% <ø> (+5.06%) ⬆️
shard-3 33.19% <ø> (+1.74%) ⬆️
shard-4 38.46% <ø> (-5.47%) ⬇️
shard-5 33.34% <ø> (-3.72%) ⬇️
shard-6 35.40% <ø> (-0.53%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 2 files with indirect coverage changes

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

loopover-orb Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-20 13:22:57 UTC

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

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
Adds two new test files exercising background.js's onMessage router (dispatch, Error-vs-string error mapping, unrecognized/nullish message handling) and options.js's refreshSettings/submit/logout/clearLocal flows, using the same vm Script/createContext + import-stripping technique already established for content.js. The tests are well-targeted, directly close #7461's stated gap, and cover both branches of the meaningful conditionals (error instanceof Error vs not, expired vs valid session, blank vs filled token field). No production code is touched, so risk is limited to test-only correctness, and the assertions match the described behavior precisely.

Nits — 5 non-blocking
  • The regex `/^import\s*\{[\s\S]*?\}\s*from\s*["']\.\/auth\.js["'];?\n?/` used in both files to strip the auth.js import is fragile against reformatting (e.g. default imports, multiple import statements, or a trailing comment) — consider a shared test helper instead of duplicating this logic across extension-background.test.ts and extension-options.test.ts.
  • In extension-options.test.ts's `loadOptions`, `window.setTimeout` is stubbed as inert via `vi.fn()`, which silently means any other window timer usage in options.js (if added later) would also become a no-op without an obvious signal in the test — worth a short comment noting this is intentional only for showStatus's auto-clear.
  • The `flush()` helper (`setTimeout(resolve, 0)`) is duplicated between both new test files instead of being pulled into a shared test util alongside the DOM/vm-context helpers already following content.js's pattern.
  • Factor the shared vm-context bootstrapping (`Script`/`createContext` setup, Error-sharing comment, import-stripping regex) into a small shared test utility used by extension-background.test.ts, extension-options.test.ts, and extension-content.test.ts to reduce triplication.
  • Consider a regression test asserting `chrome.runtime.onMessage.addListener` is called exactly once with a function, guarding against a future double-registration bug in background.js.

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 #7461
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: 49 registered-repo PR(s), 30 merged, 0 issue(s).
Contributor context ✅ Confirmed Gittensor contributor bitfathers94; Gittensor profile; 49 PR(s), 0 issue(s).
Improvement ℹ️ Insufficient signal risk: clean · value: insufficient-signal · LLM: significant
Linked issue satisfaction

Addressed
The PR adds both required test files using the vm Script/createContext technique, covering background.js's pull-context/logout dispatch, Error-vs-stringified error mapping, and unrecognized/nullish message handling, plus options.js's refreshSettings 3-way branches, conditional token-store submit path, and logout error-recovery fallback exactly as specified.

Review context
  • Author: bitfathers94
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: not available
  • Official Gittensor activity: 49 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 &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
Contributor

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 32c2ba5 into JSONbored:main Jul 20, 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.

test(extension): apps/loopover-extension's background.js and options.js have no test coverage

1 participant