Private
Public Access
refactor(ai_client): migrate set_tool_preset + set_bias_profile to Result[T] (Phase 11 sites 5+6)
Both functions had:
try: ToolPresetManager().load_all() ...
except (OSError, ValueError, AttributeError) as e:
sys.stderr.write(f'[ERROR] Failed to set {preset_name}: {e}')
sys.stderr.flush()
sys.stderr.write is logging = NOT a drain = SS violation per MUST-NOT-DO #6.
New helpers:
- _set_tool_preset_result(preset_name: Optional[str]) -> Result[None]
Empty/None preset short-circuits to Result(data=None).
On failure: Result(data=None, errors=[ErrorInfo]).
- _set_bias_profile_result(profile_name: Optional[str]) -> Result[None]
Same pattern.
Legacy wrappers set the global state (or skip on empty preset) and
delegate to the _result helper. Cache invalidation runs regardless.
Audit: ai_client SS 9 -> 7. COMPLIANT 27 -> 29.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
"""Phase 11 sites 5+6: set_tool_preset + set_bias_profile Result helpers.
|
||||
|
||||
Both had:
|
||||
try: ToolPresetManager().load_all() ...
|
||||
except (OSError, ValueError, AttributeError) as e:
|
||||
sys.stderr.write(f'[ERROR] Failed to set {preset_name}: {e}')
|
||||
sys.stderr.flush()
|
||||
|
||||
Body is sys.stderr.write = logging NOT a drain = SS violation.
|
||||
MIGRATE to Result[None].
|
||||
"""
|
||||
import sys
|
||||
sys.path.insert(0, ".")
|
||||
|
||||
|
||||
def test_phase11_sites56_set_tool_preset_result_exists():
|
||||
import src.ai_client
|
||||
assert hasattr(src.ai_client, "_set_tool_preset_result"), \
|
||||
"_set_tool_preset_result helper missing"
|
||||
|
||||
|
||||
def test_phase11_sites56_set_bias_profile_result_exists():
|
||||
import src.ai_client
|
||||
assert hasattr(src.ai_client, "_set_bias_profile_result"), \
|
||||
"_set_bias_profile_result helper missing"
|
||||
|
||||
|
||||
def test_phase11_sites56_helpers_return_result():
|
||||
import src.ai_client
|
||||
import inspect
|
||||
for name in ("_set_tool_preset_result", "_set_bias_profile_result"):
|
||||
fn = getattr(src.ai_client, name)
|
||||
sig = inspect.signature(fn)
|
||||
assert "Result" in str(sig.return_annotation), \
|
||||
f"{name} return must be Result, got {sig.return_annotation}"
|
||||
|
||||
|
||||
def test_phase11_sites56_legacy_preserved():
|
||||
import src.ai_client
|
||||
assert callable(getattr(src.ai_client, "set_tool_preset", None))
|
||||
assert callable(getattr(src.ai_client, "set_bias_profile", None))
|
||||
Reference in New Issue
Block a user