Skip to content

feat: robust upgrade detection — non-interactive git, auth injection, 24h cache#29

Merged
ericchansen merged 3 commits intomainfrom
feat/robust-upgrade-detection
May 1, 2026
Merged

feat: robust upgrade detection — non-interactive git, auth injection, 24h cache#29
ericchansen merged 3 commits intomainfrom
feat/robust-upgrade-detection

Conversation

@ericchansen
Copy link
Copy Markdown
Owner

Summary

Makes plugin upgrade detection robust for all users, including non-developers with private repos and multi-account setups. Based on patterns from Homebrew, pip, npm, gh CLI, k9s, and Renovate.

Non-interactive git (_git_env)

  • GIT_TERMINAL_PROMPT=0 — git never hangs waiting for credentials
  • GIT_SSH_COMMAND with -oBatchMode=yes — kills SSH passphrase prompts
  • Auto-injects GitHub token via gh auth token using Renovate-style GIT_CONFIG_COUNT env vars (zero files touched)
  • Falls back silently if gh is not installed or not authenticated

Graceful fetch fallback

  • Auth failures no longer abort — falls back to local cached tags from previous successful fetches
  • New _cached_latest parameter on check_plugin() allows skipping network entirely when cache is fresh

24h disk cache (UpgradeCache)

  • New ~/.copilot/upgrade-cache.json with per-plugin {latest_version, checked_at}
  • 24h TTL (matches gh CLI). Press r to force refresh.
  • Thread-safe, atomic writes via existing write_json() with .bak rotation
  • Cache invalidated automatically after successful copilot plugin update
  • Corrupted/missing cache handled gracefully

Tests

  • _git_env(): terminal prompt, SSH batch mode, token injection via env vars, no-gh fallback
  • _cached_latest: cache hit skips fetch, up-to-date detection
  • Fetch failure fallback to local tags
  • UpgradeCache: set/get, TTL expiry, invalidation, corruption, schema mismatch, multi-plugin independence

ericchansen and others added 2 commits May 1, 2026 11:39
… 24h cache

- _git_env(): GIT_TERMINAL_PROMPT=0, SSH BatchMode, gh auth token
  injection via GIT_CONFIG_COUNT (Renovate pattern)
- check_plugin(): _cached_latest param to skip network on cache hit
- UpgradeCache: disk-backed 24h TTL cache at ~/.copilot/upgrade-cache.json
- Wire cache into _check_upgrades_async, invalidate after upgrade

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves plugin upgrade detection robustness by making git operations non-interactive, adding GitHub auth token injection support, and introducing a 24-hour disk cache to reduce network calls and failures for end users.

Changes:

  • Add _git_env() and route all git subprocess calls through it to avoid interactive prompts and optionally inject GitHub auth via GH_TOKEN/GITHUB_TOKEN or gh auth token.
  • Add a disk-backed UpgradeCache (~/.copilot/upgrade-cache.json) with TTL-based reads and graceful handling for missing/corrupt cache.
  • Update the Plugins tab to use the cache for background upgrade checks and invalidate cache entries after successful plugin upgrades; add tests for cache and new upgrade-detection behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/copilotsetup/plugin_upgrades.py Adds non-interactive/auth-aware git env and adds cached-latest + fetch-fallback behavior in check_plugin().
src/copilotsetup/upgrade_cache.py New disk-backed cache wrapper around check_plugin() with TTL and schema validation.
src/copilotsetup/tabs/plugins.py Switches plugin upgrade detection to use UpgradeCache and invalidates cache after upgrades.
src/copilotsetup/config.py Adds upgrade_cache_json() path helper for cache location.
tests/test_plugin_upgrades.py Adds unit tests for _git_env(), _cached_latest, and fetch-failure fallback behavior.
tests/test_upgrade_cache.py Adds tests covering cache load/reset behavior, TTL, invalidation, and multi-plugin entries.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/copilotsetup/plugin_upgrades.py
Comment thread src/copilotsetup/plugin_upgrades.py
Comment thread src/copilotsetup/upgrade_cache.py
Comment thread src/copilotsetup/tabs/plugins.py
Comment thread src/copilotsetup/tabs/plugins.py
…verified flag

- Only write cache on actual network checks (not cache hits)
- Memoize _git_env() per session (gh auth token called once, not 30-50×)
- UpgradeCache singleton so background thread and upgrade handler share lock
- network_verified flag prevents false UP_TO_DATE caching after fetch failure
- Tests for all four fixes

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ericchansen ericchansen force-pushed the feat/robust-upgrade-detection branch from 2104345 to 8cc01dd Compare May 1, 2026 17:03
@ericchansen ericchansen merged commit d02d91e into main May 1, 2026
8 checks passed
@ericchansen ericchansen deleted the feat/robust-upgrade-detection branch May 1, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants