Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ with ProoflineClient() as client:

Use `async for` with `AsyncProoflineClient`. Each yielded page retains its raw text, decoded rows, and metadata; CSV pages retain their individual headers. Pass `cursor=` to resume an export. Iteration stops only when the server omits the next cursor, including when an intermediate page has no rows. Empty or repeated continuation cursors raise `ProoflineError` with type `urn:proofline:sdk:invalid-pagination`, and the page that carries such a cursor is never yielded. The default bound is 100 pages; set `max_pages` to an integer from 1 to 1000. Exhausting that bound while a cursor remains raises `urn:proofline:sdk:pagination-limit`, so a partial export cannot silently appear complete. Stop iteration early when only a prefix is needed.

### Finding outcomes

`iter_finding_outcomes` reads the `finding_outcomes` export as NDJSON and yields one `FindingOutcomeGroup` per row. `group_by` defaults to `"repository"`. Each rate divides by the denominator the docs name for it:

```python
with ProoflineClient() as client:
for group in client.iter_finding_outcomes(
UUID(os.environ["PROOFLINE_ORGANIZATION_ID"]),
from_time="2026-10-01T00:00:00Z",
to_time="2026-10-25T00:00:00Z",
):
print(group.name, group.human_rate("DISMISSED"), group.post_merge_rate("ADDRESSED"))
# example/payments 1 of 6 (17%) 2 of 3 (67%)
```

`human_rate` accepts `FIXED`, `CONFIRMED`, `ACCEPTED_RISK` or `DISMISSED` and divides by `external_validation_denominator`. `code_changed_rate()` divides by `published`. `post_merge_rate` divides by `post_merge.judged`. An `OutcomeRate` with a zero denominator has `value` `None` and prints as `0 of 0, no rate`, never 0% or 100%. A row that breaks a documented count raises `ProoflineError` with type `urn:proofline:sdk:invalid-response`, and the page holding it yields no groups. For example, `published` must equal the sum of the six outcomes. The `outcomes` and `post_merge` counts are read-only.

## Coverage uploads

To upload coverage reports from CI, use a repository-restricted token with `coverage:write` and current repository write access. Name the full commit SHA that the tests ran on. Send 1 to 50 LCOV, Cobertura XML, JaCoCo XML, or Go cover reports in a JSON body of at most 30 MiB.
Expand Down
3 changes: 3 additions & 0 deletions proofline/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from ._transport import ProoflineError, RunNowRefusal
from .client import AsyncProoflineClient, ProoflineClient, ReviewFilters
from .exports import ExportDataset, ExportFormat, ExportPage
from .finding_outcomes import FindingOutcomeGroup, OutcomeRate
from .knowledge import KnowledgeResult
from .outcomes import AssessmentGap, CheckGap, ReviewOutcome

Expand All @@ -56,7 +57,9 @@
"ExportPage",
"FileReviewRequest",
"FileReviewResponse",
"FindingOutcomeGroup",
"KnowledgeResult",
"OutcomeRate",
"PatchReviewRequest",
"PatchReviewResponse",
"PatchTriggerSource",
Expand Down
48 changes: 48 additions & 0 deletions proofline/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
from ._mcp import AsyncMcpClient, McpClient
from ._transport import ProoflineError
from .exports import ExportDataset, ExportFormat, ExportPage, decode_export
from .finding_outcomes import FindingOutcomeGroup, finding_outcome_group
from .fixes import AsyncFixesClient, FixesClient
from .knowledge import AsyncKnowledgeClient, KnowledgeClient
from .outcomes import ReviewOutcome, outcome
Expand Down Expand Up @@ -336,6 +337,29 @@ def iter_export_pages(
return
raise _pagination_limit("Export")

def iter_finding_outcomes(
self,
organization_id: UUID,
*,
from_time: str,
to_time: str,
cursor: str | None = None,
group_by: str = "repository",
max_pages: int = 100,
) -> Iterator[FindingOutcomeGroup]:
"""Stream finding_outcomes groups, checking each row's documented counts."""
for page in self.iter_export_pages(
organization_id,
"finding_outcomes",
from_time=from_time,
to_time=to_time,
cursor=cursor,
group_by=group_by,
max_pages=max_pages,
):
# Check the whole page first, so a bad row never yields part of a page.
yield from [finding_outcome_group(row) for row in page.rows]

def list_reviews(self, organization_id: UUID, **filters: Unpack[ReviewFilters]) -> ReviewPage:
return self._call(list_reviews.sync_detailed, ReviewPage, organization_id, **filters)

Expand Down Expand Up @@ -708,6 +732,30 @@ async def iter_export_pages(
return
raise _pagination_limit("Export")

async def iter_finding_outcomes(
self,
organization_id: UUID,
*,
from_time: str,
to_time: str,
cursor: str | None = None,
group_by: str = "repository",
max_pages: int = 100,
) -> AsyncIterator[FindingOutcomeGroup]:
"""Stream finding_outcomes groups, checking each row's documented counts."""
async for page in self.iter_export_pages(
organization_id,
"finding_outcomes",
from_time=from_time,
to_time=to_time,
cursor=cursor,
group_by=group_by,
max_pages=max_pages,
):
# Check the whole page first, so a bad row never yields part of a page.
for group in [finding_outcome_group(row) for row in page.rows]:
yield group

async def list_reviews(
self, organization_id: UUID, **filters: Unpack[ReviewFilters]
) -> ReviewPage:
Expand Down
133 changes: 133 additions & 0 deletions proofline/finding_outcomes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
"""Finding outcome groups whose rates each use their own documented denominator."""

from __future__ import annotations

from collections.abc import Mapping
from dataclasses import dataclass
from datetime import datetime
from types import MappingProxyType
from typing import Any
from uuid import UUID

from ._generated.models.finding_outcomes_export_row import FindingOutcomesExportRow
from ._generated.models.finding_outcomes_group_by import FindingOutcomesGroupBy
from ._generated.models.finding_outcomes_outcome import FindingOutcomesOutcome
from ._generated.models.finding_outcomes_post_merge_outcome import (
FindingOutcomesPostMergeOutcome,
)
from ._transport import ProoflineError

HUMAN_OUTCOMES = frozenset(
(
FindingOutcomesOutcome.FIXED,
FindingOutcomesOutcome.CONFIRMED,
FindingOutcomesOutcome.ACCEPTED_RISK,
FindingOutcomesOutcome.DISMISSED,
)
)


@dataclass(frozen=True)
class OutcomeRate:
count: int
denominator: int

@property
def value(self) -> float | None:
# A zero denominator has no rate, never 0% or 100%.
return self.count / self.denominator if self.denominator else None

def __str__(self) -> str:
value = self.value
if value is None:
return f"{self.count} of {self.denominator}, no rate"
return f"{self.count} of {self.denominator} ({value:.0%})"


@dataclass(frozen=True)
class FindingOutcomeGroup:
organization_id: UUID
from_: datetime
to: datetime
group_by: FindingOutcomesGroupBy
key: str
name: str
published: int
external_validation_denominator: int
outcomes: Mapping[FindingOutcomesOutcome, int]
code_changed: int
post_merge_judged: int
post_merge: Mapping[FindingOutcomesPostMergeOutcome, int]
limitations: tuple[str, ...]

def human_rate(self, outcome: FindingOutcomesOutcome | str) -> OutcomeRate:
"""A person's outcome over the human-validated series, not over published."""
outcome = FindingOutcomesOutcome(outcome)
if outcome not in HUMAN_OUTCOMES:
raise ValueError("A human rate needs FIXED, CONFIRMED, ACCEPTED_RISK or DISMISSED.")
return OutcomeRate(self.outcomes[outcome], self.external_validation_denominator)

def code_changed_rate(self) -> OutcomeRate:
return OutcomeRate(self.code_changed, self.published)

def post_merge_rate(self, outcome: FindingOutcomesPostMergeOutcome | str) -> OutcomeRate:
"""A post-merge outcome over the judged series, not over published."""
count = self.post_merge[FindingOutcomesPostMergeOutcome(outcome)]
return OutcomeRate(count, self.post_merge_judged)


def finding_outcome_group(raw: Any) -> FindingOutcomeGroup:
try:
if not isinstance(raw, dict):
raise ValueError
row = FindingOutcomesExportRow.from_dict(raw)
outcomes = {item.outcome: item.count for item in row.outcomes}
post_merge = {item.outcome: item.count for item in row.post_merge.outcomes}
counts = (
row.published,
row.external_validation_denominator,
row.code_changed.count,
row.post_merge.judged,
*outcomes.values(),
*post_merge.values(),
)
if (
any(type(count) is not int or count < 0 for count in counts)
or row.from_.tzinfo is None
or row.to.tzinfo is None
or not isinstance(row.key, str)
or not isinstance(row.name, str)
or not isinstance(row.limitations, list)
or not all(isinstance(item, str) for item in row.limitations)
or len(outcomes) != len(row.outcomes)
or set(outcomes) != set(FindingOutcomesOutcome)
or len(post_merge) != len(row.post_merge.outcomes)
or set(post_merge) != set(FindingOutcomesPostMergeOutcome)
or row.published != sum(outcomes.values())
or row.external_validation_denominator != sum(outcomes[o] for o in HUMAN_OUTCOMES)
or row.post_merge.judged != sum(post_merge.values())
or row.code_changed.count > row.published
or row.post_merge.judged > row.published
):
raise ValueError
except (ValueError, KeyError, TypeError, AttributeError):
raise ProoflineError(
0,
"urn:proofline:sdk:invalid-response",
"The finding outcome row is invalid.",
) from None
return FindingOutcomeGroup(
row.organization_id,
row.from_,
row.to,
row.group_by,
row.key,
row.name,
row.published,
row.external_validation_denominator,
MappingProxyType(outcomes),
row.code_changed.count,
row.post_merge.judged,
MappingProxyType(post_merge),
tuple(row.limitations),
)
9 changes: 8 additions & 1 deletion scripts/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ def main() -> None:
raise SystemExit("ReviewFilters differs from the list_reviews query parameters.")

for client in (ProoflineClient, AsyncProoflineClient):
helpers = {"close", "aclose", "iter_export_pages", "iter_reviews", "wait_for_review"}
helpers = {
"close",
"aclose",
"iter_export_pages",
"iter_finding_outcomes",
"iter_reviews",
"wait_for_review",
}
exposed = {
name
for name in dir(client)
Expand Down
Loading