Documentation
¶
Overview ¶
Package reviewpolicy owns the shared review/close policy decisions that used to be duplicated across cmd/review_policy.go, internal/db/issues.go (ReviewableByFilter), pkg/monitor/actions.go, internal/serve/handlers_transitions.go, and internal/api/snapshot_query_source.go.
Batch 1b goal: define the package and its surface without activating the new delegated-review behavior. Callers keep using their existing helpers; Batch 1c routes them through this package so all surfaces return identical decisions before Step 2 adds the record-only + close-after-review flow.
The package is intentionally framework-free: it takes in plain data (issue + session booleans) and returns a decision. Database access, config loading, and logging happen in the callers — this keeps the policy logic pure and trivially testable.
Index ¶
Constants ¶
const ( DecisionApproved = "approved" DecisionChangesRequested = "changes_requested" DecisionApprovedByParentCascade = "approved_by_parent_cascade" )
Decision values used in issue_reviews.decision. These are duplicated in internal/db/reviews.go as string literals today; centralizing them here lets Batch 1c switch call sites to named constants without introducing a models-package dependency cycle.
const ( ReasonImplementerCannotReview = "you cannot review your own implementation" // ReasonTrustedSelfReviewNeedsFlag is the teaching base string used when a // session that implemented (or has implementation history) tries to review // in trusted mode without acknowledging the self-review. It names BOTH the // preferred norm (delegate to an independent session) and the explicit // escape hatch. Callers append the issue ID via the format helper below. ReasonTrustedSelfReviewNeedsFlag = "" /* 180-byte string literal not displayed */ ReasonPriorInvolvement = "you were involved with this issue (created, started, or previously worked on)" ReasonIssueNotInReview = "issue is not in review" ReasonNoActiveReview = "no active approval review exists yet for this issue" ReasonNotAllowedCloser = "no active independent approval review exists for this issue" ReasonIssueNotFound = "issue not found" )
Rejection-reason constants. Callers format their own final messages on top of these base strings so surfaces can produce uniform error text without sharing sprintf templates.
const CascadeFromParentApproval = "cascade_from_parent_approval"
CascadeFromParentApproval is the named exemption used when an epic-approval cascade closes descendants in bulk. See pkg/monitor/actions.go approval cascade. The new model records it as an issue_reviews row with this decision so audit output can tell cascaded closes from direct ones.
Variables ¶
This section is empty.
Functions ¶
func IsReviewInvalidatingMutation ¶
func IsReviewInvalidatingMutation(m IssueMutation) bool
IsReviewInvalidatingMutation returns true if any of the flagged changes should supersede an active approval review on the issue. Called from both the DB write path and the sync import path in Batch 1c.
Types ¶
type CloseEligibility ¶
type CloseEligibility struct {
Allowed bool
CreatorOpenBypass bool // preserves the existing balanced-mode self-created throwaway path
RequiresReason bool
RejectionMessage string
}
CloseEligibility is the decision returned by EvaluateCloseEligibility.
func EvaluateCloseEligibility ¶
func EvaluateCloseEligibility(in CloseEligibilityInput) CloseEligibility
EvaluateCloseEligibility decides whether the current session may close the supplied issue. Strict and balanced modes reproduce the existing behavior exactly (cmd/review_policy.go:evaluateCloseEligibility). Delegated mode defines the new close-after-review predicate but is not yet activated by callers — Batch 1c + Step 2 flip the call sites.
type CloseEligibilityInput ¶
type CloseEligibilityInput struct {
Mode Mode
Issue *models.Issue
SessionID string
SessionIsImplementer bool
SessionIsCreator bool
SessionIsReviewerOfRecord bool // session == issue.ReviewerSession, non-empty
SessionIsReviewRequester bool // session == issue.ReviewRequestedBySession, non-empty
HasImplementationHistory bool
WasAnyInvolved bool
HasActiveApproval bool
// SelfReviewAcknowledged is true when the caller passed --self-review. It
// only has an effect in trusted mode's direct review+close path (Case 2),
// where it lets the implementer approve+close their own work in one action.
SelfReviewAcknowledged bool
}
CloseEligibilityInput is the full set of facts the policy layer needs to decide whether a session may close an issue. In delegated mode, the active approval record is the safety gate; the caller's role is audit metadata, not a close permission.
type IssueMutation ¶
type IssueMutation struct {
DescriptionChanged bool
TitleChanged bool
TypeChanged bool
PriorityChanged bool
MinorChanged bool
ParentIDChanged bool
// StatusChangedFromReviewNotClosing is true when an issue transitions
// out of in_review to any status other than closed (i.e. rejected back
// to open/in_progress/blocked). An in_review -> closed transition
// should NOT flag this; that's the normal close path and must not
// supersede its own approval.
StatusChangedFromReviewNotClosing bool
LinkedFilesChanged bool
DependenciesChanged bool
WorkSessionTagsChanged bool
// ReparentCascade is true when a parent-reparent cascade touched the
// issue indirectly. Cascades that effectively re-scope the issue should
// supersede any pending review.
ReparentCascade bool
}
IssueMutation describes the subset of an issue-update diff that is relevant to review freshness. Pure-metadata fields (due_date, labels, notes, comments, log entries) are intentionally excluded from the struct so new callers cannot accidentally widen the invalidation set.
type Mode ¶
type Mode string
Mode is the named-enum policy mode described in the plan under "Feature Flag and Compatibility Plan". Prefer this single string over stacked booleans so "what mode am I in?" is answerable from one config line.
const ( // ModeStrict preserves the pre-balanced behavior: any prior involvement // (creator, implementer, or history) blocks approval and close. ModeStrict Mode = "strict" // ModeBalanced preserves the legacy creator-exception behavior. The // implementer still cannot self-approve, but a creator that did not // implement may approve work implemented by a different session. Step 5 // made delegated the default; balanced is retained for projects that // explicitly opt in via review_policy_mode=balanced. New setups should // prefer delegated — it replaces the creator-exception workaround with // explicit review attestations that allow any involved role to close // after an independent review. ModeBalanced Mode = "balanced" // ModeDelegated is the new review-attestation model. Reviewer eligibility // is based solely on implementation independence (no started/unstarted // history, not the current implementer). Creator-only sessions are // eligible reviewers. Close-after-recorded-approval is wired in Step 2. ModeDelegated Mode = "delegated" // ModeTrusted is delegated plus a flag-gated, audited self-review escape // hatch. It keeps the delegated reviewer-independence norm — an // independent session is always the preferred reviewer — but allows the // implementer (or any session with implementation history) to record an // approval and direct-close their own work IF they explicitly acknowledge // the self-review with the --self-review flag and supply a --reason. The // acknowledgement is stamped on the review row for audit. Without the // flag, trusted mode behaves exactly like delegated and rejects the // self-review with a teaching message. ModeTrusted Mode = "trusted" )
type ReviewerEligibility ¶
type ReviewerEligibility struct {
Allowed bool
CreatorException bool
RequiresReason bool
RejectionMessage string
// SelfReview marks the trusted-mode path where an implementer (or session
// with implementation history) approved their own work after explicitly
// acknowledging it with --self-review. Callers stamp it on the review row
// for audit.
SelfReview bool
}
ReviewerEligibility is the decision returned by EvaluateReviewerEligibility. CreatorException marks the balanced-mode path where the current behavior already required a reason.
func EvaluateReviewerEligibility ¶
func EvaluateReviewerEligibility(in ReviewerEligibilityInput) ReviewerEligibility
EvaluateReviewerEligibility decides whether the current session may record an approval review for the supplied issue. Batch 1b keeps this function behavior-equivalent to the existing cmd/review_policy.go logic for strict and balanced modes. Delegated mode defines the new permission-to-record check; it does NOT yet alter caller flow (that lands in Batch 1c / Step 2).
type ReviewerEligibilityInput ¶
type ReviewerEligibilityInput struct {
Mode Mode
Issue *models.Issue
SessionID string
SessionIsImplementer bool
SessionIsCreator bool
HasImplementationHistory bool // WasSessionImplementationInvolved
HasActiveApproval bool // GetActiveApprovalReview != nil
// SelfReviewAcknowledged is true when the caller passed --self-review (or
// the UI equivalent). It only has an effect in trusted mode, where it
// converts the implementer self-review rejection into a flag-gated,
// audited allow.
SelfReviewAcknowledged bool
// WasAnyInvolved mirrors the old WasSessionInvolved helper (any history
// row at all, including created/reviewed). Required for strict mode
// parity with the current cmd/review_policy.go:evaluateApproveEligibility
// behavior. Balanced/delegated modes ignore it once the implementation
// check already ruled the session out.
//
// NOTE: this is intentionally broader than HasImplementationHistory. That
// helper counts only started/unstarted action rows; WasAnyInvolved counts
// ANY row in issue_session_history, including `created` and `reviewed`.
// Callers must not conflate the two: strict mode uses WasAnyInvolved to
// preserve the "any prior involvement disqualifies" rule; balanced and
// delegated modes use HasImplementationHistory to allow creator-only
// approvals of work another session implemented.
WasAnyInvolved bool
}
ReviewerEligibilityInput is the full set of facts the policy layer needs to decide whether a session may record an approval review for an issue.
Booleans are computed by the caller so the policy layer has no DB dependency. The caller is expected to use existing helpers like db.WasSessionImplementationInvolved to populate HasImplementationHistory.