team-ljyzipelo

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