From cbcdf3aa04262fe0dc13ba0b9d68c868fa3ccc5e Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Tue, 3 Feb 2026 07:58:12 +0000 Subject: [PATCH] Add tests, templates, and Gitea Actions workflows --- .tests/unit/errors.test.ts | 75 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 .tests/unit/errors.test.ts diff --git a/.tests/unit/errors.test.ts b/.tests/unit/errors.test.ts new file mode 100644 index 0000000..befd810 --- /dev/null +++ b/.tests/unit/errors.test.ts @@ -0,0 +1,75 @@ +import { + GitAgentSyncError, + WorkspaceExistsError, + WorkspaceNotFoundError, + InvalidAgentNameError, + MergeConflictError, + handleError, + formatError +} from '../../src/utils/errors'; + +describe('Error classes', () => { + it('should create GitAgentSyncError with code', () => { + const error = new GitAgentSyncError('Test error', 'TEST_CODE'); + expect(error.message).toBe('Test error'); + expect(error.code).toBe('TEST_CODE'); + expect(error.name).toBe('GitAgentSyncError'); + }); + + it('should create WorkspaceExistsError with details', () => { + const error = new WorkspaceExistsError('agent-1', '/path/to/workspace'); + expect(error.message).toContain('agent-1'); + expect(error.message).toContain('/path/to/workspace'); + expect(error.code).toBe('WORKSPACE_EXISTS'); + expect(error.details?.agentName).toBe('agent-1'); + }); + + it('should create WorkspaceNotFoundError', () => { + const error = new WorkspaceNotFoundError('agent-2'); + expect(error.message).toContain('agent-2'); + expect(error.code).toBe('WORKSPACE_NOT_FOUND'); + }); + + it('should create InvalidAgentNameError', () => { + const error = new InvalidAgentNameError('invalid@name'); + expect(error.message).toContain('invalid@name'); + expect(error.code).toBe('INVALID_AGENT_NAME'); + }); + + it('should create MergeConflictError with file list', () => { + const error = new MergeConflictError(['file1.ts', 'file2.ts']); + expect(error.message).toContain('file1.ts'); + expect(error.message).toContain('file2.ts'); + expect(error.code).toBe('MERGE_CONFLICT'); + }); +}); + +describe('handleError', () => { + it('should pass through GitAgentSyncError', () => { + const error = new GitAgentSyncError('test', 'CODE'); + const result = handleError(error); + expect(result).toBe(error); + }); + + it('should wrap unknown errors', () => { + const result = handleError(new Error('unknown error')); + expect(result).toBeInstanceOf(GitAgentSyncError); + expect(result.message).toBe('unknown error'); + }); + + it('should handle non-Error objects', () => { + const result = handleError('string error'); + expect(result).toBeInstanceOf(GitAgentSyncError); + expect(result.message).toBe('string error'); + }); +}); + +describe('formatError', () => { + it('should format error with color and details', () => { + const error = new GitAgentSyncError('Test error', 'TEST_CODE', { key: 'value' }); + const formatted = formatError(error); + expect(formatted).toContain('Test error'); + expect(formatted).toContain('TEST_CODE'); + expect(formatted).toContain('key'); + }); +});