883 lines
33 KiB
Rust
883 lines
33 KiB
Rust
use pretty_assertions::assert_eq;
|
|
use rcom::app::{
|
|
AppState, Command, ConnectSshRequest, Effect, ListingRequest, PaneId, PreviewRequest,
|
|
SshConnection,
|
|
};
|
|
use rcom::domain::{Entry, EntryKind, HostAlias, Location};
|
|
use rcom::fs::{FsError, ReadFileSystem};
|
|
use rcom::preview::preview_bytes;
|
|
use rcom::test_support::MemoryFs;
|
|
|
|
fn one_listing(effects: Vec<Effect>) -> ListingRequest {
|
|
let effects: [Effect; 1] = effects.try_into().expect("one listing effect");
|
|
let [Effect::LoadListing(request)] = effects else {
|
|
panic!("expected exactly one listing effect");
|
|
};
|
|
request
|
|
}
|
|
|
|
fn one_preview(effects: Vec<Effect>) -> PreviewRequest {
|
|
let effects: [Effect; 1] = effects.try_into().expect("one preview effect");
|
|
let [Effect::LoadPreview(request)] = effects else {
|
|
panic!("expected exactly one preview effect");
|
|
};
|
|
request
|
|
}
|
|
|
|
fn one_connect(effects: Vec<Effect>) -> ConnectSshRequest {
|
|
let effects: [Effect; 1] = effects.try_into().expect("one connect effect");
|
|
let [Effect::ConnectSsh(request)] = effects else {
|
|
panic!("expected exactly one connect effect");
|
|
};
|
|
request
|
|
}
|
|
|
|
fn file(name: &str) -> Entry {
|
|
Entry::new(name, EntryKind::File)
|
|
}
|
|
|
|
fn finish_listing(app: &mut AppState, request: ListingRequest, entries: Vec<Entry>) -> Vec<Effect> {
|
|
app.reduce(Command::ListingFinished(request.into_result(Ok(entries))))
|
|
}
|
|
|
|
fn connect(
|
|
app: &mut AppState,
|
|
host: &HostAlias,
|
|
home: Location,
|
|
session_epoch: u64,
|
|
) -> ListingRequest {
|
|
let request = one_connect(app.reduce(Command::ConnectSsh(host.clone())));
|
|
one_listing(
|
|
app.reduce(Command::ConnectSshFinished(request.into_result(Ok(
|
|
SshConnection {
|
|
location: home,
|
|
session_epoch,
|
|
},
|
|
)))),
|
|
)
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn successful_connect_canonicalizes_remote_home() {
|
|
let host = HostAlias::new("edge");
|
|
let fs = MemoryFs::navigation_fixture();
|
|
let mut app = AppState::new(Location::local("/workspace"));
|
|
let initial = one_listing(app.reduce(Command::Refresh));
|
|
let local_entries = fs.list(&initial.target).await;
|
|
app.reduce(Command::ListingFinished(initial.into_result(local_entries)));
|
|
let local_location = app.active_pane().location.clone();
|
|
let local_entries = app.active_pane().entries.clone();
|
|
let local_selection = app.active_pane().selection;
|
|
let local_preview = app.active_pane().preview.clone();
|
|
|
|
let request = one_connect(app.reduce(Command::ConnectSsh(host.clone())));
|
|
assert_eq!(request.host, host);
|
|
assert_eq!(request.expected_session_epoch, None);
|
|
assert_eq!(
|
|
app.active_pane().pending_target,
|
|
Some(Location::ssh(host.clone(), "."))
|
|
);
|
|
assert_eq!(app.active_pane().location, local_location);
|
|
assert!(app.active_pane().loading);
|
|
|
|
// The connector's canonicalize(".") result is the typed remote home carried by this result.
|
|
let home = fs
|
|
.canonicalize(&Location::ssh(host.clone(), "/home/user"))
|
|
.await
|
|
.expect("remote home");
|
|
let listing = one_listing(
|
|
app.reduce(Command::ConnectSshFinished(request.into_result(Ok(
|
|
SshConnection {
|
|
location: home.clone(),
|
|
session_epoch: 41,
|
|
},
|
|
)))),
|
|
);
|
|
assert_eq!(listing.target, home);
|
|
assert_eq!(listing.session_epoch, Some(41));
|
|
assert_eq!(app.active_pane().session_epoch, Some(41));
|
|
assert_eq!(app.active_pane().location, local_location);
|
|
assert_eq!(app.active_pane().entries, local_entries);
|
|
assert_eq!(app.active_pane().selection, local_selection);
|
|
assert_eq!(app.active_pane().preview, local_preview);
|
|
|
|
let entries = fs.list(&listing.target).await;
|
|
let preview = app.reduce(Command::ListingFinished(listing.into_result(entries)));
|
|
assert_eq!(preview.len(), 1);
|
|
assert_eq!(app.active_pane().location, home);
|
|
assert_eq!(app.active_pane().entries.len(), 1);
|
|
assert_eq!(
|
|
app.active_pane().selected_entry().expect("welcome").name,
|
|
"welcome.txt"
|
|
);
|
|
assert_eq!(app.active_pane().error, None);
|
|
}
|
|
|
|
#[test]
|
|
fn connect_changes_only_active_pane() {
|
|
let host = HostAlias::new("edge");
|
|
let mut app = AppState::new(Location::local("/workspace"));
|
|
let initial = one_listing(app.reduce(Command::Refresh));
|
|
finish_listing(&mut app, initial, vec![file("local")]);
|
|
app.reduce(Command::TogglePaneMode);
|
|
let right = app.pane(PaneId::Right).clone();
|
|
|
|
let home = Location::ssh(host.clone(), "/home/user");
|
|
let listing = connect(&mut app, &host, home.clone(), 3);
|
|
|
|
assert_eq!(app.active, PaneId::Left);
|
|
assert_eq!(app.pane(PaneId::Left).location, right.location);
|
|
assert_eq!(app.pane(PaneId::Left).entries, right.entries);
|
|
assert_eq!(app.pane(PaneId::Left).session_epoch, Some(3));
|
|
assert_eq!(app.pane(PaneId::Right), &right);
|
|
|
|
finish_listing(&mut app, listing, vec![file("remote")]);
|
|
assert_eq!(app.pane(PaneId::Left).location, home);
|
|
assert_eq!(app.pane(PaneId::Right), &right);
|
|
}
|
|
|
|
#[test]
|
|
fn connect_failure_preserves_both_existing_panes() {
|
|
let host = HostAlias::new("unavailable");
|
|
let mut app = AppState::new(Location::local("/workspace"));
|
|
let initial = one_listing(app.reduce(Command::Refresh));
|
|
finish_listing(&mut app, initial, vec![file("first"), file("second")]);
|
|
app.reduce(Command::SelectLast);
|
|
app.reduce(Command::TogglePaneMode);
|
|
let right = app.pane(PaneId::Right).clone();
|
|
let location = app.pane(PaneId::Left).location.clone();
|
|
let entries = app.pane(PaneId::Left).entries.clone();
|
|
let selection = app.pane(PaneId::Left).selection;
|
|
let preview = app.pane(PaneId::Left).preview.clone();
|
|
|
|
let request = one_connect(app.reduce(Command::ConnectSsh(host)));
|
|
assert!(app.active_pane().loading);
|
|
let effects = app.reduce(Command::ConnectSshFinished(
|
|
request.into_result(Err(FsError::AuthFailed)),
|
|
));
|
|
|
|
assert!(effects.is_empty());
|
|
let active = app.active_pane();
|
|
assert_eq!(active.location, location);
|
|
assert_eq!(active.entries, entries);
|
|
assert_eq!(active.selection, selection);
|
|
assert_eq!(active.preview.target, preview.target);
|
|
assert_eq!(active.preview.content, preview.content);
|
|
assert_eq!(active.preview.error, preview.error);
|
|
assert!(!active.preview.loading);
|
|
assert_eq!(active.session_epoch, None);
|
|
assert_eq!(active.error, Some(FsError::AuthFailed));
|
|
assert!(!active.loading);
|
|
assert_eq!(app.pane(PaneId::Right), &right);
|
|
assert!(!app.should_quit);
|
|
}
|
|
|
|
#[test]
|
|
fn old_epoch_response_cannot_update_reconnected_pane() {
|
|
let host = HostAlias::new("edge");
|
|
let home = Location::ssh(host.clone(), "/home/user");
|
|
let mut app = AppState::new(home.clone());
|
|
let initial = connect(&mut app, &host, home.clone(), 1);
|
|
let old_preview = one_preview(finish_listing(&mut app, initial, vec![file("original")]));
|
|
app.reduce(Command::PreviewFinished(
|
|
old_preview
|
|
.clone()
|
|
.into_result(Ok(preview_bytes(b"original preview", false))),
|
|
));
|
|
let old_listing = one_listing(app.reduce(Command::Refresh));
|
|
assert_eq!(old_listing.session_epoch, Some(1));
|
|
assert_eq!(old_preview.session_epoch, Some(1));
|
|
|
|
let new_listing = connect(&mut app, &host, home, 2);
|
|
assert_eq!(new_listing.session_epoch, Some(2));
|
|
assert_eq!(app.active_pane().session_epoch, Some(2));
|
|
assert_eq!(app.active_pane().entries, vec![file("original")]);
|
|
assert_eq!(
|
|
app.active_pane().preview.content,
|
|
Some(preview_bytes(b"original preview", false))
|
|
);
|
|
|
|
assert!(
|
|
app.reduce(Command::ListingFinished(
|
|
old_listing
|
|
.clone()
|
|
.into_result(Ok(vec![file("stale listing")])),
|
|
))
|
|
.is_empty()
|
|
);
|
|
assert!(
|
|
app.reduce(Command::PreviewFinished(
|
|
old_preview
|
|
.clone()
|
|
.into_result(Ok(preview_bytes(b"stale preview", false))),
|
|
))
|
|
.is_empty()
|
|
);
|
|
assert_eq!(app.active_pane().entries, vec![file("original")]);
|
|
assert_eq!(
|
|
app.active_pane().preview.content,
|
|
Some(preview_bytes(b"original preview", false))
|
|
);
|
|
|
|
let new_preview = one_preview(finish_listing(
|
|
&mut app,
|
|
new_listing,
|
|
vec![file("fresh listing")],
|
|
));
|
|
assert_eq!(new_preview.session_epoch, Some(2));
|
|
app.reduce(Command::ListingFinished(
|
|
old_listing.into_result(Ok(vec![file("late stale listing")])),
|
|
));
|
|
app.reduce(Command::PreviewFinished(
|
|
old_preview.into_result(Ok(preview_bytes(b"late stale preview", false))),
|
|
));
|
|
assert_eq!(app.active_pane().entries, vec![file("fresh listing")]);
|
|
assert_eq!(app.active_pane().preview.content, None);
|
|
assert!(app.active_pane().preview.loading);
|
|
}
|
|
|
|
#[test]
|
|
fn reconnect_invalidates_old_epoch_in_both_panes() {
|
|
let host = HostAlias::new("edge");
|
|
let home = Location::ssh(host.clone(), "/home/user");
|
|
let mut app = AppState::new(home.clone());
|
|
app.reduce(Command::TogglePaneMode);
|
|
|
|
let left_initial = connect(&mut app, &host, home.clone(), 10);
|
|
let left_old_preview = one_preview(finish_listing(
|
|
&mut app,
|
|
left_initial,
|
|
vec![file("left original")],
|
|
));
|
|
app.reduce(Command::SwitchPane);
|
|
let right_initial = connect(&mut app, &host, home.clone(), 10);
|
|
let right_old_preview = one_preview(finish_listing(
|
|
&mut app,
|
|
right_initial,
|
|
vec![file("right original")],
|
|
));
|
|
let right_old_listing = one_listing(app.reduce(Command::Refresh));
|
|
app.reduce(Command::SwitchPane);
|
|
let left_old_listing = one_listing(app.reduce(Command::Refresh));
|
|
assert_eq!(left_old_listing.session_epoch, Some(10));
|
|
assert_eq!(right_old_listing.session_epoch, Some(10));
|
|
|
|
let left_connect = one_connect(app.reduce(Command::ConnectSsh(host.clone())));
|
|
app.reduce(Command::SynchronizeSshEpoch {
|
|
host: host.clone(),
|
|
session_epoch: 11,
|
|
});
|
|
let left_new_listing = one_listing(app.reduce(Command::ConnectSshFinished(
|
|
left_connect.into_result(Ok(SshConnection {
|
|
location: home,
|
|
session_epoch: 11,
|
|
})),
|
|
)));
|
|
assert_eq!(app.pane(PaneId::Left).session_epoch, Some(11));
|
|
assert_eq!(app.pane(PaneId::Right).session_epoch, Some(11));
|
|
assert_eq!(
|
|
app.pane(PaneId::Right).entries,
|
|
vec![file("right original")]
|
|
);
|
|
|
|
for (listing, preview) in [
|
|
(left_old_listing, left_old_preview),
|
|
(right_old_listing, right_old_preview),
|
|
] {
|
|
assert!(
|
|
app.reduce(Command::ListingFinished(
|
|
listing.into_result(Ok(vec![file("stale remote data")])),
|
|
))
|
|
.is_empty()
|
|
);
|
|
assert!(
|
|
app.reduce(Command::PreviewFinished(
|
|
preview.into_result(Ok(preview_bytes(b"stale remote preview", false))),
|
|
))
|
|
.is_empty()
|
|
);
|
|
}
|
|
|
|
assert_eq!(app.pane(PaneId::Left).entries, vec![file("left original")]);
|
|
assert_eq!(
|
|
app.pane(PaneId::Right).entries,
|
|
vec![file("right original")]
|
|
);
|
|
assert_eq!(app.pane(PaneId::Left).preview.content, None);
|
|
assert_eq!(app.pane(PaneId::Right).preview.content, None);
|
|
|
|
finish_listing(&mut app, left_new_listing, vec![file("left fresh data")]);
|
|
app.reduce(Command::SwitchPane);
|
|
let right_new_listing = one_listing(app.reduce(Command::Refresh));
|
|
assert_eq!(right_new_listing.session_epoch, Some(11));
|
|
assert_eq!(
|
|
app.pane(PaneId::Left).entries,
|
|
vec![file("left fresh data")]
|
|
);
|
|
}
|
|
|
|
fn assert_failed_initial_home_listing_preserves_confirmed_pane(error: FsError) {
|
|
let host = HostAlias::new("edge");
|
|
let home = Location::ssh(host.clone(), "/home/user");
|
|
let mut app = AppState::new(home.clone());
|
|
let initial = connect(&mut app, &host, home.clone(), 7);
|
|
let first_preview = one_preview(finish_listing(
|
|
&mut app,
|
|
initial,
|
|
vec![file("first"), file("second")],
|
|
));
|
|
app.reduce(Command::PreviewFinished(
|
|
first_preview.into_result(Ok(preview_bytes(b"first preview", false))),
|
|
));
|
|
let second_preview = one_preview(app.reduce(Command::SelectLast));
|
|
app.reduce(Command::PreviewFinished(
|
|
second_preview.into_result(Ok(preview_bytes(b"second preview", false))),
|
|
));
|
|
app.reduce(Command::TogglePaneMode);
|
|
let confirmed = app.pane(PaneId::Left).clone();
|
|
let right = app.pane(PaneId::Right).clone();
|
|
|
|
let reconnect = one_connect(app.reduce(Command::ConnectSsh(host.clone())));
|
|
app.reduce(Command::SynchronizeSshEpoch {
|
|
host: host.clone(),
|
|
session_epoch: 8,
|
|
});
|
|
let home_listing = one_listing(
|
|
app.reduce(Command::ConnectSshFinished(reconnect.into_result(Ok(
|
|
SshConnection {
|
|
location: home,
|
|
session_epoch: 8,
|
|
},
|
|
)))),
|
|
);
|
|
assert_eq!(home_listing.session_epoch, Some(8));
|
|
assert_eq!(app.pane(PaneId::Left).session_epoch, Some(8));
|
|
assert_eq!(app.pane(PaneId::Left).location, confirmed.location);
|
|
assert_eq!(app.pane(PaneId::Left).entries, confirmed.entries);
|
|
assert_eq!(app.pane(PaneId::Left).selection, confirmed.selection);
|
|
assert_eq!(app.pane(PaneId::Left).preview, confirmed.preview);
|
|
assert_eq!(app.pane(PaneId::Right).location, right.location);
|
|
assert_eq!(app.pane(PaneId::Right).entries, right.entries);
|
|
assert_eq!(app.pane(PaneId::Right).selection, right.selection);
|
|
assert_eq!(app.pane(PaneId::Right).session_epoch, Some(8));
|
|
|
|
assert!(
|
|
app.reduce(Command::ListingFinished(
|
|
home_listing.into_result(Err(error.clone())),
|
|
))
|
|
.is_empty()
|
|
);
|
|
|
|
let failed = app.pane(PaneId::Left);
|
|
assert_eq!(failed.location, confirmed.location);
|
|
assert_eq!(failed.entries, confirmed.entries);
|
|
assert_eq!(failed.selection, confirmed.selection);
|
|
assert_eq!(failed.show_hidden, confirmed.show_hidden);
|
|
assert_eq!(failed.preview, confirmed.preview);
|
|
assert_eq!(failed.preview_generation, confirmed.preview_generation);
|
|
assert_eq!(failed.session_epoch, Some(8));
|
|
assert_eq!(failed.error, Some(error));
|
|
assert_eq!(failed.pending_target, None);
|
|
assert!(!failed.loading);
|
|
assert_eq!(app.pane(PaneId::Right).location, right.location);
|
|
assert_eq!(app.pane(PaneId::Right).entries, right.entries);
|
|
assert_eq!(app.pane(PaneId::Right).selection, right.selection);
|
|
assert_eq!(app.pane(PaneId::Right).session_epoch, Some(8));
|
|
|
|
let retry = one_listing(app.reduce(Command::Refresh));
|
|
assert_eq!(retry.target, confirmed.location);
|
|
assert_eq!(retry.session_epoch, Some(8));
|
|
}
|
|
|
|
#[test]
|
|
fn failed_initial_home_listing_permission_denied_preserves_confirmed_pane() {
|
|
assert_failed_initial_home_listing_preserves_confirmed_pane(FsError::PermissionDenied);
|
|
}
|
|
|
|
#[test]
|
|
fn failed_initial_home_listing_not_found_preserves_confirmed_pane() {
|
|
assert_failed_initial_home_listing_preserves_confirmed_pane(FsError::NotFound);
|
|
}
|
|
|
|
#[test]
|
|
fn failed_initial_home_listing_timeout_preserves_confirmed_pane() {
|
|
assert_failed_initial_home_listing_preserves_confirmed_pane(FsError::Timeout);
|
|
}
|
|
|
|
#[test]
|
|
fn failed_initial_home_listing_disconnected_preserves_confirmed_pane() {
|
|
assert_failed_initial_home_listing_preserves_confirmed_pane(FsError::Disconnected);
|
|
}
|
|
|
|
#[test]
|
|
fn canceled_connect_synchronizes_epoch_for_second_pane_refresh() {
|
|
let host = HostAlias::new("edge");
|
|
let home = Location::ssh(host.clone(), "/home/user");
|
|
let mut app = AppState::new(home.clone());
|
|
app.reduce(Command::TogglePaneMode);
|
|
|
|
let left_initial = connect(&mut app, &host, home.clone(), 10);
|
|
finish_listing(&mut app, left_initial, vec![file("left")]);
|
|
app.reduce(Command::SwitchPane);
|
|
let right_initial = connect(&mut app, &host, home.clone(), 10);
|
|
finish_listing(&mut app, right_initial, vec![file("right")]);
|
|
let right_old_listing = one_listing(app.reduce(Command::Refresh));
|
|
app.reduce(Command::SwitchPane);
|
|
let left_confirmed = app.pane(PaneId::Left).clone();
|
|
let right_confirmed = app.pane(PaneId::Right).clone();
|
|
|
|
let canceled_connect = one_connect(app.reduce(Command::ConnectSsh(host.clone())));
|
|
let canceled_left_refresh = one_listing(app.reduce(Command::Refresh));
|
|
assert_eq!(canceled_left_refresh.session_epoch, Some(10));
|
|
|
|
assert!(
|
|
app.reduce(Command::SynchronizeSshEpoch {
|
|
host: host.clone(),
|
|
session_epoch: 11,
|
|
})
|
|
.is_empty()
|
|
);
|
|
assert_eq!(app.pane(PaneId::Left).session_epoch, Some(11));
|
|
assert_eq!(app.pane(PaneId::Right).session_epoch, Some(11));
|
|
assert_eq!(app.pane(PaneId::Left).location, left_confirmed.location);
|
|
assert_eq!(app.pane(PaneId::Left).entries, left_confirmed.entries);
|
|
assert_eq!(app.pane(PaneId::Left).selection, left_confirmed.selection);
|
|
assert_eq!(app.pane(PaneId::Right).location, right_confirmed.location);
|
|
assert_eq!(app.pane(PaneId::Right).entries, right_confirmed.entries);
|
|
assert_eq!(app.pane(PaneId::Right).selection, right_confirmed.selection);
|
|
|
|
assert!(
|
|
app.reduce(Command::ConnectSshFinished(canceled_connect.into_result(
|
|
Ok(SshConnection {
|
|
location: home,
|
|
session_epoch: 11,
|
|
})
|
|
),))
|
|
.is_empty()
|
|
);
|
|
for old_listing in [canceled_left_refresh, right_old_listing] {
|
|
assert!(
|
|
app.reduce(Command::ListingFinished(
|
|
old_listing.into_result(Ok(vec![file("stale")])),
|
|
))
|
|
.is_empty()
|
|
);
|
|
}
|
|
|
|
app.reduce(Command::SwitchPane);
|
|
let right_refresh = one_listing(app.reduce(Command::Refresh));
|
|
assert_eq!(right_refresh.session_epoch, Some(11));
|
|
assert_eq!(right_refresh.target, right_confirmed.location);
|
|
assert_eq!(app.pane(PaneId::Left).location, left_confirmed.location);
|
|
}
|
|
|
|
#[test]
|
|
fn failed_initial_home_listing_from_local_uses_local_retry() {
|
|
let host = HostAlias::new("edge");
|
|
let mut app = AppState::new(Location::local("/workspace"));
|
|
let initial = one_listing(app.reduce(Command::Refresh));
|
|
finish_listing(&mut app, initial, vec![file("local")]);
|
|
let confirmed = app.active_pane().clone();
|
|
|
|
let home_listing = connect(
|
|
&mut app,
|
|
&host,
|
|
Location::ssh(host.clone(), "/home/user"),
|
|
8,
|
|
);
|
|
app.reduce(Command::ListingFinished(
|
|
home_listing.into_result(Err(FsError::PermissionDenied)),
|
|
));
|
|
|
|
assert_eq!(app.active_pane().location, confirmed.location);
|
|
assert_eq!(app.active_pane().entries, confirmed.entries);
|
|
assert_eq!(app.active_pane().session_epoch, None);
|
|
let retry = one_listing(app.reduce(Command::Refresh));
|
|
assert_eq!(retry.target, confirmed.location);
|
|
assert_eq!(retry.session_epoch, None);
|
|
}
|
|
|
|
#[test]
|
|
fn failed_initial_home_listing_to_another_host_restores_previous_routing() {
|
|
let original = HostAlias::new("edge-a");
|
|
let attempted = HostAlias::new("edge-b");
|
|
let original_home = Location::ssh(original.clone(), "/home/a");
|
|
let mut app = AppState::new(original_home.clone());
|
|
let initial = connect(&mut app, &original, original_home.clone(), 7);
|
|
finish_listing(&mut app, initial, vec![file("original")]);
|
|
let confirmed = app.active_pane().clone();
|
|
|
|
let attempted_home = Location::ssh(attempted.clone(), "/home/b");
|
|
let reconnect = one_connect(app.reduce(Command::ConnectSsh(attempted.clone())));
|
|
let attempted_listing = one_listing(app.reduce(Command::ConnectSshFinished(
|
|
reconnect.into_result(Ok(SshConnection {
|
|
location: attempted_home,
|
|
session_epoch: 8,
|
|
})),
|
|
)));
|
|
app.reduce(Command::ListingFinished(
|
|
attempted_listing.into_result(Err(FsError::Disconnected)),
|
|
));
|
|
|
|
assert_eq!(app.active_pane().location, confirmed.location);
|
|
assert_eq!(app.active_pane().entries, confirmed.entries);
|
|
assert_eq!(app.active_pane().session_epoch, Some(7));
|
|
let retry = one_listing(app.reduce(Command::Refresh));
|
|
assert_eq!(retry.target, confirmed.location);
|
|
assert_eq!(retry.session_epoch, Some(7));
|
|
}
|
|
|
|
#[test]
|
|
fn pending_home_listing_is_superseded_by_a_newer_epoch() {
|
|
let host = HostAlias::new("edge");
|
|
let mut app = AppState::new(Location::local("/workspace"));
|
|
let initial = one_listing(app.reduce(Command::Refresh));
|
|
finish_listing(&mut app, initial, vec![file("local")]);
|
|
let confirmed = app.active_pane().clone();
|
|
let home_listing = connect(
|
|
&mut app,
|
|
&host,
|
|
Location::ssh(host.clone(), "/home/user"),
|
|
1,
|
|
);
|
|
|
|
app.reduce(Command::SynchronizeSshEpoch {
|
|
host: host.clone(),
|
|
session_epoch: 2,
|
|
});
|
|
assert_eq!(app.active_pane().session_epoch, None);
|
|
assert_eq!(app.active_pane().pending_target, None);
|
|
assert!(!app.active_pane().loading);
|
|
|
|
assert!(
|
|
app.reduce(Command::ListingFinished(
|
|
home_listing.into_result(Ok(vec![file("stale remote")])),
|
|
))
|
|
.is_empty()
|
|
);
|
|
assert_eq!(app.active_pane().location, confirmed.location);
|
|
assert_eq!(app.active_pane().entries, confirmed.entries);
|
|
}
|
|
|
|
#[test]
|
|
fn epoch_synchronization_is_monotonic() {
|
|
let host = HostAlias::new("edge");
|
|
let home = Location::ssh(host.clone(), "/home/user");
|
|
let mut app = AppState::new(home.clone());
|
|
let initial = connect(&mut app, &host, home, 3);
|
|
finish_listing(&mut app, initial, vec![file("current")]);
|
|
|
|
app.reduce(Command::SynchronizeSshEpoch {
|
|
host,
|
|
session_epoch: 2,
|
|
});
|
|
|
|
assert_eq!(app.active_pane().session_epoch, Some(3));
|
|
assert_eq!(app.active_pane().entries, vec![file("current")]);
|
|
}
|
|
|
|
#[test]
|
|
fn superseded_connect_clears_loading_instead_of_leaving_spinner() {
|
|
let host = HostAlias::new("edge");
|
|
let home = Location::ssh(host.clone(), "/home/user");
|
|
let mut app = AppState::new(home.clone());
|
|
let initial = connect(&mut app, &host, home.clone(), 1);
|
|
finish_listing(&mut app, initial, vec![file("current")]);
|
|
let _preview = one_preview(app.reduce(Command::OpenPreview));
|
|
assert!(app.active_pane().preview.loading);
|
|
let reconnect = one_connect(app.reduce(Command::ConnectSsh(host.clone())));
|
|
app.reduce(Command::SynchronizeSshEpoch {
|
|
host: host.clone(),
|
|
session_epoch: 2,
|
|
});
|
|
|
|
assert!(
|
|
app.reduce(Command::ConnectSshFinished(reconnect.into_result(Ok(
|
|
SshConnection {
|
|
location: home,
|
|
session_epoch: 1,
|
|
},
|
|
))))
|
|
.is_empty()
|
|
);
|
|
let pane = app.active_pane();
|
|
assert!(!pane.loading);
|
|
assert!(!pane.preview.loading);
|
|
assert_eq!(pane.pending_target, None);
|
|
assert_eq!(pane.session_epoch, Some(2));
|
|
}
|
|
|
|
#[test]
|
|
fn cross_endpoint_rollback_uses_latest_confirmed_epoch() {
|
|
let original = HostAlias::new("edge-a");
|
|
let attempted = HostAlias::new("edge-b");
|
|
let original_home = Location::ssh(original.clone(), "/home/a");
|
|
let mut app = AppState::new(original_home.clone());
|
|
let initial = connect(&mut app, &original, original_home.clone(), 1);
|
|
finish_listing(&mut app, initial, vec![file("original")]);
|
|
let reconnect = one_connect(app.reduce(Command::ConnectSsh(attempted.clone())));
|
|
app.reduce(Command::SynchronizeSshEpoch {
|
|
host: original.clone(),
|
|
session_epoch: 2,
|
|
});
|
|
let attempted_listing = one_listing(app.reduce(Command::ConnectSshFinished(
|
|
reconnect.into_result(Ok(SshConnection {
|
|
location: Location::ssh(attempted.clone(), "/home/b"),
|
|
session_epoch: 8,
|
|
})),
|
|
)));
|
|
app.reduce(Command::ListingFinished(
|
|
attempted_listing.into_result(Err(FsError::PermissionDenied)),
|
|
));
|
|
|
|
assert_eq!(app.active_pane().location, original_home);
|
|
assert_eq!(app.active_pane().session_epoch, Some(2));
|
|
let retry = one_listing(app.reduce(Command::Refresh));
|
|
assert_eq!(retry.target, original_home);
|
|
assert_eq!(retry.session_epoch, Some(2));
|
|
}
|
|
|
|
#[test]
|
|
fn cached_connection_to_another_host_is_not_superseded_by_number() {
|
|
let original = HostAlias::new("edge-a");
|
|
let attempted = HostAlias::new("edge-b");
|
|
let original_home = Location::ssh(original.clone(), "/home/a");
|
|
let attempted_home = Location::ssh(attempted.clone(), "/home/b");
|
|
let mut app = AppState::new(original_home.clone());
|
|
let initial = connect(&mut app, &original, original_home, 2);
|
|
finish_listing(&mut app, initial, vec![file("original")]);
|
|
let reconnect = one_connect(app.reduce(Command::ConnectSsh(attempted.clone())));
|
|
app.reduce(Command::SynchronizeSshEpoch {
|
|
host: attempted.clone(),
|
|
session_epoch: 1,
|
|
});
|
|
|
|
let effects = app.reduce(Command::ConnectSshFinished(reconnect.into_result(Ok(
|
|
SshConnection {
|
|
location: attempted_home,
|
|
session_epoch: 1,
|
|
},
|
|
))));
|
|
|
|
assert_eq!(effects.len(), 1);
|
|
assert_eq!(app.active_pane().session_epoch, Some(1));
|
|
}
|
|
|
|
#[test]
|
|
fn production_sync_order_cross_endpoint_rollback_preserves_original_session() {
|
|
let original = HostAlias::new("edge-a");
|
|
let attempted = HostAlias::new("edge-b");
|
|
let original_home = Location::ssh(original.clone(), "/home/a");
|
|
let attempted_home = Location::ssh(attempted.clone(), "/home/b");
|
|
let mut app = AppState::new(original_home.clone());
|
|
let initial = connect(&mut app, &original, original_home.clone(), 1);
|
|
finish_listing(&mut app, initial, vec![file("original")]);
|
|
let reconnect = one_connect(app.reduce(Command::ConnectSsh(attempted.clone())));
|
|
|
|
app.reduce(Command::SynchronizeSshEpoch {
|
|
host: attempted.clone(),
|
|
session_epoch: 2,
|
|
});
|
|
let attempted_listing = one_listing(app.reduce(Command::ConnectSshFinished(
|
|
reconnect.into_result(Ok(SshConnection {
|
|
location: attempted_home,
|
|
session_epoch: 2,
|
|
})),
|
|
)));
|
|
app.reduce(Command::ListingFinished(
|
|
attempted_listing.into_result(Err(FsError::PermissionDenied)),
|
|
));
|
|
|
|
assert_eq!(app.active_pane().location, original_home);
|
|
assert_eq!(app.active_pane().session_epoch, Some(1));
|
|
let retry = one_listing(app.reduce(Command::Refresh));
|
|
assert_eq!(retry.target, original_home);
|
|
assert_eq!(retry.session_epoch, Some(1));
|
|
}
|
|
|
|
#[test]
|
|
fn cross_endpoint_pending_cancel_restores_original_session() {
|
|
let original = HostAlias::new("edge-a");
|
|
let attempted = HostAlias::new("edge-b");
|
|
let original_home = Location::ssh(original.clone(), "/home/a");
|
|
let mut app = AppState::new(original_home.clone());
|
|
let initial = connect(&mut app, &original, original_home.clone(), 1);
|
|
finish_listing(&mut app, initial, vec![file("original")]);
|
|
let _pending = connect(
|
|
&mut app,
|
|
&attempted,
|
|
Location::ssh(attempted.clone(), "/home/b"),
|
|
1,
|
|
);
|
|
|
|
app.reduce(Command::SynchronizeSshEpoch {
|
|
host: attempted.clone(),
|
|
session_epoch: 2,
|
|
});
|
|
|
|
assert_eq!(app.active_pane().location, original_home);
|
|
assert_eq!(app.active_pane().session_epoch, Some(1));
|
|
assert_eq!(app.active_pane().pending_target, None);
|
|
assert!(!app.active_pane().loading);
|
|
let retry = one_listing(app.reduce(Command::Refresh));
|
|
assert_eq!(retry.target, original_home);
|
|
assert_eq!(retry.session_epoch, Some(1));
|
|
}
|
|
|
|
#[test]
|
|
fn connect_error_restores_original_session_and_stops_preview_loading() {
|
|
let original = HostAlias::new("edge-a");
|
|
let attempted = HostAlias::new("edge-b");
|
|
let original_home = Location::ssh(original.clone(), "/home/a");
|
|
let mut app = AppState::new(original_home.clone());
|
|
let initial = connect(&mut app, &original, original_home.clone(), 1);
|
|
let _preview = one_preview(finish_listing(&mut app, initial, vec![file("original")]));
|
|
assert!(app.active_pane().preview.loading);
|
|
let reconnect = one_connect(app.reduce(Command::ConnectSsh(attempted.clone())));
|
|
app.reduce(Command::SynchronizeSshEpoch {
|
|
host: attempted.clone(),
|
|
session_epoch: 2,
|
|
});
|
|
|
|
assert!(
|
|
app.reduce(Command::ConnectSshFinished(
|
|
reconnect.into_result(Err(FsError::AuthFailed,))
|
|
))
|
|
.is_empty()
|
|
);
|
|
let pane = app.active_pane();
|
|
assert_eq!(pane.location, original_home);
|
|
assert_eq!(pane.session_epoch, Some(1));
|
|
assert_eq!(pane.error, Some(FsError::AuthFailed));
|
|
assert!(!pane.loading);
|
|
assert!(!pane.preview.loading);
|
|
}
|
|
|
|
#[test]
|
|
fn stale_confirmed_sync_does_not_cancel_newer_pending_endpoint() {
|
|
let original = HostAlias::new("edge-a");
|
|
let attempted = HostAlias::new("edge-b");
|
|
let original_home = Location::ssh(original.clone(), "/home/a");
|
|
let attempted_home = Location::ssh(attempted.clone(), "/home/b");
|
|
let mut app = AppState::new(original_home.clone());
|
|
let initial = connect(&mut app, &original, original_home.clone(), 5);
|
|
finish_listing(&mut app, initial, vec![file("original")]);
|
|
let _pending = connect(&mut app, &attempted, attempted_home.clone(), 7);
|
|
|
|
app.reduce(Command::SynchronizeSshEpoch {
|
|
host: original,
|
|
session_epoch: 3,
|
|
});
|
|
|
|
assert_eq!(app.active_pane().pending_target, Some(attempted_home));
|
|
assert_eq!(app.active_pane().session_epoch, Some(7));
|
|
assert_eq!(app.pane(PaneId::Left).location, original_home);
|
|
}
|
|
|
|
#[test]
|
|
fn confirmed_refresh_during_pending_other_host_restores_original_request() {
|
|
let original = HostAlias::new("edge-a");
|
|
let attempted = HostAlias::new("edge-b");
|
|
let original_home = Location::ssh(original.clone(), "/home/a");
|
|
let attempted_home = Location::ssh(attempted.clone(), "/home/b");
|
|
let mut app = AppState::new(original_home.clone());
|
|
let initial = connect(&mut app, &original, original_home.clone(), 1);
|
|
finish_listing(&mut app, initial, vec![file("original")]);
|
|
let pending = connect(&mut app, &attempted, attempted_home, 2);
|
|
|
|
let retry = one_listing(app.reduce(Command::Refresh));
|
|
assert_eq!(retry.target, original_home);
|
|
assert_eq!(retry.session_epoch, Some(1));
|
|
assert!(app.active_pane().loading);
|
|
|
|
assert!(
|
|
app.reduce(Command::ListingFinished(
|
|
pending.into_result(Err(FsError::Disconnected)),
|
|
))
|
|
.is_empty()
|
|
);
|
|
assert!(app.active_pane().loading);
|
|
finish_listing(&mut app, retry, vec![file("confirmed")]);
|
|
assert_eq!(app.active_pane().location, original_home);
|
|
assert_eq!(app.active_pane().entries, vec![file("confirmed")]);
|
|
}
|
|
|
|
#[test]
|
|
fn confirmed_preview_during_pending_other_host_uses_original_session() {
|
|
let original = HostAlias::new("edge-a");
|
|
let attempted = HostAlias::new("edge-b");
|
|
let original_home = Location::ssh(original.clone(), "/home/a");
|
|
let mut app = AppState::new(original_home.clone());
|
|
let initial = connect(&mut app, &original, original_home.clone(), 1);
|
|
finish_listing(&mut app, initial, vec![file("original")]);
|
|
let _pending = connect(
|
|
&mut app,
|
|
&attempted,
|
|
Location::ssh(attempted.clone(), "/home/b"),
|
|
2,
|
|
);
|
|
|
|
let preview = one_preview(app.reduce(Command::OpenPreview));
|
|
assert_eq!(preview.target, original_home.join("original"));
|
|
assert_eq!(preview.session_epoch, Some(1));
|
|
assert_eq!(app.active_pane().location, original_home);
|
|
assert_eq!(app.active_pane().session_epoch, Some(1));
|
|
}
|
|
|
|
#[test]
|
|
fn reconnect_to_confirmed_host_normalizes_previous_pending_endpoint() {
|
|
let original = HostAlias::new("edge-a");
|
|
let attempted = HostAlias::new("edge-b");
|
|
let original_home = Location::ssh(original.clone(), "/home/a");
|
|
let mut app = AppState::new(original_home.clone());
|
|
let initial = connect(&mut app, &original, original_home.clone(), 1);
|
|
finish_listing(&mut app, initial, vec![file("original")]);
|
|
let _pending = connect(
|
|
&mut app,
|
|
&attempted,
|
|
Location::ssh(attempted.clone(), "/home/b"),
|
|
2,
|
|
);
|
|
|
|
let reconnect = one_connect(app.reduce(Command::ConnectSsh(original.clone())));
|
|
assert_eq!(reconnect.expected_session_epoch, Some(1));
|
|
assert!(
|
|
app.reduce(Command::ConnectSshFinished(
|
|
reconnect.into_result(Err(FsError::AuthFailed,))
|
|
))
|
|
.is_empty()
|
|
);
|
|
let pane = app.active_pane();
|
|
assert_eq!(pane.location, original_home);
|
|
assert_eq!(pane.session_epoch, Some(1));
|
|
assert_eq!(pane.error, Some(FsError::AuthFailed));
|
|
assert!(!pane.loading);
|
|
assert!(!pane.preview.loading);
|
|
let retry = one_listing(app.reduce(Command::Refresh));
|
|
assert_eq!(retry.target, original_home);
|
|
assert_eq!(retry.session_epoch, Some(1));
|
|
}
|
|
|
|
#[test]
|
|
fn failed_home_listing_stops_obsolete_preview_loading() {
|
|
let host = HostAlias::new("edge");
|
|
let home = Location::ssh(host.clone(), "/home/user");
|
|
let mut app = AppState::new(home.clone());
|
|
let initial = connect(&mut app, &host, home.clone(), 1);
|
|
let _preview = one_preview(finish_listing(&mut app, initial, vec![file("current")]));
|
|
assert!(app.active_pane().preview.loading);
|
|
let reconnect = one_connect(app.reduce(Command::ConnectSsh(host.clone())));
|
|
let attempted = one_listing(
|
|
app.reduce(Command::ConnectSshFinished(reconnect.into_result(Ok(
|
|
SshConnection {
|
|
location: home,
|
|
session_epoch: 2,
|
|
},
|
|
)))),
|
|
);
|
|
app.reduce(Command::ListingFinished(
|
|
attempted.into_result(Err(FsError::PermissionDenied)),
|
|
));
|
|
|
|
assert!(!app.active_pane().preview.loading);
|
|
}
|