team-ljyzipelo

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