diff --git a/lib/components/fabro-manifest/src/workflow_bundle.rs b/lib/components/fabro-manifest/src/workflow_bundle.rs index 4c10a86c1..6c7d5c0d1 100644 --- a/lib/components/fabro-manifest/src/workflow_bundle.rs +++ b/lib/components/fabro-manifest/src/workflow_bundle.rs @@ -147,7 +147,7 @@ impl ComponentRole { struct DocumentId(usize); #[derive(Clone, Debug)] -struct DraftDocument { +struct DocumentRecord { access_path: PathBuf, provisional_path: PathBuf, component: ComponentRole, @@ -155,31 +155,31 @@ struct DraftDocument { } #[derive(Clone, Debug)] -struct DraftFileReference { +struct FileReferenceRecord { type_: CollectedFileReferenceType, original: String, from_document: Option, } #[derive(Clone, Debug)] -struct DraftFile { +struct FileRecord { document: DocumentId, - reference: DraftFileReference, + reference: FileReferenceRecord, } #[derive(Clone, Debug)] -struct DraftWorkflow { +struct WorkflowRecord { graph: DocumentId, config: Option, - files: BTreeMap, + files: BTreeMap, } struct WorkflowBundler<'a> { cwd: PathBuf, inputs: &'a HashMap, - documents: Vec, + documents: Vec, document_ids: HashMap<(PathBuf, ComponentRole, PathBuf), DocumentId>, - workflows: BTreeMap, + workflows: BTreeMap, visited_workflows: HashMap, } @@ -209,7 +209,7 @@ impl<'a> WorkflowBundler<'a> { } let document = DocumentId(self.documents.len()); - self.documents.push(DraftDocument { + self.documents.push(DocumentRecord { access_path, provisional_path, component, @@ -219,7 +219,7 @@ impl<'a> WorkflowBundler<'a> { document } - fn document(&self, document: DocumentId) -> &DraftDocument { + fn document(&self, document: DocumentId) -> &DocumentRecord { &self.documents[document.0] } @@ -271,7 +271,7 @@ impl<'a> WorkflowBundler<'a> { }) .transpose()?; - let mut workflow = DraftWorkflow { + let mut workflow = WorkflowRecord { graph, config, files: BTreeMap::new(), @@ -308,7 +308,7 @@ impl<'a> WorkflowBundler<'a> { fn collect_workflow_files( &mut self, graph_document_id: DocumentId, - files: &mut BTreeMap, + files: &mut BTreeMap, visited_imports: &mut HashSet, ) -> Result<()> { let graph = parser::parse(&self.document(graph_document_id).source).with_context(|| { @@ -454,7 +454,7 @@ impl<'a> WorkflowBundler<'a> { /// `@`-referenced file (a goal or prompt document). fn collect_bundled_template_includes( &mut self, - files: &mut BTreeMap, + files: &mut BTreeMap, bundled: DocumentId, workflow_template_root: &ManifestPath, from_document: DocumentId, @@ -474,7 +474,7 @@ impl<'a> WorkflowBundler<'a> { fn collect_template_include_files( &mut self, - files: &mut BTreeMap, + files: &mut BTreeMap, source: TemplateSource, source_document: DocumentId, from_document: DocumentId, @@ -522,9 +522,9 @@ impl<'a> WorkflowBundler<'a> { ComponentRole::Workflow, source.content, ); - files.insert(key.clone(), DraftFile { + files.insert(key.clone(), FileRecord { document, - reference: DraftFileReference { + reference: FileReferenceRecord { type_: CollectedFileReferenceType::FileInline, original: key, from_document: Some(from_document), @@ -538,7 +538,7 @@ impl<'a> WorkflowBundler<'a> { &self, source_path: &ManifestPath, closure: &TemplateDependencyClosure, - files: &BTreeMap, + files: &BTreeMap, from_document: DocumentId, ) -> Result<()> { let Some(source) = closure.sources.get(source_path) else { @@ -576,7 +576,7 @@ impl<'a> WorkflowBundler<'a> { fn collect_config_dockerfile( &mut self, config: DocumentId, - files: &mut BTreeMap, + files: &mut BTreeMap, ) -> Result<()> { let layer = self .document(config) @@ -611,7 +611,7 @@ impl<'a> WorkflowBundler<'a> { fn collect_environment_dockerfile( &mut self, - files: &mut BTreeMap, + files: &mut BTreeMap, base_dir: &Path, config: DocumentId, image: Option<&EnvironmentImageLayer>, @@ -633,7 +633,7 @@ impl<'a> WorkflowBundler<'a> { fn collect_bundled_file( &mut self, - files: &mut BTreeMap, + files: &mut BTreeMap, base_dir: &Path, reference: &str, reference_type: CollectedFileReferenceType, @@ -676,9 +676,9 @@ impl<'a> WorkflowBundler<'a> { self.document(from_document).component, source, ); - files.insert(key, DraftFile { + files.insert(key, FileRecord { document, - reference: DraftFileReference { + reference: FileReferenceRecord { type_: reference_type, original: reference.to_owned(), from_document: Some(from_document), @@ -742,43 +742,43 @@ impl<'a> WorkflowBundler<'a> { } } -/// Finalizes draft documents into collected documents, rejecting conflicting +/// Finalizes document records into collected documents, rejecting conflicting /// physical aliases and virtual-coordinate collisions. -fn finalize_documents(drafts: Vec) -> Result> { +fn finalize_documents(records: Vec) -> Result> { let mut deficits = BTreeMap::::new(); - for draft in &drafts { - let deficit = leading_parent_count(&draft.provisional_path); + for record in &records { + let deficit = leading_parent_count(&record.provisional_path); deficits - .entry(draft.component) + .entry(record.component) .and_modify(|current| *current = (*current).max(deficit)) .or_insert(deficit); } - let paths = drafts + let paths = records .iter() - .map(|draft| { + .map(|record| { finalize_component_path( - &draft.provisional_path, - draft.component, - deficits.get(&draft.component).copied().unwrap_or_default(), + &record.provisional_path, + record.component, + deficits.get(&record.component).copied().unwrap_or_default(), ) }) .collect::>>()?; - let mut order = (0..drafts.len()).collect::>(); + let mut order = (0..records.len()).collect::>(); order.sort_by(|left, right| { paths[*left] .cmp(&paths[*right]) - .then_with(|| drafts[*left].access_path.cmp(&drafts[*right].access_path)) + .then_with(|| records[*left].access_path.cmp(&records[*right].access_path)) }); let mut physical_to_virtual = BTreeMap::::new(); let mut virtual_to_physical = BTreeMap::::new(); for index in order { - let physical = std::fs::canonicalize(&drafts[index].access_path).with_context(|| { + let physical = std::fs::canonicalize(&records[index].access_path).with_context(|| { format!( "failed to identify collected file {}", - drafts[index].access_path.display() + records[index].access_path.display() ) })?; let path = &paths[index]; @@ -798,13 +798,13 @@ fn finalize_documents(drafts: Vec) -> Result Result { +fn stable_template_root(document: &DocumentRecord, source: &TemplateSource) -> Result { let relative = source .path .as_path() @@ -1489,14 +1489,14 @@ dockerfile = { path = "Dockerfile" } let second = temp.path().join("second.md"); write_file(&first, "first\n"); write_file(&second, "second\n"); - let draft = |access_path| DraftDocument { + let record = |access_path| DocumentRecord { access_path, provisional_path: PathBuf::from("shared.md"), component: ComponentRole::Workflow, source: String::new(), }; - let error = finalize_documents(vec![draft(first), draft(second)]) + let error = finalize_documents(vec![record(first), record(second)]) .expect_err("virtual collision should be rejected"); assert!( @@ -1510,7 +1510,7 @@ dockerfile = { path = "Dockerfile" } #[test] fn namespace_identity_errors_keep_the_io_error_in_the_source_chain() { let temp = tempfile::tempdir().expect("temp directory should be created"); - let draft = DraftDocument { + let record = DocumentRecord { access_path: temp.path().join("missing.md"), provisional_path: PathBuf::from("missing.md"), component: ComponentRole::Workflow, @@ -1518,7 +1518,7 @@ dockerfile = { path = "Dockerfile" } }; let error = - finalize_documents(vec![draft]).expect_err("missing physical identity should fail"); + finalize_documents(vec![record]).expect_err("missing physical identity should fail"); assert!( error