Skip to content

Commit 3442f3f

Browse files
committed
test(llama-index): add upsert_relations() idempotency test
Verifies that calling upsert_relations() twice with the same Relation produces exactly one edge (MERGE semantics, not CREATE). Closes #21
1 parent 1101ac8 commit 3442f3f

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

tests/integration/adapters/test_llama_index.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,23 @@ def test_upsert_nodes_idempotent(store, tag):
7272
assert len(found) == 1
7373

7474

75+
def test_upsert_relations_idempotent(store, tag):
76+
"""Upserting the same relation twice must produce exactly one edge (MERGE idempotent)."""
77+
src = EntityNode(label="LIIdempRel", name=f"IdempSrc-{tag}")
78+
dst = EntityNode(label="LIIdempRel", name=f"IdempDst-{tag}")
79+
store.upsert_nodes([src, dst])
80+
81+
rel = Relation(label="LI_IDEMP_REL", source_id=src.id, target_id=dst.id)
82+
store.upsert_relations([rel])
83+
store.upsert_relations([rel]) # second call must not duplicate
84+
85+
rows = store._client.cypher(
86+
"MATCH (a {id: $src})-[r:LI_IDEMP_REL]->(b {id: $dst}) RETURN count(r) AS cnt",
87+
params={"src": src.id, "dst": dst.id},
88+
)
89+
assert rows[0]["cnt"] == 1, f"expected exactly 1 edge after double upsert, got: {rows}"
90+
91+
7592
def test_get_by_id(store, tag):
7693
node = EntityNode(label="LIGetById", name=f"ById-{tag}")
7794
node_id = node.id

0 commit comments

Comments
 (0)