Files
alzeo/tests/test_install_sudo_prompt.py
T
Hasan BasbunarandClaude Opus 5.5 7a8d0afdd7 v1.18.7: a full review of v1.18.6, and the defects it found fixed with a test each
- cockpit: a non-digit Content-Length is a 400 before any read (-1 read an
  unlimited body before login)
- proxy v6.24: the identity wall covers every route and method but /health;
  a path still escaped after one decode is refused; relayed /server_info loses
  the engine key fields; an unreadable keys file says so
- docs/clients.md: the keys file is installed owned by the user, the engine
  key goes in an EnvironmentFile
- image unit: After= on the text units, so a switch stops before it starts
- lifecycle: a down unit with a live container is an orphan, busy for the gate
- cockpit: its own /health probe no longer counts as activity (the canary
  never ran)
- install.sh: sudo asked at step 1 and renewed at step 8 with a prompt;
  CONTEXT_MODE=1m refused on a flash box after the convergence; the flash
  engine bind is read from the launcher
- switch-model.sh: downloads into the cache the installed unit mounts
- uninstall.sh, install-image.sh: remove only venv/ and sglang/ of the lane
- opencode limits hold the engine window (205000/32000 flash,
  173000/64000 native), fit() and the cockpit's verdict and autofit use the
  same rule, the 27B entry of a flash install comes from the table;
  collect_opencode has its @guard back
- Setup's Fit button has a click handler
- bench-agent: the TTFT slope is in the unit it prints
- CI: negated grep, generated script lists, exact sudoers argv, flash flags
  read from install.sh

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-24 13:40:38 +02:00

110 lines
4.3 KiB
Python

#!/usr/bin/env python3
"""The installer asks for the sudo password when a terminal can take it.
`sudo -n true || die` never prompts. On a fresh box where sudo wants a password (DGX OS
does), the one-liner died at step 8, after ~20 min of pulls, with "run sudo -v": nothing
before step 8 ever called sudo, and no page said to run it first (found in review,
2026-09-24; the reference box never showed it, because the installs there ran with an
askpass helper). Checked on that box's sudo: with a terminal, `sudo -v` asks and waits;
without one it fails at once ("a terminal is required"), so a background run still gets
the named refusal instead of a prompt nobody will answer.
These run the installer's own lines, as written, against a fake sudo that records its
calls: the ticket check at the end of step 1, before any download, and the one at step 8,
which renews a ticket that expired during the downloads (sudo keeps one 15 min).
"""
import pathlib
import subprocess
import tempfile
import unittest
REPO = pathlib.Path(__file__).resolve().parents[1]
TEXT = (REPO / "install.sh").read_text()
FAKE_SUDO = """#!/bin/sh
echo "sudo $*" >> "$SUDO_LOG"
case "$1" in
-n) exit "$TICKET" ;;
-v) exit "$ANSWER" ;;
esac
exit 0
"""
def block(start, end):
i = TEXT.index(start)
return TEXT[i:TEXT.index(end, i)]
def run(snippet, ticket, answer, no_service=0):
"""(rc, output, sudo calls). ticket/answer: the exit codes of `sudo -n true` and `sudo -v`."""
t = pathlib.Path(tempfile.mkdtemp(prefix="sudo-prompt-"))
(t / "sudo").write_text(FAKE_SUDO)
(t / "sudo").chmod(0o755)
log = t / "calls"
script = ("set -euo pipefail\n"
"die(){ echo \"DIE: $*\"; exit 1; }\n"
f"NO_SERVICE={no_service}\n" + snippet + "\necho REACHED\n")
r = subprocess.run(["bash", "-c", script], capture_output=True, text=True, timeout=30,
env={"PATH": f"{t}:/usr/bin:/bin", "SUDO_LOG": str(log),
"TICKET": str(ticket), "ANSWER": str(answer)})
calls = log.read_text().splitlines() if log.exists() else []
return r.returncode, r.stdout + r.stderr, calls
STEP8 = next(line for line in TEXT.splitlines() if line.startswith("sudo -n true"))
STEP1 = block('if [ "$NO_SERVICE" -eq 0 ] && ! sudo -n true 2>/dev/null; then', 'echo "OK (aarch64')
class StepOne(unittest.TestCase):
def test_it_asks_before_the_downloads_when_there_is_no_ticket(self):
rc, out, calls = run(STEP1, ticket=1, answer=0)
self.assertEqual(rc, 0, out)
self.assertIn("asks for your password now, before the downloads", out)
self.assertEqual(calls, ["sudo -n true", "sudo -v"])
def test_it_says_nothing_when_the_ticket_is_valid(self):
rc, out, calls = run(STEP1, ticket=0, answer=1)
self.assertEqual(rc, 0, out)
self.assertNotIn("password", out)
self.assertEqual(calls, ["sudo -n true"])
def test_without_a_terminal_it_refuses_before_anything_is_pulled(self):
rc, out, _ = run(STEP1, ticket=1, answer=1)
self.assertEqual(rc, 1)
self.assertIn("run 'sudo -v' in this terminal", out)
def test_no_service_never_touches_sudo(self):
rc, out, calls = run(STEP1, ticket=1, answer=1, no_service=1)
self.assertEqual(rc, 0, out)
self.assertEqual(calls, [])
def test_it_sits_before_the_first_download(self):
self.assertLess(TEXT.index(STEP1), TEXT.index('step "2/10'))
self.assertLess(TEXT.index('step "1/10'), TEXT.index(STEP1))
class StepEight(unittest.TestCase):
def test_a_valid_ticket_goes_straight_on(self):
rc, out, calls = run(STEP8, ticket=0, answer=1)
self.assertEqual(rc, 0, out)
self.assertIn("REACHED", out)
self.assertEqual(calls, ["sudo -n true"])
def test_an_expired_ticket_is_renewed_with_a_prompt(self):
# the downloads take longer than sudo's 15 min ticket on a fresh box
rc, out, calls = run(STEP8, ticket=1, answer=0)
self.assertEqual(rc, 0, out)
self.assertIn("REACHED", out)
self.assertEqual(calls, ["sudo -n true", "sudo -v"])
def test_no_terminal_is_still_a_named_refusal(self):
rc, out, _ = run(STEP8, ticket=1, answer=1)
self.assertEqual(rc, 1)
self.assertIn("sudo -v", out)
self.assertNotIn("REACHED", out)
if __name__ == "__main__":
unittest.main(verbosity=2)