diff --git a/src/adcp/reporting/feed/projection.py b/src/adcp/reporting/feed/projection.py index 4e56ef30e..ad35280bf 100644 --- a/src/adcp/reporting/feed/projection.py +++ b/src/adcp/reporting/feed/projection.py @@ -573,6 +573,8 @@ def shown_prefix(boundaries: tuple[Any, ...]) -> tuple[Any, ...]: ledger_as_of=core.as_of, request=filters, obligations=tuple(p.obligation for p in scope_result.obligations), + owed_through=dict(core.owed_through), + scope_closed=scope_result.scope_closed, ), "health": scope_result.health, "issues": _issues_to_wire(scope_result.issues), diff --git a/src/adcp/reporting/ledger/status.py b/src/adcp/reporting/ledger/status.py index 5ac6b88a2..8588714cf 100644 --- a/src/adcp/reporting/ledger/status.py +++ b/src/adcp/reporting/ledger/status.py @@ -438,6 +438,7 @@ def render_snapshot( _parse(filters["period_end"]), reconciliation=reconciliation, consumer_status_enabled=self._consumer_status_enabled, + period_close_grace=self._period_close_grace, ) # A read renders this snapshot and schedules nothing, so no projection # here searches for the next deadline (next_due_at). @@ -514,6 +515,7 @@ def render_snapshot( request=request, obligations=tuple(p.obligation for p in result.obligations), owed_through=dict(getattr(snapshot, "owed_through", ()) or ()), + scope_closed=result.scope_closed, ) obligations = tuple(p.obligation for p in result.obligations) if view == "summary": @@ -802,6 +804,7 @@ def _scope_to_wire( request: dict[str, Any], obligations: Sequence[ReportingObligationRecord] = (), owed_through: Mapping[ReportingConfigurationGenerationKey, datetime] | None = None, + scope_closed: bool | None = None, ) -> dict[str, Any]: """The denominator this read's health was computed over. @@ -838,12 +841,17 @@ def _scope_to_wire( # No further obligation can enter a horizon that has already elapsed, # and a subscription's owed set must also be frozen through it: until # then a period may still be added, which is not missing history. - "scope_closed": horizon_end <= _utc(ledger_as_of) - and all(o.period.end <= ledger_as_of for o in obligations) - and all( - owed.get(item.generation_key) is not None and owed[item.generation_key] >= horizon_end - for item in configurations - if item.owed_set + "scope_closed": ( + scope_closed + if scope_closed is not None + else horizon_end <= _utc(ledger_as_of) + and all(o.period.end <= ledger_as_of for o in obligations) + and all( + owed.get(item.generation_key) is not None + and owed[item.generation_key] >= horizon_end + for item in configurations + if item.owed_set + ) ), # True when the caller named no media buys, so the scope is every buy # it can reach rather than an enumerated subset. diff --git a/src/adcp/reporting/ledger/status_projection.py b/src/adcp/reporting/ledger/status_projection.py index 4e4717324..161a7f8b6 100644 --- a/src/adcp/reporting/ledger/status_projection.py +++ b/src/adcp/reporting/ledger/status_projection.py @@ -54,6 +54,8 @@ ReportingStatusScope, validate_scope_refinement, ) +from adcp.reporting.ledger.period_close import DEFAULT_PERIOD_CLOSE_GRACE +from adcp.reporting.ledger.schedule import committed_periods from adcp.reporting.revision_selection import select_reporting_revision if TYPE_CHECKING: @@ -224,6 +226,7 @@ class StatusProjectionInput: # pass the complete captured account history, even when it is empty. reconciliation: tuple[ReportingDeliveryRecord, ...] | None = None consumer_status_enabled: bool = True + period_close_grace: timedelta = DEFAULT_PERIOD_CLOSE_GRACE @dataclass(frozen=True) @@ -245,6 +248,7 @@ class StatusProjectionResult: pending_count: int next_due_at: datetime | None intents: tuple[StatusLifecycleIntent, ...] + scope_closed: bool fingerprint: str @property @@ -623,7 +627,9 @@ def configuration_selected( (not delivery_config_ids or configuration.delivery_config_id in delivery_config_ids) and (not feed_purposes or configuration.feed_purpose in feed_purposes) and ( - not media_buy_ids or bool(set(configuration.media_buy_ids).intersection(media_buy_ids)) + not media_buy_ids + or configuration.media_buy_scope == "all_media_buys" + or bool(set(configuration.media_buy_ids).intersection(media_buy_ids)) ) ) @@ -640,6 +646,80 @@ def period_selected( ) +def _missing_obligation_issues( + value: StatusProjectionInput, + configurations: Sequence[ReportingConfiguration], +) -> tuple[tuple[ReportingIssue, ...], set[datetime]]: + """Project the first period a generation failed to close after its grace.""" + if value.scope.reporting_obligation_id is not None: + return (), set() + snapshot = value.snapshot + closed: dict[ReportingConfigurationGenerationKey, set[tuple[datetime, datetime]]] = {} + for obligation in snapshot.obligations: + closed.setdefault(obligation.generation_key, set()).add( + (obligation.period.start, obligation.period.end) + ) + issues: list[ReportingIssue] = [] + deadlines: set[datetime] = set() + for configuration in configurations: + if ( + configuration.owed_set + or configuration.quarantined + or configuration.activated_at is None + ): + continue + retained_from = max( + snapshot.as_of - timedelta(days=configuration.status_retention_days), + configuration.activated_at, + ) + scan_from = max( + retained_from, + value.period_start or retained_from, + ) + for period in committed_periods(configuration, near_start=scan_from): + if value.period_end is not None and period.start >= value.period_end: + break + if period.end <= retained_from or not period_selected( + period.start, period.end, value.period_start, value.period_end + ): + continue + if (period.start, period.end) in closed.get(configuration.generation_key, set()): + continue + visible_at = period.end + value.period_close_grace + deadlines.add(visible_at) + if snapshot.as_of < visible_at: + break + recovery_deadline = period.expected_at + configuration.automated_recovery_window + action_required = snapshot.as_of >= recovery_deadline + deadlines.add(recovery_deadline) + issues.append( + ReportingIssue( + issue_id=issue_id_for( + "missing-reporting-obligation-v1", + configuration.account_id, + configuration.consumer_id, + configuration.delivery_config_id, + configuration.delivery_config_version, + configuration.generation_key.offering_id, + period.start, + period.end, + ), + code="PRODUCTION_FAILED", + severity="action_required" if action_required else "delayed", + responsible_party="seller", + recommended_action=("contact_seller" if action_required else "wait_for_retry"), + delivery_config_id=configuration.delivery_config_id, + delivery_config_version=configuration.delivery_config_version, + feed_purpose=configuration.feed_purpose, + period_start=period.start, + period_end=period.end, + expected_at=period.expected_at, + ) + ) + break + return tuple(issues), deadlines + + def _project(value: StatusProjectionInput) -> tuple[StatusProjectionResult, set[datetime]]: snapshot, scope = value.snapshot, value.scope if snapshot.account_id != scope.account_id: @@ -693,6 +773,11 @@ def _project(value: StatusProjectionInput) -> tuple[StatusProjectionResult, set[ projected: list[StatusObligationProjection] = [] candidates: set[datetime] = set() pending = 0 + missing_obligation_issues, missing_obligation_deadlines = _missing_obligation_issues( + value, configurations + ) + issues.extend(missing_obligation_issues) + candidates.update(missing_obligation_deadlines) if (scope.reporting_obligation_id is not None and not obligations) or ( scope.generation_key is not None and not configurations and not obligations ): @@ -974,13 +1059,25 @@ def _project(value: StatusProjectionInput) -> tuple[StatusProjectionResult, set[ ) ) full_issues = _sorted_issues(issues) + horizon_end = value.period_end or snapshot.as_of + owed_through = dict(snapshot.owed_through) + scope_closed = ( + not missing_obligation_issues + and horizon_end <= snapshot.as_of + and all(snapshot.as_of >= o.period.end for o in obligations) + and all( + owed_through.get(c.generation_key) is not None + and owed_through[c.generation_key] >= horizon_end + for c in configurations + if c.owed_set + ) + ) if scope.reporting_obligation_id is not None and projected: health = projected[0].projection.health else: health = aggregate_reporting_health( (p.projection.health for p in projected), - scope_closed=(value.period_end is None or value.period_end <= snapshot.as_of) - and all(snapshot.as_of >= o.period.end for o in obligations), + scope_closed=scope_closed, coverage_complete=all(o.coverage_status == "full" for o in obligations), ) if any(i.severity == "action_required" for i in full_issues): @@ -1024,6 +1121,7 @@ def _project(value: StatusProjectionInput) -> tuple[StatusProjectionResult, set[ pending, None, intents, + scope_closed, fingerprint, ), candidates, diff --git a/tests/conformance/reporting/test_pg_reporting_ledger.py b/tests/conformance/reporting/test_pg_reporting_ledger.py index a76152a77..fe86895ea 100644 --- a/tests/conformance/reporting/test_pg_reporting_ledger.py +++ b/tests/conformance/reporting/test_pg_reporting_ledger.py @@ -785,8 +785,12 @@ async def test_the_status_handler_projects_a_postgres_ledger( revision, rows = _revision(obligation) await store.commit_revision(revision, rows) handler = ReportingStatusHandler(store) + period = { + "start": obligation.period.start.isoformat(), + "end": obligation.period.end.isoformat(), + } - summary = await handler.handle({"view": "summary"}, caller=CALLER) + summary = await handler.handle({"view": "summary", "period": period}, caller=CALLER) assert summary["obligation_counts"] == { "total": 1, "waiting": 0, @@ -797,7 +801,7 @@ async def test_the_status_handler_projects_a_postgres_ledger( } assert summary["health"] == "complete" - periods = await handler.handle({"view": "periods"}, caller=CALLER) + periods = await handler.handle({"view": "periods", "period": period}, caller=CALLER) assert periods["periods"][0]["reporting_obligation_id"] == obligation.reporting_obligation_id assert periods["revisions"][0]["revision_content_sha256"] == revision.revision_content_sha256 diff --git a/tests/conformance/reporting/test_reporting_core_lifecycle.py b/tests/conformance/reporting/test_reporting_core_lifecycle.py index 773a5d8ce..d6413e52d 100644 --- a/tests/conformance/reporting/test_reporting_core_lifecycle.py +++ b/tests/conformance/reporting/test_reporting_core_lifecycle.py @@ -314,7 +314,14 @@ async def _reconcile( return await reconcile_reporting_core( client, GetReportingStatusRequest.model_validate( - {"account": {"account_id": ACCOUNT}, "view": "periods"} + { + "account": {"account_id": ACCOUNT}, + "view": "periods", + "period": { + "start": expected[0].period_start, + "end": expected[-1].period_end, + }, + } ), expected_periods=expected, ) @@ -663,11 +670,14 @@ async def test_missing_period_claim_requires_complete_finality_denominator( # and internally consistent -- exactly the shape that hides an omission. await _run_worker_at(ledger, source, now=first.end + timedelta(minutes=30)) if all_finalities: - # Expand the real seller's configuration denominator, without rewriting - # its response or introducing an obligation for this other generation. + # Expand the real seller's configuration denominator with a satisfied + # official generation for the same period. await ledger.put_configuration( replace(_configuration("official"), delivery_config_id="official_delivery") ) + turn = await _run_worker_at(ledger, source, now=first.end + timedelta(minutes=30)) + assert len(turn.obligations_committed) == 1 + assert len(turn.revisions_committed) == 1 # The seller obligated one period; the buyer expects two. settled = await _reconcile(ledger, expected=_expected_periods(1)) diff --git a/tests/conformance/reporting/test_reporting_feed_contract.py b/tests/conformance/reporting/test_reporting_feed_contract.py index b2066e212..74ae58b85 100644 --- a/tests/conformance/reporting/test_reporting_feed_contract.py +++ b/tests/conformance/reporting/test_reporting_feed_contract.py @@ -10,6 +10,7 @@ from adcp.reporting.ledger.status import ReportingStatusCaller, ReportingStatusHandler from adcp.types import GetReportingStatusResponse +from ._durable_materializer_support import durable_case from ._feed_support import ( ARRAYS, feed_harness, @@ -28,6 +29,15 @@ __all__ = ["feeds"] +async def test_frozen_feed_keeps_a_missing_period_scope_open() -> None: + async with feed_harness("memory") as h: + case = await durable_case(h.store) + page = await h.store.read_reporting_feed(feed_request(case), caller=case.binding.principal) + assert page["health"] == "delayed" + assert [issue["code"] for issue in page["issues"]] == ["PRODUCTION_FAILED"] + assert page["scope"]["scope_closed"] is False + + async def test_frozen_feed_caps_and_prioritizes_status_issues() -> None: async with feed_harness("memory") as h: case = await receipt_case(h) diff --git a/tests/conformance/reporting/test_reporting_production.py b/tests/conformance/reporting/test_reporting_production.py index b6310abcc..641ab3ccb 100644 --- a/tests/conformance/reporting/test_reporting_production.py +++ b/tests/conformance/reporting/test_reporting_production.py @@ -40,7 +40,14 @@ async def test_actual_source_publication_builds_canonical_evidence(backend, coun assert item.writer.writes == 1 await drain(h.projection, item.config.account_id) page = await support.handler.get_reporting_status( - {"account": {"account_id": item.config.account_id}, "view": "summary"}, + { + "account": {"account_id": item.config.account_id}, + "view": "summary", + "period": { + "start": item.obligation.period.start.isoformat(), + "end": item.obligation.period.end.isoformat(), + }, + }, ToolContext(caller_identity=item.binding.consumer_id), ) assert page["health"] == "complete" @@ -95,7 +102,15 @@ async def test_actual_admission_verified_finish_and_private_polling( await drain(h.projection, item.config.account_id) context = ToolContext(caller_identity=item.binding.consumer_id) response = await support.handler.get_reporting_status( - {"account": {"account_id": item.config.account_id}, "view": "summary"}, context + { + "account": {"account_id": item.config.account_id}, + "view": "summary", + "period": { + "start": item.obligation.period.start.isoformat(), + "end": item.obligation.period.end.isoformat(), + }, + }, + context, ) assert response["health"] == "complete" rows = [] diff --git a/tests/conformance/reporting/test_reporting_production_lifecycle.py b/tests/conformance/reporting/test_reporting_production_lifecycle.py index 73d3e06ef..9219ff358 100644 --- a/tests/conformance/reporting/test_reporting_production_lifecycle.py +++ b/tests/conformance/reporting/test_reporting_production_lifecycle.py @@ -198,7 +198,14 @@ async def summary(): _, value = await mounted.call( client, "get_reporting_status", - {"account": request["account"], "view": "summary"}, + { + "account": request["account"], + "view": "summary", + "period": { + "start": item.obligation.period.start.isoformat(), + "end": item.obligation.period.end.isoformat(), + }, + }, ) assert value.get("status") == "completed", value return value @@ -262,7 +269,14 @@ async def summary(): _, complete = await mounted.call( client, "get_reporting_status", - {"account": request["account"], "view": "summary"}, + { + "account": request["account"], + "view": "summary", + "period": { + "start": item.obligation.period.start.isoformat(), + "end": item.obligation.period.end.isoformat(), + }, + }, transport=transport, ) assert complete["health"] == "complete" diff --git a/tests/conformance/reporting/test_reporting_status_period_close.py b/tests/conformance/reporting/test_reporting_status_period_close.py index 33389fe60..ce192b003 100644 --- a/tests/conformance/reporting/test_reporting_status_period_close.py +++ b/tests/conformance/reporting/test_reporting_status_period_close.py @@ -28,7 +28,13 @@ ReportingStatusHandler, revision_content_sha256, ) +from adcp.reporting.ledger.notification_models import ReportingStatusScope +from adcp.reporting.ledger.status_projection import ( + StatusProjectionInput, + project_status_scope, +) from adcp.reporting.ledger.store import LedgerConflictError +from tests.test_reporting_ledger import _obligation from ._generation_support import isolated_reporting_pool @@ -240,22 +246,112 @@ async def test_a_revision_published_after_the_held_boundary_is_unavailable_not_u @pytest.mark.parametrize("backend", ["memory", "postgres"]) -async def test_a_close_still_open_after_the_grace_no_longer_holds_the_boundary( +async def test_a_close_stuck_after_the_grace_is_visible_and_escalates( backend: str, ) -> None: - clock = _Clock(_at(2, 1)) + clock = _Clock(_at(1)) async with _ledger(backend, clock) as store: producer, (config,) = await _install(store, "feed_a") - await producer.close_elapsed_periods(config, now=_at(2, 1)) # A close that has not happened minutes after its boundary is stuck, # not in progress: holding every read there would freeze the caller's # whole ledger and hide lateness everywhere else. - clock.now = _at(3, 6) + clock.now = _at(2, 6) summary = await ReportingStatusHandler(store).handle({"view": "summary"}, caller=CALLER) - assert summary["ledger_as_of"] == _iso(_at(3, 6)) - + assert summary["ledger_as_of"] == _iso(_at(2, 6)) + assert summary["health"] == "delayed" + assert summary["scope"]["scope_closed"] is False + assert summary["obligation_counts"]["total"] == 0 + (issue,) = summary["issues"] + assert issue == { + "issue_id": issue["issue_id"], + "code": "PRODUCTION_FAILED", + "severity": "delayed", + "responsible_party": "seller", + "recommended_action": "wait_for_retry", + "delivery_config_id": "feed_a", + "delivery_config_version": 1, + "feed_purpose": "analytics", + "period_start": _at(1).isoformat(), + "period_end": _at(2).isoformat(), + "expected_at": _at(3).isoformat(), + } + + clock.now = _at(9) + escalated = await ReportingStatusHandler(store).handle({"view": "summary"}, caller=CALLER) + assert escalated["health"] == "action_required" + assert escalated["scope"]["scope_closed"] is False + (escalated_issue,) = escalated["issues"] + assert escalated_issue["issue_id"] == issue["issue_id"] + assert escalated_issue["severity"] == "action_required" + assert escalated_issue["recommended_action"] == "contact_seller" + + clock.now = _at(2, 6) held = await ReportingStatusHandler(store, period_close_grace=timedelta(minutes=10)).handle( {"view": "summary"}, caller=CALLER ) - assert held["ledger_as_of"] == _iso(_at(3)) + assert held["ledger_as_of"] == _iso(_at(2)) + + clock.now = _at(2, 7) + await producer.close_elapsed_periods(config, now=clock.now) + recovered = await ReportingStatusHandler(store).handle({"view": "summary"}, caller=CALLER) + assert recovered["health"] == "waiting" + assert recovered["issues"] == [] + assert recovered["scope"]["scope_closed"] is True + + +@pytest.mark.parametrize("backend", ["memory", "postgres"]) +async def test_a_later_period_filter_still_exposes_its_missing_obligation(backend: str) -> None: + clock = _Clock(_at(4, 6)) + async with _ledger(backend, clock) as store: + await _install(store, "feed_a") + summary = await ReportingStatusHandler(store).handle( + { + "view": "summary", + "period": {"start": _iso(_at(3)), "end": _iso(_at(4))}, + }, + caller=CALLER, + ) + assert summary["health"] == "delayed" + assert summary["scope"]["scope_closed"] is False + (issue,) = summary["issues"] + assert issue["code"] == "PRODUCTION_FAILED" + assert (issue["period_start"], issue["period_end"]) == ( + _at(3).isoformat(), + _at(4).isoformat(), + ) + + +@pytest.mark.parametrize("backend", ["memory", "postgres"]) +async def test_a_later_committed_obligation_does_not_hide_an_earlier_gap(backend: str) -> None: + clock = _Clock(_at(3, 6)) + async with _ledger(backend, clock) as store: + _, (configuration,) = await _install(store, "feed_a") + await store.commit_obligation(_obligation(configuration, ordinal=2)) + + summary = await ReportingStatusHandler(store).handle({"view": "summary"}, caller=CALLER) + assert summary["health"] == "delayed" + (issue,) = summary["issues"] + assert issue["code"] == "PRODUCTION_FAILED" + assert (issue["period_start"], issue["period_end"]) == ( + _at(1).isoformat(), + _at(2).isoformat(), + ) + + +@pytest.mark.parametrize("backend", ["memory", "postgres"]) +async def test_status_projection_schedules_missing_period_visibility_before_close( + backend: str, +) -> None: + clock = _Clock(_at(1, 30)) + async with _ledger(backend, clock) as store: + await _install(store, "feed_a") + snapshot = await store.read_status_snapshot(caller=CALLER) + result = project_status_scope( + StatusProjectionInput( + snapshot, + ReportingStatusScope(ACCOUNT, consumer_id="buyer"), + ) + ) + assert result.issues == () + assert result.next_due_at == _at(2, 5) diff --git a/tests/conformance/reporting/test_reporting_status_projection_contract.py b/tests/conformance/reporting/test_reporting_status_projection_contract.py index 913f1caed..76d1accb2 100644 --- a/tests/conformance/reporting/test_reporting_status_projection_contract.py +++ b/tests/conformance/reporting/test_reporting_status_projection_contract.py @@ -11,6 +11,7 @@ from adcp.reporting.ledger import InMemoryReportingLedgerStore, ReportingSubscriptionGeneration from adcp.reporting.ledger import ReportingStatusCaller as OwnershipCaller +from adcp.reporting.ledger.period_close import DEFAULT_PERIOD_CLOSE_GRACE from adcp.reporting.ledger.status import ReportingStatusCaller, ReportingStatusHandler from adcp.reporting.ledger.status_projection import StatusProjectionInput, project_status_scope from adcp.reporting.outbox import ( @@ -21,7 +22,7 @@ validate_notification_payload, ) -from ._generation_support import configuration, obligation_for, revision_for +from ._generation_support import END, START, configuration, obligation_for, revision_for from ._reliable_support import reliable_factory from .test_reporting_notification_outbox import statement @@ -194,6 +195,25 @@ async def test_new_scope_initial_fire_is_distinct_from_migration_baseline(status assert payload["issue_ids"] +async def test_sweeper_publishes_a_missing_period_at_the_close_grace(status_harness): + h = status_harness + config = replace(configuration(), deactivated_at=None) + h.clock.now = START + timedelta(minutes=30) + await h.ledger.put_configuration(config) + await h.status.baseline(account_id="acct_a") + visible_at = END + DEFAULT_PERIOD_CLOSE_GRACE + assert any( + checkpoint.next_due_at == visible_at + for checkpoint in await h.status.checkpoints(account_id="acct_a") + ) + + h.clock.now = visible_at + turn = await ReportingStatusSweeper(h.status).run_once(account_id="acct_a") + assert turn.did_work + events = await h.events(obligation=False) + assert any(event.cause.health == "delayed" and event.cause.issue_ids for event in events) + + async def test_pure_handler_event_parity_and_feed_purpose_filter(status_harness): h = status_harness obligation, revision, _ = await h.seed(readable=True) diff --git a/tests/conformance/reporting/test_reporting_status_wire_contract.py b/tests/conformance/reporting/test_reporting_status_wire_contract.py index 39063d9d9..342f0f7bd 100644 --- a/tests/conformance/reporting/test_reporting_status_wire_contract.py +++ b/tests/conformance/reporting/test_reporting_status_wire_contract.py @@ -260,7 +260,8 @@ async def test_mixed_generation_retention_uses_the_latest_common_boundary(status "+00:00", "Z" ) assert response["health"] == "action_required" - assert len(response["issues"]) == 2 + assert [issue["code"] for issue in response["issues"]].count("HISTORY_UNAVAILABLE") == 2 + assert [issue["code"] for issue in response["issues"]].count("PRODUCTION_FAILED") == 2 @pytest.mark.parametrize( diff --git a/tests/test_reporting_all_media_buys_scope.py b/tests/test_reporting_all_media_buys_scope.py index cf11af45f..6a231df97 100644 --- a/tests/test_reporting_all_media_buys_scope.py +++ b/tests/test_reporting_all_media_buys_scope.py @@ -312,7 +312,8 @@ def _first_period() -> ReportingPeriodBoundary: async def test_unresolved_scope_escalates_once_past_its_recovery_deadline() -> None: - store = InMemoryReportingLedgerStore() + now = [_at(8, 59)] + store = InMemoryReportingLedgerStore(clock=lambda: now[0]) configuration = _all_scope() await store.put_configuration(configuration) scope = _Scope(MissingHistoricalMediaBuyScope("buy edited after cutoff")) @@ -322,10 +323,40 @@ async def test_unresolved_scope_escalates_once_past_its_recovery_deadline() -> N assert period.expected_at + configuration.automated_recovery_window == _at(9) before = await producer.run_configuration(configuration, now=_at(8, 59)) assert before.escalated == [] and before.obligations_committed == [] + delayed = await ReportingStatusHandler(store).handle({"view": "summary"}, caller=CALLER) + assert delayed["health"] == "delayed" + assert delayed["scope"]["scope_closed"] is False + assert delayed["obligation_counts"]["total"] == 0 + assert [ + (issue["code"], issue["severity"], issue["recommended_action"]) + for issue in delayed["issues"] + ] == [("PRODUCTION_FAILED", "delayed", "wait_for_retry")] + filtered = await ReportingStatusHandler(store).handle( + {"view": "summary", "media_buy_ids": ["mb_a"]}, caller=CALLER + ) + assert filtered["health"] == "delayed" + assert filtered["scope"]["scope_closed"] is False + assert [issue["code"] for issue in filtered["issues"]] == ["PRODUCTION_FAILED"] + + now[0] = _at(9) after = await producer.run_configuration(configuration, now=_at(9)) assert after.escalated == [ReportingProducer._obligation_id(configuration, period)] assert after.obligations_committed == [] assert await store.list_generation_obligations(configuration.generation_key) == () + assert ( + await store.list_revisions( + account_id=configuration.account_id, + reporting_obligation_id=ReportingProducer._obligation_id(configuration, period), + ) + == () + ) + action_required = await ReportingStatusHandler(store).handle({"view": "summary"}, caller=CALLER) + assert action_required["health"] == "action_required" + assert action_required["scope"]["scope_closed"] is False + assert [ + (issue["code"], issue["severity"], issue["recommended_action"]) + for issue in action_required["issues"] + ] == [("PRODUCTION_FAILED", "action_required", "contact_seller")] async def test_zero_buy_period_publishes_a_zero_row_snapshot_without_the_source() -> None: @@ -352,6 +383,12 @@ async def test_zero_buy_period_publishes_a_zero_row_snapshot_without_the_source( assert period["coverage"]["status"] == "full" assert period["coverage"]["media_buy_ids"] == [] assert period["coverage"]["evaluated_at"] == "2026-09-01T02:00:00Z" + filtered = await ReportingStatusHandler(store).handle( + {"view": "summary", "media_buy_ids": ["mb_a"]}, caller=CALLER + ) + assert filtered["health"] == "complete" + assert filtered["issues"] == [] + assert filtered["scope"]["scope_closed"] is True async def test_an_explicit_empty_snapshot_scope_also_closes_with_zero_rows() -> None: diff --git a/tests/test_reporting_ledger.py b/tests/test_reporting_ledger.py index a25dde4c6..919ae2818 100644 --- a/tests/test_reporting_ledger.py +++ b/tests/test_reporting_ledger.py @@ -1076,7 +1076,7 @@ async def _seeded( """ boundary = ledger_as_of or datetime(2026, 9, 30, tzinfo=timezone.utc) store = InMemoryReportingLedgerStore(clock=lambda: boundary) - configuration = _configuration(consumer_id=consumer_id) + configuration = _configuration(consumer_id=consumer_id, deactivated_at=_utc_at(2026, 9, 1, 2)) await store.put_configuration(configuration) obligation = await store.commit_obligation(_obligation(configuration)) return store, obligation diff --git a/tests/test_reporting_status_page_cost.py b/tests/test_reporting_status_page_cost.py index 42a45d562..acb110512 100644 --- a/tests/test_reporting_status_page_cost.py +++ b/tests/test_reporting_status_page_cost.py @@ -268,14 +268,14 @@ def _digest(pages: list[dict[str, Any]]) -> str: # "3.3", was "3.3-rc.3") moved every digest through ledger_snapshot_id and the # cursors that carry it, and nothing else. _PAGES_BEFORE_INDEXING: dict[str, str] = { - "periods": "c0ddf6b4d095ec8803146ca403a5094ad7a1702024440451e81a5fb50b0b7cfc", - "periods_without_statuses": "083b7ede5117863fb784f5e557fd0f891e1453e9a9d64f20451f070676f539ae", - "periods_node_budget": "54610f26da2611f1a7dbbe678cdf1dea7982a68ae0c785646478ed11e1157553", - "periods_filtered": "adbb513a401fad27c1f64f3c34135c83b880b69971de42e895362ddcb91429af", + "periods": "50d26b760b1c32e26977e1f44a2c452391dec0cb6391069584a01c3ce6920647", + "periods_without_statuses": "0f303fb48d074e868e39389ec40ec2f085b13140ac9ddf190a7f67242a1d25a9", + "periods_node_budget": "a4ef0e9d1877e676116c2ae041b6a5702e82ea071abf36f3258fccc6c9bf60a2", + "periods_filtered": "b755fdefb211b864df64a623e458558c94f869feecfa4758aee8f3f61e495e97", "periods_buy_horizon": "5e5eee3b09dcd0f89c6a1db1e2645c2cca49b14deda97edb40b286e2356c473e", - "periods_incremental": "95e32c3c66142db827290976339c4e99fa7ea466539fe813f83eda2ef54024e2", - "summary": "cbec158182ce3ee06ed7f44064072b1aa4706482b188c273ca497c14aa47ccbb", - "summary_filtered": "1dc6cd549556afc710ab80b4726337b76b0165fcf99a65606c3f1029eafb2dd0", + "periods_incremental": "3a421b16b5c5c4dd03e56bbb80c04851d5f86d9405d62ad7a2ab37ab308cde54", + "summary": "2495054b9eaf279492ffe9fcc02c33607d4758cc48a81799744e5fbd0a6568b7", + "summary_filtered": "955e8ee3531ac6bfe77ebaa855666c3316f3cb2f6f764638f9ad472a445165c4", "revision": "d373d0d8dc601c7e0a7e61745bd7f1137a63d1c15b8af95fdfdcdef1a64fccbb", } diff --git a/tests/test_reporting_status_paging.py b/tests/test_reporting_status_paging.py index db52866de..bd73fe12b 100644 --- a/tests/test_reporting_status_paging.py +++ b/tests/test_reporting_status_paging.py @@ -217,8 +217,8 @@ async def _re_versioned_ledger(generations: int, *, buys: int) -> InMemoryReport async def test_a_heavily_re_versioned_account_pages_within_budget_and_completely() -> None: # Staging's account 6082151998 had 334 generations. Every page repeats the # scope (the whole evaluated denominator) and bounded issues for a horizon - # that starts before ledger_retained_from. The records must make room for - # both projections. + # that starts before ledger_retained_from and generations that still have + # open periods. The records must make room for both projections. store = await _re_versioned_ledger(334, buys=8) request = { "view": "periods", @@ -237,6 +237,7 @@ async def test_a_heavily_re_versioned_account_pages_within_budget_and_completely assert page["ledger_snapshot_id"] == pages[0]["ledger_snapshot_id"] assert len(pages[0]["scope"]["delivery_config_generations"]) == 334 assert len(pages[0]["issues"]) == 100 - assert all(i["code"] == "HISTORY_UNAVAILABLE" for i in pages[0]["issues"]) + codes = {issue["code"] for issue in pages[0]["issues"]} + assert codes == {"HISTORY_UNAVAILABLE", "PRODUCTION_FAILED"} seen = [record for page in pages for record in _record_ids(page)] assert len(seen) == len(set(seen)) == pages[0]["pagination"]["total_count"] == 668