Add explicit vocabulary and named operation contexts

This commit is contained in:
2026-10-29 22:41:38 +02:00
parent ede45d224a
commit 8413b382b1
14 changed files with 344 additions and 241 deletions
+3 -5
View File
@@ -7,9 +7,7 @@ use wireguard_admin::app::{
};
use wireguard_admin::config::{ResolvedSettings, SettingsFile};
use wireguard_admin::delivery::files::FileOutputError;
use wireguard_admin::domain::{
Client, ClientAddresses, ClientStates, RuntimeObservation, Snapshot,
};
use wireguard_admin::domain::{ApplyStatus, Client, ClientAddresses, ClientStates, Snapshot};
use wireguard_admin::persistence::SavedStore;
use wireguard_admin::vault::import::{parse_client_config, reconcile};
use wireguard_admin::vault::{VaultBundle, WireGuardPrivateKey};
@@ -59,7 +57,7 @@ fn fixture(server: String, states: ClientStates) -> Fixture {
}
fn empty_states() -> ClientStates {
ClientStates::new(Snapshot::default(), None, RuntimeObservation::Unknown).expect("empty state")
ClientStates::new(Snapshot::default(), None, ApplyStatus::Unknown).expect("empty state")
}
fn open(fixture: &Fixture) -> Application {
@@ -265,7 +263,7 @@ fn imported_ipv4_only_parameters_are_preserved_and_authenticated_conflict_blocks
let snapshot = Snapshot::new([client]).expect("snapshot");
let import_fixture = fixture(
server.clone(),
ClientStates::new(snapshot, None, RuntimeObservation::Unknown).expect("client state"),
ClientStates::new(snapshot, None, ApplyStatus::Unknown).expect("client state"),
);
let document = ConfigDocument::parse(server.as_bytes()).expect("server document");
let psk = WireGuardPrivateKey::generate().expect("synthetic preshared key");
+6 -10
View File
@@ -6,7 +6,7 @@ use wireguard_admin::app::{AppError, Application};
use wireguard_admin::backup::{BackupReason, preview_archive, preview_archive_bytes};
use wireguard_admin::config::{ResolvedSettings, SettingsFile};
use wireguard_admin::domain::{
Client, ClientAddresses, ClientStates, PublicKey, RuntimeObservation, Snapshot,
ApplyStatus, Client, ClientAddresses, ClientStates, PublicKey, Snapshot,
};
use wireguard_admin::persistence::{PersistedState, SavedStore};
use wireguard_admin::vault::{VaultBundle, WireGuardPrivateKey};
@@ -75,12 +75,8 @@ fn fixture(with_client: bool) -> Fixture {
)
.expect("server fixture is private");
let snapshot = Snapshot::new(clients).expect("initial snapshot");
let states = ClientStates::new(
snapshot.clone(),
Some(snapshot),
RuntimeObservation::Verified,
)
.expect("initial states");
let states = ClientStates::new(snapshot.clone(), Some(snapshot), ApplyStatus::Verified)
.expect("initial states");
let store = SavedStore::new(root.path(), settings.clone()).expect("saved store");
Fixture {
root,
@@ -240,7 +236,7 @@ fn restore_reserves_addresses_of_current_saved_clients_that_the_archive_removes(
.expect("new client");
app.add_client(client, None).expect("stage client");
app.commit().expect("save client");
assert_eq!(app.states().applied(), &RuntimeObservation::Unknown);
assert_eq!(app.states().applied(), &ApplyStatus::Unknown);
let preview = app
.preview_restore(archive_name(&empty_archive))
@@ -264,7 +260,7 @@ fn restore_reserves_addresses_of_current_saved_clients_that_the_archive_removes(
.contains(&"fd20::9".to_owned())
);
assert_eq!(app.states().applied(), &RuntimeObservation::Unknown);
assert_eq!(app.states().applied(), &ApplyStatus::Unknown);
assert!(
app.states()
.reserved_addresses()
@@ -520,5 +516,5 @@ fn deletion_uses_public_key_and_removes_only_that_vault_record() {
.expect("vault parses");
assert!(!bundle.contains_record(fixture.key));
assert!(bundle.contains_record(retained_key));
assert_eq!(app.states().applied(), &RuntimeObservation::Unknown);
assert_eq!(app.states().applied(), &ApplyStatus::Unknown);
}
+4 -6
View File
@@ -4,9 +4,7 @@ use std::path::Path;
use wireguard_admin::app::{Application, RestartChoice, RestartStage};
use wireguard_admin::config::{ResolvedSettings, SettingsFile};
use wireguard_admin::domain::{
Client, ClientAddresses, ClientStates, RuntimeObservation, Snapshot,
};
use wireguard_admin::domain::{ApplyStatus, Client, ClientAddresses, ClientStates, Snapshot};
use wireguard_admin::persistence::SavedStore;
use wireguard_admin::vault::WireGuardPrivateKey;
@@ -67,7 +65,7 @@ fn fixture(service: &str, timeout: u64) -> Fixture {
}
fn open(fixture: &Fixture) -> Application {
let states = ClientStates::new(Snapshot::default(), None, RuntimeObservation::Unknown)
let states = ClientStates::new(Snapshot::default(), None, ApplyStatus::Unknown)
.expect("empty saved states");
Application::open(fixture.store.clone(), states).expect("open synthetic application")
}
@@ -121,7 +119,7 @@ fn public_restart_preview_and_cancel_preserve_draft_and_saved_files() {
.expect("no cancellation backup")
.is_empty()
);
assert_eq!(app.states().applied(), &RuntimeObservation::Unknown);
assert_eq!(app.states().applied(), &ApplyStatus::Unknown);
}
#[test]
@@ -174,7 +172,7 @@ fn restore_changes_the_settings_used_by_the_next_restart_preview() {
app.saved_bytes().settings,
fixture.initial_settings.as_bytes()
);
assert_eq!(app.states().applied(), &RuntimeObservation::Unknown);
assert_eq!(app.states().applied(), &ApplyStatus::Unknown);
let restart = app
.preview_restart()
.expect("preview restored generation without invoking adapters");
+10 -13
View File
@@ -13,9 +13,9 @@ use crossterm::event::KeyCode;
use wireguard_admin::app::{FirstIssueAttempt, RestartChoice, RestartStage};
use wireguard_admin::backup::BackupReason;
use wireguard_admin::config::{ResolvedSettings, SettingsFile};
use wireguard_admin::domain::{ClientStates, PublicKey, RuntimeObservation, Snapshot};
use wireguard_admin::domain::{ApplyStatus, ClientStates, PublicKey, Snapshot};
use wireguard_admin::persistence::SavedStore;
use wireguard_admin::runtime::{InterfaceObservation, RuntimeObservation as Statistics};
use wireguard_admin::runtime::{InterfaceObservation, RuntimeObservation};
use wireguard_admin::tui::events::{
ApplicationWorker, CommandResult, FirstIssueStatus, QrStatus, SecretText, SensitiveCommand,
ShutdownProgress, StatisticsReader, UiCommand, WorkerConfig, WorkerEvent,
@@ -106,9 +106,9 @@ fn saved_peer_projection_counts_legacy_peers_without_inventing_managed_state() {
struct CountingStatistics(Arc<AtomicUsize>);
impl StatisticsReader for CountingStatistics {
fn read(&mut self, _interface: &str, _timeout: Duration) -> Statistics {
fn read(&mut self, _interface: &str, _timeout: Duration) -> RuntimeObservation {
self.0.fetch_add(1, Ordering::SeqCst);
Statistics {
RuntimeObservation {
observed_at: None,
interface: InterfaceObservation::Unavailable,
}
@@ -116,8 +116,8 @@ impl StatisticsReader for CountingStatistics {
}
fn worker(fixture: &Fixture, reader: CountingStatistics) -> ApplicationWorker {
let states = ClientStates::new(Snapshot::default(), None, RuntimeObservation::Unknown)
.expect("empty states");
let states =
ClientStates::new(Snapshot::default(), None, ApplyStatus::Unknown).expect("empty states");
let app = wireguard_admin::app::Application::open(fixture.store.clone(), states)
.expect("application opens on synthetic files");
ApplicationWorker::spawn(
@@ -166,7 +166,7 @@ fn terminal_pty_smoke() {
const CHILD: &str = "WG_ADMIN_SYNTHETIC_PTY_CHILD";
if std::env::var_os(CHILD).is_some() {
let fixture = fixture();
let states = ClientStates::new(Snapshot::default(), None, RuntimeObservation::Unknown)
let states = ClientStates::new(Snapshot::default(), None, ApplyStatus::Unknown)
.expect("empty states");
let app = wireguard_admin::app::Application::open(fixture.store, states)
.expect("synthetic application opens");
@@ -813,10 +813,7 @@ fn worker_backup_restore_preview_cancel_and_confirm_are_separate_saved_operation
match wait_for(&mut worker, restore.request_id) {
WorkerEvent::OperationFinished { result, view, .. } => {
assert!(matches!(result.unwrap(), CommandResult::Restored(_)));
assert_eq!(
view.applied,
wireguard_admin::tui::state::AppliedState::Unknown
);
assert_eq!(view.applied, wireguard_admin::domain::ApplyStatus::Unknown);
assert!(!view.has_draft);
}
_ => unreachable!(),
@@ -916,8 +913,8 @@ fn worker_commit_stops_at_mandatory_backup_failure_and_keeps_draft_and_saved_byt
#[test]
fn worker_restore_refreshes_operational_allocation_settings_before_next_create() {
let fixture = fixture();
let states = ClientStates::new(Snapshot::default(), None, RuntimeObservation::Unknown)
.expect("empty states");
let states =
ClientStates::new(Snapshot::default(), None, ApplyStatus::Unknown).expect("empty states");
let mut original_app = wireguard_admin::app::Application::open(fixture.store.clone(), states)
.expect("original application opens");
original_app