spec-kit icon indicating copy to clipboard operation
spec-kit copied to clipboard

feat(cli): warn when a newer spec-kit release is available (#1320)

Open ATelbay opened this issue 7 months ago β€’ 10 comments

Summary

Addresses #1320 β€” when explicitly opted in, the CLI prints a one-line upgrade hint on launch if a newer release is available. Off by default; enabled with SPECIFY_ENABLE_UPDATE_CHECK=1. Even when enabled, suppressed in CI (CI=1) and when stdout is not a TTY. Cached for 24h in the platform user-cache dir. Every network / parse failure is swallowed β€” the user's command is never failed by the check.

Motivation

Observed in the wild: users running older CLIs (for example v0.3.0 still installed from PyPI, or v0.4.2 as in #2185) hit No matching release asset found for claude when they try specify init --ai claude. The legacy asset-download path was removed in the Stage 6 migration (#2063) and the release workflow stopped producing those assets starting v0.4.5, so old clients have no recovery path and no signal that the fix is to upgrade the CLI. A launch-time update warning turns this silent failure into actionable guidance.

This PR implements the spec in #1320 with one deliberate change requested in review: opt-in instead of opt-out, so air-gapped / network-constrained environments never reach GitHub by default.

  • Check latest release on launch (only when opted in)
  • Display upgrade command
  • Env-var opt-in (SPECIFY_ENABLE_UPDATE_CHECK=1)
  • Graceful offline handling
  • Cache ≀ 1 check per 24h

Changes

src/specify_cli/__init__.py

  • New private helpers (near get_speckit_version()):
    • _parse_version_tuple() β€” tolerant parser (drops PEP 440 pre/post/dev/local segments)
    • _update_check_cache_path() / _read_update_check_cache() / _write_update_check_cache() β€” JSON cache in platformdirs.user_cache_dir("specify-cli") (UTF-8)
    • _fetch_latest_version() β€” urllib.request GET with 2s timeout; never raises
    • _should_skip_update_check() β€” opt-in gate plus CI / non-TTY guards
    • _check_for_updates() β€” top-level wrapper; all errors swallowed
  • callback() invokes _check_for_updates() for any non-version invocation (including bare specify); version already prints the installed version, so we skip there to avoid double-printing.
  • No new third-party deps β€” platformdirs is already a declared dependency.

tests/test_update_check.py

New tests covering:

  • Version-tuple parsing (happy paths, PEP 440 tails, garbage input, None)
  • Cache read/write (fresh, stale, missing, corrupt, round-trip)
  • urlopen success / network error / malformed JSON / missing tag
  • End-to-end helper behavior: warning text, no-op when up-to-date, cache-hit skips network, network failure is silent, opt-in default-off short-circuits, CI=1 wins over the opt-in flag (with a pinned isatty() so the CI guard is what's actually being tested)

CHANGELOG.md

Entry under ## [Unreleased].

docs/installation.md

"Update Notifications" subsection documenting the opt-in env var and the suppression conditions (CI, non-TTY).

Test plan

  • [x] uv run pytest tests/test_update_check.py β€” 27 passed
  • [x] Manual smoke test β€” SPECIFY_ENABLE_UPDATE_CHECK=1 against a simulated outdated version: warning rendered, cache written, second invocation hit cache and skipped network
  • [x] Default invocation (no env var) β€” banner renders, no warning, no network call

Manual warning output

⚠  A new spec-kit version is available: v0.6.2 (you have v0.3.0)
   Upgrade: uv tool install specify-cli --force --from git+https://github.com/github/[email protected]
   (unset SPECIFY_ENABLE_UPDATE_CHECK to disable this check)

Notes for reviewers

  • Review feedback addressed across two rounds (commits 1ffcbf9 β†’ 81a7418 β†’ e45a36a β†’ b75e55f):
    • Opt-out β†’ opt-in via SPECIFY_ENABLE_UPDATE_CHECK (per @mnriem)
    • Type annotation str | None on _parse_version_tuple
    • Explicit encoding="utf-8" on cache read/write
    • Doc/comment wording: "never fails the command" (cache-miss adds bounded startup latency)
    • Update check now runs on bare specify too
    • test_ci_suppresses_even_when_opted_in pins isatty()=True so it actually verifies the CI guard
  • Related (out of scope): #2185 is a downstream symptom of the same class of problem this PR mitigates.

ATelbay avatar Apr 14 '26 07:04 ATelbay

Hi @mnriem β€” round-2 Copilot feedback addressed in b75e55f:

  • Test brittleness (tests/test_update_check.py:271): test_ci_suppresses_even_when_opted_in now pins sys.stdout.isatty()=True, so it actually verifies the CI guard instead of short-circuiting on the TTY check (verified locally β€” removing the CI guard makes the test fail).
  • PR description / spec mismatch (src/specify_cli/__init__.py:1797): rewrote the PR body so it matches the shipped opt-in behavior (SPECIFY_ENABLE_UPDATE_CHECK=1) β€” the previous body still referenced the original opt-out wording.

All 27 tests in tests/test_update_check.py pass. Ready for another look whenever you have a moment, thanks!

ATelbay avatar Apr 28 '26 08:04 ATelbay

Resolved merge conflict with main in d8c16f7. Only CHANGELOG.md had a real conflict β€” kept the existing ## [Unreleased] entry (the update-check feature) above the new ## [0.8.1] section that landed on main. src/specify_cli/__init__.py and docs/installation.md auto-merged cleanly. Verified locally: tests/test_update_check.py β€” 27/27 pass; remaining suite β€” 838 passed, 29 skipped, 2 unrelated pre-existing failures in tests/test_workflows.py (Gemini CLI quota timeouts, not caused by this PR).

ATelbay avatar Apr 28 '26 10:04 ATelbay

Please address Copilot feedback. If not applicable, please explain why

mnriem avatar Apr 28 '26 14:04 mnriem

@mnriem β€” also rebased onto current main and integrated with #2550 (_version.py extraction). The update-check helpers now live in _version.py next to _get_installed_version / _fetch_latest_release_tag / _is_newer, which we reuse instead of duplicating. Behavior identical (same opt-in env var, same 24h TTL, same negative caching). PR no longer shows as DIRTY.

Tests:

  • tests/test_update_check.py β€” 15/15 pass (negative-cache coverage preserved through the move)
  • tests/test_version_imports.py, tests/test_console_imports.py, tests/test_utils_assets_imports.py, tests/test_cli_version.py β€” 16/16 pass

Ready for another look, thanks!

ATelbay avatar May 16 '26 11:05 ATelbay

Addressed the latest Copilot feedback in c3e063d:

  • Moved startup update-check imports to the top of _version.py to satisfy Ruff E402.
  • Wrapped malformed/unexpected _fetch_latest_release_tag() failures so they write a negative cache entry before returning.
  • Updated the install docs to match the current 5s fetch timeout.
  • Tightened wording from "never blocks" to "never fails" and added regression coverage for exception-backed negative caching.

Checks:

  • uvx ruff check src tests/test_update_check.py
  • PYTHONPATH=src uv run --extra test pytest tests/test_update_check.py tests/test_version_imports.py tests/test_console_imports.py tests/test_cli_version.py β€” 29 passed

ATelbay avatar May 20 '26 13:05 ATelbay

Addressed the latest Copilot feedback and updated the branch with current upstream/main:

  • Reworded the startup update-check comments/docstring from β€œone-line” to β€œupgrade guidance” to match the current three-line output.
  • Changed the upgrade command to use the exact GitHub release tag (latest_tag) instead of hard-coding a v prefix, with regression coverage for tags without v.
  • Added cache validation so malformed latest values are treated as cache misses, plus regression coverage that verifies the helper fetches again.
  • Updated the changelog wording from CI=1 to β€œwhen CI is set”.
  • Merged current upstream/main and resolved the changelog conflict; GitHub now reports the PR as mergeable.

Checks:

  • uvx ruff check src tests/test_update_check.py
  • PYTHONPATH=src uv run --extra test pytest tests/test_update_check.py tests/test_version_imports.py tests/test_console_imports.py tests/test_utils_assets_imports.py tests/test_cli_version.py -q β€” 35 passed

Ready for another look, thanks!

ATelbay avatar May 22 '26 08:05 ATelbay

Please address Copilot feedback

mnriem avatar May 27 '26 12:05 mnriem

Addressed in 8be289d:

  • Hardened _write_update_check_cache() against symlink-based file overwrites β€” destination and parent are checked with is_symlink(), and the write itself uses os.open(..., O_NOFOLLOW, 0o600) so the kernel refuses to follow a symlink even under a TOCTOU race. New regression tests cover both a symlinked cache file and a symlinked parent directory.
  • Reverted CHANGELOG.md to origin/main per your request β€” happy to keep the changelog out of feature PRs going forward.

ATelbay avatar May 28 '26 06:05 ATelbay

Please address Copilot feedback

mnriem avatar May 28 '26 15:05 mnriem

Please address Copilot feedback and revert changes to CHANGELOG.md

mnriem avatar Jun 16 '26 21:06 mnriem

@mnriem Addressed the latest Copilot feedback in 0facef1 and synced the branch with current main in d134ea1:

  • Symlink-hardening tests now skip via pytest.skip when the platform or user cannot create symlinks.
  • The update-check cache writer now uses os.fdopen(...).write() so the full JSON payload is written instead of relying on a single os.write() call.
  • Removed this branch's CHANGELOG.md entry as requested; the PR diff no longer includes the changelog.

Checks: tests/test_update_check.py, tests/test_version_imports.py, tests/test_console_imports.py, tests/test_utils_assets_imports.py, and tests/test_cli_version.py β€” 45 passed; git diff --check upstream/main HEAD passed.

Posted on behalf of @ATelbay by OpenAI Codex.

ATelbay avatar Aug 31 '26 10:08 ATelbay

Please address Copilot feedback

mnriem avatar Sep 01 '26 11:09 mnriem