mandrel 2.100.0 → 2.101.0
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/.agents/agents/story-worker.md +7 -1
- package/.agents/docs/agentrc-reference.json +3 -0
- package/.agents/docs/configuration.md +3 -0
- package/.agents/rules/ci-remediation.md +8 -0
- package/.agents/schemas/agentrc.schema.json +26 -0
- package/.agents/schemas/story-deliver-terminal.schema.json +17 -3
- package/.agents/schemas/validation-evidence.schema.json +10 -0
- package/.agents/scripts/lib/close-lock-events.js +18 -5
- package/.agents/scripts/lib/close-validation/gates.js +6 -1
- package/.agents/scripts/lib/close-validation/runner.js +10 -11
- package/.agents/scripts/lib/close-validation/test-delta.js +124 -0
- package/.agents/scripts/lib/config/pull-request.js +25 -0
- package/.agents/scripts/lib/config-settings-schema-delivery.js +22 -0
- package/.agents/scripts/lib/config-settings-schema.js +5 -0
- package/.agents/scripts/lib/coverage-capture-delta.js +2 -1
- package/.agents/scripts/lib/generated/agentrc-validator.js +2 -2
- package/.agents/scripts/lib/git/sync-from-base.js +4 -2
- package/.agents/scripts/lib/orchestration/ci-red-handling.js +4 -3
- package/.agents/scripts/lib/orchestration/ci-rerun-guard.js +81 -25
- package/.agents/scripts/lib/orchestration/handoff-state.js +41 -0
- package/.agents/scripts/lib/orchestration/review-providers/code-review.js +97 -28
- package/.agents/scripts/lib/orchestration/single-story-close/phases/base-sync.js +7 -0
- package/.agents/scripts/lib/orchestration/single-story-close/phases/close-validation.js +22 -4
- package/.agents/scripts/lib/orchestration/single-story-close/phases/confirm-merge.js +104 -57
- package/.agents/scripts/lib/orchestration/single-story-close/phases/merge-wait-recovery.js +16 -16
- package/.agents/scripts/lib/orchestration/single-story-close/phases/normalize-pr-title.js +28 -13
- package/.agents/scripts/lib/orchestration/single-story-close/phases/open-pr.js +1 -0
- package/.agents/scripts/lib/orchestration/single-story-close/phases/pr-body-trailers.js +38 -0
- package/.agents/scripts/lib/orchestration/single-story-close/phases/pre-push.js +24 -16
- package/.agents/scripts/lib/orchestration/single-story-close/phases/pull-request.js +18 -7
- package/.agents/scripts/lib/orchestration/single-story-close/runner.js +60 -34
- package/.agents/scripts/lib/orchestration/story-deliver-terminal.js +1 -1
- package/.agents/scripts/lib/orchestration/story-handoff.js +36 -9
- package/.agents/scripts/lib/test-run-credit.js +26 -0
- package/.agents/scripts/lib/validation-evidence.js +6 -0
- package/.agents/workflows/helpers/deliver-reference.md +28 -1
- package/docs/CHANGELOG.md +18 -0
- package/package.json +1 -1
|
@@ -31,7 +31,11 @@ import {
|
|
|
31
31
|
import { pollUntil } from '../../../util/poll-loop.js';
|
|
32
32
|
import { defaultSleep } from '../../../util/sleep.js';
|
|
33
33
|
import { applyBehindUpdate } from '../../behind-recovery.js';
|
|
34
|
-
import {
|
|
34
|
+
import {
|
|
35
|
+
checkVerdict,
|
|
36
|
+
classifyRollupEntry,
|
|
37
|
+
isRerunPermitted,
|
|
38
|
+
} from '../../check-state.js';
|
|
35
39
|
import { recordRequiredRed as defaultRecordRequiredRed } from '../../ci-red-handling.js';
|
|
36
40
|
import {
|
|
37
41
|
emitMergeFlipFailed as defaultEmitMergeFlipFailed,
|
|
@@ -54,6 +58,7 @@ import {
|
|
|
54
58
|
parseWorkflowRunId,
|
|
55
59
|
pollIntervalMs,
|
|
56
60
|
probeSettlesAsyncWait,
|
|
61
|
+
readRunName,
|
|
57
62
|
readRunSummary,
|
|
58
63
|
resolveAdvisoryGateVerdict,
|
|
59
64
|
} from '../../merge-poll.js';
|
|
@@ -179,6 +184,37 @@ async function readInMergeQueue({
|
|
|
179
184
|
return typeof queue?.inQueue === 'boolean' ? queue.inQueue : undefined;
|
|
180
185
|
}
|
|
181
186
|
|
|
187
|
+
const CHECK_STATE_OF_VERDICT = Object.freeze({
|
|
188
|
+
pass: 'success',
|
|
189
|
+
pending: 'pending',
|
|
190
|
+
fail: 'failure',
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* `name → success|pending|failure` for the head's rollup, the red-fix guard's
|
|
195
|
+
* `checks` input. A name seen twice keeps its worst state.
|
|
196
|
+
*
|
|
197
|
+
* @param {unknown} statusCheckRollup
|
|
198
|
+
* @returns {Record<string, string>}
|
|
199
|
+
*/
|
|
200
|
+
function deriveCheckStates(statusCheckRollup) {
|
|
201
|
+
const rank = ['success', 'pending', 'failure'];
|
|
202
|
+
const states = {};
|
|
203
|
+
for (const check of Array.isArray(statusCheckRollup)
|
|
204
|
+
? statusCheckRollup
|
|
205
|
+
: []) {
|
|
206
|
+
const name = readRunName(check);
|
|
207
|
+
if (!name) continue;
|
|
208
|
+
const state =
|
|
209
|
+
CHECK_STATE_OF_VERDICT[checkVerdict(classifyRollupEntry(check))];
|
|
210
|
+
const prior = states[name];
|
|
211
|
+
if (!prior || rank.indexOf(state) > rank.indexOf(prior)) {
|
|
212
|
+
states[name] = state;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return states;
|
|
216
|
+
}
|
|
217
|
+
|
|
182
218
|
/**
|
|
183
219
|
* One probe per poll iteration. A failed or timed-out read degrades to
|
|
184
220
|
* `{ checksStatus: 'pending', error }` so a flaky read is never a verdict.
|
|
@@ -235,6 +271,7 @@ export async function readPrWaitProbe({
|
|
|
235
271
|
readFn: readRequiredCheckNamesFn,
|
|
236
272
|
}),
|
|
237
273
|
redHeadRuns: deriveRedHeadRuns(view?.statusCheckRollup),
|
|
274
|
+
checkStates: deriveCheckStates(view?.statusCheckRollup),
|
|
238
275
|
headSha: readString(view?.headRefOid),
|
|
239
276
|
autoMergeArmed: readAutoMergeArmed(view),
|
|
240
277
|
};
|
|
@@ -327,7 +364,7 @@ export function resolveBudgetAnchorMs({ createdAt, enabledAt, fallbackMs }) {
|
|
|
327
364
|
* @param {{ storyId: number, blockClass: string }} args
|
|
328
365
|
* @returns {string}
|
|
329
366
|
*/
|
|
330
|
-
function advisoryGateRemedy({ storyId, blockClass }) {
|
|
367
|
+
function advisoryGateRemedy({ storyId, blockClass, redRecord }) {
|
|
331
368
|
const mergeable =
|
|
332
369
|
'GitHub reports this PR **mergeable regardless** ' +
|
|
333
370
|
'(`mergeStateStatus=UNSTABLE`) — the check that blocked is **advisory** ' +
|
|
@@ -348,11 +385,21 @@ function advisoryGateRemedy({ storyId, blockClass }) {
|
|
|
348
385
|
'`delivery.ci.rerunAdvisory`) if you believe it flaked, or exempt ' +
|
|
349
386
|
'the job via `delivery.ci.advisoryAllowlist`.';
|
|
350
387
|
return (
|
|
351
|
-
`${mergeable}\n\n${act}\n\
|
|
388
|
+
`${mergeable}\n\n${disarmedOn(redRecord)}${act}\n\n` +
|
|
389
|
+
'Then resume the land — once every disarming check reads green on this ' +
|
|
390
|
+
'head, the resume re-arms auto-merge and lands it:\n\n' +
|
|
352
391
|
`\`\`\`bash\n${NEXT_COMMANDS.resumeLand(storyId)}\n\`\`\``
|
|
353
392
|
);
|
|
354
393
|
}
|
|
355
394
|
|
|
395
|
+
/** The disarming checks the advisory digest recorded, as a remedy line. */
|
|
396
|
+
function disarmedOn(redRecord) {
|
|
397
|
+
const failures = redRecord?.failures ?? [];
|
|
398
|
+
if (failures.length === 0) return '';
|
|
399
|
+
const named = failures.map((f) => `\`${f.name}\`=${f.outcome}`).join(', ');
|
|
400
|
+
return `**Disarming check(s):** ${named}.\n\n`;
|
|
401
|
+
}
|
|
402
|
+
|
|
356
403
|
/**
|
|
357
404
|
* @param {{ storyId: number, prNumber: number|null, blockClass: string }} args
|
|
358
405
|
* @returns {string}
|
|
@@ -365,7 +412,7 @@ function unlandedRemedy({ storyId, prNumber, blockClass, redRecord }) {
|
|
|
365
412
|
blockClass === ADVISORY_GATE_INCONCLUSIVE_CLASS ||
|
|
366
413
|
blockClass === ADVISORY_GATE_RED_CLASS
|
|
367
414
|
) {
|
|
368
|
-
return advisoryGateRemedy({ storyId, blockClass });
|
|
415
|
+
return advisoryGateRemedy({ storyId, blockClass, redRecord });
|
|
369
416
|
}
|
|
370
417
|
return (
|
|
371
418
|
`Resolve the underlying condition (branch protection, required checks, ` +
|
|
@@ -707,18 +754,16 @@ async function maybeRerunAdvisory({
|
|
|
707
754
|
* already re-ran, enriches the rest, spends any rerun allowance, and disarms
|
|
708
755
|
* BEFORE returning a block so the PR cannot merge out from under it.
|
|
709
756
|
*/
|
|
710
|
-
async function resolveAdvisoryUnlanded({
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
elapsedSeconds,
|
|
721
|
-
}) {
|
|
757
|
+
async function resolveAdvisoryUnlanded(ctx, probe, elapsedSeconds) {
|
|
758
|
+
const {
|
|
759
|
+
blockOnAdvisoryFailure,
|
|
760
|
+
advisoryAllowlist,
|
|
761
|
+
rerunState,
|
|
762
|
+
prNumber,
|
|
763
|
+
ghTimeoutMs,
|
|
764
|
+
progress,
|
|
765
|
+
} = ctx;
|
|
766
|
+
const gh = ctx.injectedGh;
|
|
722
767
|
const advisory = decideAdvisoryGateBlock({
|
|
723
768
|
probe,
|
|
724
769
|
blockOnAdvisoryFailure,
|
|
@@ -752,15 +797,34 @@ async function resolveAdvisoryUnlanded({
|
|
|
752
797
|
rerunAllowance: rerunState.allowance,
|
|
753
798
|
});
|
|
754
799
|
progress?.('CONFIRM', `🛑 PR #${prNumber}: ${verdict.reason}`);
|
|
755
|
-
|
|
800
|
+
// Advisory digest: a same-head re-arm waits for these checks to go green.
|
|
801
|
+
const failures = blockingRuns.map((run) => ({
|
|
802
|
+
...failureOfRun(run),
|
|
803
|
+
required: false,
|
|
804
|
+
}));
|
|
805
|
+
const redRecord = await recordRed(ctx, probe, failures);
|
|
756
806
|
return {
|
|
757
807
|
prProbe: probe,
|
|
758
808
|
budget: { exhausted: false, elapsedSeconds },
|
|
759
809
|
blockClassOverride: verdict.blockClass,
|
|
760
|
-
reasonOverride: verdict.reason
|
|
810
|
+
reasonOverride: `${verdict.reason} Disarming check(s): ${describeFailures(failures)}.`,
|
|
811
|
+
redRecord: { ...redRecord, failures },
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
/** `{ name, outcome }` of a red rollup run, as the CI digest records it. */
|
|
816
|
+
function failureOfRun(run) {
|
|
817
|
+
return {
|
|
818
|
+
name: run?.name ?? 'unknown',
|
|
819
|
+
outcome: String(run?.conclusion ?? 'failure').toLowerCase(),
|
|
761
820
|
};
|
|
762
821
|
}
|
|
763
822
|
|
|
823
|
+
/** `policy-impact=failure, …` — the checks a block names. */
|
|
824
|
+
function describeFailures(failures) {
|
|
825
|
+
return failures.map((f) => `${f.name}=${f.outcome}`).join(', ');
|
|
826
|
+
}
|
|
827
|
+
|
|
764
828
|
/**
|
|
765
829
|
* An enqueued PR reads BLOCKED with every check green, which the classifier
|
|
766
830
|
* would call human-required — but the queue lands it unattended.
|
|
@@ -774,27 +838,23 @@ function queuedExhaustionVerdict(probe, cumulativeMs) {
|
|
|
774
838
|
}
|
|
775
839
|
|
|
776
840
|
/**
|
|
777
|
-
* A `checks-failed` fail-fast
|
|
778
|
-
*
|
|
779
|
-
*
|
|
841
|
+
* A `checks-failed` fail-fast or an advisory block gets the same first-red
|
|
842
|
+
* handling as the watcher: disarm, then write the CI digest `file-ci-gap.js`
|
|
843
|
+
* and the re-arm guard read. Never throws — the block stands regardless.
|
|
780
844
|
*
|
|
781
845
|
* @returns {Promise<object>} the `recordRequiredRed` outcome.
|
|
782
846
|
*/
|
|
783
|
-
async function
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
const failures = (probe?.redHeadRuns ?? []).map((run) => ({
|
|
795
|
-
name: run.name ?? 'unknown',
|
|
796
|
-
outcome: String(run.conclusion ?? 'failure').toLowerCase(),
|
|
797
|
-
}));
|
|
847
|
+
async function recordRed(ctx, probe, failures) {
|
|
848
|
+
const {
|
|
849
|
+
storyId,
|
|
850
|
+
prNumber,
|
|
851
|
+
cwd,
|
|
852
|
+
config,
|
|
853
|
+
progress,
|
|
854
|
+
disarmAutoMergeFn,
|
|
855
|
+
recordRequiredRedFn,
|
|
856
|
+
} = ctx;
|
|
857
|
+
const gh = ctx.injectedGh;
|
|
798
858
|
try {
|
|
799
859
|
const record = await recordRequiredRedFn({
|
|
800
860
|
storyId,
|
|
@@ -1200,17 +1260,11 @@ async function settleChecksFailed(ctx, decision, probe) {
|
|
|
1200
1260
|
budget: { exhausted: false, elapsedSeconds: decision.elapsedSeconds },
|
|
1201
1261
|
blockClassOverride: failFast.blockClass,
|
|
1202
1262
|
reasonOverride: failFast.reason,
|
|
1203
|
-
redRecord: await
|
|
1204
|
-
|
|
1205
|
-
prNumber: ctx.prNumber,
|
|
1263
|
+
redRecord: await recordRed(
|
|
1264
|
+
ctx,
|
|
1206
1265
|
probe,
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
gh: ctx.injectedGh,
|
|
1210
|
-
progress: ctx.progress,
|
|
1211
|
-
disarmAutoMergeFn: ctx.disarmAutoMergeFn,
|
|
1212
|
-
recordRequiredRedFn: ctx.recordRequiredRedFn,
|
|
1213
|
-
}),
|
|
1266
|
+
(probe?.redHeadRuns ?? []).map(failureOfRun),
|
|
1267
|
+
),
|
|
1214
1268
|
});
|
|
1215
1269
|
}
|
|
1216
1270
|
|
|
@@ -1273,18 +1327,11 @@ async function settleProvisional(ctx, decision, probe) {
|
|
|
1273
1327
|
* @returns {Promise<{ state: object, outcome: object|null }>}
|
|
1274
1328
|
*/
|
|
1275
1329
|
async function recoverOpenPr(ctx, decision, probe) {
|
|
1276
|
-
const advisory = await resolveAdvisoryUnlanded(
|
|
1330
|
+
const advisory = await resolveAdvisoryUnlanded(
|
|
1331
|
+
ctx,
|
|
1277
1332
|
probe,
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
rerunState: ctx.rerunState,
|
|
1281
|
-
prNumber: ctx.prNumber,
|
|
1282
|
-
gh: ctx.injectedGh,
|
|
1283
|
-
ghTimeoutMs: ctx.ghTimeoutMs,
|
|
1284
|
-
progress: ctx.progress,
|
|
1285
|
-
disarmAutoMergeFn: ctx.disarmAutoMergeFn,
|
|
1286
|
-
elapsedSeconds: decision.elapsedSeconds,
|
|
1287
|
-
});
|
|
1333
|
+
decision.elapsedSeconds,
|
|
1334
|
+
);
|
|
1288
1335
|
if (advisory) {
|
|
1289
1336
|
return { state: decision.state, outcome: await blockWith(ctx, advisory) };
|
|
1290
1337
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* phases/merge-wait-recovery.js — the merge wait's answer to a PR `main`
|
|
3
3
|
* moved under. DIRTY: sync in the Story worktree and push, spending the
|
|
4
4
|
* BEHIND budget; any failure hands back a `failed` / `base-sync` outcome,
|
|
5
|
-
* labels untouched. Un-armed: re-arm once per head SHA
|
|
6
|
-
* guard and the arm policy.
|
|
5
|
+
* labels untouched. Un-armed: re-arm once per head SHA and guard verdict,
|
|
6
|
+
* behind the red-fix guard and the arm policy.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { getCiDelivery } from '../../../config/ci.js';
|
|
@@ -20,6 +20,7 @@ import { integrateRemoteStoryBranch as defaultIntegrateRemote } from './story-br
|
|
|
20
20
|
|
|
21
21
|
/** The red-fix guard verdicts under which a re-arm is allowed. */
|
|
22
22
|
const REARM_VERDICTS = Object.freeze([
|
|
23
|
+
'advisory-cleared',
|
|
23
24
|
'clean',
|
|
24
25
|
'fix-at-source',
|
|
25
26
|
'rerun-permitted',
|
|
@@ -254,29 +255,28 @@ function isUnarmedOpenPr(probe, ctx) {
|
|
|
254
255
|
);
|
|
255
256
|
}
|
|
256
257
|
|
|
257
|
-
/**
|
|
258
|
-
|
|
258
|
+
/**
|
|
259
|
+
* The red-fix guard: a CI digest recorded against this head blocks it, unless
|
|
260
|
+
* every recorded failure is advisory and the probe reads each green.
|
|
261
|
+
*/
|
|
262
|
+
function rearmGuard(ctx, headSha, checks) {
|
|
259
263
|
const digest = ctx.readCiDigestFn({
|
|
260
264
|
storyId: ctx.storyId,
|
|
261
265
|
tempRoot: ctx.config?.project?.paths?.tempRoot ?? 'temp',
|
|
262
266
|
cwd: ctx.cwd,
|
|
263
267
|
});
|
|
264
|
-
return classifyGreenVerdict({ digest, headSha });
|
|
268
|
+
return classifyGreenVerdict({ digest, headSha, checks });
|
|
265
269
|
}
|
|
266
270
|
|
|
267
|
-
/** Re-arm an open, un-armed, not-red PR once per head; never a terminal. */
|
|
271
|
+
/** Re-arm an open, un-armed, not-red PR once per head and verdict; never a terminal. */
|
|
268
272
|
export async function maybeRearmPr(ctx, probe) {
|
|
269
273
|
const headSha = probe?.headSha;
|
|
270
|
-
if (
|
|
271
|
-
!isUnarmedOpenPr(probe, ctx) ||
|
|
272
|
-
!headSha ||
|
|
273
|
-
ctx.rearmedHeads.has(headSha)
|
|
274
|
-
) {
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
ctx.rearmedHeads.add(headSha);
|
|
274
|
+
if (!isUnarmedOpenPr(probe, ctx) || !headSha) return;
|
|
278
275
|
if (getCiDelivery(ctx.config).autoMerge === 'strict') return;
|
|
279
|
-
const guard = rearmGuard(ctx, headSha);
|
|
276
|
+
const guard = rearmGuard(ctx, headSha, probe.checkStates);
|
|
277
|
+
const attempt = `${headSha}:${guard.verdict}`;
|
|
278
|
+
if (ctx.rearmedHeads.has(attempt)) return;
|
|
279
|
+
ctx.rearmedHeads.add(attempt);
|
|
280
280
|
if (!REARM_VERDICTS.includes(guard.verdict)) {
|
|
281
281
|
ctx.progress?.(
|
|
282
282
|
'CONFIRM',
|
|
@@ -290,7 +290,7 @@ export async function maybeRearmPr(ctx, probe) {
|
|
|
290
290
|
ctx.progress?.(
|
|
291
291
|
'CONFIRM',
|
|
292
292
|
armed?.enabled
|
|
293
|
-
? `🔁 PR #${ctx.prNumber} lost its auto-merge request on head ${headSha.slice(0, 7)} — re-armed.`
|
|
293
|
+
? `🔁 PR #${ctx.prNumber} lost its auto-merge request on head ${headSha.slice(0, 7)} — re-armed (${guard.reason}).`
|
|
294
294
|
: `⚠️ PR #${ctx.prNumber} re-arm failed (${armed?.reason ?? 'unknown'}) — still waiting.`,
|
|
295
295
|
);
|
|
296
296
|
}
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
pickDominantType,
|
|
15
15
|
shapeDescription,
|
|
16
16
|
} from './conventional-subject.js';
|
|
17
|
+
import { liftTrailers } from './pr-body-trailers.js';
|
|
17
18
|
|
|
18
19
|
const DEFAULT_CONVENTIONAL_TYPE = 'chore';
|
|
19
20
|
|
|
@@ -116,17 +117,20 @@ function synthesizeSubject({ description, storyId, commitMessages }) {
|
|
|
116
117
|
}
|
|
117
118
|
|
|
118
119
|
/**
|
|
119
|
-
* `Closes #<id>` auto-closes the Story;
|
|
120
|
-
* spec, for repos that squash with the
|
|
120
|
+
* `Closes #<id>` auto-closes the Story; lifted trailers follow the marker and
|
|
121
|
+
* a breaking footer goes LAST, per the spec, for repos that squash with the
|
|
122
|
+
* PR body.
|
|
121
123
|
*
|
|
122
|
-
* @param {{ storyId: number|string, breakingNotes?: string[]
|
|
124
|
+
* @param {{ storyId: number|string, breakingNotes?: string[],
|
|
125
|
+
* trailerBlock?: string[] }} args
|
|
123
126
|
* @returns {string}
|
|
124
127
|
*/
|
|
125
|
-
function buildPrBody({ storyId, breakingNotes }) {
|
|
128
|
+
function buildPrBody({ storyId, breakingNotes, trailerBlock = [] }) {
|
|
126
129
|
const lines = [
|
|
127
130
|
`Closes #${storyId}`,
|
|
128
131
|
'',
|
|
129
132
|
'_Auto-opened by `/mandrel-deliver`._',
|
|
133
|
+
...trailerBlock,
|
|
130
134
|
];
|
|
131
135
|
if (breakingNotes.length > 0) {
|
|
132
136
|
lines.push('', `BREAKING CHANGE: ${breakingNotes.join(' ')}`);
|
|
@@ -134,13 +138,25 @@ function buildPrBody({ storyId, breakingNotes }) {
|
|
|
134
138
|
return lines.join('\n');
|
|
135
139
|
}
|
|
136
140
|
|
|
141
|
+
/**
|
|
142
|
+
* @param {string[]} breakingNotes
|
|
143
|
+
* @param {(tag: string, msg: string) => void} progress
|
|
144
|
+
*/
|
|
145
|
+
function announceBreaking(breakingNotes, progress) {
|
|
146
|
+
progress(
|
|
147
|
+
'PR',
|
|
148
|
+
'⚠️ Breaking change declared — the PR title carries `!` and the body a ' +
|
|
149
|
+
`BREAKING CHANGE footer: ${breakingNotes.join(' ') || '(no note text)'}`,
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
137
153
|
/**
|
|
138
154
|
* A declared break is announced on progress so an unexpected `!` is seen
|
|
139
155
|
* during the close, not in the release notes.
|
|
140
156
|
*
|
|
141
157
|
* @param {{ storyTitle: string, storyId: number|string, storyBody?: string,
|
|
142
158
|
* storyBranch: string, baseBranch: string, cwd?: string,
|
|
143
|
-
* gitSpawn?: typeof defaultGitSpawn,
|
|
159
|
+
* gitSpawn?: typeof defaultGitSpawn, config?: object,
|
|
144
160
|
* progress?: (tag: string, msg: string) => void }} args
|
|
145
161
|
* @returns {{ title: string, body: string, breaking: boolean, breakingNotes: string[] }}
|
|
146
162
|
*/
|
|
@@ -152,6 +168,7 @@ export function buildPullRequestFields({
|
|
|
152
168
|
baseBranch,
|
|
153
169
|
cwd = process.cwd(),
|
|
154
170
|
gitSpawn = defaultGitSpawn,
|
|
171
|
+
config,
|
|
155
172
|
progress = () => {},
|
|
156
173
|
}) {
|
|
157
174
|
const commitMessages = readBranchCommits({
|
|
@@ -166,16 +183,14 @@ export function buildPullRequestFields({
|
|
|
166
183
|
commitMessages,
|
|
167
184
|
storyBody,
|
|
168
185
|
});
|
|
169
|
-
if (breaking)
|
|
170
|
-
progress(
|
|
171
|
-
'PR',
|
|
172
|
-
'⚠️ Breaking change declared — the PR title carries `!` and the body a ' +
|
|
173
|
-
`BREAKING CHANGE footer: ${breakingNotes.join(' ') || '(no note text)'}`,
|
|
174
|
-
);
|
|
175
|
-
}
|
|
186
|
+
if (breaking) announceBreaking(breakingNotes, progress);
|
|
176
187
|
return {
|
|
177
188
|
title,
|
|
178
|
-
body: buildPrBody({
|
|
189
|
+
body: buildPrBody({
|
|
190
|
+
storyId,
|
|
191
|
+
breakingNotes,
|
|
192
|
+
trailerBlock: liftTrailers({ commitMessages, config }),
|
|
193
|
+
}),
|
|
179
194
|
breaking,
|
|
180
195
|
breakingNotes,
|
|
181
196
|
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Lifts declared git trailers from already-read branch commits; no spawn. */
|
|
2
|
+
|
|
3
|
+
import { getPullRequestDelivery } from '../../../config/pull-request.js';
|
|
4
|
+
import { Logger } from '../../../Logger.js';
|
|
5
|
+
|
|
6
|
+
/** The final paragraph's `<Key>: <value>` lines, keyed lower-case. */
|
|
7
|
+
function parseTrailers(message) {
|
|
8
|
+
const paragraphs = message.trim().split(/\n\s*\n/);
|
|
9
|
+
const trailers = new Map();
|
|
10
|
+
if (paragraphs.length < 2) return trailers;
|
|
11
|
+
for (const line of paragraphs.at(-1).split('\n')) {
|
|
12
|
+
const match = /^([A-Za-z][A-Za-z0-9-]*)\s*:\s*(.*)$/.exec(line);
|
|
13
|
+
if (match?.[2].trim()) {
|
|
14
|
+
trailers.set(match[1].toLowerCase(), match[2].trim());
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return trailers;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The last commit's value per declared key, led by a blank separator; a
|
|
22
|
+
* missing key is logged, never invented.
|
|
23
|
+
*/
|
|
24
|
+
export function liftTrailers({ commitMessages, config, logger = Logger }) {
|
|
25
|
+
const parsed = commitMessages.map(parseTrailers);
|
|
26
|
+
const lines = [];
|
|
27
|
+
for (const key of getPullRequestDelivery(config).bodyTrailers) {
|
|
28
|
+
const carrier = parsed.findLast((t) => t.has(key.toLowerCase()));
|
|
29
|
+
if (carrier) {
|
|
30
|
+
lines.push(`${key}: ${carrier.get(key.toLowerCase())}`);
|
|
31
|
+
} else {
|
|
32
|
+
logger.info(
|
|
33
|
+
`[normalize-pr-title] declared trailer "${key}" is on no branch commit; the PR body omits it.`,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return lines.length > 0 ? ['', ...lines] : [];
|
|
38
|
+
}
|
|
@@ -6,6 +6,28 @@ import { runWrongTreeGuardPhase } from './wrong-tree-guard.js';
|
|
|
6
6
|
|
|
7
7
|
const progress = Logger.createProgress('single-story-close', { stderr: true });
|
|
8
8
|
|
|
9
|
+
/** Base-sync's result, or `null` when `--skip-sync` elides it. */
|
|
10
|
+
async function runSyncStep(ctx, deps) {
|
|
11
|
+
const { options, worktreePath, baseBranch, storyBranch, storyId, setPhase } =
|
|
12
|
+
ctx;
|
|
13
|
+
if (options.skipSync) {
|
|
14
|
+
progress('SYNC', '⏭ Skipped (--skip-sync).');
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
setPhase('base-sync');
|
|
18
|
+
return runBaseSyncPhase({
|
|
19
|
+
cwd: options.cwd,
|
|
20
|
+
worktreePath,
|
|
21
|
+
baseBranch,
|
|
22
|
+
baseConfirmed: ctx.baseConfirmed,
|
|
23
|
+
storyBranch,
|
|
24
|
+
storyId,
|
|
25
|
+
provider: deps.provider,
|
|
26
|
+
injectedSync: deps.sync,
|
|
27
|
+
progress,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
9
31
|
/**
|
|
10
32
|
* wrong-tree guard → base-sync → close-validation. Validation runs last so
|
|
11
33
|
* the validated tree is the pushed tree (base-sync's merge commit included),
|
|
@@ -35,22 +57,7 @@ export async function runPrePushPhases(ctx, deps) {
|
|
|
35
57
|
progress,
|
|
36
58
|
gitSpawn: deps.gitSpawn,
|
|
37
59
|
});
|
|
38
|
-
|
|
39
|
-
setPhase('base-sync');
|
|
40
|
-
await runBaseSyncPhase({
|
|
41
|
-
cwd,
|
|
42
|
-
worktreePath,
|
|
43
|
-
baseBranch,
|
|
44
|
-
baseConfirmed: ctx.baseConfirmed,
|
|
45
|
-
storyBranch,
|
|
46
|
-
storyId,
|
|
47
|
-
provider: deps.provider,
|
|
48
|
-
injectedSync: deps.sync,
|
|
49
|
-
progress,
|
|
50
|
-
});
|
|
51
|
-
} else {
|
|
52
|
-
progress('SYNC', '⏭ Skipped (--skip-sync).');
|
|
53
|
-
}
|
|
60
|
+
const baseSync = await runSyncStep(ctx, deps);
|
|
54
61
|
if (options.skipValidation) {
|
|
55
62
|
progress('VALIDATE', '⏭ Skipped (--skip-validation).');
|
|
56
63
|
return {
|
|
@@ -70,6 +77,7 @@ export async function runPrePushPhases(ctx, deps) {
|
|
|
70
77
|
baseBranch,
|
|
71
78
|
storyBranch,
|
|
72
79
|
storyId,
|
|
80
|
+
baseSync,
|
|
73
81
|
progress,
|
|
74
82
|
runCloseValidation: deps.runCloseValidation,
|
|
75
83
|
buildDefaultGates: deps.buildDefaultGates,
|
|
@@ -52,6 +52,20 @@ function probeEmptyDiff({ cwd, baseBranch, storyBranch, computeChangeSet }) {
|
|
|
52
52
|
return { empty: false, baseRef: null };
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
/**
|
|
56
|
+
* @param {{ storyBranch: string, baseRef: string, storyId: number }} args
|
|
57
|
+
* @returns {Error}
|
|
58
|
+
*/
|
|
59
|
+
function emptyDiffError({ storyBranch, baseRef, storyId }) {
|
|
60
|
+
return new Error(
|
|
61
|
+
`[single-story-close] refusing to open a pull request for ${storyBranch}: ` +
|
|
62
|
+
`the head-versus-base diff (${baseRef}...${storyBranch}) contains no files. ` +
|
|
63
|
+
'An empty diff has nothing to merge, and a PR opened on it can only squash an empty ' +
|
|
64
|
+
'commit onto the base branch. If the work already landed, confirm the merge instead: ' +
|
|
65
|
+
`node .agents/scripts/single-story-confirm-merge.js --story ${storyId}`,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
55
69
|
/**
|
|
56
70
|
* @param {{
|
|
57
71
|
* cwd: string,
|
|
@@ -60,6 +74,7 @@ function probeEmptyDiff({ cwd, baseBranch, storyBranch, computeChangeSet }) {
|
|
|
60
74
|
* storyBody?: string,
|
|
61
75
|
* storyBranch: string,
|
|
62
76
|
* baseBranch: string,
|
|
77
|
+
* config?: object,
|
|
63
78
|
* gh?: ReturnType<typeof import('../../../gh-exec.js').createGh>,
|
|
64
79
|
* computeChangeSetFn?: typeof defaultComputeChangeSet,
|
|
65
80
|
* progress?: (tag: string, msg: string) => void,
|
|
@@ -73,6 +88,7 @@ export async function ensurePullRequestWith({
|
|
|
73
88
|
storyBody = '',
|
|
74
89
|
storyBranch,
|
|
75
90
|
baseBranch,
|
|
91
|
+
config,
|
|
76
92
|
gh = defaultGh,
|
|
77
93
|
computeChangeSetFn = defaultComputeChangeSet,
|
|
78
94
|
progress = () => {},
|
|
@@ -110,13 +126,7 @@ export async function ensurePullRequestWith({
|
|
|
110
126
|
computeChangeSet: computeChangeSetFn,
|
|
111
127
|
});
|
|
112
128
|
if (emptyDiff.empty) {
|
|
113
|
-
throw
|
|
114
|
-
`[single-story-close] refusing to open a pull request for ${storyBranch}: ` +
|
|
115
|
-
`the head-versus-base diff (${emptyDiff.baseRef}...${storyBranch}) contains no files. ` +
|
|
116
|
-
'An empty diff has nothing to merge, and a PR opened on it can only squash an empty ' +
|
|
117
|
-
'commit onto the base branch. If the work already landed, confirm the merge instead: ' +
|
|
118
|
-
`node .agents/scripts/single-story-confirm-merge.js --story ${storyId}`,
|
|
119
|
-
);
|
|
129
|
+
throw emptyDiffError({ storyBranch, baseRef: emptyDiff.baseRef, storyId });
|
|
120
130
|
}
|
|
121
131
|
|
|
122
132
|
progress('PR', `Opening PR for ${storyBranch} → ${baseBranch}...`);
|
|
@@ -127,6 +137,7 @@ export async function ensurePullRequestWith({
|
|
|
127
137
|
storyBranch,
|
|
128
138
|
baseBranch,
|
|
129
139
|
cwd: _cwd ?? process.cwd(),
|
|
140
|
+
config,
|
|
130
141
|
progress,
|
|
131
142
|
});
|
|
132
143
|
try {
|