fix(sys): stream package output and harden package lanes
Some checks are pending
ci / test (push) Waiting to run

This commit is contained in:
Phoebus 2026-10-01 10:23:41 -07:00
parent fd23aa4890
commit 084c315117
23 changed files with 856 additions and 117 deletions

View file

@ -5,6 +5,26 @@ this file is the curated, human-readable summary.
## Unreleased — Fast defaults with user-controlled source builds
- **Visible package operations and lane reliability (2026-10-01).** Human
`sys` sessions stream package-manager output while commands run, including
Portage compilation, Flatpak progress, Snap changes, Nix realisation,
custom ebuild builds and pinned AppImage downloads. CR progress updates are
shown as well as complete lines; broker and assistant protocols remain
structured. Update reports now distinguish a checked, current source from
an unavailable or manual lane. A root-owned system lock no longer blocks
unprivileged personal preferences. Managed AppImages moved to the readable
`/opt/phoebus/appimages` path so desktop accounts can launch and inventory
them; AppImages previously imported under the private path need to be
re-imported with the new `sys` binary. Custom ebuild removal now preserves
its recipe and reports failure if
Portage cannot unmerge the installed package. Flatpak, Snap and AppImage
mutations now request protective root/var snapshots for `sys undo`. On a
validated disposable encrypted overlay, the final `sys` passed a 22-case
real-lane cycle, a 75-case six-source read-only matrix, a 9-case custom
ebuild cycle and a 12-case Snap cycle. A two-boot AppImage rollback passed
11/11, restoring the managed file and root state while preserving `/home`.
A fresh ISO/install and physical hardware remain unverified.
- **Assistant startup and Snap availability (2026-10-01).** Fixed the installed
assistant's Quickshell window: `FloatingWindow` rejected `palette` and
`minimumHeight`, so the configuration never loaded. The palette now belongs

View file

@ -3,6 +3,37 @@
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.
- **Package-lane terminal and reliability pass (2026-10-01):** Human `sys`
sessions now stream Portage compilation, Flatpak transaction progress,
Snap operations, Nix realisation, custom ebuild builds and AppImage download
output (including carriage-return progress) while retaining redacted logs.
Broker/assistant protocols remain structured. A disposable encrypted VM
overlay passed `sys-lane-operations.sh` 20/20: Portage and Flatpak
install/remove/output, non-root preferences, honest manual-lane update
reports, AppImage import/list/normal-user launch/pinned update/remove, and
Nix realisation. A final-source re-run passed 22/22, including protective
Flatpak and AppImage snapshots and natural AppImage removal. A second boot
passed `sys-custom-ebuild-operations.sh` 9/9
for stage/build/output/unmerge/remove. AppImages moved out of the private
`/var/lib/phoebus` tree into `/opt/phoebus/appimages`; invalid AppImage
URLs that could expose URL credentials are refused. Custom ebuild removal
preserves its staged recipe when unmerge fails. Flatpak, Snap and AppImage
package mutations now request protective root/var snapshots. The installed
VM passed Snap first-use 11/11, then a final-source Snap run 12/12 including
its protective snapshot; the Store supplied no newer revision for the
refresh. The expanded six-lane catalogue matrix passed 75/75. An AppImage
import changed the real managed file, took an automatic snapshot, and was
undone across a detached reboot: rollback PASS=11, restored app/root state,
`/home` preserved. Rust format, warning-free Clippy, workspace tests,
release/static builds, VM safety tests, ShellCheck and the secret scan pass.
The existing visible playground is still running with its earlier `sys`
binary; these checks used a separate disposable overlay. `make doctor`
found only the host-space gate (about 7 GiB free during tests, 11 GiB after
deleting the completed overlay, against 20 GiB for a new VM), so this work
used a validated COW overlay and does not claim a fresh ISO/install. A
fresh release ISO/install, NVIDIA hardware, strict Snap confinement and a
revision-changing Snap refresh remain unverified.
- **Assistant launch and Snap desktop default (2026-10-01):** The visible
playground exposed a Quickshell configuration error at `shell.qml:223`:
`FloatingWindow` has no `palette`; after removing that error, it rejected

View file

@ -91,7 +91,7 @@ disposable VM; `serial-driver.py recovery` now automates the same check.
| Package policy + measured history | yes | yes | yes (326 entries) | no |
| Background update preparation | yes | yes | yes (fetch; buildpkgonly skipped) | no |
| Btrfs snapshots + history | yes | yes | yes | no |
| Coordinated snapshot sets (`@` + `@var` for all high-risk actions) | yes | yes | no | no |
| Coordinated snapshot sets (`@` + `@var` for high-risk package actions) | yes | yes | yes (2026-10-01 final `sys`: Flatpak, Snap and AppImage package mutations each reported a protective snapshot; detached AppImage rollback `serial-rollback-20261001T171752Z-b9f8d068` restored the root and app state, PASS=11) | 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 |
| System health overview (`sys status` / `SystemStatus`) | yes | yes | no | no |
@ -122,21 +122,21 @@ disposable VM; `serial-driver.py recovery` now automates the same check.
| Personal preferences + alert state (user-owned, system-default precedence) | yes | yes (save/reload/isolation/precedence/failure) | yes (installed VM: saved to user config, exit 0) | no |
| Personal write ownership (elevated chown, symlink refusal, cross-uid refusal) | yes | yes (ownership-fixer seam + CLI refusal) | no | no |
| Personal preference does not need the root-owned system transaction log | yes | yes (CLI regression: read-only transaction dir) | yes (installed VM acceptance) | n/a |
| Installed `sys` acceptance matrix (read-only/failure) | yes | yes | yes (installed VM, HEAD binary on a golden overlay `serial-boot-20260929T092147Z-6f88907a`: read-only `SUMMARY PASS=49 FAIL=0`; root mutate `serial-boot-20260929T093329Z-4ef893cf`: `SUMMARY PASS=42 FAIL=0` incl. `mutate-install`/`mutate-remove`/`mutate-history`) | no |
| `sys` terminal progress and prose answers | yes | yes (progress/redaction/heartbeat/wrapping, human CLI vs broker) | visible disposable playground overlay: `sys history --legacy` shows live phases; real OpenCode `sys ask` and `sys find glances` show model/evidence phases plus wrapped answers without approval digests; ten-second heartbeat timing unit-tested | no |
| Installed `sys` acceptance matrix (read-only/failure) | yes | yes | yes (2026-10-01 final static `sys` on an installed VM `serial-boot-20261001T171419Z-1f7973dd`: `SUMMARY PASS=75 FAIL=0`, including search/list/info/updates for all six selectors, failure/refusal cases, and honest manual-lane reports; older root mutate gate PASS=42) | no |
| `sys` terminal progress and prose answers | yes | yes (progress/redaction/heartbeat/wrapping, human CLI vs broker; CR-delimited command output) | visible playground: live phases and real OpenCode answers; 2026-10-01 installed overlay `serial-boot-20261001T171118Z-024ef75c` PASS=22: Portage merge and Flatpak transaction output reached the human terminal; `serial-boot-20261001T165211Z-a1c34407` PASS=9: custom ebuild source build output visible; `serial-boot-20261001T165609Z-019f7bb4` showed the live snapd Portage build and Snap actions | no |
| `sys` adversarial input battery (injection/traversal/boundaries) | yes | yes (54-case `tests/sys_adversarial.rs`; five validation gaps fixed: file-path metacharacters + `..`, application-name traversal, ebuild `..` category (real overlay escape), Flatpak empty element, Nix option prefix) | no | no |
| Portage config readable for non-root queries (`normalize_config_permissions`) | yes | yes (modes + keyring exclusion) | yes (fresh VM install: 0755/0644 out of the box; non-root `search` returns 3 results, `updates` reports 10) | no |
| Privileged catalogue mutations (install/remove/depclean/cache/apply updates, alternate-root) | yes | yes (unit) | yes (fresh installed VM via root: 7/7 PASS) | no |
| Rollback acceptance (snapshot -> change -> `sys undo` -> detached verify) | yes | yes | yes (`serial-rollback-20260926T030237Z-912f6386` PASS=11 FAIL=0; re-verified with the HEAD binary `serial-rollback-20260929T094640Z-256c2ba1` PASS=11 on a fresh disposable overlay: package DB changed then restored, root marker gone, `/home` survives, systemd running, recovery entry present) | no |
| Rollback acceptance (snapshot -> change -> `sys undo` -> detached verify) | yes | yes | yes (Portage 2026-09-29 PASS=11; AppImage with final `sys` on 2026-10-01 `serial-rollback-20261001T171752Z-b9f8d068` PASS=11: automatic snapshot, file changed then restored absent, root marker gone, `/home` survives, systemd running, recovery entry present) | no |
| Privileged `--broker` plan execution + replay rejection in a VM (pkexec path) | yes | yes (privileged entry point) | yes (non-root `pkexec` with a terminal polkit agent: cancelled auth, broker JSON success, replay rejected; required the shipped policy + wheel-admin rule) | n/a |
| Cache-cleanup preview is non-destructive (real `eclean`/`nix-store`) | yes | yes (preview uses `--pretend --deep` / `--print-dead`; sorted bound items) | yes (real `eclean`: upstream preview, cancelled approval, approved run, drift refusal, failed cleaner; user data preserved) | n/a |
| Reverse-dependency inspection includes installed targets | yes | yes (self-reference compares the dependent, not the target) | yes (real `sys-libs/glibc`, `sys-libs/zlib` dependents) | n/a |
| Transaction log (outcomes, protective snapshots) | yes | yes | read-only in installed VM; write path needs root | no |
| Flatpak/Nix bounded typed actions | yes | yes | no | no |
| Flatpak/Nix bounded typed actions | yes | yes | yes (`serial-boot-20261001T171118Z-024ef75c` PASS=22: Flatpak remove/reinstall with visible transaction output and protective snapshot; `nixpkgs#hello` realisation, with exact source flags) | no |
| Shared hardware-aware source selection (all lanes) | yes | yes | no | no |
| Snap lane (detect/install/list/remove/refresh/connections) | yes (snapd and socket enabled by default on new Mango desktops; reviewed first-use setup for older/minimal installs) | yes (incl. exact revisions and confinement; default package/service assertions) | partial (VM: Portage snapd, active socket, `hello-world` install/list/refresh/remove; partial confinement; refresh had no newer revision; connections not exercised. **Re-checked 2026-09-26 against the live Store**: `hello-world` still 6.4 rev 29 on every channel, refresh reports no updates; guest has no `aa-status`, confinement still `partial`. **2026-10-01 existing playground overlay:** reviewed `sys` actions installed `snapd` 2.63 and activated its socket; `snap find glances` and `sys find glances` returned Store results. The new default has no fresh-install VM run yet. A revision-changing refresh and strict confinement stay blocked on a Store revision + AppArmor-ready guest) | no |
| AppImage lane (import/acquire/integrity/desktop/remove) | yes | yes | yes (VM: acquire with pinned SHA, list, launch fixture, remove; tampered SHA refused) | no |
| Custom ebuild overlay (stage/approve/build/remove) | yes | yes | yes (VM: stage → build/install → VDB+file present → remove) | no |
| Snap lane (detect/install/list/remove/refresh/connections) | yes (snapd and socket enabled by default on new Mango desktops; reviewed first-use setup for older/minimal installs) | yes (incl. exact revisions and confinement; default package/service assertions) | partial (2026-10-01 installed overlay `serial-boot-20261001T165609Z-019f7bb4` PASS=11: Portage built snapd with visible output, socket active, daemon confinement reported, `hello-world` installed/refreshed/removed through `sys`; `serial-boot-20261001T170948Z-37654456` PASS=12 re-ran with final `sys` and confirmed protective snapshot. Refresh had no newer Store revision. Earlier VM evidence includes partial confinement; connections and a revision-changing refresh remain unverified. The new desktop default still needs a fresh-install VM run) | no |
| AppImage lane (import/acquire/integrity/desktop/remove) | yes | yes | yes (older VM: pinned acquire, tampered-hash refusal; 2026-10-01 final `sys` on installed overlay `serial-boot-20261001T171118Z-024ef75c`: import, protective snapshot, normal-user list/launch from `/opt/phoebus/appimages`, pinned update and natural-command removal all passed) | no |
| Custom ebuild overlay (stage/approve/build/remove) | yes | yes (unmerge failure and unchanged VDB preserve staged recipe) | yes (2026-10-01 installed overlay `serial-boot-20261001T165211Z-a1c34407` PASS=9: staged exact digest, built/installed VDB+file, source output visible, unmerged and removed recipe) | no |
| `sys` installed into the target + verified in chroot | yes | yes (unit) | yes (detached boot verified) | no |
| AI-first install workflow (`sys install`, `sys ask`) | yes | yes | explicit-backend journey; AI-selected not run | no |
| Bounded AI investigation (typed read-only evidence) | yes | yes | read-only actions on a booted VM | no |
@ -148,10 +148,10 @@ disposable VM; `serial-driver.py recovery` now automates the same check.
| `sys` consistent target-root execution | yes | yes | no | no |
| `sys` validation at the execution boundary | yes | yes | no | n/a |
| `sys ask` truthful failure (nonzero, stop, record) | yes | yes | no | n/a |
| Unified package search (`sys search`, all lanes, `--legacy`) | yes | yes (cross-lane; unavailable/failed/empty distinguished; source filter) | no | no |
| Unified package search (`sys search`, all lanes, `--legacy`) | yes | yes (cross-lane; unavailable/failed/empty distinguished; source filter) | yes (`serial-boot-20261001T171419Z-1f7973dd`: all six source selectors and unified search) | no |
| Installed-package inventory (`sys list`, all lanes, `--legacy`) | yes | yes (VDB/Flatpak/Snap/AppImage; **Nix active-profile packages** vs generations/store; custom ebuild never double-counted) | yes (VM read-only group) | no |
| Package information (`sys info`, `--legacy`) | yes | yes (installed/available, version/deps/size/provenance; ambiguity flagged) | yes (VM read-only group) | no |
| Cross-source update check/apply (`sys updates`, `apply updates`) | yes | yes (exact per-source transactions with full Flatpak commits/snap revisions, pinned and revalidated; manual/project-specific refused) | Flatpak verified in VM (reviewed ref+commit, pinned update, verified); direct Snap refresh with no newer revision VM-verified, exact Snap apply-updates transaction unit-tested only; Portage verified | no |
| Cross-source update check/apply (`sys updates`, `apply updates`) | yes | yes (exact per-source transactions with full Flatpak commits/snap revisions, pinned and revalidated; manual/project-specific refused; unchecked and failed lanes never claim freshness) | 2026-10-01 six-lane `sys updates` matrix PASS=75 and manual AppImage/Nix/custom-ebuild honesty checks; earlier Flatpak reviewed pinned update and Portage update VM-verified; direct Snap refresh completed with no newer revision, exact Snap apply-updates transaction unit-tested only | no |
| Nix active-profile inventory (`sys list --nix`) | yes | yes (manifest v1/v2/v3; scope; generations vs store) | yes (NIX_ENABLED=yes install: real `nodejs-slim` profile listed and filtered; a re-run correctly reported a dangling profile. **2026-09-26 on the fresh unpinned install**: bootstrap present (`/nix/store` populated, `default` link valid, `nix 2.24.9` runs); `sys list --nix` truthfully reports the base system profile has no package manifest. GC-dangling repro: `nix-collect-garbage` is not on root's PATH; user-level install/GC repro attempted — see VM evidence. **2026-09-28 run 15**: modern XDG per-user profiles enumerated — `nix profile install nixpkgs#hello` as `phoebus` into `~/.local/state/nix/profiles/profile`, `sys list --nix` reports `hello 2.12.3 [per-user:phoebus]` with 824 store paths noted separately; installer now normalizes `/nix` + `/etc/nix*` permissions so unprivileged clients work) | no |
| Catalogue maintenance (`depclean`, `clean cache`, `owners`, `deps`/`rdeps`) | yes | yes (structured depclean effects; cache-cleanup dry-run review + failure propagation; VDB dependency metadata) | yes (VM: depclean + cache-cleanup journeys; deps read-only) | no |
| AI-default catalogue routing (source flags constrain, never bypass) | yes | yes (investigation loop, full backend classification + optional-backend rewrite, fallback offers exact `--legacy` command) | yes (read-only routing cases) | no |
@ -296,8 +296,15 @@ disposable VM; `serial-driver.py recovery` now automates the same check.
backend because the serial-only VM has no logind seat. The DRM path and a
real VT login are not yet exercised. `phoebus-session` is written by the
installer for that purpose.
- **Flatpak apps** were not installed from the remote; only the runtime and
the flathub remote were verified.
- **Flatpak apps** were installed from Flathub in disposable VMs, including a
remove/reinstall cycle with live output on 2026-10-01; no hardware check.
- **AppImages imported by earlier builds** remain under private
`/var/lib/phoebus/appimages` and need a one-time administrator re-import to
the accessible `/opt/phoebus/appimages` path. The old file is kept for
explicit cleanup.
- **Nix** is a development realisation and inventory lane. `sys prepare` does
not persist a profile install, so per-profile removal and updates remain
project/user-managed rather than a `sys` transaction.
- **NVIDIA** is implemented (hardware-driven branch/flavor policy, scoped
Portage configuration, a live payload that is build-time verified, and
kernel/module/initramfs update coordination) and covered by Rust tests and the

View file

@ -252,11 +252,18 @@ plan notes that snapd also refreshes automatically.
| `appimage info name` | `appimage_info` | read |
| `appimage list` | `appimage_list` | read |
Acquisition requires a pinned SHA-256; a placeholder or mismatch is refused and
Acquisition requires a pinned SHA-256 and a public URL without credentials,
query or fragment; a placeholder or mismatch is refused and
the download is discarded. Architecture is read from the ELF header without
executing the image. Desktop entries are installed, and user data is preserved
executing the image. Managed files live in `/opt/phoebus/appimages`, where a
normal desktop account can launch them and read their inventory. Desktop
entries are installed, and user data is preserved
on removal unless `"purge_data": true`. AppImage provides **no application
sandbox** and is described as such.
Images imported by older builds into the private
`/var/lib/phoebus/appimages` directory must be re-imported by an administrator
from that original file; the current import writes the accessible path and
replaces its desktop entry. The old file is left in place for explicit cleanup.
### Custom ebuilds (Phoebus overlay)
@ -317,6 +324,14 @@ sys deps vim --legacy # forward dependencies
sys rdeps vim --legacy # reverse dependencies (equery)
```
During a terminal mutation, `sys` shows the package manager's output as it
arrives: Portage build and merge logs, Flatpak transaction progress, Snap
operations, Nix realisation, custom ebuild builds, and AppImage downloads.
Carriage-return progress updates are displayed as well as complete lines.
The current phase and slow-step heartbeat remain visible. Read-only queries
return a composed report; the broker and assistant protocols keep their
structured output.
- **Search** covers Portage (`emerge --search`), Flatpak remote search, the Snap
Store, Phoebus-managed AppImages, Nix (`nix search`, when online) and staged
custom ebuilds. Entries show source, identity, version, description and
@ -387,6 +402,13 @@ recorded.
| `undo status` | `rollback_status` | read |
| `history` | `history` | read |
Portage, Flatpak, Snap, managed AppImage and custom ebuild package changes take
a protective coordinated root/var snapshot before mutation. `sys undo`
restores a chosen snapshot on the next boot; `/home` remains outside that
snapshot. Nix `prepare` only realises a development attribute and does not
install it into a persistent profile. User-managed Nix profile changes and
snapd's automatic background refreshes are outside a `sys` transaction.
## Desktop assistant bridge (`sys --assistant-bridge`)
The desktop assistant GUI (`phoebus-assistant`) is a lightweight Quickshell QML
@ -499,6 +521,11 @@ The matrix below is the repeatable acceptance suite. `installer/tests/vm/sys-acc
runs the deterministic, legacy, and JSON acceptance cases inside a booted,
installed, detached VM and prints a machine-readable summary; it is safe to run
with no network and no model.
`sys-lane-operations.sh` exercises real Portage, Flatpak, AppImage and Nix
mutations; `sys-custom-ebuild-operations.sh` stages, builds and removes a
harmless package; `snap-guest.sh` covers Snap first use and refresh; and the
`appimage-rollback-*` fixtures verify a non-Portage change across a detached
rollback boot. All mutation fixtures require a validated disposable qcow2 VM.
| # | Case | Command | Expected |
| --- | --- | --- | --- |

View file

@ -569,10 +569,13 @@ impl SystemAction {
| SystemAction::StopService { .. }
| SystemAction::RestartService { .. }
| SystemAction::CreateSnapshot { .. }
| SystemAction::FlatpakInstall { .. }
| SystemAction::FlatpakRemove { .. }
| SystemAction::NixPrepare { .. }
| SystemAction::SetPackagePreference { .. }
| SystemAction::CustomEbuildPrepare { .. } => Risk::Medium,
SystemAction::InstallPackage { .. }
| SystemAction::RemovePackage { .. }
| SystemAction::FlatpakInstall { .. }
| SystemAction::FlatpakRemove { .. }
| SystemAction::SnapInstall { .. }
| SystemAction::SnapRemove { .. }
| SystemAction::SnapRefresh { .. }
@ -580,9 +583,6 @@ impl SystemAction {
| SystemAction::AppImageAcquire { .. }
| SystemAction::AppImageUpdate { .. }
| SystemAction::AppImageRemove { .. }
| SystemAction::CustomEbuildPrepare { .. } => Risk::Medium,
SystemAction::InstallPackage { .. }
| SystemAction::RemovePackage { .. }
| SystemAction::UpdateSystem
| SystemAction::ApplyUpdates { .. }
| SystemAction::Depclean
@ -888,8 +888,11 @@ impl SystemAction {
if !valid_appimage_name(name) {
return Err(format!("invalid AppImage name: {name}"));
}
if !valid_http_url(url) {
return Err(format!("invalid AppImage URL: {url}"));
if !valid_public_http_url(url) {
return Err(
"invalid AppImage URL: use http(s) without credentials, query or fragment"
.into(),
);
}
if !valid_sha256(sha256) {
return Err(
@ -1173,6 +1176,19 @@ pub fn valid_http_url(value: &str) -> bool {
&& !value.chars().any(|c| c.is_whitespace() || c.is_control())
}
/// AppImage URLs appear in approval text and public provenance records. Do
/// not accept a URL shape that commonly carries a credential or access token.
pub fn valid_public_http_url(value: &str) -> bool {
if !valid_http_url(value) || value.contains('?') || value.contains('#') {
return false;
}
let Some((_, rest)) = value.split_once("://") else {
return false;
};
let authority = rest.split('/').next().unwrap_or_default();
!authority.is_empty() && !authority.contains('@')
}
/// An absolute file path for an ownership query: bounded, no NUL or control
/// characters, no shell metacharacters that a backend could misread, and no
/// `..` component that could escape the queried location.
@ -1950,7 +1966,7 @@ mod tests {
let install =
parse_action(r#"{"action":"flatpak_install","app_id":"org.chromium.Chromium"}"#)
.unwrap();
assert_eq!(install.risk(), Risk::Medium);
assert_eq!(install.risk(), Risk::High);
assert!(install.is_mutating());
assert!(parse_action(r#"{"action":"flatpak_install","app_id":"bad id"}"#).is_err());
assert!(parse_action(r#"{"action":"flatpak_install","app_id":"nodots"}"#).is_err());
@ -2221,12 +2237,12 @@ mod tests {
#[test]
fn new_actions_are_classified_and_validated() {
// Snap install is medium risk, mutating, and validates its operands.
// Package-lane mutations require a recovery snapshot.
let install = parse_action(
r#"{"action":"snap_install","name":"thunderbird","channel":"latest/stable"}"#,
)
.unwrap();
assert_eq!(install.risk(), Risk::Medium);
assert_eq!(install.risk(), Risk::High);
assert!(install.is_mutating());
assert!(parse_action(r#"{"action":"snap_install","name":"Bad Name"}"#).is_err());
assert!(
@ -2238,7 +2254,7 @@ mod tests {
r#"{"action":"appimage_acquire","name":"mytool","url":"https://example.org/mytool.AppImage","sha256":"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"}"#,
)
.unwrap();
assert_eq!(acquire.risk(), Risk::Medium);
assert_eq!(acquire.risk(), Risk::High);
assert!(parse_action(
r#"{"action":"appimage_acquire","name":"mytool","url":"https://example.org/a","sha256":"0000000000000000000000000000000000000000000000000000000000000000"}"#
)
@ -2247,6 +2263,13 @@ mod tests {
r#"{"action":"appimage_acquire","name":"mytool","url":"ftp://x/a","sha256":"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"}"#
)
.is_err());
for url in [
"https://user:credential@example.org/app",
"https://example.org/app?download=1",
"https://example.org/app#fragment",
] {
assert!(!valid_public_http_url(url));
}
// Custom ebuild staging carries content and is a medium-risk mutation;
// installing it is high risk (it builds untrusted code).

View file

@ -148,13 +148,19 @@ impl UnifiedUpdateOverview {
let mut out = String::new();
out.push_str("Unified Update Overview:\n");
let total_updates = self.total_updates();
if total_updates == 0 {
if total_updates == 0
&& !self.sources.is_empty()
&& self.sources.iter().all(|s| s.supported)
{
out.push_str(" All supported package sources are up to date.\n");
}
if self.sources.is_empty() {
out.push_str(" No package sources were checked.\n");
}
for src in &self.sources {
out.push_str(&format!(" [{}] - ", src.backend.as_str()));
if !src.supported {
out.push_str(&format!("unsupported: {}\n", src.note));
out.push_str(&format!("not checked: {}\n", src.note));
} else if src.updates.is_empty() {
out.push_str(&format!("up to date ({})\n", src.note));
} else {
@ -210,4 +216,22 @@ mod tests {
assert!(build_args().contains(&"--buildpkgonly"));
assert!(build_args().contains(&"@world"));
}
#[test]
fn overview_does_not_claim_freshness_for_unchecked_lanes() {
let mut report = UnifiedUpdateOverview::default();
report.sources.push(SourceUpdateOverview {
backend: Backend::Nix,
updates: Vec::new(),
supported: false,
note: "manual profile update required".into(),
});
let text = report.render();
assert!(text.contains("not checked: manual profile update required"));
assert!(!text.contains("up to date"));
report.sources[0].supported = true;
assert!(report
.render()
.contains("All supported package sources are up to date"));
}
}

View file

@ -145,7 +145,7 @@ fn run_in_target(
program: &str,
args: &[String],
) -> Result<CommandOutput> {
exec.run(target_spec(root, stage, operation, program, args))
exec.run(target_spec(root, stage, operation, program, args).show_output())
}
/// Capture a read-only command against the intended system. Output is returned
@ -1260,7 +1260,9 @@ pub fn execute_inner(
return Err(ExecError::NotAuthorized(action.describe()));
}
let _lock = if action.is_mutating() && exec.is_real() && !exec.dry_run {
// The global mutation lock is root-owned. Personal preferences are an
// atomic user-file write and must remain usable by an unprivileged account.
let _lock = if action.requires_root() && exec.is_real() && !exec.dry_run {
Some(crate::system_lock::SystemLock::acquire(
exec,
root,
@ -1937,6 +1939,10 @@ Total: 1 package (1 new), Size of downloads: 512 KiB
.iter()
.position(|s| s.program == "emerge" || s.args.iter().any(|a| a == "emerge"))
.expect("emerge");
assert!(
specs[emerge].show_output,
"Portage build output must be visible"
);
assert!(
btrfs < emerge,
"protective snapshot must precede the mutation: {:?}",

View file

@ -19,7 +19,7 @@ use crate::error::{ExecError, Result};
use crate::exec::Exec;
/// Where Phoebus keeps managed AppImages, relative to the target root.
pub const APPIMAGE_DIR: &str = "var/lib/phoebus/appimages";
pub const APPIMAGE_DIR: &str = "opt/phoebus/appimages";
/// Where desktop entries are registered, relative to the target root.
pub const APPLICATIONS_DIR: &str = "usr/share/applications";
/// Where icons are registered, relative to the target root.
@ -299,7 +299,8 @@ pub fn acquire(
CommandSpec::new("appimage", "download image", "curl")
.args(["-fL", "--retry", "3", "-o"])
.arg(staged.to_string_lossy().to_string())
.arg(url),
.arg(url)
.show_output(),
)?;
let actual = crate::opencode::sha256_file(&staged)?;
if actual != expected_sha256 {
@ -351,8 +352,15 @@ fn adopt(
provenance: &str,
arch: &str,
) -> Result<AppImageRecord> {
let dir = root.join(APPIMAGE_DIR);
std::fs::create_dir_all(&dir).map_err(|e| ExecError::io(dir.clone(), e))?;
// /var/lib/phoebus is private (0700). Desktop launchers must be able to
// traverse the managed image directory as the logged-in user.
let target = phoebus_core::target::TargetRoot::new(root);
target
.ensure_dir_mode("opt/phoebus", 0o755)
.map_err(|e| ExecError::operation("appimage", "prepare image directory", e.to_string()))?;
let dir = target
.ensure_dir_mode(APPIMAGE_DIR, 0o755)
.map_err(|e| ExecError::operation("appimage", "prepare image directory", e.to_string()))?;
let dest = binary_path(root, name);
// Atomic-ish replacement: copy beside the destination, then rename.
let tmp = dir.join(format!(".{name}.AppImage.tmp"));

View file

@ -5,7 +5,7 @@
//! privileged logic be tested with a fake runner without touching the system.
use std::collections::HashMap;
use std::io::Write;
use std::io::{BufRead, Read, Write};
use std::path::PathBuf;
use std::process::{Command, Stdio};
use std::sync::{Arc, Mutex};
@ -24,6 +24,9 @@ pub struct CommandSpec {
pub cwd: Option<PathBuf>,
pub stage: String,
pub operation: String,
/// Forward this command's live output to the human-facing sink, when one
/// is configured. The structured logger still receives every command.
pub show_output: bool,
}
impl CommandSpec {
@ -40,6 +43,7 @@ impl CommandSpec {
cwd: None,
stage: stage.into(),
operation: operation.into(),
show_output: false,
}
}
@ -95,6 +99,11 @@ impl CommandSpec {
self.cwd = Some(dir.into());
self
}
pub fn show_output(mut self) -> Self {
self.show_output = true;
self
}
}
#[derive(Debug, Clone)]
@ -133,6 +142,9 @@ pub trait ProcessRunner: Send + Sync {
fn is_streaming(&self) -> bool {
false
}
fn shows_output(&self) -> bool {
false
}
fn is_real(&self) -> bool {
false
}
@ -142,15 +154,29 @@ pub trait ProcessRunner: Send + Sync {
#[derive(Clone, Default)]
pub struct RealRunner {
sink: Option<StreamSink>,
user_sink: Option<StreamSink>,
}
impl RealRunner {
pub fn new() -> Self {
Self { sink: None }
Self {
sink: None,
user_sink: None,
}
}
pub fn with_sink(sink: StreamSink) -> Self {
Self { sink: Some(sink) }
Self {
sink: Some(sink),
user_sink: None,
}
}
pub fn with_sinks(log_sink: StreamSink, user_sink: StreamSink) -> Self {
Self {
sink: Some(log_sink),
user_sink: Some(user_sink),
}
}
}
@ -159,6 +185,10 @@ impl ProcessRunner for RealRunner {
self.sink.is_some()
}
fn shows_output(&self) -> bool {
self.user_sink.is_some()
}
fn is_real(&self) -> bool {
true
}
@ -200,49 +230,37 @@ impl ProcessRunner for RealRunner {
let (stdout, stderr) = std::thread::scope(|s| {
let out_handle = s.spawn(|| {
let mut captured = Vec::new();
if let Some(pipe) = stdout_pipe.take() {
let mut reader = std::io::BufReader::new(pipe);
let mut buf = Vec::new();
use std::io::BufRead;
while let Ok(n) = reader.read_until(b'\n', &mut buf) {
if n == 0 {
break;
}
captured.extend_from_slice(&buf);
if let Some(sink) = &self.sink {
let text = String::from_utf8_lossy(&buf);
sink(&text);
}
buf.clear();
}
}
captured
stdout_pipe.take().map_or_else(Vec::new, |pipe| {
drain_output(
pipe,
self.sink.as_ref(),
spec.show_output
.then_some(&self.user_sink)
.and_then(Option::as_ref),
)
})
});
let err_handle = s.spawn(|| {
let mut captured = Vec::new();
if let Some(pipe) = stderr_pipe.take() {
let mut reader = std::io::BufReader::new(pipe);
let mut buf = Vec::new();
use std::io::BufRead;
while let Ok(n) = reader.read_until(b'\n', &mut buf) {
if n == 0 {
break;
}
captured.extend_from_slice(&buf);
if let Some(sink) = &self.sink {
let text = String::from_utf8_lossy(&buf);
sink(&text);
}
buf.clear();
}
}
captured
stderr_pipe.take().map_or_else(Vec::new, |pipe| {
drain_output(
pipe,
self.sink.as_ref(),
spec.show_output
.then_some(&self.user_sink)
.and_then(Option::as_ref),
)
})
});
(out_handle.join().unwrap(), err_handle.join().unwrap())
});
let stdout = out_handle.join().map_err(|_| {
ExecError::operation(&spec.stage, &spec.operation, "stdout reader stopped")
})?;
let stderr = err_handle.join().map_err(|_| {
ExecError::operation(&spec.stage, &spec.operation, "stderr reader stopped")
})?;
Ok::<_, ExecError>((stdout, stderr))
})?;
let status = child.wait().map_err(|source| ExecError::Spawn {
program: spec.program.clone(),
@ -260,6 +278,42 @@ impl ProcessRunner for RealRunner {
}
}
/// Preserve complete captured output while delivering newline and carriage
/// return updates as they arrive (Flatpak and curl use CR progress meters).
fn drain_output(pipe: impl Read, log: Option<&StreamSink>, user: Option<&StreamSink>) -> Vec<u8> {
let mut reader = std::io::BufReader::new(pipe);
let mut captured = Vec::new();
let mut pending = Vec::new();
while let Ok(bytes) = reader.fill_buf() {
if bytes.is_empty() {
break;
}
let boundary = bytes.iter().position(|b| *b == b'\n' || *b == b'\r');
let count = boundary.map_or(bytes.len(), |index| index + 1);
captured.extend_from_slice(&bytes[..count]);
pending.extend_from_slice(&bytes[..count]);
reader.consume(count);
if boundary.is_some() {
emit_chunk(&pending, log, user);
pending.clear();
}
}
if !pending.is_empty() {
emit_chunk(&pending, log, user);
}
captured
}
fn emit_chunk(bytes: &[u8], log: Option<&StreamSink>, user: Option<&StreamSink>) {
let text = String::from_utf8_lossy(bytes);
if let Some(sink) = log {
sink(&text);
}
if let Some(sink) = user {
sink(&text);
}
}
/// A recording runner for tests. It records every spec and returns canned
/// output per program (or a default success). Cloneable so a test can keep a
/// handle while the `Exec` owns another.
@ -398,4 +452,27 @@ mod tests {
let spec = CommandSpec::new("test", "true", "true");
assert!(runner.execute(&spec).unwrap().success);
}
#[test]
fn package_output_is_live_and_only_opted_in_commands_reach_the_user() {
let logged = Arc::new(Mutex::new(String::new()));
let shown = Arc::new(Mutex::new(String::new()));
let log_copy = Arc::clone(&logged);
let shown_copy = Arc::clone(&shown);
let runner = RealRunner::with_sinks(
Arc::new(move |text| log_copy.lock().unwrap().push_str(text)),
Arc::new(move |text| shown_copy.lock().unwrap().push_str(text)),
);
let spec = CommandSpec::new("test", "query", "printf").args(["hidden\\n"]);
runner.execute(&spec).unwrap();
assert_eq!(*shown.lock().unwrap(), "");
assert_eq!(*logged.lock().unwrap(), "hidden\n");
let spec = CommandSpec::new("test", "package install", "printf")
.args(["building\\rinstalled\\n"])
.show_output();
let result = runner.execute(&spec).unwrap();
assert_eq!(result.stdout_lossy(), "building\rinstalled\n");
assert_eq!(*shown.lock().unwrap(), "building\rinstalled\n");
}
}

View file

@ -310,12 +310,13 @@ pub fn install(exec: &Exec, root: &Path, atom: &str, version: &str, digest: &str
"emerge",
&[
"--ask=n".into(),
"--quiet-build=y".into(),
"--quiet-build=n".into(),
"--noreplace".into(),
atom.to_string(),
],
)
.env("FEATURES", features);
.env("FEATURES", features)
.show_output();
exec.run(spec)?;
exec.logger
.info(format!("installed custom ebuild {atom}-{version}"));
@ -329,8 +330,25 @@ pub fn remove(exec: &Exec, root: &Path, atom: &str) -> Result<()> {
.info(format!("[dry-run] would remove custom ebuild {atom}"));
return Ok(());
}
// Unmerge through Portage; a package that is not installed is not an error.
let _ = crate::portage::chroot(exec, root, "emerge", &["--unmerge", "--ask=n", atom]);
// Keep the overlay entry if unmerge fails: deleting its only recipe while
// the package remains installed would turn a failed removal into a false
// success and make later repairs harder.
if crate::portage::installed_packages(root)
.iter()
.any(|package| package.atom == atom)
{
crate::portage::chroot(exec, root, "emerge", &["--unmerge", "--ask=n", atom])?;
if crate::portage::installed_packages(root)
.iter()
.any(|package| package.atom == atom)
{
return Err(ExecError::operation(
"ebuild",
"remove custom ebuild",
format!("Portage still reports {atom} installed after unmerge"),
));
}
}
let dir = package_dir(root, atom)?;
if dir.is_dir() {
std::fs::remove_dir_all(&dir).map_err(|e| ExecError::io(dir, e))?;
@ -485,7 +503,7 @@ SLOT=\"0\"
}
#[test]
fn remove_unmerges_and_deletes_the_overlay_entry() {
fn remove_uninstalled_staged_ebuild_deletes_the_overlay_entry() {
let exec = make_exec(RecordingRunner::new(), false);
let root = tempfile::tempdir().unwrap();
prepare(
@ -504,6 +522,47 @@ SLOT=\"0\"
assert!(staged(root.path(), "app-misc/example").is_none());
}
#[test]
fn failed_unmerge_keeps_the_repairable_ebuild() {
let runner = RecordingRunner::new();
runner.fail("chroot", "unmerge failed");
let exec = make_exec(runner, false);
let root = tempfile::tempdir().unwrap();
prepare(
&exec,
root.path(),
"app-misc/example",
"1.0",
"reason",
SAMPLE,
)
.unwrap();
std::fs::create_dir_all(root.path().join("var/db/pkg/app-misc/example-1.0")).unwrap();
assert!(remove(&exec, root.path(), "app-misc/example").is_err());
assert!(staged(root.path(), "app-misc/example").is_some());
}
#[test]
fn successful_command_without_vdb_removal_is_not_success() {
let exec = make_exec(RecordingRunner::new(), false);
let root = tempfile::tempdir().unwrap();
prepare(
&exec,
root.path(),
"app-misc/example",
"1.0",
"reason",
SAMPLE,
)
.unwrap();
std::fs::create_dir_all(root.path().join("var/db/pkg/app-misc/example-1.0")).unwrap();
let err = remove(&exec, root.path(), "app-misc/example").unwrap_err();
assert!(err.to_string().contains("still reports"));
assert!(staged(root.path(), "app-misc/example").is_some());
}
#[test]
fn dry_run_stages_nothing_and_runs_nothing() {
let runner = RecordingRunner::new();

View file

@ -113,6 +113,10 @@ impl Exec {
self.runner.is_real()
}
pub fn shows_command_output(&self) -> bool {
self.runner.shows_output()
}
pub fn register_secret(&self, secret: &SecretString) {
self.logger.register_secret(secret);
}

View file

@ -248,13 +248,16 @@ pub(crate) fn chroot_spec(
pub fn chroot(exec: &Exec, root: &Path, program: &str, args: &[&str]) -> Result<()> {
let owned: Vec<String> = args.iter().map(|s| (*s).to_string()).collect();
let spec = chroot_spec(
let mut spec = chroot_spec(
"portage_configure",
&format!("chroot: {program}"),
root,
program,
&owned,
);
if program == "emerge" || program == "ebuild" || program.ends_with("/nix") {
spec = spec.show_output();
}
exec.run(spec)?;
Ok(())
}

View file

@ -74,7 +74,8 @@ fn capture(
/// Run a mutating command against the intended system.
fn run_mut(exec: &Exec, root: &Path, program: &str, args: &[&str]) -> Result<()> {
exec.run(spec(root, program, args)).map(|_| ())
exec.run(spec(root, program, args).show_output())
.map(|_| ())
}
/// A command that could not even be started means the lane is unavailable, not
@ -1778,7 +1779,7 @@ mod tests {
);
let exec = make_exec(runner);
let root = Path::new(&exec.root);
let dir = root.join("var/lib/phoebus/appimages");
let dir = root.join("opt/phoebus/appimages");
std::fs::create_dir_all(&dir).unwrap();
std::fs::write(
dir.join("firefox.toml"),

View file

@ -210,18 +210,24 @@ pub fn install(exec: &Exec, name: &str, channel: Option<&str>, classic: bool) ->
if classic {
args.push("--classic".into());
}
let out = exec.run(snap_spec("install snap", &args))?;
Ok(out.stdout_lossy())
let out = exec.run(snap_spec("install snap", &args).show_output())?;
Ok(if exec.shows_command_output() {
String::new()
} else {
out.stdout_lossy()
})
}
/// Remove a snap. Snap data under `/var/snap` is snapd's to manage.
pub fn remove(exec: &Exec, name: &str) -> Result<String> {
require_ready(exec)?;
let out = exec.run(snap_spec(
"remove snap",
&["remove".into(), name.to_string()],
))?;
Ok(out.stdout_lossy())
let out =
exec.run(snap_spec("remove snap", &["remove".into(), name.to_string()]).show_output())?;
Ok(if exec.shows_command_output() {
String::new()
} else {
out.stdout_lossy()
})
}
/// Refresh one snap, or all snaps when `name` is `None`.
@ -235,8 +241,12 @@ pub fn refresh(exec: &Exec, name: Option<&str>) -> Result<String> {
if let Some(name) = name {
args.push(name.to_string());
}
let out = exec.run(snap_spec("refresh snaps", &args))?;
Ok(out.stdout_lossy())
let out = exec.run(snap_spec("refresh snaps", &args).show_output())?;
Ok(if exec.shows_command_output() {
String::new()
} else {
out.stdout_lossy()
})
}
/// Parse `snap list` output. The first line is a header. The `Notes` column is

View file

@ -220,6 +220,7 @@ pub fn check_unified_updates_filtered(
// running root, or inside the target chroot for an alternate root.
if lane_selected(filter, Backend::PortageSource) {
let mut portage_items = Vec::new();
let mut portage_checked = false;
let portage_args: Vec<String> = [
"--pretend",
"--update",
@ -241,6 +242,7 @@ pub fn check_unified_updates_filtered(
let mut portage_note = "native OS packages".to_string();
if let Ok(res) = portage_res {
if res.success {
portage_checked = true;
let plan = phoebus_core::effects::parse_emerge_pretend(&res.stdout_lossy());
for effect in plan.effects {
if effect.kind == phoebus_core::effects::EffectKind::Upgrade
@ -257,11 +259,13 @@ pub fn check_unified_updates_filtered(
} else {
portage_note = "emerge check failed or offline".into();
}
} else {
portage_note = "emerge could not be started".into();
}
sources.push(SourceUpdateOverview {
backend: Backend::PortageSource,
updates: portage_items,
supported: true,
supported: portage_checked,
note: portage_note,
});
}
@ -270,9 +274,10 @@ pub fn check_unified_updates_filtered(
// alternate-root check never consults a host Flatpak installation.
if lane_selected(filter, Backend::Flatpak) {
let mut flatpak_items = Vec::new();
let flatpak_supported = crate::exec::tool_in_target(root, "flatpak");
let flatpak_available = crate::exec::tool_in_target(root, "flatpak");
let mut flatpak_checked = false;
let mut flatpak_note = "sandboxed desktop applications".to_string();
if flatpak_supported {
if flatpak_available {
let fp_args: Vec<String> = [
"remote-ls",
"--updates",
@ -290,6 +295,7 @@ pub fn check_unified_updates_filtered(
));
if let Ok(res) = fp_res {
if res.success {
flatpak_checked = true;
for line in res.stdout_lossy().lines() {
let mut parts = line.split_whitespace();
if let (Some(id), Some(ver)) = (parts.next(), parts.next()) {
@ -304,13 +310,15 @@ pub fn check_unified_updates_filtered(
} else {
flatpak_note = "flatpak remote check failed or offline".into();
}
} else {
flatpak_note = "flatpak remote check could not be started".into();
}
}
sources.push(SourceUpdateOverview {
backend: Backend::Flatpak,
updates: flatpak_items,
supported: flatpak_supported,
note: if flatpak_supported {
supported: flatpak_checked,
note: if flatpak_available {
flatpak_note
} else {
"flatpak is not installed".into()
@ -331,15 +339,17 @@ pub fn check_unified_updates_filtered(
confinement: crate::snap::Confinement::None,
})
};
let snap_supported = matches!(snap_status, Ok(ref s) if s.usable());
let snap_note = "snapd automatic refresh lane".to_string();
if snap_supported {
let snap_available = matches!(snap_status, Ok(ref s) if s.usable());
let mut snap_checked = false;
let mut snap_note = "snapd automatic refresh lane".to_string();
if snap_available {
let snap_res = exec.runner.execute(
&crate::command::CommandSpec::new("sys", "check snap updates", "snap")
.args(["refresh", "--list"]),
);
if let Ok(res) = snap_res {
if res.success {
snap_checked = true;
for line in res.stdout_lossy().lines().skip(1) {
let mut parts = line.split_whitespace();
if let (Some(name), Some(ver)) = (parts.next(), parts.next()) {
@ -351,14 +361,18 @@ pub fn check_unified_updates_filtered(
});
}
}
} else {
snap_note = "Snap Store refresh check failed or offline".into();
}
} else {
snap_note = "Snap Store refresh check could not be started".into();
}
}
sources.push(SourceUpdateOverview {
backend: Backend::Snap,
updates: snap_items,
supported: snap_supported,
note: if snap_supported {
supported: snap_checked,
note: if snap_available {
snap_note
} else {
"snapd is not installed or active".into()
@ -386,7 +400,7 @@ pub fn check_unified_updates_filtered(
sources.push(SourceUpdateOverview {
backend: Backend::Nix,
updates: Vec::new(),
supported: nix_installed,
supported: false,
note: if nix_installed {
"Nix dev packages are declarative/pinned; updates are managed per-project or via profile updates".into()
} else {
@ -395,6 +409,15 @@ pub fn check_unified_updates_filtered(
});
}
if lane_selected(filter, Backend::CustomEbuild) {
sources.push(SourceUpdateOverview {
backend: Backend::CustomEbuild,
updates: Vec::new(),
supported: false,
note: "custom ebuilds are reviewed and updated through Portage, not an independent update feed".into(),
});
}
// Reboot check: check /var/run/reboot-required
let reboot_required = root.join("var/run/reboot-required").exists();
let reboot_reason = if reboot_required {
@ -445,6 +468,25 @@ mod tests {
assert_eq!(state.status, PrepareStatus::Ready);
}
#[test]
fn failed_and_manual_update_checks_are_reported_truthfully() {
let runner = RecordingRunner::new();
runner.fail("emerge", "network unavailable");
let exec = make_exec(runner);
let failed =
check_unified_updates_filtered(&exec, Path::new("/"), Some(Backend::PortageSource));
assert_eq!(failed.sources.len(), 1);
assert!(!failed.sources[0].supported);
assert!(!failed.render().contains("up to date"));
let custom =
check_unified_updates_filtered(&exec, Path::new("/"), Some(Backend::CustomEbuild));
assert_eq!(custom.sources.len(), 1);
assert_eq!(custom.sources[0].backend, Backend::CustomEbuild);
assert!(!custom.sources[0].supported);
assert!(custom.render().contains("through Portage"));
}
#[test]
fn failed_prepare_records_stderr_detail() {
let runner = RecordingRunner::new();

View file

@ -260,13 +260,21 @@ fn run() -> std::result::Result<(), Box<dyn std::error::Error>> {
std::fs::create_dir_all(&state_dir).ok();
}
let logger = Logger::open(state_dir.join("sys.log"), Redactor::new(), false);
let mut exec = Exec::new(
Box::new(RealRunner::new()),
logger,
false,
cli.root.clone(),
state_dir,
);
let log_output = logger.clone();
let redactor = logger.redactor().clone();
let log_sink = Arc::new(move |text: &str| log_output.stream_output(text));
let runner = if cli.assistant_bridge || cli.broker {
RealRunner::with_sink(log_sink)
} else {
RealRunner::with_sinks(
log_sink,
Arc::new(move |text| {
let safe = redactor.redact(text);
let _ = std::io::stderr().write_all(safe.as_bytes());
}),
)
};
let mut exec = Exec::new(Box::new(runner), logger, false, cli.root.clone(), state_dir);
if let Some(view) = &progress {
let view = Arc::clone(view);
exec = exec.with_progress(Arc::new(move |event| view.on_event(event)));

View file

@ -558,7 +558,7 @@ fn remove_without_installed_copy_fails_closed() {
fn remove_ambiguous_copies_requires_explicit_lane() {
let root = tempfile::tempdir().expect("temp root");
// Create an AppImage record
let appimage_dir = root.path().join("var/lib/phoebus/appimages");
let appimage_dir = root.path().join("opt/phoebus/appimages");
std::fs::create_dir_all(&appimage_dir).unwrap();
std::fs::write(
appimage_dir.join("shared-app.toml"),

View file

@ -0,0 +1,58 @@
#!/bin/bash
# Cross-lane rollback acceptance. Run only inside the disposable encrypted VM
# through serial-driver.py rollback; the driver validates the qcow2 target.
set -uo pipefail
if [[ $(id -u) -ne 0 || ! -e /dev/mapper/cryptroot ]]; then
echo '===ROLLBACK-NEEDS-ROOT-VM==='
exit 1
fi
SYS=/tmp/sys-lanes
curl -fsSL http://10.0.2.2:8000/sys-lanes -o "$SYS" || exit 1
chmod 0755 "$SYS"
WORK=$(mktemp -d)
IMAGE=/opt/phoebus/appimages/rollback-fixture.AppImage
if [[ -e $IMAGE ]]; then
echo '===ROLLBACK-BREAK-PRESENT refusing vacuous run==='
exit 1
fi
fingerprint() {
if [[ -f $IMAGE ]]; then
sha256sum "$IMAGE" | awk '{print $1}'
else
echo absent
fi
}
HOME_MARKER="appimage-rollback-$$-$(uname -r)"
printf '%s\n' "$HOME_MARKER" > /home/phoebus/rollback-marker.txt
echo "===ROLLBACK-KNOWN-GOOD pkgs=$(fingerprint) kernel=$(uname -r) home=$HOME_MARKER==="
"$SYS" -y snapshot 'AppImage rollback acceptance' --legacy >"$WORK/snapshot.out" 2>&1 || exit 1
SNAP_ID=$(sed -n 's/^protective snapshot: //p' "$WORK/snapshot.out" | tail -1)
echo "===ROLLBACK-SNAPSHOT id=$SNAP_ID==="
[[ -n $SNAP_ID ]] || exit 1
mkdir -p /etc/phoebus
printf 'rollback acceptance\n' > /etc/phoebus/rollback-broken.txt
echo '===ROLLBACK-MARKER present==='
install -m 0755 /usr/bin/true "$WORK/rollback-fixture.AppImage"
"$SYS" -y --legacy --action \
"{\"action\":\"appimage_import\",\"path\":\"$WORK/rollback-fixture.AppImage\",\"name\":\"rollback-fixture\"}" \
>"$WORK/import.out" 2>&1 || exit 1
AUTO_ID=$(sed -n 's/^protective snapshot: //p' "$WORK/import.out" | tail -1)
echo "===ROLLBACK-AUTO-SNAPSHOT id=$AUTO_ID==="
[[ -n $AUTO_ID ]] || { sed -n '1,30p' "$WORK/import.out"; exit 1; }
echo "===ROLLBACK-BROKEN pkgs=$(fingerprint)==="
[[ -f $IMAGE ]] || exit 1
"$SYS" -y undo "$SNAP_ID" --legacy >"$WORK/undo.out" 2>&1
RC=$?
echo "===ROLLBACK-UNDO rc=$RC id=$SNAP_ID==="
[[ $RC -eq 0 ]] || { sed -n '1,30p' "$WORK/undo.out"; exit 1; }
echo '===ROLLBACK-DONE==='
sync
poweroff -f
echo '===POWEROFF==='

View file

@ -0,0 +1,34 @@
#!/bin/bash
# Post-reboot verification for appimage-rollback-guest.sh.
set -uo pipefail
if [[ $(id -u) -ne 0 || ! -e /dev/mapper/cryptroot ]]; then
echo '===AFTER-NEEDS-ROOT-VM==='
exit 1
fi
IMAGE=/opt/phoebus/appimages/rollback-fixture.AppImage
if [[ -f $IMAGE ]]; then
FINGERPRINT=$(sha256sum "$IMAGE" | awk '{print $1}')
else
FINGERPRINT=absent
fi
HOME_MARKER=$(cat /home/phoebus/rollback-marker.txt 2>/dev/null || echo missing)
echo "===AFTER-KNOWN-GOOD pkgs=$FINGERPRINT kernel=$(uname -r) home=$HOME_MARKER==="
echo "===AFTER-SYSTEMD $(systemctl is-system-running 2>&1)==="
if [[ -e /etc/phoebus/rollback-broken.txt ]]; then
echo '===AFTER-BROKEN-MARKER present==='
else
echo '===AFTER-BROKEN-MARKER absent==='
fi
if [[ -d /lib/modules/$(uname -r) ]]; then
echo '===AFTER-MODULES ok==='
else
echo '===AFTER-MODULES missing==='
fi
echo '===AFTER-RECOVERY==='
cat /efi/loader/entries/phoebus-recovery.conf \
/boot/efi/loader/entries/phoebus-recovery.conf 2>/dev/null || true
echo '===AFTER-STATUS==='
/usr/local/bin/sys rollback status --legacy 2>&1 || true
echo '===AFTER-DONE==='

View file

@ -50,8 +50,14 @@ fi
if snap list hello-world >/dev/null 2>&1; then
echo 'CASE snap-install PASS snap already installed by sys'
elif "$SYS" -y install hello-world --legacy --snap && snap list hello-world; then
elif "$SYS" -y install hello-world --legacy --snap | tee /tmp/phoebus-snap-install.out \
&& snap list hello-world; then
echo 'CASE snap-install PASS installed via reviewed sys plan'
if grep -q '^protective snapshot: ' /tmp/phoebus-snap-install.out; then
echo 'CASE snap-snapshot PASS coordinated recovery point recorded'
else
echo 'CASE snap-snapshot FAIL no protective snapshot for Snap install'
fi
else
echo 'CASE snap-install FAIL install or inventory failed'
exit 1

View file

@ -49,10 +49,12 @@ run_expect_nonzero() {
# run_expect_zero_contains <id> <needle> <args...>
run_expect_zero_contains() {
local id="$1" needle="$2"; shift 2
if "$SYS" "$@" >"$WORK/$id.out" 2>"$WORK/$id.err" && grep -q -- "$needle" "$WORK/$id.out"; then
local rc=0
"$SYS" "$@" >"$WORK/$id.out" 2>"$WORK/$id.err" || rc=$?
if [[ $rc -eq 0 ]] && grep -q -- "$needle" "$WORK/$id.out"; then
report "$id" PASS "$(head -c 160 "$WORK/$id.out" | tr '\n' ' ')"
else
report "$id" FAIL "rc=$? expected 0 and '$needle' in stdout"
report "$id" FAIL "rc=$rc expected '$needle'; stderr=$(tail -c 180 "$WORK/$id.err" | tr '\n' ' ')"
fi
}
@ -109,7 +111,7 @@ if PHOEBUS_PERSONAL_DIR="$PersonalDir" "$SYS" --legacy --action '{"action":"set_
report personal-preference FAIL "reported success without writing user config"
fi
else
report personal-preference FAIL "rc=$? stderr=$(head -c 160 "$WORK/personal-pref.err" | tr '\n' ' ')"
report personal-preference FAIL "rc=$? stderr=$(tail -c 200 "$WORK/personal-pref.err" | tr '\n' ' ')"
fi
# With no provider, `ask` must fall back deterministically and exit nonzero.
PHOEBUS_AI_PROVIDER="" PHOEBUS_AI_BACKEND=direct \
@ -167,6 +169,26 @@ run_expect_zero_contains info-legacy "Package information" --legacy info bash
run_expect_zero_contains updates-legacy "Unified Update Overview" --legacy updates
run_expect_zero_contains json-search-legacy "Package catalogue" --legacy --action '{"action":"search_packages","query":"firefox"}'
# Exercise the same everyday verbs through every source selector. A lane may
# truthfully report unavailable or empty on this VM, but must return a complete
# report rather than silently fall back to another source or hang.
for lane in portage flatpak snap appimage nix ebuild; do
run_expect_zero_contains "search-$lane" "Package catalogue" \
search hello --legacy "--$lane"
run_expect_zero_contains "list-$lane" "Package catalogue" \
list --legacy "--$lane"
run_expect_zero_contains "info-$lane" "Package information" \
info hello --legacy "--$lane"
run_expect_zero_contains "updates-$lane" "Unified Update Overview" \
updates --legacy "--$lane"
done
if grep -q '\[custom-ebuild\].*not checked:' "$WORK/updates-ebuild.out" && \
! grep -q 'All supported package sources are up to date' "$WORK/updates-ebuild.out"; then
report updates-ebuild-honest PASS "manual Portage lane identified"
else
report updates-ebuild-honest FAIL "custom ebuilds were silently reported as current"
fi
# Regression: an alternate root must never be answered by the host's Snap lane.
AltRoot="$WORK/altroot"
mkdir -p "$AltRoot"
@ -265,17 +287,30 @@ fi
# --- Optional mutating group (disposable VM only) -------------------------
if [[ "$MUTATE" == "1" ]]; then
PKG="${SYS_ACCEPTANCE_PACKAGE:-app-misc/hello}"
was_installed=0
compgen -G "/var/db/pkg/${PKG}-*" >/dev/null && was_installed=1
if "$SYS" -y install "$PKG" --legacy --portage >"$WORK/install.out" 2>&1; then
if emerge --pretend --quiet "$PKG" >/dev/null 2>&1; then
if compgen -G "/var/db/pkg/${PKG}-*" >/dev/null; then
report mutate-install PASS "installed $PKG"
else
report mutate-install FAIL "install reported ok but system does not know $PKG"
report mutate-install FAIL "install reported ok but Portage VDB lacks $PKG"
fi
else
report mutate-install FAIL "sys install failed: $(head -c 160 "$WORK/install.out")"
fi
if [[ $was_installed -eq 0 ]]; then
if grep -Eq '>>> (Emerging|Installing)|\[ebuild' "$WORK/install.out"; then
report mutate-install-live-output PASS "Portage build/merge output was visible"
else
report mutate-install-live-output FAIL "Portage build/merge output was hidden"
fi
fi
if "$SYS" -y remove "$PKG" --legacy >"$WORK/remove.out" 2>&1; then
report mutate-remove PASS "removed $PKG"
if compgen -G "/var/db/pkg/${PKG}-*" >/dev/null; then
report mutate-remove FAIL "remove reported ok but Portage VDB still has $PKG"
else
report mutate-remove PASS "removed $PKG"
fi
else
report mutate-remove FAIL "sys remove failed: $(head -c 160 "$WORK/remove.out")"
fi

View file

@ -0,0 +1,97 @@
#!/bin/bash
# Build/remove a harmless local ebuild through reviewed sys actions in a
# disposable installed VM. The fixture writes one text file under /usr/share.
set -uo pipefail
SYS="${SYS_BIN:-/tmp/sys-lanes}"
WORK="$(mktemp -d)"
trap 'rm -rf "$WORK"' EXIT
PASS=0
FAIL=0
report() {
printf 'CASE %s %s %s\n' "$1" "$2" "$3"
if [[ $2 == PASS ]]; then PASS=$((PASS + 1)); else FAIL=$((FAIL + 1)); fi
}
run_root() {
sudo -n "$SYS" -y --legacy --action-file "$1"
}
failure() {
tail -c 240 "$1" | tr '\n' ' '
}
echo '===SYS-EBUILD-START==='
if [[ ! -x "$SYS" || ! -e /dev/mapper/cryptroot || $(id -u) -eq 0 ]]; then
report preflight FAIL 'requires an installed encrypted VM and normal user'
echo "===SYS-EBUILD-END=== SUMMARY PASS=$PASS FAIL=$FAIL"
exit 1
fi
report preflight PASS 'installed encrypted VM, normal user'
python3 - "$WORK" <<'PY'
import hashlib
import json
import pathlib
import sys
work = pathlib.Path(sys.argv[1])
atom = 'app-misc/phoebus-lane-fixture'
ebuild = '''EAPI=8
DESCRIPTION="Phoebus package-lane acceptance fixture"
HOMEPAGE="https://phoebus.club"
SRC_URI=""
LICENSE="MIT"
SLOT="0"
KEYWORDS="amd64"
S="${WORKDIR}"
src_install() {
echo "Phoebus lane fixture" > "${T}/lane-fixture.txt"
insinto /usr/share/phoebus
doins "${T}/lane-fixture.txt"
}
'''
digest = hashlib.sha256(ebuild.encode()).hexdigest()
actions = {
'prepare': {'action': 'custom_ebuild_prepare', 'atom': atom,
'version': '1.0', 'rationale': 'disposable VM package-lane acceptance',
'ebuild': ebuild},
'install': {'action': 'custom_ebuild_install', 'atom': atom,
'version': '1.0', 'digest': digest},
'remove': {'action': 'custom_ebuild_remove', 'atom': atom},
}
for name, action in actions.items():
(work / f'{name}.json').write_text(json.dumps(action))
PY
if run_root "$WORK/prepare.json" >"$WORK/prepare.out" 2>&1 && \
sudo -n test -f /var/db/repos/phoebus/app-misc/phoebus-lane-fixture/phoebus-lane-fixture-1.0.ebuild; then
report ebuild-prepare PASS 'exact ebuild staged in Phoebus overlay'
else
report ebuild-prepare FAIL "$(failure "$WORK/prepare.out")"
fi
if run_root "$WORK/install.json" >"$WORK/install.out" 2>&1 && \
sudo -n test -d /var/db/pkg/app-misc/phoebus-lane-fixture-1.0 && \
sudo -n test -f /usr/share/phoebus/lane-fixture.txt; then
report ebuild-install PASS 'Portage VDB and installed file verified'
if grep -Eq '>>> (Emerging|Installing)|\[ebuild' "$WORK/install.out"; then
report ebuild-live-output PASS 'source build output reached sys terminal'
else
report ebuild-live-output FAIL 'source build output was hidden'
fi
else
report ebuild-install FAIL "$(failure "$WORK/install.out")"
fi
if run_root "$WORK/remove.json" >"$WORK/remove.out" 2>&1 && \
! sudo -n test -d /var/db/pkg/app-misc/phoebus-lane-fixture-1.0 && \
! sudo -n test -e /var/db/repos/phoebus/app-misc/phoebus-lane-fixture; then
report ebuild-remove PASS 'unmerged package and overlay recipe absent'
else
report ebuild-remove FAIL "$(failure "$WORK/remove.out")"
fi
echo "===SYS-EBUILD-END=== SUMMARY PASS=$PASS FAIL=$FAIL"
[[ $FAIL -eq 0 ]]

View file

@ -0,0 +1,159 @@
#!/bin/bash
# Installed-system package-lane cycles. Run only inside a validated disposable
# qcow2 guest; the host driver authenticates sudo before invoking this script.
set -uo pipefail
SYS="${SYS_BIN:-/tmp/sys-lanes}"
WORK="$(mktemp -d)"
trap 'rm -rf "$WORK"' EXIT
PASS=0
FAIL=0
report() {
printf 'CASE %s %s %s\n' "$1" "$2" "$3"
if [[ $2 == PASS ]]; then PASS=$((PASS + 1)); else FAIL=$((FAIL + 1)); fi
}
failure() {
tail -c 240 "$1" | tr '\n' ' '
}
run_root() {
sudo -n "$SYS" -y "$@"
}
echo '===SYS-LANES-START==='
if [[ ! -x "$SYS" || ! -e /dev/mapper/cryptroot || $(id -u) -eq 0 ]]; then
report preflight FAIL 'requires an installed encrypted VM and a normal user'
echo "===SYS-LANES-END=== SUMMARY PASS=$PASS FAIL=$FAIL"
exit 1
fi
report preflight PASS 'installed encrypted VM, normal user'
# Personal state must work without a privileged system lock.
mkdir -p "$WORK/personal"
if PHOEBUS_PERSONAL_DIR="$WORK/personal" "$SYS" --legacy --action \
'{"action":"set_package_preference","name":"lane-fixture","backend":"flatpak"}' \
>"$WORK/pref.out" 2>"$WORK/pref.err" && \
grep -q 'lane-fixture' "$WORK/personal/.config/phoebus/package-preferences.toml"; then
report personal-preference PASS 'unprivileged preference saved'
else
report personal-preference FAIL "$(failure "$WORK/pref.err")"
fi
# No lane with no update feed may claim that it was checked and is current.
for lane in appimage nix ebuild; do
if "$SYS" updates --legacy "--$lane" >"$WORK/updates-$lane.out" 2>"$WORK/updates-$lane.err" && \
grep -q 'not checked:' "$WORK/updates-$lane.out" && \
! grep -q 'All supported package sources are up to date' "$WORK/updates-$lane.out"; then
report "updates-$lane-honest" PASS 'manual or unavailable lane identified'
else
report "updates-$lane-honest" FAIL "$(failure "$WORK/updates-$lane.err")"
fi
done
# Portage install and removal must change the VDB and expose merge output.
PKG=app-misc/hello
if run_root install "$PKG" --legacy --portage >"$WORK/portage-install.out" 2>&1 && \
compgen -G "/var/db/pkg/${PKG}-*" >/dev/null; then
report portage-install PASS 'package present in VDB'
if grep -Eq '>>> (Emerging|Installing)|\[ebuild' "$WORK/portage-install.out"; then
report portage-live-output PASS 'merge output reached the sys terminal'
else
report portage-live-output FAIL 'no Portage merge output in sys terminal'
fi
else
report portage-install FAIL "$(failure "$WORK/portage-install.out")"
fi
if run_root remove "$PKG" --legacy --portage >"$WORK/portage-remove.out" 2>&1 && \
! compgen -G "/var/db/pkg/${PKG}-*" >/dev/null; then
report portage-remove PASS 'package absent from VDB'
else
report portage-remove FAIL "$(failure "$WORK/portage-remove.out")"
fi
# Flatseal is already in the fast-default Flatpak set. Remove then restore the
# exact app so the test overlay finishes with the same desktop application.
APP=com.github.tchx84.Flatseal
if flatpak list --system --app --columns=application | grep -Fxq "$APP"; then
if run_root remove "$APP" --legacy --flatpak >"$WORK/flatpak-remove.out" 2>&1 && \
! flatpak list --system --app --columns=application | grep -Fxq "$APP"; then
report flatpak-remove PASS 'app absent from system Flatpak list'
if grep -q '^protective snapshot: ' "$WORK/flatpak-remove.out"; then
report flatpak-snapshot PASS 'coordinated recovery point recorded'
else
report flatpak-snapshot FAIL 'no protective snapshot for Flatpak removal'
fi
else
report flatpak-remove FAIL "$(failure "$WORK/flatpak-remove.out")"
fi
if run_root install "$APP" --legacy --flatpak >"$WORK/flatpak-install.out" 2>&1 && \
flatpak list --system --app --columns=application | grep -Fxq "$APP"; then
report flatpak-install PASS 'app restored in system Flatpak list'
if grep -Eqi 'installing|installation|fetching|downloading|progress' "$WORK/flatpak-install.out"; then
report flatpak-live-output PASS 'Flatpak transaction output reached sys terminal'
else
report flatpak-live-output FAIL 'no Flatpak transaction output in sys terminal'
fi
else
report flatpak-install FAIL "$(failure "$WORK/flatpak-install.out")"
fi
else
report flatpak-fixture FAIL 'the fast-default Flatseal app is missing'
fi
# AppImage import/update/remove use bounded, pinned fixtures. A small ELF
# exercises integrity and managed-file behavior without executing a download.
install -m 0755 /usr/bin/true "$WORK/lane-fixture.AppImage"
if run_root --legacy --action \
"{\"action\":\"appimage_import\",\"path\":\"$WORK/lane-fixture.AppImage\",\"name\":\"lane-fixture\"}" \
>"$WORK/appimage-import.out" 2>&1 && \
sudo -n test -f /opt/phoebus/appimages/lane-fixture.AppImage; then
report appimage-import PASS 'managed image and record created'
if grep -q '^protective snapshot: ' "$WORK/appimage-import.out"; then
report appimage-snapshot PASS 'coordinated recovery point recorded'
else
report appimage-snapshot FAIL 'no protective snapshot for AppImage import'
fi
else
report appimage-import FAIL "$(failure "$WORK/appimage-import.out")"
fi
if "$SYS" --legacy appimage list >"$WORK/appimage-list.out" 2>&1 && \
grep -q 'lane-fixture' "$WORK/appimage-list.out" && \
/opt/phoebus/appimages/lane-fixture.AppImage; then
report appimage-user-access PASS 'normal account can list and launch managed image'
else
report appimage-user-access FAIL "$(stat -c '%a %n' /var/lib/phoebus /opt/phoebus/appimages 2>&1 | tr '\n' ' ') $(failure "$WORK/appimage-list.out")"
fi
if curl -fsSL http://10.0.2.2:8000/appimage-update-fixture -o "$WORK/appimage-new"; then
sha="$(sha256sum "$WORK/appimage-new" | cut -d ' ' -f1)"
if run_root --legacy --action \
"{\"action\":\"appimage_update\",\"name\":\"lane-fixture\",\"url\":\"http://10.0.2.2:8000/appimage-update-fixture\",\"sha256\":\"$sha\"}" \
>"$WORK/appimage-update.out" 2>&1 && \
test "$(sudo -n sha256sum /opt/phoebus/appimages/lane-fixture.AppImage | cut -d ' ' -f1)" = "$sha"; then
report appimage-update PASS 'pinned replacement verified on disk'
else
report appimage-update FAIL "$(failure "$WORK/appimage-update.out")"
fi
else
report appimage-update FAIL 'could not fetch host-served pinned fixture'
fi
if run_root appimage remove lane-fixture --legacy \
>"$WORK/appimage-remove.out" 2>&1 && \
! sudo -n test -e /opt/phoebus/appimages/lane-fixture.AppImage; then
report appimage-remove PASS 'managed image removed'
else
report appimage-remove FAIL "$(failure "$WORK/appimage-remove.out")"
fi
# Nix is a developer realisation lane: `sys install --nix` must evaluate and
# fetch the exact nixpkgs attribute, then explain how to use it with nix shell.
if run_root install hello --legacy --nix >"$WORK/nix-prepare.out" 2>&1 && \
grep -q 'nix shell nixpkgs#hello' "$WORK/nix-prepare.out"; then
report nix-prepare PASS 'attribute realised and usage explained'
else
report nix-prepare FAIL "$(failure "$WORK/nix-prepare.out")"
fi
echo "===SYS-LANES-END=== SUMMARY PASS=$PASS FAIL=$FAIL"
[[ $FAIL -eq 0 ]]