Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Code Quality

on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]

jobs:
quality:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: Install dependencies
run: bun install --frozen-lockfile

- name: Run Biome check
run: bunx @biomejs/biome ci ./src

- name: Type check
run: bun run build
29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Tests

on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: Install dependencies
run: bun install --frozen-lockfile

- name: Run tests
run: bun test

- name: Run tests with coverage
run: bun test --coverage
126 changes: 126 additions & 0 deletions CORREÇÕES_REALIZADAS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Correções Realizadas nos Workflows

## 🔧 Problemas Identificados e Soluções

### 1. Erro no Workflow de Code Quality

**Problema:**
```
Error: `--check` is not expected in this context
```

**Causa:**
O comando `bunx @biomejs/biome format --check ./src` estava incorreto. O Biome não usa `--check` no comando `format`.

**Solução:**
Substituído por `bunx @biomejs/biome ci ./src` que é o comando recomendado para CI environments. Este comando:
- Verifica formatação
- Executa o linter
- Falha se houver problemas

### 2. Remoção da Integração com Codecov

**Problema:**
O usuário não queria integração com codecov.

**Solução:**
Removido o step de upload para codecov do workflow de testes:
```yaml
# REMOVIDO:
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: coverage/coverage-final.json
fail_ci_if_error: false
```

## ✅ Workflows Corrigidos

### `.github/workflows/test.yml`
```yaml
name: Tests

on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: Install dependencies
run: bun install --frozen-lockfile

- name: Run tests
run: bun test

- name: Run tests with coverage
run: bun test --coverage
```

### `.github/workflows/quality.yml`
```yaml
name: Code Quality

on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]

jobs:
quality:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: Install dependencies
run: bun install --frozen-lockfile

- name: Run Biome check
run: bunx @biomejs/biome ci ./src

- name: Type check
run: bun run build
```

## 📊 Benefícios das Correções

1. **Workflow de Qualidade Funcional**: Agora usa o comando correto do Biome
2. **Sem Dependências Externas**: Não depende mais do codecov
3. **Mais Eficiente**: Um único comando do Biome para lint + format
4. **Padronizado**: Segue as melhores práticas do Biome para CI

## 🧪 Testes Validados

✅ **23 testes passando**
✅ **0 testes falhando**
✅ **87.18% de coverage**
✅ **Workflows corrigidos**
✅ **Documentação atualizada**

## 📝 Documentação Atualizada

- `TEST_IMPLEMENTATION.md`: Removidas referências ao codecov
- `tests/README.md`: Adicionada menção ao workflow de qualidade
- `CORREÇÕES_REALIZADAS.md`: Este arquivo com o resumo das correções

Os workflows agora estão prontos para uso e não devem mais apresentar erros!
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,22 @@ The tool will guide you through the process:
# Using bun
bun run build
```
* **Testing:** (Basic setup exists)
* **Testing:** Complete test suite with Bun
```bash
npm test

# Using bun
# Run all tests
bun test

# Run tests with coverage
bun test --coverage

# Run tests in watch mode
bun test --watch

# Run specific test file
bun test tests/utils/errors.test.ts
```

**Test Coverage:** 87.18% - See `tests/README.md` for detailed testing documentation.

## Unlinking

Expand Down
148 changes: 148 additions & 0 deletions TEST_IMPLEMENTATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# Implementação de Testes - GitLift

## Resumo

Foi implementada uma estrutura completa de testes para o projeto GitLift usando o Bun como runtime de testes, seguindo as melhores práticas e padrões similares aos utilizados nas pastas de rules do Cursor.

## ✅ O que foi implementado

### 1. Estrutura de Testes
- **tests/utils/errors.test.ts**: Testes para parsing de erros da API de IA
- **tests/core/prerequisites.test.ts**: Testes para verificação de pré-requisitos
- **tests/config/config.test.ts**: Testes para carregamento e validação de configurações
- **tests/ui/theme.test.ts**: Testes para funcionalidade de cores e formatação
- **tests/setup.ts**: Configuração inicial dos testes

### 2. Scripts de Teste no package.json
```json
{
"scripts": {
"test": "bun test",
"test:watch": "bun test --watch",
"test:coverage": "bun test --coverage"
}
}
```

### 3. CI/CD GitHub Actions
- **`.github/workflows/test.yml`**: Workflow para executar testes automaticamente
- **`.github/workflows/quality.yml`**: Workflow para verificar qualidade do código
- Execução automática em PRs e pushes para `main` e `develop`
- Coverage report gerado localmente

### 4. Documentação
- **tests/README.md**: Documentação completa da estrutura de testes
- Exemplos de uso e padrões de teste
- Guia de contribuição

## 📊 Cobertura de Testes

**Coverage atual: 87.18%**

| Arquivo | % Funções | % Linhas | Status |
|---------|-----------|----------|--------|
| src/config/config.ts | 100% | 100% | ✅ |
| src/ui/theme.ts | 100% | 100% | ✅ |
| src/utils/errors.ts | 100% | 100% | ✅ |
| src/core/prerequisites.ts | 100% | 48.72% | ⚠️ |

## 🧪 Testes Implementados

### 1. Testes de Utilitários (8 testes)
- ✅ Parsing de erros da API de IA
- ✅ Diferentes tipos de erros (rate limit, API key, model not found, etc.)
- ✅ Handling de erros não-Error objects
- ✅ Tratamento de null/undefined

### 2. Testes de Pré-requisitos (3 testes)
- ✅ Verificação de OPENAI_API_KEY
- ✅ Verificação de disponibilidade de comandos
- ✅ Tratamento de erros desconhecidos

### 3. Testes de Configuração (7 testes)
- ✅ Carregamento de configuração padrão
- ✅ Merge de configurações customizadas
- ✅ Validação de schema
- ✅ Tratamento de JSON inválido
- ✅ Validação de tipos

### 4. Testes de Interface (5 testes)
- ✅ Verificação de funções de tema
- ✅ Retorno de strings
- ✅ Preservação de conteúdo
- ✅ Tratamento de strings vazias
- ✅ Suporte a caracteres especiais

## 🚀 CI/CD Configurado

### Workflows do GitHub Actions:
1. **Tests** (test.yml):
- Executa em Ubuntu latest
- Instala Bun
- Executa testes
- Gera coverage report

2. **Code Quality** (quality.yml):
- Verificação de formatação e lint com Biome
- Type checking com TypeScript

### Triggers:
- ✅ Pull Requests para `main` e `develop`
- ✅ Push para `main` e `develop`
- ✅ Falha se testes não passarem

## 🔧 Como Usar

### Executar Testes Localmente:
```bash
# Todos os testes
bun test

# Com coverage
bun test --coverage

# Modo watch
bun test:watch

# Teste específico
bun test tests/utils/errors.test.ts
```

### Adicionar Novos Testes:
1. Criar arquivo `*.test.ts` na pasta apropriada
2. Seguir padrão de naming e estrutura
3. Importar funções do Bun test
4. Executar testes para verificar

## 📋 Próximos Passos

Para expandir a cobertura de testes:

1. **Testes de Integração**:
- Testar fluxos completos de comandos
- Mocking de APIs externas (OpenAI, GitHub)

2. **Testes de Commands**:
- `src/commands/init.ts`
- `src/commands/generate/`

3. **Testes de Core**:
- `src/core/git.ts`
- `src/core/github.ts`
- `src/core/ai.ts`

4. **Testes End-to-End**:
- Testes de CLI completos
- Cenários de uso real

## ✨ Recursos Implementados

- ✅ Runtime de testes moderno (Bun)
- ✅ Coverage reporting
- ✅ CI/CD automatizado
- ✅ Documentação completa
- ✅ Padrões de teste consistentes
- ✅ Setup de testes configurado
- ✅ Workflows de qualidade de código

**Total: 23 testes implementados, todos passando! 🎉**
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"dev": "bun run src/cli.ts",
"build": "tsc",
"start": "bun run src/cli.ts",
"test": "bun test",
"test:watch": "bun test --watch",
"test:coverage": "bun test --coverage",
"prepublishOnly": "bun run build"
},
"author": "arthurbm",
Expand Down
Loading