mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-01 19:25:10 +02:00
fix: update check ignores stale UP_TO_DATE cache after version change
The UP_TO_DATE cache path exited immediately without checking if the cached version still matched the local VERSION. After upgrading (e.g. 0.3.3 → 0.3.4), the cache still said "UP_TO_DATE 0.3.3" and the script never re-checked against remote — so updates were invisible until the 24h cache expired. Now both UP_TO_DATE and UPGRADE_AVAILABLE verify cached version vs local before trusting the cache. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -49,7 +49,12 @@ if [ -f "$CACHE_FILE" ]; then
|
||||
CACHED="$(cat "$CACHE_FILE" 2>/dev/null || true)"
|
||||
case "$CACHED" in
|
||||
UP_TO_DATE*)
|
||||
exit 0
|
||||
# Verify local version still matches cached version
|
||||
CACHED_VER="$(echo "$CACHED" | awk '{print $2}')"
|
||||
if [ "$CACHED_VER" = "$LOCAL" ]; then
|
||||
exit 0
|
||||
fi
|
||||
# Local version changed — fall through to re-check
|
||||
;;
|
||||
UPGRADE_AVAILABLE*)
|
||||
# Verify local version still matches cached old version
|
||||
|
||||
@@ -86,6 +86,19 @@ describe('gstack-update-check', () => {
|
||||
expect(stdout).toBe('');
|
||||
});
|
||||
|
||||
// ─── Path D1b: Fresh UP_TO_DATE cache, but local version changed ──
|
||||
test('re-checks when UP_TO_DATE cache version does not match local', () => {
|
||||
writeFileSync(join(gstackDir, 'VERSION'), '0.4.0\n');
|
||||
// Cache says UP_TO_DATE for 0.3.3, but local is now 0.4.0
|
||||
writeFileSync(join(stateDir, 'last-update-check'), 'UP_TO_DATE 0.3.3');
|
||||
// Remote says 0.5.0 — should detect upgrade
|
||||
writeFileSync(join(gstackDir, 'REMOTE_VERSION'), '0.5.0\n');
|
||||
|
||||
const { exitCode, stdout } = run();
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toBe('UPGRADE_AVAILABLE 0.4.0 0.5.0');
|
||||
});
|
||||
|
||||
// ─── Path D2: Fresh cache, UPGRADE_AVAILABLE ────────────────
|
||||
test('echoes cached UPGRADE_AVAILABLE when cache is fresh', () => {
|
||||
writeFileSync(join(gstackDir, 'VERSION'), '0.3.3\n');
|
||||
|
||||
Reference in New Issue
Block a user