team-ljyzipelo

공개
852줄26 KB
1#[cfg(feature = "ui")]
2mod dialogs;
3mod fake;
4use fake::*;
5use std::path::PathBuf;
6use zipelo_ui_memory_app::archive_ui::*;
7
8fn path(name: &str) -> PathBuf {
9 std::env::current_dir().unwrap().join(name)
10}
11fn pump(m: &mut Model) {
12 for _ in 0..100 {
13 m.poll();
14 if !m.busy() {
15 return;
16 }
17 }
18 panic!("가짜 작업자 종료 누락: {}", m.status());
19}
20fn list(m: &mut Model, f: &mut FakeFactory) {
21 assert!(m.begin(
22 Start::List {
23 archive: path("example.zip")
24 },
25 f
26 ));
27 pump(m);
28 assert!(m.list_id.is_some());
29}
30
31#[test]
32fn open_lists_only_after_terminal_eofs_and_wait() {
33 let mut f = FakeFactory::default();
34 let mut m = Model::default();
35 assert!(m.begin(
36 Start::List {
37 archive: path("example.zip")
38 },
39 &mut f
40 ));
41 while m.terminal.is_none() {
42 m.poll();
43 assert!(m.list_id.is_none());
44 assert!(!m.can_extract());
45 }
46 assert!(m.busy());
47 assert!(!m.begin(
48 Start::List {
49 archive: path("replacement.zip")
50 },
51 &mut f
52 ));
53 pump(&mut m);
54 assert_eq!(m.entries[0].name, "읽어주세요.txt");
55 assert!(m.can_extract());
56 assert!(m.confirmed);
57}
58#[test]
59fn extract_uses_list_token_selection_and_destination() {
60 let mut f = FakeFactory::default();
61 let mut m = Model::default();
62 list(&mut m, &mut f);
63 let token = m.list_id.clone().unwrap();
64 m.selected.insert(0);
65 assert!(m.extract(path("output"), true, None, &mut f));
66 pump(&mut m);
67 assert!(
68 matches!(f.state.borrow().starts.last(),Some(Start::Extract {selection:Selection::EntryIds(ids),list_id,..}) if ids==&vec![0]&&*list_id==token)
69 );
70 assert_eq!(m.terminal.unwrap().publication, Publication::Complete);
71}
72#[test]
73fn gzip_requires_explicit_leaf() {
74 let mut f = FakeFactory::default();
75 let mut m = Model::default();
76 assert!(m.begin(
77 Start::List {
78 archive: path("sample.gz")
79 },
80 &mut f
81 ));
82 pump(&mut m);
83 for name in [None, Some("../escape".into()), Some("sub/file".into())] {
84 assert!(!m.extract(path("output"), false, name, &mut f));
85 }
86 assert!(m.extract(path("output"), false, Some("압축 해제 파일".into()), &mut f));
87 pump(&mut m);
88}
89#[test]
90fn creates_zip_and_reports_progress_outputs() {
91 let mut f = FakeFactory::default();
92 let mut m = Model::default();
93 assert!(m.begin(
94 Start::CreateZip {
95 sources: vec![(path("one.txt"), "one.txt".into())],
96 output_file: path("new.zip"),
97 method: Method::Deflate,
98 aes256: false
99 },
100 &mut f
101 ));
102 pump(&mut m);
103 assert_eq!(m.progress.unwrap().1, 31);
104 assert_eq!(m.outputs.len(), 1);
105 assert_eq!(m.status(), "작업 완료");
106}
107#[test]
108fn password_challenge_is_answered_without_retaining_secret() {
109 let mut f = FakeFactory::default();
110 let mut m = Model::default();
111 assert!(m.begin(
112 Start::List {
113 archive: path("locked.zip")
114 },
115 &mut f
116 ));
117 for _ in 0..10 {
118 m.poll();
119 if m.challenge.is_some() {
120 break;
121 }
122 }
123 assert_eq!(m.challenge, Some((17, 1, false)));
124 assert!(!m.password(String::new()));
125 assert!(m.password("synthetic password".into()));
126 pump(&mut m);
127 assert!(f.state.borrow().password_seen);
128 assert!(m.challenge.is_none());
129 assert!(m.list_id.is_some());
130}
131#[test]
132fn cancel_close_retract_preserves_request_and_waits_for_exit() {
133 let mut f = FakeFactory::default();
134 let mut m = Model::default();
135 assert!(m.begin(
136 Start::List {
137 archive: path("one.zip")
138 },
139 &mut f
140 ));
141 m.poll();
142 m.request_close();
143 assert_eq!(m.close, Close::Confirm);
144 m.confirm_close();
145 m.keep_open();
146 m.cancel();
147 pump(&mut m);
148 assert_eq!(m.close, Close::Open);
149 assert_eq!(m.cancel, Some(CancelStatus::Requested));
150 assert_eq!(m.terminal.unwrap().outcome, Outcome::Cancelled);
151 assert_eq!(
152 f.state
153 .borrow()
154 .requests
155 .iter()
156 .filter(|(_, k)| *k == "cancel")
157 .count(),
158 1
159 );
160}
161#[test]
162fn terminal_race_needs_no_cancel_ack() {
163 let mut f = FakeFactory::manual();
164 let mut m = Model::default();
165 assert!(m.begin(
166 Start::List {
167 archive: path("one.zip")
168 },
169 &mut f
170 ));
171 {
172 let mut s = f.state.borrow_mut();
173 s.frame(Event::Accepted { encryption: false });
174 s.finish(Outcome::Cancelled, Publication::None);
175 }
176 m.cancel();
177 pump(&mut m);
178 assert!(m.cancel.is_none());
179 assert_eq!(m.status(), "작업 취소됨");
180}
181#[test]
182fn eof_exit_without_terminal_never_means_success() {
183 let mut f = FakeFactory::manual();
184 let mut m = Model::default();
185 assert!(m.begin(
186 Start::List {
187 archive: path("one.zip")
188 },
189 &mut f
190 ));
191 {
192 let mut s = f.state.borrow_mut();
193 s.queue.extend([
194 HostEvent::StdoutEof,
195 HostEvent::StderrEof,
196 HostEvent::Exited { success: true },
197 ]);
198 }
199 pump(&mut m);
200 assert!(!m.confirmed);
201 assert!(m.list_id.is_none());
202 assert!(m.error.is_some());
203}
204#[test]
205fn stale_sequence_and_job_are_protocol_errors() {
206 for bad_job in [true, false] {
207 let mut f = FakeFactory::manual();
208 let mut m = Model::default();
209 assert!(m.begin(
210 Start::List {
211 archive: path("one.zip")
212 },
213 &mut f
214 ));
215 let id = m.job_id().unwrap();
216 f.state.borrow_mut().queue.push_back(HostEvent::Frame {
217 job_id: if bad_job { id + 1 } else { id },
218 sequence: if bad_job { 0 } else { 1 },
219 event: Event::Accepted { encryption: false },
220 });
221 m.poll();
222 assert!(m.error.is_some());
223 assert!(m.busy());
224 }
225}
226#[test]
227fn source_changed_invalidates_selection_without_retry() {
228 let mut f = FakeFactory::default();
229 let mut m = Model::default();
230 list(&mut m, &mut f);
231 m.selected.insert(0);
232 f.state.borrow_mut().manual = true;
233 assert!(m.extract(path("out"), true, None, &mut f));
234 {
235 let mut s = f.state.borrow_mut();
236 s.frame(Event::Accepted { encryption: false });
237 s.frame(Event::Terminal(Terminal {
238 outcome: Outcome::Failed,
239 error: Some(ErrorCode::SourceChanged),
240 publication: Publication::None,
241 created_count: 0,
242 retained_partial_count: 0,
243 durability: Durability::NotApplicable,
244 cleanup: Cleanup::Complete,
245 }));
246 s.queue.extend([
247 HostEvent::StdoutEof,
248 HostEvent::StderrEof,
249 HostEvent::Exited { success: true },
250 ]);
251 }
252 pump(&mut m);
253 assert!(m.list_id.is_none());
254 assert!(m.selected.is_empty());
255 assert_eq!(f.state.borrow().starts.len(), 2);
256}
257#[test]
258fn partial_and_uncertain_results_are_preserved() {
259 let mut f = FakeFactory::manual();
260 let mut m = Model::default();
261 assert!(m.begin(
262 Start::CreateZip {
263 sources: vec![(path("one"), "one".into())],
264 output_file: path("out.zip"),
265 method: Method::Store,
266 aes256: false
267 },
268 &mut f
269 ));
270 {
271 let mut s = f.state.borrow_mut();
272 s.frame(Event::Accepted { encryption: false });
273 s.frame(Event::Output {
274 entry_id: None,
275 relative_name: "out.zip".into(),
276 disposition: Disposition::CommitUncertain,
277 });
278 s.frame(Event::Terminal(Terminal {
279 outcome: Outcome::Failed,
280 error: Some(ErrorCode::Io),
281 publication: Publication::Uncertain,
282 created_count: 0,
283 retained_partial_count: 1,
284 durability: Durability::Failed,
285 cleanup: Cleanup::Unconfirmed,
286 }));
287 s.queue.extend([
288 HostEvent::StdoutEof,
289 HostEvent::StderrEof,
290 HostEvent::Exited { success: true },
291 ]);
292 }
293 pump(&mut m);
294 let t = m.terminal.as_ref().unwrap();
295 assert_eq!(t.publication, Publication::Uncertain);
296 assert_eq!(t.retained_partial_count, 1);
297 assert_eq!(t.durability, Durability::Failed);
298 assert_eq!(m.outputs[0].1, Disposition::CommitUncertain);
299}
300#[test]
301fn close_requires_result_acknowledgement() {
302 let mut f = FakeFactory::default();
303 let mut m = Model::default();
304 assert!(m.begin(
305 Start::List {
306 archive: path("one.zip")
307 },
308 &mut f
309 ));
310 m.request_close();
311 m.confirm_close();
312 m.acknowledge_close();
313 assert_eq!(m.close, Close::Waiting);
314 pump(&mut m);
315 assert_eq!(m.close, Close::Review);
316 m.acknowledge_close();
317 assert_eq!(m.close, Close::Allowed);
318}
319#[test]
320fn unsupported_worker_and_unsafe_inputs_do_not_start() {
321 let mut m = Model::default();
322 assert!(!m.begin(
323 Start::List {
324 archive: path("one.zip")
325 },
326 &mut Unavailable
327 ));
328 assert!(m.error.as_ref().unwrap().contains("준비"));
329 let mut f = FakeFactory::default();
330 assert!(!m.begin(
331 Start::List {
332 archive: "relative.zip".into()
333 },
334 &mut f
335 ));
336 assert!(!m.begin(
337 Start::CreateZip {
338 sources: vec![(path("one"), "../one".into())],
339 output_file: path("out.zip"),
340 method: Method::Store,
341 aes256: false
342 },
343 &mut f
344 ));
345 assert!(f.state.borrow().starts.is_empty());
346}
347#[cfg(feature = "ui")]
348#[test]
349fn renders_every_flow_with_actual_egui_widgets() {
350 use eframe::egui::{self, epaint::Shape};
351 use zipelo_ui_memory_app::archive_screen::ArchiveApp;
352 fn text(shapes: &[egui::epaint::ClippedShape]) -> Vec<(String, egui::Pos2)> {
353 fn walk(shape: &Shape, result: &mut Vec<(String, egui::Pos2)>) {
354 match shape {
355 Shape::Text(t) => result.push((
356 t.galley.job.text.clone(),
357 t.pos + t.galley.rect.size() / 2.0,
358 )),
359 Shape::Vec(v) => {
360 for shape in v {
361 walk(shape, result);
362 }
363 }
364 _ => {}
365 }
366 }
367 let mut result = Vec::new();
368 for shape in shapes {
369 walk(&shape.shape, &mut result);
370 }
371 result
372 }
373 let ctx = egui::Context::default();
374 let f = FakeFactory::default();
375 let mut app = ArchiveApp::new(Box::new(f.clone()), None, true);
376 let render = |app: &mut ArchiveApp, events: Vec<egui::Event>, width: f32| {
377 let mut output = ctx.run_ui(
378 egui::RawInput {
379 screen_rect: Some(egui::Rect::from_min_size(
380 egui::Pos2::ZERO,
381 egui::vec2(width, 720.0),
382 )),
383 events,
384 ..Default::default()
385 },
386 |ui| app.show(ui),
387 );
388 output.textures_delta.clear();
389 assert!(!output.shapes.is_empty());
390 text(&output.shapes)
391 };
392 render(&mut app, vec![], 1060.0);
393 render(&mut app, vec![], 1060.0);
394 let initial = render(&mut app, vec![], 1060.0);
395 let point = initial
396 .iter()
397 .rev()
398 .find(|(t, _)| t == "압축하기")
399 .unwrap()
400 .1;
401 render(
402 &mut app,
403 vec![
404 egui::Event::PointerMoved(point),
405 egui::Event::PointerButton {
406 pos: point,
407 button: egui::PointerButton::Primary,
408 pressed: true,
409 modifiers: egui::Modifiers::default(),
410 },
411 ],
412 1060.0,
413 );
414 render(
415 &mut app,
416 vec![egui::Event::PointerButton {
417 pos: point,
418 button: egui::PointerButton::Primary,
419 pressed: false,
420 modifiers: egui::Modifiers::default(),
421 }],
422 1060.0,
423 );
424 let create = render(&mut app, vec![], 1060.0);
425 assert!(create.iter().any(|(t, _)| t == "암호로 보호하기"));
426 let mut app = ArchiveApp::new(Box::new(f.clone()), Some(path("locked.zip")), true);
427 for _ in 0..8 {
428 app.model.poll();
429 }
430 for width in [760.0, 1060.0] {
431 render(&mut app, vec![], width);
432 render(&mut app, vec![], width);
433 let password = render(&mut app, vec![], width);
434 assert!(password.iter().any(|(t, _)| t == "암호가 필요합니다"));
435 }
436 assert!(app.model.password("synthetic secret".into()));
437 pump(&mut app.model);
438 let listed = render(&mut app, vec![], 1060.0);
439 assert!(listed.iter().any(|(t, _)| t == "읽어주세요.txt"));
440 assert!(!listed.iter().any(|(t, _)| t.contains("synthetic secret")));
441 assert!(app.model.extract(path("out"), false, None, &mut f.clone()));
442 render(&mut app, vec![], 1060.0);
443 app.model.request_close();
444 render(&mut app, vec![], 1060.0);
445 let confirm = render(&mut app, vec![], 1060.0);
446 assert!(confirm.iter().any(|(t, _)| t == "작업 중 닫기"));
447 app.model.confirm_close();
448 pump(&mut app.model);
449 render(&mut app, vec![], 1060.0);
450 let result = render(&mut app, vec![], 1060.0);
451 assert!(result.iter().any(|(t, _)| t == "결과 확인 후 닫기"));
452}
453
454#[test]
455fn file_association_arguments_preserve_native_paths() {
456 let cwd = std::env::current_dir().unwrap();
457 let (fixture, archive) =
458 launch_args(vec!["--ui-fixture".into(), "한글.zip".into()], cwd.clone()).unwrap();
459 assert!(fixture);
460 assert_eq!(archive, Some(cwd.join("한글.zip")));
461 assert!(launch_args(vec!["a".into(), "b".into()], cwd.clone()).is_err());
462 #[cfg(unix)]
463 {
464 use std::os::unix::ffi::OsStringExt;
465 let name = std::ffi::OsString::from_vec(vec![b'/', 0xff, b'a']);
466 assert_eq!(
467 launch_args(vec![name.clone()], cwd).unwrap().1,
468 Some(PathBuf::from(name))
469 );
470 }
471}
472
473#[cfg(feature = "ui")]
474#[test]
475fn dropped_native_file_opens_without_ui_reading_contents() {
476 use eframe::egui;
477 use zipelo_ui_memory_app::archive_screen::ArchiveApp;
478 #[derive(Debug)]
479 struct DropFile(PathBuf);
480 impl egui::DroppedFile for DropFile {
481 fn path(&self) -> &std::path::Path {
482 &self.0
483 }
484 fn bytes(&self) -> Result<Vec<u8>, String> {
485 panic!("화면이 압축파일을 직접 읽으면 안 됨")
486 }
487 }
488 let ctx = egui::Context::default();
489 let f = FakeFactory::default();
490 let mut app = ArchiveApp::new(Box::new(f.clone()), None, true);
491 let scratch = presentation::Folder::new();
492 let file = scratch.0.join("dropped.zip");
493 std::fs::write(&file, b"fixture").unwrap();
494 let mut output = ctx.run_ui(
495 egui::RawInput {
496 dropped_files: vec![std::sync::Arc::new(DropFile(file.clone()))],
497 ..Default::default()
498 },
499 |ui| app.show(ui),
500 );
501 output.textures_delta.clear();
502 assert_eq!(app.model.archive, Some(file));
503 assert_eq!(f.state.borrow().starts.len(), 1);
504 pump(&mut app.model);
505 assert!(app.model.can_extract());
506}
507
508#[test]
509fn failed_start_retains_connection_until_both_eofs_and_child_wait() {
510 for missing in 0..3 {
511 let mut factory = FakeFactory::manual();
512 factory.state.borrow_mut().fail_start = true;
513 let mut model = Model::default();
514 assert!(!model.begin(
515 Start::List {
516 archive: path("failed.zip")
517 },
518 &mut factory
519 ));
520 assert!(model.busy());
521 assert_eq!(factory.state.borrow().dropped_connections, 0);
522 assert_eq!(model.job_id(), Some(1));
523 model.request_close();
524 model.confirm_close();
525 assert_eq!(model.close, Close::Waiting);
526 assert_eq!(factory.state.borrow().requests, vec![(0, "start")]);
527 let event = |index| match index {
528 0 => HostEvent::StdoutEof,
529 1 => HostEvent::StderrEof,
530 _ => HostEvent::Exited { success: false },
531 };
532 for index in 0..3 {
533 if index != missing {
534 factory.state.borrow_mut().queue.push_back(event(index));
535 }
536 }
537 for _ in 0..20 {
538 model.poll();
539 }
540 assert!(model.busy());
541 assert!(!model.can_extract());
542 assert_eq!(factory.state.borrow().dropped_connections, 0);
543 model.acknowledge_close();
544 assert_eq!(model.close, Close::Waiting);
545 assert!(!model.begin(
546 Start::List {
547 archive: path("replacement.zip")
548 },
549 &mut factory
550 ));
551 factory.state.borrow_mut().queue.push_back(event(missing));
552 pump(&mut model);
553 assert!(!model.confirmed);
554 assert!(model.terminal.is_none());
555 assert_eq!(model.error.as_deref(), Some("Start 전송 실패"));
556 assert_eq!(factory.state.borrow().dropped_connections, 1);
557 assert_eq!(model.close, Close::Review);
558 if missing == 0 {
559 model.acknowledge_close();
560 assert_eq!(model.close, Close::Allowed);
561 } else {
562 model.keep_open();
563 factory.state.borrow_mut().fail_start = false;
564 assert!(model.begin(
565 Start::List {
566 archive: path("replacement.zip")
567 },
568 &mut factory
569 ));
570 assert_eq!(model.job_id(), Some(2));
571 }
572 }
573}
574
575#[test]
576fn non_gzip_formats_reject_a_gzip_output_name_before_connect() {
577 for format in [Format::Zip, Format::Tar, Format::TarGzip] {
578 let mut factory = FakeFactory::default();
579 factory.state.borrow_mut().list_format = Some(format);
580 let mut model = Model::default();
581 list(&mut model, &mut factory);
582 let count = factory.state.borrow().starts.len();
583 assert!(!model.extract(path("out"), false, Some("stale.txt".into()), &mut factory));
584 assert!(!model.busy());
585 assert_eq!(factory.state.borrow().starts.len(), count);
586 assert!(model.extract(path("out"), false, None, &mut factory));
587 pump(&mut model);
588 }
589}
590
591#[cfg(feature = "ui")]
592#[test]
593fn extract_button_sends_gzip_name_only_for_raw_gzip() {
594 use eframe::egui::{self, epaint::Shape};
595 use zipelo_ui_memory_app::archive_screen::ArchiveApp;
596 for format in [Format::Zip, Format::Tar, Format::TarGzip, Format::Gzip] {
597 let ctx = egui::Context::default();
598 let factory = FakeFactory::default();
599 factory.state.borrow_mut().list_format = Some(format);
600 let mut app = ArchiveApp::new(Box::new(factory.clone()), Some(path("input.archive")), true);
601 pump(&mut app.model);
602 let render = |app: &mut ArchiveApp, events| {
603 fn walk(shape: &Shape, output: &mut Vec<(String, egui::Pos2)>) {
604 match shape {
605 Shape::Text(text) => output.push((
606 text.galley.job.text.clone(),
607 text.pos + text.galley.rect.size() / 2.0,
608 )),
609 Shape::Vec(shapes) => {
610 for shape in shapes {
611 walk(shape, output);
612 }
613 }
614 _ => {}
615 }
616 }
617 let mut frame = ctx.run_ui(
618 egui::RawInput {
619 screen_rect: Some(egui::Rect::from_min_size(
620 egui::Pos2::ZERO,
621 egui::vec2(1060.0, 720.0),
622 )),
623 events,
624 ..Default::default()
625 },
626 |ui| app.show(ui),
627 );
628 frame.textures_delta.clear();
629 let mut output = Vec::new();
630 for shape in frame.shapes {
631 walk(&shape.shape, &mut output);
632 }
633 output
634 };
635 let click = |app: &mut ArchiveApp, point| {
636 render(
637 app,
638 vec![
639 egui::Event::PointerMoved(point),
640 egui::Event::PointerButton {
641 pos: point,
642 button: egui::PointerButton::Primary,
643 pressed: true,
644 modifiers: Default::default(),
645 },
646 ],
647 );
648 render(
649 app,
650 vec![egui::Event::PointerButton {
651 pos: point,
652 button: egui::PointerButton::Primary,
653 pressed: false,
654 modifiers: Default::default(),
655 }],
656 );
657 };
658 let scratch = presentation::Folder::new();
659 app.choose_destination(scratch.0.clone());
660 render(&mut app, vec![]);
661 let dialogs = dialogs::TestDialogs::default();
662 dialogs
663 .0
664 .borrow_mut()
665 .answers
666 .push_back(Some(vec![scratch.0.clone()]));
667 app.set_dialogs(Box::new(dialogs));
668 let texts = render(&mut app, vec![]);
669 let button = texts
670 .iter()
671 .rev()
672 .find(|(text, _)| text == "압축해제")
673 .unwrap()
674 .1;
675 click(&mut app, button);
676 let state = factory.state.borrow();
677 assert_eq!(
678 state.starts.len(),
679 2,
680 "풀기 버튼의 Start 요청 누락: {format:?}"
681 );
682 match state.starts.last().unwrap() {
683 Start::Extract {
684 gzip_output_name, ..
685 } => assert_eq!(
686 gzip_output_name,
687 &if format == Format::Gzip {
688 Some("압축 해제 파일".into())
689 } else {
690 None
691 }
692 ),
693 _ => panic!("Extract 요청 누락"),
694 }
695 }
696}
697
698#[test]
699fn fake_worker_rejects_invalid_format_specific_output_names() {
700 for (format, name) in [
701 (Format::Zip, Some("stale.txt".into())),
702 (Format::Tar, Some(String::new())),
703 (Format::TarGzip, Some("stale.txt".into())),
704 (Format::Gzip, None),
705 (Format::Gzip, Some("../escape".into())),
706 ] {
707 let mut factory = FakeFactory::default();
708 factory.state.borrow_mut().list_format = Some(format);
709 let mut model = Model::default();
710 list(&mut model, &mut factory);
711 let mut connection = factory.connect(2).unwrap();
712 let previous = factory.state.borrow().starts.len();
713 assert!(
714 connection
715 .send(Request {
716 job_id: 2,
717 sequence: 0,
718 command: Command::Start(Start::Extract {
719 archive: model.archive.clone().unwrap(),
720 destination: path("output"),
721 selection: Selection::All,
722 list_id: model.list_id.clone().unwrap(),
723 gzip_output_name: name,
724 }),
725 })
726 .is_err()
727 );
728 assert_eq!(factory.state.borrow().starts.len(), previous);
729 }
730}
731
732#[test]
733fn cleanup_marker_without_error_does_not_replace_eofs() {
734 let mut factory = FakeFactory::manual();
735 let mut model = Model::default();
736 assert!(model.begin(
737 Start::List {
738 archive: path("sample.zip")
739 },
740 &mut factory
741 ));
742 factory
743 .state
744 .borrow_mut()
745 .queue
746 .push_back(HostEvent::CleanupComplete);
747 factory
748 .state
749 .borrow_mut()
750 .queue
751 .push_back(HostEvent::Exited { success: true });
752 for _ in 0..10 {
753 model.poll();
754 }
755 assert!(model.busy());
756 factory
757 .state
758 .borrow_mut()
759 .queue
760 .push_back(HostEvent::StdoutEof);
761 for _ in 0..10 {
762 model.poll();
763 }
764 assert!(model.busy());
765 factory
766 .state
767 .borrow_mut()
768 .queue
769 .push_back(HostEvent::StderrEof);
770 pump(&mut model);
771 assert!(!model.confirmed);
772}
773
774#[test]
775fn error_cleanup_requires_child_wait_without_fabricating_terminal() {
776 let mut factory = FakeFactory::manual();
777 let mut model = Model::default();
778 assert!(model.begin(
779 Start::List {
780 archive: path("sample.zip")
781 },
782 &mut factory
783 ));
784 factory
785 .state
786 .borrow_mut()
787 .queue
788 .push_back(HostEvent::Fault("pipe error".into()));
789 factory
790 .state
791 .borrow_mut()
792 .queue
793 .push_back(HostEvent::CleanupComplete);
794 model.request_close();
795 model.confirm_close();
796 for _ in 0..10 {
797 model.poll();
798 }
799 assert!(model.busy());
800 assert_eq!(model.close, Close::Waiting);
801 factory
802 .state
803 .borrow_mut()
804 .queue
805 .push_back(HostEvent::Exited { success: false });
806 pump(&mut model);
807 assert!(!model.confirmed);
808 assert!(model.terminal.is_none());
809 assert_eq!(model.error.as_deref(), Some("pipe error"));
810 assert_eq!(model.close, Close::Review);
811}
812
813#[test]
814fn password_validation_and_retry_do_not_erase_transport_failure() {
815 let mut factory = FakeFactory::default();
816 let mut model = Model::default();
817 assert!(model.begin(
818 Start::List {
819 archive: path("locked.zip")
820 },
821 &mut factory
822 ));
823 for _ in 0..10 {
824 model.poll();
825 if model.challenge.is_some() {
826 break;
827 }
828 }
829 assert!(model.challenge.is_some());
830 factory
831 .state
832 .borrow_mut()
833 .queue
834 .push_back(HostEvent::Fault("pipe error".into()));
835 for _ in 0..10 {
836 model.poll();
837 if model.error.is_some() {
838 break;
839 }
840 }
841 assert_eq!(model.error.as_deref(), Some("pipe error"));
842 assert!(!model.password(String::new()));
843 assert!(model.input_error.as_ref().unwrap().contains("1~1024바이트"));
844 assert_eq!(model.error.as_deref(), Some("pipe error"));
845 assert!(model.password("synthetic password".into()));
846 pump(&mut model);
847 assert!(model.input_error.is_none());
848 assert_eq!(model.error.as_deref(), Some("pipe error"));
849 assert!(!model.confirmed);
850}
851
852mod presentation;