Skip to content

Commit a82d922

Browse files
committed
fix(review): gate merges on attached verification
1 parent d103c0c commit a82d922

29 files changed

Lines changed: 2314 additions & 247 deletions

‎src/clawsweeper-label-policy.ts‎

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
HUMAN_REVIEW_LABEL,
1414
MANUAL_ONLY_LABEL,
1515
} from "./repair/exact-review-guard-labels.js";
16+
import type { AttachedLiveVerification } from "./live-proof/verification.js";
1617
import type {
1718
FeatureShowcase,
1819
FeatureShowcaseStatus,
@@ -33,6 +34,7 @@ interface LabelPolicyDependencies {
3334
frontMatterValue: (markdown: string, key: string) => string | undefined;
3435
isAutomationReportAuthor: (author: string | undefined) => boolean;
3536
mergeRiskOptionsFromReport: (markdown: string) => MergeRiskOption[];
37+
reportAttachedLiveVerification: (markdown: string) => AttachedLiveVerification;
3638
reportOverallCorrectness: (markdown: string) => OverallCorrectness;
3739
reportRealBehaviorProof: (markdown: string) => RealBehaviorProof;
3840
reportReviewFindings: (markdown: string) => ReviewFinding[];
@@ -46,6 +48,7 @@ export function createLabelPolicy({
4648
frontMatterValue,
4749
isAutomationReportAuthor,
4850
mergeRiskOptionsFromReport,
51+
reportAttachedLiveVerification,
4952
reportOverallCorrectness,
5053
reportRealBehaviorProof,
5154
reportReviewFindings,
@@ -124,12 +127,18 @@ export function createLabelPolicy({
124127
});
125128
}
126129

127-
function proofNeedsContributorAction(proof: Pick<RealBehaviorProof, "status">): boolean {
130+
function proofIsUnresolved(proof: Pick<RealBehaviorProof, "status">): boolean {
128131
return (
129132
proof.status === "missing" || proof.status === "mock_only" || proof.status === "insufficient"
130133
);
131134
}
132135

136+
function proofNeedsContributorAction(
137+
proof: Pick<RealBehaviorProof, "status" | "needsContributorAction">,
138+
): boolean {
139+
return proofIsUnresolved(proof) && proof.needsContributorAction;
140+
}
141+
133142
function hasBlockingReviewFindings(
134143
findings: readonly Pick<ReviewFinding, "priority">[],
135144
): boolean {
@@ -151,7 +160,7 @@ export function createLabelPolicy({
151160
}
152161

153162
function hasUnresolvedContributorWork(options: {
154-
realBehaviorProof: Pick<RealBehaviorProof, "status">;
163+
realBehaviorProof: Pick<RealBehaviorProof, "status" | "needsContributorAction">;
155164
reviewFindings: readonly Pick<ReviewFinding, "priority">[];
156165
securityReview: Pick<SecurityReview, "status">;
157166
mergeRiskOptions: readonly Pick<MergeRiskOption, "category" | "recommended">[];
@@ -166,7 +175,7 @@ export function createLabelPolicy({
166175
}
167176

168177
function isReadyForMaintainerLook(options: {
169-
realBehaviorProof: Pick<RealBehaviorProof, "status">;
178+
realBehaviorProof: Pick<RealBehaviorProof, "status" | "needsContributorAction">;
170179
reviewFindings: readonly Pick<ReviewFinding, "priority">[];
171180
securityReview: Pick<SecurityReview, "status">;
172181
mergeRiskOptions: readonly Pick<MergeRiskOption, "category" | "recommended">[];
@@ -183,7 +192,7 @@ export function createLabelPolicy({
183192
}
184193

185194
function prStatusLabelKind(options: {
186-
realBehaviorProof: Pick<RealBehaviorProof, "status">;
195+
realBehaviorProof: Pick<RealBehaviorProof, "status" | "needsContributorAction">;
187196
reviewFindings: readonly Pick<ReviewFinding, "priority">[];
188197
securityReview: Pick<SecurityReview, "status">;
189198
mergeRiskOptions: readonly Pick<MergeRiskOption, "category" | "recommended">[];
@@ -195,11 +204,12 @@ export function createLabelPolicy({
195204
}): PrStatusLabelKind | null {
196205
const unresolvedWork = hasUnresolvedContributorWork(options);
197206
if (options.hasRepairLoopPauseLabel) return null;
198-
if (options.hasAutomergeLabel) return "automerge_armed";
199207
if (options.hasRecentReReviewRequest) return "re_review_loop";
200208
if (options.hasRecentAuthorActivity && unresolvedWork) return "actively_grinding";
201209
if (proofNeedsContributorAction(options.realBehaviorProof)) return "needs_proof";
210+
if (proofIsUnresolved(options.realBehaviorProof)) return "needs_maintainer_proof_decision";
202211
if (unresolvedWork) return "waiting_on_author";
212+
if (options.hasAutomergeLabel) return "automerge_armed";
203213
if (isReadyForMaintainerLook(options)) return "ready_for_maintainer_look";
204214
return null;
205215
}
@@ -298,8 +308,14 @@ export function createLabelPolicy({
298308
currentLabels: readonly string[],
299309
): PrStatusLabelKind | null {
300310
if (frontMatterValue(markdown, "type") !== "pull_request") return null;
311+
const proof = reportRealBehaviorProof(markdown);
312+
const attached = reportAttachedLiveVerification(markdown);
313+
const statusProof =
314+
attached.status === "failed" && attached.result.failure?.phase === "execution"
315+
? { status: "insufficient" as const, needsContributorAction: false }
316+
: proof;
301317
return prStatusLabelKind({
302-
realBehaviorProof: reportRealBehaviorProof(markdown),
318+
realBehaviorProof: statusProof,
303319
reviewFindings: reportReviewFindings(markdown),
304320
securityReview: reportSecurityReview(markdown),
305321
mergeRiskOptions: mergeRiskOptionsFromReport(markdown),
@@ -323,6 +339,7 @@ export function createLabelPolicy({
323339
isPullRequest?: boolean;
324340
nextSteps?: readonly string[];
325341
proofStatus?: string;
342+
needsContributorAction?: boolean;
326343
findingPriorities?: readonly number[];
327344
securityStatus?: string;
328345
mergeRiskOptions?: readonly Pick<MergeRiskOption, "category" | "recommended">[];
@@ -351,6 +368,9 @@ export function createLabelPolicy({
351368
status: REAL_BEHAVIOR_PROOF_STATUSES.has(options.proofStatus as RealBehaviorProofStatus)
352369
? (options.proofStatus as RealBehaviorProofStatus)
353370
: "not_applicable",
371+
needsContributorAction:
372+
options.needsContributorAction ??
373+
["missing", "mock_only", "insufficient"].includes(options.proofStatus ?? ""),
354374
},
355375
reviewFindings: (options.findingPriorities ?? [])
356376
.filter((priority): priority is 0 | 1 | 2 | 3 => [0, 1, 2, 3].includes(priority))

‎src/clawsweeper-orchestration-foundation.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export function createReportOrchestrationFoundation(
4545
publicReviewTextDiffers,
4646
publicTableCell,
4747
repoUrlFor,
48+
reportAttachedLiveVerification,
4849
reportRealBehaviorProof,
4950
reportSecurityReview,
5051
reviewSectionValue,
@@ -460,6 +461,9 @@ export function createReportOrchestrationFoundation(
460461
} = labelSynchronization;
461462

462463
function realBehaviorProofBlocksMerge(markdown: string): boolean {
464+
const attached = reportAttachedLiveVerification(markdown);
465+
if (attached.status === "failed" || attached.status === "malformed") return true;
466+
if (attached.status === "passed") return false;
463467
if (frontMatterValue(markdown, "review_status") === "failed") return false;
464468
if (frontMatterStringArray(markdown, "labels").includes(PROOF_OVERRIDE_LABEL)) return false;
465469
if (isDocsOnlyPullRequestReport(markdown)) return false;

‎src/clawsweeper-report-orchestration-dependencies.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import type {
3939
TriagePriority,
4040
VisionFitStatus,
4141
} from "./clawsweeper-types.js";
42+
import type { AttachedLiveVerification } from "./live-proof/verification.js";
4243
import { type RepositoryProfile } from "./repository-profiles.js";
4344
import { type ReviewStructuralPullState } from "./review-structural-cache.js";
4445

@@ -346,6 +347,7 @@ export interface CreateReportOrchestrationDependencies {
346347
reportOverallCorrectness: (markdown: string) => OverallCorrectness;
347348
reportPrRating: (markdown: string) => PrRating;
348349
reportRealBehaviorProof: (markdown: string) => RealBehaviorProof;
350+
reportAttachedLiveVerification: (markdown: string) => AttachedLiveVerification;
349351
reportReviewFindings: (markdown: string) => ReviewFinding[];
350352
reportRootCauseCluster: (markdown: string) => RootCauseClusterAssessment;
351353
reportSecurityReview: (markdown: string) => SecurityReview;

‎src/clawsweeper-report-orchestration.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export function createReportOrchestration(dependencies: CreateReportOrchestratio
112112
replaceFrontMatterValue,
113113
repoRelativePath,
114114
reportAgentsPolicyStatus,
115+
reportAttachedLiveVerification,
115116
reportEvidence,
116117
reportLikelyOwners,
117118
reportLiveProofRecordingBlock,
@@ -299,6 +300,7 @@ export function createReportOrchestration(dependencies: CreateReportOrchestratio
299300
replaceFrontMatterValue,
300301
repoRelativePath,
301302
reportAgentsPolicyStatus,
303+
reportAttachedLiveVerification,
302304
reportEvidence,
303305
reportLikelyOwners,
304306
reportLiveProofRecordingBlock,

‎src/clawsweeper-report-parser.ts‎

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
IMPLEMENTATION_COMPLEXITIES,
1313
IMPACT_LABEL_NAMES,
1414
LIVE_PROOF_RECORDING_MARKER,
15-
LIVE_VERIFICATION_MARKER,
1615
MANTIS_RECOMMENDATION_SCENARIOS,
1716
MANTIS_RECOMMENDATION_STATUSES,
1817
MATURITY_LABEL_NAMES,
@@ -29,8 +28,9 @@ import {
2928
VISION_FIT_STATUSES,
3029
} from "./clawsweeper-policy.js";
3130
import {
32-
decodeLiveVerificationReportPayload,
31+
parseAttachedLiveVerification,
3332
renderLiveVerificationCommentBlock,
33+
type AttachedLiveVerification,
3434
} from "./live-proof/verification.js";
3535
import type {
3636
AgentsPolicyStatus,
@@ -536,6 +536,39 @@ export function createReportParser({
536536
}
537537

538538
function reportRealBehaviorProof(markdown: string): RealBehaviorProof {
539+
const attached = reportAttachedLiveVerification(markdown);
540+
if (attached.status === "passed") {
541+
return {
542+
status: "sufficient",
543+
summary: `ClawSweeper live verification passed on the reviewed ${attached.result.surface} surface.`,
544+
evidenceKind: attached.result.surface === "terminal" ? "terminal" : "live_output",
545+
needsContributorAction: false,
546+
};
547+
}
548+
if (attached.status === "failed") {
549+
if (attached.result.failure?.phase === "execution") {
550+
return recordedRealBehaviorProof(markdown);
551+
}
552+
return {
553+
status: "insufficient",
554+
summary: `ClawSweeper live verification failed on the reviewed ${attached.result.surface} surface.`,
555+
evidenceKind: attached.result.surface === "terminal" ? "terminal" : "live_output",
556+
needsContributorAction: isExternalPullRequestReport(markdown),
557+
};
558+
}
559+
if (attached.status === "malformed") {
560+
return {
561+
status: "missing",
562+
summary:
563+
"The attached ClawSweeper live verification result is malformed or does not match this pull request review.",
564+
evidenceKind: "none",
565+
needsContributorAction: isExternalPullRequestReport(markdown),
566+
};
567+
}
568+
return recordedRealBehaviorProof(markdown);
569+
}
570+
571+
function recordedRealBehaviorProof(markdown: string): RealBehaviorProof {
539572
const defaultProof = defaultRealBehaviorProof(markdown);
540573
if (defaultProof.status === "override" || isDocsOnlyPullRequestReport(markdown)) {
541574
return defaultProof;
@@ -652,7 +685,7 @@ export function createReportParser({
652685

653686
function reportLiveProofRecordingBlock(markdown: string): string {
654687
const section = reviewSectionValue(markdown, "liveProof");
655-
const verificationBlock = reportLiveVerificationBlock(section);
688+
const verificationBlock = reportLiveVerificationBlock(markdown);
656689
const markerIndex = section.lastIndexOf(LIVE_PROOF_RECORDING_MARKER);
657690
if (markerIndex < 0) return verificationBlock;
658691
const lines = section
@@ -678,28 +711,35 @@ export function createReportParser({
678711
return [verificationBlock, lines.join("\n")].filter(Boolean).join("\n\n");
679712
}
680713

681-
function reportLiveVerificationBlock(section: string): string {
682-
const markerIndex = section.lastIndexOf(`\n${LIVE_VERIFICATION_MARKER}\n`);
683-
if (markerIndex < 0) return "";
684-
const start = markerIndex + LIVE_VERIFICATION_MARKER.length + 2;
685-
const tail = section.slice(start);
686-
const resultLine = tail.split("\n", 1)[0] ?? "";
687-
const match = /^Result: ([A-Za-z0-9_-]+)$/.exec(resultLine);
688-
if (!match?.[1]) return "";
689-
try {
690-
return renderLiveVerificationCommentBlock(decodeLiveVerificationReportPayload(match[1]));
691-
} catch {
692-
return "";
693-
}
714+
function reportAttachedLiveVerification(markdown: string): AttachedLiveVerification {
715+
return parseAttachedLiveVerification(
716+
reviewSectionValue(markdown, "liveProof"),
717+
{
718+
repository: frontMatterValue(markdown, "repository"),
719+
number: frontMatterValue(markdown, "number"),
720+
type: frontMatterValue(markdown, "type"),
721+
pullHeadSha: frontMatterValue(markdown, "pull_head_sha"),
722+
},
723+
reportLiveProofPlan(markdown),
724+
);
725+
}
726+
727+
function reportLiveVerificationBlock(markdown: string): string {
728+
const attached = reportAttachedLiveVerification(markdown);
729+
return attached.status === "passed" || attached.status === "failed"
730+
? renderLiveVerificationCommentBlock(attached.result)
731+
: "";
694732
}
695733

696734
function reportPrRating(markdown: string): PrRating {
697735
const section = reviewSectionValue(markdown, "prRating");
698736
const proof = reportRealBehaviorProof(markdown);
737+
const attached = reportAttachedLiveVerification(markdown);
699738
const proofTierField = frontMatterField(markdown, "pr_rating_proof");
700739
const patchTierField = frontMatterField(markdown, "pr_rating_patch");
701740
const overallTierField = frontMatterField(markdown, "pr_rating_overall");
702741
if (
742+
attached.status !== "absent" ||
703743
[proofTierField, patchTierField, overallTierField].some(
704744
(field) =>
705745
field.status === "ambiguous" ||
@@ -907,6 +947,7 @@ export function createReportParser({
907947
labelJustificationsFromReport,
908948
reportReviewFindings,
909949
reportSecurityReview,
950+
reportAttachedLiveVerification,
910951
reportRealBehaviorProof,
911952
reportTelegramVisibleProof,
912953
reportLiveProofPlan,

‎src/clawsweeper-report-rendering-dependencies.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import type {
2727
SecurityReview,
2828
TriagePriority,
2929
} from "./clawsweeper-types.js";
30+
import type { AttachedLiveVerification } from "./live-proof/verification.js";
3031
import { type PrSurfaceFile } from "./pr-surface-stats.js";
3132
import { type ReviewStructuralPullState } from "./review-structural-cache.js";
3233

@@ -171,6 +172,7 @@ export interface CreateReportRenderingDependencies {
171172
reportOverallCorrectness: (markdown: string) => OverallCorrectness;
172173
reportPrRating: (markdown: string) => PrRating;
173174
reportRealBehaviorProof: (markdown: string) => RealBehaviorProof;
175+
reportAttachedLiveVerification: (markdown: string) => AttachedLiveVerification;
174176
reportReviewFindings: (markdown: string) => ReviewFinding[];
175177
reportRootCauseCluster: (markdown: string) => RootCauseClusterAssessment;
176178
reportSecurityReview: (markdown: string) => SecurityReview;

‎src/clawsweeper-review-comment-automation.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export function createReviewCommentAutomation(
1515
configSurfaceReviewRequired,
1616
dataModelSurfaceReviewRequired,
1717
realBehaviorProofBlocksMerge,
18+
reportAttachedLiveVerification,
1819
pullHeadShaFromReport,
1920
markerAttributeValue,
2021
} = dependencies;
@@ -68,6 +69,7 @@ export function createReviewCommentAutomation(
6869
const reviewLeaseOwner = frontMatterValue(markdown, "review_lease_owner") ?? "unknown";
6970
const reviewLeaseCommentId = frontMatterValue(markdown, "review_lease_comment_id") ?? "unknown";
7071
const sourceRevision = frontMatterValue(markdown, "item_source_revision") ?? "unknown";
72+
const liveVerification = reportAttachedLiveVerification(markdown).status;
7173
const baseAttrs = [
7274
`item=${markerAttributeValue(number)}`,
7375
`sha=${markerAttributeValue(headSha)}`,
@@ -77,6 +79,7 @@ export function createReviewCommentAutomation(
7779
`lease_owner=${markerAttributeValue(reviewLeaseOwner)}`,
7880
`lease_comment_id=${markerAttributeValue(reviewLeaseCommentId)}`,
7981
`source_revision=${markerAttributeValue(sourceRevision)}`,
82+
`live_verification=${liveVerification}`,
8083
].join(" ");
8184
const securityNeedsAttention = reportSecurityReview(markdown).status === "needs_attention";
8285
const humanReviewMarkers = (): string => {

‎src/clawsweeper-review-comment-dependencies.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
ReviewStartStatusCommentResult,
1111
SecurityReview,
1212
} from "./clawsweeper-types.js";
13+
import type { AttachedLiveVerification } from "./live-proof/verification.js";
1314
import { type ReviewHistoryLedger } from "./review-history.js";
1415

1516
export interface ReviewCommentWorkflowDependencies {
@@ -53,6 +54,7 @@ export interface ReviewCommentWorkflowDependencies {
5354
isIssueAdvisoryLabel: ReturnType<typeof createLabelSynchronization>["isIssueAdvisoryLabel"];
5455
removeIssueLabel: ReturnType<typeof createLabelSynchronization>["removeIssueLabel"];
5556
realBehaviorProofBlocksMerge: (markdown: string) => boolean;
57+
reportAttachedLiveVerification: (markdown: string) => AttachedLiveVerification;
5658
normalizedLabelSet: (labels: readonly string[]) => Set<string>;
5759
sectionLineValue: (section: string, label: string) => string | undefined;
5860
linkedPullRequestRefsFromText: (text: string, currentNumber: number) => PullRequestRef[];

0 commit comments

Comments
 (0)