feat(miner-extension): live-fetch ranked candidates from the local miner UI - #5622
Merged
Conversation
…ner UI Adds syncRankedCandidatesFromMinerUi() to background.js, pulling from #5619's GET /api/ranked-candidates and writing into the same chrome.storage.local keys the manual-paste flow already writes -- so content.js/opportunity-badge.js/toolbar-badge.js need zero changes. Triggers on startup/install and every 10 minutes via chrome.alarms, plus a manual "Sync now" button. A failed sync leaves storage untouched, naturally falling back to whatever's already there (a stale fetch or a manual paste) with no merge logic needed. Adds a "Local miner UI URL" field to the options page (default http://localhost:5174, persisted to chrome.storage.sync alongside watchedRepos).
Contributor
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5622 +/- ##
=======================================
Coverage 95.01% 95.01%
=======================================
Files 575 575
Lines 45738 45738
Branches 14661 14661
=======================================
Hits 43459 43459
Misses 1528 1528
Partials 751 751
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
syncRankedCandidatesFromMinerUi()tobackground.js: fetchesGET {minerUiUrl}/api/ranked-candidates(built in feat(miner): persist ranked-candidates snapshots and serve them locally #5619) and writes the result into the samechrome.storage.localkeys (rankedCandidates/rankedCandidatesSavedAt) the manual-paste flow inoptions.jsalready writes — socontent.js/opportunity-badge.js/toolbar-badge.jsneed zero changes; they already read from that one shared source regardless of which flow populated it.chrome.alarms(the MV3-correct primitive — a plainsetIntervalwouldn't survive the worker being killed and woken between calls), plus a manual "Sync now" button on the options page for an immediate pull.http://localhost:5174, persisted tochrome.storage.syncalongside the existingwatchedRepos)."alarms"permission (host permissions for localhost were already granted by Resolve the extension's localhost-reachability gap #4860/feat(miner-extension): grant loopback host permissions for local miner-ui access (#4860) #5578).Closes #4859 — this was sequenced after #5619 (the persisted store + read API prerequisite, merged) specifically so the auth cookie and data source both already existed before this consumer went in.
A note on same-site cookies + extensions
vite-auth.ts's cookie (#4858) is
HttpOnly; SameSite=Strict. Verified via research before writing any code that this doesn't block the extension: Chrome (79+) treats an extension-initiated request as same-site when the extension hashost_permissionsfor the target host — which #4860/#5578 already granted forlocalhost/127.0.0.1. Sobackground.js's plainfetch()call correctly carries the cookie automatically, with nochrome.cookiesAPI or custom-header workaround needed, as long as the user has opened the miner-ui dashboard in their browser at least once (so the cookie exists in the jar in the first place) — a reasonable expectation for someone running the local miner-ui. Confirmed live end-to-end below.Test plan
npm run miner-extension:lint,npm run miner-extension:typecheck,npm run miner-extension:buildnpm run typecheck,npm run docs:drift-checktest/unit/miner-extension-live-fetch.test.ts(15 cases, using the samenode:vmsandbox harnessminer-extension-content.test.tsestablished): the sync function's success/failure/malformed-payload/thrown-fetch paths, the runtime-message handler, the alarm/startup/install wiring (including that the alarm listener only reacts to its own alarm name), and the options-page URL field + Sync-now button (save, normalize-empty-to-default, populate-on-load, success/fallback status messages)test/unit/miner-extension-content.test.tsthat broke becauseoptions.jsnow requires two new DOM elements (#minerUiUrl/#syncNow) to consider the form "mounted" — updated their fixtures to match the realoptions.htmlshape, plus one assertion that now needs to account forminerUiUrlin the saved payloadsyncRankedCandidatesFromMinerUiuses (same-origin cookie, same JSON parsing) against it — confirmed{ ok: true, count: 1 }Along the way: caught and fixed a real bug in my own first draft — the catch block's non-Error fallback was a hardcoded generic string instead of
String(error)(inconsistent with every other catch block in this file and this session), silently discarding real error detail on a non-Error throw. Caught via anode:vmcross-realminstanceof Errortest failure, traced to the actual root cause rather than just adjusting the test to match.This PR touches
apps/gittensory-miner-extension/**only (nosrc/**/lib/**), so Codecov's patch gate has nothing to measure here — same precedent as every otherapps/**PR this session.