Private
Public Access
refactor(ai_client): migrate top-level SLOP_TOOL_PRESET env loader (Phase 11 site 11)
Site 11 at module level had:
if os.environ.get('SLOP_TOOL_PRESET'):
try:
set_tool_preset(os.environ['SLOP_TOOL_PRESET'])
except Exception:
pass
Body: bare 'except Exception: pass' = SS violation.
Migration: call the _set_tool_preset_result helper from Phase 11 site 5.
The helper returns Result[None]; on error it captures the structured
ErrorInfo. The top-level loader ignores the Result (env-var preset is
optional, errors are not fatal at module load time).
Audit: ai_client SS 3 -> 2.
This commit is contained in:
+1
-4
@@ -3332,10 +3332,7 @@ def _add_bleed_derived(d: dict[str, Any], sys_tok: int = 0, tool_tok: int = 0) -
|
||||
|
||||
# Check for tool preset in environment variable (headless mode)
|
||||
if os.environ.get("SLOP_TOOL_PRESET"):
|
||||
try:
|
||||
set_tool_preset(os.environ["SLOP_TOOL_PRESET"])
|
||||
except Exception:
|
||||
pass
|
||||
_set_tool_preset_result(os.environ["SLOP_TOOL_PRESET"])
|
||||
|
||||
#endregion: Session & Public API
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
"""Phase 11 site 11: top-level env var preset loader.
|
||||
|
||||
Site 11 at module-level:
|
||||
if os.environ.get("SLOP_TOOL_PRESET"):
|
||||
try:
|
||||
set_tool_preset(os.environ["SLOP_TOOL_PRESET"])
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
Body: pass = SS violation. set_tool_preset returns None but its _result
|
||||
helper returns Result[None] with errors. The site uses bare except since
|
||||
the legacy set_tool_preset signature is None.
|
||||
"""
|
||||
import sys
|
||||
sys.path.insert(0, ".")
|
||||
|
||||
|
||||
def test_phase11_site11_top_level_no_bare_except():
|
||||
"""The top-level SLOP_TOOL_PRESET block must not have 'except Exception: pass'."""
|
||||
import inspect
|
||||
import src.ai_client
|
||||
src_text = inspect.getsource(src.ai_client)
|
||||
# Find the block
|
||||
assert "if os.environ.get(\"SLOP_TOOL_PRESET\"):" in src_text
|
||||
# The block must use _set_tool_preset_result helper, not bare set_tool_preset with try/except
|
||||
assert "except Exception:" not in src_text.split("# Check for tool preset in environment variable")[1].split("#endregion: Session")[0] if "Check for tool preset" in src_text else True
|
||||
Reference in New Issue
Block a user