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
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,28 @@ 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.

## Waiting on commit deploy verifications

`wait_for_commit_deploy_verifications` polls `get_commit_deploy_verifications` for one exact 40-character lowercase commit SHA, optionally filtered by `environment_id`, `github_environment`, or `deployment_task`, and evaluates recorded evidence via `evaluate_deploy_verifications`.

```python
from proofline import DeployCheckpoint, ProoflineClient

with ProoflineClient() as client:
deploy = client.wait_for_commit_deploy_verifications(
organization_id,
repository_id,
commit_sha,
github_environment="production",
until_checkpoint=DeployCheckpoint.LANDING,
timeout=180,
)
if deploy.status not in ("VERIFIED", "CHECKPOINT_VERIFIED"):
print(deploy.status, deploy.gaps, deploy.reason)
```

Pass `until_checkpoint` (`LANDING`, `MINUTES_20`, `HOUR_1`, or `DAY_1`) to settle once every checkpoint up to that window records a result, or omit it to wait for full deploy verification. Regressions (`REGRESSED`), rollbacks (`ROLLED_BACK`), and deployment failures (`FAILED`) short-circuit immediately when `fail_fast=True`, and recorded gaps never resolve as `VERIFIED` or `CHECKPOINT_VERIFIED`.

## Review exports

`export_reviews` reads one CSV or NDJSON page over the bounded transport. Export tokens require `analytics:read`.
Expand Down
22 changes: 22 additions & 0 deletions proofline/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
from ._generated.models import (
AgentSession,
AgentVendor,
CommitDeploy,
CommitDeployRollback,
CommitDeployVerifications,
CommitReviewRequest,
CommitReviewResponse,
CoverageUploadRequest,
CoverageUploadResponse,
CustomerAssessmentDetail,
CustomerFinding,
CustomerReviewDetail,
DeployCheckpoint,
DeployCoverageCheckpoint,
FileReviewRequest,
FileReviewResponse,
PatchReviewRequest,
Expand All @@ -34,6 +39,13 @@
from ._transport import VERSION as __version__
from ._transport import ProoflineError, RunNowRefusal
from .client import AsyncProoflineClient, ProoflineClient, ReviewFilters
from .deploy_outcomes import (
DeployCheckpointGap,
DeployEvaluation,
DeployOutcomeStatus,
DeployVerificationOutcome,
evaluate_deploy_verifications,
)
from .exports import ExportDataset, ExportFormat, ExportPage
from .knowledge import KnowledgeResult
from .outcomes import AssessmentGap, CheckGap, ReviewOutcome
Expand All @@ -44,13 +56,22 @@
"AssessmentGap",
"AsyncProoflineClient",
"CheckGap",
"CommitDeploy",
"CommitDeployRollback",
"CommitDeployVerifications",
"CommitReviewRequest",
"CommitReviewResponse",
"CoverageUploadRequest",
"CoverageUploadResponse",
"CustomerAssessmentDetail",
"CustomerFinding",
"CustomerReviewDetail",
"DeployCheckpoint",
"DeployCheckpointGap",
"DeployCoverageCheckpoint",
"DeployEvaluation",
"DeployOutcomeStatus",
"DeployVerificationOutcome",
"ExportDataset",
"ExportFormat",
"ExportPage",
Expand Down Expand Up @@ -79,5 +100,6 @@
"StopResponse",
"UploadedReport",
"__version__",
"evaluate_deploy_verifications",
"models",
]
146 changes: 146 additions & 0 deletions proofline/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,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 +74,11 @@
from ._generated.types import UNSET, Response, Unset
from ._mcp import AsyncMcpClient, McpClient
from ._transport import ProoflineError
from .deploy_outcomes import (
DeployVerificationOutcome,
evaluate_deploy_verifications,
normalize_checkpoint,
)
from .exports import ExportDataset, ExportFormat, ExportPage, decode_export
from .fixes import AsyncFixesClient, FixesClient
from .knowledge import AsyncKnowledgeClient, KnowledgeClient
Expand Down Expand Up @@ -153,6 +160,9 @@ def _page_limits(page_size: int, max_pages: int, max_items: int) -> None:
)


_LOWER_HEX = frozenset("0123456789abcdef")


def _head_commit(value: str | None) -> None:
# Only a full SHA names one exact commit; a branch or an abbreviation does not.
if value is not None and (
Expand All @@ -163,6 +173,28 @@ def _head_commit(value: str | None) -> None:
raise ValueError("The head commit must be a full 40 or 64 character hexadecimal SHA.")


def _commit_sha40(value: str) -> None:
if (
not isinstance(value, str)
or len(value) != 40
or any(character not in _LOWER_HEX for character in value)
):
raise ValueError("The commit SHA must be a full 40-character lowercase hexadecimal SHA.")


def _deploy_wait_inputs(
commit_sha: str,
timeout: float,
until_checkpoint: DeployCheckpoint | str | None,
) -> str | None:
if isinstance(timeout, bool) or not math.isfinite(timeout) or timeout < 0:
raise ValueError(
"The deploy verification timeout must be a finite nonnegative number of seconds."
)
_commit_sha40(commit_sha)
return normalize_checkpoint(until_checkpoint)


def _next_cursor(page: ReviewPage, seen: set[str]) -> str | None:
if not isinstance(page.truncated, bool):
raise _transport.invalid_response()
Expand Down Expand Up @@ -583,6 +615,63 @@ def wait_for_review(
finally:
_transport.DEADLINE.reset(deadline)

def wait_for_commit_deploy_verifications(
self,
organization_id: UUID,
repository_id: UUID,
commit_sha: str,
*,
timeout: float = 300,
environment_id: UUID | None = None,
github_environment: str | None = None,
deployment_task: str | None = None,
until_checkpoint: DeployCheckpoint | str | None = None,
fail_fast: bool = True,
) -> DeployVerificationOutcome:
"""Wait for a commit's deploy verifications to settle or reach a checkpoint."""
target = _deploy_wait_inputs(commit_sha, timeout, until_checkpoint)
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
if (_transport.remaining() or 0) <= 0:
break
result = evaluate_deploy_verifications(
last,
commit_sha,
environment_id=environment_id,
github_environment=github_environment,
deployment_task=deployment_task,
until_checkpoint=target,
fail_fast=fail_fast,
)
if result is not None:
return result
sleep(min(interval, _transport.remaining() or 0))
interval = min(60, interval * 2)
timed_out = evaluate_deploy_verifications(
last,
commit_sha,
"TIMED_OUT",
environment_id=environment_id,
github_environment=github_environment,
deployment_task=deployment_task,
until_checkpoint=target,
fail_fast=fail_fast,
)
return timed_out or DeployVerificationOutcome("TIMED_OUT", commit_sha, False)
finally:
_transport.DEADLINE.reset(deadline)


class AsyncProoflineClient(AsyncOperations):
def __init__(
Expand Down Expand Up @@ -968,3 +1057,60 @@ async def wait_for_review(
return timed_out or ReviewOutcome("TIMED_OUT", url)
finally:
_transport.DEADLINE.reset(deadline)

async def wait_for_commit_deploy_verifications(
self,
organization_id: UUID,
repository_id: UUID,
commit_sha: str,
*,
timeout: float = 300,
environment_id: UUID | None = None,
github_environment: str | None = None,
deployment_task: str | None = None,
until_checkpoint: DeployCheckpoint | str | None = None,
fail_fast: bool = True,
) -> DeployVerificationOutcome:
"""Wait for a commit's deploy verifications to settle or reach a checkpoint."""
target = _deploy_wait_inputs(commit_sha, timeout, until_checkpoint)
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
if (_transport.remaining() or 0) <= 0:
break
result = evaluate_deploy_verifications(
last,
commit_sha,
environment_id=environment_id,
github_environment=github_environment,
deployment_task=deployment_task,
until_checkpoint=target,
fail_fast=fail_fast,
)
if result is not None:
return result
await async_sleep(min(interval, _transport.remaining() or 0))
interval = min(60, interval * 2)
timed_out = evaluate_deploy_verifications(
last,
commit_sha,
"TIMED_OUT",
environment_id=environment_id,
github_environment=github_environment,
deployment_task=deployment_task,
until_checkpoint=target,
fail_fast=fail_fast,
)
return timed_out or DeployVerificationOutcome("TIMED_OUT", commit_sha, False)
finally:
_transport.DEADLINE.reset(deadline)
Loading