From 79dcfdcf9a5ba13c01183dd112161c0128b3384a Mon Sep 17 00:00:00 2001 From: Lars Date: Tue, 11 Nov 2025 17:54:50 +0100 Subject: [PATCH] Dateien nach "tests" hochladen --- tests/assert_payload_schema.py | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tests/assert_payload_schema.py diff --git a/tests/assert_payload_schema.py b/tests/assert_payload_schema.py new file mode 100644 index 0000000..fc369a1 --- /dev/null +++ b/tests/assert_payload_schema.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +tests/assert_payload_schema.py + +Prüft, ob die erwarteten Payload-Indizes (payload_schema) auf den drei Collections vorhanden sind. +- mindnet_notes : note_id, type, title, updated, tags +- mindnet_chunks : note_id, chunk_id, index, type, tags +- mindnet_edges : note_id, kind, scope, source_id, target_id, chunk_id + +Aufruf: + python3 -m tests.assert_payload_schema +""" +from __future__ import annotations +import json, sys +from typing import Dict, List +from app.core.qdrant import QdrantConfig, get_client, collection_names + +REQUIRED = { + "notes": ["note_id", "type", "title", "updated", "tags"], + "chunks": ["note_id", "chunk_id", "index", "type", "tags"], + "edges": ["note_id", "kind", "scope", "source_id", "target_id", "chunk_id"], +} + +def fetch_schema(client, name: str) -> Dict[str, dict]: + info = client.get_collection(collection_name=name) + d = info.dict() if hasattr(info, "dict") else info + return (d.get("result", {}) or {}).get("payload_schema") or {} + +def ensure_fields(schema: Dict[str, dict], required: List[str]) -> Dict[str, bool]: + return {k: (k in schema) for k in required} + +def main(): + cfg = QdrantConfig.from_env() + client = get_client(cfg) + notes, chunks, edges = collection_names(cfg.prefix) + names = {"notes": notes, "chunks": chunks, "edges": edges} + + report = {} + ok_all = True + for kind, col in names.items(): + sch = fetch_schema(client, col) + checks = ensure_fields(sch, REQUIRED[kind]) + ok = all(checks.values()) + ok_all = ok_all and ok + report[kind] = { + "collection": col, + "ok": ok, + "missing": [k for k,v in checks.items() if not v], + "present": [k for k,v in checks.items() if v], + } + + print(json.dumps({"prefix": cfg.prefix, "ok": ok_all, "report": report}, ensure_ascii=False, indent=2)) + if not ok_all: + sys.exit(1) + +if __name__ == "__main__": + main()