Skip to content
Merged
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/security-issue-decision-option-text.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Delegated issue decisions record reporter-authored option text only by option label: when the options come from the body of an issue a non-hive account filed, the owner-attributed `/hive decision go with option N` no longer quotes the reporter's summary, while the "Let hive decide" preview still shows that summary as a quoted excerpt of the issue's words; options from hive-authored text keep their summary (#16937).
19 changes: 19 additions & 0 deletions src/pkg/dashboard/api_repo_item_decide_delegated_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ func TestDelegatedPlanWordingNamesTheOptionOrLeavesTheChoice(t *testing.T) {
t.Errorf("an issue with options must never read as a bare direction: %q", s)
}
}

// A reporter-authored option names itself by label alone in the recorded
// decision, but the preview still shows the owner what they approve: the
// issue's own words, quoted, on one line.
reporter := delegatedecision.Option{Label: "2", Summary: "A ujust\n recipe.", Untrusted: true}
summary, next = delegatedPlanWording(in, delegatedecision.Decision{Verdict: delegatedecision.VerdictApprove, Rule: delegatedecision.RuleRecommendedOption, Option: &reporter})
if want := "Go with option 2 (the issue's words: “A ujust recipe”) — the option #920 recommends — and let the hive build it."; summary != want {
t.Errorf("untrusted approve summary %q, want %q", summary, want)
}
if reporter.Name() != "option 2" {
t.Errorf("untrusted Name() = %q, want the label alone", reporter.Name())
}
if strings.Join(next, "|") != "Hive records option 2 as the decision and removes the needs-decision hold.|An agent claims #920 on the next cycle and builds option 2." {
t.Errorf("untrusted approve consequences %q", next)
}
empty := delegatedecision.Option{Label: "2", Untrusted: true}
if got, _ := delegatedPlanWording(in, delegatedecision.Decision{Verdict: delegatedecision.VerdictApprove, Rule: delegatedecision.RuleRecommendedOption, Option: &empty}); !strings.HasPrefix(got, "Go with option 2 — ") {
t.Errorf("empty untrusted summary must add no quote: %q", got)
}
}

func TestDelegatedDecisionPlanForAnIssueWithOptions(t *testing.T) {
Expand Down
19 changes: 18 additions & 1 deletion src/pkg/dashboard/api_repo_item_decide_delegated_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,23 @@ func (s *Server) planDelegatedDecision(ctx context.Context, repoFull string, num
return plan, nil
}

// delegatedPlanOptionName names the chosen option for the plan sentence.
// A reporter-authored option (Option.Untrusted) names itself by label alone
// in the recorded decision, but the owner still needs to see what they are
// approving: its summary is shown as a quoted, one-line preview of the
// issue's own words, never as hive's description of the option.
func delegatedPlanOptionName(o delegatedecision.Option) string {
name := strings.TrimSuffix(o.Name(), ".")
if !o.Untrusted {
return name
}
s := strings.TrimSuffix(strings.Join(strings.Fields(o.Summary), " "), ".")
if s == "" {
return name
}
return name + " (the issue's words: “" + s + "”)"
}

// delegatedPlanWording is the one decision sentence and the (at most
// two) "then" items for the decision the hive would record. Operator
// feedback on the preview (hivecommons/hive#15332's dialog: "this needs
Expand Down Expand Up @@ -340,7 +357,7 @@ func delegatedPlanWording(in delegatedecision.Input, d delegatedecision.Decision
// The issue offered a choice: the plan names the option, so
// approving never leaves the pick to the claiming agent
// (projectbluefin/utah#920).
return "Go with " + strings.TrimSuffix(d.Option.Name(), ".") + " — the option " + ref + " recommends — and let the hive build it.",
return "Go with " + delegatedPlanOptionName(*d.Option) + " — the option " + ref + " recommends — and let the hive build it.",
[]string{"Hive records option " + d.Option.Label + " as the decision and removes the needs-decision hold.", "An agent claims " + ref + " on the next cycle and builds option " + d.Option.Label + "."}
case d.Verdict == delegatedecision.VerdictApprove && in.Kind == delegatedecision.KindIssue:
// An issue has no commit to approve and nothing to merge
Expand Down
6 changes: 5 additions & 1 deletion src/pkg/delegatedecision/competing_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ const (
type Option struct {
Label string `json:"label"`
Summary string `json:"summary,omitempty"`
// Untrusted marks an option read from an issue body a non-hive account
// wrote: its summary is reporter prose and is never quoted into the
// owner-attributed decision, which names the option by label alone.
Untrusted bool `json:"untrusted,omitempty"`
}

// Name is the option as a decision names it: "option 2: A ujust recipe".
func (o Option) Name() string {
name := "option " + o.Label
if s := strings.TrimSpace(o.Summary); s != "" {
if s := strings.TrimSpace(o.Summary); s != "" && !o.Untrusted {
name += ": " + s
}
return name
Expand Down
18 changes: 13 additions & 5 deletions src/pkg/github/issue_decision_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@ import (
// it names none. Fewer than two options reads as none.
func (c *Client) IssueDecisionOptions(issueBody string, issueAuthor *gh.User, comments []*gh.IssueComment) (options []delegatedecision.Option, recommended string) {
m := c.unparkMenuFor(issueBody, issueAuthor, comments)
// Options read from the body of an issue a non-hive account filed are
// reporter-authored; the delegated decision names them by label only.
bodyUntrusted := !c.isHiveAccount(issueAuthor)
if len(m.options) >= 2 {
for _, l := range m.options {
options = append(options, delegatedecision.Option{Label: l, Summary: m.optionText[l]})
options = append(options, delegatedecision.Option{Label: l, Summary: m.optionText[l], Untrusted: bodyUntrusted && m.optionsFromBody})
}
return options, m.recommended
}
// No lettered options: the newest park text with a numbered option list
// wins, as for letters. The hive's own notices, replies and the
// delegate's verdicts are not park text; a withdrawn ask takes its
// options with it.
source := ""
source, fromBody := "", false
if numberedDecisionOptions(issueBody) != nil {
source = issueBody
source, fromBody = issueBody, true
}
for _, cm := range comments {
if cm == nil || !c.isHiveAccount(cm.GetUser()) {
Expand All @@ -39,18 +42,23 @@ func (c *Client) IssueDecisionOptions(issueBody string, issueAuthor *gh.User, co
body := cm.GetBody()
switch {
case strings.Contains(body, parkWithdrawnMarkerPrefix):
source = ""
source, fromBody = "", false
case strings.Contains(body, unparkNoticeMarker), strings.Contains(body, unparkReplyMarkerPrefix),
strings.Contains(body, unparkAcceptedMarker), strings.Contains(body, parkRecheckMarker),
delegatedecision.IsDelegatedComment(body):
case numberedDecisionOptions(body) != nil:
source = body
source, fromBody = body, false
}
}
if source == "" {
return nil, ""
}
options = numberedDecisionOptions(source)
if fromBody && bodyUntrusted {
for i := range options {
options[i].Untrusted = true
}
}
return options, numberedRecommendedOption(source, options)
}

Expand Down
52 changes: 52 additions & 0 deletions src/pkg/github/issue_decision_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,55 @@ func TestIssueDecisionOptions(t *testing.T) {
t.Errorf("a withdrawn ask kept its options: %+v", opts)
}
}

func TestIssueDecisionOptionsMarkReporterBodyUntrusted(t *testing.T) {
c := menuTestClient()
person := &gh.User{Login: gh.Ptr("someone")}
hive := &gh.User{Login: gh.Ptr("hive[bot]")}

for _, body := range []string{dakotaStyleOptions, utah920Body} {
opts, _ := c.IssueDecisionOptions(body, person, nil)
if len(opts) < 2 {
t.Fatalf("no options read from %q", body)
}
for _, o := range opts {
if !o.Untrusted {
t.Errorf("reporter body option %+v not marked untrusted", o)
}
if name := o.Name(); name != "option "+o.Label {
t.Errorf("Name() = %q, want the label alone", name)
}
}
opts, _ = c.IssueDecisionOptions(body, hive, nil)
for _, o := range opts {
if o.Untrusted {
t.Errorf("hive-authored option %+v marked untrusted", o)
}
}
}

// A hive comment's options are the hive's own text, whoever filed the
// issue — numbered or lettered, and whether or not the comment was read
// with its html_url (provenance is not inferred from optionSource).
for _, park := range []string{utah920Park, dakotaStyleOptions} {
opts, _ := c.IssueDecisionOptions("Ship the debugging tools.", person, []*gh.IssueComment{ghComment("hive[bot]", park)})
if len(opts) < 2 {
t.Fatalf("no options read from hive comment %q", park)
}
for _, o := range opts {
if o.Untrusted {
t.Errorf("hive comment option %+v marked untrusted", o)
}
if o.Summary == "" {
t.Errorf("hive comment option %+v lost its summary", o)
}
}
}

// A hive comment's lettered options replace the reporter's body options
// and are trusted.
opts, _ := c.IssueDecisionOptions(dakotaStyleOptions, person, []*gh.IssueComment{ghComment("hive[bot]", "- **A.** hive a\n- **B.** hive b\n")})
if len(opts) != 2 || opts[0].Summary != "hive a" || opts[0].Untrusted || opts[1].Untrusted {
t.Errorf("hive comment did not replace reporter body options as trusted: %+v", opts)
}
}
8 changes: 7 additions & 1 deletion src/pkg/github/issue_unpark_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ type unparkMenu struct {
// optionSource is the html_url of the hive comment the options came
// from; "" when they came from the issue body.
optionSource string
// optionsFromBody is true when options came from the issue body rather
// than a hive comment. It is the provenance signal, not optionSource:
// a comment read without its html_url still carries hive-authored text.
optionsFromBody bool
// recommended is the option the text recommends, or "" when none is named.
recommended string
// hasRecommendation is true when the issue states a recommendation.
Expand All @@ -61,6 +65,7 @@ type unparkMenu struct {
// marker in its body; it is an owner step when it lists no options.
func unparkMenuFromBody(issueBody string) unparkMenu {
m := unparkMenu{options: unparkOptionLabels(issueBody), optionText: unparkOptionTexts(issueBody)}
m.optionsFromBody = len(m.options) > 0
m.hasRecommendation = unparkMentionsRecommendation(issueBody)
if m.hasRecommendation {
m.recommended = unparkRecommendedOption(issueBody, m.options)
Expand Down Expand Up @@ -129,7 +134,7 @@ func (c *Client) unparkMenuFor(issueBody string, issueAuthor *gh.User, comments
// go with it, so a later park starts from its own text.
ownerStep = false
m.releaseStep = nil
m.options, m.optionText, m.optionSource = nil, nil, ""
m.options, m.optionText, m.optionSource, m.optionsFromBody = nil, nil, "", false
m.hasRecommendation, recommendationSource = false, ""
continue
}
Expand All @@ -155,6 +160,7 @@ func (c *Client) unparkMenuFor(issueBody string, issueAuthor *gh.User, comments
m.options = opts
m.optionText = unparkOptionTexts(body)
m.optionSource = cm.GetHTMLURL()
m.optionsFromBody = false
}
if unparkMentionsRecommendation(body) {
m.hasRecommendation, recommendationSource = true, body
Expand Down
Loading