fix(auth): gh-reuse — validate before reboot + refresh discovery on focus#113
Merged
Merged
Conversation
…ocus
Completes the gh-reuse feature to a clean state. Two gaps:
1. Errors were handled safely but imprecisely: a stale/no-subscription gh
account got written + rebooted into, then surfaced a generic 'came back
unauthenticated' ~20s later. Now POST /gh/use PRE-FLIGHTS the token against
Copilot (/copilot_internal/user) BEFORE writing/rebooting and returns a
specific 422 — 'token expired or revoked' (401) vs 'no Copilot subscription'
(403/404) vs a network message — which the UI shows immediately, no reboot.
The shell now extracts {error:{message}} so the specific reason renders.
Also closes the getModels timeout gap (it was missing from the #110 set;
cacheModels is on the boot critical path).
2. gh discovery was only refreshed on entering the Account section — adding an
account in gh while settings was already open didn't show up. Now refreshes
on window focus / visibilitychange (the natural 'returned from the terminal'
moment) + a manual Refresh button. No polling (gh auth status hits the
keyring).
+6 pre-flight unit tests (status→message mapping, DI'd usage fn — no
mock.module). Full suite green (824); valid-account import still 200 (no
happy-path regression); shell tsc clean.
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.
Brings the gh-reuse feature to a clean state — the error-precision and discovery-freshness gaps we'd been circling.
1. Errors handled precisely, before the reboot
A stale or no-Copilot gh account used to be written + rebooted-into, then surfaced a generic "came back unauthenticated" ~20s later (the reason was lost on the boot-degrade path). Now
POST /gh/usepre-flights the token against Copilot (/copilot_internal/user) before writing + rebooting and returns a specific 422:The shell extracts
{error:{message}}and shows it immediately — no wasted reboot. Also closes thegetModelstimeout gap (it was missing from #110's guarded set;cacheModelsis on the boot critical path).2. Discovery refreshes on attention, not on a poll
gh accounts were only re-read on entering the Account section — adding an account in
ghwhile Settings was already open didn't appear. Now refreshes on window focus /visibilitychange(the "switched back from the terminal aftergh auth login" moment) plus a quiet Refresh button. No polling (gh auth statustouches the keyring).Validation
+6 pre-flight unit tests (status→message, DI'd usage fn — no
mock.moduleleak). Full suite green (824); a valid account still imports (200 — no happy-path regression);check:fast+ shelltscclean.Multi-account persistence + the quick-switch list (with merge/remove/needs-reauth and the boot-degrade reason-preservation) remain the separate next project; this is the per-feature clean-up.