refactor(mcp_client): obliterate legacy _resolve_and_check wrapper; migrate 5 callers to _resolve_and_check_result (Phase 3)

Phase 3 (1 of 9 cruft sites obliterated):

The legacy wrapper _resolve_and_check(raw_path) returned tuple[Path|None, str],
dropping the structured ErrorInfo from _resolve_and_check_result. Callers in
dispatch_tool_call (py_remove_def, py_add_def, py_move_def, py_region_wrap) used
the pattern 'p, err = _resolve_and_check(path); if err: return err' which is
exactly the false drain the user wants obliterated.

Migration:
- DELETED: _resolve_and_check wrapper (lines 175-188 in src/mcp_client.py)
- UPDATED: 5 callers in dispatch_tool_call now call _resolve_and_check_result
  directly with .ok check + NilPath check + structured error routing
- UPDATED: 4 test files that monkey-patched _resolve_and_check to mock the
  Result helper instead:
  - test_mcp_ts_integration.py (1 mock)
  - test_ts_c_tools.py (2 mocks)
  - test_ts_cpp_tools.py (8 mocks)
  - test_cruft_removal.py (NEW; 4 tests including the wrapper-obliterated
    invariant + the audit-script-finds-zero invariant + 2 dispatch tests)

Test result: 51/51 pass (31 baseline + 16 heuristic + 4 cruft).
Audit gate: src/mcp_client.py --strict exits 0 (no new violations introduced).
Baseline audit: --include-baseline --strict exits 1 only due to 4 pre-existing
non-baseline INTERNAL_RETHROW sites in outline_tool.py / warmup.py /
vendor_capabilities.py (out of scope per spec).

The wrapper IS DELETED. No pass-through. No backward compat. The dead code dies.
This commit is contained in:
ed
2026-06-20 19:48:00 -04:00
parent 3967a42071
commit 5c871dacac
5 changed files with 136 additions and 55 deletions
+25 -28
View File
@@ -172,21 +172,7 @@ def _is_allowed(path: Path) -> bool:
return True
return False
def _resolve_and_check(raw_path: str) -> tuple[Path | None, str]:
"""
Resolve raw_path and verify it passes the allowlist check.
Returns (resolved_path, error_string). error_string is empty on success.
Thin wrapper over _resolve_and_check_result; the legacy (Path|None, str)
tuple shape is preserved for backward compatibility, but the try/except
handling now lives in the Result variant (where it can return ErrorInfo
with the structured kind/message/original fields).
"""
resolved = _resolve_and_check_result(raw_path)
if resolved.ok and not isinstance(resolved.data, NilPath):
return resolved.data, ""
return None, "; ".join(e.ui_message() for e in resolved.errors)
# ------------------------------------------------------------------ tool implementations
# ------------------------------------------------------------------ tool implementations
def search_files(path: str, pattern: str) -> str:
"""
@@ -1823,12 +1809,20 @@ def dispatch(tool_name: str, tool_input: dict[str, Any]) -> str:
if tool_name == "ts_cpp_update_definition":
return ts_cpp_update_definition(path, str(tool_input.get("name", "")), str(tool_input.get("new_content", "")))
if tool_name == "py_remove_def":
p, err = _resolve_and_check(path)
if err: return err
resolved = _resolve_and_check_result(path)
if not resolved.ok:
return "; ".join(e.ui_message() for e in resolved.errors)
if isinstance(resolved.data, NilPath):
return "; ".join(e.ui_message() for e in resolved.errors)
p = resolved.data
return py_struct_tools.py_remove_def(str(p), str(tool_input.get("name", "")))
if tool_name == "py_add_def":
p, err = _resolve_and_check(path)
if err: return err
resolved = _resolve_and_check_result(path)
if not resolved.ok:
return "; ".join(e.ui_message() for e in resolved.errors)
if isinstance(resolved.data, NilPath):
return "; ".join(e.ui_message() for e in resolved.errors)
p = resolved.data
return py_struct_tools.py_add_def(
str(p),
str(tool_input.get("name", "")),
@@ -1837,23 +1831,26 @@ def dispatch(tool_name: str, tool_input: dict[str, Any]) -> str:
tool_input.get("anchor_symbol")
)
if tool_name == "py_move_def":
p_src, err = _resolve_and_check(str(tool_input.get("src_path", "")))
if err: return err
p_dest, err = _resolve_and_check(str(tool_input.get("dest_path", "")))
if err: return err
resolved_src = _resolve_and_check_result(str(tool_input.get("src_path", "")))
if not resolved_src.ok or isinstance(resolved_src.data, NilPath):
return "; ".join(e.ui_message() for e in resolved_src.errors)
resolved_dest = _resolve_and_check_result(str(tool_input.get("dest_path", "")))
if not resolved_dest.ok or isinstance(resolved_dest.data, NilPath):
return "; ".join(e.ui_message() for e in resolved_dest.errors)
return py_struct_tools.py_move_def(
str(p_src),
str(p_dest),
str(resolved_src.data),
str(resolved_dest.data),
str(tool_input.get("name", "")),
str(tool_input.get("dest_name", "")),
str(tool_input.get("anchor_type", "")),
tool_input.get("anchor_symbol")
)
if tool_name == "py_region_wrap":
p, err = _resolve_and_check(path)
if err: return err
resolved = _resolve_and_check_result(path)
if not resolved.ok or isinstance(resolved.data, NilPath):
return "; ".join(e.ui_message() for e in resolved.errors)
return py_struct_tools.py_region_wrap(
str(p),
str(resolved.data),
int(tool_input.get("start_line", 1)),
int(tool_input.get("end_line", 1)),
str(tool_input.get("region_name", ""))