@kitman-sh/software-engineering 0.10.70 → 0.10.72

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/src/shepherd.ts CHANGED
@@ -30,6 +30,7 @@ import {
30
30
  import * as Effect from 'effect/Effect'
31
31
  import * as Schema from 'effect/Schema'
32
32
  import release from './release'
33
+ import { verifyHead } from './change-request-body'
33
34
  import review, { ReviewInput, ReviewOutput } from './review'
34
35
  import { ShepherdOutput } from './shepherd-output'
35
36
 
@@ -52,6 +53,8 @@ const Input = Schema.Struct({
52
53
  taskId: Schema.optional(Schema.String),
53
54
  /** Merges once it is approved, green and mergeable, without asking. */
54
55
  merge: Schema.optional(Schema.Boolean),
56
+ /** Why each test verify never ran is unverified, for the person asked whether to merge. */
57
+ notRun: Schema.optional(Schema.Array(Schema.String)),
55
58
  /** The target branch, for merging it in on a conflict, when Kitman does not say the ChangeRequest's own. */
56
59
  branch: Schema.optional(Schema.String),
57
60
  /** The ChangeRequest's branch and target, as Kitman puts the Run on it. */
@@ -191,7 +194,7 @@ const threadKey = (thread: ReviewThreads['threads'][number]) => `${thread.id}:${
191
194
  */
192
195
  export default defineLoop({
193
196
  id: 'shepherd',
194
- version: '1.2.0',
197
+ version: '1.3.0',
195
198
  title: 'Shepherd',
196
199
  input: Input,
197
200
  output: Output,
@@ -222,6 +225,8 @@ export default defineLoop({
222
225
  const leftToPerson = new Set<string>()
223
226
  /** The last review of an unapproved head's open findings, for the review of the head that fixes them. */
224
227
  let headFindings: readonly MergedFinding[] = []
228
+ /** Each head Shepherd's review passed but left unapproved, as verify never ran these of its tests. */
229
+ const unranAt = new Map<string, { readonly notRun: readonly string[]; readonly review: string }>()
225
230
  const rounds: Record<RoundKind, number> = { 'ci-fix': 0, 'head-fix': 0 }
226
231
  /** Rounds past the limit a person allowed. */
227
232
  const allowed: Record<RoundKind, number> = { 'ci-fix': 0, 'head-fix': 0 }
@@ -843,9 +848,13 @@ export default defineLoop({
843
848
  leftToPerson.add(head)
844
849
  approved = yield* waitFor(`approval:${cycle}`, { ...approval, timeout: '7 days' })
845
850
  } else {
851
+ const { notRun: headNotRun } = yield* verifyHead(`head-verify:${cycle}`, head)
852
+ const notRun = [...new Set([...(input.notRun ?? []), ...headNotRun])]
853
+
846
854
  const reviewed = yield* call(`head-review:${cycle}`, reviewLoop(), {
847
855
  base: `origin/${target}`,
848
856
  head,
857
+ ...(notRun.length === 0 ? undefined : { notRun }),
849
858
  ...(since === undefined ? undefined : { approved: since }),
850
859
  ...(headFindings.length === 0 ? undefined : { earlier: headFindings })
851
860
  })
@@ -874,21 +883,27 @@ export default defineLoop({
874
883
  continue
875
884
  }
876
885
 
877
- const recorded = yield* approveChangeRequest(`head-approve:${cycle}`, {
878
- changeRequestId,
879
- head,
880
- summary:
881
- since === undefined
882
- ? `A review of the whole change at ${head} passed with nothing blocking.`
883
- : `A review of what changed between ${since}, the last approved head, and ${head} passed with nothing blocking.`,
884
- review: `head-review:${cycle}`
885
- }).pipe(
886
- Effect.catchTag('StepFailed', error => Effect.succeed({ approved: false as const, reason: error.reason }))
887
- )
888
-
889
- if (!recorded.approved)
890
- return done('needs_you', `The review of ${head} passed, but did not approve it: ${recorded.reason}`)
891
886
  headFindings = []
887
+
888
+ if (notRun.length > 0) unranAt.set(head, { notRun, review: `head-review:${cycle}` })
889
+ else {
890
+ const recorded = yield* approveChangeRequest(`head-approve:${cycle}`, {
891
+ changeRequestId,
892
+ head,
893
+ summary:
894
+ since === undefined
895
+ ? `A review of the whole change at ${head} passed with nothing blocking.`
896
+ : `A review of what changed between ${since}, the last approved head, and ${head} passed with nothing blocking.`,
897
+ review: `head-review:${cycle}`
898
+ }).pipe(
899
+ Effect.catchTag('StepFailed', error =>
900
+ Effect.succeed({ approved: false as const, reason: error.reason })
901
+ )
902
+ )
903
+
904
+ if (!recorded.approved)
905
+ return done('needs_you', `The review of ${head} passed, but did not approve it: ${recorded.reason}`)
906
+ }
892
907
  }
893
908
  }
894
909
 
@@ -898,24 +913,57 @@ export default defineLoop({
898
913
  if (pipeline.source === 'reported' && approved !== undefined && approved.payload.head !== pipeline.head)
899
914
  continue
900
915
 
916
+ const unapproved = unranAt.get(pipeline.head)
917
+ const notRun = unapproved?.notRun ?? input.notRun ?? []
918
+
919
+ // A head with tests verify never ran merges only on a person's say.
901
920
  const merge =
902
- input.merge === true
921
+ input.merge === true && notRun.length === 0
903
922
  ? 'Merge'
904
923
  : yield* ask(`merge:${cycle}`, {
905
- prompt: 'The ChangeRequest is approved, green and mergeable. Merge now?',
924
+ prompt:
925
+ notRun.length === 0
926
+ ? 'The ChangeRequest is approved, green and mergeable. Merge now?'
927
+ : `The ChangeRequest is ${unapproved === undefined ? 'approved' : 'reviewed with nothing blocking but not approved'}, green and mergeable, but verify never ran some of its tests:\n${notRun.map(item => `- ${item}`).join('\n')}\n\nMerge now?`,
906
928
  options: [
907
929
  { value: 'Merge', description: 'Merges the head whose pipeline passed.' },
908
930
  { value: 'Wait', description: 'Leaves the merge to a person.' }
909
931
  ],
910
- recommended: 'Merge',
911
- recommendationReason: 'It is approved, green and mergeable, which is everything a merge waits for.',
932
+ recommended: notRun.length === 0 ? 'Merge' : 'Wait',
933
+ recommendationReason:
934
+ notRun.length === 0
935
+ ? 'It is approved, green and mergeable, which is everything a merge waits for.'
936
+ : 'Nobody has seen those tests pass, so run them by hand before it lands.',
912
937
  default: 'Wait',
913
938
  // A full-auto Team merges what its Review approved and its checks passed.
914
- auto: 'Merge',
939
+ ...(notRun.length === 0 ? { auto: 'Merge' } : undefined),
915
940
  timeout: '1 hour'
916
941
  })
917
942
 
918
- if (merge === 'Wait') return done('ready', 'Approved, green and mergeable; left for a person to merge')
943
+ if (merge === 'Wait')
944
+ return done(
945
+ 'ready',
946
+ unapproved === undefined
947
+ ? 'Approved, green and mergeable; left for a person to merge'
948
+ : 'Reviewed, green and mergeable, but verify never ran some of its tests; left for a person to merge'
949
+ )
950
+
951
+ if (unapproved !== undefined) {
952
+ const recorded = yield* approveChangeRequest(`head-approve:${cycle}`, {
953
+ changeRequestId,
954
+ head: pipeline.head,
955
+ summary: `A review of ${pipeline.head} passed with nothing blocking; a person chose to merge it though verify never ran some of its tests.`,
956
+ review: unapproved.review
957
+ }).pipe(
958
+ Effect.catchTag('StepFailed', error => Effect.succeed({ approved: false as const, reason: error.reason }))
959
+ )
960
+
961
+ if (!recorded.approved)
962
+ return done(
963
+ 'needs_you',
964
+ `The review of ${pipeline.head} passed, but did not approve it: ${recorded.reason}`
965
+ )
966
+ }
919
967
 
920
968
  // A Run ahead of it merges first; its merge moves the target, which this merge then finds and catches up with.
921
969
  const refused = yield* takeTurn()
package/src/sweep.ts CHANGED
@@ -8,12 +8,15 @@ import {
8
8
  defineLoop,
9
9
  openChangeRequests,
10
10
  ownChangeRequests,
11
+ pipelineStatus,
12
+ testsNotRunReasons,
11
13
  verify,
12
14
  type OpenChangeRequests,
13
15
  type VerifyResult
14
16
  } from '@kitman-sh/sdk/loop'
15
17
  import * as Effect from 'effect/Effect'
16
18
  import * as Schema from 'effect/Schema'
19
+ import { notVerifiedSection, verifyHead } from './change-request-body'
17
20
  import shepherd from './shepherd'
18
21
 
19
22
  const Input = Schema.Struct({
@@ -182,7 +185,7 @@ const reportText = (landing: readonly Placed[], left: readonly Placed[], heading
182
185
  */
183
186
  export default defineLoop({
184
187
  id: 'sweep',
185
- version: '1.0.0',
188
+ version: '1.1.0',
186
189
  title: 'Sweep',
187
190
  input: Input,
188
191
  output: Output,
@@ -199,9 +202,14 @@ export default defineLoop({
199
202
  const [earlier] = (yield* ownChangeRequests('earlier')).changeRequests
200
203
 
201
204
  if (earlier !== undefined) {
205
+ const { head } = yield* pipelineStatus('earlier-head', { changeRequestId: earlier.id })
206
+ // Tests verify never ran at the batch's head are for a person to run before it lands, as when it was opened.
207
+ const { notRun } = yield* verifyHead('earlier-verify', head)
208
+
202
209
  const landed = yield* call('land', shepherd, {
203
210
  changeRequestId: earlier.id,
204
- merge: true,
211
+ merge: notRun.length === 0,
212
+ ...(notRun.length === 0 ? undefined : { notRun }),
205
213
  ...(input.branch === undefined ? undefined : { branch: input.branch })
206
214
  })
207
215
 
@@ -340,10 +348,13 @@ export default defineLoop({
340
348
  )
341
349
  }
342
350
 
351
+ const notVerified = notVerifiedSection(checked)
352
+
343
353
  const opened = yield* changeRequest('change-request', {
344
354
  title: `Update ${landing.length} ${landing.length === 1 ? 'dependency' : 'dependencies'}`,
345
355
  body: [
346
356
  batched.summary,
357
+ ...(notVerified === undefined ? [] : [notVerified]),
347
358
  supersedes,
348
359
  ...landing.map(supersededLine),
349
360
  ...(left.length === 0
@@ -354,7 +365,9 @@ export default defineLoop({
354
365
 
355
366
  const landed = yield* call('land', shepherd, {
356
367
  changeRequestId: opened.id,
357
- merge: true,
368
+ // Tests the batch made verify skip are for a person to run before it lands.
369
+ merge: notVerified === undefined,
370
+ ...(notVerified === undefined ? undefined : { notRun: testsNotRunReasons(checked) }),
358
371
  ...(input.branch === undefined ? undefined : { branch: input.branch })
359
372
  })
360
373
 
package/src/tidy.ts CHANGED
@@ -11,6 +11,7 @@ import {
11
11
  rallyStop,
12
12
  settleRound,
13
13
  syncBase,
14
+ testsNotRunReasons,
14
15
  verify
15
16
  } from '@kitman-sh/sdk/loop'
16
17
  import * as Effect from 'effect/Effect'
@@ -149,11 +150,13 @@ export default defineLoop({
149
150
 
150
151
  const base = yield* verify('verify:base', { revision: start })
151
152
  const head = yield* verify('verify', {})
153
+ const notRun = testsNotRunReasons(head)
152
154
 
153
155
  const reviewed = yield* call('review', review, {
154
156
  base: start,
155
157
  head: head.revision,
156
158
  outcome: 'refactor',
159
+ ...(notRun.length === 0 ? undefined : { notRun }),
157
160
  claims: improvement.claims
158
161
  })
159
162