Installing Phoebus now requires a connected model: the install gate refuses with no provider unless the explicit break-glass --no-ai (alias --legacy, or PHOEBUS_NO_AI=1) is used. Add a 'local' provider kind (Ollama/llama.cpp/ LM Studio) with an optional API key and --ai-endpoint override, so a user can run a model they downloaded; no model is shipped. Desktop installs now include xdg-desktop-portal + gtk/wlr backends for Flatpak and Wayland apps.
166 lines
5.5 KiB
Rust
166 lines
5.5 KiB
Rust
//! End-to-end tests for the AI-assisted path.
|
|
//!
|
|
//! These run the real binary with `--ai-proposal-file`, which sends a proposal
|
|
//! through exactly the same parse -> review (evidence + conflicts) -> apply ->
|
|
//! plan path the live provider path uses. Provider fixtures are labelled as
|
|
//! such; no test here claims a live provider call.
|
|
|
|
use std::process::Command;
|
|
|
|
fn bin() -> &'static str {
|
|
env!("CARGO_BIN_EXE_phoebus-installer")
|
|
}
|
|
|
|
fn run_with_proposal(body: &str, extra: &[&str]) -> std::process::Output {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let path = dir.path().join("proposal.json");
|
|
std::fs::write(&path, body).unwrap();
|
|
let mut cmd = Command::new(bin());
|
|
cmd.arg("--ai-proposal-file")
|
|
.arg(&path)
|
|
.arg("--plan")
|
|
.args(extra);
|
|
cmd.output().expect("run phoebus-installer")
|
|
}
|
|
|
|
const VALID: &str = r#"{
|
|
"version": 1,
|
|
"changes": [
|
|
{"action":"set_kernel_profile","value":"safe"},
|
|
{"action":"set_build_jobs","value":4}
|
|
],
|
|
"rationale": [
|
|
{"action":"set_kernel_profile","reason":"stability over novelty","evidence":["the proven boot uses gentoo-kernel-bin"]},
|
|
{"action":"set_build_jobs","reason":"16 GiB RAM","evidence":["memory_mib=16384"]}
|
|
]
|
|
}"#;
|
|
|
|
#[test]
|
|
fn valid_proposal_is_accepted_and_reaches_the_plan() {
|
|
let out = run_with_proposal(VALID, &[]);
|
|
assert!(out.status.success(), "{:?}", out);
|
|
let stdout = String::from_utf8_lossy(&out.stdout);
|
|
assert!(stdout.contains("Accepted AI changes"), "{stdout}");
|
|
assert!(stdout.contains("kernel profile = safe"), "{stdout}");
|
|
assert!(
|
|
stdout.contains("reason: stability over novelty"),
|
|
"{stdout}"
|
|
);
|
|
// The canonical plan reflects the change.
|
|
assert!(stdout.contains("gentoo-kernel-bin"), "{stdout}");
|
|
}
|
|
|
|
#[test]
|
|
fn missing_evidence_is_rejected() {
|
|
let body = r#"{
|
|
"version": 1,
|
|
"changes": [{"action":"set_hostname","value":"box"}],
|
|
"rationale": []
|
|
}"#;
|
|
let out = run_with_proposal(body, &[]);
|
|
assert!(!out.status.success());
|
|
assert!(String::from_utf8_lossy(&out.stderr).contains("reason"));
|
|
}
|
|
|
|
#[test]
|
|
fn conflicting_changes_are_rejected() {
|
|
let body = r#"{
|
|
"version": 1,
|
|
"changes": [
|
|
{"action":"set_hostname","value":"one"},
|
|
{"action":"set_hostname","value":"two"}
|
|
],
|
|
"rationale": [
|
|
{"action":"set_hostname","reason":"a"},
|
|
{"action":"set_hostname","reason":"b"}
|
|
]
|
|
}"#;
|
|
let out = run_with_proposal(body, &[]);
|
|
assert!(!out.status.success());
|
|
assert!(String::from_utf8_lossy(&out.stderr).contains("conflicting"));
|
|
}
|
|
|
|
#[test]
|
|
fn malicious_proposal_is_refused() {
|
|
let body = r#"{"version":1,"changes":[{"action":"run_shell","command":"rm -rf /"}]}"#;
|
|
let out = run_with_proposal(body, &[]);
|
|
assert!(!out.status.success());
|
|
let err = String::from_utf8_lossy(&out.stderr);
|
|
assert!(err.contains("invalid") || err.contains("unknown"), "{err}");
|
|
}
|
|
|
|
#[test]
|
|
fn invalid_value_is_refused() {
|
|
let body = r#"{
|
|
"version": 1,
|
|
"changes": [{"action":"set_hostname","value":"bad host"}],
|
|
"rationale": [{"action":"set_hostname","reason":"x"}]
|
|
}"#;
|
|
let out = run_with_proposal(body, &[]);
|
|
assert!(!out.status.success());
|
|
}
|
|
|
|
#[test]
|
|
fn install_without_ai_is_refused() {
|
|
// Installing Phoebus requires a connected model.
|
|
let out = Command::new(bin())
|
|
.args(["--install", "--yes"])
|
|
.output()
|
|
.expect("run phoebus-installer");
|
|
assert!(!out.status.success());
|
|
let err = String::from_utf8_lossy(&out.stderr);
|
|
assert!(err.contains("requires a connected AI"), "{err}");
|
|
}
|
|
|
|
#[test]
|
|
fn no_ai_is_the_explicit_break_glass() {
|
|
// `--no-ai` passes the gate; the (incomplete) default config then stops
|
|
// before any disk is touched, with no AI requirement.
|
|
for flag in ["--no-ai", "--legacy"] {
|
|
let out = Command::new(bin())
|
|
.args(["--install", "--yes", flag])
|
|
.output()
|
|
.expect("run phoebus-installer");
|
|
let err = String::from_utf8_lossy(&out.stderr);
|
|
assert!(!err.contains("requires a connected AI"), "{flag}: {err}");
|
|
assert!(err.contains("configuration is incomplete"), "{flag}: {err}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn local_provider_needs_no_key_at_the_gate() {
|
|
// A local provider satisfies the gate without --no-ai (it fails later at
|
|
// the incomplete config, not at the AI gate).
|
|
let out = Command::new(bin())
|
|
.args(["--install", "--yes", "--ai", "--ai-provider", "local"])
|
|
.output()
|
|
.expect("run phoebus-installer");
|
|
let err = String::from_utf8_lossy(&out.stderr);
|
|
assert!(!err.contains("requires a connected AI"), "{err}");
|
|
}
|
|
|
|
#[test]
|
|
fn no_ai_fallback_still_prints_a_plan() {
|
|
let out = Command::new(bin())
|
|
.arg("--plan")
|
|
.output()
|
|
.expect("run phoebus-installer --plan");
|
|
assert!(out.status.success());
|
|
let stdout = String::from_utf8_lossy(&out.stdout);
|
|
assert!(stdout.contains("Installation plan"));
|
|
assert!(!stdout.contains("Accepted AI changes"));
|
|
}
|
|
|
|
#[test]
|
|
fn ai_facts_are_printed_without_a_provider() {
|
|
let out = Command::new(bin())
|
|
.arg("--ai-facts")
|
|
.output()
|
|
.expect("run phoebus-installer --ai-facts");
|
|
assert!(out.status.success(), "{:?}", out);
|
|
let stdout = String::from_utf8_lossy(&out.stdout);
|
|
// The approved fact set is JSON and contains no personal path.
|
|
assert!(stdout.trim_start().starts_with('{'), "{stdout}");
|
|
assert!(stdout.contains("gentoo_profile"));
|
|
assert!(!stdout.contains("/home/"), "{stdout}");
|
|
}
|