TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 5: refactor(gui_2): migrate L3163 render_tool_preset_manager_content bias_save to Result[T] (Phase 5)

Extract _render_tool_preset_bias_save_result helper from the BiasProfile
save try/except in render_tool_preset_manager_content. The imgui.button
callback drains errors to app._last_request_errors per FR-BC-4
event-handler pattern.

[pre-audit] L3163 INTERNAL_BROAD_CATCH
[post-audit] V count: 9 -> 8 (L3163 removed)
This commit is contained in:
ed
2026-06-19 23:54:02 -04:00
parent b20ea145b3
commit 5b341038a7
2 changed files with 90 additions and 4 deletions
+50
View File
@@ -1018,3 +1018,53 @@ def test_phase_5_l1428_request_patch_from_tier4_result_failure():
err = result.errors[0]
assert err.source == "gui_2.request_patch_from_tier4_result"
assert "tier4 backend down" in err.message
def test_phase_5_l3163_render_tool_preset_bias_save_result_success():
"""
L3163 _render_tool_preset_bias_save_result returns Result.ok=True on success.
The helper wraps the BiasProfile save try/except in
render_tool_preset_manager_content. On success (BiasProfile construction +
_cb_save_bias_profile), 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_bias_profile_name = "test_bias"
app._editing_bias_profile_tool_weights = {"foo": 2}
app._editing_bias_profile_category_multipliers = {"bar": 1.5}
app._editing_tool_preset_scope = "project"
mock_profile = MagicMock()
mock_profile.name = "test_bias"
with patch.object(gui_2.models, "BiasProfile", return_value=mock_profile):
result = gui_2._render_tool_preset_bias_save_result(app)
assert result.ok, f"Expected ok=True on success, got errors: {result.errors}"
assert result.data is True
assert "Saved: test_bias" in app.ai_status
def test_phase_5_l3163_render_tool_preset_bias_save_result_failure():
"""
L3163 _render_tool_preset_bias_save_result returns Result.ok=False on failure.
When BiasProfile construction or _cb_save_bias_profile raises, the helper
sets app.ai_status to an error message and returns
Result(data=False, errors=[ErrorInfo]).
"""
from src import gui_2
from unittest.mock import MagicMock, patch
app = MagicMock()
app._editing_bias_profile_name = "test_bias"
app._editing_bias_profile_tool_weights = {"foo": 2}
app._editing_bias_profile_category_multipliers = {"bar": 1.5}
app._editing_tool_preset_scope = "project"
with patch.object(gui_2.models, "BiasProfile", side_effect=RuntimeError("bias validation failed")):
result = gui_2._render_tool_preset_bias_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_tool_preset_bias_save_result"
assert "bias validation failed" in err.message
assert "Error:" in app.ai_status