Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autosurgeon reconcile not clearing all old data #46

Open
aran opened this issue May 10, 2024 · 1 comment
Open

Autosurgeon reconcile not clearing all old data #46

aran opened this issue May 10, 2024 · 1 comment

Comments

@aran
Copy link
Contributor

aran commented May 10, 2024

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);
    }
}
@aran
Copy link
Contributor Author

aran commented Jun 13, 2024

An reason not to do this in #52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant