fix(installer): harden boot recovery and desktop reliability
Some checks are pending
ci / test (push) Waiting to run

This commit is contained in:
Phoebus 2026-10-01 07:03:42 -07:00
parent 29d2cfd37a
commit b8152054b6
30 changed files with 1955 additions and 388 deletions

View file

@ -15,26 +15,5 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Rust format - name: Rust and VM harness checks
run: | run: make check
if command -v cargo >/dev/null 2>&1; then
cd installer-rs && cargo fmt --all -- --check
else
echo "cargo not installed on this runner; skipping"
fi
- name: Rust clippy
run: |
if command -v cargo >/dev/null 2>&1; then
cd installer-rs && cargo clippy --workspace --all-targets
else
echo "cargo not installed on this runner; skipping"
fi
- name: Rust test suite
run: |
if command -v cargo >/dev/null 2>&1; then
cd installer-rs && cargo test --workspace
else
echo "cargo not installed on this runner; skipping"
fi

View file

@ -5,6 +5,48 @@ this file is the curated, human-readable summary.
## Unreleased — Fast defaults with user-controlled source builds ## Unreleased — Fast defaults with user-controlled source builds
- **Installer and desktop reliability work (2026-10-01).** Armed BLS boot
counting only after creating the initial recovery snapshot, corrected the
boot-counter filename parser, and required the upstream failed-unit check
before `boot-complete.target` and `systemd-bless-boot` confirm a counted
boot. The default boot entry permits recovery fallback after exhausted
attempts. Btrfs swapfile allocation sets NOCOW first and fails closed.
Installed desktop assets have readable permissions, the DMS user service
link points into the installed system, and PipeWire/WirePlumber units are
enabled. First-login seeding now creates DMS's versioned changelog marker.
A graphical seat check found that Mango never started the installed Phoebus
welcome: its session did not run XDG autostart. The session now starts that
welcome explicitly; the QML uses fixed, unprivileged actions in place of an
undefined backend and has correctly sized cards. On a patched disposable
install, the first-login welcome and its Escape/seen-marker flow passed the
graphical desktop gate **30/30**.
The live welcome launcher and locale dropdown keyboard flow were repaired.
GURU-only Zsh plugins moved from the base package set to Mango, where the
overlay is synced before installation. ISO assembly replays boot metadata so
the MBR partition fits the remastered image; compression has bounded workers
and memory. Release reports bind gates to an ISO hash and clean source
revision, and require two installs, detached boot, recovery, fallback,
desktop, rollback, interruption, real model and CI evidence before publish.
The final candidate ISO (SHA-256
`b14f37e1b04d8e1ec37f77d2a14adb4aaef652770fee995a18a0ac7b986b5281`)
passed the live UEFI graphical gate (32/32) and real OpenCode installer flow
(18/18). Its embedded installer and `sys` hashes match the static build;
BIOS and UEFI boot entries and image partitions were verified. Two
independent encrypted Mango/Nix installs from this ISO passed 5/5 each.
The fresh installed system passed detached counted-boot assessment 5/5,
offline recovery 6/6, failed-boot fallback 9/9, graphical desktop 30/30,
package/root rollback 11/11 and interrupted-update recovery 10/10.
The desktop screenshot showed the first-login welcome and no DMS changelog.
Both installs logged a nonfatal busy LUKS mapper during final cleanup.
VM logs
and results redact registered credentials, and model UI password input uses
stdin. Release gate output handles multibyte text without panicking. Rust
format, Clippy and workspace tests pass. Forgejo CI now
runs `make check` directly so missing tooling fails the job. An intermediate
ISO with the corrected boot and DMS behavior passed its live checks but was
superseded before its installs completed when the missing installed welcome
launch was found.
- **System-wide stability audit & zero-panic hardening (2026-09-30).** - **System-wide stability audit & zero-panic hardening (2026-09-30).**
Exhaustive codebase verification, bug remediation, and panic elimination across all crates: Exhaustive codebase verification, bug remediation, and panic elimination across all crates:
1. Zero Unhandled Panics & Robust Error Handling: 1. Zero Unhandled Panics & Robust Error Handling:

View file

@ -136,13 +136,15 @@ Current state:
`enable DEST` at a synced/remote folder for a genuinely off-box copy, since `enable DEST` at a synced/remote folder for a genuinely off-box copy, since
the only git remote is one VPS. the only git remote is one VPS.
### CI runner (optional) ### CI runner (required for ISO release)
`.forgejo/workflows/ci.yml` mirrors the local gates but only runs once a `.forgejo/workflows/ci.yml` runs `make check` and only reports a result once a
Forgejo Actions runner is registered. Install `act_runner` on a machine, Forgejo Actions runner is registered. The release gate stays NotRun until an
independent runner passes; local checks do not authorize an ISO release.
Install `act_runner` on a machine,
register it (Site Administration -> Actions -> Runners, or register it (Site Administration -> Actions -> Runners, or
`act_runner register --instance https://git.phoebus.club --token <TOKEN>`), and `act_runner register --instance https://git.phoebus.club --token <TOKEN>`), and
run it as a service. Until then, run `make test` before pushing. run it as a service. Until then, run `make check` before pushing code.
### Commit signing (optional) ### Commit signing (optional)

View file

@ -3,6 +3,38 @@
Rolling note between work sessions. **Update this file before you finish**, then Rolling note between work sessions. **Update this file before you finish**, then
commit it. It should be short and current; use `git log` for detail. commit it. It should be short and current; use `git log` for detail.
- **Installer/desktop reliability candidate (2026-10-01, VM VERIFIED):**
Rust hardening, recovery-first boot counting, upstream systemd boot
assessment, desktop permissions/audio/DMS startup, live UI fixes and
exact-ISO release reporting are implemented. The current candidate is
`installer/live/phoebus-installer-amd64.iso` SHA-256
`b14f37e1b04d8e1ec37f77d2a14adb4aaef652770fee995a18a0ac7b986b5281`.
Its UEFI live UI gate passed 32/32
(`gui-gui-20261001T093944Z-0b2eeb6a`), and a real OpenCode installer
proposal passed 18/18 (`gui-opencode-20261001T094134Z-e2d90704`). The ISO
contains installer SHA-256
`5bf5d6868c1a22250ff62fc386804110e035fe52d2bc8ec10385c738a65d401a`
and `sys` SHA-256
`c5b079478f01e79ad4e823db87b32f0da7aecc13fb50afffc53cd53c58e8ff5d`;
both match the static build. Two independent encrypted Mango/Nix installs
passed 5/5 each on disposable `reliability-v7-a.qcow2` and
`reliability-v7-b.qcow2`
(`serial-install-20261001T094417Z-4e5913c7` and
`serial-install-repeat-20261001T094417Z-392fae4f`). The fresh second
install passed detached counted boot 5/5, installed graphical desktop 30/30
with visible first-login welcome, offline recovery 6/6, failed-boot
fallback 9/9, rollback 11/11 and interrupted update 10/10. Evidence IDs
and limits are in `docs/VM-BOOT-VERIFICATION.md`. The intermediate v6
installs were stopped after the missing installed welcome launch was found;
their partial disks were discarded. A patched v5 installed overlay passed
the first-login welcome and Escape/seen-marker graphical check 30/30; v5
also has two complete installs and recovery-path evidence. VM logs and
results redact registered credentials. Final cleanup on both v7 installs
logged a nonfatal busy LUKS mapper; investigate separately. CI remains
NotRun until an independent Forgejo runner reports success, and physical
hardware remains unverified. Keep the ISO unpublished while any required
release gate lacks evidence.
- **System-wide stability audit & zero-panic hardening (2026-09-30, IMPLEMENTED + TESTED):** - **System-wide stability audit & zero-panic hardening (2026-09-30, IMPLEMENTED + TESTED):**
Completed an exhaustive audit across all production crates to eliminate unexpected panics, fix subtle edge-case race conditions, and harden userspace agent protocols: Completed an exhaustive audit across all production crates to eliminate unexpected panics, fix subtle edge-case race conditions, and harden userspace agent protocols:
1. Eliminated all `unwrap()`/`expect()` panics in production code paths (`phoebus-installer::release`, `phoebus-installer::service::plan`, `phoebus-core::brand`, `phoebus-executor::chooser`, `phoebus-ai`, and `phoebus-executor::rollback`). 1. Eliminated all `unwrap()`/`expect()` panics in production code paths (`phoebus-installer::release`, `phoebus-installer::service::plan`, `phoebus-core::brand`, `phoebus-executor::chooser`, `phoebus-ai`, and `phoebus-executor::rollback`).

View file

@ -10,19 +10,19 @@ more interesting. Status vocabulary: **Done**, **Partial**, **Next**, **Later**.
| 3 | Port the deterministic core | Done | `phoebus-core` (config, plan, policy, validation, models) | | 3 | Port the deterministic core | Done | `phoebus-core` (config, plan, policy, validation, models) |
| 4 | Port the destructive backend | Done | `phoebus-executor` (storage, LUKS2, Btrfs, Portage, boot, users, services) | | 4 | Port the destructive backend | Done | `phoebus-executor` (storage, LUKS2, Btrfs, Portage, boot, users, services) |
| 5 | **Rust VM boot parity** | Done | Full encrypted UEFI install + boot, zero failed units, 10.7 s | | 5 | **Rust VM boot parity** | Done | Full encrypted UEFI install + boot, zero failed units, 10.7 s |
| 6 | Finish the desktop | Partial | **Mango + DankMaterialShell is the canonical desktop**; greetd login; the live ISO boots the branded welcome + graphical installer and was verified in a graphical VM; installed-desktop verification pending | | 6 | Finish the desktop | Partial | **Mango + DankMaterialShell is the canonical desktop**; installed seat0/DRM login, panel, terminal, spotlight, lock/unlock and logout passed in a VM; physical hardware, idle and polkit prompts remain unverified |
| 7 | Finish Flatpak | Partial | `flatpak 1.18.1` installed, flathub configured; bounded typed `flatpak_*` actions added; fast defaults install Calibre/GIMP/Flatseal system-wide from Flathub in the target (unit-tested, fail-closed verification; VM launch/MIME/update checks not run) | | 7 | Finish Flatpak | Partial | `flatpak 1.18.1` installed, flathub configured; bounded typed `flatpak_*` actions added; fast defaults install Calibre/GIMP/Flatseal system-wide from Flathub in the target (unit-tested, fail-closed verification; VM launch/MIME/update checks not run) |
| 8 | Instrument source/binary policy | Done | measured compile times harvested from `emerge.log` (326 entries); resolved-effect previews added | | 8 | Instrument source/binary policy | Done | measured compile times harvested from `emerge.log` (326 entries); resolved-effect previews added |
| 9 | Background update preparation | Partial | distfile fetch VM-verified; `--buildpkgonly` skipped while deps need merging (recorded Ready); activation explicit | | 9 | Background update preparation | Partial | distfile fetch VM-verified; `--buildpkgonly` skipped while deps need merging (recorded Ready); activation explicit |
| 10 | Snapshots / rollback | Done (normal `sys undo`); recovery-entry boot manual | normal `sys undo` acceptance PASSED on a fresh disposable clone (`serial-rollback-20260926T030237Z-912f6386` PASS=11 FAIL=0: DB changed then restored, root marker gone, `/home` survives, boot running); retention + free-space gate unit-tested; selecting the Phoebus Recovery (known-good snapshot) BLS entry offline with no network/model is a distinct manual acceptance gate (see `docs/VM-BOOT-VERIFICATION.md`), separate from `sys undo` | | 10 | Snapshots / rollback | Partial | final candidate: `sys undo` 11/11, interrupted update recovery 10/10, offline recovery 6/6 and automatic failed-boot fallback 9/9 on fresh-install overlays; physical hardware remains unverified |
| 11 | AI privilege and privacy architecture | Partial | typed actions + enforced privacy boundary + guided proposal review + OS-level sandbox (systemd-run hardening) + approval-bound resolved effects; live call/sandbox not VM-verified | | 11 | AI privilege and privacy architecture | Partial | typed actions + enforced privacy boundary + guided proposal review + OS-level sandbox (systemd-run hardening) + approval-bound resolved effects; live OpenCode calls and the `sys ask` sandbox have VM evidence, while the full installed candidate journey is pending |
| 12 | `sys` operations | Done | history, enable/disable, inspect, install, prepare-updates VM-verified; target-root consistency, execution-boundary validation, truthful `ask` failure, full transaction outcomes, empty-vs-unestablished plans, start/stop/restart + flatpak/nix/snapshot commands, deterministic `--legacy` administration, audited `--broker`/`--legacy` gates, unified multi-source updates, quiet proactive assistance, shared service layer (`phoebus_installer::service`), and 23-case VM acceptance suite (`sys-acceptance.sh` 23/23 PASS) | | 12 | `sys` operations | Done | history, enable/disable, inspect, install, prepare-updates VM-verified; target-root consistency, execution-boundary validation, truthful `ask` failure, full transaction outcomes, empty-vs-unestablished plans, start/stop/restart + flatpak/nix/snapshot commands, deterministic `--legacy` administration, audited `--broker`/`--legacy` gates, unified multi-source updates, quiet proactive assistance, shared service layer (`phoebus_installer::service`), and 23-case VM acceptance suite (`sys-acceptance.sh` 23/23 PASS) |
| 13 | Kernel optimization policy | Later | conservative fragments only; SAFE/OPTIMIZED/AGGRESSIVE selection exists | | 13 | Kernel optimization policy | Later | conservative fragments only; SAFE/OPTIMIZED/AGGRESSIVE selection exists |
| 14 | ISO / release pipeline | Partial | manifest/verify/assemble-plan tooling; release gates are executable (`gates --execute` runs each gate's real command and reports Passed/Failed/NotRun from evidence; publish refuses unless every gate passed); no CI runner has executed the VM/seat/model gates end to end | | 14 | ISO / release pipeline | Partial | manifest/verify/assemble-plan tooling; release gates are executable (`gates --execute` runs each gate's real command and reports Passed/Failed/NotRun from evidence; publish refuses unless every gate passed); the CI gate remains NotRun until an independent runner is configured |
| 15 | Recovery environment | Later | recovery BLS entry generated; snapshot-based recovery entry written at install; full recovery image not built | | 15 | Recovery environment | Later | recovery BLS entry generated; snapshot-based recovery entry written at install; full recovery image not built |
| — | Rust TUI | Partial | ratatui UI with plan/ERASE and AI provider selection; not yet the default on all paths | | — | Rust TUI | Partial | ratatui UI with plan/ERASE and AI provider selection; not yet the default on all paths |
| — | Graphical installer (welcome + wizard) | Partial | Quickshell/QML over the typed `--gui-bridge`; live graphical VM verified, including a detached install+boot; live AI call pending (ADR 0010) | | — | Graphical installer (welcome + wizard) | Partial | Quickshell/QML over the typed `--gui-bridge`; final candidate live UEFI GUI 32/32, real OpenCode guided proposal 18/18, two encrypted installs 5/5 each and installed desktop 30/30 (ADR 0010) |
| — | AI-guided install optimization | Partial | DeepSeek/OpenAI/local providers, evidence-gated typed review, mandatory at install with `--no-ai` break-glass; fixture-verified, no live call | | — | AI-guided install optimization | Partial | DeepSeek/OpenAI/local providers, evidence-gated typed review, mandatory at install with `--no-ai` break-glass; real OpenCode proposal validated and four changes applied in the live candidate VM |
| — | Nix as a built-in second lane | Partial | pinned-release bootstrap; `nix-daemon` active and `nix shell nixpkgs#hello` VM-verified; on by default | | — | Nix as a built-in second lane | Partial | pinned-release bootstrap; `nix-daemon` active and `nix shell nixpkgs#hello` VM-verified; on by default |
| — | Hardware-aware software selection (all lanes) | Partial | shared policy + candidate resolution + `choose_package`/`set_package_preference` (unit-tested); Snap first-use/install/refresh/remove, AppImage and custom-ebuild journeys VM-verified; strict Snap confinement and changed-revision update remain (ADR 0006 revised) | | — | Hardware-aware software selection (all lanes) | Partial | shared policy + candidate resolution + `choose_package`/`set_package_preference` (unit-tested); Snap first-use/install/refresh/remove, AppImage and custom-ebuild journeys VM-verified; strict Snap confinement and changed-revision update remain (ADR 0006 revised) |
| — | AI-first package administration | Done | unified CLI (`sys install`, `please`, `ask`) and desktop GUI (`phoebus-assistant`) backed by shared `service::*` planning, `PreparedPlan` digests with replay protection, Polkit elevation, QML provisioning, conversation continuity (`conversation::*`), Nix attribute verification, Portage binhost checks, and cross-source removal | | — | AI-first package administration | Done | unified CLI (`sys install`, `please`, `ask`) and desktop GUI (`phoebus-assistant`) backed by shared `service::*` planning, `PreparedPlan` digests with replay protection, Polkit elevation, QML provisioning, conversation continuity (`conversation::*`), Nix attribute verification, Portage binhost checks, and cross-source removal |
@ -30,19 +30,14 @@ more interesting. Status vocabulary: **Done**, **Partial**, **Next**, **Later**.
## Immediate next steps ## Immediate next steps
1. **Physical-seat desktop**: run Mango + DarkMaterial on a real VT (or a 1. **CI runner**: register an independent Forgejo Actions runner and record a
seat-providing VM) and verify kitty, DMS spotlight, lock, idle, the polkit passing run of `make check` for the verified ISO candidate. The release
agent, logout and reboot interactively (`docs/DEVELOPMENT.md`). gate is NotRun, so keep ISO SHA-256 `b14f37e1…c7b986b5281` unpublished.
2. **Mango + DankMaterialShell graphical verification**: Mango is now the 2. **Physical hardware follow-up**: verify Mango + DarkMaterial on a real VT,
default (ADR 0009). Install the `mango` profile and boot the Mango live ISO including idle, polkit prompts, logout and reboot. The graphical VM already
in a graphical, seat-providing VM and run the gates in proved greetd login, terminal, DMS spotlight and lock/unlock/logout.
`docs/VM-BOOT-VERIFICATION.md`. Default promotion was an explicit owner 3. **Cleanup follow-up**: diagnose the nonfatal busy LUKS mapper on installer
decision; verification is still required to claim stability. finalization, after all target subvolumes have unmounted.
3. **Offline recovery-entry boot**: select the Phoebus Recovery (known-good
snapshot) BLS entry with no network and no model, verify the selected
snapshot, boot, and basic deterministic `sys` operation — recorded
separately from the passed normal `sys undo` acceptance (ADR 0007,
`docs/VM-BOOT-VERIFICATION.md`).
4. **Binary strategy**: keep the official signed binhost for packages whose USE 4. **Binary strategy**: keep the official signed binhost for packages whose USE
matches and use Flatpak/Nix for other binaries; do not publish a private matches and use Flatpak/Nix for other binaries; do not publish a private
Gentoo binhost (ADR 0006). Verify with `emerge -pv` and record reuse. Gentoo binhost (ADR 0006). Verify with `emerge -pv` and record reuse.
@ -51,9 +46,9 @@ more interesting. Status vocabulary: **Done**, **Partial**, **Next**, **Later**.
custom-ebuild build now have VM evidence. Exercise an actual Snap revision custom-ebuild build now have VM evidence. Exercise an actual Snap revision
change and strict AppArmor confinement when suitable fixtures are available change and strict AppArmor confinement when suitable fixtures are available
(`docs/SYS.md`). (`docs/SYS.md`).
6. **Live AI provider call**: exercise `sys ask` and the installer guided path 6. **AI follow-up**: the live installer guided OpenCode path passed with a real
with a real 0600 key file; the path is currently fixture-verified only, and connected model. Recheck installed `sys ask` and sandbox behavior against
the `systemd-run` sandbox is not yet VM-verified. the final candidate ISO; the live installer model gate does not cover this.
## Later ## Later

View file

@ -43,7 +43,8 @@ VM-verified by the rollback acceptance gate
`app-misc/hello` install (package DB changed) → `sys undo <id>` → detached `app-misc/hello` install (package DB changed) → `sys undo <id>` → detached
reboot with the package DB restored, the root break marker gone, `/home` reboot with the package DB restored, the root break marker gone, `/home`
preserved, systemd running, and the snapshot-based recovery entry present. preserved, systemd running, and the snapshot-based recovery entry present.
Booting that recovery entry offline remains a manual gate. The snapshot recovery entry was later selected and booted offline in a
disposable VM; `serial-driver.py recovery` now automates the same check.
## Matrix ## Matrix
@ -71,11 +72,11 @@ Booting that recovery entry offline remains a manual gate.
| Rust VM boot parity | yes | yes | yes | no | | Rust VM boot parity | yes | yes | yes | no |
| Rust TUI | yes | yes | smoke test | no | | Rust TUI | yes | yes | smoke test | no |
| Typed GUI bridge (`--gui-bridge`) | yes | yes (dry-run) | live VM + full journey | n/a | | Typed GUI bridge (`--gui-bridge`) | yes | yes (dry-run) | live VM + full journey | n/a |
| Graphical welcome + install wizard (Quickshell) | yes | yes | live graphical VM + full GUI journey | no | | Graphical welcome + install wizard (Quickshell) | yes | yes | candidate ISO UEFI graphical gate `gui-gui-20261001T093944Z-0b2eeb6a` PASS=32 (welcome launcher, duplicate guard, locale keyboard filtering, AI requirement) | no |
| Phoebus brand system (SVG + tokens) | yes | yes | live VM | n/a | | Phoebus brand system (SVG + tokens) | yes | yes | live VM | n/a |
| Desktop profile (Mango + DarkMaterial) | yes | yes | live VM + installed | no | | Desktop profile (Mango + DarkMaterial) | yes | yes | live VM + installed | no |
| Desktop session script (socket wait, polkit, cleanup) | yes | yes | functional test (stubs) | no | | Desktop session script (socket wait, polkit, cleanup) | yes | yes | functional test (stubs) | no |
| PipeWire/WirePlumber | yes | no | headless (`wpctl`) | no | | PipeWire/WirePlumber | yes | yes (global user units enabled) | installed graphical seat: audio services active; headless `wpctl` | no |
| Flatpak + flathub | yes | no | installed + remote | no | | Flatpak + flathub | yes | no | installed + remote | no |
| Fast-default Flatpaks (Calibre/GIMP/Flatseal, system-wide, target-only) | yes | yes (install/verify/provisioning; fail-closed on missing app) | yes (installed in target root, verified in `/var/lib/flatpak/app/` and `/var/lib/phoebus/flatpaks-installed`) | no | | Fast-default Flatpaks (Calibre/GIMP/Flatseal, system-wide, target-only) | yes | yes (install/verify/provisioning; fail-closed on missing app) | yes (installed in target root, verified in `/var/lib/flatpak/app/` and `/var/lib/phoebus/flatpaks-installed`) | no |
| Fast `-bin` defaults (firefox-bin/libreoffice-bin/thunderbird-bin, fail-closed) | yes | yes (atoms, policy, binary-capability refusal) | yes (installed identities verified in Gentoo VDB on detached boot) | no | | Fast `-bin` defaults (firefox-bin/libreoffice-bin/thunderbird-bin, fail-closed) | yes | yes (atoms, policy, binary-capability refusal) | yes (installed identities verified in Gentoo VDB on detached boot) | no |
@ -83,7 +84,7 @@ Booting that recovery entry offline remains a manual gate.
| User-initiated source builds (`convert_to_source`) | yes | yes (table incl. thunderbird, review, build-before-remove, Brave/unknown refusals) | no (no conversion journey run in a VM) | no | | User-initiated source builds (`convert_to_source`) | yes | yes (table incl. thunderbird, review, build-before-remove, Brave/unknown refusals) | no (no conversion journey run in a VM) | no |
| Tuned-kernel build (`build_tuned_kernel`, separate BLS, fallback kept) | yes | yes (refusal without fallback, entry creation, default never blind-switched) | no (same long build; VM attempt recorded under the balanced row) | no | | Tuned-kernel build (`build_tuned_kernel`, separate BLS, fallback kept) | yes | yes (refusal without fallback, entry creation, default never blind-switched) | no (same long build; VM attempt recorded under the balanced row) | no |
| Balanced source kernel (`build_balanced_kernel`, broad hardware, bin fallback) | yes | yes (plan/fragment/review, refusal without fallback, separate `phoebus-balanced.conf`, default untouched; two VM-found bugs fixed: exact VDB match, `loader/entries` path) | **started, not completed** (disposable VM 2026-09-29: full distribution-config kernel build exceeded 3 h with 10 jobs, `RC=124`, no system change; needs a multi-hour window) | no | | Balanced source kernel (`build_balanced_kernel`, broad hardware, bin fallback) | yes | yes (plan/fragment/review, refusal without fallback, separate `phoebus-balanced.conf`, default untouched; two VM-found bugs fixed: exact VDB match, `loader/entries` path) | **started, not completed** (disposable VM 2026-09-29: full distribution-config kernel build exceeded 3 h with 10 jobs, `RC=124`, no system change; needs a multi-hour window) | no |
| Installed first-login welcome (once per user, reopenable, non-blocking) | yes | yes (assets, launcher, autostart, QML guards, DMS seed) | no (first login + graphical checks not run) | no | | Installed first-login welcome (once per user, reopenable, non-blocking) | yes | yes (assets, explicit Mango session launch, QML actions, DMS seed) | fresh candidate installed desktop 30/30; screenshot inspected, Escape creates seen marker | no |
| Install metrics (time, download, peak disk, installed size) | yes | yes (report rendering; orchestration hooks) | yes (Run 13 recorded 588 compile times into target metrics) | no | | Install metrics (time, download, peak disk, installed size) | yes | yes (report rendering; orchestration hooks) | yes (Run 13 recorded 588 compile times into target metrics) | no |
| XWayland / polkit agent / kitty / wofi | yes | no | installed, not launched | no | | XWayland / polkit agent / kitty / wofi | yes | no | installed, not launched | no |
| Package policy + measured history | yes | yes | yes (326 entries) | no | | Package policy + measured history | yes | yes | yes (326 entries) | no |
@ -93,12 +94,12 @@ Booting that recovery entry offline remains a manual gate.
| Inter-process mutation lock (`SystemLock` + dead-PID recovery) | yes | yes | no | no | | Inter-process mutation lock (`SystemLock` + dead-PID recovery) | yes | yes | no | no |
| Atomic durable transaction log (`transactions.toml`) | yes | yes | read-only in installed VM; write path needs root | no | | Atomic durable transaction log (`transactions.toml`) | yes | yes | read-only in installed VM; write path needs root | no |
| System health overview (`sys status` / `SystemStatus`) | yes | yes | no | no | | System health overview (`sys status` / `SystemStatus`) | yes | yes | no | no |
| Automatic Boot Assessment BLS counting (`bootctl mark-good`) | yes | yes | no | no | | Automatic Boot Assessment BLS counting (upstream `systemd-bless-boot`) | yes | yes | fresh candidate counted detached boot 5/5 and automatic fallback 9/9 | no |
| Btrfs rollback (`sys undo`) | yes | yes | yes (rollback acceptance `serial-rollback-20260926T030237Z-912f6386` PASS=11 FAIL=0) | no | | Btrfs rollback (`sys undo`) | yes | yes | yes (rollback acceptance `serial-rollback-20260926T030237Z-912f6386` PASS=11 FAIL=0) | no |
| Recovery/known-good BLS entry | yes | yes | yes: entry present + snapshot-based (rollback runs) **and the recovery entry itself was booted** (`Phoebus Recovery (known-good snapshot)` selected in the systemd-boot menu with restricted networking and no model: cmdline + findmnt prove root is the read-only `@-20260926T064646-initial-known-good` snapshot with `rescue.target`, serial login works, `sys history/rollback status --legacy` work, `sys ask` fails truthfully with the `--legacy` fallback) | no | | Recovery/known-good BLS entry | yes | yes | yes: entry present + snapshot-based (rollback runs) **and the recovery entry itself was booted** (`Phoebus Recovery (known-good snapshot)` selected in the systemd-boot menu with restricted networking and no model: cmdline + findmnt prove root is the read-only `@-20260926T064646-initial-known-good` snapshot with `rescue.target`, serial login works, `sys history/rollback status --legacy` work, `sys ask` fails truthfully with the `--legacy` fallback) | no |
| Snapshot retention + free-space gate | yes | yes | no | no | | Snapshot retention + free-space gate | yes | yes | no | no |
| AI typed proposals + evidence review | yes | yes | fixture end-to-end | n/a | | AI typed proposals + evidence review | yes | yes | fixture end-to-end | n/a |
| AI guided install (DeepSeek/OpenAI) | yes | yes | fixture path only (no live call) | n/a | | AI guided install (DeepSeek/OpenAI) | yes | yes | real OpenCode `opencode-go/deepseek-v4.1-flash` guided proposal in live candidate VM 18/18, four changes applied | n/a |
| AI privacy boundary (facts only) | yes | yes (every string field scanned, incl. `cpu_features`; forbidden path in `cpu_features` refused) | no | n/a | | AI privacy boundary (facts only) | yes | yes (every string field scanned, incl. `cpu_features`; forbidden path in `cpu_features` refused) | no | n/a |
| Provider credential + endpoint boundary | yes | yes (unsafe key characters refused before curl config; userinfo endpoint refused; derived base64 token redacted) | no | n/a | | Provider credential + endpoint boundary | yes | yes (unsafe key characters refused before curl config; userinfo endpoint refused; derived base64 token redacted) | no | n/a |
| AI typed-action schema (exact, incl. unit-variant extra keys) | yes | yes (plan/step/investigate actions via `validate_action_value`; smuggled extra key refused) | no | n/a | | AI typed-action schema (exact, incl. unit-variant extra keys) | yes | yes (plan/step/investigate actions via `validate_action_value`; smuggled extra key refused) | no | n/a |
@ -156,12 +157,12 @@ Booting that recovery entry offline remains a manual gate.
| Service start/stop/restart + flatpak/nix/snapshot commands | yes | yes | no | no | | Service start/stop/restart + flatpak/nix/snapshot commands | yes | yes | no | no |
| Desktop session helpers (DMS bar/launcher/lock/idle) | yes | yes | functional test (stubs) | no | | Desktop session helpers (DMS bar/launcher/lock/idle) | yes | yes | functional test (stubs) | no |
| Mango + DankMaterialShell profile | yes | yes | live VM yes; installed desktop_install yes (347 pkgs); **seatd service active and running on detached boot** (`/run/seatd.sock` 0660 root:seat, `phoebus` in seat group); greeter, seat, DRM, PAM authentication and `sys --legacy` are verified | no | | Mango + DankMaterialShell profile | yes | yes | live VM yes; installed desktop_install yes (347 pkgs); **seatd service active and running on detached boot** (`/run/seatd.sock` 0660 root:seat, `phoebus` in seat group); greeter, seat, DRM, PAM authentication and `sys --legacy` are verified | no |
| Mango is the canonical desktop | yes | yes | live VM yes; installed default session configured | no | | Mango is the canonical desktop | yes | yes | fresh candidate installed graphical seat 30/30: Mango + DMS, first-login Phoebus welcome, terminal, spotlight, lock/unlock/logout | no |
| greetd login (Mango + DarkMaterial) | yes | yes | yes (tuigreet verified on detached boot; **graphical authentication verified under a seat VM**: seat0 + DRM card0 + greeter session, correct password authenticates per the journal) | no | | greetd login (Mango + DarkMaterial) | yes | yes | authenticated seat0 + DRM card0 graphical login and logout, `gui-desktop-20261001T084157Z-ccefa3e1` | no |
| Live desktop ISO (Mango + DMS) | yes | guards tested | graphical VM + GUI journey + detached boot + interactive welcome (20260926 ISO, screenshot) | no | | Live desktop ISO (Mango + DMS) | yes | guards tested | candidate ISO SHA `b14f37e1…c7b986b5281`: UEFI GUI 32/32, real OpenCode 18/18; embedded static binaries match | no |
| Live welcome autostart + duplicate prevention | yes | guards tested | live graphical VM | no | | Live welcome autostart + duplicate prevention | yes | guards tested | live graphical VM | no |
| Welcome primary action keyboard-focus | yes | guards tested | live graphical VM | no | | Welcome primary action keyboard-focus | yes | guards tested | live graphical VM | no |
| VM harness disk safety + structured results | yes | yes (16 tests) | n/a | n/a | | VM harness disk safety + structured results | yes | yes (22 tests, including backing-chain and redaction cases) | n/a | n/a |
| Target disk revalidation before partition | yes | yes | no | n/a | | Target disk revalidation before partition | yes | yes | no | n/a |
| Bridge replay/concurrency + input bounds | yes | yes | no | n/a | | Bridge replay/concurrency + input bounds | yes | yes | no | n/a |
| Provider transport endpoint/size hardening | yes | yes | no | n/a | | Provider transport endpoint/size hardening | yes | yes | no | n/a |
@ -173,7 +174,7 @@ Booting that recovery entry offline remains a manual gate.
| GUI readiness refresh / AI revalidation / keyboard nav | yes | yes (Rust) | VM harness regressions | n/a | | GUI readiness refresh / AI revalidation / keyboard nav | yes | yes (Rust) | VM harness regressions | n/a |
| Mandatory AI requires a validated interaction | yes | yes | bridge + CLI | n/a | | Mandatory AI requires a validated interaction | yes | yes | bridge + CLI | n/a |
| GURU packaging (scoped keywords) | yes | yes | no (build/install unverified) | no | | GURU packaging (scoped keywords) | yes | yes | no (build/install unverified) | no |
| Release gates + atomic publish | yes | yes (executable: every gate names a real harness mode; `--execute` runs each command in its own process and reports Passed/Failed/NotRun from evidence; invalid commands, isolation, failed-gate and publish refusal covered) | no (no end-to-end candidate: VM/graphical/model gates need a runner; unconfigured host reports 0 passed / 0 failed / 6 NotRun with exact missing prerequisites) | n/a | | Release gates + atomic publish | yes | yes (executable gates, exact ISO hash and clean source revision required for publish; separate disk required for repeat install; live assistant and CI gates required) | candidate ISO UEFI UI 32/32, real assistant 18/18, two independent installs 5/5 each, detached boot 5/5, installed desktop 30/30, offline recovery 6/6, fallback 9/9, rollback 11/11, interrupted update 10/10; CI NotRun, ISO unpublished | n/a |
| `sys` verbs | yes | yes | yes | no | | `sys` verbs | yes | yes | yes | no |
| OpenCode pinned bootstrap | yes | yes | no | n/a | | OpenCode pinned bootstrap | yes | yes | no | n/a |
| Release manifest/verify | yes | yes (host CLI: manifest, verify, tampered-artifact refusal) | no | n/a | | Release manifest/verify | yes | yes (host CLI: manifest, verify, tampered-artifact refusal) | no | n/a |
@ -219,7 +220,7 @@ Booting that recovery entry offline remains a manual gate.
| Startup system check (blur/PPD/matugen/cava, truthful summary) | yes | yes (4-check evaluation + summary wording) | no (recheck after reboot NotRun; needs PPD D-Bus + DMS integration) | no | | Startup system check (blur/PPD/matugen/cava, truthful summary) | yes | yes (4-check evaluation + summary wording) | no (recheck after reboot NotRun; needs PPD D-Bus + DMS integration) | no |
| Assistant dark default + light mode + responsive + token drift guard | yes | yes (palette/aliases, drift test, layout guards) | no (graphical VM at 1024×768/1280×720/scaled NotRun) | no | | Assistant dark default + light mode + responsive + token drift guard | yes | yes (palette/aliases, drift test, layout guards) | no (graphical VM at 1024×768/1280×720/scaled NotRun) | no |
| Userspace AI agent framework (`agent_jail`, `desktop_config`, `phoebus-mcp`, `sys propose`) | yes | yes (Bubblewrap credential masking, schema validation + checkpoint undo, MCP JSON-RPC conformance, unprivileged plan staging) | smoke test (`phoebus-agent-run`, MCP stdio, theme undo) | no | | Userspace AI agent framework (`agent_jail`, `desktop_config`, `phoebus-mcp`, `sys propose`) | yes | yes (Bubblewrap credential masking, schema validation + checkpoint undo, MCP JSON-RPC conformance, unprivileged plan staging) | smoke test (`phoebus-agent-run`, MCP stdio, theme undo) | no |
| Automatic Boot Assessment (`bootctl mark-good`, `enable_boot_counting`, unmetered recovery) | yes | yes (BLS `<id>+<tries>.conf` formatting/parsing, `phoebus-boot-confirm.service`, recovery entry protection) | no | no | | Automatic Boot Assessment (upstream `systemd-bless-boot`, boot counting, unmetered recovery) | yes | yes (correct `+tries-tries_done` parsing, upstream failed-unit health check, recovery sort/default, entry protection) | fresh candidate counted detached boot 5/5 and fallback 9/9 | no |
| Update preflight safety gates (>=10 GiB storage gate + atomic coordinated `@` and `@var` snapshots) | yes | yes (`check_update_preflight` storage refusal, `create_pre_update_snapshot_set`) | no | no | | Update preflight safety gates (>=10 GiB storage gate + atomic coordinated `@` and `@var` snapshots) | yes | yes (`check_update_preflight` storage refusal, `create_pre_update_snapshot_set`) | no | no |
| Tiered update channels (`Core`, `Proven` [default], `Edge`) | yes | yes (`UpdateChannel` enum, serialization, channel defaults) | no | no | | Tiered update channels (`Core`, `Proven` [default], `Edge`) | yes | yes (`UpdateChannel` enum, serialization, channel defaults) | no | no |
@ -359,10 +360,9 @@ Booting that recovery entry offline remains a manual gate.
instead of its own snapshot, and never asserted the root marker was gone. instead of its own snapshot, and never asserted the root marker was gone.
Those harness defects are fixed in this session (sudo authentication with Those harness defects are fixed in this session (sudo authentication with
unique end markers, explicit `--legacy`, verified break, targeted undo, unique end markers, explicit `--legacy`, verified break, targeted undo,
marker-absent assertion) and the gate above is the evidence. Booting the marker-absent assertion) and the gate above is the evidence. The recovery
recovery entry itself offline (no network, no model) remains a manual, entry was later booted offline and is now selected by the automated
un-automated gate: select "Phoebus Recovery (known-good snapshot)" in the `serial-driver.py recovery` mode.
systemd-boot menu.
- **Mango + DankMaterialShell** is the canonical Phoebus desktop - **Mango + DankMaterialShell** is the canonical Phoebus desktop
(`desktop.profile = "mango"`, Flatpak on). It is implemented with Mango (`desktop.profile = "mango"`, Flatpak on). It is implemented with Mango
0.17.2, DMS (pinned release), Quickshell 0.3.1 and scenefx 0.5 from the GURU 0.17.2, DMS (pinned release), Quickshell 0.3.1 and scenefx 0.5 from the GURU

View file

@ -3,6 +3,136 @@
This records the first successful end-to-end install and boot of Phoebus OS This records the first successful end-to-end install and boot of Phoebus OS
against a disposable qcow2 disk. No physical disk was ever touched. against a disposable qcow2 disk. No physical disk was ever touched.
## 2026-10-01 Reliability candidate
- Final candidate ISO SHA-256
`b14f37e1b04d8e1ec37f77d2a14adb4aaef652770fee995a18a0ac7b986b5281`
contains installer SHA-256
`5bf5d6868c1a22250ff62fc386804110e035fe52d2bc8ec10385c738a65d401a`
and `sys` SHA-256
`c5b079478f01e79ad4e823db87b32f0da7aecc13fb50afffc53cd53c58e8ff5d`.
These match files extracted from the ISO's squashfs. xorriso reports BIOS
and UEFI boot entries; the MBR partitions end within the image.
Its UEFI live graphical gate passed **32/32**
(`gui-gui-20261001T093944Z-0b2eeb6a`), and the real OpenCode model UI
passed **18/18** (`gui-opencode-20261001T094134Z-e2d90704`): connection
tested, proposal validated and four changes applied before install. Two
independent encrypted Mango/Nix installs from this exact ISO passed **5/5
each** on
`reliability-v7-a.qcow2` and `reliability-v7-b.qcow2`
(`serial-install-20261001T094417Z-4e5913c7` and
`serial-install-repeat-20261001T094417Z-392fae4f`).
- The fresh second install passed detached counted-boot assessment **5/5**
(`serial-boot-assessed-20261001T134254Z-591a4911`). Its installed Mango/DMS
graphical seat passed **30/30**
(`gui-desktop-20261001T134354Z-9c970fae`), including a visibly readable
first-login welcome, Escape/seen-marker dismissal, no DMS onboarding or
changelog popup, terminal, launcher, lock/unlock and logout. The screenshot
was inspected. Offline snapshot recovery passed **6/6**
(`serial-recovery-20261001T134701Z-455b71b6`), three interrupted normal
boots followed by automatic recovery passed **9/9**
(`serial-fallback-20261001T134759Z-1263d7c2`), package/root rollback
passed **11/11** (`serial-rollback-20261001T135201Z-a6caf8ad`), and an
interrupted package transaction with reboot and state verification passed
**10/10** (`serial-interrupted-update-20261001T135600Z-53ea9a73`). These
destructive checks used disposable overlays. Final cleanup on both installs
logged a nonfatal busy LUKS mapper; installation, secret scan and guest
poweroff still passed. The cleanup condition remains to be diagnosed.
- The intermediate ISO SHA-256
`22a197b68a48ef4330f71a4612a8f1b79a6aba1a1d932c4c53426783ccc347a7`
passed its UEFI UI 32/32 and real OpenCode UI 18/18. Its two installs were
deliberately stopped and its partial disks discarded after a graphical
test exposed the missing installed welcome launch. It is not release
evidence for full installs.
- The Forgejo workflow now runs `make check` and fails if the Rust toolchain
is missing. No independent runner has reported a result for this ISO; the CI
release gate remains NotRun.
- The preceding ISO's UEFI graphical live gate passed **32/32** checks on SHA-256
`1c2a2feb3684d167acd5eecf2356a42dd3ca118cd1e16c215a13d7d0aa58a53d`
(`gui-gui-20261001T002227Z-2138a45d`). It opened the installer from the
welcome action, confirmed duplicate prevention, selected `de_DE` using
keyboard filtering, walked the wizard, and enforced the unconnected-model
stop. Earlier runs exposed and led to fixes for a launcher self-kill, initial
focus theft, and the combo's disconnected search filter.
- Two independent full encrypted Mango/Nix installs **passed 4/4 each** on disposable
80 GiB qcow2 disks (`reliability-v5-a.qcow2` and
`reliability-v5-b.qcow2`). Both guests reported embedded installer SHA-256
`fb362e2bfe2abb515593c4e18f66a1bffc3d78d9faf5171db25f4cb253d3438e`,
matching the binary packed into that exact ISO
(`serial-install-20261001T002156Z-be083980` and
`serial-install-repeat-20261001T002209Z-eabe6f49`). Both installs ended
after clean target unmounts; `cryptsetup close cryptroot` returned device-busy
during final cleanup, which is nonfatal and remains to be diagnosed.
- A detached counted boot passed **5/5** after manually rearming a normal BLS
entry on an overlay (`serial-boot-assessed-20261001T083943Z-19937c05`).
`systemd-bless-boot.service`, the failed-unit checker and
`boot-complete.target` were active; the entry lost its counter. The custom
`phoebus-boot-confirm.service` in the preceding ISO was skipped because its
`/run/systemd/boot-loader` condition was unmet and would fail if started
(`bootctl mark-good` is unsupported). The corrected source uses the upstream
blessing unit and only requires the failed-unit health check.
- Offline recovery on a fresh overlay of that install passed **6/6**
(`serial-recovery-20261001T084345Z-803fd654`). The fourth boot after three
simulated incomplete boots automatically chose read-only recovery and passed
**9/9** (`serial-fallback-20261001T084849Z-69692982`).
- A real `sys undo` journey on another overlay passed **11/11**
(`serial-rollback-20261001T090102Z-acf152ae`): it changed the root and
Portage database, restored the paired snapshots, and verified the detached
boot and persistent home marker. The interrupted-update journey passed
**10/10** (`serial-interrupted-update-20261001T090501Z-2e3088c6`): it killed
an active `sys`/emerge transaction, recovered the lock, undid the snapshot
and verified the package database after reboot. The fixture HTTP server
initially served stale scripts; they were synced to the repository before
these passing runs.
- The installed graphical desktop passed **27/27** on the untouched second
install (`gui-desktop-20261001T081722Z-65c0f48b`), including seat0,
Mango/DMS, audio, network, terminal, spotlight, lock/unlock and logout.
The screenshot showed a DMS changelog popup despite the generic firstlaunch
marker. After seeding the versioned `.changelog-1.6` marker on a fresh
overlay, the same graphical gate passed **28/28** and the popup was absent
(`gui-desktop-20261001T084157Z-ccefa3e1`). The corrected installer now
seeds both markers before first login.
- That screenshot also showed no Phoebus installed welcome. The custom Mango
session launched the live welcome but did not run XDG autostart for the
installed welcome. On an overlay with the new session script, launcher and
QML, the welcome appeared, but its original `GroupBox` content overlapped.
The revised fixed-size cards were visibly readable
(`gui-desktop-20261001T091939Z-6d3d9a26`, **29/29**). A second run used
Escape to dismiss it, confirmed the per-user seen marker, then passed the
rest of the desktop gate (`gui-desktop-20261001T092418Z-3f190135`,
**30/30**). These overlay runs validate behavior; the final ISO still needs
packaging and a fresh install.
- The ISO build now uses bounded squashfs workers/cache and replays the
detected El Torito configuration after mapping files. The previous image
copied the 1.9 GiB base MBR partition length into a smaller 1.5 GiB file.
The corrected image reopens cleanly in xorriso, has both BIOS and UEFI boot
entries, and its MBR partitions end within the file. Its squashfs installer
and `sys` hashes matched the static binaries copied into the ISO at assembly.
- A preceding install using the minimal VM fixture failed in `packages_base`
because GURU-only Zsh plugins were in the base package set while GURU was
only synced for Mango. The optional plugins were moved to the Mango set,
and the release install fixture now selects the canonical Mango/Nix profile.
- The offline recovery gate on a preexisting installed-system overlay passed
**6/6** checks: actual systemd-boot recovery entry selection, read-only
`@snapshots` root, and deterministic `sys` without network/model. This is
baseline evidence, separate from the new candidate run.
- The interrupted-update gate passed **10/10** on another preexisting-system
overlay (`serial-interrupted-update-20260930T214842Z-c4d8000b`): it killed
`sys` while a real `emerge --ask=n` process was active, recovered the stale
mutation lock, undid the paired snapshot, booted detached, and checked the
package DB fingerprint and persistent `/home` marker. The first trial caught
a harness race: parsing buffered CLI output missed a fast package install;
the gate now detects the active emerge process group directly.
- The failed-boot fallback preflight passed **9/9** on a disposable overlay of
the older installed system (`serial-fallback-20260930T230340Z-1983d95a`).
Three boots were stopped at the locked-root rescue prompt before health
confirmation. The fourth boot selected the read-only snapshot recovery root,
and the normal BLS entry had reached `+0-3.conf`. An earlier trial continued
from rescue into the normal target, which correctly blessed the boot and
exposed a flaw in the test procedure. The driver now simulates power loss
at the rescue prompt.
## 2026-09-29 Iterative `sys` VM loop on the golden overlay (AI sandbox + journeys) ## 2026-09-29 Iterative `sys` VM loop on the golden overlay (AI sandbox + journeys)
Fresh qcow2 overlays were created on the golden installed image Fresh qcow2 overlays were created on the golden installed image

View file

@ -237,18 +237,23 @@ pub fn format_bls_filename(stem: &str, tries: Option<u32>) -> String {
} }
/// Parses a BLS filename into its base stem and optional remaining tries. /// Parses a BLS filename into its base stem and optional remaining tries.
/// Follows the Boot Loader Specification: `<id>+<tries>[,<tries-done>].conf` /// Follows the Boot Loader Specification: `<id>+<tries>[-<tries-done>].conf`
/// E.g., `phoebus+3.conf` -> ("phoebus", Some(3)) /// E.g., `phoebus+3.conf` -> ("phoebus", Some(3))
/// E.g., `phoebus+2,1.conf` -> ("phoebus", Some(2)) /// E.g., `phoebus+2-1.conf` -> ("phoebus", Some(2))
/// E.g., `phoebus.conf` -> ("phoebus", None) /// E.g., `phoebus.conf` -> ("phoebus", None)
pub fn parse_bls_filename(filename: &str) -> (String, Option<u32>) { pub fn parse_bls_filename(filename: &str) -> (String, Option<u32>) {
let name = filename.strip_suffix(".conf").unwrap_or(filename); let name = filename.strip_suffix(".conf").unwrap_or(filename);
if let Some((stem, rest)) = name.split_once('+') { if let Some((stem, rest)) = name.rsplit_once('+') {
let tries_str = rest.split(',').next().unwrap_or(rest); let (tries_str, done_str) = rest.split_once('-').unwrap_or((rest, ""));
if (done_str.is_empty() || done_str.parse::<u32>().is_ok())
&& !tries_str.is_empty()
&& !rest.ends_with('-')
{
if let Ok(tries) = tries_str.parse::<u32>() { if let Ok(tries) = tries_str.parse::<u32>() {
return (stem.to_string(), Some(tries)); return (stem.to_string(), Some(tries));
} }
} }
}
(name.to_string(), None) (name.to_string(), None)
} }
@ -366,9 +371,13 @@ mod tests {
("phoebus".to_string(), Some(3)) ("phoebus".to_string(), Some(3))
); );
assert_eq!( assert_eq!(
parse_bls_filename("phoebus+2,1.conf"), parse_bls_filename("phoebus+2-1.conf"),
("phoebus".to_string(), Some(2)) ("phoebus".to_string(), Some(2))
); );
assert_eq!(
format_bls_filename("phoebus+2-1.conf", Some(3)),
"phoebus+3.conf"
);
assert_eq!( assert_eq!(
parse_bls_filename("phoebus.conf"), parse_bls_filename("phoebus.conf"),
("phoebus".to_string(), None) ("phoebus".to_string(), None)

View file

@ -93,9 +93,9 @@ pub fn mango_desktop_packages() -> Vec<&'static str> {
"gui-libs/xdg-desktop-portal-wlr", "gui-libs/xdg-desktop-portal-wlr",
]; ];
out.extend(workstation_packages()); out.extend(workstation_packages());
// Shell lane lives in `base_packages` (needed before `users_configure`); // The login shell lives in `base_packages` before `users_configure`.
// cursor/printing/ssh/power/helpers have no early validation and stay // GURU-only plugins are installed after the overlay is synced for Mango.
// in the desktop lane. out.extend(shell_plugin_packages());
out.extend(cursor_packages()); out.extend(cursor_packages());
out.extend(printing_packages()); out.extend(printing_packages());
out.extend(ssh_packages()); out.extend(ssh_packages());
@ -174,13 +174,16 @@ pub fn fast_default_flatpak_ids() -> Vec<&'static str> {
FAST_DEFAULT_FLATPAKS.iter().map(|(_, id)| *id).collect() FAST_DEFAULT_FLATPAKS.iter().map(|(_, id)| *id).collect()
} }
/// Shell lane: Zsh is the default login shell for newly created users. /// Base shell lane: Zsh must exist before `users_configure`. The optional
/// GURU plugins are installed with Mango after that overlay has been synced.
/// Bash stays for system scripts and root administration (`/bin/sh` is /// Bash stays for system scripts and root administration (`/bin/sh` is
/// untouched). Packaged plugins only — no downloaded shell framework. /// untouched).
pub fn shell_packages() -> Vec<&'static str> { pub fn shell_packages() -> Vec<&'static str> {
vec!["app-shells/zsh", "app-shells/zsh-completions"]
}
pub fn shell_plugin_packages() -> Vec<&'static str> {
vec![ vec![
"app-shells/zsh",
"app-shells/zsh-completions",
"app-shells/zsh-autosuggestions", "app-shells/zsh-autosuggestions",
"app-shells/zsh-syntax-highlighting", "app-shells/zsh-syntax-highlighting",
] ]
@ -913,8 +916,8 @@ pub fn accept_keywords_mango() -> String {
/// `app-shells/zsh` itself is stable; the packaged plugins /// `app-shells/zsh` itself is stable; the packaged plugins
/// (`zsh-autosuggestions` proven `~amd64`-only in GURU by VM install run 3, /// (`zsh-autosuggestions` proven `~amd64`-only in GURU by VM install run 3,
/// the other two scoped alongside it) ship testing-only. The login shell is /// the other two scoped alongside it) ship testing-only. The login shell is
/// a base package, so these keywords are written with the base Portage /// a base package; the optional plugins are installed with Mango only after
/// configuration whenever GURU is enabled — not only for the Mango profile. /// GURU is synced. These keywords are written when GURU is enabled.
/// This is NOT a global `~amd64` switch. /// This is NOT a global `~amd64` switch.
/// ///
/// `app-shells/zsh` is keyworded alongside its plugins: GURU's /// `app-shells/zsh` is keyworded alongside its plugins: GURU's
@ -1484,11 +1487,14 @@ elif [ "$started" = 0 ]; then
echo "phoebus-session-mango: dms not found; the shell will not start" >&2 echo "phoebus-session-mango: dms not found; the shell will not start" >&2
fi fi
# Live medium only: open the branded welcome/installation launcher once the # Open the live installer welcome on the live medium. On the installed system,
# session is up. The marker exists only on the live rootfs, so an installed # the same launcher name runs the one-time desktop welcome and checks the
# system never starts it. This never authorizes or starts disk changes. # per-user seen marker itself. The custom Mango session does not run XDG
# autostart entries, so it must launch the installed welcome here.
if [ -e /etc/phoebus/live ] && command -v phoebus-welcome >/dev/null 2>&1; then if [ -e /etc/phoebus/live ] && command -v phoebus-welcome >/dev/null 2>&1; then
start_helper phoebus-welcome start_helper phoebus-welcome
elif [ -x /usr/local/bin/phoebus-welcome ]; then
start_helper /usr/local/bin/phoebus-welcome
fi fi
# Run until the compositor exits; the EXIT trap stops the shell and helpers. # Run until the compositor exits; the EXIT trap stops the shell and helpers.
@ -1822,6 +1828,7 @@ pub const INSTALLED_WELCOME_QML: &str = r##"// Phoebus first-login welcome (inst
import QtQuick import QtQuick
import QtQuick.Controls import QtQuick.Controls
import QtQuick.Layouts import QtQuick.Layouts
import Quickshell
ApplicationWindow { ApplicationWindow {
id: root id: root
@ -1833,8 +1840,18 @@ ApplicationWindow {
height: 600 height: 600
color: "#14161c" color: "#14161c"
function markSeen() {
Quickshell.execDetached(["/usr/local/bin/phoebus-welcome", "--mark-seen"])
}
function openAssistant() {
markSeen()
Quickshell.execDetached(["/usr/local/bin/phoebus-assistant"])
root.close()
}
// Never modal: closing or leaving finishes nothing and blocks nothing. // Never modal: closing or leaving finishes nothing and blocks nothing.
onClosing: { welcomeBackend.markSeen(); } onClosing: markSeen()
Flickable { Flickable {
anchors.fill: parent anchors.fill: parent
@ -1872,38 +1889,96 @@ ApplicationWindow {
color: "#9aa0ab" color: "#9aa0ab"
} }
GroupBox { Rectangle {
title: "1. Review and selectively build applications from source"
Layout.fillWidth: true Layout.fillWidth: true
Label { implicitHeight: sourceContent.implicitHeight + 28
text: "Firefox, LibreOffice, Thunderbird, Calibre and GIMP can be rebuilt from their maintained sources. Shown first: exact packages, expected time, temporary disk, power/network needs, then an explicit approval. The working copy stays until the new build verifies." color: "#20242c"
wrapMode: Text.WordWrap radius: 10
Column {
id: sourceContent
x: 14
y: 14
width: parent.width - 28
spacing: 10
Text {
width: parent.width width: parent.width
text: "1. Review and selectively build applications from source"
font.bold: true
color: "#f5b942"
}
Text {
width: parent.width
text: "Firefox, LibreOffice, Thunderbird, Calibre and GIMP can be rebuilt from maintained sources. Review the exact packages, expected time, temporary disk and power needs before approving a build."
wrapMode: Text.WordWrap
color: "#d7dae0" color: "#d7dae0"
} }
RowLayout { Button {
Button { id: srcButton; text: "Review source builds"; onClicked: welcomeBackend.openSourceBuilds(); KeyNavigation.tab: kernelButton } id: srcButton
text: "Open assistant to review source builds"
onClicked: root.openAssistant()
KeyNavigation.tab: kernelButton
} }
} }
GroupBox { }
title: "2. Build a kernel tuned for this machine" Rectangle {
Layout.fillWidth: true Layout.fillWidth: true
Label { implicitHeight: kernelContent.implicitHeight + 28
text: "Starts from the proven distribution configuration with only supported tuning. A separate boot entry is created and test-booted first; the generic kernel stays installed as the known-good fallback." color: "#20242c"
wrapMode: Text.WordWrap radius: 10
Column {
id: kernelContent
x: 14
y: 14
width: parent.width - 28
spacing: 10
Text {
width: parent.width width: parent.width
text: "2. Build a kernel tuned for this machine"
font.bold: true
color: "#f5b942"
}
Text {
width: parent.width
text: "A tuned kernel starts from the proven distribution configuration. The generic kernel remains installed as the known-good fallback."
wrapMode: Text.WordWrap
color: "#d7dae0" color: "#d7dae0"
} }
RowLayout { Button {
Button { id: kernelButton; text: "Review tuned kernel"; onClicked: welcomeBackend.openTunedKernel(); KeyNavigation.tab: keepButton } id: kernelButton
text: "Open assistant to review tuned kernel"
onClicked: root.openAssistant()
KeyNavigation.tab: keepButton
} }
} }
GroupBox { }
title: "3. Keep the fast defaults and finish" Rectangle {
Layout.fillWidth: true Layout.fillWidth: true
RowLayout { implicitHeight: finishContent.implicitHeight + 28
Button { id: keepButton; text: "Keep working system and finish (default)"; highlighted: true; onClicked: { welcomeBackend.markSeen(); root.close(); } KeyNavigation.tab: srcButton } color: "#20242c"
Button { text: "Close"; onClicked: { welcomeBackend.markSeen(); root.close(); } } radius: 10
Column {
id: finishContent
x: 14
y: 14
width: parent.width - 28
spacing: 10
Text {
width: parent.width
text: "3. Keep the fast defaults and finish"
font.bold: true
color: "#f5b942"
}
Row {
spacing: 8
Button {
id: keepButton
text: "Keep working system and finish (default)"
highlighted: true
onClicked: root.close()
KeyNavigation.tab: srcButton
}
Button { text: "Close"; onClicked: root.close() }
}
} }
} }
Label { Label {
@ -1914,24 +1989,34 @@ ApplicationWindow {
} }
} }
} }
Shortcut { sequence: "Escape"; onActivated: { welcomeBackend.markSeen(); root.close(); } } Shortcut { sequence: "Escape"; onActivated: root.close() }
} }
"##; "##;
/// Launcher script for the installed welcome. Reopenable; records nothing /// Launcher script for the installed welcome. Reopenable; records nothing
/// privileged. The QML talks to `sys --assistant-bridge` for the opt-in /// privileged. The QML opens the assistant for opt-in actions; its
/// actions, so approval and privilege stay in the deterministic broker. /// `sys --assistant-bridge` path keeps approval in the deterministic broker.
pub const INSTALLED_WELCOME_SCRIPT: &str = r#"#!/bin/bash pub const INSTALLED_WELCOME_SCRIPT: &str = r#"#!/bin/bash
# Phoebus first-login welcome (installed system only). Never blocks login: # Phoebus first-login welcome (installed system only). Never blocks login:
# it runs in the background and exiting changes nothing. # it runs in the background and exiting changes nothing.
set -u set -u
SEEN="${XDG_CONFIG_HOME:-$HOME/.config}/phoebus/welcome-seen" SEEN="${XDG_CONFIG_HOME:-$HOME/.config}/phoebus/welcome-seen"
if [ "${1:-}" = "--mark-seen" ]; then
umask 077
mkdir -p -- "$(dirname -- "$SEEN")" || exit 1
: > "$SEEN" || exit 1
exit 0
fi
if [ "${1:-}" != "--reopen" ] && [ -f "$SEEN" ]; then if [ "${1:-}" != "--reopen" ] && [ -f "$SEEN" ]; then
exit 0 exit 0
fi fi
if command -v quickshell >/dev/null 2>&1 \ if [ -f /etc/xdg/quickshell/phoebus-welcome-installed/shell.qml ]; then
&& [ -f /etc/xdg/quickshell/phoebus-welcome-installed/shell.qml ]; then if command -v quickshell >/dev/null 2>&1; then
exec quickshell --no-duplicate -c phoebus-welcome-installed "$@" exec quickshell --no-duplicate -c phoebus-welcome-installed
fi
if command -v qs >/dev/null 2>&1; then
exec qs --no-duplicate -c phoebus-welcome-installed
fi
fi fi
echo "phoebus-welcome: quickshell is unavailable; reopen from the launcher later" >&2 echo "phoebus-welcome: quickshell is unavailable; reopen from the launcher later" >&2
exit 1 exit 1
@ -1965,11 +2050,17 @@ NoDisplay=true
/// Seed content suppressing the upstream DMS first-run dialogs on the /// Seed content suppressing the upstream DMS first-run dialogs on the
/// installed target, so the user sees exactly one welcome experience (ours). /// installed target, so the user sees exactly one welcome experience (ours).
/// Mirrors the live-medium seeding in `installer/live/build.sh`. /// Mirrors the live-medium seeding in `installer/live/build.sh`.
pub fn dms_firstlaunch_seed(version: &str) -> Vec<(&'static str, String)> { pub fn dms_firstlaunch_seed(version: &str) -> Vec<(String, String)> {
let major_minor = version.split('.').take(2).collect::<Vec<_>>().join("."); let major_minor = version.split('.').take(2).collect::<Vec<_>>().join(".");
vec![ vec![
(".config/DankMaterialShell/.firstlaunch", String::new()), (
(".config/DankMaterialShell/.changelog-seen", major_minor), ".config/DankMaterialShell/.firstlaunch".into(),
String::new(),
),
(
format!(".config/DankMaterialShell/.changelog-{major_minor}"),
String::new(),
),
] ]
} }
@ -3031,20 +3122,19 @@ mod tests {
#[test] #[test]
fn shell_cursor_printing_ssh_power_lanes_are_present() { fn shell_cursor_printing_ssh_power_lanes_are_present() {
// The shell lane ships in base (it must exist before // The login shell ships in base before `users_configure`; GURU-only
// `users_configure` validates the login shell); the remaining lanes // shell plugins and the remaining lanes stay in the desktop set.
// stay in the desktop set.
let base = base_packages(); let base = base_packages();
for atom in [ for atom in ["app-shells/zsh", "app-shells/zsh-completions"] {
"app-shells/zsh",
"app-shells/zsh-completions",
"app-shells/zsh-autosuggestions",
"app-shells/zsh-syntax-highlighting",
] {
assert!(base.contains(&atom), "missing base lane atom {atom}"); assert!(base.contains(&atom), "missing base lane atom {atom}");
} }
for atom in shell_plugin_packages() {
assert!(!base.contains(&atom), "GURU atom {atom} reached base");
}
let pkgs = desktop_packages(DesktopProfile::Mango); let pkgs = desktop_packages(DesktopProfile::Mango);
for atom in [ for atom in [
"app-shells/zsh-autosuggestions",
"app-shells/zsh-syntax-highlighting",
"x11-themes/vanilla-dmz-xcursors", "x11-themes/vanilla-dmz-xcursors",
"net-print/cups", "net-print/cups",
"net-misc/openssh", "net-misc/openssh",
@ -3163,16 +3253,22 @@ mod tests {
// Installed welcome: once per user, reopenable, never blocking. // Installed welcome: once per user, reopenable, never blocking.
assert!(INSTALLED_WELCOME_SCRIPT.contains("--reopen")); assert!(INSTALLED_WELCOME_SCRIPT.contains("--reopen"));
assert!(INSTALLED_WELCOME_SCRIPT.contains("welcome-seen")); assert!(INSTALLED_WELCOME_SCRIPT.contains("welcome-seen"));
assert!(INSTALLED_WELCOME_SCRIPT.contains("--mark-seen"));
assert!(INSTALLED_WELCOME_AUTOSTART.contains("X-GNOME-Autostart-enabled=true")); assert!(INSTALLED_WELCOME_AUTOSTART.contains("X-GNOME-Autostart-enabled=true"));
assert!(INSTALLED_WELCOME_DESKTOP_ENTRY.contains("--reopen")); assert!(INSTALLED_WELCOME_DESKTOP_ENTRY.contains("--reopen"));
assert!(INSTALLED_WELCOME_QML.contains("Keep working system and finish")); assert!(INSTALLED_WELCOME_QML.contains("Keep working system and finish"));
assert!(INSTALLED_WELCOME_QML.contains("KeyNavigation.tab")); assert!(INSTALLED_WELCOME_QML.contains("KeyNavigation.tab"));
assert!(INSTALLED_WELCOME_QML.contains("Thunderbird")); assert!(INSTALLED_WELCOME_QML.contains("Thunderbird"));
assert!(INSTALLED_WELCOME_QML.contains("Quickshell.execDetached"));
assert!(!INSTALLED_WELCOME_QML.contains("welcomeBackend"));
let assets = installed_welcome_assets(); let assets = installed_welcome_assets();
assert!(assets.iter().any(|(p, _)| p.contains("shell.qml"))); assert!(assets.iter().any(|(p, _)| p.contains("shell.qml")));
// DMS first-run suppression seeds the skeleton only. // Match the versioned marker used by the verified live session.
let seed = dms_firstlaunch_seed("1.6.2"); let seed = dms_firstlaunch_seed("1.6.2");
assert!(seed.iter().any(|(p, _)| p.ends_with(".firstlaunch"))); assert!(seed.iter().any(|(p, _)| p.ends_with(".firstlaunch")));
assert!(seed
.iter()
.any(|(p, value)| p.ends_with(".changelog-1.6") && value.is_empty()));
} }
#[test] #[test]

View file

@ -207,7 +207,27 @@ pub fn write_loader_conf(exec: &Exec, config: &InstallConfig) -> Result<()> {
// first entry by systemd-boot's ordering, and the recovery entry (written // first entry by systemd-boot's ordering, and the recovery entry (written
// later) can sort first, which would boot the installed system into rescue // later) can sort first, which would boot the installed system into rescue
// mode by default. // mode by default.
let default = default_entry_id(&dir.join("entries")).unwrap_or_else(|| "*".to_string()); let entries = dir.join("entries");
// A counted entry changes its file name on every attempted boot. Pinning
// its initial exact ID would leave the default pointing at a vanished
// entry. Normal entries receive an earlier sort-key than recovery when
// counting is armed, so `*` selects a healthy normal entry and can fall
// back to recovery after its attempts are exhausted.
let counted = std::fs::read_dir(&entries)
.ok()
.map(|iter| {
iter.flatten().any(|entry| {
let name = entry.file_name().to_string_lossy().to_string();
!name.contains("recovery")
&& phoebus_core::boot::parse_bls_filename(&name).1.is_some()
})
})
.unwrap_or(false);
let default = if counted {
"*".to_string()
} else {
default_entry_id(&entries).unwrap_or_else(|| "*".to_string())
};
let text = format!( let text = format!(
"# systemd-boot configuration\ndefault {default}\ntimeout 3\nconsole-mode keep\neditor no\n" "# systemd-boot configuration\ndefault {default}\ntimeout 3\nconsole-mode keep\neditor no\n"
); );
@ -587,4 +607,24 @@ mod tests {
.unwrap(); .unwrap();
assert_eq!(default_entry_id(dir.path()), None); assert_eq!(default_entry_id(dir.path()), None);
} }
#[test]
fn counted_loader_default_survives_bootloader_entry_rename() {
let exec = make_exec(RecordingRunner::new());
let entries = exec.root.join("efi/loader/entries");
std::fs::create_dir_all(&entries).unwrap();
std::fs::write(
entries.join("gentoo-6.19.2+2-1.conf"),
"title Gentoo\nlinux /gentoo/6.19.2/linux\nsort-key phoebus\n",
)
.unwrap();
std::fs::write(
entries.join("phoebus-recovery.conf"),
"title Phoebus Recovery\nlinux /gentoo/6.19.2/linux\nsort-key zzzz-phoebus-recovery\n",
)
.unwrap();
write_loader_conf(&exec, &InstallConfig::default()).unwrap();
let loader = std::fs::read_to_string(exec.root.join("efi/loader/loader.conf")).unwrap();
assert!(loader.contains("default *\n"));
}
} }

View file

@ -4,12 +4,11 @@
//! 1. When a new kernel or system update is installed, the primary BLS entry is //! 1. When a new kernel or system update is installed, the primary BLS entry is
//! provisioned with boot counting attempts: `<entry-id>+3.conf`. //! provisioned with boot counting attempts: `<entry-id>+3.conf`.
//! 2. systemd-boot decrements the counter on boot attempt (`+3` -> `+2` -> `+1` -> `+0`). //! 2. systemd-boot decrements the counter on boot attempt (`+3` -> `+2` -> `+1` -> `+0`).
//! 3. If a kernel panic, initramfs failure, or boot loop prevents reaching `multi-user.target`, //! 3. Failed attempts exhaust the counter and systemd-boot sorts the
//! tries reach 0 and systemd-boot automatically falls back to the unmetered recovery //! unmetered recovery entry ahead of the bad entry.
//! snapshot BLS entry (`phoebus-recovery.conf`). //! 4. The upstream `systemd-bless-boot` generator detects a counted entry and
//! 4. When the system boots successfully and reaches `multi-user.target` with zero failed units, //! marks it good after `boot-complete.target`. Phoebus requires the upstream
//! `phoebus-boot-confirm.service` invokes `bootctl mark-good`, removing the counter and //! failed-unit checker before that target can succeed.
//! cementing the entry as verified healthy.
use std::fs; use std::fs;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -21,24 +20,6 @@ use crate::exec::Exec;
pub const DEFAULT_BOOT_TRIES: u32 = 3; pub const DEFAULT_BOOT_TRIES: u32 = 3;
/// The systemd service unit definition that marks the boot good after reaching multi-user.target.
pub fn boot_confirm_unit() -> &'static str {
"[Unit]\n\
Description=Phoebus Boot Assessment Confirmation\n\
Documentation=man:bootctl(1)\n\
After=multi-user.target systemd-boot-check-no-failures.service\n\
WantedBy=multi-user.target\n\
ConditionPathExists=/run/systemd/boot-loader\n\
\n\
[Service]\n\
Type=oneshot\n\
RemainAfterExit=yes\n\
ExecStart=/usr/bin/bootctl mark-good\n\
\n\
[Install]\n\
WantedBy=multi-user.target\n"
}
/// Applies boot counting (`+<tries>.conf`) to all non-recovery entries in `entries_dir` /// Applies boot counting (`+<tries>.conf`) to all non-recovery entries in `entries_dir`
/// that do not currently have a boot counter. /// that do not currently have a boot counter.
pub fn enable_boot_counting( pub fn enable_boot_counting(
@ -67,6 +48,21 @@ pub fn enable_boot_counting(
let (stem, existing_counter) = parse_bls_filename(&file_name); let (stem, existing_counter) = parse_bls_filename(&file_name);
if existing_counter.is_none() { if existing_counter.is_none() {
// A sort-key on recovery alone would place recovery *before* the
// normal entry according to the BLS ordering rules. Give normal
// entries an earlier key before using `default *` for boot-count
// fallback across entry renames.
let text = fs::read_to_string(&path).map_err(|e| ExecError::io(path.clone(), e))?;
let normal =
phoebus_core::boot::BlsEntry::parse(&file_name, &text).ok_or_else(|| {
ExecError::operation(
"boot_install",
"arm boot counting",
"normal BLS entry has no kernel",
)
})?;
fs::write(&path, normal.with_sort_key("phoebus").render())
.map_err(|e| ExecError::io(path.clone(), e))?;
let new_name = format_bls_filename(&stem, Some(default_tries)); let new_name = format_bls_filename(&stem, Some(default_tries));
let new_path = entries_dir.join(new_name); let new_path = entries_dir.join(new_name);
fs::rename(&path, &new_path).map_err(|e| ExecError::io(path.clone(), e))?; fs::rename(&path, &new_path).map_err(|e| ExecError::io(path.clone(), e))?;
@ -77,30 +73,25 @@ pub fn enable_boot_counting(
Ok(renamed) Ok(renamed)
} }
/// Installs and enables `phoebus-boot-confirm.service` in the target root. /// Require the upstream failed-unit checker before systemd blesses a counted
pub fn install_boot_assessment_service(exec: &Exec) -> Result<()> { /// boot. The upstream generator starts `systemd-bless-boot.service` only when
let service_path = "etc/systemd/system/phoebus-boot-confirm.service"; /// the current entry carries a counter; a separate Phoebus service is not
exec.target().write(service_path, boot_confirm_unit())?; /// needed and can race or fail after the entry has already been blessed.
exec.logger pub fn install_boot_health_check(exec: &Exec) -> Result<()> {
.info("wrote /etc/systemd/system/phoebus-boot-confirm.service"); let check_dir = exec
.target()
let wants_dir = "etc/systemd/system/multi-user.target.wants"; .ensure_dir("etc/systemd/system/boot-complete.target.requires")?;
let wants_link = format!("{wants_dir}/phoebus-boot-confirm.service"); let check_link = check_dir.join("systemd-boot-check-no-failures.service");
if !check_link.exists() {
// Create multi-user.target.wants symlink
let target_wants = exec.root.join(wants_dir);
fs::create_dir_all(&target_wants).map_err(|e| ExecError::io(target_wants.clone(), e))?;
let link_path = exec.root.join(wants_link);
if !link_path.exists() {
let rel_target = Path::new("../phoebus-boot-confirm.service");
#[cfg(unix)] #[cfg(unix)]
std::os::unix::fs::symlink(rel_target, &link_path) std::os::unix::fs::symlink(
.map_err(|e| ExecError::io(link_path, e))?; "/usr/lib/systemd/system/systemd-boot-check-no-failures.service",
&check_link,
)
.map_err(|e| ExecError::io(check_link, e))?;
} }
exec.logger exec.logger
.info("enabled phoebus-boot-confirm.service in multi-user.target.wants"); .info("enabled systemd boot failed-unit health check");
Ok(()) Ok(())
} }
@ -109,11 +100,32 @@ mod tests {
use super::*; use super::*;
#[test] #[test]
fn unit_definition_calls_bootctl_mark_good() { fn uses_upstream_boot_assessment_and_requires_the_health_check() {
let unit = boot_confirm_unit(); use crate::command::RecordingRunner;
assert!(unit.contains("ExecStart=/usr/bin/bootctl mark-good")); use crate::log::Logger;
assert!(unit.contains("After=multi-user.target")); use phoebus_core::Redactor;
assert!(unit.contains("ConditionPathExists=/run/systemd/boot-loader"));
let path = tempfile::tempdir().unwrap();
let root = path.path().join("root");
let logger = Logger::open(path.path().join("install.log"), Redactor::new(), false);
let exec = Exec::new(
Box::new(RecordingRunner::new()),
logger,
false,
root.clone(),
path.path().to_path_buf(),
);
install_boot_health_check(&exec).unwrap();
let link = root.join(
"etc/systemd/system/boot-complete.target.requires/systemd-boot-check-no-failures.service",
);
assert_eq!(
fs::read_link(link).unwrap(),
Path::new("/usr/lib/systemd/system/systemd-boot-check-no-failures.service")
);
assert!(!root
.join("etc/systemd/system/phoebus-boot-confirm.service")
.exists());
} }
#[test] #[test]
@ -142,5 +154,21 @@ mod tests {
assert!(!entries_dir.join("phoebus.conf").exists()); assert!(!entries_dir.join("phoebus.conf").exists());
assert!(entries_dir.join("phoebus-recovery.conf").exists()); assert!(entries_dir.join("phoebus-recovery.conf").exists());
assert!(entries_dir.join("phoebus-custom+2.conf").exists()); assert!(entries_dir.join("phoebus-custom+2.conf").exists());
let text = fs::read_to_string(entries_dir.join("phoebus+3.conf")).unwrap();
assert!(text.contains("sort-key phoebus"));
}
#[test]
fn counted_entry_is_not_rearmed_after_systemd_decrements_it() {
let temp = tempfile::tempdir().unwrap();
let entries_dir = temp.path().join("loader/entries");
fs::create_dir_all(&entries_dir).unwrap();
fs::write(
entries_dir.join("phoebus+2-1.conf"),
"title Phoebus\nlinux /linux\n",
)
.unwrap();
assert!(enable_boot_counting(&entries_dir, 3).unwrap().is_empty());
assert!(entries_dir.join("phoebus+2-1.conf").exists());
} }
} }

View file

@ -64,14 +64,15 @@ pub fn write_session_script(exec: &Exec, config: &InstallConfig) -> Result<()> {
"usr/local/bin/phoebus-assistant", "usr/local/bin/phoebus-assistant",
sysgen::PHOEBUS_ASSISTANT_SCRIPT, sysgen::PHOEBUS_ASSISTANT_SCRIPT,
)?; )?;
target.write( write_public(
&target,
"usr/share/applications/phoebus-assistant.desktop", "usr/share/applications/phoebus-assistant.desktop",
sysgen::PHOEBUS_ASSISTANT_DESKTOP_ENTRY, sysgen::PHOEBUS_ASSISTANT_DESKTOP_ENTRY,
)?; )?;
// Provision all assistant QML assets and Polkit policy into the target. // Provision all assistant QML assets and Polkit policy into the target.
for (rel_path, content) in sysgen::assistant_desktop_assets() { for (rel_path, content) in sysgen::assistant_desktop_assets() {
target.write(rel_path, content)?; write_public(&target, rel_path, content)?;
} }
// The "Install Phoebus OS" entry point and welcome launcher are live-medium // The "Install Phoebus OS" entry point and welcome launcher are live-medium
@ -99,8 +100,13 @@ fn write_mango_session(exec: &Exec, target: &phoebus_core::TargetRoot) -> Result
"usr/local/bin/phoebus-session", "usr/local/bin/phoebus-session",
"#!/bin/bash\nexec /usr/local/bin/phoebus-session-mango \"$@\"\n", "#!/bin/bash\nexec /usr/local/bin/phoebus-session-mango \"$@\"\n",
)?; )?;
target.write("etc/xdg/mango/config.conf", sysgen::MANGO_CONFIG_DEFAULT)?; write_public(
target.write( target,
"etc/xdg/mango/config.conf",
sysgen::MANGO_CONFIG_DEFAULT,
)?;
write_public(
target,
"usr/lib/systemd/user/mango-session.target", "usr/lib/systemd/user/mango-session.target",
sysgen::MANGO_SESSION_TARGET, sysgen::MANGO_SESSION_TARGET,
)?; )?;
@ -108,16 +114,18 @@ fn write_mango_session(exec: &Exec, target: &phoebus_core::TargetRoot) -> Result
// the session script falls back to `dms run` otherwise. // the session script falls back to `dms run` otherwise.
let dms_unit = target.resolve("usr/lib/systemd/user/dms.service")?; let dms_unit = target.resolve("usr/lib/systemd/user/dms.service")?;
if dms_unit.exists() { if dms_unit.exists() {
target.ensure_dir_mode("etc/systemd", 0o755)?;
target.ensure_dir_mode("etc/systemd/user", 0o755)?;
target.ensure_dir_mode("etc/systemd/user/mango-session.target.wants", 0o755)?;
let wants = target.resolve("etc/systemd/user/mango-session.target.wants/dms.service")?; let wants = target.resolve("etc/systemd/user/mango-session.target.wants/dms.service")?;
if let Some(parent) = wants.parent() {
std::fs::create_dir_all(parent).map_err(|e| ExecError::io(parent.to_path_buf(), e))?;
}
let _ = std::fs::remove_file(&wants); let _ = std::fs::remove_file(&wants);
std::os::unix::fs::symlink(&dms_unit, &wants) // The link is interpreted inside the installed system. A host path
// into the staging root works during installation but breaks on boot.
std::os::unix::fs::symlink("/usr/lib/systemd/user/dms.service", &wants)
.map_err(|e| ExecError::io(wants.clone(), e))?; .map_err(|e| ExecError::io(wants.clone(), e))?;
} }
if let Some((name, entry)) = sysgen::wayland_session_entry(DesktopProfile::Mango) { if let Some((name, entry)) = sysgen::wayland_session_entry(DesktopProfile::Mango) {
target.write(&format!("usr/share/wayland-sessions/{name}"), entry)?; write_public(target, &format!("usr/share/wayland-sessions/{name}"), entry)?;
} }
configure_cursor_theme(target)?; configure_cursor_theme(target)?;
configure_nemo_default(target)?; configure_nemo_default(target)?;
@ -136,15 +144,16 @@ fn configure_cursor_theme(target: &phoebus_core::TargetRoot) -> Result<()> {
for (k, v) in sysgen::cursor_env_lines() { for (k, v) in sysgen::cursor_env_lines() {
env.push_str(&format!("export {k}={v}\n")); env.push_str(&format!("export {k}={v}\n"));
} }
target.write("etc/xdg/mango/cursor-env.sh", env)?; write_public(target, "etc/xdg/mango/cursor-env.sh", env)?;
// GTK 3/4. // GTK 3/4.
target.write( write_public(
target,
"etc/xdg/gtk-3.0/settings.ini", "etc/xdg/gtk-3.0/settings.ini",
sysgen::gtk_cursor_settings(), sysgen::gtk_cursor_settings(),
)?; )?;
// Qt/Quickshell + DMS read XCURSOR_* from the session environment; // Qt/Quickshell + DMS read XCURSOR_* from the session environment;
// the greeter sources the same fragment via its shell profile. // the greeter sources the same fragment via its shell profile.
target.write( write_public(target,
"etc/profile.d/phoebus-cursor.sh", "etc/profile.d/phoebus-cursor.sh",
format!( format!(
"# Phoebus cursor defaults (generated).\nexport XCURSOR_THEME={}\nexport XCURSOR_SIZE={}\n", "# Phoebus cursor defaults (generated).\nexport XCURSOR_THEME={}\nexport XCURSOR_SIZE={}\n",
@ -157,15 +166,20 @@ fn configure_cursor_theme(target: &phoebus_core::TargetRoot) -> Result<()> {
/// Nemo is the default graphical file manager. /// Nemo is the default graphical file manager.
fn configure_nemo_default(target: &phoebus_core::TargetRoot) -> Result<()> { fn configure_nemo_default(target: &phoebus_core::TargetRoot) -> Result<()> {
target.write("etc/xdg/mimeapps.list", sysgen::nemo_mimeapps())?; write_public(target, "etc/xdg/mimeapps.list", sysgen::nemo_mimeapps())?;
target.write("etc/skel/.config/mimeapps.list", sysgen::nemo_mimeapps())?; write_public(
target,
"etc/skel/.config/mimeapps.list",
sysgen::nemo_mimeapps(),
)?;
Ok(()) Ok(())
} }
/// CUPS with local printing enabled; remote sharing/administration disabled. /// CUPS with local printing enabled; remote sharing/administration disabled.
fn configure_cups_local(target: &phoebus_core::TargetRoot) -> Result<()> { fn configure_cups_local(target: &phoebus_core::TargetRoot) -> Result<()> {
target.write("etc/cups/cupsd.conf", sysgen::cupsd_local_conf())?; write_public(target, "etc/cups/cupsd.conf", sysgen::cupsd_local_conf())?;
target.write( write_public(
target,
"etc/cups/cups-browsed.conf", "etc/cups/cups-browsed.conf",
"# Phoebus: no remote printer browsing.\nBrowseRemoteProtocols none\n", "# Phoebus: no remote printer browsing.\nBrowseRemoteProtocols none\n",
)?; )?;
@ -180,7 +194,11 @@ pub fn configure_login(exec: &Exec, config: &InstallConfig) -> Result<()> {
} }
let target = exec.target(); let target = exec.target();
let cmd = sysgen::default_session_command(config.desktop.profile); let cmd = sysgen::default_session_command(config.desktop.profile);
target.write("etc/greetd/config.toml", sysgen::greetd_config(cmd))?; write_public(
&target,
"etc/greetd/config.toml",
sysgen::greetd_config(cmd),
)?;
ensure_greeter_user(exec)?; ensure_greeter_user(exec)?;
let root = Path::new(&exec.root); let root = Path::new(&exec.root);
for service in sysgen::desktop_login_services() { for service in sysgen::desktop_login_services() {
@ -192,6 +210,21 @@ pub fn configure_login(exec: &Exec, config: &InstallConfig) -> Result<()> {
) )
})?; })?;
} }
// Gentoo ships these user units disabled. A graphical login must start
// PipeWire and WirePlumber without requiring a per-user manual setup.
for unit in [
"pipewire.socket",
"pipewire-pulse.socket",
"wireplumber.service",
] {
portage::chroot(exec, root, "systemctl", &["--global", "enable", unit]).map_err(|e| {
ExecError::operation(
"desktop",
&format!("enable user audio unit {unit}"),
e.to_string(),
)
})?;
}
exec.logger exec.logger
.info(format!("configured greetd login (default session {cmd})")); .info(format!("configured greetd login (default session {cmd})"));
Ok(()) Ok(())
@ -252,6 +285,30 @@ fn write_script(target: &phoebus_core::TargetRoot, rel: &str, contents: &str) ->
Ok(()) Ok(())
} }
/// Files consumed by the greeter or an unprivileged desktop session must be
/// readable regardless of the installer's restrictive umask. Only call this
/// for public, generated configuration; credentials use `TargetRoot::write`.
fn write_public(
target: &phoebus_core::TargetRoot,
rel: &str,
contents: impl AsRef<[u8]>,
) -> Result<()> {
use std::os::unix::fs::PermissionsExt;
let path = target.write(rel, contents)?;
let mut parent = path.parent();
while let Some(dir) = parent {
if dir == target.path() {
break;
}
std::fs::set_permissions(dir, std::fs::Permissions::from_mode(0o755))
.map_err(|e| ExecError::io(dir.to_path_buf(), e))?;
parent = dir.parent();
}
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o644))
.map_err(|e| ExecError::io(path, e))?;
Ok(())
}
pub fn configure_flatpak(exec: &Exec, config: &InstallConfig) -> Result<()> { pub fn configure_flatpak(exec: &Exec, config: &InstallConfig) -> Result<()> {
if !config.desktop.flatpak { if !config.desktop.flatpak {
return Ok(()); return Ok(());
@ -388,13 +445,29 @@ pub fn provision_installed_welcome(exec: &Exec, config: &InstallConfig) -> Resul
sysgen::INSTALLED_WELCOME_SCRIPT, sysgen::INSTALLED_WELCOME_SCRIPT,
)?; )?;
for (rel_path, content) in sysgen::installed_welcome_assets() { for (rel_path, content) in sysgen::installed_welcome_assets() {
target.write(rel_path, content)?; write_public(&target, rel_path, content)?;
} }
// Seed the upstream DMS first-run suppression into the skeleton so every // Keep the skeleton for future accounts. The installation user already
// new user sees exactly one welcome experience (ours), without // exists (UsersConfigure runs before DesktopInstall), so seed that home
// overlapping DMS dialogs. Existing homes are never touched. // as well; otherwise DMS opens its own onboarding over Phoebus welcome.
for (rel, content) in sysgen::dms_firstlaunch_seed("1.6.2") { for (rel, content) in sysgen::dms_firstlaunch_seed("1.6.2") {
target.write(&format!("etc/skel/{rel}"), content)?; write_public(&target, &format!("etc/skel/{rel}"), &content)?;
let username = &config.user.username;
if !username.is_empty() && target.resolve(&format!("home/{username}"))?.is_dir() {
let user_rel = format!("home/{username}/{rel}");
if !target.resolve(&user_rel)?.exists() {
let config_rel = format!("home/{username}/.config");
let config_existed = target.resolve(&config_rel)?.exists();
target.write(&user_rel, &content)?;
let owner = format!("{username}:{username}");
let user_dir = format!("/home/{username}/.config/DankMaterialShell");
portage::chroot(exec, target.path(), "chown", &["-R", &owner, &user_dir])?;
if !config_existed {
let config_dir = format!("/home/{username}/.config");
portage::chroot(exec, target.path(), "chown", &[&owner, &config_dir])?;
}
}
}
} }
exec.logger exec.logger
.info("provisioned the installed first-login welcome (once per user, reopenable)"); .info("provisioned the installed first-login welcome (once per user, reopenable)");
@ -432,11 +505,26 @@ mod tests {
#[test] #[test]
fn mango_profile_installs_canonical_session_and_no_dwl_artifacts() { fn mango_profile_installs_canonical_session_and_no_dwl_artifacts() {
use std::os::unix::fs::PermissionsExt;
let runner = RecordingRunner::new(); let runner = RecordingRunner::new();
let exec = make_exec(runner); let exec = make_exec(runner);
let mut cfg = InstallConfig::default(); let mut cfg = InstallConfig::default();
cfg.desktop.profile = DesktopProfile::Mango; cfg.desktop.profile = DesktopProfile::Mango;
let xdg = exec.target().ensure_dir("etc/xdg").unwrap();
std::fs::set_permissions(&xdg, std::fs::Permissions::from_mode(0o700)).unwrap();
write_session_script(&exec, &cfg).unwrap(); write_session_script(&exec, &cfg).unwrap();
for rel in ["etc/xdg", "etc/xdg/mango"] {
let mode = std::fs::metadata(exec.root.join(rel))
.unwrap()
.permissions()
.mode();
assert_eq!(mode & 0o777, 0o755, "{rel} must be traversable");
}
let mode = std::fs::metadata(exec.root.join("etc/xdg/mango/config.conf"))
.unwrap()
.permissions()
.mode();
assert_eq!(mode & 0o777, 0o644, "Mango config must be readable");
for rel in [ for rel in [
"usr/local/bin/phoebus-session-mango", "usr/local/bin/phoebus-session-mango",
"usr/local/bin/phoebus-session", "usr/local/bin/phoebus-session",
@ -479,6 +567,33 @@ mod tests {
); );
} }
#[test]
fn mango_dms_user_unit_link_points_into_installed_system() {
use std::os::unix::fs::PermissionsExt;
let exec = make_exec(RecordingRunner::new());
let mut cfg = InstallConfig::default();
cfg.desktop.profile = DesktopProfile::Mango;
exec.target()
.write(
"usr/lib/systemd/user/dms.service",
"[Service]\nExecStart=/usr/bin/dms run\n",
)
.unwrap();
write_session_script(&exec, &cfg).unwrap();
let wants = exec
.root
.join("etc/systemd/user/mango-session.target.wants");
let link = wants.join("dms.service");
assert_eq!(
std::fs::read_link(link).unwrap(),
std::path::PathBuf::from("/usr/lib/systemd/user/dms.service")
);
assert_eq!(
std::fs::metadata(wants).unwrap().permissions().mode() & 0o777,
0o755
);
}
#[test] #[test]
fn mango_profile_configures_greetd_login_and_no_install_shortcut() { fn mango_profile_configures_greetd_login_and_no_install_shortcut() {
let runner = RecordingRunner::new(); let runner = RecordingRunner::new();
@ -507,6 +622,18 @@ mod tests {
let commands: Vec<String> = runner.recorded().iter().map(|s| s.args.join(" ")).collect(); let commands: Vec<String> = runner.recorded().iter().map(|s| s.args.join(" ")).collect();
assert!(commands.iter().any(|a| a.contains("enable greetd"))); assert!(commands.iter().any(|a| a.contains("enable greetd")));
assert!(commands.iter().any(|a| a.contains("useradd"))); assert!(commands.iter().any(|a| a.contains("useradd")));
for unit in [
"pipewire.socket",
"pipewire-pulse.socket",
"wireplumber.service",
] {
assert!(
commands
.iter()
.any(|a| a.contains(&format!("--global enable {unit}"))),
"user audio unit {unit} must be enabled"
);
}
// Seat management: seatd is enabled before the greeter, and the // Seat management: seatd is enabled before the greeter, and the
// greeter joins the seat group (plus video/input/render). // greeter joins the seat group (plus video/input/render).
let seat_pos = commands.iter().position(|a| a.contains("enable seatd")); let seat_pos = commands.iter().position(|a| a.contains("enable seatd"));
@ -524,7 +651,7 @@ mod tests {
} }
#[test] #[test]
fn live_autostart_is_gated_on_the_live_marker() { fn live_and_installed_welcomes_are_launched_by_the_mango_session() {
let runner = RecordingRunner::new(); let runner = RecordingRunner::new();
let exec = make_exec(runner); let exec = make_exec(runner);
let mut cfg = InstallConfig::default(); let mut cfg = InstallConfig::default();
@ -537,6 +664,7 @@ mod tests {
"the welcome autostart must be gated on the live marker" "the welcome autostart must be gated on the live marker"
); );
assert!(mango.contains("phoebus-welcome")); assert!(mango.contains("phoebus-welcome"));
assert!(mango.contains("elif [ -x /usr/local/bin/phoebus-welcome ]"));
} }
#[test] #[test]
@ -677,8 +805,7 @@ mod tests {
assert!(qml.contains("KeyNavigation.tab")); assert!(qml.contains("KeyNavigation.tab"));
assert!(qml.contains("Escape")); assert!(qml.contains("Escape"));
assert!(qml.contains("Flickable")); assert!(qml.contains("Flickable"));
// DMS first-run dialogs are suppressed via the skeleton so users see // Future users receive the same seed through the skeleton.
// one welcome experience; existing homes are never touched here.
assert!(exec assert!(exec
.root .root
.join("etc/skel/.config/DankMaterialShell/.firstlaunch") .join("etc/skel/.config/DankMaterialShell/.firstlaunch")
@ -690,6 +817,28 @@ mod tests {
.exists()); .exists());
} }
#[test]
fn installed_welcome_seeds_the_already_created_install_user() {
let runner = RecordingRunner::new();
let exec = make_exec(runner.clone());
let mut cfg = InstallConfig::default();
cfg.desktop.profile = DesktopProfile::Mango;
cfg.user.username = "phoebus".into();
exec.target().ensure_dir("home/phoebus").unwrap();
provision_installed_welcome(&exec, &cfg).unwrap();
assert!(exec
.root
.join("home/phoebus/.config/DankMaterialShell/.firstlaunch")
.is_file());
assert!(runner.recorded().iter().any(|spec| {
spec.program == "chroot"
&& spec
.args
.iter()
.any(|arg| arg == "/home/phoebus/.config/DankMaterialShell")
}));
}
#[test] #[test]
fn no_welcome_or_flatpaks_for_headless_profile() { fn no_welcome_or_flatpaks_for_headless_profile() {
let runner = RecordingRunner::new(); let runner = RecordingRunner::new();

View file

@ -41,9 +41,8 @@ pub fn write_config(exec: &Exec, config: &InstallConfig, hardware: &HardwareRepo
)?; )?;
keywords.push('\n'); keywords.push('\n');
keywords.push_str(&sysgen::accept_keywords_mango()); keywords.push_str(&sysgen::accept_keywords_mango());
// The login shell is a base package (validated by `users_configure` // The login shell is a base package; Mango's GURU plugins are
// before the desktop stage); its GURU plugins need the same scoped // installed later with the same scoped keyword policy.
// keywords in the same condition.
keywords.push('\n'); keywords.push('\n');
keywords.push_str(&sysgen::accept_keywords_shell()); keywords.push_str(&sysgen::accept_keywords_shell());
} }

View file

@ -371,12 +371,6 @@ pub fn create_swapfile(
_root_source: &str, _root_source: &str,
) -> Result<()> { ) -> Result<()> {
let swapdir = root.ensure_dir("swap")?; let swapdir = root.ensure_dir("swap")?;
// Ensure the swap directory itself has +C (NOCOW) so created files inherit it.
let _ = exec.run(
CommandSpec::new("storage_prepare", "disable CoW on swap directory", "chattr")
.arg("+C")
.arg(swapdir.to_string_lossy().to_string()),
);
let swapfile = swapdir.join("swapfile"); let swapfile = swapdir.join("swapfile");
let size_mib = swap_size_mib(exec); let size_mib = swap_size_mib(exec);
let spec = CommandSpec::new("storage_prepare", "create Btrfs swapfile", "btrfs") let spec = CommandSpec::new("storage_prepare", "create Btrfs swapfile", "btrfs")
@ -388,24 +382,24 @@ pub fn create_swapfile(
]) ])
.arg(swapfile.to_string_lossy().to_string()); .arg(swapfile.to_string_lossy().to_string());
if exec.run(spec).is_ok() { if exec.run(spec).is_ok() {
let _ = exec.run( exec.run(
CommandSpec::new("storage_prepare", "secure swapfile permissions", "chmod") CommandSpec::new("storage_prepare", "secure swapfile permissions", "chmod")
.arg("0600") .arg("0600")
.arg(swapfile.to_string_lossy().to_string()), .arg(swapfile.to_string_lossy().to_string()),
); )?;
return Ok(()); return Ok(());
} }
// Fallback for older btrfs-progs: // Older btrfs-progs: set NOCOW on an empty file, then allocate real
// Create empty 0-byte file first, set +C (NOCOW), then truncate, chmod 0600, and mkswap. // extents. truncate would create holes and swapon would reject the file.
let _ = std::fs::File::create(&swapfile); root.write("swap/swapfile", [])?;
let _ = exec.run( exec.run(
CommandSpec::new("storage_prepare", "disable CoW on swapfile", "chattr") CommandSpec::new("storage_prepare", "disable CoW on swapfile", "chattr")
.arg("+C") .arg("+C")
.arg(swapfile.to_string_lossy().to_string()), .arg(swapfile.to_string_lossy().to_string()),
); )?;
exec.run( exec.run(
CommandSpec::new("storage_prepare", "create swapfile container", "truncate") CommandSpec::new("storage_prepare", "preallocate swapfile", "fallocate")
.args(["-s", &format!("{size_mib}M")]) .args(["-l", &format!("{size_mib}M")])
.arg(swapfile.to_string_lossy().to_string()), .arg(swapfile.to_string_lossy().to_string()),
)?; )?;
exec.run( exec.run(
@ -589,6 +583,7 @@ mod tests {
#[test] #[test]
fn swapfile_creation_secures_permissions_and_nocow() { fn swapfile_creation_secures_permissions_and_nocow() {
let runner = RecordingRunner::new(); let runner = RecordingRunner::new();
runner.fail("btrfs", "mkswapfile unavailable");
let exec = make_exec(runner.clone()); let exec = make_exec(runner.clone());
let cfg = InstallConfig::default(); let cfg = InstallConfig::default();
let root = exec.target(); let root = exec.target();
@ -596,14 +591,37 @@ mod tests {
create_swapfile(&exec, &cfg, &root, "/dev/mapper/cryptroot").unwrap(); create_swapfile(&exec, &cfg, &root, "/dev/mapper/cryptroot").unwrap();
let recorded = runner.recorded(); let recorded = runner.recorded();
// Verify chattr +C was run on the swap directory // The fallback must set NOCOW before allocating real extents.
assert!(recorded.iter().any(|s| s.program == "chattr" assert!(recorded.iter().any(|s| s.program == "chattr"
&& s.args.contains(&"+C".to_string()) && s.args.contains(&"+C".to_string())
&& s.args.iter().any(|a| a.contains("swap")))); && s.args.iter().any(|a| a.ends_with("swapfile"))));
let programs: Vec<&str> = recorded.iter().map(|s| s.program.as_str()).collect();
assert!(programs
.windows(2)
.any(|pair| pair == ["chattr", "fallocate"]));
assert!(!programs.contains(&"truncate"));
// Verify chmod 0600 was run on the swapfile // Verify chmod 0600 was run on the swapfile
assert!(recorded.iter().any(|s| s.program == "chmod" assert!(recorded.iter().any(|s| s.program == "chmod"
&& s.args.contains(&"0600".to_string()) && s.args.contains(&"0600".to_string())
&& s.args.iter().any(|a| a.contains("swapfile")))); && s.args.iter().any(|a| a.contains("swapfile"))));
} }
#[test]
fn swapfile_creation_fails_if_nocow_or_permissions_fail() {
for failing_program in ["chattr", "fallocate", "chmod", "mkswap"] {
let runner = RecordingRunner::new();
runner.fail("btrfs", "mkswapfile unavailable");
runner.fail(failing_program, "swapfile setup failed");
let exec = make_exec(runner);
let error = create_swapfile(
&exec,
&InstallConfig::default(),
&exec.target(),
"/dev/mapper/cryptroot",
)
.unwrap_err();
assert!(error.to_string().contains(failing_program));
}
}
} }

View file

@ -9,8 +9,8 @@ use std::process::ExitCode;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use phoebus_core::VERSION; use phoebus_core::VERSION;
use phoebus_installer::release::{ use phoebus_installer::release::{
artifact_for, atomic_publish, default_manifest_path, run_gates, sha256_file, sign_command, artifact_for, atomic_publish, default_manifest_path, git_source_revision, run_gates,
verify_signature_command, GateReport, ReleaseManifest, sha256_file, sign_command, verify_signature_command, GateReport, ReleaseManifest,
}; };
#[derive(Parser)] #[derive(Parser)]
@ -191,10 +191,11 @@ fn run() -> std::result::Result<(), Box<dyn std::error::Error>> {
gate_report, gate_report,
} => { } => {
let report = GateReport::load(&gate_report)?; let report = GateReport::load(&gate_report)?;
if !report.all_passed() { if !report.ready_to_publish(&candidate)
|| !report.matches_source_revision(git_source_revision().as_deref())
{
return Err(format!( return Err(format!(
"refusing to publish: {} gate(s) passed, {} not run \ "refusing to publish: gate report must have every passing gate for this exact ISO and the current clean source revision ({} passed, {} not run)",
(run the gates on a configured runner and supply a passing report)",
report report
.results .results
.iter() .iter()

View file

@ -13,8 +13,8 @@ use phoebus_core::{
}; };
use phoebus_executor::storage::StorageState; use phoebus_executor::storage::StorageState;
use phoebus_executor::{ use phoebus_executor::{
boot, desktop, encryption, kernel, nix, portage, probe, services, snapshot, stage3, storage, boot, boot_assessment, desktop, encryption, kernel, nix, portage, probe, services, snapshot,
users, Exec, Result, stage3, storage, users, Exec, Result,
}; };
pub struct Installer { pub struct Installer {
@ -783,6 +783,7 @@ impl Installer {
.logger .logger
.warn(format!("EFI fallback not installed: {e}")); .warn(format!("EFI fallback not installed: {e}"));
} }
boot_assessment::install_boot_health_check(&self.exec)?;
let _ = boot::random_seed(&self.exec, &self.config); let _ = boot::random_seed(&self.exec, &self.config);
boot::verify(&self.exec, &self.config) boot::verify(&self.exec, &self.config)
} }
@ -920,7 +921,24 @@ impl Installer {
self.write_install_metrics(); self.write_install_metrics();
// 5. Initial known-good recovery point snapshot and boot entry. // 5. Initial known-good recovery point snapshot and boot entry.
self.create_initial_recovery_point(auth); self.create_initial_recovery_point(auth)?;
// Only arm the changing BLS filename once the snapshot-based recovery
// entry exists. Rewrite loader.conf with a stable wildcard default.
let entries = boot::esp_path(&self.exec, &self.config).join("loader/entries");
if self.config.storage.filesystem == Filesystem::Btrfs {
let recovery = entries.join("phoebus-recovery.conf");
let recovery_text = std::fs::read_to_string(&recovery)
.map_err(|e| phoebus_executor::ExecError::io(recovery.clone(), e))?;
if !recovery_text.contains("@snapshots/") {
return Err(phoebus_executor::ExecError::operation(
"finalize",
"arm boot assessment",
"snapshot-based recovery entry is missing",
));
}
boot_assessment::enable_boot_counting(&entries, boot_assessment::DEFAULT_BOOT_TRIES)?;
boot::write_loader_conf(&self.exec, &self.config)?;
}
// 6. Durability flush before unmounting. // 6. Durability flush before unmounting.
self.exec.run(phoebus_executor::command::CommandSpec::new( self.exec.run(phoebus_executor::command::CommandSpec::new(
@ -1229,7 +1247,10 @@ impl Installer {
/// Capture an initial known-good snapshot and point a boot entry at it, so /// Capture an initial known-good snapshot and point a boot entry at it, so
/// recovery does not depend on the (possibly later broken) live root. /// recovery does not depend on the (possibly later broken) live root.
fn create_initial_recovery_point(&self, auth: &phoebus_executor::DestructiveAuthorization) { fn create_initial_recovery_point(
&self,
auth: &phoebus_executor::DestructiveAuthorization,
) -> Result<()> {
if self.config.storage.filesystem != Filesystem::Btrfs if self.config.storage.filesystem != Filesystem::Btrfs
|| !self || !self
.config .config
@ -1238,7 +1259,7 @@ impl Installer {
.iter() .iter()
.any(|s| s == "@snapshots") .any(|s| s == "@snapshots")
{ {
return; return Ok(());
} }
let root = std::path::PathBuf::from(&self.exec.root); let root = std::path::PathBuf::from(&self.exec.root);
let root_str = root.to_string_lossy().to_string(); let root_str = root.to_string_lossy().to_string();
@ -1247,30 +1268,15 @@ impl Installer {
} else { } else {
None None
}; };
match snapshot::create_set_and_record_at( let record = snapshot::create_set_and_record_at(
&self.exec, &self.exec,
auth, auth,
&root, &root,
&root_str, &root_str,
var_source.as_deref(), var_source.as_deref(),
"initial known-good", "initial known-good",
) { )?;
Ok(record) => { boot::write_snapshot_recovery_entry(&self.exec, &self.config, &record.snapshot_subvol)
if let Err(e) = boot::write_snapshot_recovery_entry(
&self.exec,
&self.config,
&record.snapshot_subvol,
) {
self.exec
.logger
.warn(format!("could not write snapshot recovery entry: {e}"));
}
}
Err(e) => self
.exec
.logger
.warn(format!("could not create initial recovery snapshot: {e}")),
}
} }
} }

View file

@ -106,7 +106,7 @@ impl ReleaseManifest {
"/phoebus".into(), "/phoebus".into(),
"-boot_image".into(), "-boot_image".into(),
"any".into(), "any".into(),
"keep".into(), "replay".into(),
] ]
} }
} }
@ -178,6 +178,10 @@ pub struct GateResult {
pub struct GateReport { pub struct GateReport {
pub version: String, pub version: String,
pub created_unix: u64, pub created_unix: u64,
/// Hash of the exact ISO passed to the VM harness via ISO.
pub candidate_iso_sha256: Option<String>,
pub source_revision: Option<String>,
pub disk_images: Vec<String>,
pub results: Vec<GateResult>, pub results: Vec<GateResult>,
} }
@ -187,6 +191,38 @@ impl GateReport {
!self.results.is_empty() && self.results.iter().all(|r| r.status == GateStatus::Passed) !self.results.is_empty() && self.results.iter().all(|r| r.status == GateStatus::Passed)
} }
pub fn matches_candidate(&self, candidate: &Path) -> bool {
self.candidate_iso_sha256
.as_deref()
.is_some_and(|expected| sha256_file(candidate).is_ok_and(|actual| actual == expected))
}
pub fn ready_to_publish(&self, candidate: &Path) -> bool {
if !self.all_passed()
|| !self.matches_candidate(candidate)
|| self.source_revision.as_deref().map_or(true, |rev| {
rev.len() != 40 || !rev.bytes().all(|byte| byte.is_ascii_hexdigit())
})
{
return false;
}
let expected: std::collections::BTreeSet<_> =
candidate_gates().into_iter().map(|g| g.name).collect();
let actual: std::collections::BTreeSet<_> =
self.results.iter().map(|r| r.name.clone()).collect();
actual == expected && self.results.len() == expected.len()
}
/// A report can only authorize publication from the same clean checkout
/// that ran its gates. Call this with the revision observed at publish time.
pub fn matches_source_revision(&self, current: Option<&str>) -> bool {
current.is_some_and(|revision| {
revision.len() == 40
&& revision.bytes().all(|byte| byte.is_ascii_hexdigit())
&& self.source_revision.as_deref() == Some(revision)
})
}
pub fn not_run(&self) -> usize { pub fn not_run(&self) -> usize {
self.results self.results
.iter() .iter()
@ -213,22 +249,41 @@ impl GateReport {
/// Modes the headless serial harness accepts (`serial-driver.py` `main`). /// Modes the headless serial harness accepts (`serial-driver.py` `main`).
/// A gate naming any other mode would fail at runtime; the /// A gate naming any other mode would fail at runtime; the
/// `gate_commands_are_real_harness_modes` test pins this list. /// `gate_commands_are_real_harness_modes` test pins this list.
pub const SERIAL_DRIVER_MODES: &[&str] = &["install", "boot", "rollback"]; pub const SERIAL_DRIVER_MODES: &[&str] = &[
"install",
"install-repeat",
"boot",
"boot-assessed",
"rollback",
"recovery",
"fallback",
"interrupted-update",
];
/// Modes the graphical harness accepts (`gui-driver.py` `run`). /// Modes the graphical harness accepts (`gui-driver.py` `run`).
pub const GUI_DRIVER_MODES: &[&str] = &["gui", "opencode", "gui-install", "install", "boot"]; pub const GUI_DRIVER_MODES: &[&str] = &[
"gui",
"opencode",
"gui-install",
"install",
"boot",
"desktop",
];
/// The candidate checks. Commands are the real harness invocations, not /// The candidate checks. Commands are the real harness invocations, not
/// placeholders, so a configured runner executes exactly what is documented. /// placeholders, so a configured runner executes exactly what is documented.
/// ///
/// - `no-model-recovery` reuses the real `boot` mode: the runner boots the /// - `no-model-recovery` actually selects and boots the recovery BLS entry.
/// installed disk detached with the model unavailable and `BOOT_CHECKS` /// - `desktop-session` drives the seat and tests the installed session.
/// exercising deterministic `sys --legacy` operation (see the VM record).
/// - `desktop-session` uses the real graphical harness (`gui-driver.py boot`)
/// on a seat-providing VM; there is no headless `desktop` mode.
pub fn candidate_gates() -> Vec<Gate> { pub fn candidate_gates() -> Vec<Gate> {
let driver = "installer/tests/vm/serial-driver.py"; let driver = "installer/tests/vm/serial-driver.py";
let gui_driver = "installer/tests/vm/gui-driver.py"; let gui_driver = "installer/tests/vm/gui-driver.py";
vec![ vec![
Gate {
name: "live-installer-ui".into(),
description: "firmware boot of the candidate ISO, welcome and installer wizard".into(),
requires: GateRequirement::GraphicalSeat,
command: vec!["python3".into(), gui_driver.into(), "gui".into()],
},
Gate { Gate {
name: "install".into(), name: "install".into(),
description: "full encrypted install in the disposable VM".into(), description: "full encrypted install in the disposable VM".into(),
@ -236,34 +291,59 @@ pub fn candidate_gates() -> Vec<Gate> {
command: vec!["python3".into(), driver.into(), "install".into()], command: vec!["python3".into(), driver.into(), "install".into()],
}, },
Gate { Gate {
name: "detached-boot".into(), name: "install-repeat".into(),
description: "boot the installed disk with the ISO detached".into(), description: "second independent encrypted install from the same ISO".into(),
requires: GateRequirement::Vm, requires: GateRequirement::Vm,
command: vec!["python3".into(), driver.into(), "boot".into()], command: vec!["python3".into(), driver.into(), "install-repeat".into()],
},
Gate {
name: "detached-boot".into(),
description: "boot detached and complete the boot health assessment".into(),
requires: GateRequirement::Vm,
command: vec!["python3".into(), driver.into(), "boot-assessed".into()],
}, },
Gate { Gate {
name: "no-model-recovery".into(), name: "no-model-recovery".into(),
description: "boot detached with no model; BOOT_CHECKS runs sys --legacy".into(), description: "select and boot the snapshot recovery entry offline; run sys --legacy"
.into(),
requires: GateRequirement::Vm, requires: GateRequirement::Vm,
command: vec!["python3".into(), driver.into(), "boot".into()], command: vec!["python3".into(), driver.into(), "recovery".into()],
},
Gate {
name: "failed-boot-fallback".into(),
description: "exhaust counted normal boots and auto-select recovery offline".into(),
requires: GateRequirement::Vm,
command: vec!["python3".into(), driver.into(), "fallback".into()],
}, },
Gate { Gate {
name: "desktop-session".into(), name: "desktop-session".into(),
description: "graphical seat: launch, lock, suspend, log out".into(), description: "graphical seat: first-login welcome, authenticated session, shortcuts, lock, logout".into(),
requires: GateRequirement::GraphicalSeat, requires: GateRequirement::GraphicalSeat,
command: vec!["python3".into(), gui_driver.into(), "boot".into()], command: vec!["python3".into(), gui_driver.into(), "desktop".into()],
}, },
Gate { Gate {
name: "updates-and-rollback".into(), name: "updates-and-rollback".into(),
description: "prepare, apply, roll back and reboot detached".into(), description: "snapshot, install a package, sys undo, and verify after reboot".into(),
requires: GateRequirement::Vm, requires: GateRequirement::Vm,
command: vec!["python3".into(), driver.into(), "rollback".into()], command: vec!["python3".into(), driver.into(), "rollback".into()],
}, },
Gate {
name: "interrupted-update".into(),
description: "kill a sys package transaction, undo, and verify after reboot".into(),
requires: GateRequirement::Vm,
command: vec!["python3".into(), driver.into(), "interrupted-update".into()],
},
Gate { Gate {
name: "assistant-live".into(), name: "assistant-live".into(),
description: "one live provider call through the sandbox".into(), description: "connect the live installer to a real OpenCode provider and validate its guided proposal".into(),
requires: GateRequirement::Model, requires: GateRequirement::Model,
command: vec!["sys".into(), "ask".into(), "show system status".into()], command: vec!["python3".into(), gui_driver.into(), "opencode".into()],
},
Gate {
name: "ci-verification".into(),
description: "independent CI runner executes the Rust and VM quality gates".into(),
requires: GateRequirement::CiRunner,
command: vec!["make".into(), "check".into()],
}, },
] ]
} }
@ -335,12 +415,34 @@ pub fn gate_prerequisite_missing(gate: &Gate) -> Option<String> {
return Some(format!("missing prerequisite: {var} is not set")); return Some(format!("missing prerequisite: {var} is not set"));
} }
} }
if !std::env::var_os("ISO").is_some_and(|p| Path::new(&p).is_file()) {
return Some("missing prerequisite: ISO is not a readable candidate file".into());
}
if std::env::var_os("DISK").is_none() && std::env::var_os("DISKS").is_none() {
return Some("missing prerequisite: DISK or DISKS is not set".into());
}
if gate
.command
.get(2)
.is_some_and(|mode| mode == "install-repeat")
&& std::env::var_os("DISK_SECOND").is_none()
{
return Some("missing prerequisite: DISK_SECOND is not set".into());
}
if !program_exists(&gate.command[0]) { if !program_exists(&gate.command[0]) {
return Some(format!( return Some(format!(
"missing prerequisite: program '{}' not found on PATH", "missing prerequisite: program '{}' not found on PATH",
gate.command[0] gate.command[0]
)); ));
} }
if gate
.command
.get(2)
.is_some_and(|mode| mode == "fallback" || mode == "interrupted-update")
&& !program_exists("qemu-img")
{
return Some("missing prerequisite: qemu-img is not on PATH".into());
}
None None
} }
GateRequirement::GraphicalSeat => { GateRequirement::GraphicalSeat => {
@ -357,14 +459,11 @@ pub fn gate_prerequisite_missing(gate: &Gate) -> Option<String> {
return Some(format!("missing prerequisite: {var} is not set")); return Some(format!("missing prerequisite: {var} is not set"));
} }
} }
let seat = Path::new("/dev/dri").exists() if !std::env::var_os("ISO").is_some_and(|p| Path::new(&p).is_file()) {
|| std::env::var_os("WAYLAND_DISPLAY").is_some() return Some("missing prerequisite: ISO is not a readable candidate file".into());
|| std::env::var_os("DISPLAY").is_some() }
|| std::env::var_os("PHOEBUS_GRAPHICAL_SEAT").is_some(); if std::env::var_os("DISK").is_none() && std::env::var_os("DISKS").is_none() {
if !seat { return Some("missing prerequisite: DISK or DISKS is not set".into());
return Some(
"missing prerequisite: no graphical seat (/dev/dri, WAYLAND_DISPLAY, DISPLAY, or PHOEBUS_GRAPHICAL_SEAT)".to_string(),
);
} }
if !program_exists(&gate.command[0]) { if !program_exists(&gate.command[0]) {
return Some(format!( return Some(format!(
@ -372,9 +471,33 @@ pub fn gate_prerequisite_missing(gate: &Gate) -> Option<String> {
gate.command[0] gate.command[0]
)); ));
} }
if !std::process::Command::new("python3")
.args(["-c", "import pexpect, PIL"])
.status()
.is_ok_and(|status| status.success())
{
return Some("missing prerequisite: Python pexpect and Pillow are required".into());
}
None None
} }
GateRequirement::Model => { GateRequirement::Model => {
if gate
.command
.get(1)
.is_some_and(|path| path.ends_with("gui-driver.py"))
{
let mut seat_gate = gate.clone();
seat_gate.requires = GateRequirement::GraphicalSeat;
if let Some(missing) = gate_prerequisite_missing(&seat_gate) {
return Some(missing);
}
for var in ["OC_TARGET_PORT", "OC_PROVIDER", "OC_MODEL"] {
if std::env::var_os(var).map_or(true, |value| value.is_empty()) {
return Some(format!("missing prerequisite: {var} is not set"));
}
}
return None;
}
let key_file = std::env::var_os("PHOEBUS_AI_KEY_FILE") let key_file = std::env::var_os("PHOEBUS_AI_KEY_FILE")
.map(|p| Path::new(&p).is_file()) .map(|p| Path::new(&p).is_file())
.unwrap_or(false); .unwrap_or(false);
@ -402,10 +525,16 @@ pub fn gate_prerequisite_missing(gate: &Gate) -> Option<String> {
fn bound_tail(text: &str, max_chars: usize) -> String { fn bound_tail(text: &str, max_chars: usize) -> String {
let trimmed = text.trim(); let trimmed = text.trim();
if trimmed.len() <= max_chars { let char_count = trimmed.chars().count();
if char_count <= max_chars {
return trimmed.to_string(); return trimmed.to_string();
} }
format!("…{}", &trimmed[trimmed.len() - max_chars..]) let start = trimmed
.char_indices()
.nth(char_count - max_chars)
.map(|(index, _)| index)
.unwrap_or(0);
format!("…{}", &trimmed[start..])
} }
/// Execute one gate: run its argv, capture process status and output, and /// Execute one gate: run its argv, capture process status and output, and
@ -426,9 +555,20 @@ fn execute_gate(gate: &Gate) -> GateResult {
detail: missing, detail: missing,
}; };
} }
let output = std::process::Command::new(&gate.command[0]) let mut command = std::process::Command::new(&gate.command[0]);
.args(&gate.command[1..]) command.args(&gate.command[1..]);
.output(); if gate
.command
.get(1)
.is_some_and(|harness| harness.ends_with("gui-driver.py"))
{
// A release gate must test the immutable ISO named by `ISO`.
command.env("SKIP_ENSURE_ISO", "1");
}
if gate.name == "desktop-session" {
command.env("DESKTOP_EXPECT_WELCOME", "1");
}
let output = command.output();
match output { match output {
Err(e) if e.kind() == std::io::ErrorKind::NotFound => GateResult { Err(e) if e.kind() == std::io::ErrorKind::NotFound => GateResult {
name: gate.name.clone(), name: gate.name.clone(),
@ -476,6 +616,29 @@ fn execute_gate(gate: &Gate) -> GateResult {
} }
} }
/// Record whether the candidate was built from a clean checkout.
pub fn git_source_revision() -> Option<String> {
let head = std::process::Command::new("git")
.args(["rev-parse", "HEAD"])
.output()
.ok()
.filter(|out| out.status.success())?;
let revision = String::from_utf8_lossy(&head.stdout).trim().to_string();
if revision.is_empty() {
return None;
}
let status = std::process::Command::new("git")
.args(["status", "--porcelain"])
.output()
.ok()
.filter(|out| out.status.success())?;
if status.stdout.is_empty() {
Some(revision)
} else {
Some(format!("{revision}-dirty"))
}
}
/// Run a gate list, isolating each gate in its own process. Exported for /// Run a gate list, isolating each gate in its own process. Exported for
/// tests; production uses [`run_gates`]. /// tests; production uses [`run_gates`].
pub fn run_gate_list(execute: bool, gates: &[Gate]) -> GateReport { pub fn run_gate_list(execute: bool, gates: &[Gate]) -> GateReport {
@ -486,6 +649,20 @@ pub fn run_gate_list(execute: bool, gates: &[Gate]) -> GateReport {
let mut report = GateReport { let mut report = GateReport {
version: env!("CARGO_PKG_VERSION").to_string(), version: env!("CARGO_PKG_VERSION").to_string(),
created_unix: now, created_unix: now,
candidate_iso_sha256: if execute {
std::env::var_os("ISO").and_then(|path| sha256_file(Path::new(&path)).ok())
} else {
None
},
source_revision: git_source_revision(),
disk_images: std::env::var("DISKS")
.or_else(|_| std::env::var("DISK"))
.unwrap_or_default()
.split(',')
.filter(|s| !s.is_empty())
.map(str::to_owned)
.chain(std::env::var("DISK_SECOND").ok())
.collect(),
results: Vec::new(), results: Vec::new(),
}; };
for gate in gates { for gate in gates {
@ -496,7 +673,16 @@ pub fn run_gate_list(execute: bool, gates: &[Gate]) -> GateReport {
detail: format!("not run (requires {})", gate.requires.as_str()), detail: format!("not run (requires {})", gate.requires.as_str()),
}); });
} else { } else {
report.results.push(execute_gate(gate)); let mut result = execute_gate(gate);
if let (Some(expected), Some(candidate)) =
(&report.candidate_iso_sha256, std::env::var_os("ISO"))
{
if sha256_file(Path::new(&candidate)).ok().as_ref() != Some(expected) {
result.status = GateStatus::Failed;
result.detail = "candidate ISO changed during gate execution".into();
}
}
report.results.push(result);
} }
} }
report report
@ -605,17 +791,29 @@ mod tests {
assert_eq!(cmd[0], "xorriso"); assert_eq!(cmd[0], "xorriso");
assert!(cmd.iter().any(|a| a == "/phoebus")); assert!(cmd.iter().any(|a| a == "/phoebus"));
assert!(cmd.iter().any(|a| a == "/base.iso")); assert!(cmd.iter().any(|a| a == "/base.iso"));
assert_eq!(cmd.last().map(String::as_str), Some("replay"));
}
#[test]
fn gate_output_tail_handles_multibyte_text() {
assert_eq!(bound_tail("prefix café 🦀", 3), "…é 🦀");
} }
#[test] #[test]
fn gates_cover_the_required_checks_and_never_fake_a_pass() { fn gates_cover_the_required_checks_and_never_fake_a_pass() {
let names: Vec<String> = candidate_gates().into_iter().map(|g| g.name).collect(); let names: Vec<String> = candidate_gates().into_iter().map(|g| g.name).collect();
for required in [ for required in [
"live-installer-ui",
"install", "install",
"install-repeat",
"detached-boot", "detached-boot",
"desktop-session", "desktop-session",
"updates-and-rollback", "updates-and-rollback",
"interrupted-update",
"no-model-recovery", "no-model-recovery",
"failed-boot-fallback",
"assistant-live",
"ci-verification",
] { ] {
assert!( assert!(
names.contains(&required.to_string()), names.contains(&required.to_string()),
@ -626,6 +824,12 @@ mod tests {
assert!(!report.all_passed(), "an unexecuted gate is not a pass"); assert!(!report.all_passed(), "an unexecuted gate is not a pass");
assert_eq!(report.not_run(), report.results.len()); assert_eq!(report.not_run(), report.results.len());
assert!(report.results.iter().all(|r| r.detail.contains("requires"))); assert!(report.results.iter().all(|r| r.detail.contains("requires")));
let assistant = candidate_gates()
.into_iter()
.find(|gate| gate.name == "assistant-live")
.unwrap();
assert_eq!(assistant.command[1], "installer/tests/vm/gui-driver.py");
assert_eq!(assistant.command[2], "opencode");
} }
#[test] #[test]
@ -740,6 +944,7 @@ mod tests {
status: GateStatus::Passed, status: GateStatus::Passed,
detail: "exit 0".into(), detail: "exit 0".into(),
}], }],
..Default::default()
}; };
assert!(passing.all_passed()); assert!(passing.all_passed());
for status in [GateStatus::Failed, GateStatus::NotRun] { for status in [GateStatus::Failed, GateStatus::NotRun] {
@ -758,6 +963,7 @@ mod tests {
detail: "evidence".into(), detail: "evidence".into(),
}, },
], ],
..Default::default()
}; };
assert!( assert!(
!report.all_passed(), !report.all_passed(),
@ -770,6 +976,43 @@ mod tests {
); );
} }
#[test]
fn publish_rejects_a_report_for_a_different_iso_or_missing_gate() {
let dir = tempfile::tempdir().unwrap();
let candidate = dir.path().join("candidate.iso");
std::fs::write(&candidate, b"candidate one").unwrap();
let mut report = GateReport {
candidate_iso_sha256: Some(sha256_file(&candidate).unwrap()),
source_revision: Some("0123456789abcdef0123456789abcdef01234567".into()),
results: candidate_gates()
.into_iter()
.map(|gate| GateResult {
name: gate.name,
status: GateStatus::Passed,
detail: "verified".into(),
})
.collect(),
..Default::default()
};
assert!(report.ready_to_publish(&candidate));
assert!(report.matches_source_revision(Some("0123456789abcdef0123456789abcdef01234567")));
assert!(!report.matches_source_revision(Some("fedcba9876543210fedcba9876543210fedcba98")));
assert!(!report.matches_source_revision(None));
report.source_revision = Some("0123456789abcdef0123456789abcdef01234567-dirty".into());
assert!(!report.ready_to_publish(&candidate));
assert!(!report.matches_source_revision(Some("0123456789abcdef0123456789abcdef01234567")));
report.source_revision = Some("0123456789abcdef0123456789abcdef01234567".into());
report.results.pop();
assert!(!report.ready_to_publish(&candidate));
report.results.push(GateResult {
name: "assistant-live".into(),
status: GateStatus::Passed,
detail: "verified".into(),
});
std::fs::write(&candidate, b"candidate two").unwrap();
assert!(!report.ready_to_publish(&candidate));
}
#[test] #[test]
fn atomic_publish_keeps_the_previous_release() { fn atomic_publish_keeps_the_previous_release() {
let dir = tempfile::tempdir().unwrap(); let dir = tempfile::tempdir().unwrap();

View file

@ -242,12 +242,13 @@ fn assets_include_the_welcome_launcher_and_branding() {
} }
#[test] #[test]
fn installed_session_never_starts_the_welcome() { fn mango_session_selects_live_or_installed_welcome() {
// The live-only marker is the gate; the installed session script must not // The installed launcher checks its per-user seen marker. Mango itself
// autostart the welcome unless the marker exists. // starts the launcher because this custom session does not run XDG autostart.
let script = system::desktop_asset("session-mango").unwrap(); let script = system::desktop_asset("session-mango").unwrap();
assert!(script.contains("/etc/phoebus/live")); assert!(script.contains("if [ -e /etc/phoebus/live ]"));
assert!(script.contains("phoebus-welcome")); assert!(script.contains("elif [ -x /usr/local/bin/phoebus-welcome ]"));
assert!(system::INSTALLED_WELCOME_SCRIPT.contains("welcome-seen"));
} }
#[test] #[test]

View file

@ -459,7 +459,8 @@ printf 'virtio_gpu\n' > "$rootfs/etc/modules-load.d/phoebus-live-gpu.conf"
squashfs="$work/filesystem.squashfs" squashfs="$work/filesystem.squashfs"
rm -f "$squashfs" rm -f "$squashfs"
mksquashfs "$rootfs" "$squashfs" \ mksquashfs "$rootfs" "$squashfs" \
-noappend -comp zstd -all-root -no-progress >/dev/null -noappend -comp zstd -all-root -no-progress \
-processors 4 -mem 2G >/dev/null
echo "squashfs: $(du -h "$squashfs" | cut -f1)" echo "squashfs: $(du -h "$squashfs" | cut -f1)"
# Package list for the live medium (informational). # Package list for the live medium (informational).
@ -467,8 +468,8 @@ grep -a '^Package: ' "$rootfs/var/lib/dpkg/status" 2>/dev/null \
| awk '{print $2}' | sort -u > "$work/filesystem.packages" || true | awk '{print $2}' | sort -u > "$work/filesystem.packages" || true
# Kernel and initramfs generated inside the rootfs. # Kernel and initramfs generated inside the rootfs.
vmlinuz="$(ls -1 "$rootfs"/boot/vmlinuz-* 2>/dev/null | sort | tail -1 || true)" vmlinuz="$(find "$rootfs/boot" -maxdepth 1 -name 'vmlinuz-*' \( -type f -o -type l \) -print 2>/dev/null | sort | tail -1 || true)"
initrd="$(ls -1 "$rootfs"/boot/initrd.img-* 2>/dev/null | sort | tail -1 || true)" initrd="$(find "$rootfs/boot" -maxdepth 1 -name 'initrd.img-*' \( -type f -o -type l \) -print 2>/dev/null | sort | tail -1 || true)"
[[ -f "$vmlinuz" ]] || { echo "live rootfs has no vmlinuz" >&2; exit 1; } [[ -f "$vmlinuz" ]] || { echo "live rootfs has no vmlinuz" >&2; exit 1; }
[[ -f "$initrd" ]] || { echo "live rootfs has no initrd" >&2; exit 1; } [[ -f "$initrd" ]] || { echo "live rootfs has no initrd" >&2; exit 1; }
cp "$vmlinuz" "$work/vmlinuz" cp "$vmlinuz" "$work/vmlinuz"
@ -558,8 +559,9 @@ say "assemble ISO"
rm -f "$out" rm -f "$out"
# Replace every kernel/initrd path the base ISO ships (both the canonical # Replace every kernel/initrd path the base ISO ships (both the canonical
# /live/vmlinuz and the versioned name its GRUB config may reference), plus the # /live/vmlinuz and the versioned name its GRUB config may reference), plus the
# live squashfs and serial-patched GRUB config. `-boot_image any keep` preserves # live squashfs and serial-patched GRUB config. Replay the detected boot
# the UEFI/BIOS boot equipment. # configuration after mapping files so the MBR/GPT partition lengths reflect
# this ISO's size, while preserving its UEFI and BIOS boot entries.
kmap=() kmap=()
while IFS= read -r path; do while IFS= read -r path; do
[ -n "$path" ] || continue [ -n "$path" ] || continue
@ -579,7 +581,10 @@ xorriso -indev "$base" -outdev "$out" \
-map "$bootcfg/theme.cfg" /boot/grub/theme.cfg \ -map "$bootcfg/theme.cfg" /boot/grub/theme.cfg \
-map "$bootcfg/theme.txt" /boot/grub/live-theme/theme.txt \ -map "$bootcfg/theme.txt" /boot/grub/live-theme/theme.txt \
-map "$bootcfg/splash.png" /boot/grub/splash.png \ -map "$bootcfg/splash.png" /boot/grub/splash.png \
-boot_image any keep >/dev/null -boot_image any replay >/dev/null
# Catch stale partition tables or unreadable boot metadata before publishing.
xorriso -indev "$out" -toc >/dev/null
sha256sum "$out" | tee "$out.sha256" sha256sum "$out" | tee "$out.sha256"
ls -lh "$out" ls -lh "$out"

View file

@ -84,7 +84,6 @@ Column {
function openPopup() { function openPopup() {
combo.popupOpen = true; combo.popupOpen = true;
combo.opened(); combo.opened();
searchField.text = "";
combo.refreshFilter(); combo.refreshFilter();
searchField.forceActiveFocus(); searchField.forceActiveFocus();
} }
@ -174,6 +173,7 @@ Column {
onTextEdited: { onTextEdited: {
combo.currentValue = mainInput.text; combo.currentValue = mainInput.text;
combo.currentLabel = mainInput.text; combo.currentLabel = mainInput.text;
searchField.text = mainInput.text;
combo.refreshFilter(); combo.refreshFilter();
combo.edited(mainInput.text); combo.edited(mainInput.text);
} }

View file

@ -341,6 +341,7 @@ ShellRoot {
shell.status = ""; shell.status = "";
shell.syncFields(); shell.syncFields();
shell.loadOptions(); shell.loadOptions();
focusStepTimer.start();
} }
function updateAiVariants() { function updateAiVariants() {
@ -1131,6 +1132,7 @@ ShellRoot {
if (typeof window.requestActivate === "function") if (typeof window.requestActivate === "function")
window.requestActivate(); window.requestActivate();
page.forceActiveFocus(); page.forceActiveFocus();
shell.focusCurrentStep();
} }
} }

View file

@ -253,7 +253,7 @@ ShellRoot {
focus: true focus: true
activeFocusOnTab: true activeFocusOnTab: true
onClicked: { onClicked: {
shell.run(["sh", "-c", "pkill -f 'quickshell.*phoebus-welcome' 2>/dev/null; exec /usr/local/bin/phoebus-install"]); shell.run(["/usr/local/bin/phoebus-install"]);
} }
} }

View file

@ -7,17 +7,21 @@ touching a physical disk. The target is always a qcow2 file.
- `run-vm.sh` interactive QEMU launcher (manual testing). - `run-vm.sh` interactive QEMU launcher (manual testing).
- `install.sh` guest-side, non-interactive installation (run in the VM). - `install.sh` guest-side, non-interactive installation (run in the VM).
- `serial-driver.py` host-side pexpect driver (`install`, `boot` and - `serial-driver.py` host-side pexpect driver (`install`, `install-repeat`,
`rollback` modes). `boot`, `boot-assessed`, `recovery`, `fallback`, `rollback`,
`interrupted-update` modes).
- `rollback-guest.sh`, `rollback-verify.sh` guest-side rollback acceptance - `rollback-guest.sh`, `rollback-verify.sh` guest-side rollback acceptance
(fetch `sys`, snapshot, break, undo, verify). (fetch `sys`, snapshot, break, undo, verify).
- `interrupted-update.sh` kills an active `sys`/Portage package transaction,
recovers its lock, undoes its snapshot, and verifies after reboot.
- `snap-guest.sh` guest-side Snap setup/install/refresh/remove acceptance. - `snap-guest.sh` guest-side Snap setup/install/refresh/remove acceptance.
- `test.conf.example` installer configuration used by the driver. - `test.conf.example` installer configuration used by the driver.
## Host prerequisites ## Host prerequisites
- `qemu-system-x86_64`, `qemu-img`, OVMF firmware, Python `pexpect`. - `qemu-system-x86_64`, `qemu-img`, OVMF firmware, Python `pexpect`; the
- The reference Gentoo ISO. graphical gate also needs Pillow.
- The current Phoebus Debian-live ISO (the installed target remains Gentoo).
- The static Rust installer (the guest never runs the Bash tree): - The static Rust installer (the guest never runs the Bash tree):
```sh ```sh
@ -28,15 +32,15 @@ RUSTFLAGS="-C target-feature=+crt-static" \
## Procedure ## Procedure
Serve the static installer, the stage3 and the config to the guest: Serve the pinned stage3 and test config to the guest. The installer and `sys`
run from the candidate ISO itself:
```sh ```sh
cd /path/to/serve cd /path/to/serve
cp /path/to/phoebus_os/installer-rs/target/x86_64-unknown-linux-gnu/release/phoebus-installer .
cp /path/to/phoebus_os/installer/tests/vm/install.sh . cp /path/to/phoebus_os/installer/tests/vm/install.sh .
cp /path/to/phoebus_os/installer/tests/vm/test.conf.example test.conf # edit TARGET_DISK etc. cp /path/to/phoebus_os/installer/tests/vm/test.conf.example test-mango.conf # set the real stage3 digest
sha256sum stage3.tar.xz # set STAGE3_SHA256 sha256sum stage3.tar.xz # set STAGE3_SHA256
python3 -m http.server 8000 --bind 127.0.0.1 python3 -m http.server 8000 --bind 0.0.0.0
``` ```
Run the installation (driver boots the ISO kernel/initrd directly and drives Run the installation (driver boots the ISO kernel/initrd directly and drives
@ -49,12 +53,15 @@ QEMU_DATADIR=/path/to/qemu/share \
OVMF_CODE=/path/to/OVMF_CODE_4M.fd \ OVMF_CODE=/path/to/OVMF_CODE_4M.fd \
OVMF_VARS=/path/to/OVMF_VARS.fd \ OVMF_VARS=/path/to/OVMF_VARS.fd \
DISK=/tmp/phoebus/target.qcow2 \ DISK=/tmp/phoebus/target.qcow2 \
ISO=/path/to/livegui-amd64.iso \ ISO=/path/to/phoebus-installer-amd64.iso \
KERNEL=/tmp/live/boot/gentoo INITRD=/tmp/live/boot/gentoo.igz \ KERNEL=/path/to/live/vmlinuz INITRD=/path/to/live/initrd.img \
INSTALL_URL=http://10.0.2.2:8000/install.sh \ INSTALL_URL=http://10.0.2.2:8000/install.sh \
python3 installer/tests/vm/serial-driver.py install python3 installer/tests/vm/serial-driver.py install
``` ```
The install gate defaults to `test-mango.conf` (Mango, Flatpak and Nix). Set
`VM_INSTALL_CONFIG=test.conf` only for a separate minimal-profile exercise.
Then boot the disk alone (ISO detached) and verify: Then boot the disk alone (ISO detached) and verify:
```sh ```sh
@ -99,8 +106,12 @@ python3 installer/tests/vm/serial-driver.py rollback
``` ```
Point `DISK` at a **disposable clone** of the evidence image so the original is Point `DISK` at a **disposable clone** of the evidence image so the original is
preserved. Booting the recovery entry itself with the network removed remains a preserved. `serial-driver.py recovery` selects the actual systemd-boot recovery
manual gate; the harness records the entry but does not select it. entry with networking disabled and checks the read-only snapshot and `sys`.
`fallback` and `interrupted-update` create their own qcow2 overlays beneath
`PHOEBUS_VM_DISKS`, leaving the installed evidence image unchanged. The
`install-repeat` mode requires a distinct `DISK_SECOND` and checks its resolved
path before starting QEMU.
## Snap acceptance on an installed disposable image ## Snap acceptance on an installed disposable image
@ -134,7 +145,9 @@ output, not the test passwords it sends for LUKS, login and `sudo`.
- Screenshots use structured QMP and argument arrays; there is no shell - Screenshots use structured QMP and argument arrays; there is no shell
interpolation (`os.system`) in the harness. interpolation (`os.system`) in the harness.
- Secrets are passed through 0600 files and checked for leakage in the - Secrets are passed through 0600 files and checked for leakage in the
installer log by the guest script. installer log by the guest script. Host serial transcripts and structured
result details redact registered test credentials, including output split
across pexpect reads.
## Results ## Results

View file

@ -21,6 +21,7 @@ Modes:
with the static binary, scan the log for a secret leak, power off. with the static binary, scan the log for a secret leak, power off.
boot : boot the installed disk alone (no ISO), unlock LUKS, log in and run boot : boot the installed disk alone (no ISO), unlock LUKS, log in and run
verification commands. verification commands.
desktop : boot with a graphical seat and assert the installed Mango session.
Safety: every writable drive must be a qcow2 file inside the disposable Safety: every writable drive must be a qcow2 file inside the disposable
directory named by `PHOEBUS_VM_DISKS` (default directory named by `PHOEBUS_VM_DISKS` (default
@ -37,6 +38,7 @@ from __future__ import annotations
import json import json
import os import os
import re import re
import shlex
import shutil import shutil
import subprocess import subprocess
import sys import sys
@ -44,6 +46,7 @@ import time
from pathlib import Path from pathlib import Path
import pexpect import pexpect
from PIL import Image, ImageChops
import vmsafety import vmsafety
from vmsafety import BLOCKED, FAIL, PASS, Results, HarnessError from vmsafety import BLOCKED, FAIL, PASS, Results, HarnessError
@ -91,10 +94,14 @@ def _disposable_dir() -> Path:
class Driver: class Driver:
def __init__(self, mode: str): def __init__(self, mode: str):
self.mode = mode self.mode = mode
self.results = Results(f"gui-{mode}")
self.paths = vmsafety.make_run_paths( self.paths = vmsafety.make_run_paths(
f"gui-{mode}", base=_template_dir(), ovmf_vars_template=OVMF_VARS_TEMPLATE f"gui-{mode}", base=_template_dir(), ovmf_vars_template=OVMF_VARS_TEMPLATE
) )
self.results = Results(
f"gui-{mode}", run_id=self.paths.run_id,
secrets=[LUKS_PW, USER_PW, LIVE_PW, os.environ.get("OC_PASSWORD"),
os.environ.get("OPENAI_API_KEY"), os.environ.get("DEEPSEEK_API_KEY")],
)
self.manifest: list[dict] = [] self.manifest: list[dict] = []
self.seq = 0 self.seq = 0
self.child: pexpect.spawn | None = None self.child: pexpect.spawn | None = None
@ -166,7 +173,13 @@ class Driver:
) )
self.child.delaybeforesend = 0.4 self.child.delaybeforesend = 0.4
self.log = open(self.paths.serial_log, "w") self.log = open(self.paths.serial_log, "w")
self.child.logfile = self.log # A prompt race can echo a credential back from the guest. Buffer
# complete terminal lines so redaction also covers split reads.
self.child.logfile_read = vmsafety.RedactingTextLog(
self.log,
[LUKS_PW, USER_PW, LIVE_PW, os.environ.get("OC_PASSWORD"),
os.environ.get("OPENAI_API_KEY"), os.environ.get("DEEPSEEK_API_KEY")],
)
self.spawned = True self.spawned = True
self.results.pass_( self.results.pass_(
"qemu-spawned", f"{len(self.disks)} writable disk(s); iso={bool(ISO)}" "qemu-spawned", f"{len(self.disks)} writable disk(s); iso={bool(ISO)}"
@ -215,6 +228,20 @@ class Driver:
self.results.pass_(f"screenshot-{name}", str(png if png.exists() else ppm)) self.results.pass_(f"screenshot-{name}", str(png if png.exists() else ppm))
return ppm if ok else None return ppm if ok else None
@staticmethod
def frame_change_ratio(before: Path | None, after: Path | None) -> float:
"""Fraction of visibly changed pixels between two guest frames."""
if before is None or after is None:
return 0.0
with Image.open(before) as previous, Image.open(after) as current:
if previous.size != current.size:
return 1.0
diff = ImageChops.difference(previous.convert("RGB"), current.convert("RGB"))
# Ignore tiny cursor and antialiasing changes. DMS overlays cover
# a substantial fraction of the screen; a clock tick does not.
changed = sum(1 for value in diff.convert("L").getdata() if value > 24)
return changed / (previous.width * previous.height)
def write_manifest(self) -> None: def write_manifest(self) -> None:
path = self.paths.directory / "screenshot-manifest.json" path = self.paths.directory / "screenshot-manifest.json"
path.write_text(json.dumps(self.manifest, indent=2) + "\n") path.write_text(json.dumps(self.manifest, indent=2) + "\n")
@ -322,6 +349,8 @@ class Driver:
self.do_install() self.do_install()
elif self.mode == "boot": elif self.mode == "boot":
self.do_boot() self.do_boot()
elif self.mode == "desktop":
self.do_boot(desktop=True)
else: else:
print(__doc__) print(__doc__)
return 2 return 2
@ -330,7 +359,7 @@ class Driver:
except Exception as exc: # noqa: BLE001 except Exception as exc: # noqa: BLE001
self.results.fail("harness-exception", repr(exc)) self.results.fail("harness-exception", repr(exc))
finally: finally:
if self.spawned: if self.spawned and self.child is not None and self.child.isalive():
try: try:
self.shot("final-state", "final", "end of run", "last observed state") self.shot("final-state", "final", "end of run", "last observed state")
except Exception: # noqa: BLE001 except Exception: # noqa: BLE001
@ -346,10 +375,13 @@ class Driver:
def teardown(self) -> None: def teardown(self) -> None:
if self.child is not None: if self.child is not None:
redactor = self.child.logfile_read
try: try:
self.child.close(force=True) self.child.close(force=True)
except Exception: # noqa: BLE001 except Exception: # noqa: BLE001
pass pass
if isinstance(redactor, vmsafety.RedactingTextLog):
redactor.finish()
if self.log is not None: if self.log is not None:
try: try:
self.log.close() self.log.close()
@ -519,10 +551,9 @@ class Driver:
"the language and keyboard step is shown") "the language and keyboard step is shown")
# Regression: the suggestion list supports arrow-key navigation and # Regression: the suggestion list supports arrow-key navigation and
# Enter selection, with the value stored being the identifier. # Enter selection, with the value stored being the identifier.
self.sendkey("ctrl-a") self._gui_type("de_DE")
time.sleep(0.3) self.shot("03a-locale-filter", "locale search", "typed de_DE",
self.shell("wtype 'de_DE' >/dev/null 2>&1; echo TYPED", "TYPED", "the locale list is filtered from keyboard input")
timeout=30, label="type-locale")
time.sleep(1.0) time.sleep(1.0)
self.sendkey("down") self.sendkey("down")
time.sleep(0.5) time.sleep(0.5)
@ -782,14 +813,15 @@ class Driver:
self.sendkey("ctrl-a") self.sendkey("ctrl-a")
time.sleep(0.5) time.sleep(0.5)
if secret_file: if secret_file:
# The serial echo carries `$(cat ...)`, never the value. # wtype's `-` reads stdin; the credential never enters argv
# or the serial command echo.
self.shell( self.shell(
f'wtype "$(cat {secret_file})" >/dev/null 2>&1; echo TYPED', f'wtype - < {secret_file} >/dev/null 2>&1; echo TYPED',
"TYPED", timeout=30, label="type-secret", "TYPED", timeout=30, label="type-secret",
) )
else: else:
self.shell( self.shell(
f"wtype '{value}' >/dev/null 2>&1; echo TYPED", f"wtype {shlex.quote(value)} >/dev/null 2>&1; echo TYPED",
"TYPED", timeout=30, label="type-field", "TYPED", timeout=30, label="type-field",
) )
time.sleep(1.4) time.sleep(1.4)
@ -1310,18 +1342,180 @@ class Driver:
except pexpect.TIMEOUT: except pexpect.TIMEOUT:
self.results.fail("install-eof", "QEMU did not exit after poweroff") self.results.fail("install-eof", "QEMU did not exit after poweroff")
# -- installed graphical seat ------------------------------------------
def verify_installed_desktop(self) -> None:
"""Authenticate through greetd on the virtual seat and exercise it.
The serial login is only the observer. All login and shortcut keys
below enter through QEMU's virtio keyboard on the graphical seat.
"""
greet = self.poll_shell(
"echo GREET=$(pgrep -xc tuigreet || echo 0)",
r"GREET=([1-9][0-9]*)",
timeout=90,
label="desktop-greeter",
record=False,
)
if greet is None:
self.results.fail("desktop-greeter", "tuigreet is not running on the installed system")
return
self.results.pass_("desktop-greeter")
# The installed greetd config owns VT7; VT1 still shows dracut's
# earlier LUKS prompt after the serial console unlocked the disk.
self.sendkey("ctrl-alt-f7")
self.shot("desktop-greeter", "installed greeter", "observe seat login",
"tuigreet asks for an authenticated user login")
self._send_chars(USER)
self.sendkey("ret")
self._send_chars(USER_PW)
self.sendkey("ret")
session = self.poll_shell(
"echo DESKTOP_MANGO=$(pgrep -xc mango || echo 0) "
"DESKTOP_DMS=$(pgrep -xc dms || echo 0)",
r"DESKTOP_MANGO=([1-9][0-9]*) DESKTOP_DMS=([1-9][0-9]*)",
timeout=180,
label="desktop-session-ready",
record=False,
)
if session is None:
self.results.fail("desktop-session-ready", "authenticated Mango and DMS did not start")
self.shot("desktop-login-failed", "failed graphical login", "after credentials",
"Mango and DMS should be visible")
return
self.results.pass_("desktop-session-ready")
if os.environ.get("DESKTOP_EXPECT_WELCOME") == "1":
welcome = self.poll_shell(
"echo WELCOME=$(pgrep -ax quickshell 2>/dev/null "
"| grep -Fc phoebus-welcome-installed)",
r"WELCOME=([1-9][0-9]*)", timeout=60,
label="desktop-first-login-welcome", record=False,
)
self.results.assert_true(
"desktop-first-login-welcome", welcome is not None,
"the Phoebus first-login welcome did not start",
)
check = self.shell(
"echo SEAT-$(printf CHECK)=$(loginctl list-sessions --no-legend | grep -c seat0); "
"echo GPU-$(printf CHECK)=$(test -e /dev/dri/card0 && echo yes || echo no); "
"echo AUDIO-$(printf CHECK)=$(wpctl status >/dev/null 2>&1 && echo yes || echo no); "
"echo NET-$(printf CHECK)=$(nmcli general status >/dev/null 2>&1 && echo yes || echo no); "
"echo CONFIG-$(printf CHECK)=$(test -r \"$HOME/.config/mango/config.conf\" "
"&& echo yes || echo no); "
"echo DMS-SEED-$(printf CHECK)=$(test -f "
"\"$HOME/.config/DankMaterialShell/.firstlaunch\" "
"&& echo yes || echo no); "
"echo DMS-CHANGELOG-$(printf CHECK)=$(test -f "
"\"$HOME/.config/DankMaterialShell/.changelog-1.6\" "
"&& echo yes || echo no); "
"echo DESKTOP-$(printf CHECKS-DONE)",
"DESKTOP-CHECKS-DONE", label="desktop-basic-checks",
)
self.results.assert_true("desktop-real-seat", "SEAT-CHECK=1" in check and
"GPU-CHECK=yes" in check, "no active graphical DRM seat")
self.results.assert_true("desktop-audio-control", "AUDIO-CHECK=yes" in check,
"PipeWire/WirePlumber control is unavailable")
self.results.assert_true("desktop-network-control", "NET-CHECK=yes" in check,
"NetworkManager control is unavailable")
self.results.assert_true("desktop-mango-config", "CONFIG-CHECK=yes" in check,
"Mango did not seed a readable per-user config")
self.results.assert_true("desktop-dms-onboarding-suppressed", "DMS-SEED-CHECK=yes" in check,
"installed user lacks the DMS onboarding marker")
self.results.assert_true("desktop-dms-changelog-suppressed",
"DMS-CHANGELOG-CHECK=yes" in check,
"installed user lacks the DMS versioned changelog marker")
self.shot("desktop-session", "installed desktop", "after authenticated login",
"Mango compositor and DMS panel are visible")
if os.environ.get("DESKTOP_EXPECT_WELCOME") == "1":
self.sendkey("esc")
seen = self.poll_shell(
"echo WELCOME-SEEN=$(test -f "
"\"$HOME/.config/phoebus/welcome-seen\" && echo yes || echo no)",
r"WELCOME-SEEN=yes", timeout=30,
label="desktop-welcome-dismissed", record=False,
)
self.results.assert_true(
"desktop-welcome-dismissed", seen is not None,
"closing the first-login welcome did not record its seen marker",
)
self.sendkey("meta_l-shift-ret")
terminal = self.poll_shell(
"echo KITTY=$(pgrep -xc kitty || echo 0)",
r"KITTY=([1-9][0-9]*)",
timeout=60,
label="desktop-terminal",
record=False,
)
self.results.assert_true("desktop-terminal", terminal is not None,
"Mod+Shift+Return did not launch kitty")
terminal_frame = self.shot("desktop-terminal", "kitty", "Mod+Shift+Return",
"terminal window is visible")
self.sendkey("meta_l-spc")
time.sleep(1)
launcher_frame = self.shot("desktop-launcher", "DMS spotlight", "Mod+Space",
"spotlight launcher is visible")
self.results.assert_true(
"desktop-launcher-visible",
self.frame_change_ratio(terminal_frame, launcher_frame) > 0.02,
"Mod+Space did not visibly open the launcher",
)
self.sendkey("esc")
time.sleep(1)
unlocked_frame = self.shot("desktop-before-lock", "desktop", "dismiss launcher",
"desktop is visible")
self.sendkey("meta_l-alt-l")
time.sleep(1)
locked_frame = self.shot("desktop-locked", "DMS lock screen", "Mod+Alt+L",
"session is locked and password field is visible")
self.results.assert_true(
"desktop-lock-visible",
self.frame_change_ratio(unlocked_frame, locked_frame) > 0.05,
"Mod+Alt+L did not visibly lock the session",
)
self._send_chars(USER_PW)
self.sendkey("ret")
alive = self.poll_shell(
"echo SESSION=$(pgrep -xc mango || echo 0):$(pgrep -xc dms || echo 0)",
r"SESSION=[1-9][0-9]*:[1-9][0-9]*",
timeout=30,
label="desktop-unlocked",
record=False,
)
self.results.assert_true("desktop-unlocked", alive is not None,
"Mango or DMS exited during lock/unlock")
after_unlock = self.shot("desktop-unlocked", "installed desktop",
"unlock with account password", "desktop is visible again")
self.results.assert_true(
"desktop-unlock-visible",
self.frame_change_ratio(locked_frame, after_unlock) > 0.05,
"the lock screen did not visibly disappear after authentication",
)
self.sendkey("meta_l-shift-e")
gone = self.poll_shell(
"echo LOGOUT=$(pgrep -xc mango || echo 0)",
r"LOGOUT=0",
timeout=45,
label="desktop-logout",
record=False,
)
self.results.assert_true("desktop-logout", gone is not None,
"Mango session did not exit after Mod+Shift+e")
self.shot("desktop-logout", "greeter", "log out",
"greetd login is visible and no session remains")
# -- detached boot ----------------------------------------------------- # -- detached boot -----------------------------------------------------
def do_boot(self) -> None: def do_boot(self, desktop: bool = False) -> None:
if not self.disks: if not self.disks:
self.results.blocked("boot-disk", "no writable disk configured") self.results.blocked("boot-disk", "no writable disk configured")
return return
self.spawn(attach_iso=False, boot_disk=True) self.spawn(attach_iso=False, boot_disk=True)
checks = os.environ.get( checks = os.environ.get(
"BOOT_CHECKS", "BOOT_CHECKS",
"echo ===CHECKS-$(printf START)===; " "setopt NO_EQUALS 2>/dev/null; echo ===CHECKS-$(printf START)===; "
"echo COMM_CHECK:$(cat /proc/1/comm 2>&1); " "echo COMM_CHECK:$(cat /proc/1/comm 2>&1); "
"echo SYSTEMD_STATUS:$(systemctl is-system-running 2>&1); " "echo SYSTEMD_STATUS:$(systemctl is-system-running 2>&1); "
"echo SYS_CLI_CHECK:$(which sys 2>&1 && sys history --legacy 2>&1 | grep -o 'no transactions recorded' || echo missing); " "sys history --legacy >/tmp/phoebus-sys-history 2>&1; echo SYS_CLI_RC:$?; "
"systemctl --failed --no-pager; ip -brief addr; " "systemctl --failed --no-pager; ip -brief addr; "
"lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS; echo ===CHECKS-$(printf END)===", "lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS; echo ===CHECKS-$(printf END)===",
) )
@ -1345,16 +1539,19 @@ class Driver:
logged_in = False logged_in = False
for _ in range(5): for _ in range(5):
try: try:
self.child.expect(r"[\w\-]*login:", timeout=300) self.child.expect(r"(?m)^phoebus login:", timeout=300)
except (pexpect.TIMEOUT, pexpect.EOF): except (pexpect.TIMEOUT, pexpect.EOF):
break break
# The early getty can be replaced while default.target settles.
# Let the final prompt stabilize before sending credentials.
time.sleep(5)
self.child.sendline(USER) self.child.sendline(USER)
choice = self.child.expect( choice = self.child.expect(
[r"[Pp]assword:", r"[\w\-]*login:", r"Login incorrect"], timeout=60 [r"[Pp]assword:", r"(?m)^phoebus login:", r"Login incorrect"], timeout=60
) )
if choice == 0: if choice == 0:
self.child.sendline(USER_PW) self.child.sendline(USER_PW)
if self.child.expect([r"[$#] $", r"Login incorrect", r"[\w\-]*login:"], if self.child.expect([r"[$#] |❯", r"Login incorrect", r"(?m)^phoebus login:"],
timeout=120) == 0: timeout=120) == 0:
logged_in = True logged_in = True
break break
@ -1369,32 +1566,37 @@ class Driver:
systemd_status = systemd_status_match.group(1) if systemd_status_match else "unknown" systemd_status = systemd_status_match.group(1) if systemd_status_match else "unknown"
self.results.assert_true( self.results.assert_true(
"boot-systemd-running", "boot-systemd-running",
systemd_status in ("running", "degraded"), systemd_status == "running" if desktop else systemd_status in ("running", "degraded"),
f"systemd did not reach running/degraded state (observed: {systemd_status})", f"systemd did not reach running/degraded state (observed: {systemd_status})",
) )
sys_check_match = re.search(r"SYS_CLI_CHECK:(.*)", checks_text)
sys_status = sys_check_match.group(1).strip() if sys_check_match else "unknown"
self.results.assert_true( self.results.assert_true(
"boot-sys-installed", "boot-sys-installed",
"no transactions recorded" in sys_status, "SYS_CLI_RC:0" in checks_text,
f"sys CLI check: {sys_status}", "sys history --legacy did not complete",
) )
self.shot("boot-desktop", "booted desktop", "boot", "graphical desktop or login screen") self.shot("boot-desktop", "booted desktop", "boot", "graphical desktop or login screen")
if desktop:
self.verify_installed_desktop()
try: try:
self.shell("sync; echo phoebus-user-test | sudo -S systemctl poweroff >/dev/null 2>&1 || true; echo POW", self.child.sendline("sudo -v; echo SUDO-$(printf DONE)")
"POW", timeout=30, label="boot-poweroff") idx = self.child.expect([r"[Pp]assword(?: for [^:]+)?:", "SUDO-DONE"], timeout=30)
self.child.expect(pexpect.EOF, timeout=60) if idx == 0:
except (pexpect.TIMEOUT, pexpect.EOF, Exception): self.child.sendline(USER_PW)
pass self.child.expect("SUDO-DONE", timeout=30)
self.child.sendline("sudo -n systemctl poweroff")
self.child.expect(pexpect.EOF, timeout=120)
self.results.pass_("boot-clean-poweroff")
except (pexpect.TIMEOUT, pexpect.EOF) as exc:
self.results.fail("boot-clean-poweroff", str(exc))
def main() -> int: def main() -> int:
mode = sys.argv[1] if len(sys.argv) > 1 else "" mode = sys.argv[1] if len(sys.argv) > 1 else ""
if mode not in ("gui", "opencode", "gui-install", "install", "boot"): if mode not in ("gui", "opencode", "gui-install", "install", "boot", "desktop"):
print(__doc__) print(__doc__)
return 2 return 2
if mode in ("install", "boot", "gui-install") and not DISKS: if mode in ("install", "boot", "desktop", "gui-install") and not DISKS:
print("error: DISK/DISKS must name a disposable qcow2 image", file=sys.stderr) print("error: DISK/DISKS must name a disposable qcow2 image", file=sys.stderr)
return 2 return 2
try: try:

View file

@ -1,14 +1,15 @@
#!/bin/bash #!/bin/bash
# Guest-side automation for a disposable VM installation. # Guest-side automation for a disposable VM installation.
# #
# Run inside the Gentoo live environment. It fetches the static Rust installer # Run inside the Phoebus live environment. It executes the static Rust
# and a test configuration from a host HTTP server (QEMU user networking # installer and sys embedded in the candidate ISO, fetches only a test
# reaches the host at 10.0.2.2), supplies secrets from 0600 files, and drives # configuration and verified stage3 from the host HTTP server (QEMU user
# the deterministic backend with --install. It never uses the TUI. # networking reaches the host at 10.0.2.2), supplies secrets from 0600 files,
# and drives the deterministic backend with --install. It never uses the TUI.
# #
# Environment: # Environment:
# PHOEBUS_BASE_URL host base URL (default http://10.0.2.2:8000) # PHOEBUS_BASE_URL host base URL (default http://10.0.2.2:8000)
# PHOEBUS_CONFIG config file name on the server (default test.conf) # PHOEBUS_CONFIG config file name on the server (default test-mango.conf)
# LUKS_PASSPHRASE LUKS passphrase (kept in a 0600 temp file, never logged) # LUKS_PASSPHRASE LUKS passphrase (kept in a 0600 temp file, never logged)
# USER_PASSWORD user password # USER_PASSWORD user password
# #
@ -20,7 +21,7 @@ export PATH=/usr/sbin:/usr/bin:/sbin:/bin
export PHOEBUS_LOG_ECHO=yes export PHOEBUS_LOG_ECHO=yes
BASE="${PHOEBUS_BASE_URL:-http://10.0.2.2:8000}" BASE="${PHOEBUS_BASE_URL:-http://10.0.2.2:8000}"
CONF="${PHOEBUS_CONFIG:-test.conf}" CONF="${PHOEBUS_CONFIG:-test-mango.conf}"
echo "===PHOEBUS-DRIVER-START===" echo "===PHOEBUS-DRIVER-START==="
umask 077 umask 077
@ -29,25 +30,21 @@ printf '%s' "${USER_PASSWORD:-phoebus-user-test}" >/tmp/user.pw
chmod 600 /tmp/luks.pw /tmp/user.pw chmod 600 /tmp/luks.pw /tmp/user.pw
cd /tmp || exit 1 cd /tmp || exit 1
if ! curl -fsSL "$BASE/phoebus-installer" -o /tmp/phoebus-installer; then PHOEBUS=/usr/local/bin/phoebus-installer
echo "===FETCH-FAIL==="; poweroff -f; exit 1 SYS=/usr/local/bin/sys
if [ ! -x "$PHOEBUS" ] || [ ! -x "$SYS" ]; then
echo "===ISO-PAYLOAD-MISSING==="; poweroff -f; exit 1
fi fi
chmod 0755 /tmp/phoebus-installer echo "===ISO-INSTALLER-SHA256=$(sha256sum "$PHOEBUS" | cut -d' ' -f1)==="
# The deterministic `sys` CLI is a hard requirement of the installed system, so
# the installer locates it beside itself and installs it into the target.
if ! curl -fsSL "$BASE/sys" -o /tmp/sys; then
echo "===SYS-FETCH-FAIL==="; poweroff -f; exit 1
fi
chmod 0755 /tmp/sys
curl -fsSL "$BASE/$CONF" -o /tmp/test.conf curl -fsSL "$BASE/$CONF" -o /tmp/test.conf
echo "=== INSTALLER VERSION ===" echo "=== INSTALLER VERSION ==="
/tmp/phoebus-installer --version "$PHOEBUS" --version
echo "=== DISKS BEFORE ===" echo "=== DISKS BEFORE ==="
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS
/tmp/phoebus-installer --config /tmp/test.conf --install --yes --no-ai \ "$PHOEBUS" --config /tmp/test.conf --install --yes --no-ai \
--luks-passphrase-file /tmp/luks.pw --user-password-file /tmp/user.pw --luks-passphrase-file /tmp/luks.pw --user-password-file /tmp/user.pw
rc=$? rc=$?
echo "===INSTALL-RC=$rc===" echo "===INSTALL-RC=$rc==="

View file

@ -0,0 +1,78 @@
#!/bin/bash
# Disposable-VM acceptance: kill a real sys package transaction during emerge,
# recover its stale mutation lock, undo the pre-update snapshot, and reboot.
set -uo pipefail
if [[ $(id -u) != 0 ]]; then
echo '===INTERRUPT-NEEDS-ROOT==='
exit 1
fi
SYS=/usr/local/bin/sys
WORK=/var/tmp/phoebus-interrupted-update
mkdir -p "$WORK"
if [[ ! -x "$SYS" ]] || compgen -G '/var/db/pkg/app-misc/hello-*' >/dev/null; then
echo '===INTERRUPT-PRECONDITION-FAILED==='
exit 1
fi
pkg_fingerprint() {
find /var/db/pkg -mindepth 2 -maxdepth 2 -type d 2>/dev/null |
sort | sha256sum | awk '{print $1}'
}
before=$(pkg_fingerprint)
marker="interrupted-update-$(date +%s)-$$"
printf '%s\n' "$marker" > /home/phoebus/interrupted-update-marker.txt
echo "===INTERRUPT-BEFORE pkgs=$before home=$marker==="
"$SYS" -y snapshot 'interrupted update acceptance' --legacy > "$WORK/snapshot.log" 2>&1
snapshot=$(sed -n 's/^protective snapshot: //p' "$WORK/snapshot.log" | tail -1)
if [[ -z $snapshot ]]; then
echo '===INTERRUPT-SNAPSHOT-FAILED==='
exit 1
fi
echo "===INTERRUPT-SNAPSHOT id=$snapshot==="
# `setsid` keeps the whole sys/emerge process tree in a private process group,
# so SIGKILL cannot hit the driver shell. Follow that group until the mutating
# `emerge --ask=n` process exists; CLI output may be buffered until it exits,
# and a small package can finish before a log-based poll sees it.
setsid "$SYS" -y install app-misc/hello --legacy --portage > "$WORK/install.log" 2>&1 &
leader=$!
started=0
for _ in $(seq 1 2400); do
if ! kill -0 "$leader" 2>/dev/null; then
break
fi
if ps -eo pgid=,args= | awk -v group="$leader" \
'$1 == group && /emerge/ && /--ask=n/ { found = 1 } END { exit !found }'; then
started=1
break
fi
sleep 0.05
done
if [[ $started != 1 ]] || ! kill -0 "$leader" 2>/dev/null; then
wait "$leader" 2>/dev/null || true
echo '===INTERRUPT-NO-ACTIVE-UPDATE==='
sed -n '1,25p' "$WORK/install.log"
exit 1
fi
kill -KILL -- -"$leader"
wait "$leader" 2>/dev/null || true
echo '===INTERRUPT-SIGKILL-DURING-EMERGE==='
# The killed sys owner must not leave a permanent lock. A deterministic read
# and undo must still work without a model or a network connection.
"$SYS" history --legacy > "$WORK/history.log" 2>&1
history_rc=$?
"$SYS" -y undo "$snapshot" --legacy > "$WORK/undo.log" 2>&1
undo_rc=$?
echo "===INTERRUPT-RECOVERY history_rc=$history_rc undo_rc=$undo_rc==="
if [[ $history_rc != 0 || $undo_rc != 0 ]]; then
sed -n '1,25p' "$WORK/undo.log"
exit 1
fi
sync
echo '===INTERRUPT-POWEROFF==='
poweroff -f

View file

@ -7,11 +7,19 @@ Modes:
Phoebus non-interactively, then power off. Phoebus non-interactively, then power off.
boot : boot the installed disk alone (no ISO, no -kernel), unlock LUKS, boot : boot the installed disk alone (no ISO, no -kernel), unlock LUKS,
log in and run verification commands. log in and run verification commands.
boot-assessed: detached boot plus the boot-complete health gate and mark-good.
rollback: boot an installed disk, record a known-good state, create a rollback: boot an installed disk, record a known-good state, create a
recovery point through `sys snapshot`, introduce a reversible recovery point through `sys snapshot`, introduce a reversible
update, run the real `sys undo`, power off and boot detached to update, run the real `sys undo`, power off and boot detached to
verify the restored root/var and package state. Destructive: point verify the restored root/var and package state. Destructive: point
DISK at a disposable clone, never a physical device. DISK at a disposable clone, never a physical device.
recovery: select the snapshot recovery BLS entry for the next boot, then
boot it with no network and verify the mounted snapshot and sys.
fallback: on a qcow2 overlay, force three incomplete normal boots and
verify automatic selection of the recovery snapshot on attempt 4.
interrupted-update: kill a real sys/emerge transaction on an overlay, undo
its pre-update snapshot, and verify package state after reboot.
install-repeat: independent install to DISK_SECOND from the same ISO.
Everything is parameterised through environment variables so the script is not Everything is parameterised through environment variables so the script is not
tied to one host. See tests/vm/README.md for the variables. tied to one host. See tests/vm/README.md for the variables.
@ -23,7 +31,10 @@ Results are structured and the exit status is nonzero on failure.
""" """
import os import os
import re import re
import shlex
import subprocess
import sys import sys
import time
import pexpect import pexpect
@ -42,6 +53,8 @@ INITRD = os.environ.get("INITRD", "")
LUKS_PW = os.environ.get("LUKS_PASSPHRASE", "phoebus-luks-test") LUKS_PW = os.environ.get("LUKS_PASSPHRASE", "phoebus-luks-test")
USER_PW = os.environ.get("USER_PASSWORD", "phoebus-user-test") USER_PW = os.environ.get("USER_PASSWORD", "phoebus-user-test")
USER = os.environ.get("USERNAME", "phoebus") USER = os.environ.get("USERNAME", "phoebus")
LIVE_USER = os.environ.get("LIVE_USER", "phoebus")
LIVE_PW = os.environ.get("LIVE_PASSWORD", "phoebus")
MEM = os.environ.get("VM_MEM", "8192") MEM = os.environ.get("VM_MEM", "8192")
SMP = os.environ.get("VM_SMP", "8") SMP = os.environ.get("VM_SMP", "8")
@ -51,16 +64,18 @@ SMP = os.environ.get("VM_SMP", "8")
# (not `❯ `) is matched. Bash/root prompts keep matching `[$#] `. # (not `❯ `) is matched. Bash/root prompts keep matching `[$#] `.
SHELL_PROMPT = r"[$#] |❯" SHELL_PROMPT = r"[$#] |❯"
BLS_APPEND = ( # The ISO is a Debian live medium. Its GRUB entry uses live-boot, so the
"root=live:CDLABEL=gentoo-amd64-livegui rd.live.dir=/ " # direct-kernel serial path must pass the same root-discovery arguments.
"rd.live.squashimg=image.squashfs cdroot console=ttyS0,115200" BLS_APPEND = "boot=live components console=ttyS0,115200 noautologin"
)
# Rollback acceptance fixtures, served from the host over QEMU user networking. # Rollback acceptance fixtures, served from the host over QEMU user networking.
ROLLBACK_URL = os.environ.get("ROLLBACK_URL", "http://10.0.2.2:8000/rollback-guest.sh") ROLLBACK_URL = os.environ.get("ROLLBACK_URL", "http://10.0.2.2:8000/rollback-guest.sh")
ROLLBACK_VERIFY_URL = os.environ.get( ROLLBACK_VERIFY_URL = os.environ.get(
"ROLLBACK_VERIFY_URL", "http://10.0.2.2:8000/rollback-verify.sh" "ROLLBACK_VERIFY_URL", "http://10.0.2.2:8000/rollback-verify.sh"
) )
INTERRUPT_URL = os.environ.get(
"INTERRUPT_URL", "http://10.0.2.2:8000/interrupted-update.sh"
)
SYS_URL = os.environ.get("SYS_URL", "http://10.0.2.2:8000/sys") SYS_URL = os.environ.get("SYS_URL", "http://10.0.2.2:8000/sys")
@ -71,7 +86,7 @@ def disposable_dir():
return pathlib.Path(os.environ.get("PHOEBUS_VM_DISKS", base + "/disks")) return pathlib.Path(os.environ.get("PHOEBUS_VM_DISKS", base + "/disks"))
def base_args(ovmf_vars): def base_args(ovmf_vars, network=True):
env = dict(os.environ) env = dict(os.environ)
if LIBDIR: if LIBDIR:
env["LD_LIBRARY_PATH"] = LIBDIR env["LD_LIBRARY_PATH"] = LIBDIR
@ -82,10 +97,11 @@ def base_args(ovmf_vars):
"-cpu", "host", "-smp", SMP, "-m", MEM, "-cpu", "host", "-smp", SMP, "-m", MEM,
"-drive", f"if=pflash,format=raw,readonly=on,file={OVMF_CODE}", "-drive", f"if=pflash,format=raw,readonly=on,file={OVMF_CODE}",
"-drive", f"if=pflash,format=raw,file={ovmf_vars}", "-drive", f"if=pflash,format=raw,file={ovmf_vars}",
"-netdev", "user,id=n0", "-device", "virtio-net-pci,netdev=n0,romfile=",
"-device", "virtio-rng-pci", "-vga", "std", "-display", "none", "-device", "virtio-rng-pci", "-vga", "std", "-display", "none",
"-serial", "stdio", "-monitor", "none", "-no-reboot", "-serial", "stdio", "-monitor", "none", "-no-reboot",
] ]
if network:
args += ["-netdev", "user,id=n0", "-device", "virtio-net-pci,netdev=n0,romfile="]
return env, args return env, args
@ -94,9 +110,13 @@ def spawn(args, env, log):
encoding="utf-8", codec_errors="replace", encoding="utf-8", codec_errors="replace",
maxread=65536) maxread=65536)
child.delaybeforesend = 0.3 child.delaybeforesend = 0.3
# Log only guest output. The general logfile also records bytes sent by # Log only guest output, and redact credentials if a login race makes a
# pexpect, including LUKS, login and sudo passwords. # password reach an echoing shell instead of a no-echo password prompt.
child.logfile_read = log child.logfile_read = vmsafety.RedactingTextLog(
log,
[LUKS_PW, USER_PW, LIVE_PW,
os.environ.get("OPENAI_API_KEY"), os.environ.get("DEEPSEEK_API_KEY")],
)
return child return child
@ -104,13 +124,20 @@ def close_quietly(child):
"""Best-effort teardown. After the guest powers off, pexpect can raise """Best-effort teardown. After the guest powers off, pexpect can raise
`ExceptionPexpect: Could not terminate the child`; that must not turn a `ExceptionPexpect: Could not terminate the child`; that must not turn a
successful run into a nonzero driver exit.""" successful run into a nonzero driver exit."""
redactor = child.logfile_read
try: try:
child.close(force=True) child.close(force=True)
except Exception: # noqa: BLE001 - cleanup must never mask the result except Exception: # noqa: BLE001 - cleanup must never mask the result
pass pass
if isinstance(redactor, vmsafety.RedactingTextLog):
redactor.finish()
def do_install(results, paths, disks): def do_install(results, paths, disks):
config_name = os.environ.get("VM_INSTALL_CONFIG", "test-mango.conf")
if not re.fullmatch(r"[A-Za-z0-9][A-Za-z0-9_.-]*", config_name):
results.blocked("install-config", "VM_INSTALL_CONFIG must be a safe file name")
return
env, args = base_args(str(paths.ovmf_vars)) env, args = base_args(str(paths.ovmf_vars))
for disk in disks: for disk in disks:
args += ["-drive", f"file={disk},if=virtio,format=qcow2"] args += ["-drive", f"file={disk},if=virtio,format=qcow2"]
@ -119,10 +146,27 @@ def do_install(results, paths, disks):
log = open(paths.serial_log, "w") log = open(paths.serial_log, "w")
child = spawn(args, env, log) child = spawn(args, env, log)
try: try:
child.expect(r"root@livecd[^\n]*# ", timeout=600) idx = child.expect([r"root@livecd[^\n]*# ", r"(?m)^[^\r\n]* login:"], timeout=600)
results.pass_("live-shell") if idx == 1:
child.sendline(LIVE_USER)
child.expect(r"[Pp]assword:", timeout=90)
child.sendline(LIVE_PW)
child.expect(r"[$#] ", timeout=180)
child.sendline("sudo -v; echo SUDO-$(printf READY)")
choice = child.expect([r"[Pp]assword(?: for [^:]+)?:", "SUDO-READY"], timeout=60)
if choice == 0:
child.sendline(LIVE_PW)
child.expect("SUDO-READY", timeout=60)
child.sendline("sudo -n true && echo ROOT-$(printf READY)")
child.expect("ROOT-READY", timeout=30)
results.pass_("live-shell", "authenticated live user with sudo")
else:
results.pass_("live-shell", "root live shell")
url = os.environ.get("INSTALL_URL", "http://10.0.2.2:8000/install.sh") url = os.environ.get("INSTALL_URL", "http://10.0.2.2:8000/install.sh")
child.sendline(f"curl -fsSL {url} -o /tmp/run.sh && bash /tmp/run.sh") command = f"curl -fsSL {shlex.quote(url)} -o /tmp/run.sh && "
run = f"env PHOEBUS_CONFIG={shlex.quote(config_name)} bash /tmp/run.sh"
command += f"sudo -n {run}" if idx == 1 else run
child.sendline(command)
child.expect([r"===INSTALL-RC=([0-9]+)===", "===FETCH-FAIL===", child.expect([r"===INSTALL-RC=([0-9]+)===", "===FETCH-FAIL===",
"Kernel panic", pexpect.EOF, pexpect.TIMEOUT], timeout=19800) "Kernel panic", pexpect.EOF, pexpect.TIMEOUT], timeout=19800)
# `child.after` is the matched pattern class (not a string) when EOF or # `child.after` is the matched pattern class (not a string) when EOF or
@ -139,7 +183,11 @@ def do_install(results, paths, disks):
serial = paths.serial_log.read_text(errors="replace") serial = paths.serial_log.read_text(errors="replace")
results.assert_true("no-secret-leak", "SECRET_LEAK_FOUND" not in serial, results.assert_true("no-secret-leak", "SECRET_LEAK_FOUND" not in serial,
"the guest reported a secret leak") "the guest reported a secret leak")
child.expect(["===POWEROFF===", pexpect.EOF, pexpect.TIMEOUT], timeout=600) shutdown = child.expect(["===POWEROFF===", pexpect.EOF, pexpect.TIMEOUT], timeout=600)
if shutdown == 0:
child.expect(pexpect.EOF, timeout=180)
results.assert_true("guest-poweroff", shutdown != 2,
"installer returned but the live guest did not power off")
except pexpect.TIMEOUT as exc: except pexpect.TIMEOUT as exc:
results.fail("install", f"timeout: {exc}") results.fail("install", f"timeout: {exc}")
except pexpect.EOF: except pexpect.EOF:
@ -149,15 +197,15 @@ def do_install(results, paths, disks):
log.close() log.close()
def _installed_args(paths, disks): def _installed_args(paths, disks, network=True):
env, args = base_args(str(paths.ovmf_vars)) env, args = base_args(str(paths.ovmf_vars), network=network)
for disk in disks: for disk in disks:
args += ["-drive", f"file={disk},if=virtio,format=qcow2"] args += ["-drive", f"file={disk},if=virtio,format=qcow2"]
args += ["-boot", "order=c"] args += ["-boot", "order=c"]
return env, args return env, args
def _unlock_and_login(child, results, tag): def _unlock_and_login(child, results, tag, continue_locked_root=False):
child.expect([r"[Pp]assphrase", r"login:"], timeout=300) child.expect([r"[Pp]assphrase", r"login:"], timeout=300)
if "assphrase" in (child.after or ""): if "assphrase" in (child.after or ""):
override = os.environ.get("BOOT_PASSPHRASE") override = os.environ.get("BOOT_PASSPHRASE")
@ -169,9 +217,29 @@ def _unlock_and_login(child, results, tag):
child.sendline(candidate) child.sendline(candidate)
except (pexpect.TIMEOUT, pexpect.EOF): except (pexpect.TIMEOUT, pexpect.EOF):
break break
login_ready = False
if continue_locked_root:
# The default root account is locked. rescue.target's sulogin prints
# this instruction; Enter continues to the ordinary user getty on
# the read-only recovery snapshot.
outcome = child.expect([r"Press Enter to continue", r"phoebus login:"], timeout=300)
if outcome == 0:
child.sendline("")
# rescue.target hands control back to default.target. The serial
# getty can restart a few times during that transition; wait for
# the final login prompt before sending credentials.
time.sleep(5)
else:
login_ready = True
logged_in = False logged_in = False
for _ in range(5): for _ in range(5):
if not login_ready:
child.expect(r"phoebus login:", timeout=180) child.expect(r"phoebus login:", timeout=180)
login_ready = False
# During boot and the rescue-to-default transition, systemd may
# restart serial-getty several times. Credentials sent to an early
# prompt vanish when that agetty exits; let the final prompt settle.
time.sleep(5)
child.sendline(USER) child.sendline(USER)
idx = child.expect([r"[Pp]assword:", r"phoebus login:", r"Login incorrect"], idx = child.expect([r"[Pp]assword:", r"phoebus login:", r"Login incorrect"],
timeout=30) timeout=30)
@ -274,6 +342,7 @@ def do_rollback(results, paths, disks):
close_quietly(child) close_quietly(child)
log.close() log.close()
before = _parse_marker(phase1, "ROLLBACK-KNOWN-GOOD") before = _parse_marker(phase1, "ROLLBACK-KNOWN-GOOD")
broken = _parse_marker(phase1, "ROLLBACK-BROKEN") broken = _parse_marker(phase1, "ROLLBACK-BROKEN")
undo = _parse_marker(phase1, "ROLLBACK-UNDO") undo = _parse_marker(phase1, "ROLLBACK-UNDO")
@ -347,7 +416,269 @@ def do_rollback(results, paths, disks):
log.close() log.close()
def do_boot(results, paths, disks): def do_recovery(results, paths, disks):
"""Select the actual boot menu entry, then prove its snapshot offline."""
env, args = _installed_args(paths, disks, network=False)
args += ["-qmp", f"unix:{paths.monitor_sock},server,nowait"]
log = open(paths.serial_log, "w")
child = spawn(args, env, log)
try:
child.expect(r"Phoebus Recovery \(known-good snapshot\)", timeout=60)
# The first key freezes systemd-boot's short timeout; the second moves
# from the normal entry to recovery. QMP drives the video keyboard,
# while the LUKS passphrase still goes to the serial console.
with vmsafety.QmpClient(paths.monitor_sock) as qmp:
qmp.sendkey("spc")
qmp.sendkey("down")
qmp.sendkey("ret")
results.pass_("recovery-entry-selected")
_unlock_and_login(child, results, "recovery-offline", continue_locked_root=True)
child.sendline(
"setopt NO_EQUALS 2>/dev/null; "
"echo ===RECOVERY-$(printf START)===; "
"echo CMDLINE:$(cat /proc/cmdline); "
"echo ROOT_SOURCE:$(findmnt -no SOURCE /); "
"echo ROOT_OPTIONS:$(findmnt -no OPTIONS /); "
"echo ROOT_PROPERTY:$(btrfs property get / ro 2>&1); "
"sys history --legacy >/tmp/phoebus-recovery-history 2>&1; "
"echo SYS_HISTORY_RC:$?; "
"sys rollback status --legacy >/tmp/phoebus-recovery-status 2>&1; "
"echo SYS_ROLLBACK_RC:$?; "
"echo ===RECOVERY-$(printf END)==="
)
child.expect("===RECOVERY-END===", timeout=180)
observed_output = child.before + "===RECOVERY-END==="
match = re.search(r"===RECOVERY-START===(.*?)===RECOVERY-END===",
observed_output, re.DOTALL)
observed = match.group(1) if match else ""
results.assert_true(
"recovery-snapshot-selected",
"rootflags=subvol=@snapshots/" in observed
and "systemd.unit=rescue.target" in observed,
"recovery kernel command line did not select the snapshot",
)
results.assert_true(
"recovery-snapshot-mounted",
"ROOT_SOURCE:/dev/mapper/cryptroot[/@snapshots/" in observed
and "ro=true" in observed,
"root is not the read-only recovery subvolume",
)
results.assert_true(
"recovery-sys-offline",
"SYS_HISTORY_RC:0" in observed and "SYS_ROLLBACK_RC:0" in observed,
"deterministic sys commands did not work offline",
)
except (pexpect.TIMEOUT, pexpect.EOF) as exc:
results.fail("recovery-offline", str(exc))
finally:
close_quietly(child)
log.close()
def _gate_overlay(results, paths, disks, tag):
"""Create a writable disposable overlay without changing the install disk."""
if len(disks) != 1:
results.blocked(f"{tag}-disk", f"{tag} needs exactly one installed qcow2")
return None
overlay = disposable_dir() / f"{tag}-{paths.run_id}.qcow2"
create = subprocess.run(
["qemu-img", "create", "-f", "qcow2", "-F", "qcow2", "-b",
str(disks[0].resolve()), str(overlay)],
capture_output=True, text=True, check=False,
)
if create.returncode != 0:
results.fail(f"{tag}-overlay", create.stderr.strip() or "qemu-img create failed")
return None
try:
test_disks = vmsafety.validate_writable_drives([str(overlay)], disposable_dir())
except vmsafety.UnsafeDiskError as exc:
results.fail(f"{tag}-overlay", str(exc))
return None
results.pass_(f"{tag}-overlay", str(overlay))
return test_disks
def do_fallback(results, paths, disks):
"""Prove that exhausted normal boot attempts select recovery by default."""
test_disks = _gate_overlay(results, paths, disks, "fallback")
if test_disks is None:
return
# Prepare the overlay from a healthy boot. The next three boots stop at
# rescue.target's locked-root prompt and QEMU is terminated there. Pressing
# Enter would continue to default.target, which can bless the boot and
# clear the counter; a hard stop models the failed boot we need to test.
env, args = _installed_args(paths, test_disks, network=False)
with open(paths.directory / "serial-prepare.log", "w") as log:
child = spawn(args, env, log)
try:
_unlock_and_login(child, results, "fallback-prepare")
if not _sudo_auth(child, results, "fallback-prepare"):
return
child.sendline(
"entry=$(sudo -n find /efi/loader/entries -maxdepth 1 -type f -name '*.conf' "
"! -name '*recovery*' | sort | head -1); "
"test -n \"$entry\" && "
"test \"$(sudo -n awk '$1 == \"default\" {print $2}' /efi/loader/loader.conf)\" = '*' "
"&& sudo -n grep -Eq '^sort-key[[:space:]]+phoebus$' \"$entry\" && "
"sudo -n sed -i "
"'/^options[[:space:]]/ s/$/ systemd.unit=rescue.target/' \"$entry\" && "
"base=${entry%.conf}; base=${base%%+*}; "
"sudo -n mv \"$entry\" \"${base}+3.conf\" && "
"echo FALLBACK-$(printf PREPARED)"
)
child.expect("FALLBACK-PREPARED", timeout=60)
child.sendline("sudo -n systemctl poweroff")
child.expect(pexpect.EOF, timeout=120)
results.pass_("fallback-prepared")
except (pexpect.TIMEOUT, pexpect.EOF) as exc:
results.fail("fallback-prepare", str(exc))
return
finally:
close_quietly(child)
for attempt in range(1, 4):
env, args = _installed_args(paths, test_disks, network=False)
log_path = paths.directory / f"serial-attempt-{attempt}.log"
with open(log_path, "w") as log:
child = spawn(args, env, log)
try:
child.expect(r"[Pp]assphrase", timeout=300)
child.sendline(LUKS_PW)
child.expect("Press Enter to continue", timeout=300)
results.pass_(f"fallback-attempt-{attempt}-failed-boot")
except (pexpect.TIMEOUT, pexpect.EOF) as exc:
results.fail(f"fallback-attempt-{attempt}", str(exc))
return
finally:
close_quietly(child)
# QEMU can release the qcow2 write lock shortly after pexpect closes
# its PTY. Give the next boot a brief teardown window.
time.sleep(3)
env, args = _installed_args(paths, test_disks, network=False)
with open(paths.serial_log, "w") as log:
child = spawn(args, env, log)
try:
_unlock_and_login(child, results, "fallback-recovery",
continue_locked_root=True)
if not _sudo_auth(child, results, "fallback-recovery"):
return
child.sendline(
"setopt NO_EQUALS 2>/dev/null; echo ===FALLBACK-$(printf START)===; "
"cat /proc/cmdline; sudo -n ls -1 /efi/loader/entries; "
"echo ===FALLBACK-$(printf END)==="
)
child.expect("===FALLBACK-END===", timeout=60)
observed_output = child.before + "===FALLBACK-END==="
match = re.search(r"===FALLBACK-START===(.*?)===FALLBACK-END===",
observed_output, re.DOTALL)
observed = match.group(1) if match else ""
correct = ("rootflags=subvol=@snapshots/" in observed
and "systemd.unit=rescue.target" in observed
and re.search(r"\+0-3\.conf", observed) is not None)
results.assert_true("fallback-boot-4", correct,
f"recovery was not selected after three failures: {observed.strip()}")
if not correct:
return
child.sendline("sudo -n systemctl poweroff")
child.expect(pexpect.EOF, timeout=120)
except (pexpect.TIMEOUT, pexpect.EOF) as exc:
results.fail("fallback-recovery", str(exc))
finally:
close_quietly(child)
def do_interrupted_update(results, paths, disks):
"""Kill an in-flight package install, undo its snapshot, and reboot."""
test_disks = _gate_overlay(results, paths, disks, "interrupted-update")
if test_disks is None:
return
env, args = _installed_args(paths, test_disks)
phase1_log = paths.directory / "serial-interrupted-phase1.log"
with open(phase1_log, "w") as log:
child = spawn(args, env, log)
try:
_unlock_and_login(child, results, "interrupted-before")
if not _sudo_auth(child, results, "interrupted-before"):
return
child.sendline(
f"curl -fsSL {INTERRUPT_URL} -o /tmp/interrupted-update.sh "
"&& sudo -n bash /tmp/interrupted-update.sh"
)
outcome = child.expect(
["===INTERRUPT-POWEROFF===", "===INTERRUPT-NEEDS-ROOT===",
"===INTERRUPT-PRECONDITION-FAILED===", "===INTERRUPT-SNAPSHOT-FAILED===",
"===INTERRUPT-NO-ACTIVE-UPDATE===", "curl:", pexpect.EOF],
timeout=1800,
)
if outcome != 0:
results.fail("interrupted-update-phase1",
f"guest stopped before recovery: {child.after!r}")
return
child.expect(pexpect.EOF, timeout=120)
log.flush()
phase1 = phase1_log.read_text(errors="replace")
before = _parse_marker(phase1, "INTERRUPT-BEFORE")
recovery = _parse_marker(phase1, "INTERRUPT-RECOVERY")
results.assert_true("interrupted-update-killed",
"===INTERRUPT-SIGKILL-DURING-EMERGE===" in phase1,
"the update process was not killed during emerge")
results.assert_true("interrupted-update-undone",
recovery is not None and recovery.get("history_rc") == "0"
and recovery.get("undo_rc") == "0",
"sys did not recover its lock and undo the snapshot")
if before is None or recovery is None or recovery.get("undo_rc") != "0":
return
except (pexpect.TIMEOUT, pexpect.EOF) as exc:
results.fail("interrupted-update-phase1", str(exc))
return
finally:
close_quietly(child)
env, args = _installed_args(paths, test_disks, network=False)
with open(paths.serial_log, "w") as log:
child = spawn(args, env, log)
try:
_unlock_and_login(child, results, "interrupted-after")
child.sendline(
"setopt NO_EQUALS 2>/dev/null; echo ===INTERRUPT-$(printf VERIFY-START)===; "
"echo SYSTEMD:$(systemctl is-system-running); "
"echo PKGS:$(find /var/db/pkg -mindepth 2 -maxdepth 2 -type d 2>/dev/null "
"| sort | sha256sum | awk '{print $1}'); "
"echo HOME:$(cat /home/phoebus/interrupted-update-marker.txt); "
"echo HELLO:$(find /var/db/pkg/app-misc -maxdepth 1 -name 'hello-*' "
"-print -quit | grep -q . && echo yes || echo no); "
"sys history --legacy >/tmp/interrupted-history 2>&1; echo SYS_RC:$?; "
"echo ===INTERRUPT-$(printf VERIFY-END)==="
)
child.expect("===INTERRUPT-VERIFY-END===", timeout=120)
log.flush()
transcript = paths.serial_log.read_text(errors="replace")
match = re.search(r"===INTERRUPT-VERIFY-START===(.*?)===INTERRUPT-VERIFY-END===",
transcript, re.DOTALL)
observed = match.group(1) if match else ""
results.assert_true("interrupted-update-boot",
"SYSTEMD:running" in observed or "SYSTEMD:degraded" in observed,
"the restored system did not boot")
results.assert_true("interrupted-update-package-state",
f"PKGS:{before['pkgs']}" in observed and "HELLO:no" in observed,
"package database did not match the pre-update snapshot")
results.assert_true("interrupted-update-home",
f"HOME:{before['home']}" in observed,
"the user home marker was not preserved")
results.assert_true("interrupted-update-sys", "SYS_RC:0" in observed,
"deterministic sys failed after the interrupted update")
if _sudo_auth(child, results, "interrupted-after"):
child.sendline("sudo -n systemctl poweroff")
child.expect(pexpect.EOF, timeout=120)
except (pexpect.TIMEOUT, pexpect.EOF) as exc:
results.fail("interrupted-update-phase2", str(exc))
finally:
close_quietly(child)
def do_boot(results, paths, disks, assessment=False):
env, args = base_args(str(paths.ovmf_vars)) env, args = base_args(str(paths.ovmf_vars))
for disk in disks: for disk in disks:
args += ["-drive", f"file={disk},if=virtio,format=qcow2"] args += ["-drive", f"file={disk},if=virtio,format=qcow2"]
@ -375,11 +706,20 @@ def do_boot(results, paths, disks):
login_ready = first_prompt == 1 login_ready = first_prompt == 1
if first_prompt == 0: if first_prompt == 0:
child.sendline(LUKS_PW) child.sendline(LUKS_PW)
next_prompt = child.expect(
[r"phoebus login:", r"Press Enter to continue"], timeout=300
)
if next_prompt == 0:
login_ready = True
else:
child.sendline("")
time.sleep(5)
logged_in = False logged_in = False
for _ in range(5): for _ in range(5):
if not login_ready: if not login_ready:
child.expect(r"phoebus login:", timeout=180) child.expect(r"phoebus login:", timeout=180)
login_ready = False login_ready = False
time.sleep(5)
child.sendline(USER) child.sendline(USER)
idx = child.expect([r"[Pp]assword:", r"phoebus login:", idx = child.expect([r"[Pp]assword:", r"phoebus login:",
r"Login incorrect"], timeout=30) r"Login incorrect"], timeout=30)
@ -395,16 +735,16 @@ def do_boot(results, paths, disks):
login_ready = idx == 1 login_ready = idx == 1
results.assert_true("detached-boot-login", logged_in, "could not log in") results.assert_true("detached-boot-login", logged_in, "could not log in")
if os.environ.get("BOOT_AUTHENTICATE") == "1": if os.environ.get("BOOT_AUTHENTICATE") == "1":
child.sendline("sudo -v") if not _sudo_auth(child, results, "boot"):
idx = child.expect([r"[Pp]assword(?: for [^:]+)?:", SHELL_PROMPT], timeout=30) return
if idx == 0:
child.sendline(USER_PW)
child.expect(SHELL_PROMPT, timeout=30)
child.sendline(checks) child.sendline(checks)
child.expect("===CHECKS-END===", timeout=int(os.environ.get("CHECKS_TIMEOUT", "180"))) child.expect("===CHECKS-END===", timeout=int(os.environ.get("CHECKS_TIMEOUT", "180")))
serial = paths.serial_log.read_text(errors="replace") # pexpect can match the end marker before the redacting log sink has
checks_match = re.search(r"===CHECKS-START===(.*?)===CHECKS-END===", serial, re.DOTALL) # received its trailing newline. Parse the just-consumed output.
checks_text = checks_match.group(1) if checks_match else serial observed_checks = child.before + "===CHECKS-END==="
checks_match = re.search(r"===CHECKS-START===(.*?)===CHECKS-END===",
observed_checks, re.DOTALL)
checks_text = checks_match.group(1) if checks_match else observed_checks
m = re.search(r"SYSTEMD_STATUS:([a-z\-]+)", checks_text) m = re.search(r"SYSTEMD_STATUS:([a-z\-]+)", checks_text)
status = m.group(1) if m else "unknown" status = m.group(1) if m else "unknown"
@ -413,6 +753,35 @@ def do_boot(results, paths, disks):
status in ("running", "degraded"), status in ("running", "degraded"),
f"systemd did not report running/degraded (observed: {status})", f"systemd did not report running/degraded (observed: {status})",
) )
if assessment:
if not _sudo_auth(child, results, "assessment"):
return
child.sendline(
"setopt NO_EQUALS 2>/dev/null; "
"for i in $(seq 1 120); do "
"systemctl is-active --quiet systemd-bless-boot.service && break; "
"sleep 1; done; "
"echo ===ASSESS-$(printf START)===; "
"echo BLESS:$(systemctl is-active systemd-bless-boot.service); "
"echo CHECK:$(systemctl is-active systemd-boot-check-no-failures.service); "
"echo COMPLETE:$(systemctl is-active boot-complete.target); "
"echo COUNTED:$(sudo -n find /efi/loader/entries -maxdepth 1 "
"-name '*+*.conf' | wc -l); "
"sys history --legacy >/tmp/phoebus-assessed-history 2>&1; echo SYS_RC:$?; "
"echo ===ASSESS-$(printf END)==="
)
child.expect("===ASSESS-END===", timeout=180)
observed_assessment = child.before + "===ASSESS-END==="
match = re.search(r"===ASSESS-START===(.*?)===ASSESS-END===",
observed_assessment, re.DOTALL)
observed = match.group(1) if match else ""
results.assert_true(
"boot-assessment-confirmed",
all(marker in observed for marker in
("BLESS:active", "CHECK:active", "COMPLETE:active",
"COUNTED:0", "SYS_RC:0")),
f"boot health was not confirmed: {observed.strip()}",
)
for case in os.environ.get("BOOT_REQUIRE_CASES", "").split(","): for case in os.environ.get("BOOT_REQUIRE_CASES", "").split(","):
case = case.strip() case = case.strip()
if case: if case:
@ -421,7 +790,7 @@ def do_boot(results, paths, disks):
f"CASE {case} PASS" in checks_text, f"CASE {case} PASS" in checks_text,
f"{case} did not report PASS", f"{case} did not report PASS",
) )
if os.environ.get("BOOT_POWEROFF") == "1": if assessment or os.environ.get("BOOT_POWEROFF") == "1":
child.sendline("sudo systemctl poweroff") child.sendline("sudo systemctl poweroff")
idx = child.expect([r"[Pp]assword(?: for [^:]+)?:", pexpect.EOF], timeout=60) idx = child.expect([r"[Pp]assword(?: for [^:]+)?:", pexpect.EOF], timeout=60)
if idx == 0: if idx == 0:
@ -439,16 +808,33 @@ def do_boot(results, paths, disks):
def main() -> int: def main() -> int:
mode = sys.argv[1] if len(sys.argv) > 1 else "" mode = sys.argv[1] if len(sys.argv) > 1 else ""
if mode not in ("install", "boot", "rollback"): if mode not in ("install", "install-repeat", "boot", "boot-assessed", "rollback", "recovery",
"fallback", "interrupted-update"):
print(__doc__) print(__doc__)
return 2 return 2
results = Results(f"serial-{mode}")
paths = vmsafety.make_run_paths( paths = vmsafety.make_run_paths(
f"serial-{mode}", base=os.environ.get("PHOEBUS_VM_STATE", "/var/tmp/phoebus-vm"), f"serial-{mode}", base=os.environ.get("PHOEBUS_VM_STATE", "/var/tmp/phoebus-vm"),
ovmf_vars_template=OVMF_VARS_TEMPLATE, ovmf_vars_template=OVMF_VARS_TEMPLATE,
) )
results = Results(
f"serial-{mode}", run_id=paths.run_id,
secrets=[LUKS_PW, USER_PW, LIVE_PW,
os.environ.get("OPENAI_API_KEY"), os.environ.get("DEEPSEEK_API_KEY")],
)
selected_disks = DISKS
if mode == "install-repeat":
selected_disks = os.environ.get("DISK_SECOND", "")
if not selected_disks or selected_disks == DISKS:
results.blocked("independent-install-disk", "DISK_SECOND must name a separate disposable qcow2")
results.write(paths.results_json)
return 2
try: try:
disks = vmsafety.validate_writable_drives(DISKS.split(","), disposable_dir()) if mode == "install-repeat":
disks = vmsafety.validate_independent_disk_sets(
DISKS.split(","), selected_disks.split(","), disposable_dir()
)
else:
disks = vmsafety.validate_writable_drives(selected_disks.split(","), disposable_dir())
except vmsafety.UnsafeDiskError as exc: except vmsafety.UnsafeDiskError as exc:
results.blocked("disposable-disk", str(exc)) results.blocked("disposable-disk", str(exc))
results.write(paths.results_json) results.write(paths.results_json)
@ -456,10 +842,18 @@ def main() -> int:
return 2 return 2
results.pass_("disposable-disk", ", ".join(str(d) for d in disks)) results.pass_("disposable-disk", ", ".join(str(d) for d in disks))
try: try:
if mode == "install": if mode in ("install", "install-repeat"):
do_install(results, paths, disks) do_install(results, paths, disks)
elif mode == "rollback": elif mode == "rollback":
do_rollback(results, paths, disks) do_rollback(results, paths, disks)
elif mode == "recovery":
do_recovery(results, paths, disks)
elif mode == "fallback":
do_fallback(results, paths, disks)
elif mode == "interrupted-update":
do_interrupted_update(results, paths, disks)
elif mode == "boot-assessed":
do_boot(results, paths, disks, assessment=True)
else: else:
do_boot(results, paths, disks) do_boot(results, paths, disks)
finally: finally:

View file

@ -34,6 +34,7 @@ FEATURES_BINPKG='yes'
# none overrides it. Omitting the key selects mango. # none overrides it. Omitting the key selects mango.
DESKTOP_PROFILE='mango' DESKTOP_PROFILE='mango'
FLATPAK='yes' FLATPAK='yes'
NIX_ENABLED='yes'
# Pinned stage3 served from the host HTTP server so the SHA-256 is verified # Pinned stage3 served from the host HTTP server so the SHA-256 is verified
# without re-downloading from the internet. Replace with a real Gentoo URL for other setups. # without re-downloading from the internet. Replace with a real Gentoo URL for other setups.

View file

@ -10,6 +10,7 @@ in CI, not only during a live install:
from __future__ import annotations from __future__ import annotations
import os import os
import io
import socket import socket
import subprocess import subprocess
import tempfile import tempfile
@ -25,6 +26,7 @@ from vmsafety import (
Results, Results,
UnsafeDiskError, UnsafeDiskError,
validate_disposable_disk, validate_disposable_disk,
validate_independent_disk_sets,
validate_writable_drives, validate_writable_drives,
) )
@ -120,8 +122,44 @@ class DisposableDiskTests(unittest.TestCase):
with self.assertRaises(UnsafeDiskError): with self.assertRaises(UnsafeDiskError):
validate_writable_drives([a, "/dev/sdb"], self.dir) validate_writable_drives([a, "/dev/sdb"], self.dir)
def test_repeat_install_rejects_same_disk_through_an_alias(self):
first = make_qcow2(self.dir / "first.qcow2")
second = make_qcow2(self.dir / "second.qcow2")
alias = self.dir / "alias.qcow2"
alias.symlink_to(first)
self.assertEqual(
validate_independent_disk_sets([first], [second], self.dir), [second]
)
with self.assertRaises(UnsafeDiskError):
validate_independent_disk_sets([first], [alias], self.dir)
class RedactingTextLogTests(unittest.TestCase):
def test_redacts_secret_split_across_reads_and_final_fragment(self):
sink = io.StringIO()
log = vmsafety.RedactingTextLog(sink, ["example-secret", None])
log.write("login: example-")
self.assertEqual(sink.getvalue(), "")
log.write("secret\r\nnext example-")
log.write("secret")
log.finish()
self.assertEqual(sink.getvalue(), "login: [REDACTED]\r\nnext [REDACTED]")
def test_discards_overlong_unterminated_line(self):
sink = io.StringIO()
log = vmsafety.RedactingTextLog(sink, ["example-secret"])
log.write("x" * 1_000_001)
log.write("example-secret\nnext line\n")
log.finish()
self.assertEqual(sink.getvalue(), "[REDACTED overlong serial line]\nnext line\n")
class ResultsTests(unittest.TestCase): class ResultsTests(unittest.TestCase):
def test_failure_detail_redacts_registered_credential(self):
results = Results("unit", secrets=["example-secret"])
results.fail("login", "guest echoed example-secret")
self.assertEqual(results.checks[0].detail, "guest echoed [REDACTED]")
def test_fail_sets_nonzero_exit(self): def test_fail_sets_nonzero_exit(self):
results = Results("unit") results = Results("unit")
results.assert_true("ok", True) results.assert_true("ok", True)

View file

@ -54,6 +54,58 @@ class HarnessError(Exception):
"""A harness precondition failed (bad environment, unsafe path, ...).""" """A harness precondition failed (bad environment, unsafe path, ...)."""
class RedactingTextLog:
"""Write guest output without recording registered credentials.
pexpect can split one echoed credential across reads, so redact complete
terminal lines rather than each write call. The final fragment is flushed
by ``finish`` when QEMU closes. Extremely long unterminated lines are
discarded instead of risking an unbounded buffer or a partial secret.
"""
def __init__(self, sink, secrets):
self.sink = sink
self.secrets = tuple(sorted({s for s in secrets if s}, key=len, reverse=True))
self.pending = ""
self.discarding = False
def _redact(self, value):
for secret in self.secrets:
value = value.replace(secret, "[REDACTED]")
return value
def write(self, value):
if not isinstance(value, str):
value = str(value)
self.pending += value
while True:
newline = self.pending.find("\n")
carriage = self.pending.find("\r")
endings = [at for at in (newline, carriage) if at >= 0]
if not endings:
break
end = min(endings) + 1
line, self.pending = self.pending[:end], self.pending[end:]
if self.discarding:
self.discarding = False
else:
self.sink.write(self._redact(line))
if len(self.pending) > 1_000_000:
self.sink.write("[REDACTED overlong serial line]\n")
self.pending = ""
self.discarding = True
def flush(self):
self.sink.flush()
def finish(self):
if self.pending and not self.discarding:
self.sink.write(self._redact(self.pending))
self.pending = ""
self.discarding = False
self.sink.flush()
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Structured results # Structured results
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
@ -77,10 +129,12 @@ class Results:
when strict, any BLOCKED or NOT RUN) makes :meth:`exit_code` nonzero. when strict, any BLOCKED or NOT RUN) makes :meth:`exit_code` nonzero.
""" """
def __init__(self, scenario: str, run_id: str | None = None, strict: bool | None = None): def __init__(self, scenario: str, run_id: str | None = None,
strict: bool | None = None, secrets=()):
self.scenario = scenario self.scenario = scenario
self.run_id = run_id or new_run_id(scenario) self.run_id = run_id or new_run_id(scenario)
self.checks: list[Check] = [] self.checks: list[Check] = []
self.secrets = tuple(sorted({s for s in secrets if s}, key=len, reverse=True))
if strict is None: if strict is None:
strict = os.environ.get("PHOEBUS_VM_STRICT", "").lower() in ("1", "yes", "true") strict = os.environ.get("PHOEBUS_VM_STRICT", "").lower() in ("1", "yes", "true")
self.strict = bool(strict) self.strict = bool(strict)
@ -89,6 +143,8 @@ class Results:
def _add(self, name: str, status: str, detail: str) -> Check: def _add(self, name: str, status: str, detail: str) -> Check:
if status not in _TERMINAL: if status not in _TERMINAL:
raise ValueError(f"invalid result status: {status}") raise ValueError(f"invalid result status: {status}")
for secret in self.secrets:
detail = detail.replace(secret, "[REDACTED]")
check = Check(name=name, status=status, detail=detail) check = Check(name=name, status=status, detail=detail)
self.checks.append(check) self.checks.append(check)
stream = sys.stderr if status == FAIL else sys.stdout stream = sys.stderr if status == FAIL else sys.stdout
@ -300,6 +356,17 @@ def validate_writable_drives(paths, test_dir, *, qemu_img=True) -> list[Path]:
return checked return checked
def validate_independent_disk_sets(first, second, test_dir) -> list[Path]:
"""Return validated second-install disks only when no image is reused."""
first_checked = validate_writable_drives(first, test_dir)
second_checked = validate_writable_drives(second, test_dir)
if {path.resolve() for path in first_checked} & {
path.resolve() for path in second_checked
}:
raise UnsafeDiskError("second install resolves to a disk used by the first install")
return second_checked
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Run-scoped state # Run-scoped state
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------