mirror of
https://github.com/garrytan/gstack.git
synced 2026-07-09 17:38:40 +02:00
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:
@@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { describe, test, expect, beforeEach, afterEach } from 'bun:test';
|
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 { join } from 'path';
|
||||||
import { tmpdir } from 'os';
|
import { tmpdir } from 'os';
|
||||||
|
|
||||||
@@ -160,6 +160,21 @@ describe('gstack-update-check', () => {
|
|||||||
expect(cache).toContain('UP_TO_DATE');
|
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 ─────────────────────────────────────
|
// ─── State dir creation ─────────────────────────────────────
|
||||||
test('creates state dir if it does not exist', () => {
|
test('creates state dir if it does not exist', () => {
|
||||||
const newStateDir = join(stateDir, 'nested', 'dir');
|
const newStateDir = join(stateDir, 'nested', 'dir');
|
||||||
|
|||||||
Reference in New Issue
Block a user