fix issues (#136)

* fix: prevent delete button click when card is not swiped open

* refactor: improve CreateRepoInput type safety

* security: require AUTH_SECRET and use secure random generation

* fix: SSH key path validation, async passphrase stripping, and port handling

* fix: use correct console methods for logger levels

* Add error handling to DB update functions and improve migration logging

* Add error handling for session lookup in auth middleware

* Add structured git error handling with user-friendly messages

- Parse git errors with specific error codes (AUTH_FAILED, REPO_NOT_FOUND,
  PUSH_REJECTED, MERGE_CONFLICT, etc.) and appropriate HTTP status codes
- Return structured error responses with summary and detail from backend
- Add GitErrorBanner component for better error display in UI
- Add optional onError callback to useGit hook for external error handling

* Make IPC server initialization/disposal async and fix SSH host key handler

* add try-catch error handling in frontend lib utilities

* remove unresolved promise handlers in speech synthesizer callbacks

* Extract error types to shared package

* Import GitErrorCode from shared package

* Refactor API layer to use shared FetchError and fetchWrapper

* Update prompt parser and source control components

* Extract MCP server list to separate component with improved badge menu UX

* merge useSettingsDialogUrl into useSettingsDialog and extract getRepoDisplayName utility

* add separate loading state for passkey sign in

* refactor hooks: use fetchWrapper, improve error handling, add proper types

* replace browser confirm() with DeleteDialog component in settings

* fix: add missing variables parameter in React Query onError callbacks

* Refactor message parts to use separate Zustand store

* Update QuestionPrompt styling for light/dark mode
This commit is contained in:
Chris Scott authored and GitHub committed 2026-02-15 19:48:03 -05:00
1 parent 7f7d106c28
commit 5de419ee28
75 files changed
+1990 -1367

No files matched your search

+286
View File
@@ -0,0 +1,286 @@
import { describe, it, expect } from 'bun:test'
import { parseGitError } from '../../src/utils/git-errors'
describe('parseGitError', () => {
describe('AUTH_FAILED', () => {
it('matches HTTPS authentication failure', () => {
const error = new Error(
'Command failed with code 128: fatal: Authentication failed for \'https://github.com/user/repo.git\''
)
const result = parseGitError(error)
expect(result.code).toBe('AUTH_FAILED')
expect(result.statusCode).toBe(401)
})
it('matches SSH could not read Username', () => {
const error = new Error(
'Command failed with code 128: fatal: could not read Username for \'https://github.com\': terminal prompts disabled'
)
const result = parseGitError(error)
expect(result.code).toBe('AUTH_FAILED')
expect(result.statusCode).toBe(401)
})
})
describe('REPO_NOT_FOUND', () => {
it('matches GitHub 404', () => {
const error = new Error(
'Command failed with code 128: remote: Repository not found.\nfatal: repository \'https://github.com/user/nonexistent.git/\' not found'
)
const result = parseGitError(error)
expect(result.code).toBe('REPO_NOT_FOUND')
expect(result.statusCode).toBe(404)
})
it('matches DNS failure', () => {
const error = new Error(
'Command failed with code 128: fatal: unable to access \'https://notahost.example/repo.git/\': Could not resolve host: notahost.example'
)
const result = parseGitError(error)
expect(result.code).toBe('REPO_NOT_FOUND')
expect(result.statusCode).toBe(404)
})
})
describe('PERMISSION_DENIED', () => {
it('matches SSH permission denied', () => {
const error = new Error(
'Command failed with code 128: git@github.com: Permission denied (publickey).\nfatal: Could not read from remote repository.'
)
const result = parseGitError(error)
expect(result.code).toBe('PERMISSION_DENIED')
expect(result.statusCode).toBe(403)
})
})
describe('PUSH_REJECTED', () => {
it('matches non-fast-forward push rejection with progress lines', () => {
const error = new Error(
'Command failed with code 1: To github.com:user/repo.git\n' +
' ! [rejected] main -> main (non-fast-forward)\n' +
'error: failed to push some refs to \'github.com:user/repo.git\'\n' +
'hint: Updates were rejected because the tip of your current branch is behind\n' +
'hint: its remote counterpart.'
)
const result = parseGitError(error)
expect(result.code).toBe('PUSH_REJECTED')
expect(result.statusCode).toBe(409)
expect(result.detail).toContain('[rejected]')
expect(result.detail).toContain('non-fast-forward')
})
it('matches fetch-first rejection', () => {
const error = new Error(
'Command failed with code 1: error: failed to push some refs\n' +
'hint: Updates were rejected because the remote contains work that you do\n' +
'hint: not have locally. Integrate the remote changes before pushing again.'
)
const result = parseGitError(error)
expect(result.code).toBe('PUSH_REJECTED')
})
})
describe('MERGE_CONFLICT', () => {
it('matches actual merge conflict output', () => {
const error = new Error(
'Command failed with code 1: Auto-merging README.md\n' +
'CONFLICT (content): Merge conflict in README.md\n' +
'Automatic merge failed; fix conflicts and then commit the result.'
)
const result = parseGitError(error)
expect(result.code).toBe('MERGE_CONFLICT')
expect(result.statusCode).toBe(409)
})
it('does NOT false-positive on Auto-merging without CONFLICT', () => {
const error = new Error(
'Command failed with code 1: Auto-merging README.md\n' +
'error: some other unrelated failure occurred'
)
const result = parseGitError(error)
expect(result.code).not.toBe('MERGE_CONFLICT')
})
})
describe('NO_UPSTREAM', () => {
it('matches no upstream branch error', () => {
const error = new Error(
'Command failed with code 128: fatal: The current branch feature-xyz has no upstream branch.\n' +
'To push the current branch and set the remote as upstream, use\n' +
'\n' +
' git push --set-upstream origin feature-xyz'
)
const result = parseGitError(error)
expect(result.code).toBe('NO_UPSTREAM')
expect(result.statusCode).toBe(400)
})
})
describe('TIMEOUT', () => {
it('matches executeCommand timeout format', () => {
const error = new Error('Command timed out after 30000ms: git -C /path/to/repo push')
const result = parseGitError(error)
expect(result.code).toBe('TIMEOUT')
expect(result.statusCode).toBe(504)
})
})
describe('NOT_A_REPO', () => {
it('matches not a git repository', () => {
const error = new Error(
'Command failed with code 128: fatal: not a git repository (or any of the parent directories): .git'
)
const result = parseGitError(error)
expect(result.code).toBe('NOT_A_REPO')
expect(result.statusCode).toBe(400)
})
})
describe('LOCK_FAILED', () => {
it('matches index.lock error', () => {
const error = new Error(
'Command failed with code 128: fatal: Unable to create \'/path/.git/index.lock\': File exists.\n\n' +
'Another git process seems to be running in this repository.'
)
const result = parseGitError(error)
expect(result.code).toBe('LOCK_FAILED')
expect(result.statusCode).toBe(409)
})
})
describe('BRANCH_EXISTS', () => {
it('matches branch already exists', () => {
const error = new Error(
'Command failed with code 128: fatal: A branch named \'feature\' already exists.'
)
const result = parseGitError(error)
expect(result.code).toBe('BRANCH_EXISTS')
expect(result.statusCode).toBe(409)
})
})
describe('BRANCH_NOT_FOUND', () => {
it('matches pathspec did not match', () => {
const error = new Error(
'Command failed with code 1: error: pathspec \'nonexistent\' did not match any file(s) known to git'
)
const result = parseGitError(error)
expect(result.code).toBe('BRANCH_NOT_FOUND')
expect(result.statusCode).toBe(404)
})
})
describe('UNCOMMITTED_CHANGES', () => {
it('matches local changes would be overwritten', () => {
const error = new Error(
'Command failed with code 1: error: Your local changes to the following files would be overwritten by merge:\n' +
'\tREADME.md\n' +
'Please commit your changes or stash them before you merge.'
)
const result = parseGitError(error)
expect(result.code).toBe('UNCOMMITTED_CHANGES')
expect(result.statusCode).toBe(409)
})
})
describe('UNKNOWN', () => {
it('falls back for unrecognized errors', () => {
const error = new Error('Command failed with code 1: something completely unexpected happened')
const result = parseGitError(error)
expect(result.code).toBe('UNKNOWN')
expect(result.statusCode).toBe(500)
expect(result.summary).toBe('A git operation failed.')
expect(result.detail).toBe('something completely unexpected happened')
})
it('handles non-Error input', () => {
const result = parseGitError('a string error')
expect(result.code).toBe('UNKNOWN')
expect(result.detail).toBe('a string error')
})
it('handles object with message', () => {
const result = parseGitError({ message: 'object error' })
expect(result.code).toBe('UNKNOWN')
expect(result.detail).toBe('object error')
})
})
describe('prefix stripping', () => {
it('strips Command failed prefix', () => {
const error = new Error('Command failed with code 128: fatal: not a git repository')
const result = parseGitError(error)
expect(result.detail).not.toContain('Command failed with code')
})
it('handles errors without prefix', () => {
const error = new Error('Repository not found')
const result = parseGitError(error)
expect(result.code).toBe('REPO_NOT_FOUND')
})
})
describe('progress line cleaning', () => {
it('strips remote progress lines from detail', () => {
const error = new Error(
'Command failed with code 128: remote: Counting objects: 100% (10/10), done.\n' +
'remote: Compressing objects: 100% (5/5), done.\n' +
'remote: Total 10 (delta 3), reused 10 (delta 3)\n' +
'fatal: Authentication failed for \'https://github.com/user/repo.git\''
)
const result = parseGitError(error)
expect(result.code).toBe('AUTH_FAILED')
expect(result.detail).not.toContain('Counting objects')
expect(result.detail).not.toContain('Compressing objects')
expect(result.detail).toContain('Authentication failed')
})
it('preserves rejection lines in detail', () => {
const error = new Error(
'Command failed with code 1: To github.com:user/repo.git\n' +
' ! [rejected] main -> main (non-fast-forward)\n' +
'error: failed to push some refs'
)
const result = parseGitError(error)
expect(result.detail).toContain('[rejected]')
expect(result.detail).toContain('main -> main')
})
it('strips tracking branch lines but not error lines with arrows', () => {
const error = new Error(
'Command failed with code 128: From github.com:user/repo\n' +
' * [new branch] dev -> origin/dev\n' +
' abc1234..def5678 main -> origin/main\n' +
'fatal: not a git repository'
)
const result = parseGitError(error)
expect(result.detail).not.toContain('origin/dev')
expect(result.detail).not.toContain('abc1234..def5678')
expect(result.detail).toContain('not a git repository')
})
it('collapses excessive blank lines', () => {
const error = new Error(
'Command failed with code 1: remote: Counting objects: done.\n\n\nfatal: error message here'
)
const result = parseGitError(error)
const consecutiveNewlines = result.detail.match(/\n{3,}/g)
expect(consecutiveNewlines).toBeNull()
})
})
describe('GitService plain Error passthrough', () => {
it('handles GitService "Repository not found" throw', () => {
const error = new Error('Repository not found')
const result = parseGitError(error)
expect(result.code).toBe('REPO_NOT_FOUND')
expect(result.statusCode).toBe(404)
})
it('handles GitService "Unable to detect current branch" as UNKNOWN', () => {
const error = new Error('Unable to detect current branch. Ensure you are on a branch before pushing with --set-upstream.')
const result = parseGitError(error)
expect(result.code).toBe('UNKNOWN')
})
})
})