modified: .gitlab-ci.yml modified: bench/qa_questions.txt modified: bench/qa_sweep.py modified: bench/run.sh modified: docs/TICKETS.md modified: docs/_source/README.md modified: docs/_source/_ext/makefile_targets.py modified: docs/_source/api/cli.rst modified: docs/_source/api/distill.rst modified: docs/_source/api/mesh.rst modified: docs/_source/api/qa.rst modified: docs/_source/api/retrieval.rst modified: docs/_source/api/storage.rst modified: docs/_source/api/substrate.rst modified: docs/_source/concepts.rst modified: docs/_source/conf.py modified: docs/_source/cookbook.rst modified: docs/_source/index.rst modified: docs/_source/license.rst modified: docs/_source/quickstart.rst modified: docs/bench-maxing.md modified: docs/benchmarks.md modified: docs/cti-architecture.md modified: docs/diagrams/aborist-modules.dot modified: docs/diagrams/aborist-modules.svg modified: docs/diagrams/mesh-data-flow.dot modified: docs/diagrams/mesh-epoch-lifecycle.dot modified: docs/diagrams/mesh-epoch-lifecycle.svg modified: docs/diagrams/mesh-group-decisions.dot modified: docs/diagrams/mesh-group-decisions.svg modified: docs/diagrams/mesh-identity-stack.dot modified: docs/diagrams/mesh-secret-envelope.dot modified: docs/mesh.md modified: docs/qa-modes-bench.md modified: docs/seven-point-program.md modified: docs/tickets/ticket-000001-retrieval-keywords-audit-gap.md modified: docs/tickets/ticket-000002-reference-frame-polarity-contract.md modified: docs/tickets/ticket-000003-anchor-class-warrant.md modified: docs/tickets/ticket-000005-label-ladder-migration.md modified: docs/tickets/ticket-000006-bench-emergent-findings.md modified: docs/tickets/ticket-000007-query-layer-hyphen-fold.md modified: docs/tickets/ticket-000008-broad-quantifier-preflight-guard.md modified: docs/tickets/ticket-000009-quantifier-preflight-dag-binding.md modified: docs/tickets/ticket-000010-metacognition-preflight-guard.md modified: docs/tickets/ticket-000011-soft-preflight-hint-sidecar.md modified: scripts/backfill_concepts.py modified: scripts/bench_emergent.py modified: tests/crawler/test_async_web_fetcher.py modified: tests/crawler/test_bridge.py modified: tests/crawler/test_web_fetch.py modified: tests/test_bench_qa_sweep.py modified: tests/test_burn.py modified: tests/test_burn_doc.py modified: tests/test_claim_lattice.py modified: tests/test_cli_render.py modified: tests/test_compress.py modified: tests/test_concepts.py modified: tests/test_dag.py modified: tests/test_directives.py modified: tests/test_distill.py modified: tests/test_distill_recursive.py modified: tests/test_evict.py modified: tests/test_frame.py modified: tests/test_grok_source.py modified: tests/test_html_source.py modified: tests/test_ingest.py modified: tests/test_inspect.py modified: tests/test_journal.py modified: tests/test_keys.py modified: tests/test_llm_context_base.py modified: tests/test_merkle.py modified: tests/test_mesh.py modified: tests/test_mesh_aead.py modified: tests/test_mesh_chain.py modified: tests/test_mesh_cli.py modified: tests/test_mesh_cli_pull.py modified: tests/test_mesh_wire.py modified: tests/test_mesh_wire_e2e.py modified: tests/test_metacognition.py modified: tests/test_migration_audit_mode.py modified: tests/test_providence_source.py modified: tests/test_qa.py modified: tests/test_qa_quality_live.py modified: tests/test_quantifier_caps.py modified: tests/test_quantifier_classifier.py modified: tests/test_quantifier_phase4.py modified: tests/test_quantifier_reminder.py modified: tests/test_query.py modified: tests/test_reclassify.py modified: tests/test_repair.py modified: tests/test_resume.py modified: tests/test_snapshot.py modified: tests/test_soft_preflight.py modified: tests/test_tfidf.py modified: tests/test_vcs_source.py modified: tests/test_verify.py modified: tests/test_verify_json.py modified: tests/test_versioned_ingest.py modified: tests/test_warrant.py modified: tests/test_wikipedia_old.py modified: tests/test_wikipedia_xml.py modified: tests/test_wikitext.py
115 lines
3.8 KiB
Python
115 lines
3.8 KiB
Python
"""Versioned re-ingest: same URI, changed content -> 'supersedes' edge."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import time
|
|
from typing import Iterator
|
|
|
|
from arborist.document import Document
|
|
from arborist.ingest import ingest_source
|
|
from arborist.source import Source
|
|
from arborist.store import connect
|
|
|
|
|
|
class FakeSource(Source):
|
|
source_type = "test"
|
|
|
|
def __init__(self, docs: list[Document]):
|
|
self.docs = docs
|
|
|
|
def iter_documents(self) -> Iterator[Document]:
|
|
yield from self.docs
|
|
|
|
|
|
def _doc(uri: str, content: str) -> Document:
|
|
return Document(uri=uri, content=content, source_type="test", title=uri)
|
|
|
|
|
|
def test_unchanged_reingest_is_idempotent(tmp_path):
|
|
db = tmp_path / "idem.db"
|
|
conn = connect(db)
|
|
try:
|
|
d = _doc("test://stable", "same content same content same content " * 30)
|
|
ingest_source(conn, FakeSource([d]))
|
|
# Re-ingesting identical content = same root = idempotent skip.
|
|
ingest_source(conn, FakeSource([d]))
|
|
n = conn.execute(
|
|
"SELECT COUNT(*) FROM documents WHERE document_uri='test://stable'"
|
|
).fetchone()[0]
|
|
assert n == 1
|
|
# No supersedes edge — content unchanged.
|
|
n_super = conn.execute(
|
|
"SELECT COUNT(*) FROM edges WHERE edge_type='supersedes'"
|
|
).fetchone()[0]
|
|
assert n_super == 0
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
def test_changed_reingest_creates_supersedes_edge(tmp_path):
|
|
db = tmp_path / "v.db"
|
|
conn = connect(db)
|
|
try:
|
|
v1 = _doc("test://changing", "version one content " * 30)
|
|
ingest_source(conn, FakeSource([v1]))
|
|
time.sleep(1.05) # cross integer second so ingest_ts differs
|
|
|
|
v2 = _doc("test://changing", "version two content radically different " * 30)
|
|
ingest_source(conn, FakeSource([v2]))
|
|
|
|
# Two distinct documents share the URI.
|
|
rows = conn.execute(
|
|
"SELECT document_root FROM documents WHERE document_uri='test://changing' "
|
|
"ORDER BY ingest_ts ASC"
|
|
).fetchall()
|
|
assert len(rows) == 2
|
|
old_root = rows[0]["document_root"]
|
|
new_root = rows[1]["document_root"]
|
|
assert old_root != new_root
|
|
|
|
# Supersedes edge: new -> old.
|
|
edge = conn.execute(
|
|
"SELECT * FROM edges WHERE edge_type='supersedes'"
|
|
).fetchone()
|
|
assert edge is not None
|
|
assert edge["src_root"] == new_root
|
|
assert edge["dst_root"] == old_root
|
|
assert edge["dst_uri"] == "test://changing"
|
|
|
|
# Audit chain records the supersedes link in the new ingest's body.
|
|
from json import loads as _loads
|
|
ev = conn.execute(
|
|
"SELECT body FROM audit_events WHERE subject_root=?", (new_root,)
|
|
).fetchone()
|
|
assert _loads(ev["body"])["supersedes"] == old_root
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
def test_three_version_chain(tmp_path):
|
|
"""v1 -> v2 -> v3 produces two supersedes edges in a chain."""
|
|
db = tmp_path / "chain.db"
|
|
conn = connect(db)
|
|
try:
|
|
for i, content in enumerate(
|
|
["alpha alpha alpha " * 30, "beta beta beta " * 30, "gamma gamma gamma " * 30]
|
|
):
|
|
ingest_source(conn, FakeSource([_doc("test://multi", content)]))
|
|
time.sleep(1.05)
|
|
|
|
edges = conn.execute(
|
|
"SELECT src_root, dst_root FROM edges WHERE edge_type='supersedes'"
|
|
).fetchall()
|
|
assert len(edges) == 2
|
|
# Walk the chain: v3 -> v2, v2 -> v1.
|
|
roots = conn.execute(
|
|
"SELECT document_root FROM documents WHERE document_uri='test://multi' "
|
|
"ORDER BY ingest_ts ASC"
|
|
).fetchall()
|
|
v1, v2, v3 = (r["document_root"] for r in roots)
|
|
|
|
edge_pairs = {(e["src_root"], e["dst_root"]) for e in edges}
|
|
assert (v2, v1) in edge_pairs
|
|
assert (v3, v2) in edge_pairs
|
|
finally:
|
|
conn.close()
|