@cnc-tools/storm 0.12.0 → 0.14.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 (188) hide show
  1. package/dist/application.js +5 -1
  2. package/dist/bin/storm.js +6 -2
  3. package/dist/build-info.js +1 -1
  4. package/dist/chunks/{chunk-FK4RLDEK.js → chunk-27P2QSIM.js} +1 -1
  5. package/dist/chunks/{chunk-ODQHQJLE.js → chunk-5ED3IDUJ.js} +749 -1121
  6. package/dist/chunks/{chunk-FSP3SJ35.js → chunk-5TMHYH7G.js} +16 -46
  7. package/dist/chunks/{chunk-Y3BUNNRG.js → chunk-BFLYGMG3.js} +12 -7
  8. package/dist/chunks/{chunk-LQKNI3EG.js → chunk-BRUIATTR.js} +6 -6
  9. package/dist/chunks/{chunk-RYRJNHL7.js → chunk-HOKDKP5A.js} +3 -9
  10. package/dist/chunks/{chunk-SXW6XN4R.js → chunk-IVRRGGCD.js} +60 -20
  11. package/dist/chunks/{chunk-TMQQYHUX.js → chunk-QBR5VHJ7.js} +1 -1
  12. package/dist/chunks/{chunk-YT5OROR7.js → chunk-RA4L2ACU.js} +12 -2
  13. package/dist/chunks/{chunk-TEEZL3GA.js → chunk-RKONDLPS.js} +17 -71
  14. package/dist/chunks/{chunk-IYM44FUX.js → chunk-UC6DULWY.js} +2 -2
  15. package/dist/chunks/{chunk-4XT5RC5T.js → chunk-XPCUINWS.js} +6 -42
  16. package/dist/chunks/{chunk-U7M3ZB3Z.js → chunk-YBPTMJUM.js} +123 -180
  17. package/dist/chunks/{chunk-ISGQJIQM.js → chunk-Z5OXOZD3.js} +125 -83
  18. package/dist/chunks/{chunk-7D6LC5JY.js → chunk-ZH5R7W4A.js} +7 -39
  19. package/dist/chunks/{live-app-AZ5N5HBD.js → live-app-FBVWUUMT.js} +7 -7
  20. package/dist/commands/exec/command.d.ts +4 -90
  21. package/dist/commands/exec/command.js +15 -41
  22. package/dist/commands/exec/define-run-command.d.ts +19 -100
  23. package/dist/commands/exec/define-run-command.js +48 -15
  24. package/dist/commands/exec/driver-plan.d.ts +24 -16
  25. package/dist/commands/exec/driver-plan.js +34 -15
  26. package/dist/commands/exec/driver-refusals.js +7 -6
  27. package/dist/commands/exec/exec-words.d.ts +1 -1
  28. package/dist/commands/exec/exec-words.js +8 -2
  29. package/dist/commands/exec/final-results.d.ts +39 -0
  30. package/dist/commands/exec/final-results.js +29 -0
  31. package/dist/commands/exec/live-view.js +18 -22
  32. package/dist/commands/exec/metadata.js +1 -1
  33. package/dist/commands/exec/outcomes.d.ts +15 -109
  34. package/dist/commands/exec/outcomes.js +25 -39
  35. package/dist/commands/exec/plan-run.d.ts +11 -3
  36. package/dist/commands/exec/plan-run.js +3 -2
  37. package/dist/commands/exec/progress.d.ts +3 -19
  38. package/dist/commands/exec/progress.js +16 -60
  39. package/dist/commands/exec/run-command.d.ts +5 -24
  40. package/dist/commands/exec/run-command.js +32 -84
  41. package/dist/commands/exec/run-metadata.d.ts +0 -6
  42. package/dist/commands/exec/run-metadata.js +2 -8
  43. package/dist/commands/exec/snapshot-text.d.ts +7 -16
  44. package/dist/commands/exec/snapshot-text.js +9 -49
  45. package/dist/commands/exec/test-plan.d.ts +2 -1
  46. package/dist/commands/exec/test-plan.js +13 -4
  47. package/dist/commands/exec/tests-summary.d.ts +2 -2
  48. package/dist/commands/exec/view.js +2 -12
  49. package/dist/commands/exec/worker-chart.d.ts +1 -1
  50. package/dist/commands/playwright/command.d.ts +12 -97
  51. package/dist/commands/playwright/command.js +14 -14
  52. package/dist/commands/playwright/metadata.js +2 -2
  53. package/dist/commands/runs/facts.d.ts +1 -37
  54. package/dist/commands/runs/facts.js +4 -36
  55. package/dist/commands/runs/list/command.d.ts +0 -72
  56. package/dist/commands/runs/list/command.js +6 -6
  57. package/dist/commands/runs/list/outcomes.d.ts +0 -36
  58. package/dist/commands/runs/logs/command.js +6 -6
  59. package/dist/commands/runs/show/command.d.ts +2 -74
  60. package/dist/commands/runs/show/command.js +16 -43
  61. package/dist/commands/runs/show/metadata.js +1 -1
  62. package/dist/commands/runs/show/outcomes.d.ts +1 -37
  63. package/dist/commands/runs/show/outcomes.js +8 -42
  64. package/dist/commands/snapshots/build/command.d.ts +14 -411
  65. package/dist/commands/snapshots/build/command.js +59 -234
  66. package/dist/commands/snapshots/build/metadata.js +10 -7
  67. package/dist/commands/snapshots/build/outcomes.d.ts +11 -241
  68. package/dist/commands/snapshots/build/outcomes.js +29 -196
  69. package/dist/commands/snapshots/list/command.d.ts +2 -36
  70. package/dist/commands/snapshots/list/command.js +20 -56
  71. package/dist/commands/snapshots/list/metadata.js +1 -1
  72. package/dist/commands/snapshots/list/outcomes.d.ts +2 -37
  73. package/dist/commands/snapshots/list/outcomes.js +13 -53
  74. package/dist/commands/vitest/command.d.ts +14 -98
  75. package/dist/commands/vitest/command.js +14 -14
  76. package/dist/commands/vitest/metadata.js +2 -2
  77. package/dist/config/resolve.d.ts +1 -1
  78. package/dist/config/resolve.js +2 -1
  79. package/dist/config/schema.d.ts +8 -0
  80. package/dist/config/schema.js +5 -4
  81. package/dist/core/events.d.ts +5 -6
  82. package/dist/core/run-state.d.ts +7 -29
  83. package/dist/core/run-state.js +3 -26
  84. package/dist/core/run.d.ts +6 -14
  85. package/dist/core/run.js +17 -28
  86. package/dist/extensions/playwright/driver.js +17 -10
  87. package/dist/extensions/testserver/commands/pool/create/command.js +4 -4
  88. package/dist/extensions/testserver/commands/pool/list/command.js +2 -2
  89. package/dist/extensions/testserver/definition.d.ts +1 -1
  90. package/dist/extensions/testserver/extension.d.ts +1 -1
  91. package/dist/extensions/testserver/options/rules.d.ts +3 -3
  92. package/dist/extensions/testserver/options/rules.js +5 -5
  93. package/dist/extensions/testserver/resource.d.ts +1 -1
  94. package/dist/extensions/testserver/vercel-cli/index.d.ts +1 -0
  95. package/dist/extensions/testserver/vercel-cli/index.js +1 -0
  96. package/dist/extensions/testserver/vercel-cli/report.js +5 -2
  97. package/dist/extensions/testserver/vercel-cli/session-id.d.ts +8 -0
  98. package/dist/extensions/testserver/vercel-cli/session-id.js +16 -0
  99. package/dist/extensions/testserver/vitest/config.d.ts +2 -2
  100. package/dist/extensions/testserver/vitest/config.js +2 -2
  101. package/dist/extensions/testserver/vitest/container-scope.d.ts +25 -16
  102. package/dist/extensions/testserver/vitest/container-scope.js +32 -13
  103. package/dist/extensions/testserver/vitest/diagnostics.d.ts +5 -4
  104. package/dist/extensions/testserver/vitest/diagnostics.js +15 -8
  105. package/dist/extensions/testserver/vitest/fixtures.d.ts +10 -1
  106. package/dist/extensions/testserver/vitest/fixtures.js +36 -10
  107. package/dist/extensions/testserver/vitest/types.d.ts +9 -0
  108. package/dist/extensions/vitest/driver.js +28 -14
  109. package/dist/extensions/vitest/plan/gateways.d.ts +28 -5
  110. package/dist/extensions/vitest/plan/gateways.js +2 -2
  111. package/dist/extensions/vitest/plan/list-output.d.ts +5 -0
  112. package/dist/extensions/vitest/plan/list-output.js +23 -9
  113. package/dist/extensions/vitest/plan/live/list-gateway.d.ts +3 -2
  114. package/dist/extensions/vitest/plan/live/list-gateway.js +77 -64
  115. package/dist/extensions/vitest/plan/plan-over.d.ts +19 -7
  116. package/dist/extensions/vitest/plan/plan-over.js +18 -7
  117. package/dist/extensions/vitest/plan/plan.d.ts +14 -5
  118. package/dist/extensions/vitest/plan/plan.js +23 -9
  119. package/dist/extensions.d.ts +2 -2
  120. package/dist/run-directory/index.d.ts +1 -1
  121. package/dist/run-directory/index.js +0 -1
  122. package/dist/run-directory/plan.d.ts +3 -2
  123. package/dist/run-directory/plan.js +6 -3
  124. package/dist/run-directory/recording.js +2 -2
  125. package/dist/run-directory/run-record.d.ts +18 -135
  126. package/dist/run-directory/run-record.js +8 -68
  127. package/dist/runner/build-snapshots.d.ts +50 -114
  128. package/dist/runner/build-snapshots.js +70 -159
  129. package/dist/runner/events.d.ts +4 -88
  130. package/dist/runner/gateways.d.ts +5 -23
  131. package/dist/runner/index.d.ts +5 -6
  132. package/dist/runner/index.js +1 -1
  133. package/dist/runner/live/snapshot-records.js +7 -18
  134. package/dist/runner/prepare.d.ts +11 -22
  135. package/dist/runner/prepare.js +6 -17
  136. package/dist/runner/ready.d.ts +16 -45
  137. package/dist/runner/ready.js +34 -59
  138. package/dist/runner/recipe.d.ts +5 -45
  139. package/dist/runner/recipe.js +0 -41
  140. package/dist/runner/sandboxed-command.d.ts +5 -3
  141. package/dist/runner/sandboxed-command.js +10 -4
  142. package/dist/runner/scope.d.ts +8 -25
  143. package/dist/runner/scope.js +4 -8
  144. package/dist/runner/session.d.ts +18 -65
  145. package/dist/runner/session.js +15 -83
  146. package/dist/runner/snapshot-build.d.ts +2 -2
  147. package/dist/runner/snapshot-cache.d.ts +22 -74
  148. package/dist/runner/snapshot-cache.js +15 -107
  149. package/dist/runner/snapshot-inspect.d.ts +9 -13
  150. package/dist/runner/snapshot-inspect.js +48 -57
  151. package/dist/runner/snapshot-key.d.ts +9 -14
  152. package/dist/runner/snapshot-key.js +15 -22
  153. package/dist/sdk/extension/driver.d.ts +32 -6
  154. package/dist/sdk/extension/driver.js +12 -2
  155. package/dist/sdk/extension/index.d.ts +1 -1
  156. package/dist/sdk/extension/index.js +2 -1
  157. package/dist/sdk/extension/resource-definition.d.ts +6 -5
  158. package/dist/vendor/testserver-sdk/container/api-request.d.ts +2 -3
  159. package/dist/vendor/testserver-sdk/container/api-request.js +2 -3
  160. package/dist/vendor/testserver-sdk/container/container.d.ts +12 -2
  161. package/dist/vendor/testserver-sdk/container/container.js +10 -7
  162. package/dist/vendor/testserver-sdk/container/recorder.d.ts +29 -7
  163. package/dist/vendor/testserver-sdk/container/recorder.js +26 -14
  164. package/dist/vendor/testserver-sdk/index.d.ts +1 -1
  165. package/dist/vendor/testserver-sdk/index.js +1 -1
  166. package/dist/vendor/testserver-sdk/proxy/exchange.d.ts +24 -5
  167. package/dist/vendor/testserver-sdk/proxy/exchange.js +43 -25
  168. package/dist/vendor/testserver-sdk/proxy/faulted-exchange.js +15 -10
  169. package/dist/vendor/testserver-sdk/proxy/faults.d.ts +6 -5
  170. package/dist/vendor/testserver-sdk/proxy/proxy.d.ts +10 -1
  171. package/dist/vendor/testserver-sdk/proxy/proxy.js +5 -3
  172. package/dist/vendor/testserver-sdk/proxy/records.d.ts +17 -17
  173. package/dist/vendor/testserver-sdk/proxy/records.js +18 -17
  174. package/dist/vendor/testserver-sdk/records/body.d.ts +7 -9
  175. package/dist/vendor/testserver-sdk/records/body.js +10 -15
  176. package/dist/vendor/testserver-sdk/records/headers.d.ts +79 -0
  177. package/dist/vendor/testserver-sdk/records/headers.js +162 -0
  178. package/dist/vendor/testserver-sdk/records/index.d.ts +2 -1
  179. package/dist/vendor/testserver-sdk/records/index.js +4 -2
  180. package/dist/vendor/testserver-sdk/records/records.d.ts +19 -10
  181. package/package.json +5 -4
  182. package/skills/overview.md +5 -5
  183. package/skills/read-run-output.md +8 -9
  184. package/dist/runner/snapshot-save.d.ts +0 -70
  185. package/dist/runner/snapshot-save.js +0 -160
  186. package/dist/runner/snapshot-start.d.ts +0 -25
  187. package/dist/runner/snapshot-start.js +0 -16
  188. package/skills/testserver-builds.md +0 -82
@@ -1,66 +1,45 @@
1
1
  import type { RunnerContext } from "./context.ts";
2
2
  import type { RunnerFailure, RunnerProgress } from "./events.ts";
3
3
  import type { CheckoutHead, RunnerSnapshotCacheFailure, RunnerSnapshotEntry, SandboxAccess } from "./gateways.ts";
4
- import { type PreparedRunner, type PrepareRunnerOutcome, type RunnerPrepareContext } from "./prepare.ts";
5
- import type { CheckedRecipe, VcpusRun } from "./recipe.ts";
4
+ import type { PrepareRunnerOutcome, RunnerPrepareContext } from "./prepare.ts";
5
+ import type { CheckedRecipe } from "./recipe.ts";
6
6
  import { type RunnerScopeFacts } from "./scope.ts";
7
7
  import type { RunnerSecrets } from "./secrets.ts";
8
8
  import { type BaseSnapshotPlan } from "./snapshot-build.ts";
9
- import { type DevSnapshotDrop } from "./snapshot-cache.ts";
10
- /**
11
- * What `storm snapshots build` builds: for this checkout (`checkout`), what the next run starts from, a base snapshot
12
- * when none fits and then a dev snapshot at HEAD's commit; or only a base snapshot at the commit `ref` names (`base`).
13
- * `full` uses nothing from the cache.
14
- */
15
- export type SnapshotBuildMode = {
16
- readonly kind: "checkout";
17
- readonly full: boolean;
18
- } | {
19
- readonly kind: "base";
20
- readonly ref: string;
21
- readonly full: boolean;
22
- };
23
- /** What `prepareSnapshotBuild` checks: where, which recipe, the run `vcpus` is called with, and what to build. */
24
- export interface SnapshotBuildRequest<Run> {
9
+ /** What `prepareSnapshotBuild` checks: where, which recipe, and what to build. */
10
+ export interface SnapshotBuildRequest {
25
11
  /** The directory the command started in, inside the checkout. */
26
12
  readonly cwd: string;
27
- readonly recipe: CheckedRecipe<Run>;
28
- /** A run with no resource, for the recipe's `vcpus`. */
29
- readonly vcpusRun: VcpusRun<Run>;
30
- readonly mode: SnapshotBuildMode;
13
+ readonly recipe: CheckedRecipe;
14
+ /** The ref `--base` names; undefined builds at the merge-base. */
15
+ readonly ref: string | undefined;
16
+ /** `--full`: build whatever the cache holds. */
17
+ readonly full: boolean;
31
18
  }
32
19
  /**
33
- * What a `--base` build warns about: the working tree has uncommitted changes, which a base snapshot doesn't hold
34
- * (`uncommitted`); or the commit is in the history of none of the recipe's base refs, `refs`, so a rewrite of it makes
35
- * the snapshot unusable (`not-on-base-ref`).
20
+ * A build, checked on this machine: the base snapshot it builds (`plan`), HEAD, whose `dirty` says the working tree
21
+ * has uncommitted changes, which a base snapshot doesn't hold, the ref `--base` named (null for the merge-base), HEAD's
22
+ * merge-base and its ref (null for a `--base` build in a checkout where no base ref shares history with HEAD), whether
23
+ * the commit it builds at is that merge-base (`atMergeBase`: a run here starts only from a snapshot at its merge-base,
24
+ * though a run in another checkout, or after a later merge-base, still might), and the base snapshots of `plan`'s base
25
+ * and key the cache holds with more than an hour left (`cached`, before the team and project filter).
36
26
  */
37
- export type SnapshotBuildWarning = {
38
- readonly kind: "uncommitted";
39
- } | {
40
- readonly kind: "not-on-base-ref";
41
- readonly refs: readonly string[];
42
- };
43
- /**
44
- * A build, checked on this machine. `checkout`: the run's own local checks (`prepareRunner`); unless its
45
- * `devSnapshots` is `reuse`, it says why the build saves no dev snapshot (the recipe doesn't trust dev snapshots, or
46
- * reuses none, so no run would start from one). `base`: the commit `ref` names, its snapshot steps and key, HEAD, the base snapshots of
47
- * that commit the cache holds with more than an hour left (`cached`, before the team and project filter), and what to
48
- * warn about.
49
- */
50
- export type PreparedSnapshotBuild = {
51
- readonly kind: "checkout";
52
- readonly prepared: PreparedRunner;
53
- readonly full: boolean;
54
- } | {
55
- readonly kind: "base";
27
+ export interface PreparedSnapshotBuild {
56
28
  readonly plan: BaseSnapshotPlan;
57
- readonly ref: string;
58
29
  readonly head: CheckoutHead;
30
+ readonly ref: string | null;
31
+ readonly mergeBase: {
32
+ readonly commit: string;
33
+ readonly ref: string;
34
+ } | null;
35
+ readonly atMergeBase: boolean;
59
36
  readonly cached: readonly RunnerSnapshotEntry[];
60
37
  readonly full: boolean;
61
- readonly warnings: readonly SnapshotBuildWarning[];
62
- };
63
- /** How a build's local checks ended: a run's refusals, or `ref-not-found` when `--base` names no local commit. */
38
+ }
39
+ /**
40
+ * How a build's local checks ended: a run's refusals, but `submodules`'s and `invalid-recipe`'s and `checkout-failed`'s
41
+ * that the build shares, or `ref-not-found` when `--base` names no local commit.
42
+ */
64
43
  export type PrepareSnapshotBuildOutcome = {
65
44
  readonly kind: "ok";
66
45
  readonly build: PreparedSnapshotBuild;
@@ -71,12 +50,12 @@ export type PrepareSnapshotBuildOutcome = {
71
50
  readonly ref: string;
72
51
  };
73
52
  /**
74
- * Runs a build's local checks, before anything is minted or started. For this checkout, they are a run's
75
- * (`prepareRunner`), reading dev snapshot candidates as the recipe allows. For `--base`, they are the repository's
76
- * root, HEAD, the submodule refusal, the commit the ref resolves to locally, its snapshot steps and key, the cache's
77
- * base snapshots of it, and the warnings. It never mints, acquires or creates.
53
+ * Runs a build's local checks, before anything is minted or started: the repository's root, HEAD, the submodule
54
+ * refusal, HEAD's merge-base (`resolveBase`, which refuses with `no-base-ref` only without `--base`), the commit
55
+ * `--base` resolves to locally, the snapshot steps and key at the commit it builds, the cache's base snapshots of it,
56
+ * and, when it builds at the merge-base, HEAD's count of commits after it. It never mints, acquires or creates, and removes no cache file.
78
57
  */
79
- export declare function prepareSnapshotBuild<Run>(context: RunnerPrepareContext, request: SnapshotBuildRequest<Run>): Promise<PrepareSnapshotBuildOutcome>;
58
+ export declare function prepareSnapshotBuild(context: RunnerPrepareContext, request: SnapshotBuildRequest): Promise<PrepareSnapshotBuildOutcome>;
80
59
  /** What `buildSnapshots` is handed: the checked build, where its sandboxes run, who starts them, and the secrets. */
81
60
  export interface BuildSnapshotsRequest {
82
61
  readonly build: PreparedSnapshotBuild;
@@ -90,89 +69,46 @@ export interface BuildSnapshotsRequest {
90
69
  /**
91
70
  * How a build ended, before its sandbox scope closed.
92
71
  *
93
- * - `up-to-date`: nothing to build, so nothing started. For this checkout, the next run starts from `snapshot`: a dev
94
- * snapshot built at HEAD's commit with a clean working tree, or, for a build that saves no dev snapshot, a base
95
- * snapshot that fits. For `--base`, the cache holds `snapshot` at that commit.
96
- * - `built`: `startedFrom` is the snapshot the runner sandbox started from, null for a build that started none;
97
- * `devSnapshot` the dev snapshot it saved and cached, null when it saved none.
98
- * - `dev-snapshot-not-saved`: the scrub or the save of the dev snapshot failed (`step`), with `message`.
99
- * - `not-cached`: it saved `snapshot`, the snapshot the build ends with (the dev snapshot, or the base snapshot of a
100
- * build that saves no dev snapshot), but the cache couldn't write its entry (`failure`), so no run finds it.
101
- * - `snapshot-gone`: starting from cached runner snapshot `entry` answered that it is gone, so its entry was removed;
102
- * `removal` is why it couldn't be, if it couldn't.
72
+ * - `up-to-date`: the cache holds `snapshot`, a base snapshot at the commit for the access's team and project, so
73
+ * nothing started.
74
+ * - `built`: it built `snapshot` in `ms` (`sizeBytes`), and the cache recorded it.
75
+ * - `not-cached`: it built `snapshot`, but the cache couldn't write its entry (`failure`), so no run finds it.
103
76
  * - `failed`: a step, a Sandbox call or the checkout failed.
104
- * - `aborted`: the signal aborted, in any stage, the dev snapshot's save included. A base snapshot's save runs to its
105
- * end once started, so a signal during it still leaves a saved snapshot, which `baseSnapshot` names. A cached
106
- * replacement still drops the dev snapshots on the base snapshot it replaced before the build stops.
107
- *
108
- * In `built`, `dev-snapshot-not-saved`, `not-cached`, and `aborted`, `baseSnapshot` is the base snapshot this build
109
- * built, with whether the cache wrote its entry (`SavedBaseSnapshot`), null when it built none. In `built`,
110
- * `not-cached`, and `aborted`, `dropped` is what `--full` dropped, null when it dropped nothing: without `--full`, or
111
- * when the base snapshot it built isn't cached, so the one it replaces stays usable, and so do the dev snapshots built
112
- * on it.
77
+ * - `aborted`: the signal aborted. A base snapshot's save runs to its end once started, so a signal during it still
78
+ * leaves a saved snapshot, which `snapshot` names with whether the cache wrote its entry; null when it saved none.
113
79
  */
114
80
  export type SnapshotBuildEnd = {
115
81
  readonly kind: "up-to-date";
116
82
  readonly snapshot: RunnerSnapshotEntry;
117
83
  } | {
118
84
  readonly kind: "built";
119
- readonly baseSnapshot: SavedBaseSnapshot | null;
120
- readonly startedFrom: RunnerSnapshotEntry | null;
121
- readonly devSnapshot: SavedDevSnapshot | null;
122
- readonly dropped: DevSnapshotDrop | null;
123
- } | {
124
- readonly kind: "dev-snapshot-not-saved";
125
- readonly step: "scrub" | "save-snapshot";
126
- readonly message: string;
127
- readonly baseSnapshot: SavedBaseSnapshot | null;
85
+ readonly snapshot: RunnerSnapshotEntry;
86
+ readonly ms: number;
87
+ readonly sizeBytes: number;
128
88
  } | {
129
89
  readonly kind: "not-cached";
130
90
  readonly snapshot: RunnerSnapshotEntry;
131
91
  readonly failure: RunnerSnapshotCacheFailure;
132
- readonly baseSnapshot: SavedBaseSnapshot | null;
133
- readonly dropped: DevSnapshotDrop | null;
134
- } | {
135
- readonly kind: "snapshot-gone";
136
- readonly entry: RunnerSnapshotEntry;
137
- readonly removal: RunnerSnapshotCacheFailure | undefined;
138
92
  } | {
139
93
  readonly kind: "failed";
140
94
  readonly failure: RunnerFailure;
141
95
  } | {
142
96
  readonly kind: "aborted";
143
- readonly baseSnapshot: SavedBaseSnapshot | null;
144
- readonly dropped: DevSnapshotDrop | null;
97
+ readonly snapshot: {
98
+ readonly entry: RunnerSnapshotEntry;
99
+ readonly cached: boolean;
100
+ } | null;
145
101
  };
146
- /** A base snapshot a build built and saved: its entry, and whether the cache wrote it, so a run finds it. */
147
- export interface SavedBaseSnapshot {
148
- readonly entry: RunnerSnapshotEntry;
149
- readonly cached: boolean;
150
- }
151
- /** A dev snapshot a build saved: the cache entry it wrote, how long the save took, and the snapshot's size. */
152
- export interface SavedDevSnapshot {
153
- readonly entry: RunnerSnapshotEntry;
154
- readonly ms: number;
155
- readonly sizeBytes: number;
156
- }
157
102
  /** How a build ended (`SnapshotBuildEnd`), with what closing its sandbox scope left (`cleanup`). */
158
103
  export type SnapshotBuildOutcome = SnapshotBuildEnd & {
159
104
  readonly cleanup: RunnerScopeFacts;
160
105
  };
161
106
  /**
162
- * Builds what a checked build needs, reporting to `progress`, and closes every sandbox it started however it ends,
163
- * keeping none. `signal` stops it in any stage: it says so, then closes the scope at once.
164
- *
165
- * For this checkout, it chooses what to start from by the one rule a run uses (`chooseSnapshotStart`), or, under
166
- * `full`, builds a base snapshot whatever the cache holds. When it reuses a dev snapshot built at HEAD's commit with a clean working tree, or, for a build that
167
- * saves no dev snapshot, any snapshot, it is up to date. Otherwise it obtains the start (`obtainSnapshot`), building a
168
- * base snapshot at the merge-base when it chose to; under `full`, once the cache holds the new base snapshot's entry,
169
- * it then drops the dev snapshots built on the base snapshot it replaced (`dropDevSnapshotsOn`), before any runner
170
- * sandbox starts. A build that saves no dev snapshot ends there. Otherwise it readies a runner sandbox on the start
171
- * (`readyRunner`) and saves it as a dev snapshot at HEAD's commit (`saveDevSnapshot`). For `--base`: a cached base
172
- * snapshot of the commit for the access's team and project is up to date, unless `full`; otherwise it builds one, and
173
- * under `full`, once its entry is cached, drops the dev snapshots built on the one it replaced. A base snapshot's save
174
- * isn't stopped by the signal, so after it the build checks the signal once, after any drop, and ends `aborted` with
175
- * what it saved.
107
+ * Builds the checked build's base snapshot, reporting to `progress`, and closes every sandbox it started however it
108
+ * ends, keeping none. A cached base snapshot at the commit for the access's team and project is up to date, unless
109
+ * `full`, which builds a new one that replaces its cache entry. `signal` stops it in any stage: it says so, then
110
+ * closes the scope at once. A base snapshot's save isn't stopped by the signal, so after it the build checks the signal
111
+ * once and ends `aborted` with what it saved.
176
112
  */
177
113
  export declare function buildSnapshots(context: RunnerContext, request: BuildSnapshotsRequest, control: {
178
114
  readonly signal: AbortSignal;
@@ -1,35 +1,21 @@
1
- // `storm snapshots build`: building what the runner snapshot cache lacks for a checkout, with no run. It owns its
2
- // sandbox scope from its first stage to its end, as a run's runner session does, and reuses a run's stages: the choice
3
- // of what to start from, obtaining it, readying the runner sandbox, and the dev snapshot save. It acquires no
4
- // resource, runs no command, and keeps no sandbox.
5
- import { prepareRunner } from "./prepare.js";
6
- import { obtainSnapshot, readyRunner } from "./ready.js";
1
+ // `storm snapshots build`: building one base snapshot that the runner snapshot cache lacks, with no run: at the
2
+ // merge-base by default, or at the commit `--base <ref>` names, which a run starts from only once that commit is its
3
+ // merge-base. It owns its sandbox scope from its first stage to its end, as a run's runner session does. It
4
+ // acquires no resource, runs no command, and keeps no sandbox.
5
+ import { resolveBase } from "./base.js";
7
6
  import { runnerSandboxScope } from "./scope.js";
8
7
  import { buildSnapshot } from "./snapshot-build.js";
9
- import { dropDevSnapshotsOn, hasTimeLeft, isDevEntry } from "./snapshot-cache.js";
8
+ import { hasTimeLeft } from "./snapshot-cache.js";
10
9
  import { snapshotStepsAt } from "./snapshot-key.js";
11
- import { saveDevSnapshot } from "./snapshot-save.js";
12
- import { chooseSnapshotStart } from "./snapshot-start.js";
13
10
  /**
14
- * Runs a build's local checks, before anything is minted or started. For this checkout, they are a run's
15
- * (`prepareRunner`), reading dev snapshot candidates as the recipe allows. For `--base`, they are the repository's
16
- * root, HEAD, the submodule refusal, the commit the ref resolves to locally, its snapshot steps and key, the cache's
17
- * base snapshots of it, and the warnings. It never mints, acquires or creates.
11
+ * Runs a build's local checks, before anything is minted or started: the repository's root, HEAD, the submodule
12
+ * refusal, HEAD's merge-base (`resolveBase`, which refuses with `no-base-ref` only without `--base`), the commit
13
+ * `--base` resolves to locally, the snapshot steps and key at the commit it builds, the cache's base snapshots of it,
14
+ * and, when it builds at the merge-base, HEAD's count of commits after it. It never mints, acquires or creates, and removes no cache file.
18
15
  */
19
16
  export async function prepareSnapshotBuild(context, request) {
20
- const { recipe, mode } = request;
21
- if (mode.kind === "checkout") {
22
- const prepared = await prepareRunner(context, {
23
- cwd: request.cwd,
24
- recipe,
25
- vcpusRun: request.vcpusRun,
26
- reuseDevSnapshots: recipe.reuseDevSnapshot,
27
- });
28
- if (prepared.kind !== "ok")
29
- return prepared;
30
- return { kind: "ok", build: { kind: "checkout", prepared: prepared.prepared, full: mode.full } };
31
- }
32
17
  const { checkout } = context;
18
+ const { recipe, ref } = request;
33
19
  const root = await checkout.repositoryRoot({ cwd: request.cwd });
34
20
  if (!root.ok)
35
21
  return { kind: "checkout-failed", failure: root.failure };
@@ -37,47 +23,53 @@ export async function prepareSnapshotBuild(context, request) {
37
23
  const head = await checkout.head({ repoRoot });
38
24
  if (!head.ok)
39
25
  return { kind: "checkout-failed", failure: head.failure };
26
+ const resolved = await resolveBase(checkout, { repoRoot, baseRefs: recipe.baseRefs });
27
+ if (resolved.kind === "failed")
28
+ return { kind: "checkout-failed", failure: resolved.failure };
29
+ const mergeBase = resolved.kind === "resolved" ? { commit: resolved.base, ref: resolved.ref } : null;
40
30
  const submodules = await checkout.submodules({ repoRoot });
41
31
  if (!submodules.ok)
42
32
  return { kind: "checkout-failed", failure: submodules.failure };
43
33
  if (submodules.value.length > 0)
44
34
  return { kind: "submodules", paths: [...submodules.value] };
45
- const resolved = await checkout.resolveCommit({ repoRoot, ref: mode.ref });
46
- if (!resolved.ok)
47
- return { kind: "checkout-failed", failure: resolved.failure };
48
- if (resolved.value === null)
49
- return { kind: "ref-not-found", ref: mode.ref };
50
- const base = resolved.value;
35
+ let base;
36
+ if (ref === undefined) {
37
+ if (resolved.kind !== "resolved")
38
+ return resolved;
39
+ base = resolved.base;
40
+ }
41
+ else {
42
+ const commit = await checkout.resolveCommit({ repoRoot, ref });
43
+ if (!commit.ok)
44
+ return { kind: "checkout-failed", failure: commit.failure };
45
+ if (commit.value === null)
46
+ return { kind: "ref-not-found", ref };
47
+ base = commit.value;
48
+ }
51
49
  const steps = await snapshotStepsAt(checkout, { repoRoot, base, recipe });
52
50
  if (!steps.ok)
53
51
  return { kind: "invalid-recipe", path: steps.path, problem: steps.problem };
54
52
  // An unreadable cache holds nothing to reuse: the build goes on, and builds.
55
53
  const listed = await context.runnerSnapshots.listEntries();
56
54
  const now = context.clock.now();
57
- const cached = (listed.ok ? listed.value.entries : []).filter((entry) => !isDevEntry(entry) &&
58
- entry.base === base &&
55
+ const cached = (listed.ok ? listed.value.entries : []).filter((entry) => entry.base === base &&
59
56
  entry.recipeName === recipe.name &&
60
57
  entry.region === recipe.region &&
61
58
  entry.runtime === recipe.runtime &&
62
59
  entry.snapshotKey === steps.key &&
63
60
  hasTimeLeft(entry, now));
64
- const warnings = [];
65
- if (head.value.dirty)
66
- warnings.push({ kind: "uncommitted" });
67
- let onBaseRef = false;
68
- for (const ref of recipe.baseRefs) {
69
- const contained = await checkout.contains({ repoRoot, ancestor: base, descendant: ref });
70
- if (contained.ok && contained.value)
71
- onBaseRef = true;
61
+ const atMergeBase = base === mergeBase?.commit;
62
+ // The built snapshot's count behind HEAD, for a build at the merge-base, the one snapshot a run here starts from.
63
+ let commitsAfterBase = null;
64
+ if (atMergeBase) {
65
+ const counted = await checkout.commitCount({ repoRoot, from: base, to: "HEAD" });
66
+ if (!counted.ok)
67
+ return { kind: "checkout-failed", failure: counted.failure };
68
+ commitsAfterBase = counted.value;
72
69
  }
73
- if (!onBaseRef)
74
- warnings.push({ kind: "not-on-base-ref", refs: recipe.baseRefs });
75
- const inHistory = await checkout.contains({ repoRoot, ancestor: base, descendant: "HEAD" });
76
- const afterBase = inHistory.ok && inHistory.value ? await checkout.commitCount({ repoRoot, from: base, to: "HEAD" }) : undefined;
77
70
  return {
78
71
  kind: "ok",
79
72
  build: {
80
- kind: "base",
81
73
  plan: {
82
74
  recipe,
83
75
  repoRoot,
@@ -85,37 +77,27 @@ export async function prepareSnapshotBuild(context, request) {
85
77
  toolchains: steps.toolchains,
86
78
  prebuild: steps.prebuild,
87
79
  snapshotKey: steps.key,
88
- commitsAfterBase: afterBase?.ok === true ? afterBase.value : null,
80
+ commitsAfterBase,
89
81
  },
90
- ref: mode.ref,
91
82
  head: head.value,
83
+ ref: ref ?? null,
84
+ mergeBase,
85
+ atMergeBase,
92
86
  cached,
93
- full: mode.full,
94
- warnings,
87
+ full: request.full,
95
88
  },
96
89
  };
97
90
  }
98
- /** A build that stopped on the signal before it saved anything. */
99
- const ABORTED_EARLY = { kind: "aborted", baseSnapshot: null, dropped: null };
100
91
  /**
101
- * Builds what a checked build needs, reporting to `progress`, and closes every sandbox it started however it ends,
102
- * keeping none. `signal` stops it in any stage: it says so, then closes the scope at once.
103
- *
104
- * For this checkout, it chooses what to start from by the one rule a run uses (`chooseSnapshotStart`), or, under
105
- * `full`, builds a base snapshot whatever the cache holds. When it reuses a dev snapshot built at HEAD's commit with a clean working tree, or, for a build that
106
- * saves no dev snapshot, any snapshot, it is up to date. Otherwise it obtains the start (`obtainSnapshot`), building a
107
- * base snapshot at the merge-base when it chose to; under `full`, once the cache holds the new base snapshot's entry,
108
- * it then drops the dev snapshots built on the base snapshot it replaced (`dropDevSnapshotsOn`), before any runner
109
- * sandbox starts. A build that saves no dev snapshot ends there. Otherwise it readies a runner sandbox on the start
110
- * (`readyRunner`) and saves it as a dev snapshot at HEAD's commit (`saveDevSnapshot`). For `--base`: a cached base
111
- * snapshot of the commit for the access's team and project is up to date, unless `full`; otherwise it builds one, and
112
- * under `full`, once its entry is cached, drops the dev snapshots built on the one it replaced. A base snapshot's save
113
- * isn't stopped by the signal, so after it the build checks the signal once, after any drop, and ends `aborted` with
114
- * what it saved.
92
+ * Builds the checked build's base snapshot, reporting to `progress`, and closes every sandbox it started however it
93
+ * ends, keeping none. A cached base snapshot at the commit for the access's team and project is up to date, unless
94
+ * `full`, which builds a new one that replaces its cache entry. `signal` stops it in any stage: it says so, then
95
+ * closes the scope at once. A base snapshot's save isn't stopped by the signal, so after it the build checks the signal
96
+ * once and ends `aborted` with what it saved.
115
97
  */
116
98
  export async function buildSnapshots(context, request, control, progress) {
117
99
  const { signal } = control;
118
- const scope = runnerSandboxScope(context, progress, { keepMs: () => 0 });
100
+ const scope = runnerSandboxScope(context, progress, { keepMs: 0 });
119
101
  const stop = () => {
120
102
  void progress.emit({ kind: "stopping", commandRunning: false, keepMs: 0 }).catch(() => undefined);
121
103
  void scope.close().catch(() => undefined);
@@ -139,97 +121,26 @@ async function buildIn(context, request, control, progress) {
139
121
  const { build, access, user, secrets } = request;
140
122
  const { signal } = control;
141
123
  if (signal.aborted)
142
- return ABORTED_EARLY;
143
- if (build.kind === "base") {
144
- const cached = build.cached.find((entry) => entry.teamId === access.teamId && entry.projectId === access.projectId);
145
- if (!build.full && cached !== undefined)
146
- return { kind: "up-to-date", snapshot: cached };
147
- const built = await buildSnapshot(context, { prepared: build.plan, access, user, secrets, why: { kind: build.full ? "full" : "base" } }, control, progress);
148
- if (built.kind === "aborted")
149
- return ABORTED_EARLY;
150
- if (built.kind !== "ok")
151
- return built;
152
- const { entry, cacheFailure } = built.value;
153
- const dropped = build.full && cacheFailure === null ? await dropOn(context, entry, progress) : null;
154
- if (signal.aborted)
155
- return { kind: "aborted", baseSnapshot: savedBaseOf(built.value), dropped };
156
- return baseOnlyEnd(built.value, dropped);
157
- }
158
- const { prepared } = build;
159
- const start = build.full
160
- ? { kind: "build", why: { kind: "full" } }
161
- : chooseSnapshotStart(prepared, access);
162
- if (start.kind === "reuse") {
163
- const { entry } = start.candidate;
164
- if (isDevEntry(entry) && entry.head === prepared.head.commit && !prepared.head.dirty)
165
- return { kind: "up-to-date", snapshot: entry };
166
- // A build that saves no dev snapshot needs only a snapshot that fits.
167
- if (prepared.devSnapshots !== "reuse")
168
- return { kind: "up-to-date", snapshot: entry };
169
- }
170
- const obtained = await obtainSnapshot(context, { prepared, access, user, secrets, start }, control, progress);
171
- if (obtained.kind === "aborted")
172
- return ABORTED_EARLY;
173
- if (obtained.kind !== "ok")
174
- return obtained;
175
- const { built } = obtained.value;
176
- // The base snapshot this build built, if any. Only a cached one replaces the old one.
177
- const baseSnapshot = built === null ? null : savedBaseOf(built);
178
- const dropped = build.full && baseSnapshot?.cached === true ? await dropOn(context, baseSnapshot.entry, progress) : null;
179
- const aborted = { kind: "aborted", baseSnapshot, dropped };
124
+ return { kind: "aborted", snapshot: null };
125
+ const cached = build.cached.find((entry) => entry.teamId === access.teamId && entry.projectId === access.projectId);
126
+ if (!build.full && cached !== undefined)
127
+ return { kind: "up-to-date", snapshot: cached };
128
+ const why = build.full ? "full" : build.ref === null ? "no-snapshot" : "base";
129
+ const built = await buildSnapshot(context, {
130
+ prepared: build.plan,
131
+ access,
132
+ user,
133
+ secrets,
134
+ why: why === "no-snapshot" ? { kind: why, rejected: [] } : { kind: why },
135
+ }, control, progress);
136
+ if (built.kind === "aborted")
137
+ return { kind: "aborted", snapshot: null };
138
+ if (built.kind !== "ok")
139
+ return built;
140
+ const { entry, cacheFailure, ms, sizeBytes } = built.value;
180
141
  if (signal.aborted)
181
- return aborted;
182
- if (prepared.devSnapshots !== "reuse")
183
- // A build that reuses a snapshot here returned above, but this branch doesn't count on it.
184
- return built === null ? { kind: "up-to-date", snapshot: obtained.value.entry } : baseOnlyEnd(built, dropped);
185
- const ready = await readyRunner(context, { prepared, access, user, secrets, start: obtained.value }, control, progress);
186
- if (ready.kind === "aborted")
187
- return aborted;
188
- if (ready.kind !== "ready")
189
- return ready;
190
- const { runner } = ready;
191
- const saved = await saveDevSnapshot(context, { ready: runner, branch: prepared.head.branch, head: prepared.head.commit }, control, progress);
192
- if (saved.entry === null) {
193
- const { save } = saved;
194
- // Only a signal stops a save: its handler is what closes the scope.
195
- return save.kind === "stopped"
196
- ? aborted
197
- : { kind: "dev-snapshot-not-saved", step: save.step, message: save.message, baseSnapshot };
198
- }
199
- const { entry, cacheFailure, save } = saved;
200
- if (cacheFailure !== null)
201
- return { kind: "not-cached", snapshot: entry, failure: cacheFailure, baseSnapshot, dropped };
202
- return {
203
- kind: "built",
204
- baseSnapshot,
205
- startedFrom: runner.startedFrom,
206
- devSnapshot: { entry, ms: save.ms, sizeBytes: save.sizeBytes },
207
- dropped,
208
- };
209
- }
210
- /** A base snapshot this build built, and whether the cache wrote its entry. */
211
- function savedBaseOf(built) {
212
- return { entry: built.entry, cached: built.cacheFailure === null };
213
- }
214
- /**
215
- * How a build that saves no dev snapshot ends once it built base snapshot `built`: `built` when the cache wrote its
216
- * entry, else `not-cached`, since no run finds it. It takes the base snapshot it built, never one it reused.
217
- */
218
- function baseOnlyEnd(built, dropped) {
219
- const baseSnapshot = savedBaseOf(built);
220
- return built.cacheFailure === null
221
- ? { kind: "built", baseSnapshot, startedFrom: null, devSnapshot: null, dropped }
222
- : { kind: "not-cached", snapshot: built.entry, failure: built.cacheFailure, baseSnapshot, dropped };
223
- }
224
- /**
225
- * Drops the dev snapshots built on the base snapshot `built` replaced, the cache entry of the same identity, and
226
- * reports what it dropped and what it couldn't.
227
- */
228
- async function dropOn(context, built, progress) {
229
- const dropped = await dropDevSnapshotsOn(context, built);
230
- if (dropped.snapshotIds.length > 0)
231
- await progress.emit({ kind: "dev-snapshots-dropped", snapshotIds: dropped.snapshotIds });
232
- for (const { message } of dropped.failures)
233
- await progress.emit({ kind: "dev-snapshots-not-dropped", message });
234
- return dropped;
142
+ return { kind: "aborted", snapshot: { entry, cached: cacheFailure === null } };
143
+ return cacheFailure === null
144
+ ? { kind: "built", snapshot: entry, ms, sizeBytes }
145
+ : { kind: "not-cached", snapshot: entry, failure: cacheFailure };
235
146
  }