Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions document/format/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,19 @@ impl<L: Layout> Gdd<L> {
let mut entries: std::collections::BTreeMap<String, Option<Resource>> = std::collections::BTreeMap::new();
let directories = self.working.list_dirs("").await?;
let has_directory = |directory: &str| directories.iter().any(|name| name == directory);
if has_directory(self.layout.resources_dir()) {
if flat.is_none() && has_directory(self.layout.resources_dir()) {
entries.extend(self.working.list(self.layout.resources_dir()).await?.into_iter().map(|path| (path, None)));
}
for (hash, resource) in embedded_bytes {
entries.entry(self.layout.resource_path(&hash)).or_insert(Some(resource));
}

// A copy without history has no older blobs to use as bases, so each blob is written in full
match &flat {
Some(flat) => {
let named = flat.registry().resources.values().filter_map(|entry| entry.hash);
for hash in named.filter(|hash| working_copy_hashes.contains(hash)) {
entries.insert(self.layout.resource_path(&hash), None);
}
for hash in flat.registry().blob_hashes() {
let record = self.blobs.full_record(&hash).ok_or(Error::MissingResource(hash.into()))?;
entries.insert(self.layout.blob_path(&hash), Some(Resource::new_unchecked(record, hash.into())));
Expand Down
44 changes: 44 additions & 0 deletions document/format/tests/open_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,50 @@ fn export_with_history_carries_history_only_resources() {
});
}

/// An export without history leaves behind the working copy's bytes of a resource only history still names.
#[test]
fn export_without_history_drops_history_only_resources() {
use document_format::{ExportFormat, ExportOptions};
use document_graph_storage::NoMetadata;
use graphene_resource::{DataSource, ResourceHash, ResourceId, ResourceRegistry};

futures::executor::block_on(async {
let mut gdd = GddV1::create_in(empty_container(), GddV1Layout, PeerId(9), UserId(9), 0xBEEF, "ed".into(), "std".into()).unwrap_or_else(|error| panic!("create_in failed: {error:?}"));
let byte_store = empty_byte_store();

let removed_payload = b"bytes of a removed resource";
let removed_hash = ResourceHash::from(&removed_payload[..]);
gdd.add_resource(ResourceId::new(), removed_payload).unwrap_or_else(|error| panic!("add_resource failed: {error:?}"));

let kept_payload = b"bytes of a kept resource";
let kept_hash = ResourceHash::from(&kept_payload[..]);
let kept_id = ResourceId::new();
gdd.add_resource(kept_id, kept_payload).unwrap_or_else(|error| panic!("add_resource failed: {error:?}"));

let mut resources = ResourceRegistry::new();
resources.push_source_back(&kept_id, DataSource::Embedded);
resources.resolve(&kept_id, kept_hash);
gdd.commit_from_runtime(&network_referencing_resource(kept_id), &NoMetadata, &resources, &byte_store)
.unwrap_or_else(|error| panic!("commit_from_runtime failed: {error:?}"));

assert!(gdd.has_resource(&removed_hash).await, "the working copy should still hold the removed resource's bytes");

let options = ExportOptions {
include_history: false,
..Default::default()
};
let archive = gdd
.export_to_bytes(ExportFormat::Zip, options, &byte_store, None)
.await
.unwrap_or_else(|error| panic!("export failed: {error:?}"));
let reopened = GddV1::open_from_archive(&archive, empty_container(), GddV1Layout)
.await
.unwrap_or_else(|error| panic!("reopen failed: {error:?}"));
assert!(reopened.has_resource(&kept_hash).await, "bytes the registry names should travel with the export");
assert!(!reopened.has_resource(&removed_hash).await, "history-only bytes should stay behind");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This regression test does not verify that the no-history registry is free of the removed resource's tombstone. Retain the removed ID and assert the reopened registry has no corresponding removed_resources entry, so a persisted history-only tombstone cannot regress unnoticed.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At document/format/tests/open_create.rs, line 621:

<comment>This regression test does not verify that the no-history registry is free of the removed resource's tombstone. Retain the removed ID and assert the reopened registry has no corresponding `removed_resources` entry, so a persisted history-only tombstone cannot regress unnoticed.</comment>

<file context>
@@ -578,6 +578,50 @@ fn export_with_history_carries_history_only_resources() {
+			.await
+			.unwrap_or_else(|error| panic!("reopen failed: {error:?}"));
+		assert!(reopened.has_resource(&kept_hash).await, "bytes the registry names should travel with the export");
+		assert!(!reopened.has_resource(&removed_hash).await, "history-only bytes should stay behind");
+	});
+}
</file context>

});
}

/// A document with un-retired hot ops (e.g. a freshly converted document saved without an interaction
/// boundary, or a save mid-drag) must export losslessly: the hot log travels alongside history and the
/// reopened document reflects the staged edits. Regression for the converted-artwork "no history"
Expand Down
Loading