Files
OBLITERATUS/tests/test_som_unavailable.py
Joseph MaglyandClaude Opus 5.5 5f558a78db feat(concepts): apply #223 maintainer rulings on publication, leace and steering
Maintainer decisions for epic #223 (2026-10-15):

- Q1: `leace` is a deprecated alias of the Fisher LDA direction. It keeps
  its numerical behaviour, warns once per public resolution with a
  DeprecationWarning naming `fisher_lda` and `leace_exact`, and will be
  removed in a future minor release.
- Q4: a collateral FAIL blocks both the model card and any Hub push of
  modified weights or adapters on every path (pipeline, export_run, both
  CLIs, Concept Lab, the Hub UI and tourney uploads), checked before any
  network call. `--allow-collateral-fail REASON` (and the matching API
  argument and UI field) overrides the block and stamps the FAIL and
  reason into the card, checkpoint metadata and provenance. Local save
  and export are never blocked.
- Q5: research-tier packs no longer carry publication or local-export
  restrictions; the tier is provenance only and Q4 applies to every pack.
- Steering defaults are removal-first: `steer` defaults to alpha -1 and
  the default dose ladder is non-positive. Positive doses stay available
  explicitly; `project` keeps its positive removal strength.
- Q3 (gate modes) and Q7 (dense only, follow-up #310) are unchanged and
  documented.

Refs #223

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 15:37:51 -04:00

84 lines
3.0 KiB
Python

"""The ``som`` direction method is unavailable (no SOM extractor shipped).
``obliteratus.analysis.som_directions`` does not exist, so every ``som``
route must fail fast with a clear error before any model is loaded — never
with an ImportError from DISTILL.
"""
from __future__ import annotations
from io import StringIO
from unittest.mock import patch
import pytest
from obliteratus.abliterate import METHODS, AbliterationPipeline
from obliteratus.cli import main
def _capture_exit(argv: list[str], *, expect_code: int = 2) -> str:
buf = StringIO()
with pytest.raises(SystemExit) as exc_info, patch("sys.stderr", buf):
main(argv)
assert exc_info.value.code == expect_code
return buf.getvalue()
class TestSomUnavailable:
def test_som_preset_key_still_enumerated(self):
assert "som" in METHODS
def test_som_preset_fails_fast_before_model_load(self):
# "fake/model" does not exist; ValueError (not a load error) proves
# the failure happens at construction time, before any model load.
with pytest.raises(ValueError, match="'som' is not available"):
AbliterationPipeline(model_name="fake/model", method="som")
def test_som_direction_method_fails_fast_before_model_load(self):
with pytest.raises(ValueError, match="'som' is not available"):
AbliterationPipeline(
model_name="fake/model",
method="advanced",
direction_method="som",
)
def test_som_never_raises_import_error(self):
with pytest.raises(ValueError):
AbliterationPipeline(model_name="fake/model", method="som")
with pytest.raises(ValueError):
AbliterationPipeline(
model_name="fake/model", direction_method="som"
)
@pytest.mark.filterwarnings("default:leace is a deprecated alias:DeprecationWarning")
def test_other_direction_methods_unaffected(self):
for direction_method in ("diff_means", "svd", "leace"):
pipe = AbliterationPipeline(
model_name="fake/model",
method="advanced",
direction_method=direction_method,
)
assert pipe.direction_method == direction_method
@pytest.mark.parametrize("command", ["obliterate", "abliterate"])
@pytest.mark.parametrize(
"flag", ["--method", "--direction-method"],
)
def test_cli_rejects_som(self, command, flag):
stderr_text = _capture_exit([command, "fake/model", flag, "som"])
assert "invalid choice" in stderr_text.lower()
@pytest.mark.parametrize(
"flag", ["--method", "--direction-method"],
)
def test_self_improve_cli_rejects_som(self, flag):
stderr_text = _capture_exit(
[
"self-improve", "fake/model",
"--audit", "audit.json",
"--output-dir", "out",
flag, "som",
]
)
assert "invalid choice" in stderr_text.lower()