@kitman-sh/software-engineering 0.47.0 → 0.48.1
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/dist/bundle.js +46 -12
- package/dist/declarations.json +2641 -634
- package/package.json +3 -3
- package/src/shepherd.ts +80 -24
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitman-sh/software-engineering",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.48.1",
|
|
4
4
|
"description": "Everything for building software: Loops, their Agents, the skills they use and the Ponytail plugin.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"LICENSE.md"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@kitman-sh/sdk": "0.
|
|
22
|
+
"@kitman-sh/sdk": "0.48.1",
|
|
23
23
|
"effect": "^4.1.2"
|
|
24
24
|
},
|
|
25
25
|
"kitman": {
|
|
26
26
|
"bundle": "dist/bundle.js",
|
|
27
|
-
"digest": "
|
|
27
|
+
"digest": "eadb70000a903e7ca287d989bfe6fe94758f6e9787c6d650d591a16164e05e9c",
|
|
28
28
|
"protocolVersion": 5,
|
|
29
29
|
"declarations": "dist/declarations.json",
|
|
30
30
|
"setup": {
|
package/src/shepherd.ts
CHANGED
|
@@ -100,6 +100,9 @@ const watchLooks = 28
|
|
|
100
100
|
/** Rounds of each kind a Run takes before it asks whether to hand the ChangeRequest back to Build. */
|
|
101
101
|
const roundLimits = { 'ci-fix': 1, 'head-fix': 2 } as const
|
|
102
102
|
|
|
103
|
+
/** Bounds ci-fixes that change nothing, which no round limit counts; a person cannot extend it. */
|
|
104
|
+
const ciFixRunLimit = 3
|
|
105
|
+
|
|
103
106
|
type RoundKind = keyof typeof roundLimits
|
|
104
107
|
|
|
105
108
|
const handBackAnswer = 'Hand back to Build'
|
|
@@ -166,7 +169,9 @@ type Output = typeof Output.Type
|
|
|
166
169
|
const CiFix = Schema.Struct({
|
|
167
170
|
/** fixed: a commit fixes the branch's own failure; pre_existing: it fails on the target branch too; flaky: it passed on its rerun. */
|
|
168
171
|
verdict: Schema.Literals(['fixed', 'pre_existing', 'flaky']),
|
|
169
|
-
summary: OneSentence
|
|
172
|
+
summary: OneSentence,
|
|
173
|
+
/** With flaky: the commit `git rev-parse HEAD` named where the failing jobs ran again, and each job that passed there. */
|
|
174
|
+
reran: Schema.optionalKey(Schema.Struct({ revision: Schema.String, passed: Schema.Array(Schema.String) }))
|
|
170
175
|
})
|
|
171
176
|
|
|
172
177
|
const Replies = Schema.Struct({
|
|
@@ -191,6 +196,18 @@ const failedJobs = (pipeline: PipelineStatus) =>
|
|
|
191
196
|
const failingJobs = (pipeline: PipelineStatus) =>
|
|
192
197
|
pipeline.jobs.flatMap(job => (job.status === 'failed' ? [job.name] : []))
|
|
193
198
|
|
|
199
|
+
/** A failed report from no Runner whose every failing job a ci-fix ran again at this head and saw pass. */
|
|
200
|
+
const passedWhenRerun = (passed: Shepherding['passedOnRerun'], pipeline: PipelineStatus) => {
|
|
201
|
+
if (pipeline.source !== 'reported' || pipeline.runnerChecks !== undefined || pipeline.status !== 'failed')
|
|
202
|
+
return false
|
|
203
|
+
const failing = failingJobs(pipeline)
|
|
204
|
+
|
|
205
|
+
return (
|
|
206
|
+
failing.length > 0 &&
|
|
207
|
+
(passed ?? []).some(rerun => rerun.head === pipeline.head && failing.every(job => rerun.jobs.includes(job)))
|
|
208
|
+
)
|
|
209
|
+
}
|
|
210
|
+
|
|
194
211
|
/**
|
|
195
212
|
* The failing checks the head of the target branch fails too, and those it passes; any other is not known. `timedOut`
|
|
196
213
|
* failed there only by timing out, which is not a failure the target is known to share.
|
|
@@ -287,7 +304,7 @@ const ciFixPrompt = (pipeline: PipelineStatus, target: string, onTarget: OnTarge
|
|
|
287
304
|
return [
|
|
288
305
|
`The pipeline at ${pipeline.head} failed. These jobs failed, with the end of each log:`,
|
|
289
306
|
...failedJobs(pipeline),
|
|
290
|
-
|
|
307
|
+
`Run each failing job once more here to rule out a flake. If every one passes, change nothing, answer flaky and give in reran the commit \`git rev-parse HEAD\` names and the name of each job that passed; Shepherd lands on that only at ${pipeline.head}.`,
|
|
291
308
|
...(onTarget.passed.length === 0
|
|
292
309
|
? []
|
|
293
310
|
: [
|
|
@@ -456,6 +473,10 @@ export const Shepherding = Schema.Struct({
|
|
|
456
473
|
turn: Schema.optional(Turn),
|
|
457
474
|
/** Heads a catch-up pushed from the Charge's `head` or from another of these, each of which merges in its place. */
|
|
458
475
|
caughtUpFrom: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
476
|
+
/** Jobs of a reported pipeline that failed at `head` and passed when a ci-fix ran them again there, changing nothing. */
|
|
477
|
+
passedOnRerun: Schema.optionalKey(
|
|
478
|
+
Schema.Array(Schema.Struct({ head: Schema.String, jobs: Schema.Array(Schema.String) }))
|
|
479
|
+
),
|
|
459
480
|
/**
|
|
460
481
|
* The head whose failure the target branch shares, the target's head then, and whether anything merged into the
|
|
461
482
|
* target since.
|
|
@@ -1201,16 +1222,34 @@ export const ciFixed = step('ciFixed', {
|
|
|
1201
1222
|
|
|
1202
1223
|
/** Runs a failing pipeline again once, on the Runner or the forge, when the ci-fix found its failure a flake. */
|
|
1203
1224
|
export const reran = step('reran', {
|
|
1204
|
-
payload: {
|
|
1225
|
+
payload: {
|
|
1226
|
+
charge: Charge,
|
|
1227
|
+
at: Shepherding,
|
|
1228
|
+
pipeline: PipelineStatus,
|
|
1229
|
+
summary: Schema.String,
|
|
1230
|
+
rerun: CiFix.fields.reran
|
|
1231
|
+
},
|
|
1205
1232
|
success: Schema.Union([Again, ...Ended]),
|
|
1206
|
-
run: ({ charge, at, pipeline, summary }) =>
|
|
1233
|
+
run: ({ charge, at, pipeline, summary, rerun: ranAgain }) =>
|
|
1207
1234
|
Effect.gen(function* () {
|
|
1208
1235
|
const { changeRequestId } = charge
|
|
1209
1236
|
|
|
1210
1237
|
if (pipeline.source === 'reported') {
|
|
1211
1238
|
// Only a pipeline that runs on the Runner can be run again; nothing on the forge can run a report.
|
|
1212
|
-
if (pipeline.runnerChecks === undefined)
|
|
1213
|
-
|
|
1239
|
+
if (pipeline.runnerChecks === undefined) {
|
|
1240
|
+
const passed = [
|
|
1241
|
+
...(at.passedOnRerun ?? []),
|
|
1242
|
+
...(ranAgain?.revision === pipeline.head ? [{ head: pipeline.head, jobs: ranAgain.passed }] : [])
|
|
1243
|
+
]
|
|
1244
|
+
|
|
1245
|
+
if (!passedWhenRerun(passed, pipeline))
|
|
1246
|
+
return new NeedsYou({
|
|
1247
|
+
at,
|
|
1248
|
+
reason: `The ci-fix did not show every failing job of the pipeline at ${pipeline.head} passing there when run again: ${summary}`
|
|
1249
|
+
})
|
|
1250
|
+
|
|
1251
|
+
return new Again({ at: { ...at, reranHeads: [...at.reranHeads, pipeline.head], passedOnRerun: passed } })
|
|
1252
|
+
}
|
|
1214
1253
|
|
|
1215
1254
|
if (at.reranHeads.includes(pipeline.head))
|
|
1216
1255
|
return new NeedsYou({ at, reason: `The failing job failed again when run again on the Runner: ${summary}` })
|
|
@@ -2082,7 +2121,8 @@ export const mergedOnTurn = step('mergedOnTurn', {
|
|
|
2082
2121
|
agent: 'implementer',
|
|
2083
2122
|
approve: () => Effect.void,
|
|
2084
2123
|
...(target === 'HEAD' ? undefined : { target }),
|
|
2085
|
-
|
|
2124
|
+
// A reported failure whose jobs passed when the ci-fix ran them again lands as that run found it.
|
|
2125
|
+
read: passedWhenRerun(turn.at.passedOnRerun, pipeline) ? { ...pipeline, status: 'success' } : pipeline,
|
|
2086
2126
|
catchUp: false,
|
|
2087
2127
|
...(turn.at.repository === undefined ? undefined : { repository: turn.at.repository })
|
|
2088
2128
|
}).pipe(Effect.catchTag('MergeRefused', refused => Effect.succeed(refused)))
|
|
@@ -2184,7 +2224,10 @@ export const looked = step('looked', {
|
|
|
2184
2224
|
// Behind alone waits for the merge, which catches up while holding the turn: catching up any sooner is undone by
|
|
2185
2225
|
// every merge that lands before this one's turn. A held Run, which never merges, catches up at once. A failing
|
|
2186
2226
|
// pipeline catches up first, so a ci-fix never chases what the target already fixed.
|
|
2187
|
-
const pipelineFailed =
|
|
2227
|
+
const pipelineFailed =
|
|
2228
|
+
(pipeline.status === 'failed' || pipeline.status === 'canceled') &&
|
|
2229
|
+
!passedWhenRerun(reusing.at.passedOnRerun, pipeline)
|
|
2230
|
+
|
|
2188
2231
|
const heldBehind = hold && (pipeline.needsRebase === true || pipeline.behind === true)
|
|
2189
2232
|
const blocked = pipeline.conflicts === true || (pipeline.needsRebase === true && pipelineFailed) || heldBehind
|
|
2190
2233
|
const caughtUpHead = head === reusing.at.pipelineFirst
|
|
@@ -2451,8 +2494,8 @@ const headFixedAt = (wanted: Wanted, changed: boolean): Shepherding => {
|
|
|
2451
2494
|
* since the last approved head, and the head a catch-up pushed gets its pipeline started and its review as soon as the
|
|
2452
2495
|
* forge shows it, not once its pipeline passes. It runs one ci-fix and two head-fix rounds, each judged by the pipeline
|
|
2453
2496
|
* at the head the last fix pushed, then hands the ChangeRequest back to Build, and stops as needs you, with why, instead
|
|
2454
|
-
* of spinning
|
|
2455
|
-
* read the target again at the head each time the target moves, and catches up when they fail, as when the target
|
|
2497
|
+
* of spinning; past its third ci-fix, whatever each found, it stops as handed back without asking. Left for a person to
|
|
2498
|
+
* merge, it watches the target for up to a week, runs the repository's checks that read the target again at the head each time the target moves, and catches up when they fail, as when the target
|
|
2456
2499
|
* gained a migration the head's own does not build on. After merging it starts Release only when its release trigger is
|
|
2457
2500
|
* `merge`; under a Milestone or Project trigger that completion starts Release instead, and under `manual` a person, a
|
|
2458
2501
|
* Schedule or a Loop does. Then it offers a Backport for each other live branch of the repository, and starts one for
|
|
@@ -2517,6 +2560,7 @@ export default defineLoop({
|
|
|
2517
2560
|
// The rounds of each kind it took, and how many it may take, which a person raises a round at a time.
|
|
2518
2561
|
let rounds = noRounds
|
|
2519
2562
|
let limits: Rounds = roundLimits
|
|
2563
|
+
let ciFixRuns = 0
|
|
2520
2564
|
let next: Again | Landed | Ended = new Again({ at: unshepherded })
|
|
2521
2565
|
|
|
2522
2566
|
for (let cycle = 1; next._tag === 'Again'; cycle++) {
|
|
@@ -2534,25 +2578,29 @@ export default defineLoop({
|
|
|
2534
2578
|
|
|
2535
2579
|
const kind: RoundKind = look._tag === 'CiFixDue' ? 'ci-fix' : 'head-fix'
|
|
2536
2580
|
|
|
2537
|
-
const
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
:
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
.
|
|
2548
|
-
|
|
2581
|
+
const ciFixesSpent: boolean = look._tag === 'CiFixDue' && ciFixRuns >= ciFixRunLimit
|
|
2582
|
+
|
|
2583
|
+
const round: RoundTaken | RoundsSpent = ciFixesSpent
|
|
2584
|
+
? new RoundsSpent()
|
|
2585
|
+
: yield* roundAllowed({
|
|
2586
|
+
kind,
|
|
2587
|
+
taken: rounds[kind],
|
|
2588
|
+
limit: limits[kind],
|
|
2589
|
+
standing:
|
|
2590
|
+
look._tag === 'CiFixDue'
|
|
2591
|
+
? `the failing pipeline at ${look.pipeline.head}`
|
|
2592
|
+
: look.findings
|
|
2593
|
+
.filter(isBlocking)
|
|
2594
|
+
.map(finding => finding.id)
|
|
2595
|
+
.join(', ')
|
|
2596
|
+
})
|
|
2549
2597
|
|
|
2550
2598
|
if (round._tag === 'RoundsSpent') {
|
|
2551
2599
|
next = yield* handedBack({
|
|
2552
2600
|
charge,
|
|
2553
2601
|
at: look.at,
|
|
2554
2602
|
...look.handBack,
|
|
2555
|
-
reason: `${look.handBack.reason} after ${rounds[kind]} ${kind} rounds`
|
|
2603
|
+
reason: `${look.handBack.reason} after ${ciFixesSpent ? ciFixRuns : rounds[kind]} ${kind} rounds`
|
|
2556
2604
|
})
|
|
2557
2605
|
continue
|
|
2558
2606
|
}
|
|
@@ -2576,6 +2624,8 @@ export default defineLoop({
|
|
|
2576
2624
|
|
|
2577
2625
|
const { at, pipeline, onTarget }: CiFixDue = look
|
|
2578
2626
|
|
|
2627
|
+
ciFixRuns++
|
|
2628
|
+
|
|
2579
2629
|
const fixed: typeof CiFix.Type | Ended = yield* ciFixed({ target: charge.target, pipeline, onTarget }).pipe(
|
|
2580
2630
|
endedOn(charge, at)
|
|
2581
2631
|
)
|
|
@@ -2601,7 +2651,13 @@ export default defineLoop({
|
|
|
2601
2651
|
pipeline,
|
|
2602
2652
|
why: `the failure is pre-existing on the target branch: ${fixed.summary}`
|
|
2603
2653
|
}).pipe(endedOn(charge, at))
|
|
2604
|
-
: yield* reran({
|
|
2654
|
+
: yield* reran({
|
|
2655
|
+
charge,
|
|
2656
|
+
at,
|
|
2657
|
+
pipeline,
|
|
2658
|
+
summary: fixed.summary,
|
|
2659
|
+
...(fixed.reran === undefined ? undefined : { rerun: fixed.reran })
|
|
2660
|
+
}).pipe(endedOn(charge, at))
|
|
2605
2661
|
}
|
|
2606
2662
|
|
|
2607
2663
|
const fixRounds = rounds['ci-fix'] + rounds['head-fix']
|