This repository was archived by the owner on Jul 3, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_linux_install.py
More file actions
74 lines (61 loc) · 2.71 KB
/
Copy pathtest_linux_install.py
File metadata and controls
74 lines (61 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
"""Regression tests for the Linux autostart installer contract."""
import shlex
import shutil
import subprocess
import unittest
from pathlib import Path
from typing import Optional
ROOT = Path(__file__).resolve().parent.parent
SCRIPT = ROOT / "install" / "install_linux.sh"
def find_usable_bash() -> Optional[str]:
"""Return a Bash binary that can read Windows workspace paths."""
candidates = []
found = shutil.which("bash")
if found and "WindowsApps" not in found:
candidates.append(Path(found))
candidates.append(Path(r"C:\Program Files\Git\bin\bash.exe"))
for candidate in candidates:
if candidate.is_file():
return str(candidate)
return None
def bash_readable_path(bash: str, path: Path) -> str:
"""Convert a Windows path into a path syntax the selected Bash understands."""
if not path.drive:
return path.as_posix()
rest = path.as_posix()[3:]
if "system32\\bash.exe" in bash.lower():
return f"/mnt/{path.drive[0].lower()}/{rest}"
return f"/{path.drive[0].lower()}/{rest}"
class LinuxInstallerTests(unittest.TestCase):
def test_script_exists_and_is_bash(self):
self.assertTrue(SCRIPT.is_file())
text = SCRIPT.read_text(encoding="utf-8")
self.assertTrue(text.startswith("#!/usr/bin/env bash"))
self.assertIn("set -euo pipefail", text)
def test_systemd_user_unit_contract_is_present(self):
text = SCRIPT.read_text(encoding="utf-8")
self.assertIn("Description=Fable 5 Hunter availability watcher", text)
self.assertIn("ExecStart=$PYTHON $SCRIPT run", text)
self.assertIn("Restart=on-failure", text)
self.assertIn("WantedBy=default.target", text)
self.assertIn("systemctl --user enable --now", text)
def test_cron_fallback_contract_is_present(self):
text = SCRIPT.read_text(encoding="utf-8")
self.assertIn("CRON_BEGIN=\"# BEGIN fable-5-hunter\"", text)
self.assertIn("@reboot cd $(shell_quote \"$SCRIPT_DIR\")", text)
self.assertIn("hunter.cron.log", text)
self.assertIn("crontab \"$clean\"", text)
def test_installer_is_user_scoped(self):
text = SCRIPT.read_text(encoding="utf-8")
self.assertNotIn("sudo ", text)
self.assertIn("No sudo/admin rights required", text)
self.assertIn("systemctl --user", text)
def test_bash_syntax_when_bash_is_available(self):
bash = find_usable_bash()
if not bash:
self.skipTest("usable bash is not available on this host")
script_path = bash_readable_path(bash, SCRIPT)
subprocess.run([bash, "-lc", f"bash -n {shlex.quote(script_path)}"], check=True)
if __name__ == "__main__":
unittest.main()