WP-11: contract and failing tests for package upgrades
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
48
backend/crates/application/src/upgrade_service.rs
Normal file
48
backend/crates/application/src/upgrade_service.rs
Normal file
@ -0,0 +1,48 @@
|
||||
//! Package upgrade job: runs the host updater, streams its output into the job log,
|
||||
//! then refreshes the inventory.
|
||||
use std::sync::Arc;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use domain::host::validate_package_name;
|
||||
use domain::ports::HostUpdater;
|
||||
use domain::DomainError;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::jobs::{JobHandler, JobLog};
|
||||
use crate::InventoryService;
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct UpgradeParams {
|
||||
/// Empty = upgrade all packages.
|
||||
#[serde(default)]
|
||||
pub packages: Vec<String>,
|
||||
}
|
||||
|
||||
impl UpgradeParams {
|
||||
pub fn validate(&self) -> Result<(), DomainError> {
|
||||
self.packages
|
||||
.iter()
|
||||
.try_for_each(|p| validate_package_name(p))
|
||||
}
|
||||
|
||||
pub fn to_json(&self) -> String {
|
||||
serde_json::to_string(self).unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn from_json(s: Option<&str>) -> Result<Self, DomainError> {
|
||||
let _ = s;
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PackageUpgradeJob {
|
||||
pub updater: Arc<dyn HostUpdater>,
|
||||
pub inventory: Arc<InventoryService>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl JobHandler for PackageUpgradeJob {
|
||||
async fn run(&self, _params: Option<String>, _log: &dyn JobLog) -> Result<(), String> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user