batch_mode_batch_workspace_interface/
failing_mock.rs1crate::ix!();
3
4#[derive(Default, Debug)]
6pub struct FailingWorkspace {}
7
8#[async_trait]
9impl LoadSeedByCustomId for FailingWorkspace {
10 async fn load_seed_by_custom_id(
11 &self,
12 custom_id: &CustomRequestId,
13 ) -> Result<Box<dyn Named + Send + Sync>, BatchWorkspaceError> {
14 #[derive(Debug)]
16 struct Dummy(String);
17 impl Named for Dummy {
18 fn name(&self) -> std::borrow::Cow<'_, str> {
19 std::borrow::Cow::Borrowed(&self.0)
20 }
21 }
22 Ok(Box::new(Dummy(custom_id.as_str().to_owned())))
23 }
24}
25
26impl GetSeedManifestFilenameAtIndex for FailingWorkspace {
27 fn seed_manifest_filename(&self, batch_idx: &BatchIndex) -> PathBuf {
28 PathBuf::from("/this/path/does/not/exist/any_seed_manifest.json")
29 }
30}
31
32impl GetTargetDir for FailingWorkspace {
33
34 fn get_target_dir(&self) -> PathBuf {
35 todo!()
36 }
37}
38
39impl GetInputFilenameAtIndex for FailingWorkspace {
40 fn input_filename(&self, _batch_idx: &BatchIndex) -> PathBuf {
41 PathBuf::from("/this/path/does/not/exist/any_input.json")
42 }
43}
44impl GetOutputFilenameAtIndex for FailingWorkspace {
45 fn output_filename(&self, _batch_idx: &BatchIndex) -> PathBuf {
46 PathBuf::from("/this/path/does/not/exist/any_output.json")
47 }
48}
49impl GetErrorFilenameAtIndex for FailingWorkspace {
50 fn error_filename(&self, _batch_idx: &BatchIndex) -> PathBuf {
51 PathBuf::from("/this/path/does/not/exist/any_error.json")
52 }
53}
54impl GetMetadataFilenameAtIndex for FailingWorkspace {
55 fn metadata_filename(&self, _batch_idx: &BatchIndex) -> PathBuf {
56 PathBuf::from("/this/path/does/not/exist/any_metadata.json")
57 }
58}
59impl GetDoneDirectory for FailingWorkspace {
60 fn get_done_directory(&self) -> &PathBuf {
61 static DIR: once_cell::sync::Lazy<PathBuf> =
62 once_cell::sync::Lazy::new(|| PathBuf::from("/this/path/does/not/exist/done_dir"));
63 &DIR
64 }
65}
66impl GetFailedJsonRepairsDir for FailingWorkspace {
67 fn failed_json_repairs_dir(&self) -> PathBuf {
68 PathBuf::from("/this/path/does/not/exist/failing_json_repairs")
69 }
70}
71impl GetFailedItemsDir for FailingWorkspace {
72 fn failed_items_dir(&self) -> PathBuf {
73 PathBuf::from("/this/path/does/not/exist/failing_items")
74 }
75}
76impl GetTextStoragePath for FailingWorkspace {
77 fn text_storage_path(&self, _batch_idx: &BatchIndex) -> PathBuf {
78 PathBuf::from("/this/path/does/not/exist/failing_text_storage.txt")
79 }
80}
81impl GetWorkdir for FailingWorkspace {
82 fn workdir(&self) -> PathBuf {
83 PathBuf::from("/this/path/does/not/exist/workdir")
84 }
85}
86
87impl GetTargetPath for FailingWorkspace
88{
89 type Item = Arc<dyn GetTargetPathForAIExpansion + Send + Sync + 'static>;
90
91 fn target_path(
92 &self,
93 item: &Self::Item,
94 expected_content_type: &ExpectedContentType
95 ) -> PathBuf {
96 let broken_dir = self.workdir().join("this_cannot_be_created");
97 item.target_path_for_ai_json_expansion(&broken_dir, expected_content_type)
98 }
99}
100#[async_trait]
101impl BatchWorkspaceInterface for FailingWorkspace {}
102
103#[cfg(test)]
104mod batch_workspace_interface_exhaustive_tests {
105 use super::*;
106
107 #[traced_test]
111 fn mock_workspace_implements_all_traits() {
112 info!("Starting test: mock_workspace_implements_all_traits");
113 let workspace = Arc::new(MockBatchWorkspace::default());
114 let idx = BatchIndex::Usize(123);
115
116 let in_file = workspace.input_filename(&idx);
118 debug!("input_filename => {:?}", in_file);
119
120 let out_file = workspace.output_filename(&idx);
122 debug!("output_filename => {:?}", out_file);
123
124 let err_file = workspace.error_filename(&idx);
126 debug!("error_filename => {:?}", err_file);
127
128 let meta_file = workspace.metadata_filename(&idx);
130 debug!("metadata_filename => {:?}", meta_file);
131
132 let done_dir = workspace.get_done_directory();
134 debug!("done_directory => {:?}", done_dir);
135
136 let txt_store = workspace.text_storage_path(&idx);
138 debug!("text_storage_path => {:?}", txt_store);
139
140 let repairs_dir = workspace.failed_json_repairs_dir();
142 debug!("failed_json_repairs_dir => {:?}", repairs_dir);
143
144 let fails_dir = workspace.failed_items_dir();
146 debug!("failed_items_dir => {:?}", fails_dir);
147
148 let wd = workspace.workdir();
150 debug!("workdir => {:?}", wd);
151
152 let item: Arc<dyn GetTargetPathForAIExpansion + Send + Sync> =
154 Arc::new(MockItem { name: "test_item".to_string() });
155
156 let targ = workspace.target_path(&item, &ExpectedContentType::Json);
157 debug!("target_path => {:?}", targ);
158
159 assert!(in_file.to_string_lossy().contains("mock_input_123"));
161 assert!(out_file.to_string_lossy().contains("mock_output_123"));
162 assert!(err_file.to_string_lossy().contains("mock_error_123"));
163 assert!(meta_file.to_string_lossy().contains("mock_metadata_123"));
164 assert!(!done_dir.as_os_str().is_empty());
165 assert!(txt_store.to_string_lossy().contains("text_storage_123"));
166 assert!(!repairs_dir.as_os_str().is_empty());
167 assert!(!fails_dir.as_os_str().is_empty());
168 assert!(!wd.as_os_str().is_empty());
169 assert!(targ.to_string_lossy().contains("json_output"));
170
171 info!("Finished test: mock_workspace_implements_all_traits");
172 }
173
174 #[traced_test]
175 fn failing_workspace_implements_all_traits() {
176 info!("Starting test: failing_workspace_implements_all_traits");
177 let workspace = Arc::new(FailingWorkspace::default());
178 let idx = BatchIndex::new(); let in_file = workspace.input_filename(&idx);
181 debug!("failing input_filename => {:?}", in_file);
182
183 let out_file = workspace.output_filename(&idx);
184 debug!("failing output_filename => {:?}", out_file);
185
186 let err_file = workspace.error_filename(&idx);
187 debug!("failing error_filename => {:?}", err_file);
188
189 let meta_file = workspace.metadata_filename(&idx);
190 debug!("failing metadata_filename => {:?}", meta_file);
191
192 let done_dir = workspace.get_done_directory();
193 debug!("failing done_directory => {:?}", done_dir);
194
195 let txt_store = workspace.text_storage_path(&idx);
196 debug!("failing text_storage_path => {:?}", txt_store);
197
198 let repairs_dir = workspace.failed_json_repairs_dir();
199 debug!("failing failed_json_repairs_dir => {:?}", repairs_dir);
200
201 let fails_dir = workspace.failed_items_dir();
202 debug!("failing failed_items_dir => {:?}", fails_dir);
203
204 let wd = workspace.workdir();
205 debug!("failing workdir => {:?}", wd);
206
207 let item: Arc<dyn GetTargetPathForAIExpansion + Send + Sync> =
209 Arc::new(MockItem { name: "test_failing_item".to_string() });
210
211 let targ = workspace.target_path(&item, &ExpectedContentType::PlainText);
212 debug!("failing target_path => {:?}", targ);
213
214 assert!(in_file.to_string_lossy().contains("/this/path/does/not/exist"));
215 assert!(out_file.to_string_lossy().contains("/this/path/does/not/exist"));
216 assert!(err_file.to_string_lossy().contains("/this/path/does/not/exist"));
217 assert!(meta_file.to_string_lossy().contains("/this/path/does/not/exist"));
218 assert!(done_dir.to_string_lossy().contains("/this/path/does/not/exist/done_dir"));
219 assert!(txt_store.to_string_lossy().contains("/this/path/does/not/exist"));
220 assert!(repairs_dir.to_string_lossy().contains("/this/path/does/not/exist/failing_json_repairs"));
221 assert!(fails_dir.to_string_lossy().contains("/this/path/does/not/exist/failing_items"));
222 assert!(wd.to_string_lossy().contains("/this/path/does/not/exist/workdir"));
223 assert!(targ.to_string_lossy().contains("this_cannot_be_created"));
224
225 info!("Finished test: failing_workspace_implements_all_traits");
226 }
227}