Private
Public Access
TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 4: refactor(gui_2): migrate L3398 render_persona_editor_window to Result[T] (Phase 4)
Adds _render_persona_editor_save_result(app) -> Result[bool] helper that wraps the models.Persona(...) construction + _cb_save_persona try/except in render_persona_editor_window Save button. The legacy wrapper drains errors to app._last_request_errors (per FR-BC-3 modal pattern; data plane attribute). Audit: BROAD_CATCH count 17 -> 16, COMPLIANT count 20 -> 21. Migration target count drops by 1. Tests: 2/2 pass.
This commit is contained in:
@@ -604,4 +604,57 @@ def test_phase_3_l4848_render_warmup_status_indicator_result_failure():
|
||||
assert result.errors, "Expected at least one error on failure"
|
||||
err = result.errors[0]
|
||||
assert err.source == "gui_2._render_warmup_status_indicator_result"
|
||||
assert "warmup backend down" in err.message
|
||||
def test_phase_4_l3398_render_persona_editor_save_result_success():
|
||||
"""
|
||||
L3398 _render_persona_editor_save_result returns Result.ok=True on success.
|
||||
|
||||
The helper wraps the Save button try/except in render_persona_editor_window
|
||||
(Persona creation: models.Persona(...) + _cb_save_persona). On success,
|
||||
sets app.ai_status to "Saved: <name>" and returns Result(data=True).
|
||||
"""
|
||||
from src import gui_2
|
||||
from unittest.mock import MagicMock, patch
|
||||
app = MagicMock()
|
||||
app._editing_persona_name = "test_persona"
|
||||
app._editing_persona_system_prompt = "you are a helper"
|
||||
app._editing_persona_tool_preset_id = ""
|
||||
app._editing_persona_bias_profile_id = ""
|
||||
app._editing_persona_context_preset_id = ""
|
||||
app._editing_persona_aggregation_strategy = ""
|
||||
app._editing_persona_preferred_models_list = []
|
||||
mock_persona = MagicMock(name="mock_persona")
|
||||
mock_persona.name = "test_persona"
|
||||
with patch.object(gui_2.models, "Persona", return_value=mock_persona):
|
||||
result = gui_2._render_persona_editor_save_result(app)
|
||||
assert result.ok, f"Expected ok=True on success, got errors: {result.errors}"
|
||||
assert result.data is True
|
||||
assert "Saved: test_persona" in app.ai_status
|
||||
|
||||
|
||||
def test_phase_4_l3398_render_persona_editor_save_result_failure():
|
||||
"""
|
||||
L3398 _render_persona_editor_save_result returns Result.ok=False on failure.
|
||||
|
||||
When Persona construction or _cb_save_persona raises, the helper sets
|
||||
app.ai_status to an error message and returns Result(data=False,
|
||||
errors=[ErrorInfo]). The legacy wrapper should drain to
|
||||
app._last_request_errors (per FR-BC-3 modal pattern).
|
||||
"""
|
||||
from src import gui_2
|
||||
from unittest.mock import MagicMock, patch
|
||||
app = MagicMock()
|
||||
app._editing_persona_name = "test_persona"
|
||||
app._editing_persona_system_prompt = "you are a helper"
|
||||
app._editing_persona_tool_preset_id = ""
|
||||
app._editing_persona_bias_profile_id = ""
|
||||
app._editing_persona_context_preset_id = ""
|
||||
app._editing_persona_aggregation_strategy = ""
|
||||
app._editing_persona_preferred_models_list = []
|
||||
with patch.object(gui_2.models, "Persona", side_effect=RuntimeError("validation failed")):
|
||||
result = gui_2._render_persona_editor_save_result(app)
|
||||
assert not result.ok, f"Expected ok=False on failure, got data: {result.data}"
|
||||
assert result.errors, "Expected at least one error on failure"
|
||||
err = result.errors[0]
|
||||
assert err.source == "gui_2._render_persona_editor_save_result"
|
||||
assert "validation failed" in err.message
|
||||
assert "Error:" in app.ai_status
|
||||
|
||||
Reference in New Issue
Block a user