- src/cli/comments.py exposes:
stack comments extract — walk + write combined.md (default
root .state/comments/, parallel via
walker, --docket/--limit/--workers
/--force/--bib/--no-bib).
stack comments extract-ocr — phase-2 stub (raises typer.Exit(2)
with a clear message).
stack comments stats — rebuild index, print per-status counts.
- Inline body lookup hits bib.sqlite items.abstract by comment_id;
--no-bib disables (useful in tests / when bib isn't seeded).
- Integration test exercises one real .state/comments/{docket}/{cid}/
dir if present (skipped on CI without state).
Closes the v1 implementation surface for #253. Live smoke run + #253
issue update happen as the operational follow-up.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
59 lines
1.9 KiB
Python
59 lines
1.9 KiB
Python
"""Smoke test against a real .state/comments/ dir if available.
|
|
|
|
Skipped on CI where state isn't present. Exercises the PyMuPDF code path
|
|
on real CMS comment PDFs (formatting, headers, multi-page) before
|
|
running the full backfill.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import shutil
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from rex.comments import extract_comment, parse_combined
|
|
|
|
_LIVE = Path(".state/comments")
|
|
|
|
|
|
def _pick_real_comment_dir() -> Path | None:
|
|
"""Find one .state/comments/{docket}/{cid}/ dir with at least one PDF."""
|
|
if not _LIVE.is_dir():
|
|
return None
|
|
for docket in sorted(_LIVE.iterdir()):
|
|
if not docket.is_dir() or not docket.name.startswith("CMS-"):
|
|
continue
|
|
for cdir in sorted(docket.iterdir()):
|
|
if not cdir.is_dir():
|
|
continue
|
|
if any(p.suffix.lower() == ".pdf" for p in cdir.iterdir()):
|
|
return cdir
|
|
return None
|
|
|
|
|
|
def test_real_comment_extracts(tmp_path: Path):
|
|
src = _pick_real_comment_dir()
|
|
if src is None:
|
|
pytest.skip(".state/comments/ not present")
|
|
|
|
# Copy to tmp so we don't write combined.md into the live tree.
|
|
dst_docket = tmp_path / src.parent.name
|
|
dst_docket.mkdir(parents=True)
|
|
dst = dst_docket / src.name
|
|
shutil.copytree(src, dst)
|
|
# Strip any pre-existing combined.md so we re-run extraction.
|
|
pre = dst / "combined.md"
|
|
if pre.exists():
|
|
pre.unlink()
|
|
|
|
out = extract_comment(dst, inline_body="(no inline body in this fixture)")
|
|
fm, body = parse_combined(out.read_text())
|
|
assert fm["comment_id"] == src.name
|
|
assert fm["docket_id"] == src.parent.name
|
|
assert fm["attachments"], "expected at least one attachment"
|
|
# At least one of the attachments should be ok or ocr_needed (not failed).
|
|
statuses = {a["status"] for a in fm["attachments"]}
|
|
assert statuses & {"ok", "ocr_needed"}, f"all failed: {statuses}"
|
|
assert "## Inline comment" in body
|