fix: remove unused import + add corrupt cache test

Address pre-landing review findings:
- Remove unused mkdirSync import from gstack-update-check.test.ts
- Add Path I test: corrupt cache file falls through to remote fetch

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-03-14 00:14:46 -05:00
parent f43c962b50
commit 650680443e
+16 -1
View File
@@ -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');