Skip to content

Autosurgeon reconcile not clearing all old data #46

Open
@aran

Description

I'm not sure the test below is 100% minimal, but I am seeing that the old key "discard" is not removed from the converted document.

automerge = "0.5.11"
autosurgeon = "0.8.3"
#[cfg(test)]
mod tests {
    use automerge::AutoCommit;
    use autosurgeon::{reconcile, Hydrate, Reconcile};

    pub fn debug_dump_doc<D>(doc: &D) -> String
    where
        D: automerge::ReadDoc,
    {
        serde_json::to_string_pretty(&automerge::AutoSerde::from(doc)).unwrap()
    }

    #[derive(Clone, Debug, Default, Hydrate, Reconcile)]
    pub struct V1Container {
        pub items: Vec<V1Item>,
    }

    #[derive(Clone, Debug, Default, Hydrate, Reconcile)]
    pub struct V1Item{
        pub keep: String,
        pub discard: String,
    }

    #[derive(Clone, Debug, Default, Hydrate, Reconcile)]
    pub struct V2Container {
        pub items: Vec<V2Item>,
    }

    #[derive(Clone, Debug, Default, Hydrate, Reconcile)]
    pub struct V2Item{
        pub keep: String,
    }

    pub fn convert_item(old: V1Item) -> V2Item {
        V2Item {
            keep: old.keep,
        }
    }

    pub fn convert_container(old: V1Container) -> V2Container {
        V2Container {
            items: old.items.into_iter().map(convert_item).collect(),
        }
    }

    fn make_test_v1() -> V1Container {
        V1Container {
            items: vec![
                V1Item {
                    keep: "keep".to_string(),
                    discard: "discard".to_string(),
                },
                V1Item {
                    keep: "keep".to_string(),
                    discard: "discard".to_string(),
                },
            ],
        }
    }

    #[test]
    fn test_container_with_items() {
        let orig = make_test_v1();

        let converted = convert_container(orig.clone());

        let mut doc = AutoCommit::new();
        reconcile(&mut doc, &orig).unwrap();
        reconcile(&mut doc, &converted).unwrap();
        let orig_dump = debug_dump_doc(&doc);

        let mut new_doc = AutoCommit::new();
        reconcile(&mut new_doc, converted.clone()).unwrap();

        let new_dump = debug_dump_doc(&new_doc);

        assert_eq!(orig_dump, new_dump);
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions