airev 1.1.1__tar.gz → 1.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {airev-1.1.1 → airev-1.2.0}/PKG-INFO +1 -1
- {airev-1.1.1 → airev-1.2.0}/src/airev.egg-info/PKG-INFO +1 -1
- {airev-1.1.1 → airev-1.2.0}/src/code_reviewer/__init__.py +1 -1
- {airev-1.1.1 → airev-1.2.0}/src/code_reviewer/cli.py +6 -6
- {airev-1.1.1 → airev-1.2.0}/src/code_reviewer/updater/__init__.py +2 -1
- {airev-1.1.1 → airev-1.2.0}/src/code_reviewer/updater/http_client.py +1 -1
- airev-1.2.0/src/code_reviewer/updater/upgrade.py +182 -0
- {airev-1.1.1 → airev-1.2.0}/src/code_reviewer/updater/version_check.py +18 -0
- {airev-1.1.1 → airev-1.2.0}/tests/test_updater.py +215 -8
- airev-1.1.1/src/code_reviewer/updater/upgrade.py +0 -87
- {airev-1.1.1 → airev-1.2.0}/README.md +0 -0
- {airev-1.1.1 → airev-1.2.0}/pyproject.toml +0 -0
- {airev-1.1.1 → airev-1.2.0}/setup.cfg +0 -0
- {airev-1.1.1 → airev-1.2.0}/src/airev.egg-info/SOURCES.txt +0 -0
- {airev-1.1.1 → airev-1.2.0}/src/airev.egg-info/dependency_links.txt +0 -0
- {airev-1.1.1 → airev-1.2.0}/src/airev.egg-info/entry_points.txt +0 -0
- {airev-1.1.1 → airev-1.2.0}/src/airev.egg-info/requires.txt +0 -0
- {airev-1.1.1 → airev-1.2.0}/src/airev.egg-info/top_level.txt +0 -0
- {airev-1.1.1 → airev-1.2.0}/src/code_reviewer/context_builder.py +0 -0
- {airev-1.1.1 → airev-1.2.0}/src/code_reviewer/diff_parser.py +0 -0
- {airev-1.1.1 → airev-1.2.0}/src/code_reviewer/formatters/__init__.py +0 -0
- {airev-1.1.1 → airev-1.2.0}/src/code_reviewer/formatters/progress.py +0 -0
- {airev-1.1.1 → airev-1.2.0}/src/code_reviewer/formatters/terminal.py +0 -0
- {airev-1.1.1 → airev-1.2.0}/src/code_reviewer/i18n/__init__.py +0 -0
- {airev-1.1.1 → airev-1.2.0}/src/code_reviewer/locales/en.yaml +0 -0
- {airev-1.1.1 → airev-1.2.0}/src/code_reviewer/locales/pt-br.yaml +0 -0
- {airev-1.1.1 → airev-1.2.0}/src/code_reviewer/models.py +0 -0
- {airev-1.1.1 → airev-1.2.0}/src/code_reviewer/prompt_builder.py +0 -0
- {airev-1.1.1 → airev-1.2.0}/src/code_reviewer/prompts/review_system.md +0 -0
- {airev-1.1.1 → airev-1.2.0}/src/code_reviewer/response_parser.py +0 -0
- {airev-1.1.1 → airev-1.2.0}/src/code_reviewer/runners/__init__.py +0 -0
- {airev-1.1.1 → airev-1.2.0}/src/code_reviewer/runners/base.py +0 -0
- {airev-1.1.1 → airev-1.2.0}/src/code_reviewer/runners/copilot.py +0 -0
- {airev-1.1.1 → airev-1.2.0}/src/code_reviewer/runners/gemini.py +0 -0
- {airev-1.1.1 → airev-1.2.0}/src/code_reviewer/updater/notifier.py +0 -0
- {airev-1.1.1 → airev-1.2.0}/tests/test_context_builder.py +0 -0
- {airev-1.1.1 → airev-1.2.0}/tests/test_copilot_runner.py +0 -0
- {airev-1.1.1 → airev-1.2.0}/tests/test_diff_parser.py +0 -0
- {airev-1.1.1 → airev-1.2.0}/tests/test_i18n.py +0 -0
- {airev-1.1.1 → airev-1.2.0}/tests/test_progress.py +0 -0
- {airev-1.1.1 → airev-1.2.0}/tests/test_prompt_builder.py +0 -0
- {airev-1.1.1 → airev-1.2.0}/tests/test_response_parser.py +0 -0
- {airev-1.1.1 → airev-1.2.0}/tests/test_terminal_formatter.py +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""CLI Entry Point - Comando principal do
|
|
1
|
+
"""CLI Entry Point - Comando principal do airev."""
|
|
2
2
|
|
|
3
3
|
import sys
|
|
4
4
|
import time
|
|
@@ -88,13 +88,13 @@ def review(
|
|
|
88
88
|
|
|
89
89
|
Exemplos:
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
airev review --base main
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
airev review --base develop --runner copilot
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
airev review --base main --json-output
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
airev review --base main --no-progress
|
|
98
98
|
"""
|
|
99
99
|
workdir = workdir or Path.cwd()
|
|
100
100
|
start_time = time.perf_counter()
|
|
@@ -232,7 +232,7 @@ def runners():
|
|
|
232
232
|
|
|
233
233
|
@main.command()
|
|
234
234
|
def upgrade():
|
|
235
|
-
"""Atualiza o
|
|
235
|
+
"""Atualiza o airev para a versão mais recente."""
|
|
236
236
|
from rich.console import Console
|
|
237
237
|
|
|
238
238
|
console = Console()
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"""Módulo de auto-update para verificação e atualização de versões."""
|
|
2
2
|
|
|
3
|
-
from .version_check import check_for_update, UpdateInfo
|
|
3
|
+
from .version_check import check_for_update, clear_cache, UpdateInfo
|
|
4
4
|
from .notifier import notify_update
|
|
5
5
|
from .upgrade import detect_installer, run_upgrade
|
|
6
6
|
|
|
7
7
|
__all__ = [
|
|
8
8
|
"check_for_update",
|
|
9
|
+
"clear_cache",
|
|
9
10
|
"UpdateInfo",
|
|
10
11
|
"notify_update",
|
|
11
12
|
"detect_installer",
|
|
@@ -30,7 +30,7 @@ class UrllibClient:
|
|
|
30
30
|
try:
|
|
31
31
|
request = urllib.request.Request(
|
|
32
32
|
url,
|
|
33
|
-
headers={"Accept": "application/json", "User-Agent": "
|
|
33
|
+
headers={"Accept": "application/json", "User-Agent": "airev"},
|
|
34
34
|
)
|
|
35
35
|
with urllib.request.urlopen(request, timeout=timeout) as response:
|
|
36
36
|
data = response.read().decode("utf-8")
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"""Funcionalidades de upgrade do pacote."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import subprocess
|
|
5
|
+
import sys
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from rich.console import Console
|
|
9
|
+
|
|
10
|
+
from .. import __version__
|
|
11
|
+
from .version_check import check_for_update, clear_cache
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def detect_installer() -> str:
|
|
15
|
+
"""Detecta qual instalador foi usado (pipx ou pip).
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
"pipx" se instalado via pipx, "pip" caso contrário
|
|
19
|
+
"""
|
|
20
|
+
exe_path = Path(sys.executable)
|
|
21
|
+
|
|
22
|
+
# pipx instala em ~/.local/pipx/venvs/
|
|
23
|
+
if "pipx" in exe_path.parts:
|
|
24
|
+
return "pipx"
|
|
25
|
+
|
|
26
|
+
return "pip"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def get_installed_version(installer: str) -> str | None:
|
|
30
|
+
"""Obtém a versão real instalada do airev consultando o instalador.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
installer: "pipx" ou "pip"
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
String com a versão instalada ou None se não conseguir obter
|
|
37
|
+
"""
|
|
38
|
+
try:
|
|
39
|
+
if installer == "pipx":
|
|
40
|
+
# Tenta usar pipx list --json
|
|
41
|
+
result = subprocess.run(
|
|
42
|
+
["pipx", "list", "--json"],
|
|
43
|
+
capture_output=True,
|
|
44
|
+
text=True,
|
|
45
|
+
check=False,
|
|
46
|
+
)
|
|
47
|
+
if result.returncode == 0:
|
|
48
|
+
data = json.loads(result.stdout)
|
|
49
|
+
venvs = data.get("venvs", {})
|
|
50
|
+
if "airev" in venvs:
|
|
51
|
+
metadata = venvs["airev"].get("metadata", {})
|
|
52
|
+
return metadata.get("main_package", {}).get("package_version")
|
|
53
|
+
# Fallback: tenta sem --json (versões antigas do pipx)
|
|
54
|
+
return _get_version_from_pipx_list_text()
|
|
55
|
+
else:
|
|
56
|
+
# pip show airev
|
|
57
|
+
result = subprocess.run(
|
|
58
|
+
[sys.executable, "-m", "pip", "show", "airev"],
|
|
59
|
+
capture_output=True,
|
|
60
|
+
text=True,
|
|
61
|
+
check=False,
|
|
62
|
+
)
|
|
63
|
+
if result.returncode == 0:
|
|
64
|
+
for line in result.stdout.splitlines():
|
|
65
|
+
if line.startswith("Version:"):
|
|
66
|
+
return line.split(":", 1)[1].strip()
|
|
67
|
+
except (subprocess.SubprocessError, json.JSONDecodeError, KeyError):
|
|
68
|
+
pass
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _get_version_from_pipx_list_text() -> str | None:
|
|
73
|
+
"""Fallback para obter versão do pipx list sem --json.
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
String com a versão ou None se não encontrar
|
|
77
|
+
"""
|
|
78
|
+
try:
|
|
79
|
+
result = subprocess.run(
|
|
80
|
+
["pipx", "list"],
|
|
81
|
+
capture_output=True,
|
|
82
|
+
text=True,
|
|
83
|
+
check=False,
|
|
84
|
+
)
|
|
85
|
+
if result.returncode == 0:
|
|
86
|
+
# Procura por linha como "airev 1.0.0" ou "package airev 1.0.0"
|
|
87
|
+
for line in result.stdout.splitlines():
|
|
88
|
+
if "airev" in line.lower():
|
|
89
|
+
parts = line.split()
|
|
90
|
+
for i, part in enumerate(parts):
|
|
91
|
+
if "airev" in part.lower() and i + 1 < len(parts):
|
|
92
|
+
version = parts[i + 1].strip(",")
|
|
93
|
+
# Verifica se parece uma versão
|
|
94
|
+
if version and version[0].isdigit():
|
|
95
|
+
return version
|
|
96
|
+
except subprocess.SubprocessError:
|
|
97
|
+
pass
|
|
98
|
+
return None
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def run_upgrade(console: Console | None = None) -> bool:
|
|
102
|
+
"""Executa upgrade do pacote.
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
console: Console Rich para output (opcional)
|
|
106
|
+
|
|
107
|
+
Returns:
|
|
108
|
+
True se upgrade foi executado com sucesso, False caso contrário
|
|
109
|
+
"""
|
|
110
|
+
if console is None:
|
|
111
|
+
console = Console()
|
|
112
|
+
|
|
113
|
+
# Verifica se há atualização disponível
|
|
114
|
+
console.print("[dim]Verificando atualizações...[/]")
|
|
115
|
+
update_info = check_for_update()
|
|
116
|
+
|
|
117
|
+
if update_info is None:
|
|
118
|
+
# Limpa cache mesmo quando não há atualização (garante consistência)
|
|
119
|
+
clear_cache()
|
|
120
|
+
console.print(
|
|
121
|
+
f"[green]✓[/] Você já está na versão mais recente ([cyan]{__version__}[/])"
|
|
122
|
+
)
|
|
123
|
+
return False
|
|
124
|
+
|
|
125
|
+
installer = detect_installer()
|
|
126
|
+
|
|
127
|
+
# Obtém versão antes do upgrade para comparação
|
|
128
|
+
version_before = get_installed_version(installer) or __version__
|
|
129
|
+
|
|
130
|
+
console.print(
|
|
131
|
+
f"[yellow]→[/] Atualizando de {version_before} "
|
|
132
|
+
f"para {update_info.latest_version}..."
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
# Monta comando de upgrade
|
|
136
|
+
if installer == "pipx":
|
|
137
|
+
cmd = ["pipx", "upgrade", "airev"]
|
|
138
|
+
else:
|
|
139
|
+
cmd = [sys.executable, "-m", "pip", "install", "--upgrade", "airev"]
|
|
140
|
+
|
|
141
|
+
try:
|
|
142
|
+
result = subprocess.run(
|
|
143
|
+
cmd,
|
|
144
|
+
capture_output=True,
|
|
145
|
+
text=True,
|
|
146
|
+
check=False,
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
# Sempre limpa o cache após tentativa de upgrade
|
|
150
|
+
clear_cache()
|
|
151
|
+
|
|
152
|
+
if result.returncode == 0:
|
|
153
|
+
# Verifica se a versão realmente mudou
|
|
154
|
+
version_after = get_installed_version(installer)
|
|
155
|
+
|
|
156
|
+
if version_after and version_after != version_before:
|
|
157
|
+
console.print(
|
|
158
|
+
f"[green]✓[/] Atualizado de {version_before} para {version_after}"
|
|
159
|
+
)
|
|
160
|
+
return True
|
|
161
|
+
else:
|
|
162
|
+
# Comando executou mas versão não mudou
|
|
163
|
+
console.print(
|
|
164
|
+
f"[green]✓[/] Você já está na versão mais recente "
|
|
165
|
+
f"([cyan]{version_after or version_before}[/])"
|
|
166
|
+
)
|
|
167
|
+
return False
|
|
168
|
+
else:
|
|
169
|
+
console.print(f"[red]✗[/] Falha ao atualizar: {result.stderr.strip()}")
|
|
170
|
+
console.print(f"[dim]Tente manualmente: {' '.join(cmd)}[/]")
|
|
171
|
+
return False
|
|
172
|
+
|
|
173
|
+
except FileNotFoundError:
|
|
174
|
+
clear_cache()
|
|
175
|
+
console.print(f"[red]✗[/] Comando '{cmd[0]}' não encontrado")
|
|
176
|
+
if installer == "pipx":
|
|
177
|
+
console.print("[dim]Tente: pip install --upgrade airev[/]")
|
|
178
|
+
return False
|
|
179
|
+
except Exception as e:
|
|
180
|
+
clear_cache()
|
|
181
|
+
console.print(f"[red]✗[/] Erro inesperado: {e}")
|
|
182
|
+
return False
|
|
@@ -110,6 +110,24 @@ def _write_cache(latest_version: str) -> None:
|
|
|
110
110
|
pass
|
|
111
111
|
|
|
112
112
|
|
|
113
|
+
def clear_cache() -> bool:
|
|
114
|
+
"""Remove o arquivo de cache de verificação de versão.
|
|
115
|
+
|
|
116
|
+
Deve ser chamada após upgrade para garantir que a próxima
|
|
117
|
+
verificação consulte o PyPI novamente.
|
|
118
|
+
|
|
119
|
+
Returns:
|
|
120
|
+
True se o cache foi removido ou não existia, False se falhou
|
|
121
|
+
"""
|
|
122
|
+
try:
|
|
123
|
+
if CACHE_FILE.exists():
|
|
124
|
+
CACHE_FILE.unlink()
|
|
125
|
+
return True
|
|
126
|
+
except OSError:
|
|
127
|
+
# Falha ao remover cache - ignora silenciosamente
|
|
128
|
+
return False
|
|
129
|
+
|
|
130
|
+
|
|
113
131
|
def get_latest_version(timeout: float = DEFAULT_TIMEOUT) -> str | None:
|
|
114
132
|
"""Consulta PyPI para obter a versão mais recente.
|
|
115
133
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Testes para o módulo de auto-update."""
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
|
+
import subprocess
|
|
4
5
|
import sys
|
|
5
6
|
from datetime import datetime, timedelta, timezone
|
|
6
7
|
from io import StringIO
|
|
@@ -17,11 +18,16 @@ from code_reviewer.updater.version_check import (
|
|
|
17
18
|
_read_cache,
|
|
18
19
|
_write_cache,
|
|
19
20
|
check_for_update,
|
|
21
|
+
clear_cache,
|
|
20
22
|
compare_versions,
|
|
21
23
|
get_latest_version,
|
|
22
24
|
)
|
|
23
25
|
from code_reviewer.updater.notifier import notify_update
|
|
24
|
-
from code_reviewer.updater.upgrade import
|
|
26
|
+
from code_reviewer.updater.upgrade import (
|
|
27
|
+
detect_installer,
|
|
28
|
+
get_installed_version,
|
|
29
|
+
run_upgrade,
|
|
30
|
+
)
|
|
25
31
|
|
|
26
32
|
|
|
27
33
|
class TestHttpClient:
|
|
@@ -159,6 +165,48 @@ class TestCache:
|
|
|
159
165
|
assert cache is None
|
|
160
166
|
|
|
161
167
|
|
|
168
|
+
class TestClearCache:
|
|
169
|
+
"""Testes para clear_cache."""
|
|
170
|
+
|
|
171
|
+
def test_clear_existing_cache(self, tmp_path):
|
|
172
|
+
"""Deve remover arquivo de cache existente."""
|
|
173
|
+
cache_file = tmp_path / "update-check.json"
|
|
174
|
+
cache_file.write_text('{"test": true}')
|
|
175
|
+
|
|
176
|
+
with patch(
|
|
177
|
+
"code_reviewer.updater.version_check.CACHE_FILE", cache_file
|
|
178
|
+
):
|
|
179
|
+
result = clear_cache()
|
|
180
|
+
|
|
181
|
+
assert result is True
|
|
182
|
+
assert not cache_file.exists()
|
|
183
|
+
|
|
184
|
+
def test_clear_nonexistent_cache(self, tmp_path):
|
|
185
|
+
"""Deve retornar True quando cache não existe."""
|
|
186
|
+
cache_file = tmp_path / "nonexistent.json"
|
|
187
|
+
|
|
188
|
+
with patch(
|
|
189
|
+
"code_reviewer.updater.version_check.CACHE_FILE", cache_file
|
|
190
|
+
):
|
|
191
|
+
result = clear_cache()
|
|
192
|
+
|
|
193
|
+
assert result is True
|
|
194
|
+
|
|
195
|
+
def test_clear_cache_permission_error(self, tmp_path):
|
|
196
|
+
"""Deve retornar False quando não consegue remover."""
|
|
197
|
+
cache_file = tmp_path / "update-check.json"
|
|
198
|
+
cache_file.write_text('{"test": true}')
|
|
199
|
+
|
|
200
|
+
with patch(
|
|
201
|
+
"code_reviewer.updater.version_check.CACHE_FILE", cache_file
|
|
202
|
+
), patch(
|
|
203
|
+
"pathlib.Path.unlink", side_effect=OSError("Permission denied")
|
|
204
|
+
):
|
|
205
|
+
result = clear_cache()
|
|
206
|
+
|
|
207
|
+
assert result is False
|
|
208
|
+
|
|
209
|
+
|
|
162
210
|
class TestCheckForUpdate:
|
|
163
211
|
"""Testes para check_for_update."""
|
|
164
212
|
|
|
@@ -252,7 +300,7 @@ class TestDetectInstaller:
|
|
|
252
300
|
|
|
253
301
|
def test_detect_pipx(self):
|
|
254
302
|
"""Deve detectar pipx quando no path do executável."""
|
|
255
|
-
fake_path = Path("/home/user/.local/pipx/venvs/
|
|
303
|
+
fake_path = Path("/home/user/.local/pipx/venvs/airev/bin/python")
|
|
256
304
|
with patch.object(sys, "executable", str(fake_path)):
|
|
257
305
|
result = detect_installer()
|
|
258
306
|
assert result == "pipx"
|
|
@@ -272,59 +320,167 @@ class TestDetectInstaller:
|
|
|
272
320
|
assert result == "pip"
|
|
273
321
|
|
|
274
322
|
|
|
323
|
+
class TestGetInstalledVersion:
|
|
324
|
+
"""Testes para get_installed_version."""
|
|
325
|
+
|
|
326
|
+
def test_get_version_pipx_json(self):
|
|
327
|
+
"""Deve obter versão do pipx list --json."""
|
|
328
|
+
pipx_json = {
|
|
329
|
+
"venvs": {
|
|
330
|
+
"airev": {
|
|
331
|
+
"metadata": {
|
|
332
|
+
"main_package": {
|
|
333
|
+
"package_version": "1.2.3"
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
mock_result = MagicMock(returncode=0, stdout=json.dumps(pipx_json))
|
|
340
|
+
|
|
341
|
+
with patch("subprocess.run", return_value=mock_result):
|
|
342
|
+
result = get_installed_version("pipx")
|
|
343
|
+
|
|
344
|
+
assert result == "1.2.3"
|
|
345
|
+
|
|
346
|
+
def test_get_version_pipx_not_installed(self):
|
|
347
|
+
"""Deve retornar None quando airev não está instalado no pipx."""
|
|
348
|
+
pipx_json = {"venvs": {}}
|
|
349
|
+
mock_result = MagicMock(returncode=0, stdout=json.dumps(pipx_json))
|
|
350
|
+
|
|
351
|
+
with patch("subprocess.run", return_value=mock_result):
|
|
352
|
+
result = get_installed_version("pipx")
|
|
353
|
+
|
|
354
|
+
assert result is None
|
|
355
|
+
|
|
356
|
+
def test_get_version_pip(self):
|
|
357
|
+
"""Deve obter versão do pip show."""
|
|
358
|
+
pip_output = """Name: airev
|
|
359
|
+
Version: 1.0.0
|
|
360
|
+
Summary: Code reviewer CLI
|
|
361
|
+
"""
|
|
362
|
+
mock_result = MagicMock(returncode=0, stdout=pip_output)
|
|
363
|
+
|
|
364
|
+
with patch("subprocess.run", return_value=mock_result):
|
|
365
|
+
result = get_installed_version("pip")
|
|
366
|
+
|
|
367
|
+
assert result == "1.0.0"
|
|
368
|
+
|
|
369
|
+
def test_get_version_pip_not_installed(self):
|
|
370
|
+
"""Deve retornar None quando pip show falha."""
|
|
371
|
+
mock_result = MagicMock(returncode=1, stdout="")
|
|
372
|
+
|
|
373
|
+
with patch("subprocess.run", return_value=mock_result):
|
|
374
|
+
result = get_installed_version("pip")
|
|
375
|
+
|
|
376
|
+
assert result is None
|
|
377
|
+
|
|
378
|
+
def test_get_version_subprocess_error(self):
|
|
379
|
+
"""Deve retornar None em erro de subprocess."""
|
|
380
|
+
with patch("subprocess.run", side_effect=subprocess.SubprocessError):
|
|
381
|
+
result = get_installed_version("pipx")
|
|
382
|
+
|
|
383
|
+
assert result is None
|
|
384
|
+
|
|
385
|
+
|
|
275
386
|
class TestRunUpgrade:
|
|
276
387
|
"""Testes para run_upgrade."""
|
|
277
388
|
|
|
278
389
|
def test_upgrade_no_update_available(self):
|
|
279
|
-
"""Deve retornar False quando não há update."""
|
|
390
|
+
"""Deve retornar False e limpar cache quando não há update."""
|
|
280
391
|
from rich.console import Console
|
|
281
392
|
|
|
282
393
|
console = Console(file=StringIO(), force_terminal=True)
|
|
283
394
|
|
|
284
395
|
with patch(
|
|
285
396
|
"code_reviewer.updater.upgrade.check_for_update", return_value=None
|
|
286
|
-
)
|
|
397
|
+
), patch(
|
|
398
|
+
"code_reviewer.updater.upgrade.clear_cache", return_value=True
|
|
399
|
+
) as mock_clear:
|
|
287
400
|
result = run_upgrade(console)
|
|
288
401
|
|
|
289
402
|
assert result is False
|
|
403
|
+
mock_clear.assert_called_once()
|
|
290
404
|
|
|
291
|
-
def
|
|
292
|
-
"""Deve executar pipx upgrade
|
|
405
|
+
def test_upgrade_success_pipx_version_changed(self):
|
|
406
|
+
"""Deve executar pipx upgrade e verificar mudança de versão."""
|
|
293
407
|
from rich.console import Console
|
|
294
408
|
|
|
295
409
|
console = Console(file=StringIO(), force_terminal=True)
|
|
296
410
|
update_info = UpdateInfo(current_version="0.1.0", latest_version="0.2.0")
|
|
297
411
|
mock_result = MagicMock(returncode=0, stderr="")
|
|
298
412
|
|
|
413
|
+
# Simula versão mudando de 0.1.0 para 0.2.0 após upgrade
|
|
414
|
+
version_calls = iter(["0.1.0", "0.2.0"])
|
|
415
|
+
|
|
299
416
|
with patch(
|
|
300
417
|
"code_reviewer.updater.upgrade.check_for_update",
|
|
301
418
|
return_value=update_info,
|
|
302
419
|
), patch(
|
|
303
420
|
"code_reviewer.updater.upgrade.detect_installer", return_value="pipx"
|
|
304
421
|
), patch(
|
|
422
|
+
"code_reviewer.updater.upgrade.get_installed_version",
|
|
423
|
+
side_effect=lambda _: next(version_calls),
|
|
424
|
+
), patch(
|
|
425
|
+
"code_reviewer.updater.upgrade.clear_cache", return_value=True
|
|
426
|
+
) as mock_clear, patch(
|
|
305
427
|
"subprocess.run", return_value=mock_result
|
|
306
428
|
) as mock_run:
|
|
307
429
|
result = run_upgrade(console)
|
|
308
430
|
|
|
309
431
|
assert result is True
|
|
310
432
|
mock_run.assert_called_once()
|
|
433
|
+
mock_clear.assert_called_once()
|
|
311
434
|
cmd = mock_run.call_args[0][0]
|
|
312
435
|
assert "pipx" in cmd
|
|
313
436
|
assert "upgrade" in cmd
|
|
314
437
|
|
|
315
|
-
def
|
|
316
|
-
"""Deve
|
|
438
|
+
def test_upgrade_success_but_version_unchanged(self):
|
|
439
|
+
"""Deve retornar False quando versão não muda após upgrade."""
|
|
440
|
+
from rich.console import Console
|
|
441
|
+
|
|
442
|
+
console = Console(file=StringIO(), force_terminal=True)
|
|
443
|
+
update_info = UpdateInfo(current_version="0.1.0", latest_version="0.2.0")
|
|
444
|
+
mock_result = MagicMock(returncode=0, stderr="")
|
|
445
|
+
|
|
446
|
+
with patch(
|
|
447
|
+
"code_reviewer.updater.upgrade.check_for_update",
|
|
448
|
+
return_value=update_info,
|
|
449
|
+
), patch(
|
|
450
|
+
"code_reviewer.updater.upgrade.detect_installer", return_value="pipx"
|
|
451
|
+
), patch(
|
|
452
|
+
"code_reviewer.updater.upgrade.get_installed_version",
|
|
453
|
+
return_value="0.1.0", # Versão não muda
|
|
454
|
+
), patch(
|
|
455
|
+
"code_reviewer.updater.upgrade.clear_cache", return_value=True
|
|
456
|
+
) as mock_clear, patch(
|
|
457
|
+
"subprocess.run", return_value=mock_result
|
|
458
|
+
):
|
|
459
|
+
result = run_upgrade(console)
|
|
460
|
+
|
|
461
|
+
assert result is False
|
|
462
|
+
mock_clear.assert_called_once()
|
|
463
|
+
|
|
464
|
+
def test_upgrade_success_pip_version_changed(self):
|
|
465
|
+
"""Deve executar pip install --upgrade e verificar mudança."""
|
|
317
466
|
from rich.console import Console
|
|
318
467
|
|
|
319
468
|
console = Console(file=StringIO(), force_terminal=True)
|
|
320
469
|
update_info = UpdateInfo(current_version="0.1.0", latest_version="0.2.0")
|
|
321
470
|
mock_result = MagicMock(returncode=0, stderr="")
|
|
322
471
|
|
|
472
|
+
version_calls = iter(["0.1.0", "0.2.0"])
|
|
473
|
+
|
|
323
474
|
with patch(
|
|
324
475
|
"code_reviewer.updater.upgrade.check_for_update",
|
|
325
476
|
return_value=update_info,
|
|
326
477
|
), patch(
|
|
327
478
|
"code_reviewer.updater.upgrade.detect_installer", return_value="pip"
|
|
479
|
+
), patch(
|
|
480
|
+
"code_reviewer.updater.upgrade.get_installed_version",
|
|
481
|
+
side_effect=lambda _: next(version_calls),
|
|
482
|
+
), patch(
|
|
483
|
+
"code_reviewer.updater.upgrade.clear_cache", return_value=True
|
|
328
484
|
), patch(
|
|
329
485
|
"subprocess.run", return_value=mock_result
|
|
330
486
|
) as mock_run:
|
|
@@ -335,3 +491,54 @@ class TestRunUpgrade:
|
|
|
335
491
|
cmd = mock_run.call_args[0][0]
|
|
336
492
|
assert "--upgrade" in cmd
|
|
337
493
|
assert "airev" in cmd
|
|
494
|
+
|
|
495
|
+
def test_upgrade_clears_cache_on_failure(self):
|
|
496
|
+
"""Deve limpar cache mesmo quando upgrade falha."""
|
|
497
|
+
from rich.console import Console
|
|
498
|
+
|
|
499
|
+
console = Console(file=StringIO(), force_terminal=True)
|
|
500
|
+
update_info = UpdateInfo(current_version="0.1.0", latest_version="0.2.0")
|
|
501
|
+
mock_result = MagicMock(returncode=1, stderr="Error")
|
|
502
|
+
|
|
503
|
+
with patch(
|
|
504
|
+
"code_reviewer.updater.upgrade.check_for_update",
|
|
505
|
+
return_value=update_info,
|
|
506
|
+
), patch(
|
|
507
|
+
"code_reviewer.updater.upgrade.detect_installer", return_value="pipx"
|
|
508
|
+
), patch(
|
|
509
|
+
"code_reviewer.updater.upgrade.get_installed_version",
|
|
510
|
+
return_value="0.1.0",
|
|
511
|
+
), patch(
|
|
512
|
+
"code_reviewer.updater.upgrade.clear_cache", return_value=True
|
|
513
|
+
) as mock_clear, patch(
|
|
514
|
+
"subprocess.run", return_value=mock_result
|
|
515
|
+
):
|
|
516
|
+
result = run_upgrade(console)
|
|
517
|
+
|
|
518
|
+
assert result is False
|
|
519
|
+
mock_clear.assert_called_once()
|
|
520
|
+
|
|
521
|
+
def test_upgrade_clears_cache_on_exception(self):
|
|
522
|
+
"""Deve limpar cache quando ocorre exceção."""
|
|
523
|
+
from rich.console import Console
|
|
524
|
+
|
|
525
|
+
console = Console(file=StringIO(), force_terminal=True)
|
|
526
|
+
update_info = UpdateInfo(current_version="0.1.0", latest_version="0.2.0")
|
|
527
|
+
|
|
528
|
+
with patch(
|
|
529
|
+
"code_reviewer.updater.upgrade.check_for_update",
|
|
530
|
+
return_value=update_info,
|
|
531
|
+
), patch(
|
|
532
|
+
"code_reviewer.updater.upgrade.detect_installer", return_value="pipx"
|
|
533
|
+
), patch(
|
|
534
|
+
"code_reviewer.updater.upgrade.get_installed_version",
|
|
535
|
+
return_value="0.1.0",
|
|
536
|
+
), patch(
|
|
537
|
+
"code_reviewer.updater.upgrade.clear_cache", return_value=True
|
|
538
|
+
) as mock_clear, patch(
|
|
539
|
+
"subprocess.run", side_effect=FileNotFoundError
|
|
540
|
+
):
|
|
541
|
+
result = run_upgrade(console)
|
|
542
|
+
|
|
543
|
+
assert result is False
|
|
544
|
+
mock_clear.assert_called_once()
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"""Funcionalidades de upgrade do pacote."""
|
|
2
|
-
|
|
3
|
-
import subprocess
|
|
4
|
-
import sys
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
|
|
7
|
-
from rich.console import Console
|
|
8
|
-
|
|
9
|
-
from .. import __version__
|
|
10
|
-
from .version_check import check_for_update
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def detect_installer() -> str:
|
|
14
|
-
"""Detecta qual instalador foi usado (pipx ou pip).
|
|
15
|
-
|
|
16
|
-
Returns:
|
|
17
|
-
"pipx" se instalado via pipx, "pip" caso contrário
|
|
18
|
-
"""
|
|
19
|
-
exe_path = Path(sys.executable)
|
|
20
|
-
|
|
21
|
-
# pipx instala em ~/.local/pipx/venvs/
|
|
22
|
-
if "pipx" in exe_path.parts:
|
|
23
|
-
return "pipx"
|
|
24
|
-
|
|
25
|
-
return "pip"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def run_upgrade(console: Console | None = None) -> bool:
|
|
29
|
-
"""Executa upgrade do pacote.
|
|
30
|
-
|
|
31
|
-
Args:
|
|
32
|
-
console: Console Rich para output (opcional)
|
|
33
|
-
|
|
34
|
-
Returns:
|
|
35
|
-
True se upgrade foi executado, False se já está atualizado ou falhou
|
|
36
|
-
"""
|
|
37
|
-
if console is None:
|
|
38
|
-
console = Console()
|
|
39
|
-
|
|
40
|
-
# Verifica se há atualização disponível
|
|
41
|
-
console.print("[dim]Verificando atualizações...[/]")
|
|
42
|
-
update_info = check_for_update()
|
|
43
|
-
|
|
44
|
-
if update_info is None:
|
|
45
|
-
console.print(
|
|
46
|
-
f"[green]✓[/] Você já está na versão mais recente ([cyan]{__version__}[/])"
|
|
47
|
-
)
|
|
48
|
-
return False
|
|
49
|
-
|
|
50
|
-
installer = detect_installer()
|
|
51
|
-
console.print(
|
|
52
|
-
f"[yellow]→[/] Atualizando de {update_info.current_version} "
|
|
53
|
-
f"para {update_info.latest_version}..."
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
# Monta comando de upgrade
|
|
57
|
-
if installer == "pipx":
|
|
58
|
-
cmd = ["pipx", "upgrade", "airev"]
|
|
59
|
-
else:
|
|
60
|
-
cmd = [sys.executable, "-m", "pip", "install", "--upgrade", "airev"]
|
|
61
|
-
|
|
62
|
-
try:
|
|
63
|
-
result = subprocess.run(
|
|
64
|
-
cmd,
|
|
65
|
-
capture_output=True,
|
|
66
|
-
text=True,
|
|
67
|
-
check=False,
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
if result.returncode == 0:
|
|
71
|
-
console.print(
|
|
72
|
-
f"[green]✓[/] Atualizado para versão {update_info.latest_version}"
|
|
73
|
-
)
|
|
74
|
-
return True
|
|
75
|
-
else:
|
|
76
|
-
console.print(f"[red]✗[/] Falha ao atualizar: {result.stderr.strip()}")
|
|
77
|
-
console.print(f"[dim]Tente manualmente: {' '.join(cmd)}[/]")
|
|
78
|
-
return False
|
|
79
|
-
|
|
80
|
-
except FileNotFoundError:
|
|
81
|
-
console.print(f"[red]✗[/] Comando '{cmd[0]}' não encontrado")
|
|
82
|
-
if installer == "pipx":
|
|
83
|
-
console.print("[dim]Tente: pip install --upgrade airev[/]")
|
|
84
|
-
return False
|
|
85
|
-
except Exception as e:
|
|
86
|
-
console.print(f"[red]✗[/] Erro inesperado: {e}")
|
|
87
|
-
return False
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|