diff --git a/installer-rs/crates/phoebus-ai/src/assistant.rs b/installer-rs/crates/phoebus-ai/src/assistant.rs index 4705579..c71c351 100644 --- a/installer-rs/crates/phoebus-ai/src/assistant.rs +++ b/installer-rs/crates/phoebus-ai/src/assistant.rs @@ -68,7 +68,8 @@ pub const ASSISTANT_PROMPT: &str = "\ You are the Phoebus OS system assistant. You can ONLY propose actions from this \ closed set: inspect_service, enable_service, disable_service, start_service, \ stop_service, restart_service, inspect_package, \ -install_package, remove_package, search_packages, choose_package, flatpak_install, \ +install_package, remove_package, search_packages, choose_package, \ +set_package_preference, flatpak_install, \ flatpak_remove, flatpak_list, nix_prepare, snap_find, snap_info, snap_install, \ snap_remove, snap_list, snap_refresh, snap_connections, appimage_import, \ appimage_acquire, appimage_update, appimage_remove, appimage_info, appimage_list, \ @@ -362,4 +363,44 @@ mod tests { assert_eq!(action_tag(&SystemAction::History), "history"); assert_eq!(action_tag(&SystemAction::FlatpakList), "flatpak_list"); } + + #[test] + fn the_prompt_names_the_extended_selection_actions() { + for action in [ + "choose_package", + "set_package_preference", + "snap_install", + "appimage_acquire", + "custom_ebuild_prepare", + ] { + assert!( + ASSISTANT_PROMPT.contains(action), + "the prompt must advertise {action}" + ); + } + // The prompt must forbid the old category routing and call a custom + // ebuild untrusted. + assert!(ASSISTANT_PROMPT.contains("category")); + assert!(ASSISTANT_PROMPT.contains("untrusted")); + } + + #[test] + fn a_plan_may_choose_a_lane_and_stage_a_custom_ebuild() { + let text = r#"{ + "version": 1, + "summary": "pick the best source, then stage a custom ebuild", + "actions": [ + {"action":"choose_package","name":"firefox","gui":true}, + {"action":"snap_install","name":"thunderbird"} + ], + "rationale": [ + {"action":"choose_package","reason":"compare the lanes"}, + {"action":"snap_install","reason":"the user asked for the snap"} + ] + }"#; + let plan = parse_plan(text).unwrap(); + assert_eq!(plan.actions.len(), 2); + assert!(plan.render().contains("choose the best source")); + assert!(plan.render().contains("install snap thunderbird")); + } } diff --git a/installer-rs/crates/phoebus-core/src/selection.rs b/installer-rs/crates/phoebus-core/src/selection.rs index 8c89736..7b28510 100644 --- a/installer-rs/crates/phoebus-core/src/selection.rs +++ b/installer-rs/crates/phoebus-core/src/selection.rs @@ -706,8 +706,10 @@ fn score( if need.requires_sandbox && c.sandbox != SandboxLevel::None { s += 25; } else if c.sandbox == SandboxLevel::Strong { - s += 8; - why.push("provides a strong application sandbox".into()); + // A sandbox is a mild plus when it was not required. It must not become + // an automatic category rule that always routes GUI apps to Flatpak or + // Snap; native integration and provenance weigh at least as much. + s += 3; } // Wayland/desktop integration matters for GUI requests. if need.gui { @@ -1236,4 +1238,79 @@ mod tests { let sel = select(&need, &candidates, &facts(), &Preferences::default(), None).unwrap(); assert_eq!(sel.chosen.backend, Backend::PortageVendor); } + + #[test] + fn missing_hardware_information_does_not_fabricate_a_rejection() { + // An unknown GPU, zero memory and zero storage report must not reject a + // candidate that could actually work; unknowns are not failures. + let mut f = facts(); + f.gpus = vec![GpuVendor::Unknown]; + f.memory_mib = 0; + f.storage_free_mib = 0; + let mut c = Candidate::new(Backend::PortageBinary, "app-editors/vim", "binhost"); + c.verified = true; + c.gpu_vendors = vec![GpuVendor::Intel]; + let need = Need::new("vim").kind(PackageKind::CliTool); + let sel = select(&need, &[c], &f, &Preferences::default(), None).unwrap(); + assert_eq!(sel.chosen.backend, Backend::PortageBinary); + } + + #[test] + fn limited_storage_favours_the_smaller_candidate() { + let mut f = facts(); + // Enough for the small candidate (and its runtime), not for the large. + f.storage_free_mib = 1500; + let small = flatpak("org.example.Small"); + let mut large = flatpak("org.example.Large"); + large.install_mib = Some(5000); + large.download_mib = Some(3000); + let need = Need::new("editor").kind(PackageKind::DesktopApp).gui(true); + let sel = select(&need, &[small, large], &f, &Preferences::default(), None).unwrap(); + assert_eq!(sel.chosen.id, "org.example.Small"); + assert!(sel + .rejected + .iter() + .any(|r| r.id == "org.example.Large" && r.reason == RejectReason::InsufficientStorage)); + } + + /// The same application resolves to different lanes on different machines + /// and for different requirements — the point of ADR 0006's revision. + #[test] + fn the_same_application_diverges_by_machine_and_requirement() { + let candidates = vec![ + portage_source("www-client/firefox", 4200), + portage_binary("www-client/firefox", 90), + flatpak("org.mozilla.firefox"), + ]; + + // Low-memory laptop, no sandbox requirement: the signed binary wins. + let mut low = facts(); + low.memory_mib = 2048; + let need = Need::new("firefox").kind(PackageKind::DesktopApp).gui(true); + let sel = select(&need, &candidates, &low, &Preferences::default(), None).unwrap(); + assert_eq!(sel.chosen.backend, Backend::PortageBinary); + + // A machine where the user prefers source: source wins. + let prefs = Preferences { + prefer_source: true, + ..Default::default() + }; + let sel = select(&need, &candidates, &facts(), &prefs, None).unwrap(); + assert_eq!(sel.chosen.backend, Backend::PortageSource); + + // An untrusted-download requirement: only the sandboxed lane can win. + let sandboxed = Need::new("firefox") + .kind(PackageKind::DesktopApp) + .gui(true) + .requires_sandbox(); + let sel = select( + &sandboxed, + &candidates, + &facts(), + &Preferences::default(), + None, + ) + .unwrap(); + assert_eq!(sel.chosen.backend, Backend::Flatpak); + } }