diff --git a/src/snapshot_middleware/lua.rs b/src/snapshot_middleware/lua.rs index 6f3040e9..077a9b4b 100644 --- a/src/snapshot_middleware/lua.rs +++ b/src/snapshot_middleware/lua.rs @@ -128,10 +128,16 @@ pub fn snapshot_lua_init( let mut init_snapshot = snapshot_lua(context, vfs, init_path, &dir_snapshot.name, script_type)?.unwrap(); + // Preserve the init script's instigating_source (the actual file path) + // before copying the directory's metadata (which has the folder path) + let script_instigating_source = init_snapshot.metadata.instigating_source.take(); + init_snapshot.children = dir_snapshot.children; init_snapshot.metadata = dir_snapshot.metadata; - // The directory snapshot middleware includes all possible init paths - // so we don't need to add it here. + + // Restore the init script's instigating_source so two-way sync writes + // to the actual file (e.g., init.luau) instead of the directory + init_snapshot.metadata.instigating_source = script_instigating_source; DirectoryMetadata::read_and_apply_all(vfs, folder_path, &mut init_snapshot)?; diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__init_module_from_vfs.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__init_module_from_vfs.snap index 6175f588..45416fff 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__init_module_from_vfs.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__init_module_from_vfs.snap @@ -6,7 +6,7 @@ snapshot_id: "00000000000000000000000000000000" metadata: ignore_unknown_instances: false instigating_source: - Path: /root + Path: /root/init.lua relevant_paths: - /root - /root/init.lua diff --git a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__init_module_from_vfs_with_meta.snap b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__init_module_from_vfs_with_meta.snap index 23a7f6b1..736985d4 100644 --- a/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__init_module_from_vfs_with_meta.snap +++ b/src/snapshot_middleware/snapshots/librojo__snapshot_middleware__lua__test__init_module_from_vfs_with_meta.snap @@ -6,7 +6,7 @@ snapshot_id: "00000000000000000000000000000000" metadata: ignore_unknown_instances: false instigating_source: - Path: /root + Path: /root/init.lua relevant_paths: - /root - /root/init.lua