Some checks are pending
ci / test (push) Waiting to run
- Mango + DankMaterialShell desktop option (desktop.profile = "mango") through the GURU overlay with scoped ~amd64 keywords, a sealed session entry point and a dwl fallback session (ADR 0009). - Coherent rollback/recovery: coordinated @ + @var snapshots, fstab and BLS root-subvolume rewriting, matching-kernel selection, snapshot recovery entry, retention/space gates and sys undo (ADR 0007). - Installed assistant (sys ask) with an OS-level systemd sandbox boundary and fail-closed typed plans; resolved package effects bound to approval. - Nix build isolation enforced (sandbox, no fallback) plus lifecycle/cleanup. - Desktop helpers (menu/lock/idle), transaction log, release gates with atomic publish and signing helpers, and a Debian-Live appliance VM harness.
61 lines
1.6 KiB
Rust
61 lines
1.6 KiB
Rust
//! Persisted transaction log for assistant and `sys` actions.
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
use phoebus_core::transaction::{TransactionLog, TransactionRecord};
|
|
|
|
use crate::error::{ExecError, Result};
|
|
use crate::exec::Exec;
|
|
|
|
pub const TRANSACTIONS_REL: &str = "var/lib/phoebus/transactions.toml";
|
|
|
|
pub fn path(root: &Path) -> PathBuf {
|
|
root.join(TRANSACTIONS_REL)
|
|
}
|
|
|
|
pub fn read(root: &Path) -> Result<TransactionLog> {
|
|
TransactionLog::load(&path(root)).map_err(ExecError::Core)
|
|
}
|
|
|
|
pub fn append(exec: &Exec, root: &Path, record: TransactionRecord) -> Result<()> {
|
|
let mut log = read(root)?;
|
|
log.append(record);
|
|
log.save(&path(root)).map_err(ExecError::Core)?;
|
|
exec.logger.info("recorded transaction");
|
|
Ok(())
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use crate::command::RecordingRunner;
|
|
use crate::log::Logger;
|
|
use phoebus_core::Redactor;
|
|
|
|
#[test]
|
|
fn append_persists_to_the_target() {
|
|
let path = tempfile::tempdir().unwrap().keep();
|
|
let logger = Logger::open(path.join("l.log"), Redactor::new(), false);
|
|
let exec = Exec::new(
|
|
Box::new(RecordingRunner::new()),
|
|
logger,
|
|
false,
|
|
path.join("root"),
|
|
path,
|
|
);
|
|
let root = Path::new(&exec.root);
|
|
append(
|
|
&exec,
|
|
root,
|
|
TransactionRecord {
|
|
origin: "sys".into(),
|
|
summary: "test".into(),
|
|
..Default::default()
|
|
},
|
|
)
|
|
.unwrap();
|
|
let log = read(root).unwrap();
|
|
assert_eq!(log.records.len(), 1);
|
|
assert_eq!(log.records[0].origin, "sys");
|
|
}
|
|
}
|