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:
Garry Tan
2026-03-14 13:23:25 -05:00
parent 4e31acbd47
commit baf8acd55c
2 changed files with 19 additions and 1 deletions
+13
View File
@@ -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');