sand-boxer/tests/test_runtime_smoke.py
tegwick 53f6ea2603
All checks were successful
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 2s
Advance dependency roots with guarded source implementations
Assistant: codex
Assistant-Model: gpt-6.1-sol
Assistant-Session: 01a10391-6355-7b41-b0fa-3e14e874f091
2026-10-04 11:01:47 +02:00

77 lines
2.7 KiB
Python

import importlib.util
import subprocess
import sys
from pathlib import Path
from types import SimpleNamespace
import pytest
spec = importlib.util.spec_from_file_location(
"runtime_smoke", Path(__file__).parents[1] / "scripts/smoke-bwrap-runtime.py"
)
smoke = importlib.util.module_from_spec(spec)
spec.loader.exec_module(smoke)
namespace = {"subprocess": subprocess, "Path": Path}
exec(smoke.ENTRYPOINT_PROBE, namespace)
started = namespace["entrypoint_started"]
inside = namespace["package_inside_runtime"]
def launcher(tmp_path, body):
runtime = tmp_path / "relocated runtime"
(runtime / "bin").mkdir(parents=True)
entry = runtime / "bin/glas-harness"
entry.write_text(f"#!{sys.executable}\n{body}\n")
entry.chmod(0o755)
return runtime, entry
def test_real_relocated_launcher_help_starts(tmp_path):
runtime, _ = launcher(tmp_path, "print('Usage: glas-harness [options]')")
assert started(runtime, "glas-harness")
@pytest.mark.parametrize("body", [
"print('not command help')",
"import sys; print('usage: fixture'); sys.exit(127)",
"import sys; print('stderr-canary', file=sys.stderr); sys.exit(1)",
])
def test_failed_or_non_help_launcher_is_not_evidence(tmp_path, body, capsys):
runtime, _ = launcher(tmp_path, body)
assert not started(runtime, "glas-harness")
assert capsys.readouterr() == ("", "")
def test_vanished_build_interpreter_and_missing_launcher_refuse(tmp_path):
runtime, entry = launcher(tmp_path, "print('usage: fixture')")
entry.write_text("#!/bin/sh\nexec /vanished/build/bin/python3 -c 'print(1)'\n")
assert not started(runtime, "glas-harness")
assert not started(runtime, "rein-aharness")
def test_launcher_timeout_is_not_startup_success(tmp_path):
runtime, _ = launcher(tmp_path, "import time; time.sleep(10)")
assert not started(runtime, "glas-harness", timeout=0.05)
def test_external_symlink_launcher_refuses_even_if_help_succeeds(tmp_path):
runtime, entry = launcher(tmp_path, "print('usage: fixture')")
external = tmp_path / "external"
entry.rename(external)
entry.symlink_to(external)
assert not started(runtime, "glas-harness")
def test_package_provenance_rejects_external_and_symlink_origins(tmp_path):
runtime = tmp_path / "runtime"
runtime.mkdir()
installed = runtime / "package.py"
installed.write_text("")
assert inside(SimpleNamespace(__file__=str(installed)), runtime)
external = tmp_path / "external.py"
external.write_text("")
installed.unlink()
installed.symlink_to(external)
assert not inside(SimpleNamespace(__file__=str(installed)), runtime)
assert not inside(SimpleNamespace(__file__=str(external)), runtime)
assert not inside(SimpleNamespace(), runtime)