From c051153a1f60f6d8ee22ee47d02169e10b28ace7 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Fri, 4 Oct 2019 18:05:27 -0700 Subject: [PATCH] Mark project file as instigating source for top-level instances --- src/snapshot_middleware/project.rs | 17 ++++++++++++----- .../test__project_from_direct_file.snap | 4 +++- .../snapshots/test__project_from_folder.snap | 4 +++- .../test__project_path_property_overrides.snap | 4 +++- .../snapshots/test__project_with_children.snap | 4 +++- .../test__project_with_path_to_project.snap | 4 +++- ...ject_with_path_to_project_with_children.snap | 4 +++- .../test__project_with_path_to_txt.snap | 4 +++- .../test__project_with_resolved_properties.snap | 4 +++- ...est__project_with_unresolved_properties.snap | 4 +++- 10 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/snapshot_middleware/project.rs b/src/snapshot_middleware/project.rs index ac3106a6..a0b5d6aa 100644 --- a/src/snapshot_middleware/project.rs +++ b/src/snapshot_middleware/project.rs @@ -51,11 +51,18 @@ impl SnapshotMiddleware for SnapshotProject { // unwrap is safe. let mut snapshot = snapshot_project_node(&project.name, &project.tree, imfs)?.unwrap(); - // If the project file updates, we want to trigger a snapshot of the - // entire project tree. We're overwriting the "instigating path" for the - // root instance of the project, since we want to snapshot the project - // file and not the snapshot's original instigating path, or else we - // won't pick up new changes from the project file. + // Setting the instigating source to the project file path is a little + // coarse. + // + // Ideally, we'd only snapshot the project file if the project file + // actually changed. Because Rojo only has the concept of one + // relevant path -> snapshot path mapping per instance, we pick the more + // conservative approach of snapshotting the project file if any + // relevant paths changed. + snapshot.metadata.instigating_source = Some(entry.path().to_path_buf().into()); + + // Mark this snapshot (the root node of the project file) as being + // related to the project file. // // We SHOULD NOT mark the project file as a relevant path for any // nodes that aren't roots. They'll be updated as part of the project diff --git a/src/snapshot_middleware/snapshots/test__project_from_direct_file.snap b/src/snapshot_middleware/snapshots/test__project_from_direct_file.snap index 3e4c5d40..1d4f7009 100644 --- a/src/snapshot_middleware/snapshots/test__project_from_direct_file.snap +++ b/src/snapshot_middleware/snapshots/test__project_from_direct_file.snap @@ -5,9 +5,11 @@ expression: instance_snapshot snapshot_id: ~ metadata: ignore_unknown_instances: true + instigating_source: + Path: /foo/hello.project.json relevant_paths: - /foo/hello.project.json name: direct-project class_name: Model properties: {} -children: [] \ No newline at end of file +children: [] diff --git a/src/snapshot_middleware/snapshots/test__project_from_folder.snap b/src/snapshot_middleware/snapshots/test__project_from_folder.snap index 8b7935ab..d8417c62 100644 --- a/src/snapshot_middleware/snapshots/test__project_from_folder.snap +++ b/src/snapshot_middleware/snapshots/test__project_from_folder.snap @@ -5,9 +5,11 @@ expression: instance_snapshot snapshot_id: ~ metadata: ignore_unknown_instances: true + instigating_source: + Path: /foo/default.project.json relevant_paths: - /foo/default.project.json name: indirect-project class_name: Folder properties: {} -children: [] \ No newline at end of file +children: [] diff --git a/src/snapshot_middleware/snapshots/test__project_path_property_overrides.snap b/src/snapshot_middleware/snapshots/test__project_path_property_overrides.snap index 5c367846..ee98a5c6 100644 --- a/src/snapshot_middleware/snapshots/test__project_path_property_overrides.snap +++ b/src/snapshot_middleware/snapshots/test__project_path_property_overrides.snap @@ -5,6 +5,8 @@ expression: instance_snapshot snapshot_id: ~ metadata: ignore_unknown_instances: true + instigating_source: + Path: /foo/default.project.json relevant_paths: - /foo/other.project.json - /foo/default.project.json @@ -14,4 +16,4 @@ properties: Value: Type: String Value: Changed -children: [] \ No newline at end of file +children: [] diff --git a/src/snapshot_middleware/snapshots/test__project_with_children.snap b/src/snapshot_middleware/snapshots/test__project_with_children.snap index f3270e67..b6329a43 100644 --- a/src/snapshot_middleware/snapshots/test__project_with_children.snap +++ b/src/snapshot_middleware/snapshots/test__project_with_children.snap @@ -5,6 +5,8 @@ expression: instance_snapshot snapshot_id: ~ metadata: ignore_unknown_instances: true + instigating_source: + Path: /foo/default.project.json relevant_paths: - /foo/default.project.json name: children @@ -18,4 +20,4 @@ children: name: Child class_name: Model properties: {} - children: [] \ No newline at end of file + children: [] diff --git a/src/snapshot_middleware/snapshots/test__project_with_path_to_project.snap b/src/snapshot_middleware/snapshots/test__project_with_path_to_project.snap index d3d51a0d..406b0b61 100644 --- a/src/snapshot_middleware/snapshots/test__project_with_path_to_project.snap +++ b/src/snapshot_middleware/snapshots/test__project_with_path_to_project.snap @@ -5,10 +5,12 @@ expression: instance_snapshot snapshot_id: ~ metadata: ignore_unknown_instances: true + instigating_source: + Path: /foo/default.project.json relevant_paths: - /foo/other.project.json - /foo/default.project.json name: path-project class_name: Model properties: {} -children: [] \ No newline at end of file +children: [] diff --git a/src/snapshot_middleware/snapshots/test__project_with_path_to_project_with_children.snap b/src/snapshot_middleware/snapshots/test__project_with_path_to_project_with_children.snap index 199b2129..e0ffbefd 100644 --- a/src/snapshot_middleware/snapshots/test__project_with_path_to_project_with_children.snap +++ b/src/snapshot_middleware/snapshots/test__project_with_path_to_project_with_children.snap @@ -5,6 +5,8 @@ expression: instance_snapshot snapshot_id: ~ metadata: ignore_unknown_instances: true + instigating_source: + Path: /foo/default.project.json relevant_paths: - /foo/other.project.json - /foo/default.project.json @@ -19,4 +21,4 @@ children: name: SomeChild class_name: Model properties: {} - children: [] \ No newline at end of file + children: [] diff --git a/src/snapshot_middleware/snapshots/test__project_with_path_to_txt.snap b/src/snapshot_middleware/snapshots/test__project_with_path_to_txt.snap index 48e0fae5..de80caa4 100644 --- a/src/snapshot_middleware/snapshots/test__project_with_path_to_txt.snap +++ b/src/snapshot_middleware/snapshots/test__project_with_path_to_txt.snap @@ -5,6 +5,8 @@ expression: instance_snapshot snapshot_id: ~ metadata: ignore_unknown_instances: false + instigating_source: + Path: /foo/default.project.json relevant_paths: - /foo/other.txt - /foo/default.project.json @@ -14,4 +16,4 @@ properties: Value: Type: String Value: "Hello, world!" -children: [] \ No newline at end of file +children: [] diff --git a/src/snapshot_middleware/snapshots/test__project_with_resolved_properties.snap b/src/snapshot_middleware/snapshots/test__project_with_resolved_properties.snap index 27a3c724..96194799 100644 --- a/src/snapshot_middleware/snapshots/test__project_with_resolved_properties.snap +++ b/src/snapshot_middleware/snapshots/test__project_with_resolved_properties.snap @@ -5,6 +5,8 @@ expression: instance_snapshot snapshot_id: ~ metadata: ignore_unknown_instances: true + instigating_source: + Path: /foo/default.project.json relevant_paths: - /foo/default.project.json name: resolved-properties @@ -13,4 +15,4 @@ properties: Value: Type: String Value: "Hello, world!" -children: [] \ No newline at end of file +children: [] diff --git a/src/snapshot_middleware/snapshots/test__project_with_unresolved_properties.snap b/src/snapshot_middleware/snapshots/test__project_with_unresolved_properties.snap index 98f76032..383d0746 100644 --- a/src/snapshot_middleware/snapshots/test__project_with_unresolved_properties.snap +++ b/src/snapshot_middleware/snapshots/test__project_with_unresolved_properties.snap @@ -5,6 +5,8 @@ expression: instance_snapshot snapshot_id: ~ metadata: ignore_unknown_instances: true + instigating_source: + Path: /foo/default.project.json relevant_paths: - /foo/default.project.json name: unresolved-properties @@ -13,4 +15,4 @@ properties: Value: Type: String Value: Hi! -children: [] \ No newline at end of file +children: []