@webpieces/pr-gate 0.4.825 → 0.4.827
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/package.json +3 -3
- package/src/dashboard/checklist-comment-renderer.js +8 -6
- package/src/dashboard/checklist-comment-renderer.js.map +1 -1
- package/src/dashboard/checklist-comment-row.d.ts +6 -0
- package/src/dashboard/checklist-comment-row.js +6 -0
- package/src/dashboard/checklist-comment-row.js.map +1 -1
- package/src/dashboard/dashboard.d.ts +11 -0
- package/src/dashboard/dashboard.js +24 -6
- package/src/dashboard/dashboard.js.map +1 -1
- package/src/scripts/commands/await-reviews-command.d.ts +3 -3
- package/src/scripts/commands/await-reviews-command.js +25 -21
- package/src/scripts/commands/await-reviews-command.js.map +1 -1
- package/src/scripts/commands/finish-upsert-pr-command.js +26 -21
- package/src/scripts/commands/finish-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/review-upsert-pr-command.d.ts +3 -8
- package/src/scripts/commands/review-upsert-pr-command.js +16 -18
- package/src/scripts/commands/review-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/write-review-command.d.ts +43 -7
- package/src/scripts/commands/write-review-command.js +91 -12
- package/src/scripts/commands/write-review-command.js.map +1 -1
- package/src/scripts/commands/write-review-fixes-command.d.ts +5 -1
- package/src/scripts/commands/write-review-fixes-command.js +6 -2
- package/src/scripts/commands/write-review-fixes-command.js.map +1 -1
- package/src/scripts/pr-gate-app.d.ts +3 -1
- package/src/scripts/pr-gate-app.js +4 -0
- package/src/scripts/pr-gate-app.js.map +1 -1
- package/src/scripts/workflow/checklist-scanner.d.ts +61 -10
- package/src/scripts/workflow/checklist-scanner.js +105 -16
- package/src/scripts/workflow/checklist-scanner.js.map +1 -1
- package/src/scripts/workflow/hotfix-finish-preparer.js +1 -1
- package/src/scripts/workflow/hotfix-finish-preparer.js.map +1 -1
- package/src/scripts/workflow/provenance-enforcer.d.ts +2 -2
- package/src/scripts/workflow/provenance-enforcer.js +5 -5
- package/src/scripts/workflow/provenance-enforcer.js.map +1 -1
- package/src/scripts/workflow/review-report.d.ts +26 -8
- package/src/scripts/workflow/review-report.js +65 -39
- package/src/scripts/workflow/review-report.js.map +1 -1
- package/src/scripts/workflow/review-round-state.d.ts +90 -11
- package/src/scripts/workflow/review-round-state.js +256 -85
- package/src/scripts/workflow/review-round-state.js.map +1 -1
- package/src/scripts/workflow/review-round-text.d.ts +37 -0
- package/src/scripts/workflow/review-round-text.js +87 -0
- package/src/scripts/workflow/review-round-text.js.map +1 -0
- package/src/scripts/workflow/review-stage-receipt.d.ts +7 -6
- package/src/scripts/workflow/review-stage-receipt.js +7 -11
- package/src/scripts/workflow/review-stage-receipt.js.map +1 -1
- package/src/scripts/workflow/reviewer-briefing-builder.js +0 -1
- package/src/scripts/workflow/reviewer-briefing-builder.js.map +1 -1
- package/src/scripts/workflow/reviewer-verdict-gate.d.ts +14 -26
- package/src/scripts/workflow/reviewer-verdict-gate.js +38 -51
- package/src/scripts/workflow/reviewer-verdict-gate.js.map +1 -1
- package/src/scripts/workflow/verdict-provenance.d.ts +13 -7
- package/src/scripts/workflow/verdict-provenance.js +30 -22
- package/src/scripts/workflow/verdict-provenance.js.map +1 -1
- package/src/scripts/wp-write-review.js +7 -0
- package/src/scripts/wp-write-review.js.map +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ReviewRoundStateService = exports.ReviewRemediation = exports.RemediationResponse = exports.ReviewRoundPlan = exports.ROUND_ACTION_FINISH = exports.ROUND_ACTION_RECORD = exports.ROUND_ACTION_FIX = exports.ROUND_ACTION_RESUME = exports.ROUND_ACTION_REVIEW = void 0;
|
|
3
|
+
exports.ReviewRoundStateService = exports.ReviewRemediation = exports.RemediationResponse = exports.RoundSnapshot = exports.ReviewRoundPlan = exports.ROUND_ACTION_FINISH = exports.ROUND_ACTION_RECORD = exports.ROUND_ACTION_FIX = exports.ROUND_ACTION_RESUME = exports.ROUND_ACTION_REVIEW = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fs = tslib_1.__importStar(require("fs"));
|
|
6
6
|
const path = tslib_1.__importStar(require("path"));
|
|
@@ -14,6 +14,10 @@ exports.ROUND_ACTION_RESUME = 'resume';
|
|
|
14
14
|
exports.ROUND_ACTION_FIX = 'fix';
|
|
15
15
|
exports.ROUND_ACTION_RECORD = 'record';
|
|
16
16
|
exports.ROUND_ACTION_FINISH = 'finish';
|
|
17
|
+
/** Every round-numbered file of a branch's review lives beside summary.json under this prefix (issue #1053). */
|
|
18
|
+
const ROUND_FILE = /^review-round(\d+)-(.+)\.json$/;
|
|
19
|
+
const FIXES_ID = 'fixes';
|
|
20
|
+
const PROVENANCE_SUFFIX = '.provenance';
|
|
17
21
|
class ReviewRoundPlan {
|
|
18
22
|
action;
|
|
19
23
|
round;
|
|
@@ -21,16 +25,38 @@ class ReviewRoundPlan {
|
|
|
21
25
|
basis;
|
|
22
26
|
changedFiles;
|
|
23
27
|
redChecklistIds;
|
|
24
|
-
|
|
28
|
+
/** The final round's ORANGE checklists — must-fix, never re-reviewed (issue #1053). */
|
|
29
|
+
orangeChecklistIds;
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
31
|
+
constructor(action, round, maxRounds, basis, changedFiles = [], redChecklistIds = [], orangeChecklistIds = []) {
|
|
25
32
|
this.action = action;
|
|
26
33
|
this.round = round;
|
|
27
34
|
this.maxRounds = maxRounds;
|
|
28
35
|
this.basis = basis;
|
|
29
36
|
this.changedFiles = changedFiles;
|
|
30
37
|
this.redChecklistIds = redChecklistIds;
|
|
38
|
+
this.orangeChecklistIds = orangeChecklistIds;
|
|
31
39
|
}
|
|
32
40
|
}
|
|
33
41
|
exports.ReviewRoundPlan = ReviewRoundPlan;
|
|
42
|
+
/**
|
|
43
|
+
* Where a branch's review stands, DERIVED from the round-numbered files on disk plus the stage-② receipt
|
|
44
|
+
* (issue #1053). There is no separate round counter: `round` is the highest round any file or briefing
|
|
45
|
+
* names. Data-only.
|
|
46
|
+
*/
|
|
47
|
+
class RoundSnapshot {
|
|
48
|
+
round; // 0 = no round has started
|
|
49
|
+
roster; // the checklists briefed in `round`
|
|
50
|
+
headSha; // the commit `round` was briefed on
|
|
51
|
+
complete; // every checklist on the roster has a verdict in `round`
|
|
52
|
+
constructor(round, roster, headSha, complete) {
|
|
53
|
+
this.round = round;
|
|
54
|
+
this.roster = roster;
|
|
55
|
+
this.headSha = headSha;
|
|
56
|
+
this.complete = complete;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.RoundSnapshot = RoundSnapshot;
|
|
34
60
|
class RemediationResponse {
|
|
35
61
|
checklistId;
|
|
36
62
|
resolution;
|
|
@@ -42,6 +68,7 @@ class RemediationResponse {
|
|
|
42
68
|
}
|
|
43
69
|
}
|
|
44
70
|
exports.RemediationResponse = RemediationResponse;
|
|
71
|
+
/** The author's recorded fixes for one completed round: `review-round<N>-fixes.json`. Data-only. */
|
|
45
72
|
class ReviewRemediation {
|
|
46
73
|
agent;
|
|
47
74
|
model;
|
|
@@ -49,6 +76,7 @@ class ReviewRemediation {
|
|
|
49
76
|
toHead;
|
|
50
77
|
responses;
|
|
51
78
|
writtenAt;
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
52
80
|
constructor(agent, model, fromHead, toHead, responses) {
|
|
53
81
|
this.agent = agent;
|
|
54
82
|
this.model = model;
|
|
@@ -59,7 +87,20 @@ class ReviewRemediation {
|
|
|
59
87
|
}
|
|
60
88
|
}
|
|
61
89
|
exports.ReviewRemediation = ReviewRemediation;
|
|
62
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
* The reviewer rounds of one branch, read from their round-numbered files (issue #1053).
|
|
92
|
+
*
|
|
93
|
+
* `commands.pr-gate.maxReviewerRounds` is a HARD CEILING, not a quota: 1 round means 1 round. Three rules
|
|
94
|
+
* follow from it, and everything here exists to hold them:
|
|
95
|
+
*
|
|
96
|
+
* 1. Every verdict is `review-round<N>-<id>.json` (+ `.provenance.json`), every author fix record is
|
|
97
|
+
* `review-round<N>-fixes.json`, and nothing is ever overwritten. The live verdict of a checklist is its
|
|
98
|
+
* highest round; the round the branch is on is the highest round any file names.
|
|
99
|
+
* 2. A new round starts ONLY when the previous round has a RED and rounds remain, and it re-briefs only
|
|
100
|
+
* those reds. A green or yellow stands whatever changes afterwards — staleness never re-reviews.
|
|
101
|
+
* 3. The final round has no red. Its blocking color is ORANGE: the author fixes it best effort, records the
|
|
102
|
+
* fix, and ships with the finding and its claimed fix stamped on the dashboard.
|
|
103
|
+
*/
|
|
63
104
|
let ReviewRoundStateService = class ReviewRoundStateService {
|
|
64
105
|
reviewJson;
|
|
65
106
|
provenance;
|
|
@@ -69,70 +110,134 @@ let ReviewRoundStateService = class ReviewRoundStateService {
|
|
|
69
110
|
this.provenance = provenance;
|
|
70
111
|
this.atomicFile = atomicFile;
|
|
71
112
|
}
|
|
72
|
-
|
|
73
|
-
|
|
113
|
+
/** The author's recorded fixes for one round: `review-round<N>-fixes.json`, beside summary.json. */
|
|
114
|
+
fixesPath(summaryPath, round) {
|
|
115
|
+
return path.join(path.dirname(summaryPath), `review-round${round}-${FIXES_ID}.json`);
|
|
74
116
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
117
|
+
/** The highest round any round-numbered file names, or 0. */
|
|
118
|
+
highestRound(summaryPath) {
|
|
119
|
+
let highest = 0;
|
|
120
|
+
for (const name of this.roundFiles(summaryPath)) {
|
|
121
|
+
const match = ROUND_FILE.exec(name);
|
|
122
|
+
if (match !== null)
|
|
123
|
+
highest = Math.max(highest, Number(match[1]));
|
|
124
|
+
}
|
|
125
|
+
return highest;
|
|
80
126
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
127
|
+
/** Every checklist that has a verdict in ANY round on this branch. */
|
|
128
|
+
verdictChecklistIds(summaryPath) {
|
|
129
|
+
const ids = new Set();
|
|
130
|
+
for (const name of this.roundFiles(summaryPath)) {
|
|
131
|
+
const id = this.verdictIdOf(name);
|
|
132
|
+
if (id !== '')
|
|
133
|
+
ids.add(id);
|
|
134
|
+
}
|
|
135
|
+
return [...ids].sort();
|
|
136
|
+
}
|
|
137
|
+
/** Where the branch's review stands — see {@link RoundSnapshot}. */
|
|
138
|
+
snapshot(summaryPath, receipt) {
|
|
139
|
+
const briefed = receipt !== null && receipt.reviewersBriefed.length > 0 ? receipt.round : 0;
|
|
140
|
+
const round = Math.max(this.highestRound(summaryPath), briefed);
|
|
141
|
+
if (round < 1)
|
|
142
|
+
return new RoundSnapshot(0, [], '', false);
|
|
143
|
+
if (receipt !== null && receipt.round === round) {
|
|
144
|
+
return new RoundSnapshot(round, receipt.reviewersBriefed.slice(), receipt.headSha, this.everyVerdictIn(summaryPath, receipt.reviewersBriefed, round));
|
|
145
|
+
}
|
|
146
|
+
// The receipt names an older round (or is gone): the files are the record, so the roster is exactly
|
|
147
|
+
// the checklists that have a verdict in this round, and the reviewed HEAD is what their provenance says.
|
|
148
|
+
const roster = this.roundFiles(summaryPath)
|
|
149
|
+
.filter((name) => name.startsWith(`review-round${round}-`))
|
|
150
|
+
.map((name) => this.verdictIdOf(name))
|
|
151
|
+
.filter((id) => id !== '')
|
|
152
|
+
.sort();
|
|
153
|
+
const headSha = roster.length === 0 ? '' : this.provenance.read(summaryPath, roster[0], round)?.headSha ?? '';
|
|
154
|
+
return new RoundSnapshot(round, roster, headSha, roster.length > 0);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* TRUE once a review round has started on this branch. From then on the checklist set is FROZEN (issue
|
|
158
|
+
* #1053): finish judges only the checklists that were briefed, never ones a later commit newly triggers.
|
|
159
|
+
*/
|
|
160
|
+
roundStarted(summaryPath, receipt) {
|
|
161
|
+
return this.snapshot(summaryPath, receipt).round >= 1;
|
|
162
|
+
}
|
|
163
|
+
/** The frozen checklist set: every checklist briefed in any round — see {@link roundStarted}. */
|
|
164
|
+
briefedChecklistIds(summaryPath, receipt) {
|
|
165
|
+
const ids = new Set(this.verdictChecklistIds(summaryPath));
|
|
166
|
+
if (receipt !== null && receipt.round >= 1)
|
|
167
|
+
for (const id of receipt.reviewersBriefed)
|
|
168
|
+
ids.add(id);
|
|
169
|
+
return [...ids].sort();
|
|
85
170
|
}
|
|
86
|
-
|
|
87
|
-
|
|
171
|
+
/** Does `checklistId` already have a verdict in `round`? A round's verdict is never overwritten. */
|
|
172
|
+
hasVerdict(summaryPath, checklistId, round) {
|
|
173
|
+
return fs.existsSync(this.reviewJson.checklistResultPath(summaryPath, checklistId, round));
|
|
174
|
+
}
|
|
175
|
+
/** The roster checklists whose verdict in the snapshot's round is `status`. */
|
|
176
|
+
checklistIdsWithStatus(summaryPath, snap, status) {
|
|
177
|
+
if (!snap.complete)
|
|
88
178
|
return [];
|
|
89
|
-
return
|
|
90
|
-
const raw = this.readObject(
|
|
91
|
-
return raw !== null && raw['status'] ===
|
|
179
|
+
return snap.roster.filter((id) => {
|
|
180
|
+
const raw = this.readObject(this.reviewJson.checklistResultPath(summaryPath, id, snap.round));
|
|
181
|
+
return raw !== null && raw['status'] === status;
|
|
92
182
|
});
|
|
93
183
|
}
|
|
94
|
-
|
|
95
|
-
return path.join(this.roundDir(summaryPath, round), 'review-fixes.json');
|
|
96
|
-
}
|
|
184
|
+
/** What stage ② does next. See the class comment for the three rules it holds. */
|
|
97
185
|
plan(repoRoot, summaryPath, receipt, maxRounds, fullBasis) {
|
|
98
|
-
|
|
186
|
+
const snap = this.snapshot(summaryPath, receipt);
|
|
187
|
+
if (snap.round < 1)
|
|
99
188
|
return new ReviewRoundPlan(exports.ROUND_ACTION_REVIEW, 1, maxRounds, fullBasis);
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
+ `${receipt.headSha.slice(0, 8)}. Finish that fixed roster before changing the reviewed HEAD.`);
|
|
189
|
+
if (!snap.complete) {
|
|
190
|
+
if (snap.headSha !== fullBasis.headSha) {
|
|
191
|
+
throw new rules_config_1.InformAiError(`Reviewer round ${snap.round} of ${maxRounds} is still active at `
|
|
192
|
+
+ `${snap.headSha.slice(0, 8)}. Finish that fixed roster before changing the reviewed HEAD.`);
|
|
105
193
|
}
|
|
106
|
-
return new ReviewRoundPlan(exports.ROUND_ACTION_RESUME,
|
|
194
|
+
return new ReviewRoundPlan(exports.ROUND_ACTION_RESUME, snap.round, maxRounds, fullBasis);
|
|
107
195
|
}
|
|
108
|
-
const reds = this.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (
|
|
112
|
-
return new ReviewRoundPlan(exports.
|
|
196
|
+
const reds = this.checklistIdsWithStatus(summaryPath, snap, rules_config_1.VERDICT_RED);
|
|
197
|
+
const oranges = this.checklistIdsWithStatus(summaryPath, snap, rules_config_1.VERDICT_ORANGE);
|
|
198
|
+
// No red, or no round left: nothing is ever re-reviewed. Oranges are the author's to fix and record.
|
|
199
|
+
if (reds.length === 0 || snap.round >= maxRounds) {
|
|
200
|
+
return new ReviewRoundPlan(exports.ROUND_ACTION_FINISH, snap.round, maxRounds, fullBasis, [], reds, oranges);
|
|
113
201
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return new ReviewRoundPlan(exports.ROUND_ACTION_RECORD, receipt.round, maxRounds, fullBasis, [], reds);
|
|
202
|
+
if (snap.headSha === fullBasis.headSha) {
|
|
203
|
+
return new ReviewRoundPlan(exports.ROUND_ACTION_FIX, snap.round, maxRounds, fullBasis, [], reds, oranges);
|
|
117
204
|
}
|
|
118
|
-
if (
|
|
119
|
-
return new ReviewRoundPlan(exports.
|
|
205
|
+
if (this.validFixes(repoRoot, summaryPath, snap) === null) {
|
|
206
|
+
return new ReviewRoundPlan(exports.ROUND_ACTION_RECORD, snap.round, maxRounds, fullBasis, [], reds, oranges);
|
|
120
207
|
}
|
|
121
|
-
const basis = new diff_basis_1.DiffBasis(
|
|
122
|
-
const changed = this.git(repoRoot, ['diff', '--name-only',
|
|
208
|
+
const basis = new diff_basis_1.DiffBasis(snap.headSha, fullBasis.headSha, false, [], `git diff ${snap.headSha} ${fullBasis.headSha}`, `git diff ${snap.headSha} ${fullBasis.headSha} -- <file>`, fullBasis.hashMainHead);
|
|
209
|
+
const changed = this.git(repoRoot, ['diff', '--name-only', snap.headSha, fullBasis.headSha])
|
|
123
210
|
.split('\n').filter((f) => f.trim() !== '');
|
|
124
|
-
return new ReviewRoundPlan(exports.ROUND_ACTION_REVIEW,
|
|
211
|
+
return new ReviewRoundPlan(exports.ROUND_ACTION_REVIEW, snap.round + 1, maxRounds, basis, changed, reds, oranges);
|
|
125
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* Record the author's fixes for the latest completed round — one response per RED (a round that is not
|
|
215
|
+
* the last) or ORANGE (the final round) — as `review-round<N>-fixes.json`.
|
|
216
|
+
*
|
|
217
|
+
* A record that still HOLDS is never overwritten. One that no longer holds — its `toHead` left HEAD's
|
|
218
|
+
* history, which every `wp-start-upsert-pr` squash-update does — is kept beside it as
|
|
219
|
+
* `review-round<N>-fixes.json.superseded-<k>` and a fresh record is written, so re-recording is always
|
|
220
|
+
* the way past a stale record and nothing is ever lost.
|
|
221
|
+
*/
|
|
126
222
|
writeRemediation(repoRoot, summaryPath, receipt, json) {
|
|
127
|
-
|
|
223
|
+
const snap = this.snapshot(summaryPath, receipt);
|
|
224
|
+
if (!snap.complete) {
|
|
128
225
|
throw new rules_config_1.InformAiError('wp-write-review-fixes: the active reviewer round is not complete yet.');
|
|
129
226
|
}
|
|
227
|
+
const blocking = this.blockingIds(summaryPath, snap);
|
|
228
|
+
if (blocking.length === 0) {
|
|
229
|
+
throw new rules_config_1.InformAiError(`wp-write-review-fixes: round ${snap.round} has no red or orange verdict to fix.`);
|
|
230
|
+
}
|
|
231
|
+
const out = this.fixesPath(summaryPath, snap.round);
|
|
232
|
+
const holding = this.validFixes(repoRoot, summaryPath, snap);
|
|
233
|
+
if (holding !== null) {
|
|
234
|
+
throw new rules_config_1.InformAiError(`wp-write-review-fixes: the fixes for round ${snap.round} are already recorded in ${out}, and `
|
|
235
|
+
+ `that record still holds (its fixed commit ${holding.toHead.slice(0, 8)} is in HEAD's history), so it is not `
|
|
236
|
+
+ 'overwritten. Nothing more to record: re-run pnpm wp-review-upsert-pr, or pnpm wp-finish-upsert-pr after the last round.');
|
|
237
|
+
}
|
|
130
238
|
this.assertClean(repoRoot);
|
|
131
239
|
const currentHead = this.git(repoRoot, ['rev-parse', 'HEAD']);
|
|
132
|
-
|
|
133
|
-
if (reds.length === 0)
|
|
134
|
-
throw new rules_config_1.InformAiError('wp-write-review-fixes: the completed round has no red verdict to remediate.');
|
|
135
|
-
if (currentHead === receipt.headSha || this.git(repoRoot, ['diff', '--name-only', receipt.headSha, currentHead]) === '') {
|
|
240
|
+
if (currentHead === snap.headSha || this.git(repoRoot, ['diff', '--name-only', snap.headSha, currentHead]) === '') {
|
|
136
241
|
throw new rules_config_1.InformAiError('wp-write-review-fixes: remediation must contain a committed, non-empty delta after the reviewed HEAD.');
|
|
137
242
|
}
|
|
138
243
|
const raw = this.parseObject(json, 'wp-write-review-fixes: input must be one JSON object.');
|
|
@@ -140,66 +245,79 @@ let ReviewRoundStateService = class ReviewRoundStateService {
|
|
|
140
245
|
const model = this.requiredText(raw, 'model');
|
|
141
246
|
const responses = this.responses(raw['responses']);
|
|
142
247
|
const ids = responses.map((r) => r.checklistId);
|
|
143
|
-
const unknown = ids.filter((id) => !
|
|
144
|
-
const missing =
|
|
248
|
+
const unknown = ids.filter((id) => !blocking.includes(id));
|
|
249
|
+
const missing = blocking.filter((id) => !ids.includes(id));
|
|
145
250
|
if (unknown.length > 0 || missing.length > 0) {
|
|
146
|
-
throw new rules_config_1.InformAiError(`wp-write-review-fixes: responses must cover exactly the red checklist(s). `
|
|
251
|
+
throw new rules_config_1.InformAiError(`wp-write-review-fixes: responses must cover exactly the red/orange checklist(s) of round ${snap.round}. `
|
|
147
252
|
+ `Unknown: ${unknown.join(', ') || '(none)'}. Missing: ${missing.join(', ') || '(none)'}.`);
|
|
148
253
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
this.atomicFile.writeJsonAtomic(out, record);
|
|
254
|
+
this.supersede(out);
|
|
255
|
+
this.atomicFile.writeJsonAtomic(out, new ReviewRemediation(agent, model, snap.headSha, currentHead, responses));
|
|
152
256
|
return out;
|
|
153
257
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
258
|
+
/**
|
|
259
|
+
* Keep a record that no longer holds beside the new one, as `<file>.superseded-<k>` — a name no round
|
|
260
|
+
* scan reads, so it is history and never a live record.
|
|
261
|
+
*/
|
|
262
|
+
supersede(file) {
|
|
263
|
+
if (!fs.existsSync(file))
|
|
264
|
+
return;
|
|
265
|
+
let k = 1;
|
|
266
|
+
while (fs.existsSync(`${file}.superseded-${k}`))
|
|
267
|
+
k++;
|
|
268
|
+
fs.renameSync(file, `${file}.superseded-${k}`);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* The round's recorded fixes, or null when there are none that still hold: written from the reviewed
|
|
272
|
+
* HEAD, to a later commit that is still in HEAD's history, covering exactly the round's red/orange set.
|
|
273
|
+
*/
|
|
274
|
+
validFixes(repoRoot, summaryPath, snap) {
|
|
275
|
+
const record = this.readFixes(repoRoot, summaryPath, snap.round);
|
|
276
|
+
if (record === null || record.fromHead !== snap.headSha)
|
|
157
277
|
return null;
|
|
158
|
-
const
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
const ids = responses.map((r) => r.checklistId);
|
|
162
|
-
if (this.text(raw['agent']) === '' || this.text(raw['model']) === ''
|
|
163
|
-
|| raw['fromHead'] !== receipt.headSha || raw['toHead'] !== currentHead
|
|
164
|
-
|| currentHead === receipt.headSha || reds.some((id) => !ids.includes(id))
|
|
165
|
-
|| ids.some((id) => !reds.includes(id)))
|
|
278
|
+
const blocking = this.blockingIds(summaryPath, snap);
|
|
279
|
+
const ids = record.responses.map((r) => r.checklistId);
|
|
280
|
+
if (blocking.some((id) => !ids.includes(id)) || ids.some((id) => !blocking.includes(id)))
|
|
166
281
|
return null;
|
|
167
|
-
return
|
|
282
|
+
return record;
|
|
168
283
|
}
|
|
169
|
-
|
|
284
|
+
/**
|
|
285
|
+
* checklist id → the dashboard stamp for every ORANGE whose fix the author recorded (issue #1053):
|
|
286
|
+
* "orange at <fromHead>, author-fixed in <toHead>, not re-reviewed: <resolution>". An orange with no
|
|
287
|
+
* valid record is absent, and so still blocks.
|
|
288
|
+
*/
|
|
289
|
+
orangeFixes(repoRoot, summaryPath, results) {
|
|
170
290
|
const out = {};
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
291
|
+
for (const result of results) {
|
|
292
|
+
if (result.status !== rules_config_1.VERDICT_ORANGE || result.problem !== '')
|
|
293
|
+
continue;
|
|
294
|
+
const record = this.readFixes(repoRoot, summaryPath, result.round);
|
|
295
|
+
const response = record?.responses.find((r) => r.checklistId === result.id);
|
|
296
|
+
if (record === null || response === undefined)
|
|
297
|
+
continue;
|
|
298
|
+
out[result.id] = `orange at ${record.fromHead.slice(0, 8)}, author-fixed in ${record.toHead.slice(0, 8)}, `
|
|
299
|
+
+ `not re-reviewed: ${response.resolution}`;
|
|
179
300
|
}
|
|
180
301
|
return out;
|
|
181
302
|
}
|
|
182
|
-
auditTrail(summaryPath, checklistId,
|
|
183
|
-
if (receipt === null || receipt.round < 1)
|
|
184
|
-
return '';
|
|
303
|
+
auditTrail(summaryPath, checklistId, maxRounds) {
|
|
185
304
|
const lines = [];
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const verdict = this.readObject(
|
|
189
|
-
const record = this.readObject(path.join(dir, `review-${checklistId}.provenance.json`));
|
|
305
|
+
const highest = this.highestRound(summaryPath);
|
|
306
|
+
for (let round = 1; round <= highest; round++) {
|
|
307
|
+
const verdict = this.readObject(this.reviewJson.checklistResultPath(summaryPath, checklistId, round));
|
|
190
308
|
if (verdict !== null) {
|
|
191
|
-
lines.push(`#### Reviewer round ${round} of ${
|
|
192
|
-
lines.push(`Reviewed SHA: ${this.
|
|
309
|
+
lines.push(`#### Reviewer round ${round} of ${maxRounds}`);
|
|
310
|
+
lines.push(`Reviewed SHA: ${this.provenance.read(summaryPath, checklistId, round)?.headSha || '(unknown)'}`);
|
|
193
311
|
lines.push(`Status: ${this.text(verdict['status']).toUpperCase()}`);
|
|
194
312
|
lines.push('', this.text(verdict['output']), '');
|
|
195
313
|
}
|
|
196
|
-
const remediation = this.readObject(this.
|
|
314
|
+
const remediation = this.readObject(this.fixesPath(summaryPath, round));
|
|
197
315
|
if (remediation !== null && Array.isArray(remediation['responses'])) {
|
|
198
316
|
const response = remediation['responses'].find((entry) => typeof entry === 'object' && entry !== null && !Array.isArray(entry)
|
|
199
317
|
&& entry['checklistId'] === checklistId);
|
|
200
318
|
if (typeof response === 'object' && response !== null && !Array.isArray(response)) {
|
|
201
319
|
const raw = response;
|
|
202
|
-
lines.push(`#### Author
|
|
320
|
+
lines.push(`#### Author fix after round ${round}`);
|
|
203
321
|
lines.push(`Range: ${this.text(remediation['fromHead'])}..${this.text(remediation['toHead'])}`);
|
|
204
322
|
lines.push('', this.text(raw['resolution']), '');
|
|
205
323
|
}
|
|
@@ -207,6 +325,42 @@ let ReviewRoundStateService = class ReviewRoundStateService {
|
|
|
207
325
|
}
|
|
208
326
|
return lines.join('\n').trim();
|
|
209
327
|
}
|
|
328
|
+
blockingIds(summaryPath, snap) {
|
|
329
|
+
return [
|
|
330
|
+
...this.checklistIdsWithStatus(summaryPath, snap, rules_config_1.VERDICT_RED),
|
|
331
|
+
...this.checklistIdsWithStatus(summaryPath, snap, rules_config_1.VERDICT_ORANGE),
|
|
332
|
+
];
|
|
333
|
+
}
|
|
334
|
+
/** A round's fix record, provided its `toHead` is still in HEAD's history; else null. */
|
|
335
|
+
readFixes(repoRoot, summaryPath, round) {
|
|
336
|
+
const raw = this.readObject(this.fixesPath(summaryPath, round));
|
|
337
|
+
if (raw === null)
|
|
338
|
+
return null;
|
|
339
|
+
const responses = this.responsesOrEmpty(raw['responses']);
|
|
340
|
+
const fromHead = this.text(raw['fromHead']);
|
|
341
|
+
const toHead = this.text(raw['toHead']);
|
|
342
|
+
if (this.text(raw['agent']) === '' || this.text(raw['model']) === '' || responses.length === 0
|
|
343
|
+
|| fromHead === '' || toHead === '' || fromHead === toHead || !this.isAncestorOfHead(repoRoot, toHead))
|
|
344
|
+
return null;
|
|
345
|
+
return new ReviewRemediation(this.text(raw['agent']), this.text(raw['model']), fromHead, toHead, responses);
|
|
346
|
+
}
|
|
347
|
+
everyVerdictIn(summaryPath, roster, round) {
|
|
348
|
+
return roster.length > 0 && roster.every((id) => this.hasVerdict(summaryPath, id, round));
|
|
349
|
+
}
|
|
350
|
+
/** `review-round<N>-<id>.json` → `<id>`; '' for the fixes record, a provenance file, or anything else. */
|
|
351
|
+
verdictIdOf(name) {
|
|
352
|
+
const match = ROUND_FILE.exec(name);
|
|
353
|
+
if (match === null)
|
|
354
|
+
return '';
|
|
355
|
+
const id = match[2];
|
|
356
|
+
return id === FIXES_ID || id.endsWith(PROVENANCE_SUFFIX) ? '' : id;
|
|
357
|
+
}
|
|
358
|
+
roundFiles(summaryPath) {
|
|
359
|
+
const dir = path.dirname(summaryPath);
|
|
360
|
+
if (!fs.existsSync(dir))
|
|
361
|
+
return [];
|
|
362
|
+
return fs.readdirSync(dir).filter((name) => ROUND_FILE.test(name));
|
|
363
|
+
}
|
|
210
364
|
responses(value) {
|
|
211
365
|
const responses = this.responsesOrEmpty(value);
|
|
212
366
|
if (responses.length === 0)
|
|
@@ -278,6 +432,23 @@ let ReviewRoundStateService = class ReviewRoundStateService {
|
|
|
278
432
|
if (status !== '')
|
|
279
433
|
throw new rules_config_1.InformAiError('wp-write-review-fixes: commit every remediation and leave no staged, unstaged, or untracked files first.');
|
|
280
434
|
}
|
|
435
|
+
/**
|
|
436
|
+
* `git merge-base --is-ancestor`: exit 0 = yes, 1 = no. A `sha` git does not know (exit 128 with
|
|
437
|
+
* "Not a valid commit name") is also no — the commit is gone from this clone, so it is not in HEAD's
|
|
438
|
+
* history. Anything else is a real failure and refuses.
|
|
439
|
+
*/
|
|
440
|
+
isAncestorOfHead(repoRoot, sha) {
|
|
441
|
+
const result = (0, child_process_1.spawnSync)('git', ['merge-base', '--is-ancestor', sha, 'HEAD'], { cwd: repoRoot, encoding: 'utf8' });
|
|
442
|
+
if (result.status === 0)
|
|
443
|
+
return true;
|
|
444
|
+
if (result.status === 1 || /not a valid (commit|object) name/i.test(result.stderr ?? ''))
|
|
445
|
+
return false;
|
|
446
|
+
const detail = (result.stderr ?? '').trim() || result.error?.message || `exit ${result.status ?? 'unknown'}`;
|
|
447
|
+
const message = `Review-round Git command failed: git merge-base --is-ancestor ${sha} HEAD\n${detail}`;
|
|
448
|
+
if (result.error !== undefined)
|
|
449
|
+
throw new rules_config_1.InformAiError(message, { cause: result.error });
|
|
450
|
+
throw new rules_config_1.InformAiError(message);
|
|
451
|
+
}
|
|
281
452
|
git(repoRoot, args) {
|
|
282
453
|
const result = (0, child_process_1.spawnSync)('git', args, { cwd: repoRoot, encoding: 'utf8' });
|
|
283
454
|
if (result.status === 0)
|