diff --git a/artefact/lib/artefact/op.ex b/artefact/lib/artefact/op.ex index 31eac86..78ddf7a 100644 --- a/artefact/lib/artefact/op.ex +++ b/artefact/lib/artefact/op.ex @@ -157,11 +157,16 @@ defmodule Artefact.Op do nodes_from_a = Enum.map(a1.graph.nodes, fn n -> Map.get(primary_updates, n.uuid, n) end) + rel_offset = length(a1.graph.relationships) + rels_from_b = - Enum.map(a2.graph.relationships, fn rel -> + a2.graph.relationships + |> Enum.with_index(rel_offset) + |> Enum.map(fn {rel, i} -> %{ rel - | from_id: Map.get(b_id_remap, rel.from_id, rel.from_id), + | id: "r#{i}", + from_id: Map.get(b_id_remap, rel.from_id, rel.from_id), to_id: Map.get(b_id_remap, rel.to_id, rel.to_id) } end) diff --git a/artefact/test/artefact_test.exs b/artefact/test/artefact_test.exs index fb954dc..db33102 100644 --- a/artefact/test/artefact_test.exs +++ b/artefact/test/artefact_test.exs @@ -556,6 +556,7 @@ defmodule ArtefactTest do tag: :self_harmonise, details: %{uuid: uuid} }} = Artefact.harmonise(a, a, bindings) + assert uuid == a.uuid end @@ -1309,6 +1310,34 @@ defmodule ArtefactTest do Artefact.combine!(heart, other) end end + + test "combine!/2 produces unique relationship IDs" do + shared_uuid = "019d0000-0000-7000-8000-000000000099" + + a = + Artefact.new!( + base_label: "Knowing", + nodes: [ + shared: [labels: ["Node"], uuid: shared_uuid], + b: [labels: ["B"]] + ], + relationships: [[from: :shared, type: "KNOWS", to: :b]] + ) + + b = + Artefact.new!( + base_label: "Valuing", + nodes: [ + shared: [labels: ["Node"], uuid: shared_uuid], + c: [labels: ["C"]] + ], + relationships: [[from: :shared, type: "LOVES", to: :c]] + ) + + combined = Artefact.combine!(a, b) + ids = Enum.map(combined.graph.relationships, & &1.id) + assert ids == Enum.uniq(ids), "duplicate relationship IDs after combine!/2" + end end describe "Artefact.graft/3 — happy path with OurShells fixture" do