35bac5eda7
aggregate.py (1 site): - compute_file_stats returns Result[dict[str, int]]. The 2 SILENT_SWALLOW sites (ast.parse + open) now append to errors list. Callers in gui_2.py updated to extract result.data from the cache. api_hooks.py (1 site): - WebSocketServer._handler - was 2 except ...: pass (JSONDecodeError + ConnectionClosed). Now logs warnings instead of silently swallowing. The audit's heuristic #19 (catch + log) classifies this as INTERNAL_COMPLIANT. context_presets.py (1 site): - ContextPresetManager.load_all returns Result[Dict[str, ContextPreset]]. Caller in app_controller.py (load_context_preset) updated to check result.ok. external_editor.py (1 site): - _find_vscode_in_registry returns Result[Optional[str]]. The 1 SILENT_SWALLOW site (subprocess.run) now appends to errors. Caller in ExternalEditorLauncher._resolve_vscode updated to extract result.data. Tests updated to check result.ok and use result.data.
32 lines
1.0 KiB
Python
32 lines
1.0 KiB
Python
import pytest
|
|
from src.aggregate import group_files_by_dir, compute_file_stats
|
|
from src.models import FileItem
|
|
|
|
def test_group_files_by_dir():
|
|
files = [
|
|
FileItem(path="src/main.py"),
|
|
FileItem(path="src/utils/helpers.py"),
|
|
FileItem(path="tests/test_main.py"),
|
|
FileItem(path="README.md")
|
|
]
|
|
grouped = group_files_by_dir(files)
|
|
assert len(grouped) == 4
|
|
assert grouped["src"] == [files[0]]
|
|
assert grouped["src/utils"] == [files[1]]
|
|
assert grouped["tests"] == [files[2]]
|
|
assert grouped["."] == [files[3]]
|
|
|
|
def test_compute_file_stats():
|
|
import tempfile
|
|
import os
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
# Create a dummy python file
|
|
py_path = os.path.join(temp_dir, "test.py")
|
|
with open(py_path, "w") as f:
|
|
f.write("def foo():\n pass\n\nclass Bar:\n pass\n")
|
|
stats_result = compute_file_stats(py_path)
|
|
assert stats_result.ok, f"compute_file_stats failed: {stats_result.errors}"
|
|
stats = stats_result.data
|
|
assert stats["lines"] == 5
|
|
assert stats["ast_elements"] == 2 # 1 func, 1 class
|