Some checks failed
CI / lint (push) Successful in 1m26s
CI / notebooks-smoke (push) Successful in 2m36s
CI / test (push) Has been cancelled
Deploy / changes (push) Has started running
Deploy / notebooks (push) Has been cancelled
Deploy / zotero (push) Has been cancelled
Deploy / docs (push) Has been cancelled
Deploy / api (push) Has been cancelled
Deploy / bcda (push) Has been cancelled
Deploy / llm (push) Has been cancelled
Deploy / mc (push) Has been cancelled
Deploy / report (push) Has been cancelled
Infra CI / mc (push) Has been cancelled
Infra CI / notebooks (push) Has been cancelled
Infra CI / zotero (push) Has been cancelled
Infra CI / docs (push) Has been cancelled
Infra CI / api (push) Has been cancelled
Infra CI / bcda (push) Has been cancelled
Infra CI / llm (push) Has been cancelled
Nothing ran 'stack comments extract' on a schedule, and extract skipped every sealed docket outright. 28 dockets (~29k comments with attachments, including every OPPS/IPPS docket) were sealed before anyone extracted them, so the tagger and the chat index only ever saw their 'see attached' stubs. Comment Pull now extracts between pull and index, and a seal skips only a fully extracted docket.
176 lines
5.1 KiB
Python
176 lines
5.1 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import fitz
|
|
import pytest
|
|
from typer.testing import CliRunner
|
|
|
|
from bib.dockets import Docket
|
|
from bib.store import Store
|
|
from cli.comments import app
|
|
|
|
runner = CliRunner()
|
|
|
|
|
|
@pytest.fixture
|
|
def store() -> Store:
|
|
s = Store(":memory:", storage_dir="/tmp/nope")
|
|
try:
|
|
yield s
|
|
finally:
|
|
s.close()
|
|
|
|
|
|
def _seed_dir(root: Path, docket: str) -> Path:
|
|
cdir = root / docket / f"{docket}-0001"
|
|
cdir.mkdir(parents=True)
|
|
doc = fitz.open()
|
|
doc.new_page().insert_text((50, 72), "Long body content " * 10)
|
|
doc.save(str(cdir / "attachment_1.pdf"))
|
|
doc.close()
|
|
return cdir
|
|
|
|
|
|
@patch("bib.connect")
|
|
def test_dockets_table_lists_rows(mc_connect, store):
|
|
s = store
|
|
s.docket_upsert(
|
|
Docket(
|
|
id="CMS-2019-0111",
|
|
rule_cms_id="CMS-1693-P",
|
|
comment_end_date="2019-09-27",
|
|
sealed_at="2020-01-01T00:00:00Z",
|
|
seal_reason="manual",
|
|
)
|
|
)
|
|
s.docket_upsert(
|
|
Docket(
|
|
id="CMS-2026-2377", rule_cms_id="CMS-1848-P", comment_end_date="2026-09-14"
|
|
)
|
|
)
|
|
mc_connect.return_value = s
|
|
result = runner.invoke(app, ["dockets"])
|
|
assert result.exit_code == 0, result.output
|
|
assert "CMS-2019-0111" in result.output and "sealed" in result.output
|
|
assert "CMS-2026-2377" in result.output and "open" in result.output
|
|
|
|
|
|
@patch("bib.connect")
|
|
def test_seal_and_unseal(mc_connect, store):
|
|
s = store
|
|
s.docket_upsert(Docket(id="CMS-2019-0111"))
|
|
mc_connect.return_value = s
|
|
assert (
|
|
runner.invoke(
|
|
app, ["seal", "CMS-2019-0111", "--reason", "historical"]
|
|
).exit_code
|
|
== 0
|
|
)
|
|
assert s.docket_get("CMS-2019-0111").seal_reason == "historical"
|
|
assert runner.invoke(app, ["unseal", "CMS-2019-0111"]).exit_code == 0
|
|
assert not s.docket_get("CMS-2019-0111").sealed
|
|
|
|
|
|
@patch("bib.connect")
|
|
def test_seal_unknown_docket_fails(mc_connect, store):
|
|
mc_connect.return_value = store
|
|
result = runner.invoke(app, ["seal", "CMS-0000-0000"])
|
|
assert result.exit_code == 1
|
|
assert "unknown docket" in result.output
|
|
|
|
|
|
@patch("bib.regulations_gov.discover_docket")
|
|
@patch("bib.regulations_gov.Client")
|
|
@patch("bib.connect")
|
|
def test_dockets_discover_populates_from_tags(mc_connect, mc_client, mc_disc, store):
|
|
from bib.item import Source
|
|
|
|
s = store
|
|
it = Source(title="c", url="https://www.regulations.gov/comment/CMS-2019-0111-1")
|
|
it.add_tag("reg-docket:CMS-2019-0111")
|
|
it.add_tag("rule:CMS-1693-P")
|
|
s.create(it)
|
|
mc_connect.return_value = s
|
|
api = MagicMock()
|
|
api.__enter__ = MagicMock(return_value=api)
|
|
api.__exit__ = MagicMock(return_value=False)
|
|
mc_client.return_value = api
|
|
mc_disc.return_value = Docket(
|
|
id="CMS-2019-0111",
|
|
rule_cms_id="CMS-1693-P",
|
|
fr_object_id="o",
|
|
comment_end_date="2019-09-27",
|
|
)
|
|
|
|
result = runner.invoke(app, ["dockets", "--discover"])
|
|
|
|
assert result.exit_code == 0, result.output
|
|
mc_disc.assert_called_once_with(api, "CMS-2019-0111", rule_cms_id="CMS-1693-P")
|
|
assert s.docket_get("CMS-2019-0111").comment_end_date == "2019-09-27"
|
|
|
|
|
|
@patch("bib.connect")
|
|
def test_extract_still_extracts_a_sealed_docket_with_unextracted_dirs(
|
|
mc_connect, tmp_path: Path, store
|
|
):
|
|
# 28 dockets were sealed before anyone ran extract, and the seal then
|
|
# kept them unextracted forever: a seal only skips finished work.
|
|
s = store
|
|
s.docket_upsert(
|
|
Docket(
|
|
id="CMS-2024-0001", sealed_at="2025-01-01T00:00:00Z", seal_reason="manual"
|
|
)
|
|
)
|
|
mc_connect.return_value = s
|
|
cdir = _seed_dir(tmp_path, "CMS-2024-0001")
|
|
result = runner.invoke(
|
|
app, ["extract", "--root", str(tmp_path), "--workers", "1", "--no-attach"]
|
|
)
|
|
assert result.exit_code == 0, result.output
|
|
assert (cdir / "combined.md").exists()
|
|
|
|
|
|
@patch("bib.connect")
|
|
def test_extract_skips_a_fully_extracted_sealed_docket(
|
|
mc_connect, tmp_path: Path, store
|
|
):
|
|
s = store
|
|
s.docket_upsert(
|
|
Docket(
|
|
id="CMS-2024-0001", sealed_at="2025-01-01T00:00:00Z", seal_reason="manual"
|
|
)
|
|
)
|
|
mc_connect.return_value = s
|
|
cdir = _seed_dir(tmp_path, "CMS-2024-0001")
|
|
(cdir / "combined.md").write_text("done")
|
|
result = runner.invoke(
|
|
app, ["extract", "--root", str(tmp_path), "--workers", "1", "--no-attach"]
|
|
)
|
|
assert result.exit_code == 0, result.output
|
|
assert "skipped_sealed: 1" in result.output
|
|
assert (cdir / "combined.md").read_text() == "done"
|
|
|
|
|
|
@patch("bib.connect")
|
|
def test_extract_force_runs_sealed_docket(mc_connect, tmp_path: Path, store):
|
|
s = store
|
|
s.docket_upsert(Docket(id="CMS-2024-0001", sealed_at="2025-01-01T00:00:00Z"))
|
|
mc_connect.return_value = s
|
|
cdir = _seed_dir(tmp_path, "CMS-2024-0001")
|
|
result = runner.invoke(
|
|
app,
|
|
[
|
|
"extract",
|
|
"--root",
|
|
str(tmp_path),
|
|
"--workers",
|
|
"1",
|
|
"--no-attach",
|
|
"--force",
|
|
],
|
|
)
|
|
assert result.exit_code == 0, result.output
|
|
assert (cdir / "combined.md").is_file()
|