Files
OBLITERATUS/tests/test_gsq_launch_oracle.py

56 lines
2.3 KiB
Python

"""Exercise the GSQ launch oracle against harmless paths and injected argv."""
import pytest
from tests import test_gsq_workflow as cases
pytestmark = pytest.mark.cpu
fake_tree = cases.fake_tree
@pytest.mark.parametrize("word", cases.BANNED_DEPLOYMENT_STRINGS)
def test_launch_oracle_accepts_environment_interpreter(fake_tree, tmp_path, monkeypatch, word):
# No executable is created or run: the shared fixture records the launch.
interpreter = str(tmp_path / word / "bin" / "python")
monkeypatch.setattr(cases.sys, "executable", interpreter)
cases.test_run_quantization_executes_verified_command(fake_tree, tmp_path, monkeypatch)
@pytest.mark.parametrize("word", cases.BANNED_DEPLOYMENT_STRINGS)
def test_launch_oracle_accepts_verified_config_path(fake_tree, tmp_path, monkeypatch, word):
monkeypatch.setattr(cases.sys, "executable", str(tmp_path / "python"))
directory = tmp_path / word
directory.mkdir()
cases.test_run_quantization_executes_verified_command(fake_tree, directory, monkeypatch)
@pytest.mark.parametrize("argument", [*cases.BANNED_DEPLOYMENT_STRINGS, "-c", "-m", "--extra"])
def test_launch_oracle_rejects_tool_argument_injection(fake_tree, tmp_path, monkeypatch, argument):
monkeypatch.setattr(cases.sys, "executable", str(tmp_path / "python"))
original = cases.workflow.build_run_command
def inject(*args, **kwargs):
command = original(*args, **kwargs)
command.insert(2, argument)
return command
monkeypatch.setattr(cases.workflow, "build_run_command", inject)
with pytest.raises(AssertionError):
cases.test_run_quantization_executes_verified_command(fake_tree, tmp_path, monkeypatch)
@pytest.mark.parametrize("replacement", ["different-python", "python -c injected_code"])
def test_launch_oracle_rejects_interpreter_changes(fake_tree, tmp_path, monkeypatch, replacement):
monkeypatch.setattr(cases.sys, "executable", str(tmp_path / "python"))
original = cases.workflow.build_run_command
def inject(*args, **kwargs):
command = original(*args, **kwargs)
command[0] = str(tmp_path / replacement)
return command
monkeypatch.setattr(cases.workflow, "build_run_command", inject)
with pytest.raises(AssertionError):
cases.test_run_quantization_executes_verified_command(fake_tree, tmp_path, monkeypatch)