766 lines
26 KiB
Rust
766 lines
26 KiB
Rust
use std::collections::BTreeMap;
|
|
use std::time::Duration;
|
|
|
|
use pretty_assertions::assert_eq;
|
|
use rcom::app::{
|
|
AppState, CollisionChoice, Command, DestinationFingerprint, Effect, ItemDiagnostic, Overlay,
|
|
PaneId, PaneMode, PlanOperationOutput, PlanOperationRequest, QuitDecision,
|
|
};
|
|
use rcom::domain::{Entry, EntryKind, Location};
|
|
use rcom::operations::{
|
|
CollisionPolicy, CommitOutcome, ItemId, ItemOutcome, ItemPhase, OperationEvent,
|
|
OperationEventKind, OperationPlan, ProgressUpdate, SourceCleanupOutcome, SourceItem,
|
|
TaskResult, TaskStatus,
|
|
};
|
|
|
|
fn file(name: &str) -> Entry {
|
|
Entry::new(name, EntryKind::File).with_metadata(Some(4), None, None)
|
|
}
|
|
|
|
fn dual_app() -> AppState {
|
|
let mut app = AppState::new(Location::local("/source"));
|
|
app.mode = PaneMode::Dual;
|
|
app.active_pane_mut().entries = vec![file("a.txt"), file("b.txt")];
|
|
app.active_pane_mut().selection.set(Some(0), 2);
|
|
app.panes[1].location = Location::local("/destination");
|
|
app.panes[1].entries = vec![file("existing.txt")];
|
|
app.panes[1].selection.set(Some(0), 1);
|
|
app
|
|
}
|
|
|
|
fn plan_request(effects: Vec<Effect>) -> PlanOperationRequest {
|
|
let effects: [Effect; 1] = effects.try_into().expect("one planner effect");
|
|
let [Effect::PlanOperation(request)] = effects else {
|
|
panic!("expected read-only planner effect");
|
|
};
|
|
request
|
|
}
|
|
|
|
fn output(request: &PlanOperationRequest) -> PlanOperationOutput {
|
|
let sources = request
|
|
.sources
|
|
.iter()
|
|
.enumerate()
|
|
.map(|(index, source)| {
|
|
SourceItem::new(
|
|
ItemId::new(index as u64 + 1),
|
|
Location {
|
|
source: source.source.clone(),
|
|
path: source.path.clone(),
|
|
},
|
|
)
|
|
})
|
|
.collect();
|
|
PlanOperationOutput {
|
|
prepared: None,
|
|
plan: OperationPlan::new(
|
|
request.plan_id,
|
|
request.generation,
|
|
request.kind,
|
|
sources,
|
|
request.destination.clone(),
|
|
request.policy,
|
|
Some(request.sources.len() as u64),
|
|
Some(8),
|
|
BTreeMap::new(),
|
|
)
|
|
.unwrap(),
|
|
destination_fingerprint: DestinationFingerprint::new("fingerprint-v1"),
|
|
collisions: Vec::new(),
|
|
item_diagnostics: Vec::new(),
|
|
}
|
|
}
|
|
|
|
fn finish_plan(app: &mut AppState, request: PlanOperationRequest) {
|
|
let output = output(&request);
|
|
assert!(
|
|
app.reduce(Command::PlanFinished(request.into_result(Ok(output))))
|
|
.is_empty()
|
|
);
|
|
}
|
|
|
|
fn execute(effects: Vec<Effect>) -> rcom::app::ExecuteOperationRequest {
|
|
let mut executions = effects.into_iter().filter_map(|effect| match effect {
|
|
Effect::ExecuteOperation(request) => Some(request),
|
|
Effect::LoadListing(_) => None,
|
|
_ => panic!("unexpected effect"),
|
|
});
|
|
let request = executions.next().expect("one execution effect");
|
|
assert!(executions.next().is_none());
|
|
request
|
|
}
|
|
|
|
#[test]
|
|
fn dual_f5_uses_the_inactive_confirmed_location_without_switching_panes() {
|
|
let mut app = dual_app();
|
|
let right = app.pane(PaneId::Right).clone();
|
|
let request = plan_request(app.reduce(Command::Copy));
|
|
|
|
assert_eq!(app.active, PaneId::Left);
|
|
assert_eq!(app.pane(PaneId::Right), &right);
|
|
assert_eq!(request.destination, Location::local("/destination"));
|
|
assert_eq!(request.destination_pane.unwrap().pane, PaneId::Right);
|
|
assert_eq!(request.source.listing_generation, 0);
|
|
assert_eq!(request.source.location, Location::local("/source"));
|
|
assert_eq!(
|
|
request.sources,
|
|
[Location::local("/source").entry_id("a.txt")]
|
|
);
|
|
assert_eq!(request.policy, CollisionPolicy::Ask);
|
|
assert!(app.planned_operations.is_empty());
|
|
assert!(app.task_manager.is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn single_f5_requires_an_explicit_visible_destination_before_planning() {
|
|
let mut app = dual_app();
|
|
app.mode = PaneMode::Single;
|
|
|
|
assert!(app.reduce(Command::Copy).is_empty());
|
|
assert_eq!(app.overlay, Overlay::DestinationPrompt);
|
|
let initial = app
|
|
.operation_session
|
|
.as_ref()
|
|
.unwrap()
|
|
.destination_input
|
|
.clone();
|
|
assert_eq!(initial, "/source");
|
|
app.reduce(Command::DestinationBackspace);
|
|
for character in "/chosen".chars() {
|
|
app.reduce(Command::DestinationInput(character));
|
|
}
|
|
let shown = app
|
|
.operation_session
|
|
.as_ref()
|
|
.unwrap()
|
|
.destination_input
|
|
.clone();
|
|
assert!(shown.ends_with("/chosen"));
|
|
let request = plan_request(app.reduce(Command::SubmitDestination));
|
|
assert_eq!(request.destination, Location::local(shown));
|
|
assert_eq!(request.destination_pane, None);
|
|
assert!(app.task_manager.is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn plan_results_are_rejected_after_navigation_or_source_disappearance() {
|
|
let mut app = dual_app();
|
|
let request = plan_request(app.reduce(Command::Copy));
|
|
app.active_pane_mut().listing_generation += 1;
|
|
assert!(
|
|
app.reduce(Command::PlanFinished(
|
|
request.clone().into_result(Ok(output(&request)))
|
|
))
|
|
.is_empty()
|
|
);
|
|
assert_eq!(app.planned_operation, None);
|
|
assert!(app.task_manager.is_empty());
|
|
|
|
let mut app = dual_app();
|
|
let request = plan_request(app.reduce(Command::Copy));
|
|
app.active_pane_mut().entries.clear();
|
|
app.active_pane_mut().selection_set.clear();
|
|
app.reduce(Command::PlanFinished(
|
|
request.into_result(Err(rcom::fs::FsError::NotFound)),
|
|
));
|
|
assert_eq!(app.planned_operation, None);
|
|
assert_eq!(app.overlay, Overlay::ConfirmOperation);
|
|
assert!(app.operation_error().is_some());
|
|
assert!(app.task_manager.is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn canonical_same_endpoint_destination_is_accepted_and_fingerprint_still_guards_staleness() {
|
|
let mut app = dual_app();
|
|
let request = plan_request(app.reduce(Command::Copy));
|
|
let mut output = output(&request);
|
|
output.plan = OperationPlan::new(
|
|
request.plan_id,
|
|
request.generation,
|
|
request.kind,
|
|
output.plan.sources().to_vec(),
|
|
Location::local("/canonical/destination"),
|
|
request.policy,
|
|
Some(1),
|
|
Some(8),
|
|
BTreeMap::new(),
|
|
)
|
|
.unwrap();
|
|
app.reduce(Command::PlanFinished(
|
|
request.clone().into_result(Ok(output)),
|
|
));
|
|
assert_eq!(
|
|
app.planned_operation.as_ref().unwrap().plan.destination(),
|
|
&Location::local("/canonical/destination")
|
|
);
|
|
assert!(!app.reduce(Command::ConfirmPlan(request.plan_id)).is_empty());
|
|
assert_eq!(app.task_manager.len(), 1);
|
|
}
|
|
|
|
#[test]
|
|
fn confirmation_starts_once_and_stale_or_repeated_confirmation_cannot_execute() {
|
|
let mut app = dual_app();
|
|
let request = plan_request(app.reduce(Command::Copy));
|
|
finish_plan(&mut app, request.clone());
|
|
assert_eq!(app.overlay, Overlay::ConfirmOperation);
|
|
let planned = app.planned_operation.clone().unwrap();
|
|
assert_eq!(planned.plan.expected_items(), Some(1));
|
|
assert_eq!(planned.plan.expected_bytes(), Some(8));
|
|
|
|
assert!(
|
|
app.reduce(Command::ConfirmPlan(rcom::operations::PlanId::new(999)))
|
|
.is_empty()
|
|
);
|
|
assert!(app.task_manager.is_empty());
|
|
let execution = execute(app.reduce(Command::ConfirmOperation));
|
|
assert_eq!(execution.start.plan_id, request.plan_id);
|
|
assert_eq!(app.task_manager.len(), 1);
|
|
assert_eq!(app.overlay, Overlay::None);
|
|
|
|
assert!(app.reduce(Command::ConfirmOperation).is_empty());
|
|
assert!(app.reduce(Command::ConfirmPlan(request.plan_id)).is_empty());
|
|
assert_eq!(app.task_manager.len(), 1);
|
|
}
|
|
|
|
#[test]
|
|
fn collision_decisions_replan_without_mutating_the_immutable_plan() {
|
|
let mut app = dual_app();
|
|
let first_request = plan_request(app.reduce(Command::Copy));
|
|
let mut first_output = output(&first_request);
|
|
let source = first_request.sources[0].clone();
|
|
first_output.collisions.push(rcom::app::OperationCollision {
|
|
source: source.clone(),
|
|
destination: Location::local("/destination/a.txt"),
|
|
existing_kind: EntryKind::File,
|
|
});
|
|
app.reduce(Command::PlanFinished(
|
|
first_request.clone().into_result(Ok(first_output)),
|
|
));
|
|
let original = app.planned_operation.clone().unwrap();
|
|
assert_eq!(app.overlay, Overlay::Collision);
|
|
|
|
let second_request = plan_request(app.reduce(Command::ResolveCollision {
|
|
choice: CollisionChoice::Skip,
|
|
apply_to_all: false,
|
|
}));
|
|
assert_eq!(original.plan.policy(), CollisionPolicy::Ask);
|
|
assert_eq!(
|
|
second_request.plan_id.get(),
|
|
first_request.plan_id.get() + 1
|
|
);
|
|
assert_eq!(second_request.resolutions[0].source, source);
|
|
assert_eq!(second_request.resolutions[0].policy, CollisionPolicy::Skip);
|
|
assert!(app.task_manager.is_empty());
|
|
|
|
finish_plan(&mut app, second_request);
|
|
assert_eq!(app.overlay, Overlay::ConfirmOperation);
|
|
assert_eq!(
|
|
execute(app.reduce(Command::ConfirmOperation))
|
|
.operation
|
|
.plan
|
|
.policy(),
|
|
CollisionPolicy::Ask
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn collision_apply_all_and_directory_overwrite_are_explicit_and_safe() {
|
|
let mut app = dual_app();
|
|
let request = plan_request(app.reduce(Command::Move));
|
|
let mut output = output(&request);
|
|
output.collisions.push(rcom::app::OperationCollision {
|
|
source: request.sources[0].clone(),
|
|
destination: Location::local("/destination/a.txt"),
|
|
existing_kind: EntryKind::Directory,
|
|
});
|
|
app.reduce(Command::PlanFinished(request.into_result(Ok(output))));
|
|
|
|
assert!(
|
|
app.reduce(Command::ResolveCollision {
|
|
choice: CollisionChoice::Overwrite,
|
|
apply_to_all: true,
|
|
})
|
|
.is_empty()
|
|
);
|
|
assert!(app.planned_operation.is_some());
|
|
assert!(app.operation_error().unwrap().contains("Directory"));
|
|
|
|
assert!(
|
|
app.reduce(Command::ResolveCollision {
|
|
choice: CollisionChoice::Cancel,
|
|
apply_to_all: false,
|
|
})
|
|
.is_empty()
|
|
);
|
|
assert_eq!(app.pending_operation, None);
|
|
assert_eq!(app.overlay, Overlay::None);
|
|
assert!(app.task_manager.is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn changed_destination_fingerprint_requires_and_requests_a_fresh_plan() {
|
|
let mut app = dual_app();
|
|
let request = plan_request(app.reduce(Command::Copy));
|
|
finish_plan(&mut app, request.clone());
|
|
let effects = app.reduce(Command::DestinationFingerprintChanged {
|
|
plan_id: request.plan_id,
|
|
fingerprint: DestinationFingerprint::new("fingerprint-v2"),
|
|
});
|
|
let replacement = plan_request(effects);
|
|
assert_ne!(replacement.plan_id, request.plan_id);
|
|
assert!(app.planned_operation.is_none());
|
|
assert!(app.operation_error().unwrap().contains("stale"));
|
|
assert!(app.task_manager.is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn queued_tasks_start_only_after_terminal_events_and_emit_each_execution_once() {
|
|
let mut app = dual_app();
|
|
let first_request = plan_request(app.reduce(Command::Copy));
|
|
finish_plan(&mut app, first_request);
|
|
let first = execute(app.reduce(Command::ConfirmOperation));
|
|
|
|
let second_request = plan_request(app.reduce(Command::Copy));
|
|
finish_plan(&mut app, second_request);
|
|
assert!(app.reduce(Command::ConfirmOperation).is_empty());
|
|
assert_eq!(app.task_manager.queued_len(), 1);
|
|
|
|
let item = first.operation.plan.sources()[0].id();
|
|
app.reduce(Command::OperationEvent(OperationEvent::new(
|
|
first.start.operation_id,
|
|
first.start.plan_id,
|
|
OperationEventKind::ItemStarted(item),
|
|
)));
|
|
app.reduce(Command::OperationEvent(OperationEvent::new(
|
|
first.start.operation_id,
|
|
first.start.plan_id,
|
|
OperationEventKind::ItemFinished(ItemOutcome::new(
|
|
item,
|
|
ItemPhase::Succeeded,
|
|
CommitOutcome::Committed,
|
|
SourceCleanupOutcome::NotRequired,
|
|
)),
|
|
)));
|
|
let second = execute(app.reduce(Command::OperationEvent(OperationEvent::new(
|
|
first.start.operation_id,
|
|
first.start.plan_id,
|
|
OperationEventKind::Completed,
|
|
))));
|
|
assert_ne!(second.start.operation_id, first.start.operation_id);
|
|
assert!(
|
|
app.reduce(Command::OperationEvent(OperationEvent::new(
|
|
first.start.operation_id,
|
|
first.start.plan_id,
|
|
OperationEventKind::Completed,
|
|
)))
|
|
.is_empty()
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn tasks_overlay_progress_cancellation_and_quit_waiting_are_reducer_only() {
|
|
let mut app = dual_app();
|
|
let request = plan_request(app.reduce(Command::Move));
|
|
finish_plan(&mut app, request);
|
|
let execution = execute(app.reduce(Command::ConfirmOperation));
|
|
app.reduce(Command::OpenTasks);
|
|
assert_eq!(app.overlay, Overlay::Tasks);
|
|
app.reduce(Command::OperationEvent(OperationEvent::new(
|
|
execution.start.operation_id,
|
|
execution.start.plan_id,
|
|
OperationEventKind::Progress(ProgressUpdate::new(
|
|
0,
|
|
2,
|
|
Some(execution.operation.plan.sources()[0].id()),
|
|
Duration::from_secs(65),
|
|
)),
|
|
)));
|
|
let task = app.task_manager.task(execution.start.task_id).unwrap();
|
|
assert_eq!(task.progress().processed_bytes(), 2);
|
|
assert_eq!(task.progress().elapsed(), Duration::from_secs(65));
|
|
|
|
app.reduce(Command::CloseOverlay);
|
|
assert_eq!(
|
|
app.task_manager.active_task(),
|
|
Some(execution.start.task_id)
|
|
);
|
|
assert!(app.reduce(Command::Quit).is_empty());
|
|
assert!(!app.should_quit);
|
|
assert_eq!(app.overlay, Overlay::Quit);
|
|
assert!(
|
|
app.reduce(Command::DecideQuit(QuitDecision::Stay))
|
|
.is_empty()
|
|
);
|
|
assert_eq!(app.overlay, Overlay::None);
|
|
|
|
app.reduce(Command::Quit);
|
|
let effects: [Effect; 1] = app
|
|
.reduce(Command::DecideQuit(QuitDecision::CancelAndWait))
|
|
.try_into()
|
|
.expect("one cancellation effect");
|
|
let [Effect::CancelOperation(operation_id)] = effects else {
|
|
panic!("expected active cancellation");
|
|
};
|
|
assert_eq!(operation_id, execution.start.operation_id);
|
|
assert!(!app.should_quit);
|
|
assert_eq!(
|
|
app.task_manager
|
|
.task(execution.start.task_id)
|
|
.unwrap()
|
|
.status(),
|
|
TaskStatus::Cancelling
|
|
);
|
|
assert!(
|
|
app.reduce(Command::OperationEvent(OperationEvent::new(
|
|
execution.start.operation_id,
|
|
execution.start.plan_id,
|
|
OperationEventKind::CancellationAcknowledged,
|
|
)))
|
|
.is_empty()
|
|
);
|
|
assert!(app.should_quit);
|
|
}
|
|
|
|
#[test]
|
|
fn queued_completed_event_resolves_cancel_and_wait_race() {
|
|
let mut app = dual_app();
|
|
let request = plan_request(app.reduce(Command::Copy));
|
|
finish_plan(&mut app, request);
|
|
let execution = execute(app.reduce(Command::ConfirmOperation));
|
|
let item = execution.operation.plan.sources()[0].id();
|
|
for kind in [
|
|
OperationEventKind::ItemStarted(item),
|
|
OperationEventKind::ItemFinished(ItemOutcome::new(
|
|
item,
|
|
ItemPhase::Succeeded,
|
|
CommitOutcome::Committed,
|
|
SourceCleanupOutcome::NotRequired,
|
|
)),
|
|
] {
|
|
app.reduce(Command::OperationEvent(OperationEvent::new(
|
|
execution.start.operation_id,
|
|
execution.start.plan_id,
|
|
kind,
|
|
)));
|
|
}
|
|
|
|
app.reduce(Command::Quit);
|
|
app.reduce(Command::DecideQuit(QuitDecision::CancelAndWait));
|
|
assert!(!app.should_quit);
|
|
let effects = app.reduce(Command::OperationEvent(OperationEvent::new(
|
|
execution.start.operation_id,
|
|
execution.start.plan_id,
|
|
OperationEventKind::Completed,
|
|
)));
|
|
assert!(!effects.is_empty());
|
|
assert!(
|
|
effects
|
|
.iter()
|
|
.all(|effect| matches!(effect, Effect::LoadListing(_)))
|
|
);
|
|
assert!(app.should_quit);
|
|
assert_eq!(
|
|
app.task_manager
|
|
.task(execution.start.task_id)
|
|
.unwrap()
|
|
.status(),
|
|
TaskStatus::Succeeded
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn queued_cancellation_is_final_without_an_executor_event() {
|
|
let mut app = dual_app();
|
|
let first = plan_request(app.reduce(Command::Copy));
|
|
finish_plan(&mut app, first);
|
|
let active = execute(app.reduce(Command::ConfirmOperation));
|
|
let second = plan_request(app.reduce(Command::Copy));
|
|
finish_plan(&mut app, second);
|
|
assert!(app.reduce(Command::ConfirmOperation).is_empty());
|
|
app.reduce(Command::OpenTasks);
|
|
app.reduce(Command::SelectTask(1));
|
|
|
|
assert!(app.reduce(Command::CancelSelectedTask).is_empty());
|
|
assert_eq!(
|
|
app.task_manager
|
|
.task(active.start.task_id)
|
|
.unwrap()
|
|
.status(),
|
|
TaskStatus::Running
|
|
);
|
|
assert_eq!(app.task_manager.queued_len(), 0);
|
|
assert_eq!(
|
|
app.task_manager
|
|
.tasks()
|
|
.filter(|task| task.status() == TaskStatus::Cancelled)
|
|
.count(),
|
|
1
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn copy_completion_refreshes_destination_once_and_never_switches_the_active_pane() {
|
|
let mut app = dual_app();
|
|
let request = plan_request(app.reduce(Command::Copy));
|
|
finish_plan(&mut app, request);
|
|
let execution = execute(app.reduce(Command::ConfirmOperation));
|
|
let item = execution.operation.plan.sources()[0].id();
|
|
for kind in [
|
|
OperationEventKind::ItemStarted(item),
|
|
OperationEventKind::ItemFinished(ItemOutcome::new(
|
|
item,
|
|
ItemPhase::Succeeded,
|
|
CommitOutcome::Committed,
|
|
SourceCleanupOutcome::NotRequired,
|
|
)),
|
|
] {
|
|
app.reduce(Command::OperationEvent(OperationEvent::new(
|
|
execution.start.operation_id,
|
|
execution.start.plan_id,
|
|
kind,
|
|
)));
|
|
}
|
|
let effects = app.reduce(Command::OperationEvent(OperationEvent::new(
|
|
execution.start.operation_id,
|
|
execution.start.plan_id,
|
|
OperationEventKind::Completed,
|
|
)));
|
|
let refreshed: Vec<_> = effects
|
|
.iter()
|
|
.map(|effect| match effect {
|
|
Effect::LoadListing(request) => request.pane,
|
|
_ => panic!("unexpected completion effect"),
|
|
})
|
|
.collect();
|
|
assert_eq!(refreshed, vec![PaneId::Left, PaneId::Right]);
|
|
assert_eq!(app.active, PaneId::Left);
|
|
assert!(
|
|
app.reduce(Command::OperationEvent(OperationEvent::new(
|
|
execution.start.operation_id,
|
|
execution.start.plan_id,
|
|
OperationEventKind::Completed,
|
|
)))
|
|
.is_empty()
|
|
);
|
|
|
|
let mut stale = dual_app();
|
|
let request = plan_request(stale.reduce(Command::Copy));
|
|
finish_plan(&mut stale, request);
|
|
let execution = execute(stale.reduce(Command::ConfirmOperation));
|
|
let item = execution.operation.plan.sources()[0].id();
|
|
for kind in [
|
|
OperationEventKind::ItemStarted(item),
|
|
OperationEventKind::ItemFinished(ItemOutcome::new(
|
|
item,
|
|
ItemPhase::Succeeded,
|
|
CommitOutcome::Committed,
|
|
SourceCleanupOutcome::NotRequired,
|
|
)),
|
|
] {
|
|
stale.reduce(Command::OperationEvent(OperationEvent::new(
|
|
execution.start.operation_id,
|
|
execution.start.plan_id,
|
|
kind,
|
|
)));
|
|
}
|
|
stale.pane_mut(PaneId::Right).location = Location::local("/elsewhere");
|
|
let effects = stale.reduce(Command::OperationEvent(OperationEvent::new(
|
|
execution.start.operation_id,
|
|
execution.start.plan_id,
|
|
OperationEventKind::Completed,
|
|
)));
|
|
assert!(effects.iter().all(|effect| {
|
|
!matches!(effect, Effect::LoadListing(request) if request.pane == PaneId::Right)
|
|
}));
|
|
}
|
|
|
|
#[test]
|
|
fn completion_does_not_replace_a_newer_pending_navigation_with_an_old_refresh() {
|
|
let mut app = dual_app();
|
|
let request = plan_request(app.reduce(Command::Copy));
|
|
finish_plan(&mut app, request);
|
|
let execution = execute(app.reduce(Command::ConfirmOperation));
|
|
let item = execution.operation.plan.sources()[0].id();
|
|
for kind in [
|
|
OperationEventKind::ItemStarted(item),
|
|
OperationEventKind::ItemFinished(ItemOutcome::new(
|
|
item,
|
|
ItemPhase::Succeeded,
|
|
CommitOutcome::Committed,
|
|
SourceCleanupOutcome::NotRequired,
|
|
)),
|
|
] {
|
|
app.reduce(Command::OperationEvent(OperationEvent::new(
|
|
execution.start.operation_id,
|
|
execution.start.plan_id,
|
|
kind,
|
|
)));
|
|
}
|
|
|
|
app.active = PaneId::Right;
|
|
let navigation: [Effect; 1] = app
|
|
.reduce(Command::GoHome(Location::local("/elsewhere")))
|
|
.try_into()
|
|
.unwrap();
|
|
let [Effect::LoadListing(navigation)] = navigation else {
|
|
panic!("expected pending navigation");
|
|
};
|
|
let navigation_generation = navigation.generation;
|
|
app.active = PaneId::Left;
|
|
let effects = app.reduce(Command::OperationEvent(OperationEvent::new(
|
|
execution.start.operation_id,
|
|
execution.start.plan_id,
|
|
OperationEventKind::Completed,
|
|
)));
|
|
assert!(effects.iter().all(|effect| {
|
|
!matches!(effect, Effect::LoadListing(request) if request.pane == PaneId::Right)
|
|
}));
|
|
assert_eq!(
|
|
app.pane(PaneId::Right).pending_target,
|
|
Some(Location::local("/elsewhere"))
|
|
);
|
|
assert_eq!(
|
|
app.pane(PaneId::Right).listing_generation,
|
|
navigation_generation
|
|
);
|
|
|
|
app.reduce(Command::ListingFinished(
|
|
navigation.into_result(Ok(vec![file("new-location.txt")])),
|
|
));
|
|
assert_eq!(
|
|
app.pane(PaneId::Right).location,
|
|
Location::local("/elsewhere")
|
|
);
|
|
assert_eq!(app.pane(PaneId::Right).entries[0].name, "new-location.txt");
|
|
}
|
|
|
|
#[test]
|
|
fn partial_cancelled_and_uncommitted_results_drive_only_evidence_based_refresh() {
|
|
for (cancel, committed, all_succeed) in [
|
|
(false, true, true),
|
|
(true, true, false),
|
|
(false, true, false),
|
|
(false, false, false),
|
|
] {
|
|
let mut app = dual_app();
|
|
app.reduce(Command::SelectAll);
|
|
let request = plan_request(app.reduce(Command::Copy));
|
|
finish_plan(&mut app, request);
|
|
let execution = execute(app.reduce(Command::ConfirmOperation));
|
|
let items: Vec<_> = execution
|
|
.operation
|
|
.plan
|
|
.sources()
|
|
.iter()
|
|
.map(|source| source.id())
|
|
.collect();
|
|
assert_eq!(items.len(), 2);
|
|
for kind in [
|
|
OperationEventKind::ItemStarted(items[0]),
|
|
OperationEventKind::ItemFinished(ItemOutcome::new(
|
|
items[0],
|
|
if all_succeed {
|
|
ItemPhase::Succeeded
|
|
} else {
|
|
ItemPhase::Failed
|
|
},
|
|
if committed {
|
|
CommitOutcome::Committed
|
|
} else {
|
|
CommitOutcome::NotAttempted
|
|
},
|
|
SourceCleanupOutcome::NotRequired,
|
|
)),
|
|
] {
|
|
app.reduce(Command::OperationEvent(OperationEvent::new(
|
|
execution.start.operation_id,
|
|
execution.start.plan_id,
|
|
kind,
|
|
)));
|
|
}
|
|
if cancel {
|
|
app.reduce(Command::OpenTasks);
|
|
app.reduce(Command::CancelSelectedTask);
|
|
} else {
|
|
for kind in [
|
|
OperationEventKind::ItemStarted(items[1]),
|
|
OperationEventKind::ItemFinished(ItemOutcome::new(
|
|
items[1],
|
|
if all_succeed {
|
|
ItemPhase::Succeeded
|
|
} else {
|
|
ItemPhase::Failed
|
|
},
|
|
if all_succeed {
|
|
CommitOutcome::Committed
|
|
} else {
|
|
CommitOutcome::NotAttempted
|
|
},
|
|
SourceCleanupOutcome::NotRequired,
|
|
)),
|
|
] {
|
|
app.reduce(Command::OperationEvent(OperationEvent::new(
|
|
execution.start.operation_id,
|
|
execution.start.plan_id,
|
|
kind,
|
|
)));
|
|
}
|
|
}
|
|
let effects = app.reduce(Command::OperationEvent(OperationEvent::new(
|
|
execution.start.operation_id,
|
|
execution.start.plan_id,
|
|
if cancel {
|
|
OperationEventKind::CancellationAcknowledged
|
|
} else {
|
|
OperationEventKind::Completed
|
|
},
|
|
)));
|
|
assert_eq!(
|
|
effects
|
|
.iter()
|
|
.any(|effect| matches!(effect, Effect::LoadListing(_))),
|
|
committed
|
|
);
|
|
let task = app.task_manager.task(execution.start.task_id).unwrap();
|
|
let expected_result = if cancel {
|
|
TaskResult::Cancelled
|
|
} else if !committed {
|
|
TaskResult::Failed
|
|
} else if all_succeed {
|
|
TaskResult::Succeeded
|
|
} else {
|
|
TaskResult::Partial
|
|
};
|
|
assert_eq!(task.result(), Some(expected_result));
|
|
assert_eq!(
|
|
task.status(),
|
|
if cancel {
|
|
TaskStatus::Cancelled
|
|
} else if all_succeed {
|
|
TaskStatus::Succeeded
|
|
} else {
|
|
TaskStatus::Failed
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn planned_item_diagnostics_retain_part_paths_for_task_details() {
|
|
let mut app = dual_app();
|
|
let request = plan_request(app.reduce(Command::Copy));
|
|
let mut output = output(&request);
|
|
output.item_diagnostics.push(ItemDiagnostic {
|
|
source: Some(request.sources[0].clone()),
|
|
message: "unknown close outcome".into(),
|
|
partial: Some(Location::local("/destination/.a.txt.part")),
|
|
});
|
|
app.reduce(Command::PlanFinished(request.into_result(Ok(output))));
|
|
let execution = execute(app.reduce(Command::ConfirmOperation));
|
|
assert_eq!(
|
|
app.planned_operations[&execution.start.plan_id].item_diagnostics[0]
|
|
.partial
|
|
.as_ref(),
|
|
Some(&Location::local("/destination/.a.txt.part"))
|
|
);
|
|
}
|