mirror of
https://github.com/elder-plinius/OBLITERATUS.git
synced 2026-12-06 02:53:54 +01:00
94 lines
4.2 KiB
Python
94 lines
4.2 KiB
Python
"""Invalid tournament inputs must fail before output cleanup or execution."""
|
|
|
|
from unittest.mock import Mock
|
|
|
|
import pytest
|
|
|
|
from obliteratus import tourney
|
|
from tests.test_tourney_execution import _metrics, _outcome, _runner
|
|
|
|
pytestmark = pytest.mark.cpu
|
|
|
|
|
|
@pytest.mark.parametrize("overrides,error,message", [
|
|
({"seed": True}, ValueError, "seed must be a non-negative integer"),
|
|
({"seed": -1}, ValueError, "seed must be a non-negative integer"),
|
|
({"seed": 1.5}, ValueError, "seed must be a non-negative integer"),
|
|
({"kl_budget": float("nan")}, ValueError, "kl_budget must be finite and non-negative"),
|
|
({"kl_budget": -.1}, ValueError, "kl_budget must be finite and non-negative"),
|
|
({"kl_budget": True}, ValueError, "kl_budget must be finite and non-negative"),
|
|
({"arm_executor": None}, ValueError, "must be configured together"),
|
|
({"winner_publisher": None}, ValueError, "must be configured together"),
|
|
({"arm_executor": "executor"}, TypeError, "must be callable"),
|
|
({"winner_publisher": "publisher"}, TypeError, "must be callable"),
|
|
({"executor_identity": None}, ValueError, "requires executor_identity"),
|
|
({"artifact_budget_bytes": True}, ValueError, "requires a positive artifact budget"),
|
|
({"retain_arm_artifacts": "false"}, TypeError, "must be a boolean"),
|
|
({"methods": []}, ValueError, "nonempty sequence of unique names"),
|
|
({"methods": ["alpha", "alpha"]}, ValueError, "nonempty sequence of unique names"),
|
|
({"methods": [""]}, ValueError, "nonempty sequence of unique names"),
|
|
({"methods": [1]}, ValueError, "nonempty sequence of unique names"),
|
|
({"executor_identity": []}, TypeError, "JSON mapping with string keys"),
|
|
({"executor_identity": {1: "value"}}, TypeError, "JSON mapping with string keys"),
|
|
({"executor_identity": {"nested": float("inf")}}, ValueError, "must be finite JSON"),
|
|
({"executor_identity": {"nested": {"not-json"}}}, TypeError, "must be finite JSON"),
|
|
])
|
|
def test_invalid_configuration_preserves_existing_output(tmp_path, overrides, error, message):
|
|
executor, publisher = Mock(), Mock()
|
|
retained = tmp_path / "retained-evidence.json"
|
|
retained.write_bytes(b"previous experiment")
|
|
arguments = dict(
|
|
methods=["alpha"], output_dir=str(tmp_path), arm_executor=executor,
|
|
winner_publisher=publisher, executor_identity={"schema": 1},
|
|
artifact_budget_bytes=100,
|
|
)
|
|
arguments.update(overrides)
|
|
|
|
with pytest.raises(error, match=message):
|
|
tourney.TourneyRunner("fixture/model", **arguments)
|
|
|
|
assert retained.read_bytes() == b"previous experiment"
|
|
assert list(tmp_path.iterdir()) == [retained]
|
|
executor.assert_not_called()
|
|
publisher.assert_not_called()
|
|
|
|
|
|
def test_insufficient_disjoint_prompt_rows_fail_before_any_arm(tmp_path):
|
|
executor, publisher = Mock(), Mock()
|
|
runner = _runner(tmp_path, ["alpha"], executor, publisher)
|
|
runner._dataset_prompts = lambda: (["intervention"] * 275, ["control"] * 400)
|
|
|
|
with pytest.raises(ValueError, match="need 276 paired rows, got 275"):
|
|
runner.run()
|
|
|
|
executor.assert_not_called()
|
|
publisher.assert_not_called()
|
|
assert not runner._checkpoint_path.exists()
|
|
assert not (runner.output_dir / "tourney_results.json").exists()
|
|
|
|
|
|
@pytest.mark.parametrize("metric,value", [("kl_divergence", -1.), ("perplexity", -100.)])
|
|
def test_negative_measurement_is_ineligible_before_composite_scoring(tmp_path, metric, value):
|
|
# These values would divide by zero if scored before the quality gate.
|
|
def execute(request):
|
|
metrics = _metrics(request.method)
|
|
if request.method == "alpha":
|
|
metrics[metric] = value
|
|
return _outcome(request, metrics)
|
|
|
|
published = []
|
|
from tests.test_tourney_execution import _publisher
|
|
|
|
def publish(request):
|
|
published.append(request.method)
|
|
return _publisher(request)
|
|
|
|
result = _runner(tmp_path, ["alpha", "beta"], execute, publish).run()
|
|
|
|
rejected = result.rounds[0].contenders[0]
|
|
assert rejected.method == "alpha"
|
|
assert rejected.error is None and not rejected.eligible and rejected.score == -1.
|
|
assert rejected.ineligible_reasons == [f"{metric} must be non-negative"]
|
|
assert result.winner.method == "beta"
|
|
assert published == ["beta"]
|