From e4115e705e4015aee45b22a62e188780ee6db84c Mon Sep 17 00:00:00 2001 From: Lars Date: Mon, 17 Nov 2025 15:31:36 +0100 Subject: [PATCH] tests/test_edges_all.py aktualisiert --- tests/test_edges_all.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/tests/test_edges_all.py b/tests/test_edges_all.py index 971b224..f861aaa 100644 --- a/tests/test_edges_all.py +++ b/tests/test_edges_all.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- from __future__ import annotations + import sys, json from collections import Counter from app.core.qdrant import QdrantConfig, get_client @@ -21,6 +22,12 @@ def fetch_all(client, col): break 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(): cfg = QdrantConfig.from_env() cl = get_client(cfg) @@ -33,20 +40,25 @@ def main(): edges = fetch_all(cl, ce) 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: pl = e.payload nid = pl.get("note_id") k = pl.get("kind") or pl.get("relation") - if k == "belongs_to": belongs_by_note[nid] += 1 - elif k == "next": next_by_note[nid] += 1 - elif k == "prev": prev_by_note[nid] += 1 + if k == "belongs_to": + belongs_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(): if belongs_by_note[nid] != ccount: fail("belongs_to != chunks", {"note_id": nid, "chunks": ccount, "belongs_to": belongs_by_note[nid]}) - if not (next_by_note[nid] == prev_by_note[nid] == max(ccount-1, 0)): + if not (next_by_note[nid] == prev_by_note[nid] == max(ccount - 1, 0)): fail("next/prev mismatch", {"note_id": nid, "chunks": ccount, "next": next_by_note[nid], "prev": prev_by_note[nid]}) # Dubletten @@ -62,11 +74,10 @@ def main(): seen.add(key) # 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: - from collections import Counter - cnt = Counter((e.payload.get("chunk_id"), e.payload.get("kind") or e.payload.get("relation")) for e in callouts) - if max(cnt.values() or [0]) < 2: + ck = 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: fail("callout edges present but no multi-target callout detected") print(json.dumps({"ok": True, "notes_checked": len(chunks_by_note)}, ensure_ascii=False))