Private
Public Access
0
0
Files
manual_slop/tests/test_patch_modal.py
T
ed ba3eb0c090 refactor(multiple): continue Phase 6 Optional[T] elimination (batch 2)
Phase 6: Eliminate Optional[T] returns - BATCH 2 of 7
Before: 7 more Optional[T] returns removed
After:  0 in command_palette.py, diff_viewer.py, fuzzy_anchor.py,
        multi_agent_conductor.py, patch_modal.py, app_controller.py
Delta:  -7 sites (cumulative: -15 of 30)

Specific changes:
- src/command_palette.py:50: CommandRegistry.get() returns Command (zero-init
  sentinel: id="", title="", category="uncategorized", action=lambda: None)
- src/diff_viewer.py:117: get_line_color returns "" when no marker prefix
- src/fuzzy_anchor.py:40: FuzzyAnchor.resolve_slice returns (-1, -1) sentinel
  (replaced 3x `return None` with `return (-1, -1)`)
- src/multi_agent_conductor.py:64: WorkerPool.spawn returns threading.Thread()
  (empty sentinel, not started) when pool is full
- src/patch_modal.py:33: PatchModalManager.get_pending_patch returns
  PendingPatch; class has EMPTY_PATCH sentinel; field type changed from
  Optional[PendingPatch] to PendingPatch; 2x `= None` reset replaced with
  `= EMPTY_PATCH`
- src/app_controller.py:4414: _confirm_and_run returns "" when not approved
  (was Optional[str] returning None)

Test updates:
- tests/test_diff_viewer.py:95: get_line_color(" context") == ""
- tests/test_fuzzy_anchor.py:42,59: assert result == (-1, -1)
- tests/test_parallel_execution.py:31: t3 sentinel is now unstarted thread
  (check via not t3.is_alive())
- tests/test_patch_modal.py:9,31,78: get_pending_patch() == "" sentinel check

Verification:
- audit_weak_types --strict: OK (107 <= 112 baseline)
- 22+ tests pass (test_diff_viewer, test_fuzzy_anchor,
  test_parallel_execution, test_patch_modal, test_command_palette)
- py_check_syntax: OK on all changed files

REMAINING: ~15 Optional[T] returns in:
- src/external_editor.py (3)
- src/file_cache.py (7)
- src/diff_viewer.py: parse_hunk_header (1)
- src/models.py: ExternalEditorConfig.get_default (1)
- src/project_manager.py: load_track_state (1)
- src/session_logger.py: log_tool_call (1)
- src/app_controller.py: _pending_mma_spawn, _pending_mma_approval (2)
2026-06-26 05:07:35 -04:00

89 lines
2.3 KiB
Python

import pytest
from src.patch_modal import (
PatchModalManager, PendingPatch,
get_patch_modal_manager, reset_patch_modal_manager
)
def test_patch_modal_manager_init():
manager = PatchModalManager()
assert manager.get_pending_patch().patch_text == ""
assert manager.is_modal_shown() is False
def test_request_patch_approval():
manager = PatchModalManager()
patch_text = "--- a/test.py\n+++ b/test.py\n@@ -1 +1 @@\n-old\n+new"
file_paths = ["test.py"]
result = manager.request_patch_approval(patch_text, file_paths)
assert result is True
assert manager.is_modal_shown() is True
pending = manager.get_pending_patch()
assert pending is not None
assert pending.patch_text == patch_text
assert pending.file_paths == file_paths
def test_reject_patch():
manager = PatchModalManager()
manager.request_patch_approval("diff", ["file.py"])
manager.reject_patch()
assert manager.get_pending_patch().patch_text == ""
assert manager.is_modal_shown() is False
def test_close_modal():
manager = PatchModalManager()
manager.request_patch_approval("diff", ["file.py"])
manager.close_modal()
assert manager.is_modal_shown() is False
def test_apply_callback():
manager = PatchModalManager()
called = []
def apply_fn(patch: str) -> bool:
called.append(patch)
return True
manager.set_apply_callback(apply_fn)
patch_text = "--- a/test.py\n+++ b/test.py\n"
result = manager.apply_patch(patch_text)
assert result is True
assert len(called) == 1
assert called[0] == patch_text
def test_reject_callback():
manager = PatchModalManager()
called = []
def reject_fn() -> None:
called.append(True)
manager.set_reject_callback(reject_fn)
manager.reject_patch()
assert len(called) == 1
def test_reset():
manager = PatchModalManager()
manager.request_patch_approval("diff", ["file.py"])
manager.set_apply_callback(lambda x: True)
manager.set_reject_callback(lambda: None)
manager.reset()
assert manager.get_pending_patch().patch_text == ""
assert manager.is_modal_shown() is False
def test_get_patch_modal_manager_singleton():
reset_patch_modal_manager()
mgr1 = get_patch_modal_manager()
mgr2 = get_patch_modal_manager()
assert mgr1 is mgr2
reset_patch_modal_manager()