team-ljyzipelo

공개

추출 요청과 완료 판정의 선택 범위를 일치시킴

작성자
호시노 히나타
작성 시각
커밋
ea7f5213871c65aab62b1c73ce5e0b90badb53d5
부모
d90f1d6
이 시점의 파일 보기

변경된 파일 5개

+204-71
수정experiments/rust-ui-memory-app/src/archive_present.rs+21-51
@@ -98,75 +98,45 @@ pub fn remove_owned_empty(path: &Path) {
9898 let _ = fs::remove_dir(path);
9999}
100100
101추가: fn requested(entry: &Entry, selection: &Selection) -> bool {
102추가: match selection {
103추가: Selection::All => true,
104추가: Selection::EntryIds(ids) => ids.contains(&entry.id),
105추가: }
106추가: }
107추가:
101108pub fn target_files(
102109 entries: &[Entry],
103삭제: selected: &BTreeSet<u32>,
104삭제: only: bool,
110추가: selection: &Selection,
105111 gzip: Option<&str>,
106112) -> Option<BTreeSet<String>> {
107삭제: let selected_names = entries
108삭제: .iter()
109삭제: .filter(|e| selected.contains(&e.id))
110삭제: .map(|e| (e.name.as_str(), e.kind))
111삭제: .collect::<Vec<_>>();
112113 let mut names = BTreeSet::new();
113삭제: for entry in entries.iter().filter(|e| e.kind == Kind::File) {
114삭제: let included = !only
115삭제: || selected_names.iter().any(|(name, kind)| {
116삭제: *name == entry.name
117삭제: || (*kind == Kind::Directory
118삭제: && entry
119삭제: .name
120삭제: .starts_with(&format!("{}/", name.trim_end_matches('/'))))
121삭제: });
122삭제: if included && !names.insert(gzip.unwrap_or(&entry.name).replace('\\', "/")) {
114추가: for entry in entries
115추가: .iter()
116추가: .filter(|entry| entry.kind == Kind::File && requested(entry, selection))
117추가: {
118추가: if !names.insert(gzip.unwrap_or(&entry.name).replace('\\', "/")) {
123119 return None;
124120 }
125121 }
126122 Some(names)
127123}
128124
129삭제: pub fn target_directories(
130삭제: entries: &[Entry],
131삭제: selected: &BTreeSet<u32>,
132삭제: only: bool,
133삭제: ) -> BTreeSet<String> {
134삭제: let selected_directories = entries
135삭제: .iter()
136삭제: .filter(|entry| entry.kind == Kind::Directory && selected.contains(&entry.id))
137삭제: .map(|entry| {
138삭제: entry
139삭제: .name
140삭제: .replace('\\', "/")
141삭제: .trim_end_matches('/')
142삭제: .to_owned()
143삭제: })
144삭제: .collect::<BTreeSet<_>>();
125추가: pub fn target_directories(entries: &[Entry], selection: &Selection) -> BTreeSet<String> {
145126 let mut directories = BTreeSet::new();
146삭제: for entry in entries
147삭제: .iter()
148삭제: .filter(|entry| matches!(entry.kind, Kind::File | Kind::Directory))
149삭제: {
127추가: for entry in entries.iter().filter(|entry| {
128추가: matches!(entry.kind, Kind::File | Kind::Directory) && requested(entry, selection)
129추가: }) {
150130 let normalized = entry.name.replace('\\', "/");
151131 let name = normalized.trim_end_matches('/');
132추가: if entry.kind == Kind::Directory {
133추가: directories.insert(name.to_owned());
134추가: }
152135 let mut parent = name;
153삭제: let mut ancestors = Vec::new();
154136 while let Some((directory, _)) = parent.rsplit_once('/') {
155삭제: ancestors.push(directory);
137추가: directories.insert(directory.to_owned());
156138 parent = directory;
157139 }
158삭제: if only
159삭제: && !selected.contains(&entry.id)
160삭제: && !ancestors
161삭제: .iter()
162삭제: .any(|directory| selected_directories.contains(*directory))
163삭제: {
164삭제: continue;
165삭제: }
166삭제: if entry.kind == Kind::Directory {
167삭제: directories.insert(name.to_owned());
168삭제: }
169삭제: directories.extend(ancestors.into_iter().map(str::to_owned));
170140 }
171141 directories
172142}
수정experiments/rust-ui-memory-app/src/archive_screen.rs+8-12
@@ -160,29 +160,25 @@ impl ArchiveApp {
160160 .list_id
161161 .as_ref()
162162 .is_some_and(|id| id.format == Format::Gzip);
163추가: let selection = if self.selected_only {
164추가: Selection::EntryIds(self.model.selected.iter().copied().collect())
165추가: } else {
166추가: Selection::All
167추가: };
163168 self.targets = present::target_files(
164169 &self.model.entries,
165삭제: &self.model.selected,
166삭제: self.selected_only,
170추가: &selection,
167171 gzip.then_some(self.gzip_name.as_str()),
168172 );
169173 self.directories = if gzip {
170174 BTreeSet::new()
171175 } else {
172삭제: present::target_directories(
173삭제: &self.model.entries,
174삭제: &self.model.selected,
175삭제: self.selected_only,
176삭제: )
176추가: present::target_directories(&self.model.entries, &selection)
177177 };
178178 let request = Start::Extract {
179179 archive: self.model.archive.clone().unwrap(),
180180 destination: self.destination.clone(),
181삭제: selection: if self.selected_only {
182삭제: Selection::EntryIds(self.model.selected.iter().copied().collect())
183삭제: } else {
184삭제: Selection::All
185삭제: },
181추가: selection,
186182 list_id: self.model.list_id.clone().unwrap(),
187183 gzip_output_name: gzip.then(|| self.gzip_name.clone()),
188184 };
수정tests/rust-app-real-worker/flows.rs+5-0
@@ -58,6 +58,7 @@ fn binary(name: &str) -> PathBuf {
5858#[derive(Default)]
5959struct Observation {
6060 jobs: Vec<Vec<&'static str>>,
61추가: starts: Vec<Start>,
6162}
6263struct ObservedFactory {
6364 process: ProcessFactory,
@@ -82,6 +83,9 @@ impl Factory for ObservedFactory {
8283}
8384impl Connection for ObservedConnection {
8485 fn send(&mut self, request: Request) -> Result<(), String> {
86추가: if let Command::Start(start) = &request.command {
87추가: self.observed.borrow_mut().starts.push(start.clone());
88추가: }
8589 self.connection.send(request)
8690 }
8791 fn poll(&mut self) -> Option<HostEvent> {
@@ -287,6 +291,7 @@ mod screen {
287291 }
288292 }
289293 include!("password_flows.rs");
294추가: include!("selection_flows.rs");
290295
291296 fn archive_flow(name: &str, format: Format) {
292297 let scratch = Scratch::new();
추가tests/rust-app-real-worker/selection_flows.rs+148-0
@@ -0,0 +1,148 @@
1추가: #[test]
2추가: fn extraction_completion_matches_actual_worker_selection_matrix() {
3추가: use std::collections::BTreeSet;
4추가:
5추가: fn contents(root: &Path) -> BTreeSet<String> {
6추가: fn visit(root: &Path, current: &Path, found: &mut BTreeSet<String>) {
7추가: for entry in fs::read_dir(current).unwrap() {
8추가: let path = entry.unwrap().path();
9추가: found.insert(
10추가: path.strip_prefix(root)
11추가: .unwrap()
12추가: .to_str()
13추가: .unwrap()
14추가: .replace('\\', "/"),
15추가: );
16추가: if path.is_dir() {
17추가: visit(root, &path, found);
18추가: }
19추가: }
20추가: }
21추가: let mut found = BTreeSet::new();
22추가: visit(root, root, &mut found);
23추가: found
24추가: }
25추가:
26추가: let scratch = Scratch::new();
27추가: let docs = make_directory(&scratch.path("docs"));
28추가: fs::create_dir(docs.join("empty")).unwrap();
29추가: fs::create_dir(docs.join("nested")).unwrap();
30추가: fs::write(docs.join("nested/one.txt"), b"nested content").unwrap();
31추가: let root_file = scratch.path("root.txt");
32추가: fs::write(&root_file, b"root content").unwrap();
33추가: let archive = scratch.path("selection.zip");
34추가: let (factory, observed) = observed_factory();
35추가: let mut screen = Screen::new(factory);
36추가: screen.app.add_sources(vec![docs, root_file]);
37추가: screen.render(vec![]);
38추가: screen.set_text("zip-name", "selection.zip");
39추가: screen.click("만들기");
40추가: screen.settle();
41추가:
42추가: let cases: [(&str, Option<&[&str]>, &[&str]); 6] = [
43추가: (
44추가: "all",
45추가: None,
46추가: &[
47추가: "docs",
48추가: "docs/empty",
49추가: "docs/nested",
50추가: "docs/nested/one.txt",
51추가: "root.txt",
52추가: ],
53추가: ),
54추가: (
55추가: "files",
56추가: Some(&["docs/nested/one.txt", "root.txt"]),
57추가: &["docs", "docs/nested", "docs/nested/one.txt", "root.txt"],
58추가: ),
59추가: ("directory", Some(&["docs"]), &["docs"]),
60추가: (
61추가: "mixed",
62추가: Some(&["docs", "docs/nested/one.txt"]),
63추가: &["docs", "docs/nested", "docs/nested/one.txt"],
64추가: ),
65추가: ("empty", Some(&["docs/empty"]), &["docs", "docs/empty"]),
66추가: (
67추가: "nested-directory",
68추가: Some(&["docs/nested"]),
69추가: &["docs", "docs/nested"],
70추가: ),
71추가: ];
72추가: for (name, selected, expected) in cases {
73추가: screen.open(&archive);
74추가: let ids = selected.map(|names| {
75추가: names
76추가: .iter()
77추가: .map(|name| {
78추가: screen
79추가: .app
80추가: .model
81추가: .entries
82추가: .iter()
83추가: .find(|entry| entry.name.trim_end_matches('/') == *name)
84추가: .unwrap_or_else(|| panic!("목록 항목 누락: {name}"))
85추가: .id
86추가: })
87추가: .collect::<BTreeSet<_>>()
88추가: });
89추가: if let Some(ids) = &ids {
90추가: screen.app.model.selected = ids.clone();
91추가: screen.click("선택한 항목만 풀기");
92추가: }
93추가: let output = make_directory(&scratch.path(name));
94추가: screen.extract(&output);
95추가: let terminal = screen.app.model.terminal.as_ref().unwrap();
96추가: assert_eq!(terminal.outcome, Outcome::Completed, "{name}");
97추가: assert!(screen.app.model.confirmed, "{name}");
98추가: assert!(terminal.error.is_none(), "{name}");
99추가: let expected = expected
100추가: .iter()
101추가: .map(|name| name.to_string())
102추가: .collect::<BTreeSet<_>>();
103추가: assert_eq!(contents(&output), expected, "{name}");
104추가: let reports = screen
105추가: .app
106추가: .model
107추가: .outputs
108추가: .iter()
109추가: .map(|(name, disposition)| {
110추가: assert_eq!(*disposition, Disposition::Created);
111추가: name.clone()
112추가: })
113추가: .collect::<BTreeSet<_>>();
114추가: assert_eq!(reports, expected, "{name}");
115추가: assert_eq!(terminal.created_count as usize, expected.len(), "{name}");
116추가: for (path, bytes) in [
117추가: ("docs/nested/one.txt", b"nested content".as_slice()),
118추가: ("root.txt", b"root content".as_slice()),
119추가: ] {
120추가: if expected.contains(path) {
121추가: assert_eq!(fs::read(output.join(path)).unwrap(), bytes, "{name}");
122추가: }
123추가: }
124추가: match observed.borrow().starts.last().unwrap() {
125추가: Start::Extract { selection, .. } => match (selection, &ids) {
126추가: (Selection::All, None) => {}
127추가: (Selection::EntryIds(actual), Some(ids)) => {
128추가: assert_eq!(actual, &ids.iter().copied().collect::<Vec<_>>(), "{name}");
129추가: }
130추가: _ => panic!("요청 선택 범위 불일치: {name}"),
131추가: },
132추가: _ => panic!("추출 요청 누락: {name}"),
133추가: }
134추가: let shown = screen.render(vec![]);
135추가: assert!(
136추가: shown.iter().any(|(text, _)| text == "압축을 풀었습니다"),
137추가: "{name}: {shown:?}"
138추가: );
139추가: assert!(
140추가: !shown
141추가: .iter()
142추가: .any(|(text, _)| text.contains("저장이 끝났는지") || text.contains("일부 파일만")),
143추가: "{name}"
144추가: );
145추가: screen.click("확인");
146추가: }
147추가: assert_reaped(&observed);
148추가: }
수정tests/rust-app-ui/presentation.rs+22-8
@@ -148,7 +148,7 @@ fn every_error_and_stage_has_user_facing_text() {
148148 assert_eq!(progress_text(Stage::Decode, false), "압축을 푸는 중");
149149}
150150#[test]
151삭제: fn folder_selection_expands_only_matching_descendants() {
151추가: fn file_targets_follow_requested_ids_without_expanding_directories() {
152152 let entries = vec![
153153 Entry {
154154 id: 0,
@@ -176,9 +176,25 @@ fn folder_selection_expands_only_matching_descendants() {
176176 },
177177 ];
178178 assert_eq!(
179삭제: target_files(&entries, &[0].into_iter().collect(), true, None),
179추가: target_files(&entries, &Selection::EntryIds(vec![0]), None),
180추가: Some(BTreeSet::new())
181추가: );
182추가: assert_eq!(
183추가: target_files(&entries, &Selection::EntryIds(vec![0, 2]), None),
184추가: Some(["docs-old/two.txt".into()].into_iter().collect())
185추가: );
186추가: assert_eq!(
187추가: target_files(&entries, &Selection::EntryIds(vec![1]), None),
180188 Some(["docs/one.txt".into()].into_iter().collect())
181189 );
190추가: assert_eq!(
191추가: target_files(&entries, &Selection::All, None),
192추가: Some(
193추가: ["docs/one.txt".into(), "docs-old/two.txt".into()]
194추가: .into_iter()
195추가: .collect()
196추가: )
197추가: );
182198}
183199
184200#[test]
@@ -277,13 +293,11 @@ fn directory_targets_include_selected_members_and_implicit_parents() {
277293 },
278294 ];
279295 assert_eq!(
280삭제: target_directories(&entries, &[0].into_iter().collect(), true),
281삭제: ["top".into(), "top/empty".into(), "top/nested".into()]
282삭제: .into_iter()
283삭제: .collect()
296추가: target_directories(&entries, &Selection::EntryIds(vec![0])),
297추가: ["top".into()].into_iter().collect()
284298 );
285299 assert_eq!(
286삭제: target_directories(&entries, &[2].into_iter().collect(), true),
300추가: target_directories(&entries, &Selection::EntryIds(vec![2])),
287301 ["top".into(), "top/nested".into()].into_iter().collect()
288302 );
289303}
@@ -298,7 +312,7 @@ fn duplicate_names_prevent_file_completion_assumptions() {
298312 packed: None,
299313 encrypted: false,
300314 };
301삭제: assert!(target_files(&[entry.clone(), entry], &BTreeSet::new(), false, None).is_none());
315추가: assert!(target_files(&[entry.clone(), entry], &Selection::All, None).is_none());
302316 assert_eq!(
303317 warnings(Some(&terminal()), true, None, &BTreeSet::new(), &[]),
304318 vec![UNCERTAIN]