Skip to content

test(miner-extension): bring the miner extension under a real coverage gate - #5639

Closed
claytonlin1110 wants to merge 2 commits into
JSONbored:mainfrom
claytonlin1110:feat/miner-extension-coverage-4865
Closed

test(miner-extension): bring the miner extension under a real coverage gate#5639
claytonlin1110 wants to merge 2 commits into
JSONbored:mainfrom
claytonlin1110:feat/miner-extension-coverage-4865

Conversation

@claytonlin1110

Copy link
Copy Markdown
Contributor

Summary

  • apps/gittensory-miner-extension had zero test coverage — excluded via the root vitest config's blanket apps/** ignore, and its five source files' __GITTENSORY_MINER_EXTENSION_TEST__-gated internals-exposure hooks (already wired in by whoever built Give the browser extension a real package.json and CI wiring #4866/feat(miner-extension): add workspace package and CI wiring #5567) went unused.
  • Adds a real vitest suite: one *.test.js per source file (background.js, content.js, opportunity-badge.js, options.js, toolbar-badge.js), running under jsdom. Each test file sets globalThis.__GITTENSORY_MINER_EXTENSION_TEST__ = true plus whatever chrome.*/fetch/DOM mocks that file needs, then does a dynamic import() (a static import would be hoisted above that setup) to get a fresh module instance per scenario via vi.resetModules().
  • Exercises both sides of every branch that matters: each of background.js's optional-API guards (chrome.alarms, chrome.runtime.onStartup/onInstalled, chrome.action + chrome.storage.onChanged) present vs. absent; every error path (syncRankedCandidatesFromMinerUi's non-2xx / malformed-payload / thrown-fetch cases; options.js's malformed-JSON / oversized-payload / rejected-sendMessage cases); the "never populated" vs. "populated but empty" vs. "populated" three-way distinction in toolbar-badge.js.
  • This is the second half of Bring the miner-ui and extension under a coverage gate #4865 — the miner-ui half landed in test(miner-ui): bring the miner-ui under a real coverage gate #5613, which explicitly scoped the extension out ("no vitest setup or test suite at all yet... a separate, larger effort left for a follow-up").
  • Wires miner-extension:test into .github/workflows/ci.yml right alongside the existing extension:lint/miner-extension:lint/typecheck steps (same trigger condition), and adds the matching miner-extension:test script to the root package.json.
  • Coverage thresholds in the new vitest.config.ts are set to the real measured baseline (99.2% statements / 92.1% branches / 95.12% functions / 100% lines) with a small buffer below, mirroring apps/gittensory-miner-ui/vitest.config.ts's identical framing from test(miner-ui): bring the miner-ui under a real coverage gate #5613 — a floor to catch a genuine regression, not a ratchet.
  • Documents the testing approach in the app's README.md.

Scope

  • The PR title follows type(scope): short summary Conventional Commit format, for example fix(api): restore profile access checks.
  • 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 (e.g. Closes #123) — a linked open issue is required for every contributor PR.

Closes #4865

Validation

  • git diff --check
  • npm run actionlint
  • npm run db:migrations:check / db:schema-drift:check / selfhost:env-reference:check (no DB/env changes in this PR; ran as part of npm run test:ci)
  • npm run typecheck
  • npm run test:coverage (this PR only touches apps/gittensory-miner-extension/**, which Codecov's src/**-only patch rule does not gate — coverage here is enforced locally via the new vitest.config.ts thresholds instead, matching the miner-ui half's precedent)
  • npm run miner-extension:test — 96 tests, all passing, coverage thresholds met
  • npm run ui:lint
  • npm run ui:typecheck
  • npm audit --audit-level=moderate
  • New or changed behavior has unit/integration tests for new branches, fallback paths, and sanitizer boundaries

If any required check was skipped, explain why:

  • npm run cf-typegen:check (part of npm run test:ci) fails locally on this Windows dev machine with a wrangler ENOENTscripts/gen-cf-typegen.mjs calls execFileSync("wrangler", ...) without shell: true, which cannot invoke npm's .cmd shim on Windows (reproduces in isolation, independent of any change in this PR). This PR makes no Cloudflare/wrangler.jsonc changes; the check runs fine on the actual CI (Linux runners). Every other step in npm run test:ci ran and passed before that point.

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 — no auth/session/CORS surface touched; this is test-only + CI wiring.)
  • API/OpenAPI/MCP behavior is updated and tested where needed. (N/A.)
  • UI changes use live API data or real empty/error/loading states, not production mock/demo fallbacks. (N/A — no UI-visible change; this PR adds tests and CI wiring only.)
  • Visible UI changes include a UI Evidence section below with JPG/JPEG or PNG screenshots. N/A for this PR — it has no visible UI surface (pure test coverage + CI config), so no screenshot evidence applies.
  • Public docs/changelogs are updated where needed; changelogs are only edited for release-prep PRs. (README.md updated with a short "Testing" section; no changelog edit.)

Notes

…e gate

apps/gittensory-miner-extension had no test suite at all -- coverage was
excluded via the blanket apps/** ignore and its five source files' existing
__GITTENSORY_MINER_EXTENSION_TEST__ internals-exposure hooks were unused.
Add a vitest suite (one *.test.js per source file, jsdom environment) that
dynamically imports each file after setting that flag and mocking the
chrome.*/fetch/DOM surfaces it needs, exercising both sides of every
optional-API guard (chrome.alarms, onStartup, onInstalled, action+onChanged)
and error path. Wire miner-extension:test into CI (mirrors how
extension:lint/typecheck are already wired) and set coverage thresholds to
the measured baseline (99.2% statements, 92.1% branches, 95.12% functions,
100% lines), matching apps/gittensory-miner-ui/vitest.config.ts's precedent
from the sibling half of this same issue.

Closes JSONbored#4865
@superagent-security

Copy link
Copy Markdown
Contributor

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

@loopover-orb loopover-orb Bot added the gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. label Jul 13, 2026
@claytonlin1110
claytonlin1110 marked this pull request as draft July 13, 2026 18:04
@loopover-orb

loopover-orb Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Caution

🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥

🛑 LoopOver review result - reject/close recommended

Review updated: 2026-07-13 18:36:14 UTC

11 files · 1 AI reviewer · 1 blocker · readiness 100/100 · CI green · clean

🛑 Suggested Action - Reject/Close

Review summary
This PR wires a real vitest+jsdom test suite (one *.test.js per source file) plus coverage thresholds for the previously-untested miner-extension, using dynamic imports and a `__GITTENSORY_MINER_EXTENSION_TEST__` flag to reach the internals-exposure hooks already wired in by #4866/#5567. The tests are thorough and exercise both sides of the meaningful branches (optional chrome.* API guards in background.js, error paths in syncRankedCandidatesFromMinerUi/options.js, the three-way toolbar-badge state), and the CI/package.json/root package.json wiring matches the existing extension:lint/typecheck pattern. The one notable oddity is the package-lock.json diff, which — beyond the two new devDependencies — also drops several apparently-unrelated top-level entries (`@​anthropic-ai/sdk`, `@​cloudflare/workers-types`, `@​stablelib/base64`, `ts-algebra`, `fast-sha256`, `empathic`, `import-meta-resolve`, `@​types/gensync`), which is broader lockfile churn than a two-package devDependency addition should normally produce.

Nits — 5 non-blocking
  • package-lock.json's diff removes several unrelated top-level packages (@​anthropic-ai/sdk, @​cloudflare/workers-types, @​stablelib/base64, ts-algebra, fast-sha256, empathic, import-meta-resolve, @​types/gensync) beyond the two new devDependencies — worth confirming this is legitimate npm dedup from adding jsdom/vitest rather than a stale/regenerated lockfile, since other workspaces may rely on those peer deps.
  • jsdom@​28.1.0 has no published SLSA/sigstore attestation per the dependency scan — not a blocker for a devDependency, but worth a passing mention if the repo otherwise tracks supply-chain provenance.
  • The coverage thresholds in vitest.config.ts (97/89/92/97) are already well-commented with the measured baseline and buffer rationale, so no further justification needed there.
  • Run `npm ci` (or equivalent) against this lockfile in isolation to confirm the unrelated package-lock.json deletions don't break another workspace's install before merging.
  • Consider a follow-up issue/PR reference check: confirm Bring the miner-ui and extension under a coverage gate #4865 is explicitly the authorizing issue for this scope (test-only, CI-wiring) since the external linkage shows only partial coverage of that issue.

Why this is blocked

  • Linked issue overlaps another open PR — Review the related PRs before spending reviewer time on duplicate work.
📋 Copy for AI agents — paste into your coding agent
Fix the following blocker(s) from this PR review:

1. Linked issue overlaps another open PR — Review the related PRs before spending reviewer time on duplicate work.
Signal Result Evidence
Code review ❌ 1 blocker 1 reviewer
Linked issue ✅ Linked #4865
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: 448 registered-repo PR(s), 307 merged, 102 issue(s).
Contributor context ✅ Confirmed Gittensor contributor claytonlin1110; Gittensor profile; 448 PR(s), 102 issue(s).
Gate result ❌ Blocking Repo-configured hard blocker found.
Improvement ✅ Minor risk: clean · value: minor — Code changes are accompanied by test evidence.
Review context
  • Author: claytonlin1110
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, JavaScript, TypeScript, Rust
  • Official Gittensor activity: 448 PR(s), 102 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.
[BETA] Chat with Gittensory

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

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

Full command reference: https://gittensory.aethereal.dev/docs/gittensory-commands

Visual preview
Route Viewport Before (production) After (this PR's preview) Diff
/ desktop before / after /
/ mobile before / (mobile) after / (mobile)

Click any thumbnail to open the full-size screenshot. Before = production · After = this PR's preview deploy.

🟩 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

The lockfile change in the previous commit (adding jsdom/vitest to the
miner-extension workspace) was written by a plain `npm install`, which
dropped 16 pre-existing "peer": true phantom lockfile entries for unmet-
but-declared optional peer dependencies (@cloudflare/workers-types,
@types/gensync, agents/node_modules/@babel/{core,compat-data,helpers,
helper-compilation-targets,helper-validator-option,lru-cache}, empathic,
import-meta-resolve, @anthropic-ai/sdk, @stablelib/base64, fast-sha256,
json-schema-to-ts, standardwebhooks, ts-algebra) that npm ci's stricter
lockfile-completeness validation still requires present -- confirmed by
diffing package-lock.json's package keys between main and this branch,
finding the 16 removed entries line up 1:1 with this PR's actual CI
failure ("Missing: X from lock file" on every job).

Re-running npm install (under both npm 11 and npm 10, from a clean
main-derived baseline) did not restore these entries either -- npm's
install resolver treats them as prunable cruft since nothing currently
requires them to be installed. This commit surgically restores just
those 16 entries from main's lockfile via a targeted merge, keeping the
legitimate jsdom/vitest additions untouched.
@claytonlin1110
claytonlin1110 marked this pull request as ready for review July 13, 2026 18:34
@loopover-orb

loopover-orb Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Gittensory is closing this pull request on the maintainer's behalf (Linked issue overlaps another open PR; duplicate of another open PR). This is an automated maintenance action — to pursue this change, please open a new pull request with the issues resolved. Closed PRs may be analyzed later to improve review accuracy, but they are not automatically reopened or re-reviewed.

@loopover-orb loopover-orb Bot closed this Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bring the miner-ui and extension under a coverage gate

1 participant