Skip to content
Closed
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
1 change: 1 addition & 0 deletions changelog.d/fixed-delegated-capability-inference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Delegated issue decisions now use the blocker ledger's shared capability inference, keeping repository-write, branch-protection, secret, and workflow permission gaps parked instead of approving ineffective directions, while retaining the park for other missing App permissions (#15217).
20 changes: 14 additions & 6 deletions src/pkg/delegatedecision/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"sort"
"strconv"
"strings"

"github.com/hivecommons/hive/pkg/blocker"
)

// PolicyName is the policy identifier the audit marker carries.
Expand Down Expand Up @@ -247,9 +249,9 @@ var (
ratchetRE = regexp.MustCompile(`(?i)\b(actionlint|ratchet|duplication (?:gate|threshold|check)|link[- ]?checker|allow-?list|lint gate|hygiene gate|shellcheck|yamllint|markdownlint)\b`)
proposalRE = regexp.MustCompile(`(?i)\bacceptance criteria\b`)
hivePolicyRE = regexp.MustCompile(`(?i)\b(hive\.ya?ml|governance|security posture|hive (?:settings?|config(?:uration)?|policy|policies)|branch protection|CODEOWNERS|required checks?|autonomy level|acmm level)\b`)
// capabilityGapRE matches a blocker no direction decision can clear: the
// GitHub App lacks a permission (for example `workflows`).
capabilityGapRE = regexp.MustCompile(`(?i)\b(?:app(?: token)?|installation|github app)\b[^\n]{0,80}\b(?:cannot|can't|lacks?|no|without|missing)\b[^\n]{0,60}\b(?:workflows?|permissions?)\b|\bno [\x60]?workflows[\x60]? permission\b`)
// appPermissionRE preserves the park for App permissions that have no
// specific capability kind in the blocker ledger.
appPermissionRE = regexp.MustCompile(`(?i)\b(?:app(?: token)?|installation|github app)\b[^\n]{0,80}\b(?:cannot|can't|lacks?|missing|without|no)\b[^\n]{0,60}\bpermissions?\b`)
duplicateOfRE = regexp.MustCompile(`(?i)\bduplicate of #(\d+)`)
blockedOnPRRE = regexp.MustCompile(`(?i)\b(review backlog|blocked on (?:its|their|the) PR)\b`)
)
Expand Down Expand Up @@ -322,10 +324,16 @@ func HivePolicyChange(in Input) bool {
}

// CapabilityGap reports a needs-human whose blocker is a missing GitHub App
// capability rather than an open question.
// capability rather than an open question. Shared ledger inference handles
// known capability kinds; a generic App-permission guard keeps other missing
// permissions parked. Human-only blockers are handled by the ledger.
func CapabilityGap(in Input) bool {
return capabilityGapRE.MatchString(in.headline()) ||
in.Kind == KindIssue && capabilityGapRE.MatchString(firstLines(in.Body, 12))
isCapability := func(text string) bool {
k, ok := blocker.Infer(text)
return ok && k.IsCapability() || appPermissionRE.MatchString(text)
}
return isCapability(in.headline()) ||
in.Kind == KindIssue && isCapability(firstLines(in.Body, 12))
}

// OwnerOnly reports a secrets / PAT / org-permission item.
Expand Down
46 changes: 46 additions & 0 deletions src/pkg/delegatedecision/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,52 @@ func sameKinds(a, b []ActionKind) bool {
return true
}

func TestCapabilityGapSharedInference(t *testing.T) {
for _, report := range []string{
"The App cannot push changes to workflow files.",
"The App cannot push to the upstream repository.",
"The App cannot update the protected branch.",
"The App cannot set the repository secret.",
"The GitHub App lacks the `issues: write` permission.",
"App lacks the `administration` permission to edit rulesets",
"The installation lacks the required permissions; needs a human.",
"The App token is missing the `checks: write` permission.",
"The installation has no permission to manage checks.",
"The App is without the required permission.",
"The App cannot obtain the required permission.",
"The App can't obtain the required permission.",
} {
t.Run(report, func(t *testing.T) {
for _, in := range []Input{
{Kind: KindIssue, Title: report},
{Kind: KindIssue, Question: report},
{Kind: KindIssue, Reasons: []string{report}},
{Kind: KindIssue, Body: report},
{Kind: KindIssue, Body: strings.Repeat("context\n", 11) + report},
} {
d := Run(in)
if !CapabilityGap(in) || d.Rule != RuleCapabilityGap || d.Verdict != VerdictRecommendOnly || !d.KeepsPark || !sameKinds(kinds(d), []ActionKind{ActionRecommendOnly}) {
t.Fatalf("capability report must keep the park: input=%+v decision=%+v", in, d)
}
}
})
}
for _, in := range []Input{
{Kind: KindIssue, Title: "The contributor must sign the CLA."},
{Kind: KindIssue, Title: "Which workflow retry strategy should we use?"},
{Kind: KindIssue, Title: "Which permissions should the GitHub App request?"},
{Kind: KindIssue, Title: "The GitHub App has the required permissions."},
{Kind: KindIssue, Body: strings.Repeat("context\n", 12) + "The GitHub App lacks the `issues: write` permission."},
{Kind: KindPR, Body: "The GitHub App lacks the `issues: write` permission."},
{Kind: KindIssue, Body: strings.Repeat("context\n", 12) + "The App cannot push to the repository."},
{Kind: KindPR, Body: "The App cannot push to the repository."},
} {
if CapabilityGap(in) {
t.Errorf("unexpected capability gap: %+v", in)
}
}
}

func TestDecideIssueRules(t *testing.T) {
t.Parallel()
cases := []struct {
Expand Down
Loading