tests/inspect_one_note.py hinzugefügt
All checks were successful
Deploy mindnet to llm-node / deploy (push) Successful in 3s
All checks were successful
Deploy mindnet to llm-node / deploy (push) Successful in 3s
This commit is contained in:
parent
6b4b3ce2ba
commit
6e0e965883
70
tests/inspect_one_note.py
Normal file
70
tests/inspect_one_note.py
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
tests/inspect_one_note.py
|
||||||
|
Diagnose einer einzelnen Markdown-Datei (kein Upsert).
|
||||||
|
Usage:
|
||||||
|
python3 tests/inspect_one_note.py --path ./test_vault/30_projects/project-demo.md
|
||||||
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
import os, sys, json, argparse
|
||||||
|
|
||||||
|
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
||||||
|
if PROJECT_ROOT not in sys.path:
|
||||||
|
sys.path.insert(0, PROJECT_ROOT)
|
||||||
|
|
||||||
|
from app.core.parser import read_markdown, normalize_frontmatter, validate_required_frontmatter
|
||||||
|
from app.core.chunker import assemble_chunks
|
||||||
|
from app.core.chunk_payload import make_chunk_payloads
|
||||||
|
try:
|
||||||
|
from app.core.derive_edges import build_edges_for_note
|
||||||
|
except Exception:
|
||||||
|
from app.core.edges import build_edges_for_note # type: ignore
|
||||||
|
|
||||||
|
def main():
|
||||||
|
ap = argparse.ArgumentParser()
|
||||||
|
ap.add_argument("--path", required=True)
|
||||||
|
args = ap.parse_args()
|
||||||
|
p = os.path.abspath(args.path)
|
||||||
|
|
||||||
|
try:
|
||||||
|
parsed = read_markdown(p)
|
||||||
|
if parsed is None:
|
||||||
|
print(json.dumps({"path": p, "error": "read_markdown returned None"}))
|
||||||
|
return
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"path": p, "error": f"read_markdown failed: {type(e).__name__}: {e}"}))
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
fm = normalize_frontmatter(parsed.frontmatter)
|
||||||
|
validate_required_frontmatter(fm)
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"path": p, "error": f"frontmatter invalid: {type(e).__name__}: {e}"}))
|
||||||
|
return
|
||||||
|
|
||||||
|
body = getattr(parsed, "body", "") or ""
|
||||||
|
chunks = assemble_chunks(fm["id"], body, fm.get("type", "concept"))
|
||||||
|
rel_for_payload = os.path.relpath(p, os.path.join(p, "..", ".."))
|
||||||
|
chunk_pls = make_chunk_payloads(fm, rel_for_payload, chunks, note_text=body)
|
||||||
|
|
||||||
|
edge_error = None
|
||||||
|
edges_count = 0
|
||||||
|
try:
|
||||||
|
edges = build_edges_for_note(fm["id"], chunk_pls, include_note_scope_refs=True)
|
||||||
|
edges_count = len(edges)
|
||||||
|
except Exception as e:
|
||||||
|
edge_error = f"{type(e).__name__}: {e}"
|
||||||
|
|
||||||
|
print(json.dumps({
|
||||||
|
"path": p,
|
||||||
|
"id": fm.get("id"),
|
||||||
|
"title": fm.get("title"),
|
||||||
|
"body_len": len(body),
|
||||||
|
"chunks": len(chunk_pls),
|
||||||
|
"edges": edges_count,
|
||||||
|
"edge_error": edge_error
|
||||||
|
}, ensure_ascii=False, indent=2))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in New Issue
Block a user