Initial commit

This commit is contained in:
Warezpeddler
2026-04-25 23:09:31 +01:00
commit 3325436017
92 changed files with 18397 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
"""Frozen-style mSCP script re-exec (generate_guidance) entrypoint."""
from __future__ import annotations
import sys
from pathlib import Path
import pytest
from applepy import cli
from applepy.mscp import APPLEPY_INTERNAL_MSCP_SCRIPT_FLAG, run_generate_guidance
def test_internal_mscp_script_entry_runs_script(tmp_path: Path) -> None:
script = tmp_path / "x.py"
script.write_text(
"import sys\n"
"assert 'hello' in sys.argv\n"
"raise SystemExit(0)\n",
encoding="utf-8",
)
code = cli._internal_mscp_script_entry([str(tmp_path), str(script), "hello"])
assert code == 0
def test_run_generate_guidance_frozen_uses_applepy_executable(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
root = tmp_path / "macos_security"
(root / "scripts").mkdir(parents=True)
(root / "scripts" / "generate_guidance.py").write_text("# stub\n", encoding="utf-8")
bl = root / "baselines" / "cis.yaml"
bl.parent.mkdir(parents=True)
bl.write_text("{}", encoding="utf-8")
captured: list[list[str]] = []
def fake_run(cmd, **kwargs):
captured.append(cmd)
class R:
returncode = 0
stdout = ""
stderr = ""
return R()
monkeypatch.setattr(sys, "frozen", True, raising=False)
monkeypatch.setattr(sys, "executable", "/fake/applepy", raising=False)
monkeypatch.setattr("applepy.mscp.subprocess.run", fake_run)
monkeypatch.delenv("APPLEPY_MSCP_FORCE_SUBPROCESS", raising=False)
code, out, err = run_generate_guidance(root, bl)
assert code == 0
assert captured
assert captured[0][0] == "/fake/applepy"
assert captured[0][1] == APPLEPY_INTERNAL_MSCP_SCRIPT_FLAG
assert captured[0][2] == str(root.resolve())
assert captured[0][3] == str((root / "scripts" / "generate_guidance.py").resolve())