team-ljyzipelo

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