From 045a564172da52bd977054a3278828b2afe8abda Mon Sep 17 00:00:00 2001 From: Keavon Chambers Date: Fri, 13 Nov 2026 21:05:18 -0800 Subject: [PATCH] Fix false positives in the migration API check and scaffolder --- document/migrations/snapshot/src/nodes.rs | 27 ++++++++++++++++++-- document/migrations/snapshot/src/scaffold.rs | 23 ++++++++++++++--- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/document/migrations/snapshot/src/nodes.rs b/document/migrations/snapshot/src/nodes.rs index 66ba05c34dc..33afa914fd5 100644 --- a/document/migrations/snapshot/src/nodes.rs +++ b/document/migrations/snapshot/src/nodes.rs @@ -12,7 +12,7 @@ pub(crate) struct NodeSource { pub version: u32, pub function: String, pub file: PathBuf, - /// The parameters and output as written, without their attributes. Comparing it tells whether stored inputs still fit. + /// The parameters and output as written, without their attributes or `#[data]` fields. Comparing it tells whether stored inputs still fit. pub signature: String, } @@ -131,7 +131,10 @@ fn node_source(function: &syn::ItemFn, file: &Path, module_path: &[String]) -> O } let function_name = function.sig.ident.to_string(); - let parameters = function.sig.inputs.iter().map(|parameter| match parameter { + + // A `#[data]` field is the node's own state rather than a stored input, so documents don't notice it changing + let is_data_field = |parameter: &&syn::FnArg| matches!(parameter, syn::FnArg::Typed(typed) if typed.attrs.iter().any(|attribute| attribute.path().is_ident("data"))); + let parameters = function.sig.inputs.iter().filter(|parameter| !is_data_field(parameter)).map(|parameter| match parameter { syn::FnArg::Typed(typed) => { let (pattern, ty) = (&typed.pat, &typed.ty); quote::quote!(#pattern: #ty).to_string() @@ -149,3 +152,23 @@ fn node_source(function: &syn::ItemFn, file: &Path, module_path: &[String]) -> O signature, }) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn data_fields_are_left_out_of_the_signature() { + let function: syn::ItemFn = syn::parse_quote! { + #[node_macro::node(category("Raster"))] + fn lookup(_: impl Ctx, image: Item, #[data] cache: Cache) -> Item { + image + } + }; + let node = node_source(&function, Path::new("lib.rs"), &["raster_nodes".to_string()]).expect("the function is a node"); + + assert_eq!(node.identifier, "raster_nodes::LookupNode"); + assert!(!node.signature.contains("cache"), "{}", node.signature); + assert!(node.signature.contains("image"), "{}", node.signature); + } +} diff --git a/document/migrations/snapshot/src/scaffold.rs b/document/migrations/snapshot/src/scaffold.rs index 565ddee09f8..6f146502a52 100644 --- a/document/migrations/snapshot/src/scaffold.rs +++ b/document/migrations/snapshot/src/scaffold.rs @@ -1,6 +1,6 @@ //! Scaffolds node migrations into `migration-nodes`, one file per step, in a module per node crate. -use crate::lineage::{MigrationStep, find_migrations}; +use crate::lineage::{MigrationStep, find_all_migrations}; use crate::nodes::{NodeSource, find_nodes}; use convert_case::{Case, Casing}; use std::path::{Path, PathBuf}; @@ -18,7 +18,7 @@ pub(crate) fn scaffold(workspace: &Path, command: &str, arguments: &[String]) -> match (command, arguments) { ("new", []) => { - let steps = missing_steps(&nodes, &find_migrations(&migrations)?); + let steps = missing_steps(&nodes, &find_all_migrations(workspace, &MIGRATION_CRATES)?); if steps.is_empty() { println!("Every node version already has a migration leading to it"); return Ok(()); @@ -35,7 +35,7 @@ pub(crate) fn scaffold(workspace: &Path, command: &str, arguments: &[String]) -> )); } - let steps = missing_steps(std::slice::from_ref(node), &find_migrations(&migrations)?); + let steps = missing_steps(std::slice::from_ref(node), &find_all_migrations(workspace, &MIGRATION_CRATES)?); if steps.is_empty() { return Err(format!("migrations up to `{}`@{} already exist", node.identifier, node.version)); } @@ -242,6 +242,7 @@ fn declare_module(file: &Path, module: &str) -> Result<(), String> { #[cfg(test)] mod tests { use super::*; + use crate::lineage::find_migrations; /// A workspace with one node crate and an empty `migration-nodes`, removed on drop. struct Workspace(PathBuf); @@ -329,6 +330,22 @@ mod tests { assert!(missing_steps(&nodes, &found).is_empty()); } + #[test] + fn a_version_reached_from_a_compiled_migration_needs_no_step() { + let workspace = Workspace::new("compiled"); + let compiled = workspace.0.join("document/migrations/compiled/src"); + std::fs::create_dir_all(&compiled).unwrap(); + std::fs::write( + compiled.join("lib.rs"), + "#[migration(\"old::Node\"@1 => \"blending_nodes::OpacityNode\"@2)]\npub fn opacity_from_node(inputs: &mut Inputs) {}\n", + ) + .unwrap(); + + scaffold(&workspace.0, "new", &[]).unwrap(); + assert!(!workspace.0.join(MIGRATIONS).join("blending_nodes/opacity_v1.rs").exists()); + assert!(workspace.read("legacy/brighten_v1.rs").contains("\"legacy::adjust::BrightenNode\"@1 => @2")); + } + #[test] fn a_file_no_module_declares_is_no_migration() { let workspace = Workspace::new("undeclared");