Files
OBLITERATUS/tests/test_recipe_capability_runtime.py
Joseph Magly 134bd2c32c feat(recipes): move recipe tools to v2 pipelines; v1 read-only
recipe search, confirm, promote and obliterate --recipe now operate on
v2 recipes: search grids are v2 step variations (recipe-search-grid v2,
same preregistered selection rule), confirmation and promotion consume
evaluation profiles and bind evidence to applied resolution records,
and --recipe applies pipelines through apply_recipe. v1 recipes and
grids load through mechanical migration with a notice; writing v1 is
refused. Shipped v1 data is migrated to v2, and the two recipes
confirmed on the protocol final test in the initial core run ship as
accepted v2 data: llama3.1-8b-e03-reg02 and qwen2.5-1.5b-mid10-18-dim1,
with KL-advisory profiles and value-only confirmation evidence.

Fixes #571
2026-11-21 01:27:13 -05:00

141 lines
6.0 KiB
Python

"""Search and confirm forward capability-evaluator settings to verify-edit only."""
import json
from pathlib import Path
import pytest
from obliteratus.recipes.validation import RecipeError
from tests.test_recipe_search import Runner, _read, _write, setup_grid # noqa: F401
pytestmark = pytest.mark.cpu
MATRIC = "/opt/matric-eval/bin/matric-eval"
VLLM = "env VLLM_USE_FLASHINFER_SAMPLER=0 vllm serve {model} --port {port}"
def test_capability_flags_helper(tmp_path):
from obliteratus.recipes.search import verify_edit_capability_flags
assert verify_edit_capability_flags({}, tmp_path) == []
assert verify_edit_capability_flags({"batch_size": 4}, tmp_path) == ["--batch-size", "4"]
flags = verify_edit_capability_flags(
{"batch_size": 8, "matric_eval_bin": MATRIC, "vllm_command": VLLM}, tmp_path / "cap")
assert flags == ["--batch-size", "8", "--matric-eval-bin", MATRIC, "--vllm-command", VLLM,
"--capability-dir", str(tmp_path / "cap")]
class RecordingRunner(Runner):
def __init__(self):
super().__init__()
self.checkpoint_failure.clear()
self.argv = []
def __call__(self, argv, **kwargs):
self.argv.append(list(argv))
return super().__call__(argv, **kwargs)
def test_search_forwards_runtime_capability_settings(setup_grid): # noqa: F811
from obliteratus.recipes.search import run_search
grid, grid_path, out, _, _ = setup_grid
grid["runtime"] = {"device": "cuda", "dtype": "bfloat16", "batch_size": 8,
"matric_eval_bin": MATRIC, "vllm_command": VLLM}
_write(grid_path, grid)
runner = RecordingRunner()
run_search(grid_path, runner=runner)
verify = [argv for argv in runner.argv if argv[3] == "verify-edit"]
assert verify
for argv in verify:
assert argv[argv.index("--batch-size") + 1] == "8"
assert argv[argv.index("--matric-eval-bin") + 1] == MATRIC
assert argv[argv.index("--vllm-command") + 1] == VLLM
capability = Path(argv[argv.index("--capability-dir") + 1])
assert capability.name == "capability" and out in capability.parents
for argv in runner.argv:
if argv[3] == "verify-checkpoint":
assert "--matric-eval-bin" not in argv and "--batch-size" not in argv
if argv[3] == "recipe":
request = _read(Path(argv[5]))
assert request["device"] == "cuda" and request["dtype"] == "bfloat16"
assert not {"batch_size", "matric_eval_bin", "vllm_command"} & set(request)
@pytest.mark.parametrize("bad", [{"batch_size": 0}, {"matric_eval_bin": ""}, {"vllm_command": 3},
{"unknown": True}])
def test_search_rejects_invalid_runtime(setup_grid, bad): # noqa: F811
from obliteratus.recipes.search import run_search
grid, grid_path, _, _, _ = setup_grid
grid["runtime"] = bad
_write(grid_path, grid)
with pytest.raises(RecipeError):
run_search(grid_path, runner=RecordingRunner())
def test_confirm_cli_forwards_capability_options(monkeypatch, tmp_path):
from obliteratus.cli import main
from obliteratus.recipes import confirmation
seen = {}
def run(selection, **kwargs):
seen.update(kwargs)
return {"outcome": "pass", "run_id": "r1"}
monkeypatch.setattr(confirmation, "run_confirmation", run)
(tmp_path / "stock").mkdir()
with pytest.raises(SystemExit) as error:
main(["recipe", "confirm", "some-recipe", "--stock", str(tmp_path / "stock"),
"--output-dir", str(tmp_path / "out"), "--batch-size", "8",
"--matric-eval-bin", MATRIC, "--vllm-command", VLLM])
assert error.value.code == 0
assert seen["batch_size"] == 8
assert seen["matric_eval_bin"] == MATRIC
assert seen["vllm_command"] == VLLM
def test_confirm_steps_forward_capability_flags_to_verify_edit_only(monkeypatch, tmp_path):
from obliteratus.recipes import confirmation
from tests.test_recipe_application import recipe as legacy_recipe
from tests.test_recipe_confirmation import write_edit_resolution
from obliteratus.recipes import migrate_v1
recipe = confirmation.prepare_execution_recipe(migrate_v1(legacy_recipe()), seed=1)
calls = []
def fake_step(argv, log, out, runner):
calls.append(argv)
log.write_text("log\n")
if argv[3] == "recipe":
write_edit_resolution(json.loads(Path(argv[5]).read_bytes()))
if argv[3] == "verify-checkpoint":
report = Path(argv[argv.index("--report") + 1])
report.write_text(json.dumps({"verdict": "pass"}))
return {"exit_code": 0}
monkeypatch.setattr(confirmation, "_run_step", fake_step)
record = {"model": {"stock": str(tmp_path / "stock"), "model_id": "org/Model", "revision": "a" * 40},
"edit": {"resolved": {"recipe_sha256": recipe["canonical_sha256"]}}, "margins": {"resolved_sha256": "0" * 64},
"steps": [], "reports": {}}
spec = {"generation": {"seed": 1}}
capability = {"batch_size": 8, "matric_eval_bin": MATRIC, "vllm_command": VLLM}
# No verify-edit report exists, so the final-report check fails after all
# three steps have been launched; the launched argv is what this test checks.
with pytest.raises((RecipeError, KeyError)):
confirmation._run_steps(record, tmp_path, spec, recipe, tmp_path, None, "cuda", "bfloat16", capability)
steps = {argv[3]: argv for argv in calls}
assert set(steps) == {"recipe", "verify-checkpoint", "verify-edit"}
verify = steps["verify-edit"]
assert verify[verify.index("--matric-eval-bin") + 1] == MATRIC
assert verify[verify.index("--vllm-command") + 1] == VLLM
assert verify[verify.index("--batch-size") + 1] == "8"
assert verify[verify.index("--capability-dir") + 1] == str(tmp_path / "capability")
assert "--matric-eval-bin" not in steps["verify-checkpoint"]
request = json.loads((tmp_path / "edit-request.json").read_text())
assert not {"batch_size", "matric_eval_bin", "vllm_command"} & set(request)