Pyramid web app for inspecting arborist Merkle trees over sharded SQLite: document roots, inclusion proofs, an interactive 3D Merkle lattice (six.js / WebGL with graceful fallback), audit-chain linkage, and a live SSE event stream. Generated artifacts (env/, vendored static/six/ bundles, demo databases) are gitignored and rebuilt via the Makefile (venv, six, init-db, serve).
77 lines
2.4 KiB
Python
77 lines
2.4 KiB
Python
"""Shared fixtures — seed a temp arborist shard so endpoints have real data."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import tempfile
|
|
|
|
import pytest
|
|
from pyramid.paster import get_app
|
|
from webtest import TestApp
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def demo_shard(tmp_path_factory):
|
|
"""Seed a small arborist shard once per test session."""
|
|
try:
|
|
from arborist.embed import open_store, ingest_documents, Document
|
|
except Exception:
|
|
pytest.skip("arborist library not installed; integration tests skipped")
|
|
|
|
db_path = str(tmp_path_factory.mktemp("shard") / "demo.db")
|
|
conn = open_store(db_path)
|
|
ingest_documents(
|
|
conn,
|
|
[
|
|
Document(
|
|
uri="https://test.local/doc1",
|
|
title="Doc 1",
|
|
source_type="test",
|
|
content="One. Two. Three. Four. Five. Six. Seven sentences make a tree with several leaves.",
|
|
),
|
|
Document(
|
|
uri="https://test.local/doc2",
|
|
title="Doc 2",
|
|
source_type="test",
|
|
content="Alpha. Beta. Gamma. Delta.",
|
|
),
|
|
],
|
|
source_type="test",
|
|
chunker_name="sent-v1",
|
|
)
|
|
conn.close()
|
|
return db_path
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def demo_facts(demo_shard):
|
|
"""Pull a known (root, leaf_hash, leaf_index, event_hash) tuple out of the shard."""
|
|
import sqlite3
|
|
c = sqlite3.connect(demo_shard)
|
|
root = c.execute("SELECT document_root FROM documents ORDER BY ingest_ts LIMIT 1").fetchone()[0]
|
|
leaf = c.execute("SELECT leaf_hash, idx FROM chunks WHERE document_root=? ORDER BY idx LIMIT 1", (root,)).fetchone()
|
|
event = c.execute("SELECT event_hash FROM audit_events WHERE subject_root=? ORDER BY seq LIMIT 1", (root,)).fetchone()
|
|
c.close()
|
|
return {
|
|
"root": root,
|
|
"leaf_hash": leaf[0],
|
|
"leaf_index": leaf[1],
|
|
"event_hash": event[0],
|
|
}
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def app(demo_shard):
|
|
"""WSGI app pointed at the demo shard via env var."""
|
|
os.environ["ARBORIST_VIZ_SHARDS"] = demo_shard
|
|
wsgi = get_app("development.ini")
|
|
return TestApp(wsgi)
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def app_no_shard():
|
|
"""WSGI app with NO shard — exercises the fallback path."""
|
|
os.environ.pop("ARBORIST_VIZ_SHARDS", None)
|
|
# Force a fresh app build by clearing any cached env.
|
|
wsgi = get_app("development.ini")
|
|
return TestApp(wsgi)
|