Harden remote execution contracts and tests

This commit is contained in:
Joseph Magly
2026-08-15 00:13:26 -04:00
parent 1240bf2adb
commit 62a480fd6a
12 changed files with 961 additions and 51 deletions
+44 -1
View File
@@ -168,7 +168,8 @@ def test_run_local_overrides_and_remote_config(monkeypatch, tmp_path):
config.remote = ns(
host="host", user="user", port=2200, ssh_key="key", remote_dir="/work",
python="python", sync_results=True, gpus="0",
known_hosts_file="known_hosts", install_timeout=120, python="python",
sync_results=True, gpus="0", install_source="obliteratus==0.1.2",
)
runner = MagicMock()
runner.run_config.return_value = "/local/results"
@@ -347,6 +348,15 @@ def test_remote_runner_factory_and_commands(monkeypatch):
monkeypatch.setattr(obliteratus.remote, "RemoteRunner", Mock(return_value=runner))
args = _remote_args()
assert cli._make_remote_runner(args) is runner
obliteratus.remote.RemoteConfig.from_cli_args.assert_called_once_with(
"user@host",
port=22,
ssh_key=None,
remote_dir="/work",
python="python3",
sync_results=True,
gpus="0",
)
monkeypatch.setattr(cli, "_make_remote_runner", lambda _args: runner)
runner.run_obliterate.return_value = "results"
@@ -359,6 +369,25 @@ def test_remote_runner_factory_and_commands(monkeypatch):
cli._cmd_remote_abliterate(args)
assert "refusal_max_tokens" not in runner.run_obliterate.call_args.kwargs
for name in (
"quantization", "n_directions", "direction_method", "regularization",
"refinement_passes", "min_layer_fraction", "max_layer_fraction",
"harmless_pc_count", "shield_concept_count", "shield_ridge",
"shield_residualize", "shield_layer_penalty", "projection_target",
"projection_row_fraction", "verify_sample_size", "refusal_max_tokens",
):
setattr(args, name, None)
args.large_model = False
runner.run_obliterate.reset_mock()
cli._cmd_remote_abliterate(args)
assert runner.run_obliterate.call_args.kwargs == {
"model": "model",
"local_output_dir": "out",
"method": "advanced",
"device": "cuda",
"dtype": "float16",
}
runner.run_config.return_value = "results"
cli._cmd_remote_run(args)
runner.run_tourney.return_value = "results"
@@ -375,6 +404,20 @@ def test_remote_runner_factory_and_commands(monkeypatch):
cli._cmd_remote_tourney(args)
@pytest.mark.parametrize("port", ["0", "65536", "not-a-port"])
def test_remote_cli_rejects_invalid_ssh_ports_before_dispatch(port):
with pytest.raises(SystemExit) as exc:
cli.main(["run", "config.yml", "--remote", "host", "--ssh-port", port])
assert exc.value.code == 2
def test_remote_cli_accepts_valid_ssh_port_and_dispatches(monkeypatch):
dispatch = Mock()
monkeypatch.setattr(cli, "_cmd_remote_run", dispatch)
cli.main(["run", "config.yml", "--remote", "host", "--ssh-port", "2222"])
assert dispatch.call_args.args[0].ssh_port == 2222
def test_abliterate_pipeline_callbacks_residue_and_contribution(monkeypatch, tmp_path):
import obliteratus.abliterate
import obliteratus.community