Skip to content

Commit 3ca76a6

Browse files
committed
fix: distinguish PR merge drift in review context
1 parent 9b0b0b3 commit 3ca76a6

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

‎prompts/review-item.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ discussion:
169169
`merge-risk: 🚨 security-boundary`: 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data.
170170
`merge-risk: 🚨 availability`: 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages.
171171
`merge-risk: 🚨 automation`: 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation.
172+
Do not treat a branch being behind the current base as proof that merging the
173+
PR will delete current-base-only files or commits. When GitHub reports the PR as
174+
mergeable or clean and the only concern is stale base drift, describe it as
175+
needing rebase or review refresh in `risks`, `workReason`, or `bestSolution`,
176+
but leave `reviewFindings` and `mergeRiskLabels` focused on defects or risks
177+
that survive the actual three-way merge result. Use deletion/drop wording for
178+
current-base behavior only when a merge result, merge ref, conflict, or concrete
179+
patch evidence shows that the merged PR would remove or regress it.
172180
When merge risk is present, explain it in `risks` in maintainer-facing language
173181
and make `bestSolution` the best end state. Fill `mergeRiskOptions` with 1-3
174182
risk-specific maintainer options. Do not use a fixed menu. Each option needs a

‎src/clawsweeper.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2892,6 +2892,7 @@ function compactPullRequest(value: unknown): unknown {
28922892
mergedAt: pull.merged_at,
28932893
mergeCommitSha: pull.merge_commit_sha,
28942894
mergeable: pull.mergeable,
2895+
mergeableState: pull.mergeable_state,
28952896
author: login(pull.user),
28962897
head: {
28972898
ref: head.ref,
@@ -2910,6 +2911,10 @@ function compactPullRequest(value: unknown): unknown {
29102911
};
29112912
}
29122913

2914+
export function compactPullRequestForTest(value: unknown): unknown {
2915+
return compactPullRequest(value);
2916+
}
2917+
29132918
interface ClosingPullRequestReference {
29142919
repo: string;
29152920
number: number;

‎test/clawsweeper.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
closingPullRequestReferenceTarget,
2929
compactMappedSlice,
3030
compactMappedWindow,
31+
compactPullRequestForTest,
3132
codexEnv,
3233
dashboardClosedAt,
3334
extractLatestClawSweeperReviewForTest,
@@ -867,6 +868,39 @@ test("review prompt includes compact previous review state without raw durable r
867868
assert.doesNotMatch(prompt, /clawsweeper-pr-egg-hatch/);
868869
});
869870

871+
test("review prompt includes merge state and guards clean behind-branch drift", () => {
872+
const compactPullRequest = compactPullRequestForTest({
873+
number: 123,
874+
title: "Sample PR",
875+
html_url: "https://github.com/openclaw/openclaw/pull/123",
876+
state: "open",
877+
draft: false,
878+
merged: false,
879+
mergeable: true,
880+
mergeable_state: "clean",
881+
head: { ref: "feature", sha: "head123" },
882+
base: { ref: "main", sha: "base123" },
883+
user: { login: "contributor" },
884+
additions: 10,
885+
deletions: 2,
886+
changed_files: 1,
887+
});
888+
const context = {
889+
issue: { number: 123, title: "Sample PR" },
890+
comments: [],
891+
timeline: [],
892+
pullRequest: compactPullRequest,
893+
counts: { comments: 0, timeline: 0 },
894+
};
895+
896+
const prompt = reviewPromptForTest(item({ kind: "pull_request", number: 123 }), context, git);
897+
898+
assert.deepEqual((compactPullRequest as { mergeableState?: unknown }).mergeableState, "clean");
899+
assert.match(prompt, /"mergeableState": "clean"/);
900+
assert.match(prompt, /Do not treat a branch being behind the current base as proof/);
901+
assert.match(prompt, /actual three-way merge result/);
902+
});
903+
870904
test("review context ledger records ordered section budgets", () => {
871905
const context = {
872906
issue: { number: 123, title: "Sample PR" },

0 commit comments

Comments
 (0)