feat(viewer): show document summary together with the original (TODO.md L5)
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
Uses the real compose Postgres (``db`` fixture) and FastAPI's TestClient:
|
||||
* 200 with the full field set for a seeded document (all formats);
|
||||
* ``summary`` surfaced for summarized docs, ``null`` for markdown (phase 36);
|
||||
* anonymous access stays 200 (phase 16 soft rule — public viewer);
|
||||
* 404 for an unknown (source, path) pair;
|
||||
* 404 for traversal-style ``path`` values (no filesystem access → no leak).
|
||||
"""
|
||||
@@ -21,6 +23,7 @@ def _seed_doc(
|
||||
title: str = "Kubernetes Homelab Cluster",
|
||||
content: str = "# Kubernetes\n\nTalos on 3 nodes.",
|
||||
chunks: int = 2,
|
||||
summary: str | None = None,
|
||||
) -> None:
|
||||
"""Truncate the KB and insert one document with ``chunks`` chunk rows."""
|
||||
db.execute(text("TRUNCATE chunks, documents"))
|
||||
@@ -33,6 +36,7 @@ def _seed_doc(
|
||||
content=content,
|
||||
content_hash="a" * 64,
|
||||
indexed_at=datetime.now(UTC),
|
||||
summary=summary,
|
||||
)
|
||||
db.add(doc)
|
||||
db.flush()
|
||||
@@ -53,11 +57,14 @@ def test_content_200_all_fields(client, db) -> None:
|
||||
)
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert set(body) == {"source", "path", "title", "format", "content", "indexed_at", "chunks"}
|
||||
assert set(body) == {
|
||||
"source", "path", "title", "format", "summary", "content", "indexed_at", "chunks"
|
||||
}
|
||||
assert body["source"] == "Homelab"
|
||||
assert body["path"] == "kubernetes.md"
|
||||
assert body["title"] == "Kubernetes Homelab Cluster"
|
||||
assert body["format"] == "md"
|
||||
assert body["summary"] is None # markdown doc → no summary (phase 36)
|
||||
assert body["content"] == "# Kubernetes\n\nTalos on 3 nodes."
|
||||
assert body["chunks"] == 2
|
||||
datetime.fromisoformat(body["indexed_at"]) # raises if not ISO-8601
|
||||
@@ -66,6 +73,62 @@ def test_content_200_all_fields(client, db) -> None:
|
||||
db.commit()
|
||||
|
||||
|
||||
def test_content_summary_surfaced_for_summarized_doc(client, db) -> None:
|
||||
"""A non-markdown document with a phase-30 summary returns it verbatim
|
||||
(phase 36 — the viewer's data contract gains the nullable field).
|
||||
|
||||
Anonymous by design: the ``client`` fixture carries no admin cookie,
|
||||
so the 200 here re-confirms the phase-16 soft rule (public viewer).
|
||||
"""
|
||||
summary = (
|
||||
"GitLab CE runs in a Podman compose stack on the homelab NAS with a "
|
||||
"persistent volume for data and a backup job."
|
||||
)
|
||||
_seed_doc(
|
||||
db,
|
||||
path="container_gitlab/gitlab-compose.yaml",
|
||||
title="gitlab-compose",
|
||||
content="services:\n gitlab:\n image: gitlab/gitlab-ce",
|
||||
summary=summary,
|
||||
)
|
||||
try:
|
||||
r = client.get(
|
||||
"/api/documents/content",
|
||||
params={"source": "Homelab", "path": "container_gitlab/gitlab-compose.yaml"},
|
||||
)
|
||||
assert r.status_code == 200 # anonymous (no cookie) — public viewer
|
||||
body = r.json()
|
||||
assert body["summary"] == summary # verbatim, no wrapping
|
||||
assert body["content"] == "services:\n gitlab:\n image: gitlab/gitlab-ce"
|
||||
finally:
|
||||
db.execute(text("TRUNCATE chunks, documents"))
|
||||
db.commit()
|
||||
|
||||
|
||||
def test_content_summary_null_for_markdown_doc(client, db) -> None:
|
||||
"""Markdown documents carry no summary (phase 30) → JSON ``null``, and
|
||||
anonymous access still returns 200 (phase 16 soft rule)."""
|
||||
_seed_doc(
|
||||
db,
|
||||
path="kubernetes.md",
|
||||
content="# Kubernetes\n\nTalos on 3 nodes.",
|
||||
summary=None,
|
||||
)
|
||||
try:
|
||||
r = client.get(
|
||||
"/api/documents/content",
|
||||
params={"source": "Homelab", "path": "kubernetes.md"},
|
||||
)
|
||||
assert r.status_code == 200 # anonymous (no cookie) — public viewer
|
||||
body = r.json()
|
||||
assert "summary" in body
|
||||
assert body["summary"] is None
|
||||
assert body["content"] == "# Kubernetes\n\nTalos on 3 nodes."
|
||||
finally:
|
||||
db.execute(text("TRUNCATE chunks, documents"))
|
||||
db.commit()
|
||||
|
||||
|
||||
def test_content_404_unknown_path(client, db) -> None:
|
||||
_seed_doc(db)
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user