mirror of
https://github.com/safishamsi/graphify.git
synced 2026-07-12 10:27:11 +00:00
58 lines
2.0 KiB
Python
58 lines
2.0 KiB
Python
"""Integration tests for incremental graphify extract behavior."""
|
|
from __future__ import annotations
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
PYTHON = sys.executable
|
|
|
|
|
|
def _run(args: list[str], cwd: Path) -> subprocess.CompletedProcess:
|
|
return subprocess.run(
|
|
[PYTHON, "-m", "graphify"] + args,
|
|
cwd=cwd,
|
|
capture_output=True,
|
|
text=True,
|
|
)
|
|
|
|
|
|
def _make_docs_corpus(tmp_path: Path) -> Path:
|
|
docs = tmp_path / "docs"
|
|
docs.mkdir()
|
|
(docs / "intro.md").write_text("# Introduction\nThis doc introduces the system.")
|
|
(docs / "api.md").write_text("# API Reference\nThe API has endpoints.")
|
|
return docs
|
|
|
|
|
|
def test_manifest_written_after_extract(tmp_path):
|
|
"""After a full extract run, manifest.json must exist (or run fails before writing it)."""
|
|
docs = _make_docs_corpus(tmp_path)
|
|
r = _run(["extract", str(docs)], tmp_path)
|
|
# Should fail with no API key — but NOT with a path error
|
|
assert "no LLM API key" in r.stderr or r.returncode != 0
|
|
# manifest should NOT exist (run failed before writing)
|
|
manifest = docs / "graphify-out" / "manifest.json"
|
|
assert not manifest.exists()
|
|
|
|
|
|
def test_incremental_mode_detected_via_manifest(tmp_path):
|
|
"""If manifest.json + graph.json exist, incremental mode message is shown."""
|
|
docs = _make_docs_corpus(tmp_path)
|
|
out = docs / "graphify-out"
|
|
out.mkdir()
|
|
(out / "graph.json").write_text(json.dumps({"nodes": [], "links": []}))
|
|
(out / "manifest.json").write_text(json.dumps({"document": [str(docs / "intro.md")]}))
|
|
r = _run(["extract", str(docs)], tmp_path)
|
|
combined = r.stdout + r.stderr
|
|
assert "incremental" in combined.lower() or r.returncode != 0
|
|
|
|
|
|
def test_no_incremental_without_manifest(tmp_path):
|
|
"""Without manifest.json, full scan message is shown (not incremental)."""
|
|
docs = _make_docs_corpus(tmp_path)
|
|
r = _run(["extract", str(docs)], tmp_path)
|
|
assert "incremental" not in r.stdout
|