diff --git a/src/utils/testRepoManager.ts b/src/utils/testRepoManager.ts index bd33e22..5a93d45 100644 --- a/src/utils/testRepoManager.ts +++ b/src/utils/testRepoManager.ts @@ -13,7 +13,6 @@ export class TestRepoManager { private repoDir: string | null = null; private constructor() { - // Initialize repoDir to a fixed location this.repoDir = path.join(os.tmpdir(), "hxckr-test-repo"); } @@ -26,19 +25,20 @@ export class TestRepoManager { private async initializeRepo(): Promise { try { - // Check if directory exists - const exists = await fs - .access(this.repoDir!) + await fs.mkdir(this.repoDir!, { recursive: true }); + const isGitRepo = await fs + .access(path.join(this.repoDir!, ".git")) .then(() => true) .catch(() => false); - if (!exists) { - // First time: Clone the repository - await fs.mkdir(this.repoDir!, { recursive: true }); + if (!isGitRepo) { await execAsync( `git clone -b ${TEST_REPO_CONFIG.branch} ${TEST_REPO_CONFIG.repoUrl} ${this.repoDir}`, ); logger.info("Test repository cloned successfully"); + } else { + await execAsync(`cd ${this.repoDir} && git pull`); + logger.info("Test repository updated successfully"); } } catch (error) { logger.error("Error initializing test repository", { error }); @@ -46,20 +46,11 @@ export class TestRepoManager { } } - private async updateRepo(): Promise { - try { - await execAsync(`cd ${this.repoDir} && git pull --rebase`); - logger.info("Test repository updated successfully"); - } catch (error) { - logger.error("Error updating test repository", { error }); - throw error; - } - } - public static getTestExtension(language: string): string { const extensions: Record = { typescript: ".test.ts", rust: ".test.rs", + python: "_test.py", // Add more languages as needed }; return extensions[language] || ".test"; @@ -67,9 +58,7 @@ export class TestRepoManager { private async ensureRepoUpdated(): Promise { try { - // Initialize repo if it doesn't exist await this.initializeRepo(); - return this.repoDir!; } catch (error) { logger.error("Error ensuring repo is updated", { error }); @@ -92,7 +81,9 @@ export class TestRepoManager { ); try { - return await fs.readFile(testPath, "utf-8"); + const content = await fs.readFile(testPath, "utf-8"); + logger.info("Test content retrieved successfully"); + return content; } catch (error) { logger.error("Error reading test file", { testPath, @@ -105,11 +96,10 @@ export class TestRepoManager { } } - // We don't need cleanup anymore since we're keeping the repo - // But we might want a method to force update public async forceUpdate(): Promise { try { - await this.updateRepo(); + await execAsync(`cd ${this.repoDir} && git pull`); + logger.info("Test repository force updated successfully"); } catch (error) { logger.error("Error forcing update", { error }); throw error;