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
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,36 @@ if outcome.status != "COMPLETED":

`head_commit_sha` is a full SHA of 40 or 64 hexadecimal characters; any other value raises `ValueError` before a request. A review pinned to another head ends the wait on the read that names it. Its outcome is `INCOMPLETE` whatever the review's own status, its last gap has the reason code `HEAD_COMMIT_MISMATCH`, and `reason` says that the review is pinned to another head commit. A settled review that names no head has `HEAD_COMMIT_UNAVAILABLE` instead and is not `COMPLETED` either. `outcome.review.head_commit_sha` is the commit the review is pinned to. A patch review's head is a derived revision ID, so no commit matches it. In a GitHub Actions `pull_request` job, `GITHUB_SHA` is the merge commit; pass the pull request's head.

## Deploy verification

`wait_for_deploy_verifications` waits until Proofline records a check of the deploys of one commit, then returns what those checks recorded. It follows the same rules as `proofline ci deploy`.

```python
from proofline import DeploySelector

outcome = client.wait_for_deploy_verifications(
organization_id,
repository_id,
commit_sha,
until="MINUTES_20",
selector=DeploySelector(github_environment="production", deployment_task="deploy:web"),
timeout=1800,
)
if outcome.status != "NO_REGRESSION":
print(outcome.status, outcome.reason)
```

`until` is the check to wait for: `LANDING` (the default), `MINUTES_20`, `HOUR_1` or `DAY_1`, and the checks before it count too. `commit_sha` is a full 40-character lowercase SHA; any other value raises `ValueError` before a request. `selector` narrows the deploys by `environment_id`, `github_environment`, `deployment_task`, `github_deployment_id`, `workflow_run_id`, `workflow_run_attempt` or `aws_run_id`; without it every recorded deploy of the commit counts.

The outcome's `status` is one of:

- `REGRESSED`: a selected deploy failed or any of its checks recorded `REGRESSED`. This ends the wait at once.
- `NO_REGRESSION`: every check through `until` recorded `HEALTHY` with no gap. This means no regression was observed, not that the deploy is free of problems.
- `INCOMPLETE`: the check will not be recorded, or it is recorded but does not establish the result, for example a gap, a superseded or inactive deploy, deploy checks that ended early, or a state this SDK does not know.
- `TIMED_OUT`: the check was not recorded, or no selected deploy was recorded, before `timeout` seconds passed.

`outcome.readings` holds each selected deploy with its own reading, and `reason` explains any status other than `NO_REGRESSION`. To judge a single read yourself, pass the result of `get_commit_deploy_verifications` to `judge_deploy_verifications(read, until, selector)`; a check not recorded yet then reads `INCOMPLETE`. `AsyncProoflineClient` offers the same methods with `await`.

## Review exports

`export_reviews` reads one CSV or NDJSON page over the bounded transport. Export tokens require `analytics:read`.
Expand Down
16 changes: 16 additions & 0 deletions proofline/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
from ._generated.models import (
AgentSession,
AgentVendor,
CommitDeploy,
CommitDeployVerifications,
CommitReviewRequest,
CommitReviewResponse,
CoverageUploadRequest,
CoverageUploadResponse,
CustomerAssessmentDetail,
CustomerFinding,
CustomerReviewDetail,
DeployCheckpoint,
FileReviewRequest,
FileReviewResponse,
PatchReviewRequest,
Expand All @@ -34,6 +37,12 @@
from ._transport import VERSION as __version__
from ._transport import ProoflineError, RunNowRefusal
from .client import AsyncProoflineClient, ProoflineClient, ReviewFilters
from .deploys import (
DeployReading,
DeploySelector,
DeployVerificationOutcome,
judge_deploy_verifications,
)
from .exports import ExportDataset, ExportFormat, ExportPage
from .knowledge import KnowledgeResult
from .outcomes import AssessmentGap, CheckGap, ReviewOutcome
Expand All @@ -44,13 +53,19 @@
"AssessmentGap",
"AsyncProoflineClient",
"CheckGap",
"CommitDeploy",
"CommitDeployVerifications",
"CommitReviewRequest",
"CommitReviewResponse",
"CoverageUploadRequest",
"CoverageUploadResponse",
"CustomerAssessmentDetail",
"CustomerFinding",
"CustomerReviewDetail",
"DeployCheckpoint",
"DeployReading",
"DeploySelector",
"DeployVerificationOutcome",
"ExportDataset",
"ExportFormat",
"ExportPage",
Expand Down Expand Up @@ -79,5 +94,6 @@
"StopResponse",
"UploadedReport",
"__version__",
"judge_deploy_verifications",
"models",
]
36 changes: 0 additions & 36 deletions proofline/_generated/api/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,14 @@

from ... import _transport
from ..client import AuthenticatedClient
from ..models.commit_deploy_verifications import CommitDeployVerifications
from ..models.scan_request_body import ScanRequestBody
from ..models.scan_response import ScanResponse
from .default import get_commit_deploy_verifications as operation_get_commit_deploy_verifications
from .default import request_scan as operation_request_scan


class Operations:
_api: AuthenticatedClient

def get_commit_deploy_verifications(
self,
org_id: UUID,
repo_id: UUID,
commit_sha: str,
) -> CommitDeployVerifications:
with _transport.operation_errors():
response = operation_get_commit_deploy_verifications.sync_detailed(
client=self._api,
org_id=org_id,
repo_id=repo_id,
commit_sha=commit_sha,
)
if not (response.status_code == 200):
raise _transport.invalid_response()
return cast(CommitDeployVerifications, response.parsed)

def request_scan(
self,
org_id: UUID,
Expand All @@ -54,23 +35,6 @@ def request_scan(
class AsyncOperations:
_api: AuthenticatedClient

async def get_commit_deploy_verifications(
self,
org_id: UUID,
repo_id: UUID,
commit_sha: str,
) -> CommitDeployVerifications:
with _transport.operation_errors():
response = await operation_get_commit_deploy_verifications.asyncio_detailed(
client=self._api,
org_id=org_id,
repo_id=repo_id,
commit_sha=commit_sha,
)
if not (response.status_code == 200):
raise _transport.invalid_response()
return cast(CommitDeployVerifications, response.parsed)

async def request_scan(
self,
org_id: UUID,
Expand Down
127 changes: 127 additions & 0 deletions proofline/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
get_agent_session,
get_agent_session_prompt,
get_assessment,
get_commit_deploy_verifications,
get_deployment_review,
get_finding,
get_finding_fix_prompt,
Expand All @@ -44,13 +45,15 @@
from ._generated.models.agent_session import AgentSession
from ._generated.models.agent_session_prompt_type_0 import AgentSessionPromptType0
from ._generated.models.agent_session_prompt_type_1 import AgentSessionPromptType1
from ._generated.models.commit_deploy_verifications import CommitDeployVerifications
from ._generated.models.commit_review_request import CommitReviewRequest
from ._generated.models.commit_review_response import CommitReviewResponse
from ._generated.models.coverage_upload_request import CoverageUploadRequest
from ._generated.models.coverage_upload_response import CoverageUploadResponse
from ._generated.models.customer_assessment_detail import CustomerAssessmentDetail
from ._generated.models.customer_finding import CustomerFinding
from ._generated.models.customer_review_detail import CustomerReviewDetail
from ._generated.models.deploy_checkpoint import DeployCheckpoint
from ._generated.models.file_review_request import FileReviewRequest
from ._generated.models.file_review_response import FileReviewResponse
from ._generated.models.finding_fix_prompt_type_0 import FindingFixPromptType0
Expand All @@ -72,6 +75,13 @@
from ._generated.types import UNSET, Response, Unset
from ._mcp import AsyncMcpClient, McpClient
from ._transport import ProoflineError
from .deploys import (
Checkpoint,
DeploySelector,
DeployVerificationOutcome,
checkpoint_name,
conclude,
)
from .exports import ExportDataset, ExportFormat, ExportPage, decode_export
from .fixes import AsyncFixesClient, FixesClient
from .knowledge import AsyncKnowledgeClient, KnowledgeClient
Expand Down Expand Up @@ -163,6 +173,23 @@ def _head_commit(value: str | None) -> None:
raise ValueError("The head commit must be a full 40 or 64 character hexadecimal SHA.")


def _commit_sha(value: str) -> None:
# The deploy route accepts only a full lowercase SHA; refuse anything else before a request.
if (
not isinstance(value, str)
or len(value) != 40
or any(character not in "0123456789abcdef" for character in value)
):
raise ValueError("The commit must be a full 40 character lowercase hexadecimal SHA.")


def _deploy_wait(timeout: float, commit_sha: str, until: str) -> Checkpoint:
if not math.isfinite(timeout) or timeout < 0:
raise ValueError("The deploy timeout must be a finite nonnegative number of seconds.")
_commit_sha(commit_sha)
return checkpoint_name(until)


def _next_cursor(page: ReviewPage, seen: set[str]) -> str | None:
if not isinstance(page.truncated, bool):
raise _transport.invalid_response()
Expand Down Expand Up @@ -539,6 +566,59 @@ def iter_reviews(
params["cursor"] = cursor
raise _pagination_limit()

def get_commit_deploy_verifications(
self, organization_id: UUID, repository_id: UUID, commit_sha: str
) -> CommitDeployVerifications:
_commit_sha(commit_sha)
return self._call(
get_commit_deploy_verifications.sync_detailed,
CommitDeployVerifications,
organization_id,
repository_id,
commit_sha,
)

def wait_for_deploy_verifications(
self,
organization_id: UUID,
repository_id: UUID,
commit_sha: str,
*,
until: Checkpoint | DeployCheckpoint = "LANDING",
selector: DeploySelector | None = None,
timeout: float = 1800,
) -> DeployVerificationOutcome:
"""Wait until the selected deploys record the `until` check, or return TIMED_OUT.

A regression ends the wait at once. NO_REGRESSION means every check
through `until` recorded HEALTHY with no gap; any other settled read is
INCOMPLETE.
"""
checkpoint = _deploy_wait(timeout, commit_sha, until)
last: CommitDeployVerifications | None = None
deadline = _transport.DEADLINE.set(monotonic() + timeout)
interval = 5.0
try:
while (_transport.remaining() or 0) > 0:
try:
last = self.get_commit_deploy_verifications(
organization_id, repository_id, commit_sha
)
except ProoflineError as error:
if error.status == 0 and (_transport.remaining() or 0) <= 0:
break
raise
result = conclude(last, checkpoint, selector, None)
if result is not None:
return result
sleep(min(interval, _transport.remaining() or 0))
interval = min(60, interval * 2)
return cast(
DeployVerificationOutcome, conclude(last, checkpoint, selector, "TIMED_OUT")
)
finally:
_transport.DEADLINE.reset(deadline)

def wait_for_review(
self,
organization_id: UUID,
Expand Down Expand Up @@ -934,6 +1014,53 @@ async def iter_reviews(
params["cursor"] = cursor
raise _pagination_limit()

async def get_commit_deploy_verifications(
self, organization_id: UUID, repository_id: UUID, commit_sha: str
) -> CommitDeployVerifications:
_commit_sha(commit_sha)
return await self._call(
get_commit_deploy_verifications.asyncio_detailed,
CommitDeployVerifications,
organization_id,
repository_id,
commit_sha,
)

async def wait_for_deploy_verifications(
self,
organization_id: UUID,
repository_id: UUID,
commit_sha: str,
*,
until: Checkpoint | DeployCheckpoint = "LANDING",
selector: DeploySelector | None = None,
timeout: float = 1800,
) -> DeployVerificationOutcome:
checkpoint = _deploy_wait(timeout, commit_sha, until)
last: CommitDeployVerifications | None = None
deadline = _transport.DEADLINE.set(monotonic() + timeout)
interval = 5.0
try:
while (_transport.remaining() or 0) > 0:
try:
last = await self.get_commit_deploy_verifications(
organization_id, repository_id, commit_sha
)
except ProoflineError as error:
if error.status == 0 and (_transport.remaining() or 0) <= 0:
break
raise
result = conclude(last, checkpoint, selector, None)
if result is not None:
return result
await async_sleep(min(interval, _transport.remaining() or 0))
interval = min(60, interval * 2)
return cast(
DeployVerificationOutcome, conclude(last, checkpoint, selector, "TIMED_OUT")
)
finally:
_transport.DEADLINE.reset(deadline)

async def wait_for_review(
self,
organization_id: UUID,
Expand Down
Loading