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
9 changes: 7 additions & 2 deletions artefact/lib/artefact/op.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions artefact/test/artefact_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ defmodule ArtefactTest do
tag: :self_harmonise,
details: %{uuid: uuid}
}} = Artefact.harmonise(a, a, bindings)

assert uuid == a.uuid
end

Expand Down Expand Up @@ -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
Expand Down
Loading