@cnc-tools/storm 0.16.0 → 0.18.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.
Files changed (290) hide show
  1. package/dist/bin/storm.js +54 -40
  2. package/dist/build-info.js +1 -1
  3. package/dist/chunks/{chunk-VL7WFTVQ.js → chunk-24UYAK4R.js} +465 -365
  4. package/dist/chunks/{chunk-DC2CDHNK.js → chunk-2JMWUKH3.js} +2074 -473
  5. package/dist/chunks/{chunk-FOZWA52V.js → chunk-3VXZONGE.js} +481 -376
  6. package/dist/chunks/{chunk-ZG3WQ4UF.js → chunk-55O4FCN4.js} +1 -1
  7. package/dist/chunks/{chunk-CN4EFA5J.js → chunk-72ZFEMAW.js} +1 -1
  8. package/dist/chunks/chunk-AS37D43E.js +2173 -0
  9. package/dist/chunks/chunk-CQAY6GLP.js +1260 -0
  10. package/dist/chunks/chunk-DZLU7BYK.js +340 -0
  11. package/dist/chunks/{chunk-R7XVBZOY.js → chunk-EEENLQHE.js} +59 -11
  12. package/dist/chunks/{chunk-TJNFVNKR.js → chunk-EI3XDCEI.js} +1 -1
  13. package/dist/chunks/{chunk-HVNK3I45.js → chunk-FDUY3BNF.js} +1 -1
  14. package/dist/chunks/{chunk-FCQUJDA4.js → chunk-GUCCYCIO.js} +4 -189
  15. package/dist/chunks/{chunk-OIY3DMF2.js → chunk-HBI4LEMH.js} +3 -3
  16. package/dist/chunks/{chunk-2MAD5NKK.js → chunk-K4MDQPLW.js} +1 -18
  17. package/dist/chunks/chunk-KK7PAWIZ.js +198 -0
  18. package/dist/chunks/{chunk-G3PHMXH5.js → chunk-KQ5FXRUD.js} +18 -1
  19. package/dist/chunks/{chunk-5VXBKPW6.js → chunk-LKXHGGGX.js} +1 -1
  20. package/dist/chunks/{chunk-P357TZAY.js → chunk-LOGHIUUB.js} +21 -18
  21. package/dist/chunks/{chunk-CK2GZEPK.js → chunk-OEPFINFT.js} +2 -2
  22. package/dist/chunks/{chunk-DWEAHX4T.js → chunk-OI4AP6Z7.js} +5 -5
  23. package/dist/chunks/{chunk-V4IKA3WI.js → chunk-PMBQWVTW.js} +26 -19
  24. package/dist/chunks/chunk-SZMYIIG2.js +88 -0
  25. package/dist/chunks/{chunk-5CCP36QQ.js → chunk-TXCOFC7N.js} +1 -1
  26. package/dist/chunks/{chunk-VUPZH7J2.js → chunk-UXD3TVWM.js} +1 -1
  27. package/dist/chunks/{chunk-3L52KNQA.js → chunk-WNW2QXQK.js} +8 -8
  28. package/dist/chunks/{chunk-AWBSONHB.js → chunk-XBDRVFEV.js} +55 -16
  29. package/dist/chunks/{live-app-WECQOQ4C.js → live-app-UY7BEDUN.js} +17 -13
  30. package/dist/cli.d.ts +28 -0
  31. package/dist/cli.js +64 -0
  32. package/dist/commands/exec/across-sandboxes-outcomes.d.ts +2 -2
  33. package/dist/commands/exec/across-sandboxes-outcomes.js +3 -3
  34. package/dist/commands/exec/before-run.d.ts +123 -0
  35. package/dist/commands/exec/before-run.js +105 -0
  36. package/dist/commands/exec/command.d.ts +67 -14
  37. package/dist/commands/exec/command.js +31 -95
  38. package/dist/commands/exec/driver-plan.d.ts +9 -4
  39. package/dist/commands/exec/driver-plan.js +8 -8
  40. package/dist/commands/exec/exec-words.js +1 -1
  41. package/dist/commands/exec/execute-run.d.ts +39 -0
  42. package/dist/commands/exec/execute-run.js +325 -0
  43. package/dist/commands/exec/live-view.d.ts +3 -3
  44. package/dist/commands/exec/live-view.js +16 -15
  45. package/dist/commands/exec/metadata.js +1 -1
  46. package/dist/commands/exec/mint-failed.d.ts +38 -0
  47. package/dist/commands/exec/mint-failed.js +27 -4
  48. package/dist/commands/exec/outcomes.d.ts +104 -22
  49. package/dist/commands/exec/outcomes.js +73 -26
  50. package/dist/commands/exec/plan-run.d.ts +58 -150
  51. package/dist/commands/exec/plan-run.js +239 -90
  52. package/dist/commands/exec/progress.d.ts +10 -6
  53. package/dist/commands/exec/progress.js +38 -25
  54. package/dist/commands/exec/run-bin.d.ts +11 -11
  55. package/dist/commands/exec/run-bin.js +9 -9
  56. package/dist/commands/exec/run-flags.d.ts +69 -0
  57. package/dist/commands/exec/run-flags.js +58 -0
  58. package/dist/commands/exec/run-metadata.js +4 -4
  59. package/dist/commands/exec/run-summary.d.ts +58 -0
  60. package/dist/commands/exec/run-summary.js +205 -0
  61. package/dist/commands/exec/runner-refusals.d.ts +82 -0
  62. package/dist/commands/exec/runner-refusals.js +71 -0
  63. package/dist/commands/exec/sandbox-progress.js +3 -0
  64. package/dist/commands/exec/stopped-outcome.d.ts +12 -0
  65. package/dist/commands/exec/stopped-outcome.js +77 -0
  66. package/dist/commands/exec/view.d.ts +20 -11
  67. package/dist/commands/exec/view.js +103 -47
  68. package/dist/commands/runs/facts.d.ts +8 -4
  69. package/dist/commands/runs/facts.js +19 -10
  70. package/dist/commands/runs/list/command.d.ts +16 -8
  71. package/dist/commands/runs/list/command.js +10 -10
  72. package/dist/commands/runs/list/outcomes.d.ts +8 -4
  73. package/dist/commands/runs/logs/command.js +10 -10
  74. package/dist/commands/runs/show/command.d.ts +16 -8
  75. package/dist/commands/runs/show/command.js +31 -29
  76. package/dist/commands/runs/show/metadata.js +1 -1
  77. package/dist/commands/runs/show/outcomes.d.ts +8 -4
  78. package/dist/commands/runs/show/outcomes.js +8 -6
  79. package/dist/commands/snapshots/access.d.ts +111 -0
  80. package/dist/commands/snapshots/access.js +96 -0
  81. package/dist/commands/snapshots/build/command.d.ts +376 -101
  82. package/dist/commands/snapshots/build/command.js +447 -149
  83. package/dist/commands/snapshots/build/metadata.d.ts +10 -0
  84. package/dist/commands/snapshots/build/metadata.js +31 -11
  85. package/dist/commands/snapshots/build/outcomes.d.ts +242 -47
  86. package/dist/commands/snapshots/build/outcomes.js +200 -36
  87. package/dist/commands/snapshots/list/command.d.ts +368 -27
  88. package/dist/commands/snapshots/list/command.js +298 -68
  89. package/dist/commands/snapshots/list/metadata.d.ts +16 -0
  90. package/dist/commands/snapshots/list/metadata.js +29 -6
  91. package/dist/commands/snapshots/list/outcomes.d.ts +247 -15
  92. package/dist/commands/snapshots/list/outcomes.js +223 -52
  93. package/dist/commands/snapshots/metadata.js +1 -1
  94. package/dist/commands/snapshots/prune/command.d.ts +430 -0
  95. package/dist/commands/snapshots/prune/command.js +161 -0
  96. package/dist/commands/snapshots/prune/metadata.d.ts +28 -0
  97. package/dist/commands/snapshots/prune/metadata.js +39 -0
  98. package/dist/commands/snapshots/prune/outcomes.d.ts +208 -0
  99. package/dist/commands/snapshots/prune/outcomes.js +78 -0
  100. package/dist/commands/suites/list/command.js +17 -17
  101. package/dist/commands/suites/list/outcomes.js +2 -2
  102. package/dist/commands/test/command.d.ts +67 -14
  103. package/dist/commands/test/command.js +49 -252
  104. package/dist/commands/test/outcomes.d.ts +33 -7
  105. package/dist/config/check-runner.d.ts +3 -3
  106. package/dist/config/check-runner.js +8 -7
  107. package/dist/config/credential-resolver.d.ts +50 -5
  108. package/dist/config/credential-resolver.js +51 -19
  109. package/dist/config/credential-settle.d.ts +6 -2
  110. package/dist/config/credential-settle.js +11 -5
  111. package/dist/config/index.d.ts +2 -2
  112. package/dist/config/index.js +1 -1
  113. package/dist/config/runner.d.ts +5 -5
  114. package/dist/config/runner.js +1 -1
  115. package/dist/config/schema.d.ts +2 -2
  116. package/dist/config/schema.js +1 -1
  117. package/dist/config-file/define.d.ts +1 -1
  118. package/dist/config-file/define.js +1 -1
  119. package/dist/config-file/runner.d.ts +5 -5
  120. package/dist/config-file/toolchain.d.ts +14 -4
  121. package/dist/config-file/toolchain.js +43 -7
  122. package/dist/context.d.ts +10 -6
  123. package/dist/context.js +8 -6
  124. package/dist/core/across-sandboxes.d.ts +7 -6
  125. package/dist/core/across-sandboxes.js +123 -152
  126. package/dist/core/coordinator.d.ts +166 -0
  127. package/dist/core/coordinator.js +233 -0
  128. package/dist/core/events.d.ts +2 -2
  129. package/dist/core/index.d.ts +4 -2
  130. package/dist/core/index.js +1 -1
  131. package/dist/core/outcomes.d.ts +148 -0
  132. package/dist/core/{sandbox-end.js → outcomes.js} +28 -4
  133. package/dist/core/resources.d.ts +31 -53
  134. package/dist/core/resources.js +32 -70
  135. package/dist/core/run-state.d.ts +7 -1
  136. package/dist/core/run-state.js +2 -0
  137. package/dist/core/run.d.ts +32 -236
  138. package/dist/core/run.js +107 -267
  139. package/dist/core/state-directory.d.ts +1 -1
  140. package/dist/core/state-directory.js +2 -2
  141. package/dist/credential/gateways.d.ts +15 -1
  142. package/dist/credential/index.d.ts +4 -3
  143. package/dist/credential/index.js +3 -2
  144. package/dist/credential/live/vercel-cli-gateway.d.ts +1 -1
  145. package/dist/credential/live/vercel-cli-gateway.js +1 -1
  146. package/dist/credential/live/vercel-oidc-token-gateway.d.ts +11 -0
  147. package/dist/credential/live/vercel-oidc-token-gateway.js +16 -0
  148. package/dist/credential/source.d.ts +73 -6
  149. package/dist/credential/source.js +55 -2
  150. package/dist/extension-commands.d.ts +1 -1
  151. package/dist/extension-commands.js +2 -2
  152. package/dist/extensions/testserver/commands/pool/create/command.d.ts +35 -2
  153. package/dist/extensions/testserver/commands/pool/create/command.js +7 -7
  154. package/dist/extensions/testserver/commands/pool/create/metadata.js +5 -5
  155. package/dist/extensions/testserver/commands/pool/create/outcomes.d.ts +17 -1
  156. package/dist/extensions/testserver/commands/pool/list/command.js +4 -4
  157. package/dist/extensions/testserver/credential-facts.d.ts +6 -2
  158. package/dist/extensions/testserver/credential-facts.js +29 -11
  159. package/dist/extensions/testserver/lifecycle.js +7 -1
  160. package/dist/extensions/testserver/limit.d.ts +3 -0
  161. package/dist/extensions/testserver/limit.js +3 -0
  162. package/dist/extensions/testserver/provision.d.ts +8 -1
  163. package/dist/extensions/testserver/provision.js +8 -3
  164. package/dist/extensions/testserver/refusals.d.ts +6 -1
  165. package/dist/extensions/testserver/refusals.js +16 -1
  166. package/dist/extensions/testserver/resource.d.ts +1 -1
  167. package/dist/extensions/testserver/resource.js +1 -1
  168. package/dist/extensions/testserver/result.d.ts +1 -1
  169. package/dist/extensions/testserver/result.js +9 -4
  170. package/dist/planning/driver-file-lists.d.ts +0 -15
  171. package/dist/planning/driver-file-lists.js +2 -21
  172. package/dist/planning/plan-only.d.ts +3 -14
  173. package/dist/planning/plan-only.js +11 -20
  174. package/dist/planning/run-kind-flags.js +2 -2
  175. package/dist/planning/run-plan.d.ts +45 -12
  176. package/dist/planning/run-plan.js +4 -3
  177. package/dist/planning/suites.d.ts +1 -1
  178. package/dist/planning/suites.js +2 -2
  179. package/dist/planning/test-plan.d.ts +9 -0
  180. package/dist/planning/test-plan.js +9 -0
  181. package/dist/run-directory/recording.js +3 -3
  182. package/dist/run-directory/run-record.d.ts +26 -11
  183. package/dist/run-directory/run-record.js +16 -13
  184. package/dist/runner/base.js +1 -1
  185. package/dist/runner/build-snapshots.d.ts +60 -29
  186. package/dist/runner/build-snapshots.js +136 -29
  187. package/dist/runner/context.d.ts +15 -7
  188. package/dist/runner/context.js +19 -6
  189. package/dist/runner/events.d.ts +16 -10
  190. package/dist/runner/gateways.d.ts +122 -23
  191. package/dist/runner/gateways.js +1 -1
  192. package/dist/runner/gh.d.ts +42 -0
  193. package/dist/runner/gh.js +58 -0
  194. package/dist/runner/index.d.ts +13 -8
  195. package/dist/runner/index.js +12 -6
  196. package/dist/runner/live/checkout-gateway.js +7 -0
  197. package/dist/runner/live/gh-output.d.ts +17 -0
  198. package/dist/runner/live/gh-output.js +37 -0
  199. package/dist/runner/live/gh-token-gateway.d.ts +13 -0
  200. package/dist/runner/live/gh-token-gateway.js +51 -0
  201. package/dist/runner/live/sandbox-errors.d.ts +2 -0
  202. package/dist/runner/live/sandbox-errors.js +4 -0
  203. package/dist/runner/live/sandbox-gateway.js +140 -4
  204. package/dist/runner/live/snapshot-index-gateway.d.ts +12 -0
  205. package/dist/runner/live/{snapshot-cache-gateway.js → snapshot-index-gateway.js} +11 -11
  206. package/dist/runner/live/snapshot-records.js +12 -12
  207. package/dist/runner/local-snapshot-index.d.ts +205 -0
  208. package/dist/runner/local-snapshot-index.js +210 -0
  209. package/dist/runner/network-policy.d.ts +6 -6
  210. package/dist/runner/network-policy.js +7 -7
  211. package/dist/runner/policy-writes.d.ts +1 -1
  212. package/dist/runner/policy-writes.js +1 -1
  213. package/dist/runner/prepare.d.ts +14 -14
  214. package/dist/runner/prepare.js +20 -11
  215. package/dist/runner/ready.d.ts +19 -11
  216. package/dist/runner/ready.js +104 -33
  217. package/dist/runner/sandboxed-command.d.ts +3 -3
  218. package/dist/runner/sandboxed-command.js +3 -3
  219. package/dist/runner/scope.d.ts +15 -8
  220. package/dist/runner/scope.js +16 -5
  221. package/dist/runner/secrets.d.ts +41 -18
  222. package/dist/runner/secrets.js +226 -30
  223. package/dist/runner/session.d.ts +8 -8
  224. package/dist/runner/session.js +6 -3
  225. package/dist/runner/shared-snapshot-entry.d.ts +92 -0
  226. package/dist/runner/shared-snapshot-entry.js +168 -0
  227. package/dist/runner/shared-snapshot-list.d.ts +81 -0
  228. package/dist/runner/shared-snapshot-list.js +155 -0
  229. package/dist/runner/shared-snapshot-lookup.d.ts +51 -0
  230. package/dist/runner/shared-snapshot-lookup.js +118 -0
  231. package/dist/runner/shared-snapshot-prune.d.ts +58 -0
  232. package/dist/runner/shared-snapshot-prune.js +133 -0
  233. package/dist/runner/snapshot-build.d.ts +42 -14
  234. package/dist/runner/snapshot-build.js +79 -47
  235. package/dist/runner/snapshot-choice.js +2 -1
  236. package/dist/runner/snapshot-inspect.d.ts +39 -40
  237. package/dist/runner/snapshot-inspect.js +52 -35
  238. package/dist/runner/snapshot-key.d.ts +32 -17
  239. package/dist/runner/snapshot-key.js +43 -18
  240. package/dist/runner/snapshot-source.d.ts +31 -0
  241. package/dist/runner/snapshot-source.js +122 -0
  242. package/dist/runner/steps.d.ts +1 -1
  243. package/dist/runner/steps.js +1 -1
  244. package/dist/runner/{recipe-check.d.ts → vercel-sandbox-check.d.ts} +4 -2
  245. package/dist/runner/{recipe-check.js → vercel-sandbox-check.js} +7 -2
  246. package/dist/runner/{recipe.d.ts → vercel-sandbox-options.d.ts} +59 -28
  247. package/dist/runner/{recipe.js → vercel-sandbox-options.js} +128 -84
  248. package/dist/runner/vercel-sandbox-secrets.d.ts +116 -0
  249. package/dist/runner/{recipe-secrets.js → vercel-sandbox-secrets.js} +159 -26
  250. package/dist/sdk/extension/credential-diagnosis.d.ts +3 -1
  251. package/dist/sdk/extension/credential-diagnosis.js +25 -5
  252. package/dist/sdk/extension/credential-source.d.ts +20 -3
  253. package/dist/sdk/extension/credential-source.js +4 -4
  254. package/dist/sdk/extension/index.d.ts +3 -2
  255. package/dist/sdk/extension/index.js +2 -1
  256. package/dist/sdk/extension/resource-definition.d.ts +1 -1
  257. package/dist/sdk/extension/secret-source.d.ts +1 -1
  258. package/dist/sdk/extension/secret-source.js +1 -1
  259. package/dist/sdk/extension/vercel-oidc-facts.d.ts +20 -0
  260. package/dist/sdk/extension/vercel-oidc-facts.js +20 -0
  261. package/dist/shared/cleanup.d.ts +3 -3
  262. package/dist/shared/cleanup.js +15 -5
  263. package/dist/shared/snapshot-text.d.ts +4 -4
  264. package/dist/shared/snapshot-text.js +11 -11
  265. package/dist/time/duration.js +1 -1
  266. package/package.json +5 -3
  267. package/skills/overview.md +4 -4
  268. package/skills/plan-runs.md +1 -1
  269. package/skills/read-run-output.md +6 -6
  270. package/dist/application.d.ts +0 -21
  271. package/dist/application.js +0 -30
  272. package/dist/chunks/chunk-7EENF73W.js +0 -782
  273. package/dist/chunks/chunk-Z5PBVG3Y.js +0 -2599
  274. package/dist/commands/exec/across-sandboxes-run.d.ts +0 -180
  275. package/dist/commands/exec/across-sandboxes-run.js +0 -339
  276. package/dist/commands/exec/plan-only.d.ts +0 -10
  277. package/dist/commands/exec/plan-only.js +0 -45
  278. package/dist/commands/exec/run-command.d.ts +0 -475
  279. package/dist/commands/exec/run-command.js +0 -603
  280. package/dist/commands/exec/run-planned.d.ts +0 -20
  281. package/dist/commands/exec/run-planned.js +0 -22
  282. package/dist/commands/exec/sandbox-view.d.ts +0 -19
  283. package/dist/commands/exec/sandbox-view.js +0 -72
  284. package/dist/commands/test/plan.d.ts +0 -92
  285. package/dist/commands/test/plan.js +0 -125
  286. package/dist/core/sandbox-end.d.ts +0 -64
  287. package/dist/runner/live/snapshot-cache-gateway.d.ts +0 -12
  288. package/dist/runner/recipe-secrets.d.ts +0 -67
  289. package/dist/runner/snapshot-cache.d.ts +0 -148
  290. package/dist/runner/snapshot-cache.js +0 -126
@@ -1,51 +1,79 @@
1
1
  import type { SandboxCredential } from "../sdk/extension/index.ts";
2
2
  import { type RunnerContext } from "./context.ts";
3
3
  import type { RunnerProgress, RunnerStage, SnapshotBuildReason } from "./events.ts";
4
- import type { RunnerSnapshotCacheFailure, RunnerSnapshotEntry, SandboxAccess } from "./gateways.ts";
4
+ import type { RunnerSnapshotEntry, RunnerSnapshotIndexFailure, SandboxAccess } from "./gateways.ts";
5
5
  import type { PreparedRunner } from "./prepare.ts";
6
6
  import type { RunnerSandboxScope } from "./scope.ts";
7
7
  /** How long a build sandbox may live: 30 minutes. */
8
8
  export declare const BUILD_SANDBOX_TIMEOUT_MS: number;
9
9
  /** The label of the step between the toolchain and prebuild steps that commits the base's files. */
10
10
  export declare const BASE_INDEX_LABEL = "Committing the base's files";
11
- /** A runner snapshot a run built and the cache entry recorded for it, or why the cache couldn't record it. */
11
+ /** A runner snapshot a run built and the local snapshot index entry recorded for it, or why it couldn't record it. */
12
12
  export interface BuiltSnapshot {
13
13
  readonly entry: RunnerSnapshotEntry;
14
- /** How long the build took, from its start to the cache entry. */
14
+ /** How long the build took, from its start to the local snapshot index entry. */
15
15
  readonly ms: number;
16
16
  readonly sizeBytes: number;
17
- /** Why the cache couldn't write `entry`; null when it wrote it. */
18
- readonly cacheFailure: RunnerSnapshotCacheFailure | null;
17
+ /** Why the local snapshot index couldn't write `entry`; null when it wrote it. */
18
+ readonly localIndexFailure: RunnerSnapshotIndexFailure | null;
19
19
  }
20
20
  /**
21
- * What a base snapshot build reads of a prepared run, or of a `storm snapshots build` plan: the recipe, the
21
+ * What a runner snapshot build reads of a prepared run, or of a `storm snapshots build` plan: the runner options, the
22
22
  * checkout, the base, its snapshot steps and key, and how many commits HEAD has after the base.
23
23
  */
24
- export interface BaseSnapshotPlan extends Pick<PreparedRunner, "recipe" | "repoRoot" | "base" | "baseFiles" | "snapshotKey"> {
24
+ export interface RunnerSnapshotPlan extends Pick<PreparedRunner, "options" | "repoRoot" | "base" | "baseFiles" | "snapshotKey"> {
25
25
  /** How many commits HEAD has after the base; null for a `--base` commit that isn't HEAD's merge-base. */
26
26
  readonly commitsAfterBase: number | null;
27
27
  }
28
28
  /** What a snapshot build needs to know: what it builds, who it runs as, the credentials, and why it builds. */
29
29
  export interface BuildSnapshotRequest {
30
- readonly prepared: BaseSnapshotPlan;
30
+ readonly prepared: RunnerSnapshotPlan;
31
31
  readonly access: SandboxAccess;
32
32
  /** The local user, for the sandbox's `user` tag. */
33
33
  readonly user: string;
34
34
  /**
35
- * The recipe's credentials, with their values; the firewall adds each one from before the first toolchain step until
35
+ * The runner's credentials, with their values; the firewall adds each one from before the first toolchain step until
36
36
  * the scope revokes them before the snapshot save, or in its fence if the build ends early.
37
37
  */
38
38
  readonly credentials: readonly Required<SandboxCredential>[];
39
39
  /** Why it builds, for the line that says so. */
40
40
  readonly why: SnapshotBuildReason;
41
+ /**
42
+ * Publish the build to the shared snapshot index: the build sandbox takes `name` and `tags`
43
+ * (`snapshotIndexTags`), and stays in the project, stopped, once saved. Undefined builds an unnamed build sandbox
44
+ * with the runner's tags, which is deleted once saved.
45
+ */
46
+ readonly publish?: SnapshotPublish;
47
+ }
48
+ /** The name and tags of a build sandbox kept stopped as a shared snapshot index entry. */
49
+ export interface SnapshotPublish {
50
+ readonly name: string;
51
+ readonly tags: Readonly<Record<string, string>>;
41
52
  }
42
53
  /**
43
- * Builds a base snapshot of `prepared.base`. The build sandbox starts while the base's files are packed, and is
44
- * deleted once saved; a build that fails leaves it to the scope to stop and delete. Its cache entry replaces one of the
45
- * same identity, a base snapshot of the same owner, recipe, snapshot key and base. A cache entry that can't be written
46
- * is reported, and the build still succeeds, saying why (`BuiltSnapshot.cacheFailure`).
54
+ * How a published snapshot build ended: a build's stage, or `name-taken` when a sandbox named `name` already exists in
55
+ * the project, such as one another build started first, so this build started nothing.
47
56
  */
48
- export declare function buildSnapshot(context: Pick<RunnerContext, "checkout" | "runnerSnapshots" | "runnerSandboxes" | "clock">, request: BuildSnapshotRequest, control: {
57
+ export type PublishedSnapshotStage = RunnerStage<BuiltSnapshot> | {
58
+ readonly kind: "name-taken";
59
+ readonly name: string;
60
+ readonly message: string;
61
+ };
62
+ /**
63
+ * Builds a runner snapshot of `prepared.base`. The build sandbox starts while the base's files are packed, and is
64
+ * deleted once saved; a build that fails leaves it to the scope to stop and delete. Its local snapshot index entry
65
+ * replaces one of the same identity, a runner snapshot of the same owner, runner, snapshot key, and base. A local
66
+ * snapshot index entry that can't be written is reported, and the build still succeeds, saying why
67
+ * (`BuiltSnapshot.localIndexFailure`). With `publish`, the build sandbox takes its name and tags and stays in the
68
+ * project, stopped, once saved, and a name already taken ends the build `name-taken` before anything else starts.
69
+ */
70
+ export declare function buildSnapshot(context: Pick<RunnerContext, "checkout" | "runnerSnapshots" | "runnerSandboxes" | "clock">, request: BuildSnapshotRequest & {
71
+ readonly publish?: undefined;
72
+ }, control: {
49
73
  readonly scope: RunnerSandboxScope;
50
74
  readonly signal: AbortSignal;
51
75
  }, progress: RunnerProgress): Promise<RunnerStage<BuiltSnapshot>>;
76
+ export declare function buildSnapshot(context: Pick<RunnerContext, "checkout" | "runnerSnapshots" | "runnerSandboxes" | "clock">, request: BuildSnapshotRequest, control: {
77
+ readonly scope: RunnerSandboxScope;
78
+ readonly signal: AbortSignal;
79
+ }, progress: RunnerProgress): Promise<PublishedSnapshotStage>;
@@ -1,79 +1,99 @@
1
1
  // Building a runner snapshot of a run's base: a build sandbox runs the toolchain steps, commits exactly the base's
2
- // tracked files, runs the prebuild steps, and is saved as a snapshot, which the cache then records. The sandbox scope
3
- // grants the recipe's credentials before the first toolchain step, and revokes them before the snapshot save (or in the
4
- // scope's fence if the build fails or is canceled).
2
+ // tracked files, runs the prebuild steps, and is saved as a snapshot, which the local snapshot index then records. The
3
+ // sandbox scope grants the runner's credentials before the first toolchain step, and revokes them before the snapshot
4
+ // save (or in the scope's fence if the build fails or is canceled). A published build names its build sandbox and keeps
5
+ // it stopped once saved, as an entry of the shared snapshot index.
5
6
  import { runnerTags } from "./context.js";
6
- import { SNAPSHOT_EXPIRATION_MS } from "./snapshot-cache.js";
7
- import { baseIndexScript, STAGED_FILES } from "./snapshot-key.js";
7
+ import { SNAPSHOT_EXPIRATION_MS } from "./local-snapshot-index.js";
8
+ import { baseIndexScript, gitFetchBaseIndexScript, STAGED_FILES } from "./snapshot-key.js";
9
+ import { normalizeGitFetchUrl } from "./snapshot-source.js";
8
10
  import { networkPolicyStop, runStep, sandboxStop } from "./steps.js";
9
11
  /** How long a build sandbox may live: 30 minutes. */
10
12
  export const BUILD_SANDBOX_TIMEOUT_MS = 30 * 60_000;
11
13
  /** The label of the step between the toolchain and prebuild steps that commits the base's files. */
12
14
  export const BASE_INDEX_LABEL = "Committing the base's files";
13
- /**
14
- * Builds a base snapshot of `prepared.base`. The build sandbox starts while the base's files are packed, and is
15
- * deleted once saved; a build that fails leaves it to the scope to stop and delete. Its cache entry replaces one of the
16
- * same identity, a base snapshot of the same owner, recipe, snapshot key and base. A cache entry that can't be written
17
- * is reported, and the build still succeeds, saying why (`BuiltSnapshot.cacheFailure`).
18
- */
19
15
  export async function buildSnapshot(context, request, control, progress) {
20
16
  const { prepared, access } = request;
21
- const { recipe, repoRoot, base } = prepared;
17
+ const { options, repoRoot, base } = prepared;
22
18
  const { scope, signal } = control;
19
+ const { publish } = request;
23
20
  const now = () => context.clock.now().getTime();
24
21
  const startedAt = now();
25
22
  await progress.emit({
26
23
  kind: "snapshot-build-started",
27
24
  base,
28
25
  why: request.why,
29
- summary: recipe.snapshot.summary ??
30
- [...recipe.snapshot.toolchains, ...recipe.snapshot.prebuild].map(({ label }) => label).join(", "),
26
+ summary: options.snapshot.summary ??
27
+ [...options.snapshot.toolchains, ...options.snapshot.prebuild].map(({ label }) => label).join(", "),
31
28
  });
32
- const [started, archive] = await Promise.all([
33
- scope.startBuildSandbox(access, {
34
- region: recipe.region,
35
- runtime: recipe.runtime,
36
- vcpus: recipe.snapshot.vcpus,
37
- timeoutMs: BUILD_SANDBOX_TIMEOUT_MS,
38
- tags: runnerTags(recipe.name, "snapshot-build", request.user),
39
- }),
40
- context.checkout.baseArchive({ repoRoot, base }),
41
- ]);
29
+ let fetchUrl;
30
+ if (options.snapshot.source !== undefined) {
31
+ const resolved = await resolveGitFetchUrl(context.checkout, {
32
+ repoRoot,
33
+ remote: options.snapshot.source.remote,
34
+ });
35
+ if (!resolved.ok)
36
+ return { kind: "failed", failure: { kind: "checkout-failed", failure: resolved.failure } };
37
+ fetchUrl = resolved.value;
38
+ }
39
+ const startBuild = () => scope.startBuildSandbox(access, {
40
+ region: options.region,
41
+ image: options.image,
42
+ vcpus: options.snapshot.vcpus,
43
+ timeoutMs: BUILD_SANDBOX_TIMEOUT_MS,
44
+ ...(publish === undefined
45
+ ? { tags: runnerTags(options.name, "snapshot-build", request.user) }
46
+ : { name: publish.name, tags: publish.tags }),
47
+ });
48
+ const [started, baseStep] = fetchUrl === undefined
49
+ ? await Promise.all([startBuild(), context.checkout.baseArchive({ repoRoot, base })])
50
+ : [await startBuild(), fetchUrl];
42
51
  if (!started.ok)
43
- return sandboxStop("start-build-sandbox", started.failure);
52
+ return started.failure.kind === "name-taken"
53
+ ? { kind: "name-taken", name: started.failure.name, message: started.failure.message }
54
+ : sandboxStop("start-build-sandbox", started.failure);
44
55
  const sandbox = started.value;
45
56
  await progress.emit({
46
57
  kind: "sandbox-started",
47
58
  role: "snapshot-build",
48
59
  name: sandbox.name,
49
- region: recipe.region,
50
- vcpus: recipe.snapshot.vcpus,
60
+ region: options.region,
61
+ vcpus: options.snapshot.vcpus,
51
62
  ms: now() - startedAt,
52
63
  });
53
- if (!archive.ok)
54
- return { kind: "failed", failure: { kind: "checkout-failed", failure: archive.failure } };
55
- const staged = await context.runnerSandboxes.upload(sandbox, [
56
- { name: STAGED_FILES.baseTarball, content: archive.value.tarball },
57
- { name: STAGED_FILES.baseFileList, content: archive.value.fileList },
58
- ], signal);
59
- if (!staged.ok)
60
- return sandboxStop("upload", staged.failure);
64
+ let baseStepScript;
65
+ if (typeof baseStep === "string") {
66
+ baseStepScript = gitFetchBaseIndexScript(baseStep, base);
67
+ }
68
+ else {
69
+ if (!baseStep.ok)
70
+ return { kind: "failed", failure: { kind: "checkout-failed", failure: baseStep.failure } };
71
+ const staged = await context.runnerSandboxes.upload(sandbox, [
72
+ { name: STAGED_FILES.baseTarball, content: baseStep.value.tarball },
73
+ { name: STAGED_FILES.baseFileList, content: baseStep.value.fileList },
74
+ ], signal);
75
+ if (!staged.ok)
76
+ return sandboxStop("upload", staged.failure);
77
+ baseStepScript = baseIndexScript(base, staged.value.directory);
78
+ }
61
79
  if (prepared.baseFiles.length > 0) {
62
80
  const encoder = new TextEncoder();
63
81
  const placed = await context.runnerSandboxes.placeBaseFiles(sandbox, prepared.baseFiles.map(({ path, text }) => ({ name: path, content: encoder.encode(text) })), signal);
64
82
  if (!placed.ok)
65
83
  return sandboxStop("upload", placed.failure);
66
84
  }
67
- // Every credential the recipe declares goes on the steps' requests, from before the first toolchain step until
85
+ // Every credential the runner declares goes on the steps' requests, from before the first toolchain step until
68
86
  // `saveSnapshot` revokes them before saving (or the scope's fence revokes them if a step fails or the build is
69
- // canceled). storm's own base-index step falls inside: it runs only tar and git on the uploaded files, so it makes no
70
- // request, and revoking and granting again around it would add two writes and their failures for nothing.
87
+ // canceled). storm's own base-index step falls inside. With `snapshot.source: { kind: "git-fetch" }` its fetch needs
88
+ // them, since a credential for the Git host reaches the fetch's requests only this way. Otherwise it runs only tar and
89
+ // git on the uploaded files, so it makes no request, and revoking and granting again around it would add two writes
90
+ // and their failures for nothing.
71
91
  const steps = [
72
- ...recipe.snapshot.toolchains,
73
- { label: BASE_INDEX_LABEL, script: baseIndexScript(base, staged.value.directory) },
74
- ...recipe.snapshot.prebuild,
92
+ ...options.snapshot.toolchains,
93
+ { label: BASE_INDEX_LABEL, script: baseStepScript },
94
+ ...options.snapshot.prebuild,
75
95
  ];
76
- await progress.emit({ kind: "output-started", section: "snapshot", sandbox: sandbox.name, region: recipe.region });
96
+ await progress.emit({ kind: "output-started", section: "snapshot", sandbox: sandbox.name, region: options.region });
77
97
  let stop;
78
98
  if (request.credentials.length > 0) {
79
99
  const granted = await scope.grantCredentials(sandbox, request.credentials, signal);
@@ -114,7 +134,10 @@ export async function buildSnapshot(context, request, control, progress) {
114
134
  if (signal.aborted)
115
135
  return { kind: "aborted" };
116
136
  await progress.emit({ kind: "snapshot-saving" });
117
- const saved = await scope.saveSnapshot(sandbox, { expirationMs: SNAPSHOT_EXPIRATION_MS });
137
+ const saved = await scope.saveSnapshot(sandbox, {
138
+ expirationMs: SNAPSHOT_EXPIRATION_MS,
139
+ ...(publish === undefined ? {} : { keepStopped: true }),
140
+ });
118
141
  if (!saved.ok)
119
142
  return saved.failure.kind === "credential-not-revoked"
120
143
  ? networkPolicyStop("remove", "snapshot-save", saved.failure.failure)
@@ -123,9 +146,9 @@ export async function buildSnapshot(context, request, control, progress) {
123
146
  const entry = {
124
147
  teamId: access.teamId,
125
148
  projectId: access.projectId,
126
- region: recipe.region,
127
- runtime: recipe.runtime,
128
- recipeName: recipe.name,
149
+ region: options.region,
150
+ image: options.image,
151
+ runnerName: options.name,
129
152
  snapshotKey: prepared.snapshotKey,
130
153
  base,
131
154
  snapshotId: saved.value.snapshotId,
@@ -146,6 +169,15 @@ export async function buildSnapshot(context, request, control, progress) {
146
169
  });
147
170
  return {
148
171
  kind: "ok",
149
- value: { entry, ms, sizeBytes: saved.value.sizeBytes, cacheFailure: written.ok ? null : written.failure },
172
+ value: { entry, ms, sizeBytes: saved.value.sizeBytes, localIndexFailure: written.ok ? null : written.failure },
150
173
  };
151
174
  }
175
+ async function resolveGitFetchUrl(checkout, request) {
176
+ const remote = await checkout.remoteUrl(request);
177
+ if (!remote.ok)
178
+ return remote;
179
+ const fetchUrl = normalizeGitFetchUrl(remote.value);
180
+ if (fetchUrl.ok)
181
+ return { ok: true, value: fetchUrl.url };
182
+ return { ok: false, failure: { message: `the URL of Git remote "${request.remote}" ${fetchUrl.problem}` } };
183
+ }
@@ -19,7 +19,8 @@ export async function chooseSnapshotForRun(context, request, control, progress)
19
19
  // reporting cancellation or stopping sandboxes outside the running step.
20
20
  const scope = runnerSandboxScope(context, progress, {
21
21
  keepMs: 0,
22
- basePolicy: runnerNetworkPolicy(request.prepared.recipe),
22
+ basePolicy: runnerNetworkPolicy(request.prepared.options),
23
+ managedCredentials: request.prepared.options.managedCredentials,
23
24
  signal,
24
25
  });
25
26
  try {
@@ -1,85 +1,84 @@
1
1
  import type { CheckoutFailure, CheckoutHead, RunnerSnapshotEntry, UnreadableSnapshotEntry } from "./gateways.ts";
2
- import type { CheckedRecipe } from "./recipe.ts";
3
- import { type SnapshotCacheContext, type SnapshotRejectionReason } from "./snapshot-cache.ts";
2
+ import type { CheckedVercelSandboxOptions } from "./vercel-sandbox-options.ts";
3
+ import { type LocalSnapshotIndexContext, type SnapshotRejectionReason } from "./local-snapshot-index.ts";
4
4
  /**
5
- * One cached runner snapshot, as a checkout sees it: from the checkout's Git history, whether HEAD is its base or
6
- * holds it (`inHistory`), which an amend or a rebase can change, and how many commits HEAD has that its base lacks
7
- * (`builtBehind`). `inHistory` is null when storm didn't check it: outside a Git checkout, or without a recipe or a
8
- * base; `builtBehind` is null then too, and when the base isn't in HEAD's history. `picked` says a run here starts
9
- * from it, for its team and project.
10
- * `reason` says why a run here doesn't (`SnapshotRejectionReason`), `other-recipe` for another recipe's, or null for
5
+ * One runner snapshot in the local snapshot index, as a checkout sees it: from the checkout's Git history, whether HEAD
6
+ * is its base or holds it (`inHistory`), which an amend or a rebase can change, and how many commits HEAD has that its
7
+ * base lacks (`builtBehind`). `inHistory` is null when storm didn't check it: outside a Git checkout, or without a
8
+ * runner or a base; `builtBehind` is null then too, and when the base isn't in HEAD's history. `picked` says a run
9
+ * here starts from it, for its team and project.
10
+ * `reason` says why a run here doesn't (`SnapshotRejectionReason`), `other-runner` for another runner's, or null for
11
11
  * a picked one and when storm checked nothing.
12
12
  */
13
13
  export interface InspectedSnapshot {
14
14
  readonly entry: RunnerSnapshotEntry;
15
15
  readonly inHistory: boolean | null;
16
16
  readonly builtBehind: number | null;
17
+ readonly commitsBehindMergeBase: number | null;
17
18
  readonly expired: boolean;
18
19
  readonly picked: boolean;
19
- readonly reason: SnapshotRejectionReason | "other-recipe" | null;
20
+ readonly reason: SnapshotRejectionReason | "other-runner" | null;
20
21
  }
21
22
  /**
22
- * Why the inspection picked for no recipe: the directory is in no Git checkout (`no-checkout`), no runner recipe
23
- * applies there (`no-recipe`), or no base ref of the recipe exists locally and shares history with HEAD (`no-base`).
23
+ * Why the inspection picked for no runner: the directory is in no Git checkout (`no-checkout`), no Vercel Sandbox
24
+ * runner applies there (`no-runner`), or no base ref of the runner exists locally and shares history with HEAD
25
+ * (`no-base`).
24
26
  */
25
- export type UnpickedReason = "no-checkout" | "no-recipe" | "no-base";
26
- /** What `inspectSnapshotCache` found. */
27
- export interface SnapshotCacheInspection {
28
- /** Where the cache lives. */
27
+ export type UnpickedReason = "no-checkout" | "no-runner" | "no-base";
28
+ /** What `inspectLocalSnapshotIndex` found. */
29
+ export interface LocalSnapshotIndexInspection {
30
+ /** Where the local snapshot index lives. */
29
31
  readonly directory: string;
30
- /** The checkout the directory is in: its root, HEAD, and HEAD's merge-base with a base ref; null without one. */
32
+ /**
33
+ * The checkout the directory is in: its root, HEAD, and HEAD's merge-base with a base ref, with how many commits HEAD
34
+ * has that the merge-base lacks; null without one.
35
+ */
31
36
  readonly checkout: {
32
37
  readonly repoRoot: string;
33
38
  readonly head: CheckoutHead;
34
39
  readonly mergeBase: {
35
40
  readonly commit: string;
36
41
  readonly ref: string;
42
+ readonly commitsAfterBase: number;
37
43
  } | null;
38
44
  } | null;
39
- /** The recipe a run here uses, by name, when storm picked for it; else why it picked for none. */
45
+ /** The runner a run here uses, by name, when storm picked for it; else why it picked for none. */
40
46
  readonly picking: {
41
- readonly kind: "recipe";
42
- readonly recipe: string;
47
+ readonly kind: "runner";
48
+ readonly runner: string;
43
49
  } | {
44
50
  readonly kind: "none";
45
51
  readonly why: UnpickedReason;
46
52
  };
47
- /** The recipe's snapshots, and with `all` every other recipe's too. */
53
+ /** The run's snapshot key at the merge-base, when storm picked for a runner; else null. */
54
+ readonly snapshotKey: string | null;
55
+ /** The runner's snapshots, and with `all` every other runner's too. */
48
56
  readonly snapshots: readonly InspectedSnapshot[];
49
57
  readonly unreadable: readonly UnreadableSnapshotEntry[];
50
58
  }
51
59
  /**
52
- * How an inspection ended: what it found; the cache it couldn't list; git failing while it checked the checkout or a
53
- * snapshot (`checkout-failed`); or a declared base file of the recipe that couldn't be read at the merge-base
54
- * (`invalid-recipe`), as a run's local checks refuse it, with `path` the key inside the recipe.
60
+ * How an inspection ended: what it found; the local snapshot index it couldn't list (`local-index-unreadable`); git
61
+ * failing while it checked the checkout or a snapshot (`checkout-failed`); or a declared base file of the runner that
62
+ * couldn't be read at the merge-base (`invalid-runner`), as a run's local checks refuse it, with `path` the key inside
63
+ * the runner options.
55
64
  */
56
- export type SnapshotCacheInspectionOutcome = {
65
+ export type LocalSnapshotIndexInspectionOutcome = {
57
66
  readonly kind: "ok";
58
- readonly inspection: SnapshotCacheInspection;
67
+ readonly inspection: LocalSnapshotIndexInspection;
59
68
  } | {
60
- readonly kind: "cache-unreadable";
69
+ readonly kind: "local-index-unreadable";
61
70
  readonly path: string;
62
71
  readonly message: string;
63
72
  } | {
64
73
  readonly kind: "checkout-failed";
65
74
  readonly failure: CheckoutFailure;
66
75
  } | {
67
- readonly kind: "invalid-recipe";
76
+ readonly kind: "invalid-runner";
68
77
  readonly path: readonly string[];
69
78
  readonly problem: string;
70
79
  };
71
- /**
72
- * Inspects the cache from `cwd` for `recipe`, the runner recipe that applies there, if any. With a recipe, in a Git
73
- * checkout whose HEAD shares history with one of its base refs, it marks for each team and project the snapshot a run
74
- * here starts from, by a run's own rule (`classifySnapshotEntries`, `pickSnapshot`), and gives each other
75
- * snapshot of the recipe the reason it isn't picked. It reads the recipe's declared base files at the merge-base for
76
- * the run's snapshot key, as a run does. Otherwise it picks none and
77
- * says why. `all` adds the snapshots of other recipes, and of the recipe's other regions and runtimes, as
78
- * `other-recipe`. It lists the cache once and classifies that listing, which removes no file, so an expired entry of
79
- * the recipe stays and is `expired`. A git failure ends it with `checkout-failed`, as it ends a run.
80
- */
81
- export declare function inspectSnapshotCache(context: SnapshotCacheContext, request: {
80
+ export declare function inspectLocalSnapshotIndex(context: LocalSnapshotIndexContext, request: {
82
81
  readonly cwd: string;
83
- readonly recipe: CheckedRecipe | undefined;
82
+ readonly options: CheckedVercelSandboxOptions | undefined;
84
83
  readonly all: boolean;
85
- }): Promise<SnapshotCacheInspectionOutcome>;
84
+ }): Promise<LocalSnapshotIndexInspectionOutcome>;
@@ -1,32 +1,19 @@
1
- // What the runner snapshot cache holds, as a checkout sees it: every cached snapshot with where it was built, in
2
- // commits, and for the checkout's recipe which one a run here starts from and why not from each other one. It reads
3
- // the cache and Git, and changes nothing: no file is removed, nothing is minted, and no sandbox starts.
1
+ // What the local snapshot index holds, as a checkout sees it: every indexed snapshot with where it was built, in
2
+ // commits, and for the checkout's runner which one a run here starts from and why not from each other one. It reads
3
+ // the local snapshot index and Git, and changes nothing: no file is removed, nothing is minted, and no sandbox starts.
4
4
  import { resolveBase } from "./base.js";
5
- import { classifySnapshotEntries, isExpiredEntry, pickSnapshot, } from "./snapshot-cache.js";
5
+ import { classifySnapshotEntries, isExpiredEntry, matchesRunnerTarget, pickSnapshot, resolveAncestorDistances, } from "./local-snapshot-index.js";
6
6
  import { snapshotInputsAt } from "./snapshot-key.js";
7
- /**
8
- * Inspects the cache from `cwd` for `recipe`, the runner recipe that applies there, if any. With a recipe, in a Git
9
- * checkout whose HEAD shares history with one of its base refs, it marks for each team and project the snapshot a run
10
- * here starts from, by a run's own rule (`classifySnapshotEntries`, `pickSnapshot`), and gives each other
11
- * snapshot of the recipe the reason it isn't picked. It reads the recipe's declared base files at the merge-base for
12
- * the run's snapshot key, as a run does. Otherwise it picks none and
13
- * says why. `all` adds the snapshots of other recipes, and of the recipe's other regions and runtimes, as
14
- * `other-recipe`. It lists the cache once and classifies that listing, which removes no file, so an expired entry of
15
- * the recipe stays and is `expired`. A git failure ends it with `checkout-failed`, as it ends a run.
16
- */
17
- export async function inspectSnapshotCache(context, request) {
7
+ export async function inspectLocalSnapshotIndex(context, request) {
18
8
  const { checkout, runnerSnapshots } = context;
19
- const { recipe } = request;
9
+ const { options } = request;
20
10
  const listed = await runnerSnapshots.listEntries();
21
11
  if (!listed.ok)
22
- return { kind: "cache-unreadable", ...listed.failure };
12
+ return { kind: "local-index-unreadable", ...listed.failure };
23
13
  const { directory, entries, unreadable } = listed.value;
24
14
  const now = context.clock.now();
25
- const ofRecipe = (entry) => recipe !== undefined &&
26
- entry.recipeName === recipe.name &&
27
- entry.region === recipe.region &&
28
- entry.runtime === recipe.runtime;
29
- const shows = (entry) => request.all || recipe === undefined || ofRecipe(entry);
15
+ const ofRunner = (entry) => options !== undefined && matchesRunnerTarget(entry, options);
16
+ const shows = (entry) => request.all || options === undefined || ofRunner(entry);
30
17
  const shown = entries.filter(shows);
31
18
  const root = await checkout.repositoryRoot({ cwd: request.cwd });
32
19
  const head = root.ok ? await checkout.head({ repoRoot: root.value }) : undefined;
@@ -37,41 +24,53 @@ export async function inspectSnapshotCache(context, request) {
37
24
  directory,
38
25
  checkout: null,
39
26
  picking: { kind: "none", why: "no-checkout" },
27
+ snapshotKey: null,
40
28
  snapshots: shown.map((entry) => unchecked(entry, now)),
41
29
  unreadable,
42
30
  },
43
31
  };
44
32
  }
45
33
  const repoRoot = root.value;
46
- const resolved = recipe === undefined ? undefined : await resolveBase(checkout, { repoRoot, baseRefs: recipe.baseRefs });
34
+ const resolved = options === undefined ? undefined : await resolveBase(checkout, { repoRoot, baseRefs: options.baseRefs });
47
35
  if (resolved?.kind === "failed")
48
36
  return { kind: "checkout-failed", failure: resolved.failure };
49
- if (recipe === undefined || resolved === undefined || resolved.kind !== "resolved") {
37
+ if (options === undefined || resolved === undefined || resolved.kind !== "resolved") {
50
38
  return {
51
39
  kind: "ok",
52
40
  inspection: {
53
41
  directory,
54
42
  checkout: { repoRoot, head: head.value, mergeBase: null },
55
- picking: { kind: "none", why: recipe === undefined ? "no-recipe" : "no-base" },
43
+ picking: { kind: "none", why: options === undefined ? "no-runner" : "no-base" },
44
+ snapshotKey: null,
56
45
  snapshots: shown.map((entry) => unchecked(entry, now)),
57
46
  unreadable,
58
47
  },
59
48
  };
60
49
  }
61
50
  const mergeBase = resolved.base;
62
- const inputs = await snapshotInputsAt(checkout, { repoRoot, base: mergeBase, recipe });
51
+ const inputs = await snapshotInputsAt(checkout, { repoRoot, base: mergeBase, options });
63
52
  if (!inputs.ok)
64
- return { kind: "invalid-recipe", path: inputs.path, problem: inputs.problem };
53
+ return { kind: "invalid-runner", path: inputs.path, problem: inputs.problem };
65
54
  const afterBase = await checkout.commitCount({ repoRoot, from: mergeBase, to: "HEAD" });
66
55
  if (!afterBase.ok)
67
56
  return { kind: "checkout-failed", failure: afterBase.failure };
68
- // The one listing above is classified as a run would, but nothing is removed: an expired entry is `expired`.
57
+ // The one listing above is classified as a run would, with ancestors of the merge-base allowed, and nothing is
58
+ // removed: an expired entry is `expired`.
59
+ const ancestorDistances = await resolveAncestorDistances(context, {
60
+ repoRoot,
61
+ entries,
62
+ options,
63
+ mergeBase,
64
+ });
65
+ if (!ancestorDistances.ok)
66
+ return { kind: "checkout-failed", failure: ancestorDistances.failure };
69
67
  const read = classifySnapshotEntries(context, {
70
68
  entries,
71
- recipe,
69
+ options,
72
70
  base: mergeBase,
73
71
  snapshotKey: inputs.key,
74
72
  commitsAfterBase: afterBase.value,
73
+ ancestorDistances: ancestorDistances.value,
75
74
  });
76
75
  // The choice is per team and project, since the credential that names them isn't minted here. Every entry that isn't
77
76
  // a candidate keeps the classification's reason, since it is ruled out whoever the run's credential names.
@@ -82,7 +81,12 @@ export async function inspectSnapshotCache(context, request) {
82
81
  if (pick !== undefined)
83
82
  picked.add(pick);
84
83
  }
85
- const place = historyPlacer(context, { repoRoot, mergeBase, commitsAfterBase: afterBase.value });
84
+ const place = historyPlacer(context, {
85
+ repoRoot,
86
+ mergeBase,
87
+ commitsAfterBase: afterBase.value,
88
+ ancestorDistances: ancestorDistances.value,
89
+ });
86
90
  const snapshots = [];
87
91
  for (const verdict of read.verdicts) {
88
92
  const { entry } = verdict;
@@ -95,6 +99,7 @@ export async function inspectSnapshotCache(context, request) {
95
99
  entry,
96
100
  inHistory: true,
97
101
  builtBehind: candidate.builtBehind,
102
+ commitsBehindMergeBase: candidate.commitsBehindMergeBase,
98
103
  expired,
99
104
  picked: picked.has(candidate),
100
105
  reason: null,
@@ -108,28 +113,35 @@ export async function inspectSnapshotCache(context, request) {
108
113
  snapshots.push({
109
114
  entry,
110
115
  ...placed.value,
116
+ commitsBehindMergeBase: null,
111
117
  expired,
112
118
  picked: false,
113
- reason: verdict.kind === "rejected" ? verdict.rejection.reason : "other-recipe",
119
+ reason: verdict.kind === "rejected" ? verdict.rejection.reason : "other-runner",
114
120
  });
115
121
  }
116
122
  return {
117
123
  kind: "ok",
118
124
  inspection: {
119
125
  directory,
120
- checkout: { repoRoot, head: head.value, mergeBase: { commit: mergeBase, ref: resolved.ref } },
121
- picking: { kind: "recipe", recipe: recipe.name },
126
+ checkout: {
127
+ repoRoot,
128
+ head: head.value,
129
+ mergeBase: { commit: mergeBase, ref: resolved.ref, commitsAfterBase: afterBase.value },
130
+ },
131
+ picking: { kind: "runner", runner: options.name },
132
+ snapshotKey: inputs.key,
122
133
  snapshots,
123
134
  unreadable,
124
135
  },
125
136
  };
126
137
  }
127
- /** An entry storm checked nothing of: outside a Git checkout, or with no recipe or no base to pick for. */
138
+ /** An entry storm checked nothing of: outside a Git checkout, or with no runner or no base to pick for. */
128
139
  function unchecked(entry, now) {
129
140
  return {
130
141
  entry,
131
142
  inHistory: null,
132
143
  builtBehind: null,
144
+ commitsBehindMergeBase: null,
133
145
  expired: isExpiredEntry(entry, now),
134
146
  picked: false,
135
147
  reason: null,
@@ -137,12 +149,17 @@ function unchecked(entry, now) {
137
149
  }
138
150
  /**
139
151
  * Where a base sits in HEAD's history, for the list: whether HEAD is it or holds it, and if so how many commits HEAD
140
- * has that it lacks. Git is asked at most once per base, and nothing for the merge-base, whose count the caller has.
152
+ * has that it lacks. Git is asked at most once per base, and nothing for the merge-base or an ancestor of it, whose
153
+ * counts the caller has.
141
154
  */
142
155
  function historyPlacer(context, request) {
143
156
  const { repoRoot } = request;
144
157
  const known = new Map([
145
158
  [request.mergeBase, { inHistory: true, builtBehind: request.commitsAfterBase }],
159
+ ...Object.entries(request.ancestorDistances).map(([base, commitsBehindMergeBase]) => [
160
+ base,
161
+ { inHistory: true, builtBehind: request.commitsAfterBase + commitsBehindMergeBase },
162
+ ]),
146
163
  ]);
147
164
  return async (base) => {
148
165
  const answer = known.get(base);