Private
Public Access
0
0
Files
manual_slop/tests/test_context_presets.py
T
ed 35bac5eda7 refactor(src): Phase 10.2 batch 4 - aggregate + api_hooks + context_presets + external_editor
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.
2026-06-17 22:38:17 -04:00

62 lines
2.0 KiB
Python

import pytest
from src.context_presets import ContextPresetManager
from src.models import ContextPreset, ContextFileEntry
def test_save_context_preset():
manager = ContextPresetManager()
project_dict = {}
preset_name = "test_preset"
files = [ContextFileEntry(path="file1.py"), ContextFileEntry(path="file2.py")]
screenshots = ["screenshot1.png"]
preset = ContextPreset(name=preset_name, files=files, screenshots=screenshots)
manager.save_preset(project_dict, preset)
assert "context_presets" in project_dict
assert preset_name in project_dict["context_presets"]
assert project_dict["context_presets"][preset_name]["files"] == [f.to_dict() for f in files]
assert project_dict["context_presets"][preset_name]["screenshots"] == screenshots
def test_load_all_context_presets():
manager = ContextPresetManager()
project_dict = {
"context_presets": {
"test_preset": {
"name": "test_preset",
"files": [{"path": "file1.py", "view_mode": "summary", "custom_slices": []}],
"screenshots": ["screenshot1.png"]
}
}
}
presets_result = manager.load_all(project_dict)
assert presets_result.ok, f"load_all failed: {presets_result.errors}"
presets = presets_result.data
assert "test_preset" in presets
assert presets["test_preset"].files[0].path == "file1.py"
assert presets["test_preset"].screenshots == ["screenshot1.png"]
def test_delete_context_preset():
manager = ContextPresetManager()
project_dict = {
"context_presets": {
"test_preset": {
"name": "test_preset",
"files": [{"path": "file1.py", "view_mode": "summary", "custom_slices": []}],
"screenshots": []
}
}
}
manager.delete_preset(project_dict, "test_preset")
assert "test_preset" not in project_dict["context_presets"]
def test_delete_nonexistent_preset_no_error():
manager = ContextPresetManager()
project_dict = {"context_presets": {}}
# Should not raise error if it doesn't exist
manager.delete_preset(project_dict, "nonexistent")
assert "nonexistent" not in project_dict["context_presets"]