-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Error Handling and Test Coverage Improvements #171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d73be1d
feat(bin): enhance error handling in CLI entry point
yamadashy 5965b3f
chore(ci): update CI workflow to use repomix.cjs
yamadashy 8a94241
feat(bin): improve error handling in repomix.cjs
yamadashy e34a8da
test(core): improve test coverage for core components
yamadashy 47b179b
test(core): improve test coverage
yamadashy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,57 @@ | ||
| #!/usr/bin/env node | ||
| 'use strict'; | ||
|
|
||
| const nodeVersion = process.versions.node; | ||
| const [major] = nodeVersion.split('.').map(Number); | ||
|
|
||
| const EXIT_CODES = { | ||
| SUCCESS: 0, | ||
| ERROR: 1, | ||
| }; | ||
|
|
||
| if (major < 16) { | ||
| console.error(`Repomix requires Node.js version 16 or higher. Current version: ${nodeVersion}\n`); | ||
| process.exit(EXIT_CODES.ERROR); | ||
| } | ||
|
|
||
| function setupErrorHandlers() { | ||
| process.on('uncaughtException', (error) => { | ||
| console.error('Uncaught Exception:', error); | ||
| process.exit(EXIT_CODES.ERROR); | ||
| }); | ||
|
|
||
| process.on('unhandledRejection', (reason) => { | ||
| console.error('Unhandled Promise Rejection:', reason); | ||
| process.exit(EXIT_CODES.ERROR); | ||
| }); | ||
|
|
||
| function shutdown() { | ||
| process.exit(EXIT_CODES.SUCCESS); | ||
| } | ||
|
|
||
| process.on('SIGINT', () => { | ||
| console.log('\nReceived SIGINT. Shutting down...'); | ||
| shutdown(); | ||
| }); | ||
| process.on('SIGTERM', shutdown); | ||
| } | ||
|
|
||
| (async () => { | ||
| const { run } = await import('../lib/cli/cliRun.js'); | ||
| run(); | ||
| try { | ||
| setupErrorHandlers(); | ||
|
|
||
| const { run } = await import('../lib/cli/cliRun.js'); | ||
|
yamadashy marked this conversation as resolved.
|
||
| await run(); | ||
| } catch (error) { | ||
| if (error instanceof Error) { | ||
| console.error('Fatal Error:', { | ||
| name: error.name, | ||
| message: error.message, | ||
| stack: error.stack, | ||
| }); | ||
| } else { | ||
| console.error('Fatal Error:', error); | ||
| } | ||
|
|
||
| process.exit(EXIT_CODES.ERROR); | ||
| } | ||
| })(); | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,43 +1,85 @@ | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import { formatGitUrl } from '../../../src/cli/actions/remoteAction.js'; | ||
| import * as fs from 'node:fs/promises'; | ||
| import * as os from 'node:os'; | ||
| import path from 'node:path'; | ||
| import { beforeEach, describe, expect, test, vi } from 'vitest'; | ||
| import { | ||
| checkGitInstallation, | ||
| cleanupTempDirectory, | ||
| copyOutputToCurrentDirectory, | ||
| createTempDirectory, | ||
| formatGitUrl, | ||
| runRemoteAction, | ||
| } from '../../../src/cli/actions/remoteAction.js'; | ||
|
|
||
| vi.mock('node:fs/promises'); | ||
| vi.mock('node:child_process'); | ||
| vi.mock('../../../src/cli/actions/defaultAction.js'); | ||
| vi.mock('../../../src/shared/logger.js'); | ||
| vi.mock('node:fs/promises', async (importOriginal) => { | ||
| const actual = await importOriginal<typeof import('node:fs/promises')>(); | ||
| return { | ||
| ...actual, | ||
| copyFile: vi.fn(), | ||
| }; | ||
| }); | ||
| vi.mock('../../../src/shared/logger'); | ||
|
|
||
| describe('remoteAction', () => { | ||
| describe('remoteAction functions', () => { | ||
| beforeEach(() => { | ||
| vi.resetAllMocks(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.restoreAllMocks(); | ||
| describe('runRemoteAction', () => { | ||
| test('should clone the repository', async () => { | ||
| vi.mocked(fs.copyFile).mockResolvedValue(undefined); | ||
| await runRemoteAction('yamadashy/repomix', {}); | ||
| }); | ||
| }); | ||
|
yamadashy marked this conversation as resolved.
|
||
|
|
||
| describe('checkGitInstallation Integration', () => { | ||
| test('should detect git installation in real environment', async () => { | ||
| const result = await checkGitInstallation(); | ||
| expect(result).toBe(true); | ||
| }); | ||
|
yamadashy marked this conversation as resolved.
|
||
| }); | ||
|
|
||
| describe('formatGitUrl', () => { | ||
| it('should format GitHub shorthand correctly', () => { | ||
| test('should convert GitHub shorthand to full URL', () => { | ||
| expect(formatGitUrl('user/repo')).toBe('https://github.com/user/repo.git'); | ||
| expect(formatGitUrl('user-name/repo-name')).toBe('https://github.com/user-name/repo-name.git'); | ||
| expect(formatGitUrl('user_name/repo_name')).toBe('https://github.com/user_name/repo_name.git'); | ||
| }); | ||
|
|
||
| it('should add .git to HTTPS URLs if missing', () => { | ||
| test('should handle HTTPS URLs', () => { | ||
| expect(formatGitUrl('https://github.com/user/repo')).toBe('https://github.com/user/repo.git'); | ||
| expect(formatGitUrl('https://github.com/user/repo.git')).toBe('https://github.com/user/repo.git'); | ||
| }); | ||
|
|
||
| it('should not modify URLs that are already correctly formatted', () => { | ||
| expect(formatGitUrl('https://github.com/user/repo.git')).toBe('https://github.com/user/repo.git'); | ||
| expect(formatGitUrl('git@github.com:user/repo.git')).toBe('git@github.com:user/repo.git'); | ||
| test('should not modify SSH URLs', () => { | ||
| const sshUrl = 'git@github.com:user/repo.git'; | ||
| expect(formatGitUrl(sshUrl)).toBe(sshUrl); | ||
| }); | ||
| }); | ||
|
|
||
| describe('copyOutputToCurrentDirectory', () => { | ||
| test('should copy output file', async () => { | ||
| const sourceDir = '/source/dir'; | ||
| const targetDir = '/target/dir'; | ||
| const fileName = 'output.txt'; | ||
|
|
||
| vi.mocked(fs.copyFile).mockResolvedValue(); | ||
|
|
||
| it('should not modify SSH URLs', () => { | ||
| expect(formatGitUrl('git@github.com:user/repo.git')).toBe('git@github.com:user/repo.git'); | ||
| await copyOutputToCurrentDirectory(sourceDir, targetDir, fileName); | ||
|
|
||
| expect(fs.copyFile).toHaveBeenCalledWith(path.join(sourceDir, fileName), path.join(targetDir, fileName)); | ||
| }); | ||
|
|
||
| it('should not modify URLs from other Git hosting services', () => { | ||
| expect(formatGitUrl('https://gitlab.com/user/repo.git')).toBe('https://gitlab.com/user/repo.git'); | ||
| expect(formatGitUrl('https://bitbucket.org/user/repo.git')).toBe('https://bitbucket.org/user/repo.git'); | ||
| test('should throw error when copy fails', async () => { | ||
| const sourceDir = '/source/dir'; | ||
| const targetDir = '/target/dir'; | ||
| const fileName = 'output.txt'; | ||
|
|
||
| vi.mocked(fs.copyFile).mockRejectedValue(new Error('Permission denied')); | ||
|
|
||
| await expect(copyOutputToCurrentDirectory(sourceDir, targetDir, fileName)).rejects.toThrow( | ||
| 'Failed to copy output file', | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.