fix(core): use dedicated temp subdirectory for GSD temp files (#1975) (#2100)

Move GSD temp file writes from os.tmpdir() root to os.tmpdir()/gsd
subdirectory. This limits reapStaleTempFiles() scan to only GSD files
instead of scanning the entire system temp directory.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Tom Boucher
2026-04-11 09:15:00 -04:00
committed by GitHub
parent 6b0e3904c2
commit f34dc66fa9
3 changed files with 161 additions and 10 deletions

View File

@@ -1629,9 +1629,11 @@ describe('findProjectRoot', () => {
// ─── reapStaleTempFiles ─────────────────────────────────────────────────────
describe('reapStaleTempFiles', () => {
const gsdTmpDir = path.join(os.tmpdir(), 'gsd');
test('removes stale gsd-*.json files older than maxAgeMs', () => {
const tmpDir = os.tmpdir();
const stalePath = path.join(tmpDir, `gsd-reap-test-${Date.now()}.json`);
fs.mkdirSync(gsdTmpDir, { recursive: true });
const stalePath = path.join(gsdTmpDir, `gsd-reap-test-${Date.now()}.json`);
fs.writeFileSync(stalePath, '{}');
// Set mtime to 10 minutes ago
const oldTime = new Date(Date.now() - 10 * 60 * 1000);
@@ -1643,8 +1645,8 @@ describe('reapStaleTempFiles', () => {
});
test('preserves fresh gsd-*.json files', () => {
const tmpDir = os.tmpdir();
const freshPath = path.join(tmpDir, `gsd-reap-fresh-${Date.now()}.json`);
fs.mkdirSync(gsdTmpDir, { recursive: true });
const freshPath = path.join(gsdTmpDir, `gsd-reap-fresh-${Date.now()}.json`);
fs.writeFileSync(freshPath, '{}');
reapStaleTempFiles('gsd-reap-fresh-', { maxAgeMs: 5 * 60 * 1000 });
@@ -1655,8 +1657,8 @@ describe('reapStaleTempFiles', () => {
});
test('removes stale temp directories when present', () => {
const tmpDir = os.tmpdir();
const staleDir = fs.mkdtempSync(path.join(tmpDir, 'gsd-reap-dir-'));
fs.mkdirSync(gsdTmpDir, { recursive: true });
const staleDir = fs.mkdtempSync(path.join(gsdTmpDir, 'gsd-reap-dir-'));
fs.writeFileSync(path.join(staleDir, 'data.jsonl'), 'test');
// Set mtime to 10 minutes ago
const oldTime = new Date(Date.now() - 10 * 60 * 1000);