tests/test_edges_all.py aktualisiert
All checks were successful
Deploy mindnet to llm-node / deploy (push) Successful in 3s

This commit is contained in:
Lars 2025-11-17 15:31:36 +01:00
parent 0cbc4a2d72
commit e4115e705e

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import annotations from __future__ import annotations
import sys, json import sys, json
from collections import Counter from collections import Counter
from app.core.qdrant import QdrantConfig, get_client from app.core.qdrant import QdrantConfig, get_client
@ -21,6 +22,12 @@ def fetch_all(client, col):
break break
return points return points
def is_callout_rule(rule_id: str) -> bool:
if not rule_id:
return False
r = rule_id.lower()
return r.startswith("callout:edge:v1") or ("callout" in r)
def main(): def main():
cfg = QdrantConfig.from_env() cfg = QdrantConfig.from_env()
cl = get_client(cfg) cl = get_client(cfg)
@ -33,15 +40,20 @@ def main():
edges = fetch_all(cl, ce) edges = fetch_all(cl, ce)
chunks_by_note = Counter([c.payload.get("note_id") for c in chunks]) chunks_by_note = Counter([c.payload.get("note_id") for c in chunks])
belongs_by_note = Counter(); next_by_note = Counter(); prev_by_note = Counter() belongs_by_note = Counter()
next_by_note = Counter()
prev_by_note = Counter()
for e in edges: for e in edges:
pl = e.payload pl = e.payload
nid = pl.get("note_id") nid = pl.get("note_id")
k = pl.get("kind") or pl.get("relation") k = pl.get("kind") or pl.get("relation")
if k == "belongs_to": belongs_by_note[nid] += 1 if k == "belongs_to":
elif k == "next": next_by_note[nid] += 1 belongs_by_note[nid] += 1
elif k == "prev": prev_by_note[nid] += 1 elif k == "next":
next_by_note[nid] += 1
elif k == "prev":
prev_by_note[nid] += 1
for nid, ccount in chunks_by_note.items(): for nid, ccount in chunks_by_note.items():
if belongs_by_note[nid] != ccount: if belongs_by_note[nid] != ccount:
@ -62,11 +74,10 @@ def main():
seen.add(key) seen.add(key)
# Wenn Callouts vorhanden: mindestens eine Mehrfach-Ziel-Zeile muss erkannt worden sein # Wenn Callouts vorhanden: mindestens eine Mehrfach-Ziel-Zeile muss erkannt worden sein
callouts = [e for e in edges if (e.payload.get("rule_id") or "").startswith("callout:edge:v1")] callouts = [e for e in edges if is_callout_rule(e.payload.get("rule_id") or "")]
if callouts: if callouts:
from collections import Counter ck = Counter((e.payload.get("chunk_id"), (e.payload.get("kind") or e.payload.get("relation"))) for e in callouts)
cnt = Counter((e.payload.get("chunk_id"), e.payload.get("kind") or e.payload.get("relation")) for e in callouts) if max(ck.values() or [0]) < 2:
if max(cnt.values() or [0]) < 2:
fail("callout edges present but no multi-target callout detected") fail("callout edges present but no multi-target callout detected")
print(json.dumps({"ok": True, "notes_checked": len(chunks_by_note)}, ensure_ascii=False)) print(json.dumps({"ok": True, "notes_checked": len(chunks_by_note)}, ensure_ascii=False))