Add an OpenAI-compatible provider layer (DeepSeek, OpenAI and a test transport) that sends only bounded system facts and injects the API key via a curl config on stdin, never in argv, config or logs. Extend the typed proposal schema with scoped package.use, build jobs and binary-package preference; every change now needs a non-empty reason and duplicates are rejected. Wire --ai/--ai-proposal-file/--ai-facts into the CLI and add provider selection to the TUI. Deterministic validation and review are unchanged: the model never reaches the executor and the no-AI path keeps working.
127 lines
4.1 KiB
Rust
127 lines
4.1 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 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}");
|
|
}
|