diff --git a/installer/tests/vm/gui-driver.py b/installer/tests/vm/gui-driver.py index 4852dae..ed771a3 100644 --- a/installer/tests/vm/gui-driver.py +++ b/installer/tests/vm/gui-driver.py @@ -14,7 +14,8 @@ Modes: opencode: drive the OpenCode AI step through the real graphical UI and validate a model response and proposal. gui-install: complete a full installation through the visible wizard (AI - connection, disk, account, ERASE, install) on a disposable disk. + connection, disk, account, direct "Install now", install) on a + disposable disk. install : boot, log in on serial, fetch a non-interactive config and 0600 secrets over QEMU user networking, run the deterministic install with the static binary, scan the log for a secret leak, power off. @@ -57,11 +58,12 @@ LIVE_PW = os.environ.get("LIVE_PASSWORD", "phoebus") USER = os.environ.get("USERNAME", "phoebus") USER_PW = os.environ.get("USER_PASSWORD", "phoebus-user-test") LUKS_PW = os.environ.get("LUKS_PASSPHRASE", "phoebus-luks-test") +USER_NAME = os.environ.get("USER_USERNAME", USER) +HOST_NAME = os.environ.get("HOST_NAME", "phoebus-vm") MEM = os.environ.get("VM_MEM", "8192") SMP = os.environ.get("VM_SMP", "8") BOOT_TIMEOUT = int(os.environ.get("BOOT_TIMEOUT", "900")) INSTALL_TIMEOUT = int(os.environ.get("INSTALL_TIMEOUT", "10800")) -SESSION_SETTLE = int(os.environ.get("SESSION_SETTLE", "20")) BACKEND_SETTLE = int(os.environ.get("BACKEND_SETTLE", "30")) # OpenCode GUI-driving knobs (test-only). The wizard focuses the first AI # provider chip when the AI step opens, so three Tabs reach the OpenCode chip. @@ -499,12 +501,16 @@ class Driver: f"n1={n1} n2={n2}", ) - # Keyboard-walk the wizard, capturing each step. The welcome step's - # primary action is focused, so Return starts the journey; Ctrl+Right - # then advances through the deterministic steps. - self.sendkey("ret") - time.sleep(2) - self.shot("03-language", "language and keyboard", "Return on Get started", + # The installer opens directly on step 1 (language and keyboard): the + # duplicate step-0 welcome was removed. Capture it and walk with + # Ctrl+Right from the frontend's own state, not a keystroke count. + at_language = self._goto_step(1) + self.results.assert_true( + "language-step-reached", + at_language is not None and at_language["step"] == 1, + f"the wizard did not open on the language step: {at_language}", + ) + self.shot("03-language", "language and keyboard", "installer opened", "the language and keyboard step is shown") # Regression: the suggestion list supports arrow-key navigation and # Enter selection, with the value stored being the identifier. @@ -526,13 +532,16 @@ class Driver: ) self.shot("03b-locale-selected", "locale selected", "Down then Enter", "the highlighted locale is selected") - for slug, state in [ - ("04-network", "network and prerequisites"), - ("05-ai-model", "AI model connection"), + for slug, label, target in [ + ("04-network", "network and prerequisites", 2), + ("05-ai-model", "AI model connection", 3), ]: - self.sendkey("ctrl-right") - time.sleep(2) - self.shot(slug, state, "Ctrl+Right", "next wizard step") + reached = self._goto_step(target) + self.results.assert_true( + f"{slug}-reached", reached is not None and reached["step"] == target, + f"did not reach {label}: {reached}", + ) + self.shot(slug, label, "Ctrl+Right", "next wizard step") if not self._installer_alive(): self.results.fail("installer-survived-navigation", f"crashed at {slug}") return @@ -655,6 +664,36 @@ class Driver: time.sleep(2) return None + def _goto_step(self, target: int, *, timeout: int = 90) -> dict | None: + """Advance to a wizard step using the frontend's own state. + + The installer now starts directly on step 1 (the duplicate step-0 + welcome was removed), so counting keystrokes is brittle. Poll the + secret-free state line and advance with Ctrl+Right until the step is + reached: a state-based wait, not a fixed number of keypresses. + """ + state = self._frontend_state() + if state is not None and state["step"] >= target: + return state + deadline = time.monotonic() + timeout + while time.monotonic() < deadline: + self.sendkey("ctrl-right") + time.sleep(1.5) + state = self._frontend_state() + if state is not None and state["step"] >= target: + return state + return state + + def _install_progress(self) -> str: + """A short, secret-free description of the current install state.""" + state = self._frontend_state() + if state is None: + return "no frontend state line available" + return ( + f"step={state['step']} phase={state['phase']} " + f"aiConnected={state['aiConnected']}" + ) + def do_opencode(self) -> None: """Drive the OpenCode AI step through the real graphical UI. @@ -706,19 +745,13 @@ class Driver: "CLOSED", timeout=30, label="close-welcome", ) - # Navigate to the AI step (welcome -> language -> network -> AI). - self.sendkey("ret") - time.sleep(2) - self.sendkey("ctrl-right") - time.sleep(2) - self.sendkey("ctrl-right") - time.sleep(2) - state = self._frontend_state() + # Navigate to the AI step from step 1 (language -> network -> AI). + state = self._goto_step(3) self.results.assert_true( "ai-step-reached", state is not None and state["step"] == 3, f"frontend state: {state}", ) - self.shot("oc-01-ai", "AI step", "Return + Ctrl+Right twice", "the AI model step is shown") + self.shot("oc-01-ai", "AI step", "Ctrl+Right to step 3", "the AI model step is shown") # Select the "OpenCode agent" chip with the keyboard. The AI step opens # with the first provider chip focused. @@ -890,8 +923,9 @@ class Driver: `appliance-guest-gui.sh` installs non-interactively, which does not prove the graphical journey. This mode presses the real controls: it connects OpenCode through the UI, accepts the reviewed AI changes, - selects a disk, sets the account, types ERASE, installs, and checks the - frontend reports completion. The disk must be a disposable qcow2. + selects a disk, sets the account, triggers the direct "Install now" + action, and checks the frontend reports completion. The disk must be a + disposable qcow2. """ if not self.disks: self.results.blocked("gui-install-disk", "no writable disk configured") @@ -908,8 +942,8 @@ class Driver: self.set_wayland() # Preseed the wizard defaults so the run is bounded (safe kernel, no - # desktop) while the wizard, validation, AI gate and ERASE confirmation - # remain the real graphical path. + # desktop) while the wizard, validation, AI gate and the direct + # "Install now" authorization remain the real graphical path. self.shell( f"curl -fsSL {SERVE_URL}/test.conf -o /tmp/gui-install.conf && " "sudo -n install -D -m 0644 /tmp/gui-install.conf /etc/phoebus/install.conf && " @@ -949,17 +983,11 @@ class Driver: "CLOSED", timeout=30, label="close-welcome", ) - # Welcome -> language -> network -> AI. - self.sendkey("ret") - time.sleep(2) - self.sendkey("ctrl-right") - time.sleep(2) - self.sendkey("ctrl-right") - time.sleep(3) - state = self._frontend_state() + # The installer opens on step 1; advance to the AI step. + state = self._goto_step(3) self.results.assert_true("gui-install-ai-step", state is not None and state["step"] == 3, f"AI step not reached: {state}") - self.shot("gi-01-ai", "AI step", "Return, Ctrl+Right twice", "AI connection step") + self.shot("gi-01-ai", "AI step", "Ctrl+Right to step 3", "AI connection step") # Select OpenCode and connect through the UI. for _ in range(OC_TAB_TO_CHIP): @@ -994,8 +1022,7 @@ class Driver: self.shot("gi-02-ai-reviewed", "AI reviewed", "Accept changes", "review accepted") # Destination disk: pick the first selectable disk. - self.sendkey("ctrl-right") - time.sleep(3) + self._goto_step(4) self.sendkey("tab") time.sleep(0.5) self.sendkey("ret") @@ -1041,59 +1068,66 @@ class Driver: f"the disk selection did not survive backtracking: {state}", ) - # Account and encryption. - self.sendkey("ctrl-right") - time.sleep(2) - state = self._frontend_state() + # Account and encryption. The current product has a single Username + # field, a Computer name, Password and Confirm password; the + # "Use same password to encrypt disk" toggle is on by default, so the + # separate LUKS passphrase fields are hidden and must not be driven. + state = self._goto_step(5) self.results.assert_true("gui-install-account-step", state is not None and state["step"] == 5, f"account step not reached: {state}") - self._tabs(3) # full name -> username -> computer name -> password + # Focus opens on Username. + self._gui_type(USER_NAME) + self._tabs(1) # -> Computer name + self._gui_type(HOST_NAME) + self._tabs(1) # -> Password self._gui_type(USER_PW) - self._tabs(2) # reveal -> confirm password + self._tabs(1) # -> Confirm password self._gui_type(USER_PW) - self._tabs(2) # reveal -> passphrase - self._gui_type(LUKS_PW) - self._tabs(2) # reveal -> confirm passphrase - self._gui_type(LUKS_PW) self.shot("gi-04-account", "account and encryption", "typed credentials", - "password and passphrase entered") + "username, computer name and matching password entered") - # Review and ERASE. The review step focuses the ERASE field. - self.sendkey("ctrl-right") - time.sleep(4) - state = self._frontend_state() + # Review. The product now uses a direct "Install now" action: typing + # ERASE and the confirmation checkbox were intentionally removed, and + # Ctrl+Right on the review step runs exactly that action. The backend + # still enforces approval binding and disk revalidation. + state = self._goto_step(6) self.results.assert_true("gui-install-review-step", state is not None and state["step"] == 6, f"review step not reached: {state}") self.shot("gi-05-review", "review and confirmation", "review shown", - "backend facts, plan and ERASE confirmation") - self._gui_type("ERASE") - self.sendkey("tab") # the confirmation toggle - time.sleep(0.4) - confirmed = self._frontend_state() - # The toggle responds to Return and Space; QEMU names Space `spc`. - for key in ("ret", "spc"): - if confirmed is not None and confirmed["confirm"]: - break - self.sendkey(key) - time.sleep(0.5) - confirmed = self._frontend_state() - if confirmed is None or not confirmed["confirm"]: - self.results.fail( - "gui-install-erase-confirmed", - f"the confirmation toggle was not ticked: {confirmed}", - ) - return - self.results.pass_("gui-install-erase-confirmed") - self.sendkey("ctrl-right") # authorize and install + "backend facts and the installation plan") + self.sendkey("ctrl-right") # Install now + started = time.monotonic() self.shot("gi-06-installing", "installing", "Ctrl+Right on review", "the installation has started") + # Approval replay: once the install is underway, submitting the review + # again must not crash the installer or regress it to a failure. The + # backend binds the authorization to the reviewed plan; the frontend + # must survive a repeated action. + underway = self.wait_state( + lambda s: s["phase"] in ("installing", "done", "failed"), timeout=180 + ) + if underway is not None: + self.sendkey("ctrl-right") + time.sleep(3) + replay = self._frontend_state() + self.results.assert_true( + "gui-install-replay-safe", + replay is not None and replay["phase"] != "failed" and self._installer_alive(), + f"re-submitting the review was not handled safely: {replay}", + ) + done = self.wait_state( lambda s: s["phase"] in ("done", "failed"), timeout=INSTALL_TIMEOUT, ) if done is None: - self.results.fail("gui-install-completes", "the wizard did not report completion") + elapsed = int(time.monotonic() - started) + self.results.fail( + "gui-install-completes", + f"the wizard did not report completion after {elapsed}s " + f"({self._install_progress()})", + ) return self.results.assert_true( "gui-install-completes", done["phase"] == "done", @@ -1211,7 +1245,20 @@ class Driver: assert self.child is not None idx = self.expect([r"[Pp]assphrase", r"login:"], timeout=BOOT_TIMEOUT, label="boot-prompt") if idx == 0: - self.child.sendline(LUKS_PW) + # `gui-install` uses the default single-password encryption, so the + # disk passphrase is the user password; the non-interactive + # `install` journey sets a separate one. Try both, in that order, + # and let cryptsetup's immediate re-prompt disambiguate without + # consuming the login prompt on success. + override = os.environ.get("BOOT_PASSPHRASE") + candidates = [override] if override else [USER_PW, LUKS_PW] + self.child.sendline(candidates[0]) + for candidate in candidates[1:]: + try: + self.child.expect(r"[Pp]assphrase", timeout=15) + self.child.sendline(candidate) + except (pexpect.TIMEOUT, pexpect.EOF): + break # accepted; the system is booting logged_in = False for _ in range(5): try: