import os import stat import subprocess import textwrap import unittest from pathlib import Path from tempfile import TemporaryDirectory ROOT = Path(__file__).resolve().parents[1] def write_executable(path, content): path.write_text(textwrap.dedent(content).lstrip(), encoding="utf-8") path.chmod(path.stat().st_mode | stat.S_IXUSR) class CheckSteamOSMirrorTests(unittest.TestCase): def test_fetches_repo_metadata_and_extracts_interesting_packages(self): tmp = TemporaryDirectory() self.addCleanup(tmp.cleanup) tmp_path = Path(tmp.name) run_dir = tmp_path / "run" fake_bin = tmp_path / "bin" fake_bin.mkdir() write_executable( fake_bin / "curl", """ #!/bin/sh for arg in "$@"; do url="$arg" done case "$url" in */archlinux-mirror/) printf '%s\\n' 'jupiter-main/holo-main/fremont-main/' ;; */archlinux-mirror/sources/) printf '%s\\n' 'jupiter-main/deckard-main/' ;; */jupiter-main.db|*/holo-main.db) printf '%s\\n' 'fake db' ;; *) echo "unexpected url: $url" >&2 exit 22 ;; esac """, ) write_executable( fake_bin / "bsdtar", """ #!/bin/sh out="" while [ "$#" -gt 0 ]; do if [ "$1" = "-C" ]; then shift out="$1" fi shift || true done mkdir -p "$out/jupiter-hw-support-20260413.1-1" "$out/steam-frame-config-1-1" cat > "$out/jupiter-hw-support-20260413.1-1/desc" <<'EOF' %NAME% jupiter-hw-support %VERSION% 20260413.1-1 EOF cat > "$out/steam-frame-config-1-1/desc" <<'EOF' %NAME% steam-frame-config %VERSION% 1-1 EOF """, ) env = os.environ.copy() env.update( { "PATH": f"{fake_bin}:{env['PATH']}", "STEAMOS_MIRROR_REPOS": "jupiter-main holo-main", } ) result = subprocess.run( [str(ROOT / "scripts" / "check_steamos_mirror.sh"), str(run_dir)], cwd=ROOT, env=env, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False, ) self.assertEqual("", result.stderr) self.assertEqual(0, result.returncode) key_lines = (run_dir / "reports" / "steamos-mirror-key-lines.txt").read_text( encoding="utf-8" ) repos = (run_dir / "reports" / "steamos-mirror-interesting-repos.txt").read_text( encoding="utf-8" ) self.assertIn("steam-frame-config", key_lines) self.assertIn("fremont-main", repos) self.assertIn("deckard-main", repos) class CheckSteamVRDepotsTests(unittest.TestCase): def test_rejects_challenge_pages_and_scans_local_snapshots(self): tmp = TemporaryDirectory() self.addCleanup(tmp.cleanup) tmp_path = Path(tmp.name) run_dir = tmp_path / "run" snapshot_dir = tmp_path / "steamvr" dashboard_dir = snapshot_dir / "resources" / "webinterface" dashboard_dir.mkdir(parents=True) (dashboard_dir / "dashboard.js").write_text( "const activeFrame = 'Steam Frame'; const codename = 'Deckard';", encoding="utf-8", ) fake_bin = tmp_path / "bin" fake_bin.mkdir() write_executable( fake_bin / "curl", """ #!/bin/sh for arg in "$@"; do url="$arg" done case "$url" in *steamdb.info*) printf '%s\\n' '