diff --git a/browse/test/gstack-update-check.test.ts b/browse/test/gstack-update-check.test.ts index 7856f03d..ac674b3d 100644 --- a/browse/test/gstack-update-check.test.ts +++ b/browse/test/gstack-update-check.test.ts @@ -7,7 +7,7 @@ */ import { describe, test, expect, beforeEach, afterEach } from 'bun:test'; -import { mkdtempSync, writeFileSync, rmSync, existsSync, readFileSync, mkdirSync } from 'fs'; +import { mkdtempSync, writeFileSync, rmSync, existsSync, readFileSync } from 'fs'; import { join } from 'path'; import { tmpdir } from 'os'; @@ -160,6 +160,21 @@ describe('gstack-update-check', () => { expect(cache).toContain('UP_TO_DATE'); }); + // ─── Path I: Corrupt cache file ───────────────────────────── + test('falls through to remote fetch when cache is corrupt', () => { + writeFileSync(join(gstackDir, 'VERSION'), '0.3.3\n'); + writeFileSync(join(stateDir, 'last-update-check'), 'garbage data here'); + // Remote says same version — should end up UP_TO_DATE + writeFileSync(join(gstackDir, 'REMOTE_VERSION'), '0.3.3\n'); + + const { exitCode, stdout } = run(); + expect(exitCode).toBe(0); + expect(stdout).toBe(''); + // Cache should be overwritten with valid content + const cache = readFileSync(join(stateDir, 'last-update-check'), 'utf-8'); + expect(cache).toContain('UP_TO_DATE'); + }); + // ─── State dir creation ───────────────────────────────────── test('creates state dir if it does not exist', () => { const newStateDir = join(stateDir, 'nested', 'dir');