agent-dealer 1.4.2 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/server/dist/adapters/github.js +66 -3
- package/bundle/server/dist/adapters/github.test.js +90 -0
- package/bundle/server/dist/coordinator/args.js +7 -9
- package/bundle/server/dist/coordinator/args.test.js +5 -2
- package/bundle/server/dist/coordinator/auto-merge.js +17 -6
- package/bundle/server/dist/coordinator/commands.js +18 -2
- package/bundle/server/dist/coordinator/developer-effect.js +46 -5
- package/bundle/server/dist/coordinator/developer-effect.test.js +118 -4
- package/bundle/server/dist/coordinator/muse-spawn.js +1 -0
- package/bundle/server/dist/coordinator/operator-criteria.js +250 -17
- package/bundle/server/dist/coordinator/operator-criteria.test.js +177 -4
- package/bundle/server/dist/coordinator/operator-verification.integration.test.js +208 -0
- package/bundle/server/dist/coordinator/projection.js +5 -1
- package/bundle/server/dist/coordinator/prompts.js +77 -4
- package/bundle/server/dist/coordinator/prompts.test.js +22 -4
- package/bundle/server/dist/coordinator/reviewer-browser-probe.js +2 -3
- package/bundle/server/dist/coordinator/reviewer-effect.js +64 -45
- package/bundle/server/dist/coordinator/reviewer-effect.test.js +63 -10
- package/bundle/server/dist/coordinator/reviewer-pr-evidence.test.js +245 -0
- package/bundle/server/dist/coordinator/reviewer-result.js +4 -3
- package/bundle/server/dist/coordinator/reviewer-result.test.js +6 -0
- package/bundle/server/dist/coordinator/routing.js +3 -0
- package/bundle/server/dist/coordinator/routing.test.js +19 -0
- package/bundle/server/dist/coordinator/spawn.js +25 -5
- package/bundle/server/dist/coordinator/spawn.test.js +84 -0
- package/bundle/server/dist/docs-api-reference.test.js +89 -0
- package/bundle/server/dist/runners/muse-config-core.js +33 -9
- package/bundle/server/dist/runners/muse-config.test.js +13 -8
- package/bundle/server/dist/runners/spawn-cli.js +12 -4
- package/bundle/server/dist/runners/spawn-cli.test.js +19 -0
- package/bundle/server/package.json +2 -2
- package/bundle/shared/package.json +1 -1
- package/package.json +1 -1
|
@@ -26,13 +26,13 @@ import os from "node:os";
|
|
|
26
26
|
import path from "node:path";
|
|
27
27
|
import { parseProfileSnapshot, roleCeiling } from "@agent-dealer/shared";
|
|
28
28
|
import { getTaskSnapshot } from "./commands.js";
|
|
29
|
-
import {
|
|
29
|
+
import { listOperatorAttestations, operatorCriteriaForSnapshot } from "./operator-criteria.js";
|
|
30
30
|
import { buildReviewerPrompt, formatDiffForPrompt, TOTAL_DIFF_LIMIT } from "./prompts.js";
|
|
31
31
|
import { cleanupStagedVisualArtifacts, resolveReviewerVisualEvidence, toReviewerVisualEvidenceInput, } from "./reviewer-visual-evidence.js";
|
|
32
32
|
import { readLatestVisualQa } from "./visual-qa.js";
|
|
33
33
|
import { guidanceForNextSession } from "./guidance.js";
|
|
34
34
|
import { realReviewerSpawn, reviewerSessionLogPath } from "./spawn.js";
|
|
35
|
-
import { parseReviewerResult, normalizeReviewerResult,
|
|
35
|
+
import { parseReviewerResult, normalizeReviewerResult, ReviewerResult as ReviewerResultSchema, } from "./reviewer-result.js";
|
|
36
36
|
import { createRoleWorktree, safeRemoveWorktree, isWorktreeClean, listChangedFiles, mergeBase, fetchRef, diffShas, } from "../adapters/git-worktree.js";
|
|
37
37
|
import { ensureIssueRepoCheckout, roleWorktreePathForResolution, resolveCheckoutBaseBranch, } from "../adapters/managed-repo.js";
|
|
38
38
|
import { prepareWorkerDeckConnection, releaseWorkerDeckConnection } from "../adapters/agent-deck-bind.js";
|
|
@@ -121,46 +121,24 @@ async function bestEffortRemove(repo, worktreePath) {
|
|
|
121
121
|
// leave it for crash-recovery inspection — cleanup is a courtesy, not part of the contract
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
|
-
/** Inject a stable blocking incomplete-review finding listing omitted paths (NOT-150). */
|
|
125
|
-
function withIncompleteReviewFinding(result, omittedPaths) {
|
|
126
|
-
if (result.findings.some((f) => f.fingerprint === INCOMPLETE_REVIEW_FINGERPRINT)) {
|
|
127
|
-
const { productScopeQuestion: _drop, ...rest } = result;
|
|
128
|
-
return { ...rest, verdict: "changes_requested" };
|
|
129
|
-
}
|
|
130
|
-
const paths = omittedPaths.length > 0 ? omittedPaths.join(", ") : "(unlisted omitted files)";
|
|
131
|
-
const { productScopeQuestion: _drop, ...rest } = result;
|
|
132
|
-
return {
|
|
133
|
-
...rest,
|
|
134
|
-
verdict: "changes_requested",
|
|
135
|
-
findings: [
|
|
136
|
-
...result.findings,
|
|
137
|
-
{
|
|
138
|
-
fingerprint: INCOMPLETE_REVIEW_FINGERPRINT,
|
|
139
|
-
severity: "blocking",
|
|
140
|
-
title: "Diff truncated — incomplete review",
|
|
141
|
-
rationale: `Reviewer prompt omitted path(s): ${paths}. Cannot fully certify acceptance criteria without them; shrink the change set or split the PR so the next review sees the full AC-critical surface.`,
|
|
142
|
-
},
|
|
143
|
-
],
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
124
|
/**
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* the incomplete-review finding listing omitted paths (in addition to any other blocking).
|
|
125
|
+
* NOT-630 truncation policy: shippable approved stays approved; a reviewer's own blocking
|
|
126
|
+
* findings take the normal repair path; every other incomplete review goes to the operator.
|
|
150
127
|
*/
|
|
151
128
|
function applyTruncationVerdictPolicy(result, omittedPaths) {
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (normalized.verdict === "escalated" && hasProductQ) {
|
|
156
|
-
return normalized;
|
|
129
|
+
const hasBlocking = result.findings.some((f) => f.severity === "blocking");
|
|
130
|
+
if (result.verdict === "approved" && !hasBlocking) {
|
|
131
|
+
return { result };
|
|
157
132
|
}
|
|
158
|
-
if (
|
|
159
|
-
|
|
133
|
+
if (hasBlocking) {
|
|
134
|
+
const { productScopeQuestion: _drop, ...rest } = result;
|
|
135
|
+
return { result: { ...rest, verdict: "changes_requested" } };
|
|
160
136
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
137
|
+
const paths = omittedPaths.length > 0 ? omittedPaths.join(", ") : "(unlisted omitted files)";
|
|
138
|
+
return {
|
|
139
|
+
result,
|
|
140
|
+
finalReviewReason: `Diff exceeds the reviewer limit (${TOTAL_DIFF_LIMIT.toLocaleString("en-US")} characters); not reviewed: ${paths}`,
|
|
141
|
+
};
|
|
164
142
|
}
|
|
165
143
|
function readImplementationConclusion(issueId) {
|
|
166
144
|
const artifact = latestIssueArtifact(issueId, "implementation_conclusion");
|
|
@@ -187,6 +165,21 @@ function readChecksSummary(issueId) {
|
|
|
187
165
|
return null;
|
|
188
166
|
}
|
|
189
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* NOT-575: the PR's live body for the reviewer prompt. Null without a PR
|
|
170
|
+
* number, without the adapter read, or on any lookup failure — every one of
|
|
171
|
+
* those renders no section rather than failing the review.
|
|
172
|
+
*/
|
|
173
|
+
export async function readPrBodyForReview(github, cwd, prNumber) {
|
|
174
|
+
if (prNumber == null || !github.prBody)
|
|
175
|
+
return null;
|
|
176
|
+
try {
|
|
177
|
+
return await github.prBody({ cwd, number: prNumber });
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
190
183
|
/**
|
|
191
184
|
* Unique per queued reviewer work item — embedded in the published review body purely
|
|
192
185
|
* as a human-readable audit trail back to the exact work item that produced it.
|
|
@@ -271,6 +264,8 @@ export async function runReviewerEffect(ctx, deps = defaultDeps) {
|
|
|
271
264
|
return { kind: "session_failed" };
|
|
272
265
|
let worktreePath;
|
|
273
266
|
let result;
|
|
267
|
+
let truncationFinalReviewReason;
|
|
268
|
+
let truncationOmittedPaths;
|
|
274
269
|
let workerAuthority = null;
|
|
275
270
|
let repoPath;
|
|
276
271
|
let baseBranch;
|
|
@@ -364,10 +359,17 @@ export async function runReviewerEffect(ctx, deps = defaultDeps) {
|
|
|
364
359
|
// NOT-314: the frozen snapshot's operator criteria — the reviewer must not
|
|
365
360
|
// treat missing operator evidence as a defect (Dealer gates the merge), but
|
|
366
361
|
// the probe and doc must exist. Rendered only when non-empty.
|
|
367
|
-
|
|
362
|
+
// NOT-575: the same union the gate uses (AC text + structured contract).
|
|
363
|
+
const operatorCriteria = operatorCriteriaForSnapshot(taskSnapshot);
|
|
368
364
|
// NOT-381: the latest coordinator-validated visual receipt (or loud
|
|
369
365
|
// rejection), SHA-checked against the pinned head inside the prompt section.
|
|
370
366
|
const visualQaRecord = readLatestVisualQa(issue.id);
|
|
367
|
+
// NOT-575: the PR's live body and recorded operator attestations — best
|
|
368
|
+
// effort, never failing the review. A lookup failure (or an adapter
|
|
369
|
+
// without the read) yields no section, and the reviewer judges without
|
|
370
|
+
// it; a missing body is never evidence of anything.
|
|
371
|
+
const prBody = await readPrBodyForReview(deps.github, worktreePath, issue.prNumber);
|
|
372
|
+
const operatorAttestations = listOperatorAttestations(issue.id);
|
|
371
373
|
const prompt = buildReviewerPrompt({
|
|
372
374
|
taskSnapshot,
|
|
373
375
|
round: workItem.round,
|
|
@@ -383,6 +385,8 @@ export async function runReviewerEffect(ctx, deps = defaultDeps) {
|
|
|
383
385
|
operatorCriteria: operatorCriteria.length > 0 ? operatorCriteria : undefined,
|
|
384
386
|
visualEvidence,
|
|
385
387
|
visualQa: visualQaRecord ? { record: visualQaRecord, pinnedHeadSha: headSha } : undefined,
|
|
388
|
+
prBody: prBody ?? undefined,
|
|
389
|
+
operatorAttestations: operatorAttestations.length > 0 ? operatorAttestations : undefined,
|
|
386
390
|
});
|
|
387
391
|
// NOT-83 review finding — see developer-effect.ts's identical check for the full
|
|
388
392
|
// rationale: re-verify this item is still leased right before the real spawn, since an
|
|
@@ -559,7 +563,9 @@ export async function runReviewerEffect(ctx, deps = defaultDeps) {
|
|
|
559
563
|
author: "system",
|
|
560
564
|
blobPath: spawned.logPath,
|
|
561
565
|
});
|
|
562
|
-
|
|
566
|
+
// Preserve the reviewer's own findings on a truncated diff so NOT-630 can distinguish
|
|
567
|
+
// them from normalizeReviewer's synthetic bare-escalate repair finding.
|
|
568
|
+
const parsed = parseReviewerResult(spawned.transcript, { normalize: !diffTruncated });
|
|
563
569
|
if (!parsed) {
|
|
564
570
|
await bestEffortRemove(repoPath, worktreePath);
|
|
565
571
|
return { kind: "session_failed" };
|
|
@@ -574,11 +580,14 @@ export async function runReviewerEffect(ctx, deps = defaultDeps) {
|
|
|
574
580
|
return { kind: "session_failed" };
|
|
575
581
|
}
|
|
576
582
|
result = parsed;
|
|
577
|
-
//
|
|
578
|
-
//
|
|
583
|
+
// NOT-630: persist truncation evidence; keep shippable approved and genuine blockers,
|
|
584
|
+
// but send every other incomplete review to a final_review operator action.
|
|
579
585
|
if (diffTruncated) {
|
|
580
586
|
const reportedVerdict = result.verdict;
|
|
581
|
-
|
|
587
|
+
const policy = applyTruncationVerdictPolicy(result, omittedPaths);
|
|
588
|
+
result = policy.result;
|
|
589
|
+
truncationFinalReviewReason = policy.finalReviewReason;
|
|
590
|
+
truncationOmittedPaths = omittedPaths;
|
|
582
591
|
createIssueArtifact({
|
|
583
592
|
issueId: issue.id,
|
|
584
593
|
workerSessionId: sessionId,
|
|
@@ -641,8 +650,14 @@ export async function runReviewerEffect(ctx, deps = defaultDeps) {
|
|
|
641
650
|
// attempt, or the winner itself failed) has nothing safe to report — escalate.
|
|
642
651
|
if (claim.row?.state === "published" && claim.row.resultJson) {
|
|
643
652
|
const winnerParsed = ReviewerResultSchema.parse(JSON.parse(claim.row.resultJson));
|
|
644
|
-
const
|
|
645
|
-
|
|
653
|
+
const winnerPolicy = truncationOmittedPaths
|
|
654
|
+
? applyTruncationVerdictPolicy(winnerParsed, truncationOmittedPaths)
|
|
655
|
+
: { result: normalizeReviewerResult(winnerParsed) };
|
|
656
|
+
return {
|
|
657
|
+
kind: "verdict",
|
|
658
|
+
result: winnerPolicy.result,
|
|
659
|
+
...(winnerPolicy.finalReviewReason ? { finalReviewReason: winnerPolicy.finalReviewReason } : {}),
|
|
660
|
+
};
|
|
646
661
|
}
|
|
647
662
|
return { kind: "publish_failed" };
|
|
648
663
|
}
|
|
@@ -675,7 +690,11 @@ export async function runReviewerEffect(ctx, deps = defaultDeps) {
|
|
|
675
690
|
content: { event: published.event, usedCommentFallback: published.usedCommentFallback, verdict: result.verdict },
|
|
676
691
|
});
|
|
677
692
|
await bestEffortRemove(repoPath, worktreePath);
|
|
678
|
-
return {
|
|
693
|
+
return {
|
|
694
|
+
kind: "verdict",
|
|
695
|
+
result,
|
|
696
|
+
...(truncationFinalReviewReason ? { finalReviewReason: truncationFinalReviewReason } : {}),
|
|
697
|
+
};
|
|
679
698
|
}
|
|
680
699
|
catch {
|
|
681
700
|
await bestEffortRemove(repoPath, worktreePath);
|
|
@@ -26,6 +26,7 @@ const { createAgent } = await import("../repository/agents.js");
|
|
|
26
26
|
const { createIssue, getIssue } = await import("../repository/issues.js");
|
|
27
27
|
const { listWorkerSessionsForIssue } = await import("../repository/worker-sessions.js");
|
|
28
28
|
const { listWorkItemsForIssue, cancelWorkItem } = await import("../repository/work-items.js");
|
|
29
|
+
const { createIssueArtifact } = await import("../repository/artifacts.js");
|
|
29
30
|
const { listArtifactsForIssue } = await import("../repository/artifacts-for-issue.js");
|
|
30
31
|
const { listHumanActionsForIssue } = await import("../repository/human-actions.js");
|
|
31
32
|
const { listFindingsForIssue } = await import("../repository/findings.js");
|
|
@@ -105,7 +106,7 @@ async function makeIssue(opts = {}) {
|
|
|
105
106
|
maxReviewRounds: 3,
|
|
106
107
|
maxInfraAttempts: opts.maxInfraAttempts ?? 3,
|
|
107
108
|
// NOT-489: omitted now means auto-merge; this suite exercises final human review.
|
|
108
|
-
autoMerge: false,
|
|
109
|
+
autoMerge: opts.autoMerge ?? false,
|
|
109
110
|
source: "manual"
|
|
110
111
|
}).id;
|
|
111
112
|
}
|
|
@@ -283,6 +284,53 @@ test("approved: the coordinator verifies the pinned SHA, publishes the review, a
|
|
|
283
284
|
assert.equal(usage.length, 1);
|
|
284
285
|
assert.equal(usage[0].workerSessionId, revSession.id);
|
|
285
286
|
});
|
|
287
|
+
test("NOT-575: the reviewer prompt carries the PR's live body as evidence", async () => {
|
|
288
|
+
const issueId = await makeIssue();
|
|
289
|
+
const github = fakeGithub();
|
|
290
|
+
github.prBody = async () => "Implementation conclusion.\n\nProbe output:\n```\nSSO login OK\n```";
|
|
291
|
+
await advanceToReviewing(issueId, github);
|
|
292
|
+
let captured = "";
|
|
293
|
+
const capturing = async (input) => {
|
|
294
|
+
captured = input.prompt;
|
|
295
|
+
return verdictSpawn({ verdict: "approved" })(input);
|
|
296
|
+
};
|
|
297
|
+
registerEffectHandler("reviewer", (ctx) => runReviewerEffect(ctx, { deckCallTool: okDeckCallTool, spawn: capturing, github }));
|
|
298
|
+
await pump(1);
|
|
299
|
+
assert.match(captured, /## PR body \(live — evidence pasted there counts\)/);
|
|
300
|
+
assert.match(captured, /SSO login OK/);
|
|
301
|
+
assert.match(captured, /never escalate only because it lives here instead of in the diff/);
|
|
302
|
+
assert.equal(getIssue(issueId).status, "final_review");
|
|
303
|
+
});
|
|
304
|
+
test("NOT-575: the reviewer prompt carries recorded operator attestations as evidence", async () => {
|
|
305
|
+
const issueId = await makeIssue();
|
|
306
|
+
const github = fakeGithub();
|
|
307
|
+
await advanceToReviewing(issueId, github);
|
|
308
|
+
const headSha = getIssue(issueId).headSha;
|
|
309
|
+
createIssueArtifact({
|
|
310
|
+
issueId,
|
|
311
|
+
kind: "operator_verification",
|
|
312
|
+
author: "human",
|
|
313
|
+
content: {
|
|
314
|
+
headSha,
|
|
315
|
+
note: "SSO login OK — dashboard shown.",
|
|
316
|
+
verifiedBy: "op",
|
|
317
|
+
verifiedAt: new Date().toISOString(),
|
|
318
|
+
criteria: ["Operator signs in with SSO [operator]"],
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
let captured = "";
|
|
322
|
+
const capturing = async (input) => {
|
|
323
|
+
captured = input.prompt;
|
|
324
|
+
return verdictSpawn({ verdict: "approved" })(input);
|
|
325
|
+
};
|
|
326
|
+
registerEffectHandler("reviewer", (ctx) => runReviewerEffect(ctx, { deckCallTool: okDeckCallTool, spawn: capturing, github }));
|
|
327
|
+
await pump(1);
|
|
328
|
+
assert.match(captured, /## Operator attestations \(recorded results count as evidence\)/);
|
|
329
|
+
assert.match(captured, /SSO login OK — dashboard shown/);
|
|
330
|
+
assert.match(captured, /never escalate for evidence an attestation below already provides/);
|
|
331
|
+
assert.match(captured, /this head/);
|
|
332
|
+
assert.equal(getIssue(issueId).status, "final_review");
|
|
333
|
+
});
|
|
286
334
|
test("same-identity fallback: GitHub rejecting APPROVE as a self-review still records the internal verdict and moves to final_review", async () => {
|
|
287
335
|
const issueId = await makeIssue();
|
|
288
336
|
const github = fakeGithub({ rejectSelfReview: true });
|
|
@@ -452,7 +500,7 @@ test("publish claim: a prior claimant that recorded failure is safely reclaimed
|
|
|
452
500
|
test("diff truncated: AC-met approved (no blocking) stays on the approve path — never bare escalate", async () => {
|
|
453
501
|
const issueId = await makeIssue();
|
|
454
502
|
const github = fakeGithub();
|
|
455
|
-
// A single file whose diff alone exceeds prompts.ts's TOTAL_DIFF_LIMIT (
|
|
503
|
+
// A single file whose diff alone exceeds prompts.ts's TOTAL_DIFF_LIMIT (600,000 chars).
|
|
456
504
|
const bigFileSpawn = async (input) => {
|
|
457
505
|
const lines = Array.from({ length: 20_000 }, (_, i) => `line ${i} of a very large generated file`);
|
|
458
506
|
fs.writeFileSync(path.join(input.cwd, "big.txt"), `${lines.join("\n")}\n`);
|
|
@@ -475,7 +523,7 @@ test("diff truncated: AC-met approved (no blocking) stays on the approve path
|
|
|
475
523
|
const published = listArtifactsForIssue(issueId).find((a) => a.kind === "review_published");
|
|
476
524
|
assert.equal(JSON.parse(published.contentJson).event, "APPROVE");
|
|
477
525
|
});
|
|
478
|
-
test("diff truncated: blocking
|
|
526
|
+
test("diff truncated: the reviewer's own blocking finding becomes changes_requested without an incomplete-review finding", async () => {
|
|
479
527
|
const issueId = await makeIssue();
|
|
480
528
|
const github = fakeGithub();
|
|
481
529
|
const bigFileSpawn = async (input) => {
|
|
@@ -507,10 +555,13 @@ test("diff truncated: blocking incomplete-review finding remaps to changes_reque
|
|
|
507
555
|
const truncateEvidence = listArtifactsForIssue(issueId).find((a) => a.kind === "diff_truncated_evidence");
|
|
508
556
|
assert.ok(truncateEvidence);
|
|
509
557
|
assert.equal(JSON.parse(truncateEvidence.contentJson).overriddenTo, "changes_requested");
|
|
558
|
+
const findings = listFindingsForIssue(issueId);
|
|
559
|
+
assert.deepEqual(findings.map(({ fingerprint, severity, title, rationale }) => ({ fingerprint, severity, title, rationale })), [finding]);
|
|
560
|
+
assert.ok(!findings.some((f) => f.fingerprint === "diff-truncated-incomplete-review"));
|
|
510
561
|
assert.ok(!listHumanActionsForIssue(issueId).find((a) => a.actionType === "policy_escalation"));
|
|
511
562
|
});
|
|
512
|
-
test("diff truncated: bare escalated
|
|
513
|
-
const issueId = await makeIssue();
|
|
563
|
+
test("diff truncated: bare escalated opens final_review with omitted paths even when auto-merge is on", async () => {
|
|
564
|
+
const issueId = await makeIssue({ autoMerge: true });
|
|
514
565
|
const github = fakeGithub();
|
|
515
566
|
const bigFileSpawn = async (input) => {
|
|
516
567
|
const lines = Array.from({ length: 20_000 }, (_, i) => `line ${i} of a very large generated file`);
|
|
@@ -525,12 +576,14 @@ test("diff truncated: bare escalated remaps to changes_requested with incomplete
|
|
|
525
576
|
registerEffectHandler("reviewer", (ctx) => runReviewerEffect(ctx, { deckCallTool: okDeckCallTool, spawn: verdictSpawn({ verdict: "escalated" }), github }));
|
|
526
577
|
await pump(1);
|
|
527
578
|
const issue = getIssue(issueId);
|
|
528
|
-
assert.equal(issue.status, "
|
|
579
|
+
assert.equal(issue.status, "final_review");
|
|
529
580
|
const truncateEvidence = listArtifactsForIssue(issueId).find((a) => a.kind === "diff_truncated_evidence");
|
|
530
|
-
assert.equal(JSON.parse(truncateEvidence.contentJson).overriddenTo, "
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
assert.
|
|
581
|
+
assert.equal(JSON.parse(truncateEvidence.contentJson).overriddenTo, "escalated");
|
|
582
|
+
const action = listHumanActionsForIssue(issueId).find((a) => a.actionType === "final_review");
|
|
583
|
+
assert.ok(action);
|
|
584
|
+
assert.equal(action.reason, "Diff exceeds the reviewer limit (600,000 characters); not reviewed: big.txt");
|
|
585
|
+
assert.equal(listWorkItemsForIssue(issueId).filter((item) => item.kind === "developer" && item.round === 2).length, 0, "operator escalation must not queue a repair round");
|
|
586
|
+
assert.deepEqual(listFindingsForIssue(issueId), []);
|
|
534
587
|
});
|
|
535
588
|
test("changes_requested: findings thread onto the issue and a fresh developer repair round is queued", async () => {
|
|
536
589
|
const issueId = await makeIssue();
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
// NOT-575: the reviewer can see PR-body evidence and recorded operator
|
|
2
|
+
// attestations — the sandbox has no network/`gh`, so both arrive via the
|
|
3
|
+
// prompt. Covers the PR-body path and the attestation path.
|
|
4
|
+
import { test, before, beforeEach } from "node:test";
|
|
5
|
+
import assert from "node:assert/strict";
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import os from "node:os";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
process.env.AGENT_DEALER_HOME = fs.mkdtempSync(path.join(os.tmpdir(), "dealer-not575-rev-"));
|
|
10
|
+
const { migrate, getDb } = await import("../db/index.js");
|
|
11
|
+
const { BUILTIN_AGENT_CLAUDE_ID, BUILTIN_AGENT_CURSOR_ID } = await import("@agent-dealer/shared");
|
|
12
|
+
const { createIssue } = await import("../repository/issues.js");
|
|
13
|
+
const { createIssueArtifact } = await import("../repository/artifacts.js");
|
|
14
|
+
const { appendWorkflowEvent } = await import("../repository/workflow-events.js");
|
|
15
|
+
const { listOperatorAttestations } = await import("./operator-criteria.js");
|
|
16
|
+
const { buildReviewerPrompt, operatorAttestationsSection, prBodyEvidenceSection, PR_BODY_EVIDENCE_MAX_CHARS, OPERATOR_ATTESTATION_NOTE_MAX_CHARS, OPERATOR_ATTESTATIONS_MAX_COUNT, } = await import("./prompts.js");
|
|
17
|
+
const { readPrBodyForReview } = await import("./reviewer-effect.js");
|
|
18
|
+
const { createGithubAdapter, parsePrBody } = await import("../adapters/github.js");
|
|
19
|
+
before(() => migrate());
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
getDb().exec(`
|
|
22
|
+
DELETE FROM work_items;
|
|
23
|
+
DELETE FROM human_actions;
|
|
24
|
+
DELETE FROM workflow_events;
|
|
25
|
+
DELETE FROM worker_sessions;
|
|
26
|
+
DELETE FROM artifacts;
|
|
27
|
+
DELETE FROM workflow_instances;
|
|
28
|
+
DELETE FROM issues;
|
|
29
|
+
`);
|
|
30
|
+
});
|
|
31
|
+
const taskSnapshot = {
|
|
32
|
+
title: "Add widget",
|
|
33
|
+
description: "Build the widget.",
|
|
34
|
+
acceptanceCriteria: "Widget renders.",
|
|
35
|
+
repo: "acme/app",
|
|
36
|
+
baseBranch: "main",
|
|
37
|
+
};
|
|
38
|
+
const reviewerBase = {
|
|
39
|
+
taskSnapshot,
|
|
40
|
+
round: 1,
|
|
41
|
+
baseSha: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
42
|
+
headSha: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
|
|
43
|
+
diff: "diff --git a/x b/x\n+added line\n",
|
|
44
|
+
};
|
|
45
|
+
test("PR-body path: the prompt embeds the live body and never escalates for living there", () => {
|
|
46
|
+
const withBody = buildReviewerPrompt({
|
|
47
|
+
...reviewerBase,
|
|
48
|
+
prBody: "Implementation conclusion.\n\nProbe output:\n```\nSSO login OK — dashboard shown\n```",
|
|
49
|
+
});
|
|
50
|
+
assert.match(withBody, /## PR body \(live — evidence pasted there counts\)/);
|
|
51
|
+
assert.match(withBody, /SSO login OK — dashboard shown/);
|
|
52
|
+
assert.match(withBody, /never escalate only because it lives here instead of in the diff/);
|
|
53
|
+
});
|
|
54
|
+
test("PR-body path: absent or blank bodies render nothing (byte-for-byte)", () => {
|
|
55
|
+
const without = buildReviewerPrompt(reviewerBase);
|
|
56
|
+
assert.doesNotMatch(without, /## PR body/);
|
|
57
|
+
assert.equal(buildReviewerPrompt({ ...reviewerBase, prBody: undefined }), without);
|
|
58
|
+
assert.equal(buildReviewerPrompt({ ...reviewerBase, prBody: null }), without);
|
|
59
|
+
assert.equal(buildReviewerPrompt({ ...reviewerBase, prBody: " \n " }), without);
|
|
60
|
+
assert.deepEqual(prBodyEvidenceSection(undefined), []);
|
|
61
|
+
assert.deepEqual(prBodyEvidenceSection(" "), []);
|
|
62
|
+
});
|
|
63
|
+
test("PR-body path: long bodies cap with an explicit truncation marker", () => {
|
|
64
|
+
const body = `start-${"x".repeat(PR_BODY_EVIDENCE_MAX_CHARS + 500)}`;
|
|
65
|
+
const section = prBodyEvidenceSection(body).join("\n");
|
|
66
|
+
assert.match(section, /start-xxx/);
|
|
67
|
+
assert.match(section, new RegExp(`PR body truncated to ${PR_BODY_EVIDENCE_MAX_CHARS} characters`));
|
|
68
|
+
assert.ok(section.length < body.length + 1000);
|
|
69
|
+
});
|
|
70
|
+
test("attestation path: verified and waived results render with heads, criteria, and notes", () => {
|
|
71
|
+
const section = operatorAttestationsSection([
|
|
72
|
+
{
|
|
73
|
+
kind: "verified",
|
|
74
|
+
headSha: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
|
|
75
|
+
note: "SSO login OK — dashboard shown.",
|
|
76
|
+
by: "op",
|
|
77
|
+
at: "2026-11-01T00:00:00.000Z",
|
|
78
|
+
criteria: ["Operator signs in with SSO [operator]"],
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
kind: "waived",
|
|
82
|
+
headSha: "cccccccccccccccccccccccccccccccccccccccc",
|
|
83
|
+
note: "Staging down; shipping behind the flag.",
|
|
84
|
+
by: "op2",
|
|
85
|
+
at: null,
|
|
86
|
+
criteria: [],
|
|
87
|
+
},
|
|
88
|
+
], "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb").join("\n");
|
|
89
|
+
assert.match(section, /## Operator attestations \(recorded results count as evidence\)/);
|
|
90
|
+
assert.match(section, /never escalate for evidence an attestation below already provides/);
|
|
91
|
+
assert.match(section, /### Verified \(this head by op at 2026-11-01T00:00:00\.000Z\)/);
|
|
92
|
+
assert.match(section, /- Criterion: Operator signs in with SSO \[operator\]/);
|
|
93
|
+
assert.match(section, /SSO login OK — dashboard shown/);
|
|
94
|
+
assert.match(section, /### Waived \(head `cccccccc` by op2\)/);
|
|
95
|
+
assert.match(section, /Staging down; shipping behind the flag/);
|
|
96
|
+
});
|
|
97
|
+
test("attestation path: empty renders nothing; notes and count cap with markers", () => {
|
|
98
|
+
assert.deepEqual(operatorAttestationsSection(undefined, reviewerBase.headSha), []);
|
|
99
|
+
assert.deepEqual(operatorAttestationsSection([], reviewerBase.headSha), []);
|
|
100
|
+
const without = buildReviewerPrompt(reviewerBase);
|
|
101
|
+
assert.doesNotMatch(without, /## Operator attestations/);
|
|
102
|
+
assert.equal(buildReviewerPrompt({ ...reviewerBase, operatorAttestations: [] }), without);
|
|
103
|
+
const long = operatorAttestationsSection([
|
|
104
|
+
{
|
|
105
|
+
kind: "verified",
|
|
106
|
+
headSha: reviewerBase.headSha,
|
|
107
|
+
note: `n-${"y".repeat(OPERATOR_ATTESTATION_NOTE_MAX_CHARS + 100)}`,
|
|
108
|
+
by: null,
|
|
109
|
+
at: null,
|
|
110
|
+
criteria: [],
|
|
111
|
+
},
|
|
112
|
+
], reviewerBase.headSha).join("\n");
|
|
113
|
+
assert.match(long, new RegExp(`attestation note truncated to ${OPERATOR_ATTESTATION_NOTE_MAX_CHARS} characters`));
|
|
114
|
+
const many = Array.from({ length: OPERATOR_ATTESTATIONS_MAX_COUNT + 2 }, (_, i) => ({
|
|
115
|
+
kind: "verified",
|
|
116
|
+
headSha: reviewerBase.headSha,
|
|
117
|
+
note: `note-${i}`,
|
|
118
|
+
by: null,
|
|
119
|
+
at: null,
|
|
120
|
+
criteria: [],
|
|
121
|
+
}));
|
|
122
|
+
const capped = operatorAttestationsSection(many, reviewerBase.headSha).join("\n");
|
|
123
|
+
assert.match(capped, /2 older attestation\(s\) omitted/);
|
|
124
|
+
assert.match(capped, /note-6/);
|
|
125
|
+
assert.doesNotMatch(capped, /note-0/);
|
|
126
|
+
});
|
|
127
|
+
test("attestation path: the prompt carries both evidence sections together", () => {
|
|
128
|
+
const both = buildReviewerPrompt({
|
|
129
|
+
...reviewerBase,
|
|
130
|
+
prBody: "PR body with the probe command.",
|
|
131
|
+
operatorAttestations: [
|
|
132
|
+
{
|
|
133
|
+
kind: "verified",
|
|
134
|
+
headSha: reviewerBase.headSha,
|
|
135
|
+
note: "SSO login OK.",
|
|
136
|
+
by: "op",
|
|
137
|
+
at: null,
|
|
138
|
+
criteria: ["Operator signs in with SSO [operator]"],
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
});
|
|
142
|
+
assert.match(both, /## PR body \(live/);
|
|
143
|
+
assert.match(both, /PR body with the probe command/);
|
|
144
|
+
assert.match(both, /## Operator attestations/);
|
|
145
|
+
assert.match(both, /SSO login OK/);
|
|
146
|
+
});
|
|
147
|
+
function newIssueId() {
|
|
148
|
+
return createIssue({
|
|
149
|
+
title: "Widget",
|
|
150
|
+
description: "d",
|
|
151
|
+
acceptanceCriteria: "Widget renders.",
|
|
152
|
+
repo: "acme/app",
|
|
153
|
+
developerAgentId: BUILTIN_AGENT_CLAUDE_ID,
|
|
154
|
+
reviewerAgentId: BUILTIN_AGENT_CURSOR_ID,
|
|
155
|
+
baseBranch: "main",
|
|
156
|
+
maxReviewRounds: 3,
|
|
157
|
+
maxInfraAttempts: 3,
|
|
158
|
+
source: "manual",
|
|
159
|
+
autoMerge: true,
|
|
160
|
+
}).id;
|
|
161
|
+
}
|
|
162
|
+
test("listOperatorAttestations reads verified artifacts and waiver events, oldest first", () => {
|
|
163
|
+
const issueId = newIssueId();
|
|
164
|
+
assert.deepEqual(listOperatorAttestations(issueId), []);
|
|
165
|
+
createIssueArtifact({
|
|
166
|
+
issueId,
|
|
167
|
+
kind: "operator_verification",
|
|
168
|
+
author: "human",
|
|
169
|
+
content: {
|
|
170
|
+
headSha: "aaa",
|
|
171
|
+
note: "SSO login OK.",
|
|
172
|
+
verifiedBy: "op",
|
|
173
|
+
verifiedAt: "2026-11-01T00:00:00.000Z",
|
|
174
|
+
criteria: ["Operator signs in with SSO [operator]"],
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
appendWorkflowEvent({
|
|
178
|
+
issueId,
|
|
179
|
+
type: "operator_verification.waived",
|
|
180
|
+
actorType: "human",
|
|
181
|
+
actorRef: "op2",
|
|
182
|
+
stage: "needs_human",
|
|
183
|
+
round: 1,
|
|
184
|
+
payload: {
|
|
185
|
+
actionType: "operator_verification",
|
|
186
|
+
choice: "waive",
|
|
187
|
+
headSha: "bbb",
|
|
188
|
+
waivedBy: "op2",
|
|
189
|
+
note: "Staging down.",
|
|
190
|
+
criteria: ["Operator completes a paid checkout [operator]"],
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
const attestations = listOperatorAttestations(issueId);
|
|
194
|
+
assert.equal(attestations.length, 2);
|
|
195
|
+
assert.deepEqual(attestations[0], {
|
|
196
|
+
kind: "verified",
|
|
197
|
+
headSha: "aaa",
|
|
198
|
+
note: "SSO login OK.",
|
|
199
|
+
by: "op",
|
|
200
|
+
at: "2026-11-01T00:00:00.000Z",
|
|
201
|
+
criteria: ["Operator signs in with SSO [operator]"],
|
|
202
|
+
});
|
|
203
|
+
assert.equal(attestations[1].kind, "waived");
|
|
204
|
+
assert.equal(attestations[1].headSha, "bbb");
|
|
205
|
+
assert.equal(attestations[1].note, "Staging down.");
|
|
206
|
+
assert.equal(attestations[1].by, "op2");
|
|
207
|
+
assert.deepEqual(attestations[1].criteria, ["Operator completes a paid checkout [operator]"]);
|
|
208
|
+
});
|
|
209
|
+
test("listOperatorAttestations skips unreadable rows instead of throwing", () => {
|
|
210
|
+
const issueId = newIssueId();
|
|
211
|
+
getDb()
|
|
212
|
+
.prepare("INSERT INTO artifacts (id, issue_id, kind, content_json, author, created_at) VALUES (?, ?, 'operator_verification', 'not json', 'human', ?)")
|
|
213
|
+
.run(crypto.randomUUID(), issueId, new Date().toISOString());
|
|
214
|
+
assert.deepEqual(listOperatorAttestations(issueId), []);
|
|
215
|
+
});
|
|
216
|
+
test("readPrBodyForReview returns the body, null without a PR, a read, or on failure", async () => {
|
|
217
|
+
const withBody = { prBody: async () => "live body" };
|
|
218
|
+
assert.equal(await readPrBodyForReview(withBody, "/wt", 42), "live body");
|
|
219
|
+
assert.equal(await readPrBodyForReview(withBody, "/wt", null), null);
|
|
220
|
+
assert.equal(await readPrBodyForReview({}, "/wt", 42), null);
|
|
221
|
+
const failing = {
|
|
222
|
+
prBody: async () => {
|
|
223
|
+
throw new Error("gh down");
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
assert.equal(await readPrBodyForReview(failing, "/wt", 42), null);
|
|
227
|
+
});
|
|
228
|
+
test("parsePrBody keeps the body text, null when absent or blank", () => {
|
|
229
|
+
assert.equal(parsePrBody("hello"), "hello");
|
|
230
|
+
assert.equal(parsePrBody(" padded "), " padded ");
|
|
231
|
+
assert.equal(parsePrBody(""), null);
|
|
232
|
+
assert.equal(parsePrBody(" "), null);
|
|
233
|
+
assert.equal(parsePrBody(null), null);
|
|
234
|
+
assert.equal(parsePrBody(undefined), null);
|
|
235
|
+
assert.equal(parsePrBody(42), null);
|
|
236
|
+
});
|
|
237
|
+
test("the real adapter reads the PR body with an explicit-number gh pr view", async () => {
|
|
238
|
+
const seen = [];
|
|
239
|
+
const adapter = createGithubAdapter(async (args, opts) => {
|
|
240
|
+
seen.push({ args, cwd: opts.cwd });
|
|
241
|
+
return { stdout: JSON.stringify({ body: "the live body" }) };
|
|
242
|
+
});
|
|
243
|
+
assert.equal(await adapter.prBody({ cwd: "/repo", number: 42 }), "the live body");
|
|
244
|
+
assert.deepEqual(seen, [{ args: ["pr", "view", "42", "--json", "body"], cwd: "/repo" }]);
|
|
245
|
+
});
|
|
@@ -74,15 +74,16 @@ export function normalizeReviewerResult(raw) {
|
|
|
74
74
|
return withoutQuestion;
|
|
75
75
|
}
|
|
76
76
|
/** Mirrors the plan-triage/reflect JSON-fence parsing pattern already used elsewhere. */
|
|
77
|
-
export function parseReviewerResult(text) {
|
|
77
|
+
export function parseReviewerResult(text, options = {}) {
|
|
78
78
|
const trimmed = text.trim();
|
|
79
79
|
const fenceMatch = trimmed.match(/```(?:json)?\s*\n([\s\S]*?)\n```/);
|
|
80
80
|
const candidates = [fenceMatch?.[1] ?? trimmed, trimmed];
|
|
81
81
|
for (const candidate of candidates) {
|
|
82
82
|
try {
|
|
83
83
|
const parsed = ReviewerResult.safeParse(JSON.parse(candidate));
|
|
84
|
-
if (parsed.success)
|
|
85
|
-
return normalizeReviewerResult(parsed.data);
|
|
84
|
+
if (parsed.success) {
|
|
85
|
+
return options.normalize === false ? parsed.data : normalizeReviewerResult(parsed.data);
|
|
86
|
+
}
|
|
86
87
|
}
|
|
87
88
|
catch {
|
|
88
89
|
// try next candidate
|
|
@@ -43,6 +43,12 @@ test("NOT-150: escalated without productScopeQuestion remaps to changes_requeste
|
|
|
43
43
|
assert.ok(result?.findings.some((f) => f.severity === "blocking"));
|
|
44
44
|
assert.ok(result?.findings.some((f) => f.fingerprint === "escalated-without-product-scope-question"));
|
|
45
45
|
});
|
|
46
|
+
test("NOT-630: parsing can preserve a bare escalated verdict for truncated-diff policy", () => {
|
|
47
|
+
const bare = { ...valid, verdict: "escalated" };
|
|
48
|
+
const result = parseReviewerResult(`\`\`\`json\n${JSON.stringify(bare)}\n\`\`\``, { normalize: false });
|
|
49
|
+
assert.equal(result?.verdict, "escalated");
|
|
50
|
+
assert.deepEqual(result?.findings, []);
|
|
51
|
+
});
|
|
46
52
|
test("NOT-150: bare escalate with existing blocking findings keeps those findings", () => {
|
|
47
53
|
const bare = {
|
|
48
54
|
...valid,
|
|
@@ -366,6 +366,9 @@ export function routeReviewerOutcome(outcome, limits, pinnedHeadSha) {
|
|
|
366
366
|
// See routeDeveloperOutcome — the reviewer never spawned either (NOT-136).
|
|
367
367
|
return { next: "defer_work", reason: outcome.reason };
|
|
368
368
|
case "verdict":
|
|
369
|
+
if (outcome.finalReviewReason) {
|
|
370
|
+
return { next: "final_review", reason: outcome.finalReviewReason };
|
|
371
|
+
}
|
|
369
372
|
return routeVerdict(outcome.result, limits);
|
|
370
373
|
}
|
|
371
374
|
}
|
|
@@ -377,6 +377,25 @@ test("approved verdict with autoMerge routes to auto_merge instead of final_revi
|
|
|
377
377
|
};
|
|
378
378
|
assert.deepStrictEqual(routeReviewerOutcome(outcome, { ...REVIEW_ROUNDS_LEFT, autoMerge: true }, PINNED_HEAD), { next: "auto_merge" });
|
|
379
379
|
});
|
|
380
|
+
test("NOT-630: an incomplete truncated review forces final_review even with autoMerge", () => {
|
|
381
|
+
const outcome = {
|
|
382
|
+
kind: "verdict",
|
|
383
|
+
result: {
|
|
384
|
+
verdict: "escalated",
|
|
385
|
+
baseSha: "b",
|
|
386
|
+
headSha: "h",
|
|
387
|
+
acceptanceCriteriaAssessment: "incomplete",
|
|
388
|
+
evidenceAssessment: "visible diff reviewed",
|
|
389
|
+
findings: [],
|
|
390
|
+
risks: [],
|
|
391
|
+
},
|
|
392
|
+
finalReviewReason: "Diff exceeds the reviewer limit (600,000 characters); not reviewed: big.txt",
|
|
393
|
+
};
|
|
394
|
+
assert.deepStrictEqual(routeReviewerOutcome(outcome, { ...REVIEW_ROUNDS_LEFT, autoMerge: true }, PINNED_HEAD), {
|
|
395
|
+
next: "final_review",
|
|
396
|
+
reason: "Diff exceeds the reviewer limit (600,000 characters); not reviewed: big.txt",
|
|
397
|
+
});
|
|
398
|
+
});
|
|
380
399
|
test("changes_requested with rounds remaining retries the developer with findings", () => {
|
|
381
400
|
const outcome = {
|
|
382
401
|
kind: "verdict",
|