UNPKG

create-ai-chat-context-experimental

Version:

Phase 2: TypeScript rewrite - AI Chat Context & Memory System with conversation extraction and AICF format support (powered by aicf-core v2.1.0).

94 lines 3.05 kB
"use strict"; /** * This file is part of create-ai-chat-context-experimental. * Licensed under the GNU Affero General Public License v3.0 or later (AGPL-3.0-or-later). * See LICENSE file for details. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.TestDirManager = void 0; exports.getTestOutputDir = getTestOutputDir; exports.createTestDir = createTestDir; exports.cleanupTestDir = cleanupTestDir; /** * Test Helpers * Utilities for creating and managing test directories */ const fs_1 = require("fs"); const path_1 = require("path"); /** * Get the centralized test output directory * All test artifacts should be created within this directory */ function getTestOutputDir() { const testOutputDir = (0, path_1.join)(process.cwd(), '.test-output'); return testOutputDir; } /** * Create a temporary test directory within the centralized test output folder * @param prefix - Prefix for the temporary directory name * @returns Path to the created temporary directory */ function createTestDir(prefix = 'test-') { const testOutputDir = getTestOutputDir(); const testDir = (0, fs_1.mkdtempSync)((0, path_1.join)(testOutputDir, prefix)); return testDir; } /** * Clean up a test directory with retry logic * @param testDir - Path to the test directory to clean up * @param maxAttempts - Maximum number of cleanup attempts (default: 3) */ function cleanupTestDir(testDir, maxAttempts = 3) { if (!(0, fs_1.existsSync)(testDir)) return; // Retry cleanup up to maxAttempts times with delays (handles file locks) let attempts = 0; while (attempts < maxAttempts) { try { (0, fs_1.rmSync)(testDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 }); return; // Success } catch (error) { attempts++; if (attempts >= maxAttempts) { console.warn(`Failed to cleanup ${testDir} after ${maxAttempts} attempts:`, error); } } } } /** * Create a test directory manager that tracks all created directories * and provides automatic cleanup */ class TestDirManager { testDirs = []; /** * Create a new test directory * @param prefix - Prefix for the temporary directory name * @returns Path to the created temporary directory */ create(prefix = 'test-') { const testDir = createTestDir(prefix); this.testDirs.push(testDir); return testDir; } /** * Clean up a specific test directory * @param testDir - Path to the test directory to clean up */ cleanup(testDir) { cleanupTestDir(testDir); this.testDirs = this.testDirs.filter((dir) => dir !== testDir); } /** * Clean up all test directories created by this manager */ cleanupAll() { for (const testDir of this.testDirs) { cleanupTestDir(testDir); } this.testDirs = []; } } exports.TestDirManager = TestDirManager; //# sourceMappingURL=test-helpers.js.map