5822ea8e65
Site L1990: inner _send(r_idx) in _send_gemini_cli had:
try: resp_data = adapter.send(...)
except Exception as e: events.emit('response_received', {'error': str(e)}); raise
This is Re-Raise Pattern 2 (catch + emit event + raise). Per TIER1_REVIEW,
the migration is to Result[T] because the audit does not yet recognize
events.emit as a structured error carrier.
New helper _send_cli_round_result(r_idx, adapter, payload, ...) -> Result[dict]:
- Emits request_start + [CLI] comms before SDK call
- Returns Result(data=resp_data) on SDK success
- On failure: emits response_received error event + returns Result(errors=[ErrorInfo(original=e)])
Inner _send refactored:
send_result = _send_cli_round_result(r_idx, adapter, payload, ...)
if not send_result.ok:
raise cast(Exception, send_result.errors[0].original)
resp_data = send_result.data
This preserves the original re-raise behavior so the outer
_send_gemini_cli try/except still catches and converts to Result.
Audit: ai_client BC 4 -> 3.
27 lines
965 B
Python
27 lines
965 B
Python
"""Phase 10 site 6: _send_cli_round_result helper.
|
|
|
|
Site L1990 (in _send_gemini_cli):
|
|
try: resp_data = adapter.send(...)
|
|
except Exception as e: events.emit('response_received', {'error': str(e)}); raise
|
|
|
|
Re-Raise Pattern 2 (catch + emit + raise). Migration: extract Result helper.
|
|
The inner _send calls the helper; on error, re-raise original exception
|
|
(preserving outer _send_gemini_cli catch behavior).
|
|
"""
|
|
import sys
|
|
sys.path.insert(0, ".")
|
|
|
|
|
|
def test_phase10_site6_send_cli_round_result_exists():
|
|
import src.ai_client
|
|
assert hasattr(src.ai_client, "_send_cli_round_result"), \
|
|
"_send_cli_round_result helper missing"
|
|
|
|
|
|
def test_phase10_site6_send_cli_round_result_returns_result():
|
|
import src.ai_client
|
|
import inspect
|
|
fn = src.ai_client._send_cli_round_result
|
|
sig = inspect.signature(fn)
|
|
assert "Result" in str(sig.return_annotation), \
|
|
f"_send_cli_round_result return must be Result, got {sig.return_annotation}" |