Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(review): show a kept rule finding's current text (#21889)

rebelicead3f21234dac
diff --git a/backend/store/review_run.go b/backend/store/review_run.go
index b080d1500e..8196c28643 100644
--- a/backend/store/review_run.go
+++ b/backend/store/review_run.go
@@ -212,8 +212,8 @@ func (s *Store) ClaimAvailableReviewRuns(ctx context.Context, replicaID string)
// status, fenced on the claim's attempt. On DONE it posts the run's results in
// the same transaction. A current root of the same reviewer on the issue (one
// no run has superseded) whose fingerprint a result repeats keeps its thread,
-// state and replies included, and takes the result's anchor; that result is
-// not posted again. Every other current root of the reviewer is marked
+// state and replies included, and takes the result's text and anchor; that
+// result is not posted again. Every other current root of the reviewer is marked
// superseded and, if OPEN, resolved; the remaining results are inserted as
// OPEN roots with no creator, carrying the run's attempt; and a
// ReviewRunCompletion event records the counts. A FAILED run leaves the
@@ -314,27 +314,33 @@ func (s *Store) CompleteReviewRun(ctx context.Context, claimed *ClaimedReviewRun
return false, errors.Wrapf(err, "failed to resolve reopened review results")
}
- // A kept root moves to its statement in the SQL this run reviewed:
- // equal fingerprints mean equal statement text, and an anchor left
- // on an earlier sheet can lose its place in the current one.
+ // A kept root takes the text and the anchor of the result that
+ // repeats it. The fingerprint leaves the text out, so the text can
+ // differ: omni rewords a finding, or names what it found, such as an
+ // object's kind, differently. Equal fingerprints mean equal statement
+ // text, and an anchor left on an earlier sheet can lose its place in
+ // the current one. A result on the whole change has no anchor and
+ // leaves the kept one alone.
q = qb.Q().Space(`
UPDATE issue_comment kept
- SET payload = jsonb_set(kept.payload, '{statementAnchor}', r.payload->'statementAnchor')
+ SET payload = kept.payload || jsonb_strip_nulls(jsonb_build_object(
+ 'comment', r.payload->'comment',
+ 'statementAnchor', r.payload->'statementAnchor'))
FROM unnest(?::JSONB[]) AS r(payload)
WHERE kept.project = ? AND kept.issue_id = ?
AND kept.parent_id IS NULL
AND kept.payload->'reviewMetadata'->>'runType' = ?
AND kept.payload->'reviewMetadata'->'superseded' IS NULL
AND kept.payload->'reviewMetadata'->>'fingerprint' = r.payload->'reviewMetadata'->>'fingerprint'
- AND r.payload ?? 'statementAnchor'
- AND kept.payload->'statementAnchor' IS DISTINCT FROM r.payload->'statementAnchor'
+ AND ((r.payload ?? 'comment' AND kept.payload->'comment' IS DISTINCT FROM r.payload->'comment')
+ OR (r.payload ?? 'statementAnchor' AND kept.payload->'statementAnchor' IS DISTINCT FROM r.payload->'statementAnchor'))
`, resultPayloads, claimed.ProjectID, claimed.IssueUID, claimed.Type)
query, args, err = q.ToSQL()
if err != nil {
return false, errors.Wrapf(err, "failed to build sql")
}
if _, err := tx.ExecContext(ctx, query, args...); err != nil {
- return false, errors.Wrapf(err, "failed to move kept review results")
+ return false, errors.Wrapf(err, "failed to update kept review results")
}
}
diff --git a/backend/store/review_run_lock_order_test.go b/backend/store/review_run_lock_order_test.go
index b814c93f5a..352ed99ca3 100644
--- a/backend/store/review_run_lock_order_test.go
+++ b/backend/store/review_run_lock_order_test.go
@@ -234,7 +234,7 @@ func TestCompleteReviewRunOverlappingAttempts(t *testing.T) {
got, _ := listSupersession(t, fixture, "default")
require.Equal(t, []supersession{
{Comment: "x", ThreadState: "RESOLVED", Superseded: true},
- {Comment: "y", ThreadState: "OPEN"},
+ {Comment: "y moved", ThreadState: "OPEN"},
}, got)
- require.Equal(t, reviewResultSheet+"/4", reviewResultAnchors(t, fixture, "default")["y"])
+ require.Equal(t, reviewResultSheet+"/4", reviewResultAnchors(t, fixture, "default")["y moved"])
}
diff --git a/backend/store/review_run_results_test.go b/backend/store/review_run_results_test.go
index 823805f533..17b40032d0 100644
--- a/backend/store/review_run_results_test.go
+++ b/backend/store/review_run_results_test.go
@@ -315,21 +315,21 @@ func TestCompleteReviewRunKeepsResultsReportedAgain(t *testing.T) {
got, updatedAfter := listSupersession(t, fixture, "default")
require.Equal(t, []supersession{
{Comment: "ai", ThreadState: "OPEN"},
- {Comment: "open", ThreadState: "OPEN"},
- {Comment: "accepted", ThreadState: "RESOLVED"},
+ {Comment: "open again", ThreadState: "OPEN"},
+ {Comment: "accepted again", ThreadState: "RESOLVED"},
{Comment: "fixed", ThreadState: "RESOLVED", Superseded: true},
{Comment: "no fingerprint", ThreadState: "RESOLVED", Superseded: true},
- {Comment: "whole", ThreadState: "OPEN"},
+ {Comment: "whole again", ThreadState: "OPEN"},
{Comment: "new", ThreadState: "OPEN"},
{Comment: "no fingerprint again", ThreadState: "OPEN"},
- }, got)
- for _, comment := range []string{"open", "accepted", "whole"} {
- require.Equal(t, updatedBefore[comment], updatedAfter[comment], "keeping %q is no content edit", comment)
+ }, got, "a kept result takes the text of the result that repeats it")
+ for before, after := range map[string]string{"open": "open again", "accepted": "accepted again", "whole": "whole again"} {
+ require.Equal(t, updatedBefore[before], updatedAfter[after], "keeping %q is no person's edit", before)
}
anchors := reviewResultAnchors(t, fixture, "default")
- require.Equal(t, movedSheet+"/3", anchors["open"], "a kept result moves to the statement the run found")
- require.Equal(t, reviewResultSheet+"/1", anchors["accepted"])
- require.Equal(t, "", anchors["whole"])
+ require.Equal(t, movedSheet+"/3", anchors["open again"], "a kept result moves to the statement the run found")
+ require.Equal(t, reviewResultSheet+"/1", anchors["accepted again"])
+ require.Equal(t, "", anchors["whole again"])
require.Equal(t, []reviewRunCompletion{
{RunType: storepb.ReviewRun_AI, Posted: 1},
{RunType: storepb.ReviewRun_RULE, Posted: 5},
@@ -345,22 +345,24 @@ func TestCompleteReviewRunKeepsResultsReportedAgain(t *testing.T) {
final, _ := listSupersession(t, fixture, "default")
require.Equal(t, []supersession{
{Comment: "ai", ThreadState: "OPEN"},
- {Comment: "open", ThreadState: "RESOLVED", Superseded: true},
- {Comment: "accepted", ThreadState: "RESOLVED", Superseded: true},
+ {Comment: "open again", ThreadState: "RESOLVED", Superseded: true},
+ {Comment: "accepted again", ThreadState: "RESOLVED", Superseded: true},
{Comment: "fixed", ThreadState: "RESOLVED", Superseded: true},
{Comment: "no fingerprint", ThreadState: "RESOLVED", Superseded: true},
- {Comment: "whole", ThreadState: "RESOLVED", Superseded: true},
- {Comment: "new", ThreadState: "OPEN"},
+ {Comment: "whole again", ThreadState: "RESOLVED", Superseded: true},
+ {Comment: "new again", ThreadState: "OPEN"},
{Comment: "no fingerprint again", ThreadState: "RESOLVED", Superseded: true},
{Comment: "fixed again", ThreadState: "OPEN"},
}, final)
require.Equal(t, map[string]int64{
- "ai": 0, "open": 0, "accepted": 0, "fixed": 0, "no fingerprint": 0, "whole": 0,
- "new": 1, "no fingerprint again": 1, "fixed again": 2,
+ "ai": 0, "open again": 0, "accepted again": 0, "fixed": 0, "no fingerprint": 0, "whole again": 0,
+ "new again": 1, "no fingerprint again": 1, "fixed again": 2,
}, reviewResultAttempts(t, fixture, "default"), "a kept result keeps the attempt that posted it")
completions := listReviewRunCompletions(t, fixture, "default")
require.Equal(t, reviewRunCompletion{RunType: storepb.ReviewRun_RULE, Attempt: 2, Posted: 1, Kept: 1, Superseded: 4}, completions[len(completions)-1])
require.Equal(t, []reviewRunCompletion{{RunType: storepb.ReviewRun_RULE, Posted: 1}}, listReviewRunCompletions(t, fixture, "other"))
+ other, _ = listSupersession(t, fixture, "other")
+ require.Equal(t, []supersession{{Comment: "other", ThreadState: "OPEN"}}, other, "keeping the colliding fingerprint leaves the other project's text")
// Fingerprints are unique within a run.
ctx, s := fixture.ctx, fixture.store