fix(bib): discover_docket prefers the Proposed Rule document over a later-closing final rule (refs #615 #680)
This commit is contained in:
@@ -898,15 +898,28 @@ def upsert_comment_status(
|
||||
def discover_docket(client: Client, docket_id: str, *, rule_cms_id: str = "") -> Docket:
|
||||
"""One ``/documents`` listing → the docket's commentable document.
|
||||
|
||||
Picks the document that has an ``objectId`` and a ``commentEndDate``
|
||||
(latest close date wins when several qualify). Called once per
|
||||
docket; the result is persisted so later runs make no API call.
|
||||
Picks the Proposed Rule that has an ``objectId`` and a
|
||||
``commentEndDate`` — latest close date wins among proposed rules;
|
||||
falls back to any commentable document. Called once per docket; the
|
||||
result is persisted so later runs make no API call.
|
||||
"""
|
||||
best: dict | None = None
|
||||
qualifying: list[dict] = []
|
||||
for fr_doc in client.find_documents_in_docket(docket_id):
|
||||
attrs = fr_doc.get("attributes") or {}
|
||||
if not attrs.get("objectId") or not attrs.get("commentEndDate"):
|
||||
continue
|
||||
qualifying.append(fr_doc)
|
||||
|
||||
proposed_rules = [
|
||||
fr_doc
|
||||
for fr_doc in qualifying
|
||||
if (fr_doc.get("attributes") or {}).get("documentType") == "Proposed Rule"
|
||||
]
|
||||
candidates = proposed_rules or qualifying
|
||||
|
||||
best: dict | None = None
|
||||
for fr_doc in candidates:
|
||||
attrs = fr_doc.get("attributes") or {}
|
||||
if (
|
||||
best is None
|
||||
or attrs["commentEndDate"]
|
||||
|
||||
@@ -66,6 +66,44 @@ def test_discover_docket_picks_commentable_doc():
|
||||
api.find_documents_in_docket.assert_called_once_with(D)
|
||||
|
||||
|
||||
def test_discover_docket_prefers_proposed_rule():
|
||||
api = MagicMock()
|
||||
api.find_documents_in_docket.return_value = [
|
||||
{
|
||||
"id": "CMS-2019-0111-41991",
|
||||
"attributes": {
|
||||
"objectId": "o-rule",
|
||||
"commentEndDate": "2020-01-03T03:59:59Z",
|
||||
"documentType": "Rule",
|
||||
},
|
||||
},
|
||||
{
|
||||
"id": "CMS-2019-0111-0092",
|
||||
"attributes": {
|
||||
"objectId": "o-nprm",
|
||||
"commentEndDate": "2019-09-28T03:59:59Z",
|
||||
"documentType": "Proposed Rule",
|
||||
},
|
||||
},
|
||||
{
|
||||
"id": "CMS-2019-0111-0001",
|
||||
"attributes": {
|
||||
"objectId": "o-display",
|
||||
"commentEndDate": "2019-08-14T03:59:59Z",
|
||||
"documentType": "Proposed Rule",
|
||||
},
|
||||
},
|
||||
]
|
||||
d = discover_docket(api, "CMS-2019-0111", rule_cms_id="CMS-1738-P")
|
||||
assert d == Docket(
|
||||
id="CMS-2019-0111",
|
||||
rule_cms_id="CMS-1738-P",
|
||||
fr_document_id="CMS-2019-0111-0092",
|
||||
fr_object_id="o-nprm",
|
||||
comment_end_date="2019-09-28",
|
||||
)
|
||||
|
||||
|
||||
def test_walk_creates_counts_and_advances_watermark():
|
||||
s = _store()
|
||||
s.docket_upsert(_docket())
|
||||
|
||||
Reference in New Issue
Block a user