2026-12-06 05:11:31 +03:00
|
|
|
use std::io::Cursor;
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
|
|
use image::{DynamicImage, ImageBuffer, ImageFormat, Rgba};
|
|
|
|
|
use ratatui::{Terminal, backend::TestBackend};
|
|
|
|
|
use rcom::app::{Command, Overlay, PaneId};
|
|
|
|
|
use rcom::domain::Location;
|
|
|
|
|
use rcom::fs::BackendRegistry;
|
|
|
|
|
use rcom::image_preview::{ImageEngine, ImageProtocolFactory, ImageRenderContext};
|
|
|
|
|
use rcom::preview::{EncodedImage, Preview, PreviewKind};
|
|
|
|
|
use rcom::session::Application;
|
|
|
|
|
use rcom::ssh::{ConnectionManager, DiscoveryResult, OpenSshConnector};
|
|
|
|
|
use rcom::test_support::MemoryFs;
|
|
|
|
|
use rcom::ui::{IconMode, Theme, render_with_context};
|
|
|
|
|
|
|
|
|
|
fn png() -> Vec<u8> {
|
|
|
|
|
let mut pixels = ImageBuffer::from_pixel(10, 20, Rgba([255, 0, 0, 255]));
|
|
|
|
|
for (x, y, pixel) in pixels.enumerate_pixels_mut() {
|
|
|
|
|
if y >= 10 {
|
|
|
|
|
*pixel = Rgba([0, 0, 255, 255]);
|
|
|
|
|
}
|
|
|
|
|
let _ = x;
|
|
|
|
|
}
|
|
|
|
|
let image = DynamicImage::ImageRgba8(pixels);
|
|
|
|
|
let mut cursor = Cursor::new(Vec::new());
|
|
|
|
|
image.write_to(&mut cursor, ImageFormat::Png).unwrap();
|
|
|
|
|
cursor.into_inner()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn changed_png() -> Vec<u8> {
|
|
|
|
|
let mut pixels = ImageBuffer::from_pixel(10, 20, Rgba([0, 0, 255, 255]));
|
|
|
|
|
for (_, y, pixel) in pixels.enumerate_pixels_mut() {
|
|
|
|
|
if y >= 10 {
|
|
|
|
|
*pixel = Rgba([0, 255, 0, 255]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let mut cursor = Cursor::new(Vec::new());
|
|
|
|
|
DynamicImage::ImageRgba8(pixels)
|
|
|
|
|
.write_to(&mut cursor, ImageFormat::Png)
|
|
|
|
|
.unwrap();
|
|
|
|
|
cursor.into_inner()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn application() -> (Application, tokio::sync::mpsc::Receiver<Command>) {
|
|
|
|
|
let fs = MemoryFs::new().with_file(Location::local("/pixel.png"), png());
|
|
|
|
|
let registry = BackendRegistry::new(Arc::new(fs));
|
|
|
|
|
let connections = ConnectionManager::new(Arc::new(OpenSshConnector::default()), registry);
|
|
|
|
|
Application::new(
|
|
|
|
|
Location::local("/"),
|
|
|
|
|
connections,
|
|
|
|
|
DiscoveryResult::default(),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn dispatch_until(
|
|
|
|
|
app: &mut Application,
|
|
|
|
|
results: &mut tokio::sync::mpsc::Receiver<Command>,
|
|
|
|
|
predicate: impl Fn(&Command) -> bool,
|
|
|
|
|
) {
|
|
|
|
|
let command = tokio::time::timeout(Duration::from_secs(2), async {
|
|
|
|
|
loop {
|
|
|
|
|
let command = results.recv().await.unwrap();
|
|
|
|
|
if predicate(&command) {
|
|
|
|
|
return command;
|
|
|
|
|
}
|
|
|
|
|
app.dispatch(command);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.await
|
|
|
|
|
.unwrap();
|
|
|
|
|
app.dispatch(command);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn draw(app: &Application) -> ratatui::buffer::Buffer {
|
|
|
|
|
let cache = app.image_cache();
|
|
|
|
|
let cache = cache.lock().unwrap();
|
|
|
|
|
let factory = app.image_factory().unwrap();
|
|
|
|
|
let context = ImageRenderContext {
|
|
|
|
|
cache: &cache,
|
|
|
|
|
factory: &factory,
|
|
|
|
|
};
|
|
|
|
|
let area = app.terminal_area();
|
|
|
|
|
let mut terminal = Terminal::new(TestBackend::new(area.width, area.height)).unwrap();
|
|
|
|
|
terminal
|
|
|
|
|
.draw(|frame| {
|
|
|
|
|
render_with_context(
|
|
|
|
|
frame,
|
|
|
|
|
app.state(),
|
|
|
|
|
None,
|
|
|
|
|
&Theme::default().with_icon_mode(IconMode::None),
|
|
|
|
|
Some(context),
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
|
|
|
|
terminal.backend().buffer().clone()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn has_pixels(buffer: &ratatui::buffer::Buffer) -> bool {
|
|
|
|
|
buffer
|
|
|
|
|
.content()
|
|
|
|
|
.iter()
|
|
|
|
|
.any(|cell| matches!(cell.symbol(), "▀" | "▄"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn install_current_image(app: &mut Application, pane: PaneId, name: &str) {
|
|
|
|
|
let target = Location::local(format!("/{name}"));
|
|
|
|
|
let state = app.state_mut_for_test();
|
|
|
|
|
state.panes[pane.index()].entries = vec![rcom::domain::Entry::new(
|
|
|
|
|
name,
|
|
|
|
|
rcom::domain::EntryKind::File,
|
|
|
|
|
)];
|
|
|
|
|
state.panes[pane.index()].selection.set(Some(0), 1);
|
|
|
|
|
state.panes[pane.index()].preview.target = Some(target);
|
|
|
|
|
state.panes[pane.index()].preview.content = Some(Preview {
|
|
|
|
|
kind: PreviewKind::Image,
|
|
|
|
|
lines: vec!["Preparing".into()],
|
|
|
|
|
truncated: false,
|
2026-12-06 11:13:55 +03:00
|
|
|
directory_entries: Vec::new(),
|
2026-12-06 05:11:31 +03:00
|
|
|
});
|
|
|
|
|
state.panes[pane.index()].preview.encoded_image = Some(EncodedImage {
|
|
|
|
|
bytes: Arc::new(png()),
|
|
|
|
|
format: rcom::image_preview::SupportedImageFormat::Png,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
async fn rapid_image_selection_uses_shared_debounce_before_preparation() {
|
|
|
|
|
let fs = MemoryFs::new()
|
|
|
|
|
.with_file(Location::local("/a.png"), png())
|
|
|
|
|
.with_file(Location::local("/b.png"), png());
|
|
|
|
|
let registry = BackendRegistry::new(Arc::new(fs));
|
|
|
|
|
let connections = ConnectionManager::new(Arc::new(OpenSshConnector::default()), registry);
|
|
|
|
|
let (mut app, mut results) = Application::new(
|
|
|
|
|
Location::local("/"),
|
|
|
|
|
connections,
|
|
|
|
|
DiscoveryResult::default(),
|
|
|
|
|
);
|
|
|
|
|
app.configure_images(ImageEngine::Enabled(ImageProtocolFactory::Halfblocks));
|
|
|
|
|
app.update_terminal_area(ratatui::layout::Rect::new(0, 0, 120, 30));
|
|
|
|
|
app.dispatch(Command::Refresh);
|
|
|
|
|
dispatch_until(&mut app, &mut results, |command| {
|
|
|
|
|
matches!(command, Command::PreviewFinished(_))
|
|
|
|
|
})
|
|
|
|
|
.await;
|
|
|
|
|
dispatch_until(&mut app, &mut results, |command| {
|
|
|
|
|
matches!(command, Command::ImagePrepared(_))
|
|
|
|
|
})
|
|
|
|
|
.await;
|
|
|
|
|
let start = std::time::Instant::now();
|
|
|
|
|
app.dispatch_at(Command::MoveSelection(1), start);
|
|
|
|
|
assert_eq!(app.pending_preview_count(), 1);
|
|
|
|
|
assert!(matches!(
|
|
|
|
|
results.try_recv(),
|
|
|
|
|
Err(tokio::sync::mpsc::error::TryRecvError::Empty)
|
|
|
|
|
));
|
|
|
|
|
app.expire_pending_at(start + Duration::from_millis(40));
|
|
|
|
|
dispatch_until(&mut app, &mut results, |command| {
|
|
|
|
|
matches!(command, Command::PreviewFinished(_))
|
|
|
|
|
})
|
|
|
|
|
.await;
|
|
|
|
|
assert_eq!(
|
|
|
|
|
app.state().panes[0].preview.target,
|
|
|
|
|
Some(Location::local("/b.png"))
|
|
|
|
|
);
|
|
|
|
|
dispatch_until(&mut app, &mut results, |command| {
|
|
|
|
|
matches!(command, Command::ImagePrepared(_))
|
|
|
|
|
})
|
|
|
|
|
.await;
|
|
|
|
|
assert!(has_pixels(&draw(&app)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
async fn global_image_worker_has_max_active_one_across_panes() {
|
|
|
|
|
let (mut app, mut results) = application();
|
|
|
|
|
install_current_image(&mut app, PaneId::Left, "left.png");
|
|
|
|
|
install_current_image(&mut app, PaneId::Right, "right.png");
|
|
|
|
|
app.configure_images(ImageEngine::Enabled(ImageProtocolFactory::Halfblocks));
|
|
|
|
|
app.state_mut_for_test().mode = rcom::app::PaneMode::Dual;
|
|
|
|
|
app.state_mut_for_test().overlay = Overlay::Preview;
|
|
|
|
|
app.update_terminal_area(ratatui::layout::Rect::new(0, 0, 120, 30));
|
|
|
|
|
app.dispatch(Command::SwitchPane);
|
|
|
|
|
let mut prepared = 0;
|
|
|
|
|
while prepared < 2 {
|
|
|
|
|
let command = tokio::time::timeout(Duration::from_secs(2), results.recv())
|
|
|
|
|
.await
|
|
|
|
|
.unwrap()
|
|
|
|
|
.unwrap();
|
|
|
|
|
if matches!(command, Command::ImagePrepared(_)) {
|
|
|
|
|
prepared += 1;
|
|
|
|
|
}
|
|
|
|
|
app.dispatch(command);
|
|
|
|
|
}
|
|
|
|
|
assert_eq!(app.image_worker_metrics(), (0, 1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
async fn image_job_cancelled_before_blocking_start_never_decodes_or_publishes() {
|
|
|
|
|
let (mut app, mut results) = application();
|
|
|
|
|
app.set_image_worker_permits_for_test(0);
|
|
|
|
|
install_current_image(&mut app, PaneId::Left, "left.png");
|
|
|
|
|
app.configure_images(ImageEngine::Enabled(ImageProtocolFactory::Halfblocks));
|
|
|
|
|
app.state_mut_for_test().overlay = Overlay::Preview;
|
|
|
|
|
app.update_terminal_area(ratatui::layout::Rect::new(0, 0, 120, 30));
|
|
|
|
|
app.dispatch(Command::ToggleHelp);
|
|
|
|
|
app.release_image_worker_permit_for_test();
|
|
|
|
|
tokio::time::sleep(Duration::from_millis(50)).await;
|
|
|
|
|
let received = results.try_recv();
|
|
|
|
|
assert!(
|
|
|
|
|
matches!(received, Err(tokio::sync::mpsc::error::TryRecvError::Empty)),
|
|
|
|
|
"{received:?}"
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(app.image_worker_metrics(), (0, 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
async fn local_image_preview_prepares_and_renders_real_pixels_in_persistent_and_f3() {
|
|
|
|
|
let (mut app, mut results) = application();
|
|
|
|
|
app.configure_images(ImageEngine::Enabled(ImageProtocolFactory::Halfblocks));
|
|
|
|
|
app.update_terminal_area(ratatui::layout::Rect::new(0, 0, 120, 30));
|
|
|
|
|
app.dispatch(Command::Refresh);
|
|
|
|
|
dispatch_until(&mut app, &mut results, |command| {
|
|
|
|
|
matches!(command, Command::PreviewFinished(_))
|
|
|
|
|
})
|
|
|
|
|
.await;
|
|
|
|
|
assert_eq!(
|
|
|
|
|
app.state().panes[0].preview.content.as_ref().unwrap().kind,
|
|
|
|
|
rcom::preview::PreviewKind::Image
|
|
|
|
|
);
|
|
|
|
|
dispatch_until(&mut app, &mut results, |command| {
|
|
|
|
|
matches!(command, Command::ImagePrepared(_))
|
|
|
|
|
})
|
|
|
|
|
.await;
|
|
|
|
|
let buffer = draw(&app);
|
|
|
|
|
assert!(has_pixels(&buffer));
|
|
|
|
|
|
|
|
|
|
app.dispatch(Command::OpenPreview);
|
|
|
|
|
dispatch_until(&mut app, &mut results, |command| {
|
|
|
|
|
matches!(command, Command::ImagePrepared(_))
|
|
|
|
|
})
|
|
|
|
|
.await;
|
|
|
|
|
assert_eq!(app.state().overlay, Overlay::Preview);
|
|
|
|
|
assert!(has_pixels(&draw(&app)));
|
|
|
|
|
app.dispatch(Command::CloseOverlay);
|
|
|
|
|
dispatch_until(&mut app, &mut results, |command| {
|
|
|
|
|
matches!(command, Command::ImagePrepared(_))
|
|
|
|
|
})
|
|
|
|
|
.await;
|
|
|
|
|
assert!(has_pixels(&draw(&app)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
async fn resize_editor_epoch_and_text_selection_invalidate_prepared_pixels() {
|
|
|
|
|
let (mut app, mut results) = application();
|
|
|
|
|
app.configure_images(ImageEngine::Enabled(ImageProtocolFactory::Halfblocks));
|
|
|
|
|
app.update_terminal_area(ratatui::layout::Rect::new(0, 0, 120, 30));
|
|
|
|
|
app.dispatch(Command::Refresh);
|
|
|
|
|
dispatch_until(&mut app, &mut results, |command| {
|
|
|
|
|
matches!(command, Command::PreviewFinished(_))
|
|
|
|
|
})
|
|
|
|
|
.await;
|
|
|
|
|
dispatch_until(&mut app, &mut results, |command| {
|
|
|
|
|
matches!(command, Command::ImagePrepared(_))
|
|
|
|
|
})
|
|
|
|
|
.await;
|
|
|
|
|
assert!(has_pixels(&draw(&app)));
|
|
|
|
|
|
|
|
|
|
app.update_terminal_area(ratatui::layout::Rect::new(0, 0, 100, 30));
|
|
|
|
|
assert!(
|
|
|
|
|
!has_pixels(&draw(&app)),
|
|
|
|
|
"old oversized protocol must not render"
|
|
|
|
|
);
|
|
|
|
|
dispatch_until(&mut app, &mut results, |command| {
|
|
|
|
|
matches!(command, Command::ImagePrepared(_))
|
|
|
|
|
})
|
|
|
|
|
.await;
|
|
|
|
|
assert!(has_pixels(&draw(&app)));
|
|
|
|
|
|
|
|
|
|
app.resume_images();
|
|
|
|
|
assert!(app.image_cache().lock().unwrap().is_empty());
|
|
|
|
|
dispatch_until(&mut app, &mut results, |command| {
|
|
|
|
|
matches!(command, Command::ImagePrepared(_))
|
|
|
|
|
})
|
|
|
|
|
.await;
|
|
|
|
|
assert!(has_pixels(&draw(&app)));
|
|
|
|
|
|
|
|
|
|
app.state_mut_for_test().panes[0].preview.encoded_image = None;
|
|
|
|
|
app.state_mut_for_test().panes[0].preview.content = None;
|
|
|
|
|
app.dispatch(Command::OpenMessage);
|
|
|
|
|
assert!(app.image_cache().lock().unwrap().is_empty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
async fn background_image_refresh_prepares_accepted_new_bytes_instead_of_old_generation() {
|
|
|
|
|
let (mut app, mut results) = application();
|
|
|
|
|
app.configure_images(ImageEngine::Enabled(ImageProtocolFactory::Halfblocks));
|
|
|
|
|
app.update_terminal_area(ratatui::layout::Rect::new(0, 0, 120, 30));
|
|
|
|
|
app.dispatch(Command::Refresh);
|
|
|
|
|
dispatch_until(&mut app, &mut results, |command| {
|
|
|
|
|
matches!(command, Command::PreviewFinished(_))
|
|
|
|
|
})
|
|
|
|
|
.await;
|
|
|
|
|
dispatch_until(&mut app, &mut results, |command| {
|
|
|
|
|
matches!(command, Command::ImagePrepared(_))
|
|
|
|
|
})
|
|
|
|
|
.await;
|
|
|
|
|
let old_identity = app.current_image_identity(PaneId::Left).unwrap();
|
|
|
|
|
let background = app
|
|
|
|
|
.state_mut_for_test()
|
|
|
|
|
.reduce(Command::RefreshPane(PaneId::Left));
|
|
|
|
|
let [rcom::app::Effect::LoadListing(listing)] = background.as_slice() else {
|
|
|
|
|
panic!("background listing")
|
|
|
|
|
};
|
|
|
|
|
let background_preview =
|
|
|
|
|
app.state_mut_for_test()
|
|
|
|
|
.reduce(Command::ListingFinished(listing.clone().into_result(Ok(
|
|
|
|
|
vec![rcom::domain::Entry::new(
|
|
|
|
|
"pixel.png",
|
|
|
|
|
rcom::domain::EntryKind::File,
|
|
|
|
|
)],
|
|
|
|
|
))));
|
|
|
|
|
assert!(matches!(
|
|
|
|
|
background_preview.as_slice(),
|
|
|
|
|
[rcom::app::Effect::LoadPreview(_)]
|
|
|
|
|
));
|
|
|
|
|
assert!(app.state().panes[0].preview_generation > old_identity.generation);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
app.current_image_identity(PaneId::Left).unwrap(),
|
|
|
|
|
old_identity
|
|
|
|
|
);
|
|
|
|
|
assert!(matches!(
|
|
|
|
|
results.try_recv(),
|
|
|
|
|
Err(tokio::sync::mpsc::error::TryRecvError::Empty)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
let pane = &app.state().panes[0];
|
|
|
|
|
let request = rcom::app::PreviewRequest {
|
|
|
|
|
pane: PaneId::Left,
|
|
|
|
|
generation: pane.preview_generation,
|
|
|
|
|
target: pane.preview.target.clone().unwrap(),
|
|
|
|
|
session_epoch: pane.session_epoch,
|
|
|
|
|
images_enabled: true,
|
|
|
|
|
};
|
|
|
|
|
let mut response = request.into_result(Ok(Preview {
|
|
|
|
|
kind: PreviewKind::Image,
|
|
|
|
|
lines: vec!["Changed image".into()],
|
|
|
|
|
truncated: false,
|
2026-12-06 11:13:55 +03:00
|
|
|
directory_entries: Vec::new(),
|
2026-12-06 05:11:31 +03:00
|
|
|
}));
|
|
|
|
|
response.encoded_image = Some(EncodedImage {
|
|
|
|
|
bytes: Arc::new(changed_png()),
|
|
|
|
|
format: rcom::image_preview::SupportedImageFormat::Png,
|
|
|
|
|
});
|
|
|
|
|
app.dispatch(Command::PreviewFinished(response));
|
|
|
|
|
let new_identity = app.current_image_identity(PaneId::Left).unwrap();
|
|
|
|
|
assert_ne!(new_identity, old_identity);
|
|
|
|
|
dispatch_until(&mut app, &mut results, |command| {
|
|
|
|
|
matches!(command, Command::ImagePrepared(_))
|
|
|
|
|
})
|
|
|
|
|
.await;
|
|
|
|
|
assert!(has_pixels(&draw(&app)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
async fn stale_image_errors_after_resize_and_resume_never_replace_current_content() {
|
|
|
|
|
for resume in [false, true] {
|
|
|
|
|
let (mut app, _results) = application();
|
|
|
|
|
install_current_image(&mut app, PaneId::Left, "left.png");
|
|
|
|
|
app.configure_images(ImageEngine::Enabled(ImageProtocolFactory::Halfblocks));
|
|
|
|
|
app.state_mut_for_test().overlay = Overlay::Preview;
|
|
|
|
|
app.update_terminal_area(ratatui::layout::Rect::new(0, 0, 120, 30));
|
|
|
|
|
let stale = app.current_image_identity(PaneId::Left).unwrap();
|
|
|
|
|
if resume {
|
|
|
|
|
app.resume_images();
|
|
|
|
|
} else {
|
|
|
|
|
app.update_terminal_area(ratatui::layout::Rect::new(0, 0, 100, 30));
|
|
|
|
|
}
|
|
|
|
|
assert_ne!(app.current_image_identity(PaneId::Left).unwrap(), stale);
|
|
|
|
|
app.dispatch(Command::ImagePrepared(rcom::app::ImagePreparationResult {
|
|
|
|
|
identity: stale,
|
|
|
|
|
result: Err("stale error".into()),
|
|
|
|
|
}));
|
|
|
|
|
let preview = &app.state().panes[0].preview;
|
|
|
|
|
assert_eq!(preview.content.as_ref().unwrap().kind, PreviewKind::Image);
|
|
|
|
|
assert!(preview.encoded_image.is_some());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
async fn corrupt_current_image_becomes_visible_metadata_instead_of_preparing_forever() {
|
|
|
|
|
let bytes = png()[..40].to_vec();
|
|
|
|
|
let fs = MemoryFs::new().with_file(Location::local("/pixel.png"), bytes);
|
|
|
|
|
let registry = BackendRegistry::new(Arc::new(fs));
|
|
|
|
|
let connections = ConnectionManager::new(Arc::new(OpenSshConnector::default()), registry);
|
|
|
|
|
let (mut app, mut results) = Application::new(
|
|
|
|
|
Location::local("/"),
|
|
|
|
|
connections,
|
|
|
|
|
DiscoveryResult::default(),
|
|
|
|
|
);
|
|
|
|
|
app.configure_images(ImageEngine::Enabled(ImageProtocolFactory::Halfblocks));
|
|
|
|
|
app.update_terminal_area(ratatui::layout::Rect::new(0, 0, 120, 30));
|
|
|
|
|
app.dispatch(Command::Refresh);
|
|
|
|
|
dispatch_until(&mut app, &mut results, |command| {
|
|
|
|
|
matches!(command, Command::PreviewFinished(_))
|
|
|
|
|
})
|
|
|
|
|
.await;
|
|
|
|
|
dispatch_until(&mut app, &mut results, |command| {
|
|
|
|
|
matches!(command, Command::ImagePrepared(_))
|
|
|
|
|
})
|
|
|
|
|
.await;
|
|
|
|
|
let preview = app.state().panes[0].preview.content.as_ref().unwrap();
|
|
|
|
|
assert_eq!(preview.kind, rcom::preview::PreviewKind::Metadata);
|
|
|
|
|
assert!(preview.lines[0].contains("unavailable"));
|
|
|
|
|
assert!(app.state().panes[0].preview.encoded_image.is_none());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn direct_halfblock_factory_needs_no_detection_and_zero_area_is_a_safe_placeholder() {
|
|
|
|
|
let image = DynamicImage::ImageRgb8(ImageBuffer::new(1, 1));
|
|
|
|
|
assert!(
|
|
|
|
|
ImageProtocolFactory::Halfblocks
|
|
|
|
|
.prepare(image, ratatui::layout::Size::new(0, 0))
|
|
|
|
|
.is_err()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
async fn disabled_images_have_explicit_fallback_and_no_large_second_read() {
|
|
|
|
|
let target = Location::local("/pixel.png");
|
|
|
|
|
let recording = rcom::test_support::RecordingFs::new(Arc::new(
|
|
|
|
|
MemoryFs::new().with_file(target.clone(), png()),
|
|
|
|
|
));
|
|
|
|
|
let request = rcom::app::PreviewRequest {
|
|
|
|
|
pane: PaneId::Left,
|
|
|
|
|
generation: 1,
|
|
|
|
|
target,
|
|
|
|
|
session_epoch: None,
|
|
|
|
|
images_enabled: false,
|
|
|
|
|
};
|
|
|
|
|
let result = rcom::app::preview::execute_preview(request, &recording).await;
|
|
|
|
|
let preview = result.result.unwrap();
|
|
|
|
|
assert_eq!(preview.kind, PreviewKind::Binary);
|
|
|
|
|
assert!(preview.lines[0].contains("unsupported"));
|
|
|
|
|
assert!(
|
|
|
|
|
preview
|
|
|
|
|
.lines
|
|
|
|
|
.iter()
|
|
|
|
|
.any(|line| line.contains("disabled or unavailable"))
|
|
|
|
|
);
|
|
|
|
|
assert!(result.encoded_image.is_none());
|
|
|
|
|
let operations = recording.operations();
|
|
|
|
|
assert_eq!(operations.len(), 2);
|
|
|
|
|
assert_eq!(operations[1].limit, Some(rcom::preview::MAX_PREVIEW_BYTES));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
async fn fake_ssh_image_uses_the_same_bounded_read_path_without_a_shell() {
|
|
|
|
|
let target = Location::ssh(rcom::domain::HostAlias::new("fake"), "/pixel.png");
|
|
|
|
|
let fs = MemoryFs::new().with_file(target.clone(), png());
|
|
|
|
|
let request = rcom::app::PreviewRequest {
|
|
|
|
|
pane: PaneId::Left,
|
|
|
|
|
generation: 1,
|
|
|
|
|
target,
|
|
|
|
|
session_epoch: Some(1),
|
|
|
|
|
images_enabled: true,
|
|
|
|
|
};
|
|
|
|
|
let result = rcom::app::preview::execute_preview(request, &fs).await;
|
|
|
|
|
assert!(result.result.is_ok());
|
|
|
|
|
assert!(result.encoded_image.is_some());
|
|
|
|
|
}
|