@cnc-tools/storm 0.5.0 → 0.7.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 (171) hide show
  1. package/dist/build-info.js +1 -1
  2. package/dist/combine-errors.js +2 -2
  3. package/dist/commands/dashboard.js +1 -1
  4. package/dist/commands/{run → exec}/cleanup.d.ts +1 -1
  5. package/dist/commands/{run → exec}/cleanup.js +1 -1
  6. package/dist/commands/{run/outcomes.d.ts → exec/command.d.ts} +103 -112
  7. package/dist/commands/exec/command.js +23 -0
  8. package/dist/commands/{run → exec}/job-summary.d.ts +5 -1
  9. package/dist/commands/{run → exec}/job-summary.js +5 -2
  10. package/dist/commands/{run → exec}/live-view.js +29 -13
  11. package/dist/commands/exec/metadata.d.ts +69 -0
  12. package/dist/commands/exec/metadata.js +55 -0
  13. package/dist/commands/{run → exec}/mint-failed.js +4 -4
  14. package/dist/commands/exec/outcomes.d.ts +664 -0
  15. package/dist/commands/exec/outcomes.js +347 -0
  16. package/dist/commands/{run → exec}/progress.d.ts +14 -2
  17. package/dist/commands/{run → exec}/progress.js +54 -9
  18. package/dist/commands/exec/run-command.d.ts +227 -0
  19. package/dist/commands/exec/run-command.js +696 -0
  20. package/dist/commands/exec/run-metadata.d.ts +59 -0
  21. package/dist/commands/exec/run-metadata.js +61 -0
  22. package/dist/commands/{run → exec}/run-record.d.ts +110 -5
  23. package/dist/commands/{run → exec}/run-record.js +57 -1
  24. package/dist/commands/exec/testserver-flags.d.ts +48 -0
  25. package/dist/commands/exec/testserver-flags.js +80 -0
  26. package/dist/commands/{run → exec}/view.js +36 -4
  27. package/dist/commands/runs/facts.d.ts +25 -0
  28. package/dist/commands/runs/facts.js +38 -5
  29. package/dist/commands/runs/list/command.d.ts +25 -0
  30. package/dist/commands/runs/list/outcomes.d.ts +25 -0
  31. package/dist/commands/runs/logs/metadata.js +1 -1
  32. package/dist/commands/runs/logs/outcomes.js +4 -1
  33. package/dist/commands/runs/past-run.d.ts +2 -2
  34. package/dist/commands/runs/past-run.js +2 -2
  35. package/dist/commands/runs/show/command.d.ts +25 -0
  36. package/dist/commands/runs/show/metadata.js +2 -2
  37. package/dist/commands/runs/show/outcomes.d.ts +25 -0
  38. package/dist/commands/runs/show/outcomes.js +37 -5
  39. package/dist/commands/vitest/command.d.ts +325 -0
  40. package/dist/commands/vitest/command.js +138 -0
  41. package/dist/commands/vitest/metadata.d.ts +69 -0
  42. package/dist/commands/vitest/metadata.js +35 -0
  43. package/dist/commands/vitest/outcomes.d.ts +298 -0
  44. package/dist/commands/vitest/outcomes.js +77 -0
  45. package/dist/config/index.d.ts +2 -1
  46. package/dist/config/index.js +1 -0
  47. package/dist/config/resolve.d.ts +3 -3
  48. package/dist/config/resolve.js +3 -3
  49. package/dist/config/resource-config.d.ts +2 -2
  50. package/dist/config/schema.d.ts +1 -1
  51. package/dist/config/set.d.ts +15 -4
  52. package/dist/config/set.js +28 -12
  53. package/dist/config-file/define.d.ts +8 -6
  54. package/dist/context.d.ts +6 -3
  55. package/dist/context.js +4 -2
  56. package/dist/core/command-provider.d.ts +1 -1
  57. package/dist/core/events.d.ts +9 -7
  58. package/dist/core/presentation.js +1 -1
  59. package/dist/core/presentations.js +1 -1
  60. package/dist/core/run-state.d.ts +30 -6
  61. package/dist/core/run-state.js +19 -4
  62. package/dist/core/run.d.ts +17 -4
  63. package/dist/core/run.js +61 -25
  64. package/dist/resources/testserver/command.d.ts +1 -1
  65. package/dist/resources/testserver/command.js +1 -1
  66. package/dist/resources/testserver/config.d.ts +1 -1
  67. package/dist/resources/testserver/config.js +3 -2
  68. package/dist/resources/testserver/credential-facts.js +1 -1
  69. package/dist/resources/testserver/resource.d.ts +2 -2
  70. package/dist/resources/testserver/sandbox/create.d.ts +2 -2
  71. package/dist/resources/testserver/sandbox/create.js +2 -2
  72. package/dist/resources.d.ts +9 -6
  73. package/dist/resources.js +3 -3
  74. package/dist/runner/events.d.ts +64 -1
  75. package/dist/runner/gateways.d.ts +17 -6
  76. package/dist/runner/index.d.ts +5 -4
  77. package/dist/runner/index.js +4 -3
  78. package/dist/runner/live/snapshot-records.js +18 -4
  79. package/dist/runner/prepare.d.ts +23 -4
  80. package/dist/runner/prepare.js +13 -3
  81. package/dist/runner/ready.d.ts +7 -3
  82. package/dist/runner/ready.js +11 -5
  83. package/dist/runner/scope.d.ts +17 -1
  84. package/dist/runner/scope.js +4 -0
  85. package/dist/runner/snapshot-build.d.ts +3 -1
  86. package/dist/runner/snapshot-build.js +12 -2
  87. package/dist/runner/snapshot-cache.d.ts +46 -8
  88. package/dist/runner/snapshot-cache.js +60 -11
  89. package/dist/runner/snapshot-key.d.ts +12 -1
  90. package/dist/runner/snapshot-key.js +17 -1
  91. package/dist/runner/snapshot-save.d.ts +53 -0
  92. package/dist/runner/snapshot-save.js +148 -0
  93. package/dist/sdk/index.js +1 -1
  94. package/dist/sdk/payload/payload.d.ts +2 -2
  95. package/dist/sdk/payload/payload.js +2 -2
  96. package/dist/story/align.d.ts +1 -1
  97. package/dist/story/align.js +1 -1
  98. package/dist/story/definition.d.ts +22 -15
  99. package/dist/story/definition.js +2 -2
  100. package/dist/story/errors.js +1 -1
  101. package/dist/story/gateways.d.ts +45 -25
  102. package/dist/story/gateways.js +2 -2
  103. package/dist/story/host.d.ts +11 -8
  104. package/dist/story/host.js +37 -37
  105. package/dist/story/index.d.ts +1 -1
  106. package/dist/story/index.js +4 -4
  107. package/dist/story/json.d.ts +1 -1
  108. package/dist/story/json.js +2 -2
  109. package/dist/story/live/recording-gateway.d.ts +2 -0
  110. package/dist/story/live/{artifact-gateway.js → recording-gateway.js} +33 -12
  111. package/dist/story/mode.d.ts +2 -2
  112. package/dist/story/mode.js +1 -1
  113. package/dist/story/orphans.d.ts +23 -5
  114. package/dist/story/orphans.js +44 -8
  115. package/dist/story/recording.d.ts +62 -0
  116. package/dist/story/{artifact.js → recording.js} +31 -27
  117. package/dist/story/report.d.ts +21 -9
  118. package/dist/story/report.js +37 -25
  119. package/dist/story/settle.d.ts +23 -21
  120. package/dist/story/settle.js +17 -16
  121. package/dist/story/{run.d.ts → start.d.ts} +18 -17
  122. package/dist/story/{run.js → start.js} +66 -43
  123. package/dist/vercel-cli/driver.d.ts +1 -1
  124. package/dist/vercel-cli/entry.d.ts +1 -1
  125. package/dist/vercel-cli/entry.js +1 -1
  126. package/dist/vercel-cli/verbose.d.ts +2 -2
  127. package/dist/vercel-cli/verbose.js +2 -2
  128. package/dist/vitest/config.d.ts +5 -5
  129. package/dist/vitest/config.js +5 -5
  130. package/dist/vitest/find-vitest.d.ts +7 -0
  131. package/dist/vitest/find-vitest.js +28 -0
  132. package/dist/vitest/fixtures.d.ts +2 -2
  133. package/dist/vitest/fixtures.js +3 -3
  134. package/dist/vitest/gateways.d.ts +37 -6
  135. package/dist/vitest/gateways.js +3 -2
  136. package/dist/vitest/live/list-gateway.d.ts +7 -3
  137. package/dist/vitest/live/list-gateway.js +55 -8
  138. package/dist/vitest/plan.d.ts +41 -8
  139. package/dist/vitest/plan.js +47 -16
  140. package/dist/vitest/sandbox.d.ts +1 -1
  141. package/dist/vitest/sandbox.js +1 -1
  142. package/dist/vitest/test-events.d.ts +2 -2
  143. package/dist/vitest/test-events.js +3 -3
  144. package/dist/vitest/test-results.d.ts +1 -1
  145. package/dist/vitest/test-results.js +1 -1
  146. package/dist/vitest/types.d.ts +1 -1
  147. package/package.json +2 -2
  148. package/skills/overview.md +5 -4
  149. package/skills/read-run-output.md +1 -1
  150. package/dist/commands/run/command.d.ts +0 -327
  151. package/dist/commands/run/command.js +0 -620
  152. package/dist/commands/run/metadata.d.ts +0 -47
  153. package/dist/commands/run/metadata.js +0 -83
  154. package/dist/commands/run/outcomes.js +0 -332
  155. package/dist/story/artifact.d.ts +0 -60
  156. package/dist/story/live/artifact-gateway.d.ts +0 -2
  157. /package/dist/commands/{run → exec}/live-view.d.ts +0 -0
  158. /package/dist/commands/{run → exec}/mint-failed.d.ts +0 -0
  159. /package/dist/commands/{run → exec}/redaction.d.ts +0 -0
  160. /package/dist/commands/{run → exec}/redaction.js +0 -0
  161. /package/dist/commands/{run → exec}/run-collector.d.ts +0 -0
  162. /package/dist/commands/{run → exec}/run-collector.js +0 -0
  163. /package/dist/commands/{run → exec}/tests-summary.d.ts +0 -0
  164. /package/dist/commands/{run → exec}/tests-summary.js +0 -0
  165. /package/dist/commands/{run → exec}/text.d.ts +0 -0
  166. /package/dist/commands/{run → exec}/text.js +0 -0
  167. /package/dist/commands/{run → exec}/view.d.ts +0 -0
  168. /package/dist/commands/{run → exec}/waterfall.d.ts +0 -0
  169. /package/dist/commands/{run → exec}/waterfall.js +0 -0
  170. /package/dist/commands/{run → exec}/worker-chart.d.ts +0 -0
  171. /package/dist/commands/{run → exec}/worker-chart.js +0 -0
@@ -98,7 +98,7 @@ export declare function defineRefusals<const Schemas extends Readonly<Record<str
98
98
  export type UnpreparedErrorOf<Kind extends ResourceKind> = [Kind["prepareRefusal"]] extends [never] ? undefined : (refusal: Kind["prepareRefusal"]) => CommandError<Kind["reason"]>;
99
99
  /**
100
100
  * The command half of one resource, of kind `Kind`, whose refusal errors are `Refusals`. Every error a run ends with
101
- * for it is one of `errors` or `refusalErrors`, which the `run` command lists, and its reason is one of the kind's
101
+ * for it is one of `errors` or `refusalErrors`, which `exec` and `vitest` list, and its reason is one of the kind's
102
102
  * (`Kind["reason"]`), which the run's own outcomes check both ways. It knows nothing of the run's cleanup: the host
103
103
  * defines each refusal error with the run's cleanup beside its data.
104
104
  *
@@ -1,5 +1,5 @@
1
1
  import type { MintTarget } from "../credential/index.ts";
2
- import type { RunnerEvent, SnapshotCacheNote } from "../runner/index.ts";
2
+ import type { RunnerEvent, RunnerSandboxPlan, SnapshotCacheNote } from "../runner/index.ts";
3
3
  import type { Clock } from "../time/index.ts";
4
4
  import type { TestEvent } from "../sdk/index.ts";
5
5
  import type { AnyResources, ResourceEvent, ResourceFailures, ResourceHoldings, RunLane } from "./resource.ts";
@@ -15,7 +15,8 @@ export type LaneOutcome = "ready" | "failed" | "stopped";
15
15
  * provider order: none when it holds no resource with a lane, and `resources` the resources it holds, by name, in
16
16
  * provider order.
17
17
  * - `runner-prepared`: in a runner run, what the local checks found: the base, a full SHA, and the ref it is HEAD's
18
- * merge-base with; the untracked nested Git repositories the upload leaves out; and what the cache read noticed.
18
+ * merge-base with; the untracked nested Git repositories the upload leaves out; what the cache read noticed; and
19
+ * whether `--save-snapshot` saves nothing because HEAD is detached (`saveSkipped`).
19
20
  * - `minting`, `minted` and `requesting-token`: a credential's events (`CredentialEvent`): the run's one mint, which a
20
21
  * runner run makes for its runner sandbox and a resource makes in a local run, and a GitHub Actions OIDC token
21
22
  * request.
@@ -29,9 +30,10 @@ export type LaneOutcome = "ready" | "failed" | "stopped";
29
30
  * - `command-started`: the command started, or in a runner run is about to start in the runner sandbox.
30
31
  * - `command-ended`: the command ended as `outcome` after `ms`; `command` is its executable's name. A command the
31
32
  * run killed reports the runner's `command-stopped` instead.
32
- * - `cleanup-started`: the run is cleaning up: in a runner run (`runner`) stopping and deleting the runner's
33
- * sandboxes, but for the runner sandbox it keeps running `keepSandboxMs` when that is above 0 (always 0 in a local
34
- * run), then releasing its resources, holding what `holdings` says of each.
33
+ * - `cleanup-started`: the run is cleaning up: in a runner run (`runnerSandbox`, null in a local run) stopping and
34
+ * deleting the runner's sandboxes, but for the runner sandbox, which it keeps running `ms` when that is above 0
35
+ * (`keep`) or saves as a branch snapshot of `branch` while it releases the resources (`save`, only when the save
36
+ * runs); and releasing its resources, holding what `holdings` says of each.
35
37
  * - `cleanup-finished`: it is done; `resourceFailures` counts, for each resource the run held, what releasing it
36
38
  * couldn't do, and in a runner run `notStopped` and `notDeleted` sandboxes couldn't be stopped or deleted.
37
39
  * - `test`: in a runner run, a test event the command appended to the run payload's `testEvents` file, as it
@@ -53,6 +55,7 @@ export type RunEvent<K> = {
53
55
  readonly baseRef: string;
54
56
  readonly nestedRepositories: readonly string[];
55
57
  readonly notes: readonly SnapshotCacheNote[];
58
+ readonly saveSkipped: boolean;
56
59
  } | CredentialEvent | {
57
60
  readonly kind: "lanes-started";
58
61
  } | {
@@ -72,8 +75,7 @@ export type RunEvent<K> = {
72
75
  readonly ms: number;
73
76
  } | {
74
77
  readonly kind: "cleanup-started";
75
- readonly runner: boolean;
76
- readonly keepSandboxMs: number;
78
+ readonly runnerSandbox: RunnerSandboxPlan | null;
77
79
  readonly holdings: ResourceHoldings<K>;
78
80
  } | {
79
81
  readonly kind: "cleanup-finished";
@@ -1,5 +1,5 @@
1
1
  // The presentation contract: how a resource shows in a run's progress. A resource renders its own events as plain
2
2
  // lines and as the live view's notices, and, with a lane, its lane's rows in the live view's blocks and its row's label
3
- // on the waterfall. The `run` command's views own the layout around them: the time and lane prefix of a plain line,
3
+ // on the waterfall. A run's views own the layout around them: the time and lane prefix of a plain line,
4
4
  // each block's rows and their order, the glyphs and the widths. It names no resource.
5
5
  export {};
@@ -1,4 +1,4 @@
1
- // How the `run` command's views ask every resource how it shows, through each provider's presentation, in provider
1
+ // How a run's views (`exec`'s and `vitest`'s) ask every resource how it shows, through each provider's presentation, in provider
2
2
  // order: the presentation counterpart of `command-slots.ts`. `presentationSlotOf` binds one provider's presentation
3
3
  // to its name, so each function below indexes the run's maps by that name and never relates a name to the kinds map.
4
4
  /** `provider`'s presentation, bound to its name. */
@@ -1,5 +1,5 @@
1
1
  import type { MintTarget } from "../credential/index.ts";
2
- import type { KeptSandbox } from "../runner/index.ts";
2
+ import type { KeptSandbox, RunnerSandboxPlan } from "../runner/index.ts";
3
3
  import type { TimedRunEvent } from "./events.ts";
4
4
  import type { LaneStates, ResourceLanes } from "./lane.ts";
5
5
  import type { ResourceHoldings, RunLane } from "./resource.ts";
@@ -30,15 +30,35 @@ export interface RunnerStepState {
30
30
  /** The last line the step printed, while it runs. */
31
31
  readonly latest: string | undefined;
32
32
  }
33
- /** What the runner did with its runner snapshot: reused or built one, of the base it holds, or is building one. */
33
+ /**
34
+ * What the runner did with its runner snapshot: reused or built one, of the base it holds, or is building one. A reused
35
+ * branch snapshot names the branch and HEAD commit of the run that saved it; each is null for a base snapshot.
36
+ */
34
37
  export type RunnerSnapshotState = {
35
38
  readonly kind: "reused" | "built";
36
39
  readonly id: string;
37
40
  readonly base: string;
41
+ readonly branch: string | null;
42
+ readonly head: string | null;
38
43
  } | {
39
44
  readonly kind: "building";
40
45
  readonly summary: string;
41
46
  };
47
+ /**
48
+ * Saving the runner sandbox as a branch snapshot of `branch` (`--save-snapshot`): under way, saved as runner snapshot
49
+ * `id` at HEAD commit `head`, or not saved.
50
+ */
51
+ export type BranchSnapshotSaveState = {
52
+ readonly kind: "saving";
53
+ readonly branch: string;
54
+ } | {
55
+ readonly kind: "saved";
56
+ readonly id: string;
57
+ readonly branch: string;
58
+ readonly head: string;
59
+ } | {
60
+ readonly kind: "not-saved";
61
+ };
42
62
  /** One vitest worker, as its test events show it. */
43
63
  export interface TestWorkerState {
44
64
  readonly worker: number;
@@ -73,6 +93,8 @@ export interface RunnerState extends Span {
73
93
  readonly activity: "saving-snapshot" | "waiting-for-snapshot" | undefined;
74
94
  /** The runner sandbox the run kept running once it ended, once closing kept it. */
75
95
  readonly kept: KeptSandbox | undefined;
96
+ /** Saving the runner sandbox as a branch snapshot, once it began. */
97
+ readonly save: BranchSnapshotSaveState | undefined;
76
98
  }
77
99
  /** The command: its argument list and how it ended; `stopped` when the run killed it. */
78
100
  export interface CommandState extends Span {
@@ -81,10 +103,12 @@ export interface CommandState extends Span {
81
103
  }
82
104
  /** The cleanup over the registry's kinds `K`: what it stops and releases, and what it couldn't. */
83
105
  export interface CleanupState<K> extends Span {
84
- /** Whether it stops and deletes the runner's sandboxes. */
85
- readonly runner: boolean;
86
- /** How long it keeps the runner sandbox running, in milliseconds; 0 when it stops and deletes it. */
87
- readonly keepSandboxMs: number;
106
+ /**
107
+ * In a runner run, what it does with the runner sandbox while it stops and deletes the runner's other sandboxes: keeps
108
+ * it running `ms` (`keep`, stopping and deleting it at 0) or saves it as a branch snapshot (`save`); null in a local
109
+ * run.
110
+ */
111
+ readonly runnerSandbox: RunnerSandboxPlan | null;
88
112
  /** What the run held of each resource as cleanup started, which each resource's presentation names. */
89
113
  readonly holdings: ResourceHoldings<K>;
90
114
  /** What releasing the resources the run held couldn't do, summed over them, such as leases not released. */
@@ -71,6 +71,7 @@ function applyEvent(lanes, state, event, at) {
71
71
  uploadBytes: undefined,
72
72
  activity: undefined,
73
73
  kept: undefined,
74
+ save: undefined,
74
75
  },
75
76
  };
76
77
  case "minting":
@@ -125,8 +126,7 @@ function applyEvent(lanes, state, event, at) {
125
126
  status: "running",
126
127
  startedAt: at,
127
128
  endedAt: undefined,
128
- runner: event.runner,
129
- keepSandboxMs: event.keepSandboxMs,
129
+ runnerSandbox: event.runnerSandbox,
130
130
  holdings: event.holdings,
131
131
  resourceFailures: 0,
132
132
  notStopped: 0,
@@ -210,11 +210,16 @@ function runnerEnded(state, outcome, at) {
210
210
  function applyRunnerEvent(state, event, at) {
211
211
  switch (event.kind) {
212
212
  case "snapshot-reused":
213
- return withRunner(withStep(state, "snapshot", () => ({ status: "done", startedAt: at, endedAt: at })), () => ({ snapshot: { kind: "reused", id: event.snapshotId, base: event.base } }));
213
+ return withRunner(withStep(state, "snapshot", () => ({ status: "done", startedAt: at, endedAt: at })), () => ({
214
+ snapshot: { kind: "reused", id: event.snapshotId, base: event.base, branch: event.branch, head: event.head },
215
+ }));
214
216
  case "snapshot-build-started":
215
217
  return withRunner(withStep(state, "snapshot", () => ({ status: "running", startedAt: at })), () => ({ snapshot: { kind: "building", summary: event.summary } }));
216
218
  case "snapshot-built":
217
- return withRunner(withStep(state, "snapshot", () => ({ status: "done", endedAt: at, latest: undefined })), () => ({ snapshot: { kind: "built", id: event.snapshotId, base: event.base }, activity: undefined }));
219
+ return withRunner(withStep(state, "snapshot", () => ({ status: "done", endedAt: at, latest: undefined })), () => ({
220
+ snapshot: { kind: "built", id: event.snapshotId, base: event.base, branch: null, head: null },
221
+ activity: undefined,
222
+ }));
218
223
  case "snapshot-saving":
219
224
  return withRunner(state, () => ({ activity: "saving-snapshot" }));
220
225
  case "runner-sandbox-starting":
@@ -248,11 +253,21 @@ function applyRunnerEvent(state, event, at) {
248
253
  return withRunner(state.cleanup === undefined ? state : { ...state, cleanup: { ...state.cleanup, waiting: true } }, () => ({ activity: "waiting-for-snapshot" }));
249
254
  case "sandbox-kept":
250
255
  return withRunner(state, () => ({ kept: { name: event.name, stopsAt: event.stopsAt } }));
256
+ case "branch-snapshot-saving":
257
+ return withRunner(state, () => ({ save: { kind: "saving", branch: event.branch } }));
258
+ case "branch-snapshot-saved":
259
+ return withRunner(state, () => ({
260
+ save: { kind: "saved", id: event.snapshotId, branch: event.branch, head: event.head },
261
+ }));
262
+ case "branch-snapshot-not-saved":
263
+ return withRunner(state, () => ({ save: { kind: "not-saved" } }));
251
264
  // A step's outcome comes from its lane's end, not from the end of its output.
252
265
  case "output-started":
253
266
  case "output-ended":
254
267
  case "snapshot-entry-not-written":
255
268
  case "command-output-started":
269
+ case "branch-snapshots-dropped":
270
+ case "branch-snapshots-not-dropped":
256
271
  return state;
257
272
  }
258
273
  }
@@ -1,5 +1,5 @@
1
1
  import { type CredentialGateway, type CredentialSourceChoice, type GitHubActionsTokenGateway, type MintFailure, type MintTarget } from "../credential/index.ts";
2
- import { type PreparedRunner, type RunnerContext, type RunnerFailure, type RunnerScopeReport, type RunnerSnapshotCacheFailure, type RunnerSnapshotEntry } from "../runner/index.ts";
2
+ import { type PreparedRunner, type RunnerContext, type RunnerFailure, type RunnerSandboxPlan, type RunnerSave, type RunnerScopeReport, type RunnerSnapshotCacheFailure, type RunnerSnapshotEntry } from "../runner/index.ts";
3
3
  import type { RunProgress } from "./events.ts";
4
4
  import type { CommandGateway } from "./gateways.ts";
5
5
  import type { CoreContext, RunProviders, ResourceCanceledFacts, ResourceCleanup, ResourceFacts, ResourceRefusal, ResourceRequests, ResourceUnprepared } from "./resource.ts";
@@ -23,8 +23,12 @@ export interface RunRunnerRequest {
23
23
  readonly target: MintTarget;
24
24
  /** The local user name, for each sandbox's `user` tag. */
25
25
  readonly user: string;
26
- /** How long the runner sandbox keeps running once the run ends, in milliseconds; 0 stops and deletes it. */
27
- readonly keepSandboxMs: number;
26
+ /**
27
+ * What the run does with the runner sandbox once it ends, decided before it starts: keep it running for the keep time
28
+ * (0 stops and deletes it), or, under `--save-snapshot` on a branch, save it as a branch snapshot once the command
29
+ * ends on its own (`saveBranchSnapshot`), never keeping it.
30
+ */
31
+ readonly sandbox: RunnerSandboxPlan;
28
32
  }
29
33
  /** What every run was asked to do, local or in a runner run. */
30
34
  interface RunRequestBase {
@@ -88,13 +92,21 @@ export type RunRunnerFailure = RunnerFailure | {
88
92
  };
89
93
  /** What a runner run got from the runner sandbox, once the command ran in it. */
90
94
  export interface RanRunner {
95
+ /** The runner snapshot it started from, and its base. */
91
96
  readonly snapshotId: string;
92
97
  readonly base: string;
98
+ /** For a branch snapshot it started from, the branch and HEAD commit of the run that saved it; null otherwise. */
99
+ readonly snapshotBranch: string | null;
100
+ readonly snapshotHead: string | null;
93
101
  /** Whether this run built the runner snapshot. */
94
102
  readonly built: boolean;
95
103
  readonly vcpus: number;
96
104
  readonly region: string;
97
105
  readonly runtime: string;
106
+ /** How long the build step took, in milliseconds. */
107
+ readonly buildMs: number;
108
+ /** How saving the runner sandbox as a branch snapshot ended; null without `--save-snapshot`. */
109
+ readonly save: RunnerSave | null;
98
110
  }
99
111
  /**
100
112
  * How a run ended, over the registry's kinds `K`.
@@ -181,7 +193,8 @@ export type RunStopped<K> = ResourceRefusal<K> | {
181
193
  *
182
194
  * Release happens in `finally`, however the run ended, a throw included: once the command has stopped and, in a
183
195
  * runner run, the runner's sandboxes are closed, each resource is released in reverse order, even when the
184
- * `cleanup-started` event can't be reported.
196
+ * `cleanup-started` event can't be reported. A runner run that saves the runner sandbox as a branch snapshot releases
197
+ * them while the save runs, since the command is done with them.
185
198
  */
186
199
  export declare function executeRun<K, C extends RunContext>(providers: RunProviders<K, C>, context: C, request: RunRequest<K>, control: RunControl, progress: RunProgress<K>): Promise<RunOutcome<K>>;
187
200
  export {};
package/dist/core/run.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { posix } from "node:path";
2
2
  import { credentialSourceFor, mintSource, } from "../credential/index.js";
3
- import { readyRunner, runnerSandboxScope, REMOTE_TEST_EVENTS_PATH, lineSplitter, runRemote, } from "../runner/index.js";
3
+ import { readyRunner, runnerSandboxScope, REMOTE_TEST_EVENTS_PATH, keptMs, lineSplitter, runRemote, saveBranchSnapshot, } from "../runner/index.js";
4
4
  import { parseTestEvent } from "../sdk/index.js";
5
5
  import { mintReported, mintSourceReported } from "./mint.js";
6
6
  import { colorEnvironment, commandEnvironment, runPayload } from "./payload.js";
@@ -17,7 +17,8 @@ import { acquireResources, canceledHolding, heldLanes, heldResources, prepareRes
17
17
  *
18
18
  * Release happens in `finally`, however the run ended, a throw included: once the command has stopped and, in a
19
19
  * runner run, the runner's sandboxes are closed, each resource is released in reverse order, even when the
20
- * `cleanup-started` event can't be reported.
20
+ * `cleanup-started` event can't be reported. A runner run that saves the runner sandbox as a branch snapshot releases
21
+ * them while the save runs, since the command is done with them.
21
22
  */
22
23
  export async function executeRun(providers, context, request, control, progress) {
23
24
  const slots = resourceSlots(providers, context, request.resources);
@@ -37,6 +38,7 @@ export async function executeRun(providers, context, request, control, progress)
37
38
  baseRef: prepared.baseRef,
38
39
  nestedRepositories: prepared.upload.nestedRepositories,
39
40
  notes: prepared.notes,
41
+ saveSkipped: prepared.save?.kind === "skipped",
40
42
  });
41
43
  }
42
44
  const unprepared = await prepareResources(slots, progress);
@@ -44,35 +46,38 @@ export async function executeRun(providers, context, request, control, progress)
44
46
  return unprepared;
45
47
  // Each slot keeps what its resource holds, pushed as it is acquired: the run releases all of it however it ends.
46
48
  let cleanupStarted = false;
47
- // Said once, before the runner's sandboxes are stopped in a runner run, else before the resources are released.
48
- const startCleanup = async () => {
49
+ // Said once, before the runner's sandboxes are stopped in a runner run, else before the resources are released, with
50
+ // what cleanup does with the runner sandbox (`runnerSandbox`). The first call's says it: a runner run that saves a
51
+ // branch snapshot calls `release` with its `save` before anything else starts cleanup.
52
+ const startCleanup = async (runnerSandbox) => {
49
53
  if (cleanupStarted)
50
54
  return;
51
55
  cleanupStarted = true;
52
- await progress.emit({
53
- kind: "cleanup-started",
54
- runner: request.runner !== undefined,
55
- keepSandboxMs: request.runner?.keepSandboxMs ?? 0,
56
- holdings: resourceHoldings(slots),
57
- });
56
+ await progress.emit({ kind: "cleanup-started", runnerSandbox, holdings: resourceHoldings(slots) });
58
57
  };
58
+ let resourceCleanup = {};
59
+ let releasing;
60
+ // Once: reporting cleanup's start can fail, and releasing what the run holds must not depend on it.
61
+ const release = (runnerSandbox) => (releasing ??= (async () => {
62
+ try {
63
+ await startCleanup(runnerSandbox);
64
+ }
65
+ finally {
66
+ resourceCleanup = await releaseResources(slots, progress);
67
+ }
68
+ })());
69
+ // What cleanup does with the runner sandbox when no save runs: the plan's keep time, 0 for a save that didn't run.
70
+ const unsaved = request.runner === undefined ? null : { kind: "keep", ms: keptMs(request.runner.sandbox) };
59
71
  let ended;
60
72
  let runnerCleanup = null;
61
- let resourceCleanup = {};
62
73
  try {
63
74
  ({ ended, runnerCleanup } =
64
75
  request.runner === undefined
65
76
  ? { ended: await provisionAndRun(context, request, slots, control, progress), runnerCleanup: null }
66
- : await provisionAndRunRemote(context, request, slots, control, progress, startCleanup));
77
+ : await provisionAndRunRemote(context, request, slots, control, progress, { startCleanup, release }));
67
78
  }
68
79
  finally {
69
- // Reporting cleanup's start can fail; releasing what the run holds must not depend on it.
70
- try {
71
- await startCleanup();
72
- }
73
- finally {
74
- resourceCleanup = await releaseResources(slots, progress);
75
- }
80
+ await release(unsaved);
76
81
  }
77
82
  await progress.emit({
78
83
  kind: "cleanup-finished",
@@ -179,10 +184,16 @@ function runnerStopped(outcome) {
179
184
  * for a create in flight and a snapshot still saving run while readying winds down; the close the run awaits later
180
185
  * gets that close's report, or its error. A runner run always mints, whatever resources it holds, so its request names
181
186
  * no credential source: the command layer refuses `--credential github-actions` with it.
187
+ *
188
+ * The run's plan (`request.runner.sandbox`) gives the scope its keep time, which is 0 for a `save` plan: such a run
189
+ * never keeps its runner sandbox, however it ends. Under a `save` plan, once the command ended on its own and no signal
190
+ * arrived, it saves the runner sandbox as a branch snapshot (`saveBranchSnapshot`) while the resources are released,
191
+ * and closes the scope once the save is done, even when releasing them threw.
182
192
  */
183
- async function provisionAndRunRemote(context, request, slots, control, progress, startCleanup) {
193
+ async function provisionAndRunRemote(context, request, slots, control, progress, cleanup) {
184
194
  const runnerProgress = { emit: (event) => progress.emit({ kind: "runner", event }) };
185
- const keepMs = request.runner.keepSandboxMs;
195
+ const plan = request.runner.sandbox;
196
+ const keepMs = keptMs(plan);
186
197
  const scope = runnerSandboxScope(context, runnerProgress, { keepMs });
187
198
  let commandRunning = false;
188
199
  // Said before the close starts, so the stopping line comes before any line the close's waits print.
@@ -202,9 +213,29 @@ async function provisionAndRunRemote(context, request, slots, control, progress,
202
213
  commandRunning = true;
203
214
  },
204
215
  }, progress, runnerProgress);
205
- await startCleanup();
216
+ commandRunning = false;
217
+ const unsaved = { kind: "keep", ms: keepMs };
218
+ if (ended.kind !== "command-ended") {
219
+ await cleanup.startCleanup(unsaved);
220
+ return { ended, runnerCleanup: { ...(await scope.close()), target: request.runner.target } };
221
+ }
222
+ const { ready, ...rest } = ended;
223
+ const { prepared } = request.runner;
224
+ let save = prepared.save?.kind === "skipped" ? prepared.save : null;
225
+ const action = plan.kind === "save" && !control.signal.aborted ? plan : unsaved;
226
+ if (action.kind === "save") {
227
+ const saving = saveBranchSnapshot(context, { ready, branch: action.branch, head: prepared.head.commit }, { scope, signal: control.signal }, runnerProgress);
228
+ // The save settles before the scope closes, even when releasing the resources threw.
229
+ try {
230
+ await cleanup.release(action);
231
+ }
232
+ finally {
233
+ save = await saving;
234
+ }
235
+ }
236
+ await cleanup.startCleanup(action);
206
237
  const runnerCleanup = { ...(await scope.close()), target: request.runner.target };
207
- return { ended, runnerCleanup };
238
+ return { ended: { ...rest, runner: { ...rest.runner, save } }, runnerCleanup };
208
239
  }
209
240
  finally {
210
241
  control.signal.removeEventListener("abort", stop);
@@ -290,13 +321,18 @@ async function mintAndRunRemote(context, request, slots, control, progress, runn
290
321
  resources: resourcesFacts(slots),
291
322
  command,
292
323
  runner: {
293
- snapshotId: ready.snapshotId,
294
- base: ready.base,
324
+ snapshotId: ready.startedFrom.snapshotId,
325
+ base: ready.startedFrom.base,
326
+ snapshotBranch: ready.startedFrom.branch ?? null,
327
+ snapshotHead: ready.startedFrom.head ?? null,
295
328
  built: ready.built,
296
329
  vcpus: ready.vcpus,
297
330
  region: ready.region,
298
331
  runtime: ready.runtime,
332
+ buildMs: ready.buildMs,
333
+ save: null,
299
334
  },
335
+ ready,
300
336
  };
301
337
  }
302
338
  /**
@@ -112,7 +112,7 @@ export declare const testserverPoolRefusalErrors: {
112
112
  /**
113
113
  * The Testserver pool resource's command half, `resources.testserverPool`, with its errors: its prepare's,
114
114
  * `pool_unavailable`, and its refusal errors. A failed mint with no Testserver sandbox in hand ends the run as the
115
- * run's own `mint_failed`, which the `run` command defines.
115
+ * run's own `mint_failed`, which `exec` and `vitest` define.
116
116
  */
117
117
  export declare const testserverPoolCommand: {
118
118
  errors: import("@vercel/clinkr").SharedErrors<{
@@ -185,7 +185,7 @@ export const testserverPoolRefusalErrors = defineRefusals({
185
185
  /**
186
186
  * The Testserver pool resource's command half, `resources.testserverPool`, with its errors: its prepare's,
187
187
  * `pool_unavailable`, and its refusal errors. A failed mint with no Testserver sandbox in hand ends the run as the
188
- * run's own `mint_failed`, which the `run` command defines.
188
+ * run's own `mint_failed`, which `exec` and `vitest` define.
189
189
  */
190
190
  export const testserverPoolCommand = {
191
191
  errors: testserverPoolPrepareErrors,
@@ -9,7 +9,7 @@ import type { TestserverPoolOptions } from "./resource.ts";
9
9
  export type TestserverPoolSettings = TestserverPoolRequest;
10
10
  /**
11
11
  * The Testserver pool resource's config. Every option has a default, so a run that holds the resource, by the file or
12
- * by a `--set` of any option, has them all. Its checks across options:
12
+ * by a flag for any option, has them all. Its checks across options:
13
13
  *
14
14
  * - under `noCreate`, which creates no Testserver sandbox, a `ttl` from a flag is refused, and the file's is unused;
15
15
  * - otherwise the `ttl` must be longer than `minTimeLeft`, or no Testserver sandbox the run created would have the time
@@ -1,5 +1,6 @@
1
1
  // The Testserver pool resource's config: its section `resources.testserverPool` in `storm.config.ts`, the rule
2
- // and default of each option, and the checks across its options. `config` loads, reads `--set` and merges against it;
2
+ // and default of each option, and the checks across its options. `config` loads and merges against it, and `exec` and
3
+ // `vitest` check their own `--testserver-<option>` flags with its rules;
3
4
  // the command half (`command.ts`) settles the resolved options into the run's request.
4
5
  import { checkBoolean, checkNonEmptyString, describeValue, optionKeyPath, readBooleanText, readTextAsIs, readWholeNumberText, wrongValue, } from "../../config/index.js";
5
6
  import { parseDuration, parseTtl } from "../../time/index.js";
@@ -26,7 +27,7 @@ function ttl(value) {
26
27
  const KIND = "testserverPool";
27
28
  /**
28
29
  * The Testserver pool resource's config. Every option has a default, so a run that holds the resource, by the file or
29
- * by a `--set` of any option, has them all. Its checks across options:
30
+ * by a flag for any option, has them all. Its checks across options:
30
31
  *
31
32
  * - under `noCreate`, which creates no Testserver sandbox, a `ttl` from a flag is refused, and the file's is unused;
32
33
  * - otherwise the `ttl` must be longer than `minTimeLeft`, or no Testserver sandbox the run created would have the time
@@ -1,4 +1,4 @@
1
- // How the Testserver pool's `run` errors and `pool create` report a credential source's failures: a failed GitHub
1
+ // How the Testserver pool's run errors and `pool create` report a credential source's failures: a failed GitHub
2
2
  // Actions OIDC token request, and where a rejected credential came from.
3
3
  import { z } from "zod";
4
4
  import { describeTokenRequestFailure, rejectedCredentialFix, } from "../../credential/index.js";
@@ -1,6 +1,6 @@
1
1
  /**
2
- * The Testserver pool resource's options: the Testserver sandboxes a run holds for its command. `storm run
3
- * --set resources.testserverPool.<option>=<value>` overrides each one, and `pool create` reads `build` and `ttl`.
2
+ * The Testserver pool resource's options: the Testserver sandboxes a run holds for its command. `storm vitest`
3
+ * and `storm exec` override each one with its own flag, `--testserver-<option>`, and `pool create` reads `build` and `ttl`.
4
4
  */
5
5
  export interface TestserverPoolOptions {
6
6
  /** How many Testserver sandboxes a run gets: 1 to 32; 1 by default. */
@@ -2,8 +2,8 @@ import type { Credential } from "../../../credential/index.ts";
2
2
  import type { ControlPlaneGateway, CreateOutcome, CreateProgress } from "./gateways.ts";
3
3
  import type { Timer } from "../../../time/index.ts";
4
4
  /**
5
- * The TTL a Testserver sandbox gets unless the `ttl` setting (`resources.testserverPool.ttl`, `--set` of it, or `pool
6
- * create --ttl`) says otherwise: 5 hours.
5
+ * The TTL a Testserver sandbox gets unless the `ttl` setting (`resources.testserverPool.ttl`, `run --testserver-ttl`,
6
+ * or `pool create --ttl`) says otherwise: 5 hours.
7
7
  */
8
8
  export declare const DEFAULT_TTL_MINUTES = 300;
9
9
  /** A TTL as a person reads it: `5 hours`, `1 hour`, `30 minutes`, `90 minutes`. */
@@ -1,6 +1,6 @@
1
1
  /**
2
- * The TTL a Testserver sandbox gets unless the `ttl` setting (`resources.testserverPool.ttl`, `--set` of it, or `pool
3
- * create --ttl`) says otherwise: 5 hours.
2
+ * The TTL a Testserver sandbox gets unless the `ttl` setting (`resources.testserverPool.ttl`, `run --testserver-ttl`,
3
+ * or `pool create --ttl`) says otherwise: 5 hours.
4
4
  */
5
5
  export const DEFAULT_TTL_MINUTES = 300;
6
6
  /** A TTL as a person reads it: `5 hours`, `1 hour`, `30 minutes`, `90 minutes`. */
@@ -1,4 +1,4 @@
1
- import { type StormCleanupFacts } from "./commands/run/cleanup.ts";
1
+ import { type StormCleanupFacts } from "./commands/exec/cleanup.ts";
2
2
  import type { CommandMount } from "@vercel/clinkr";
3
3
  import type { AnyResourceConfig, GivenResources, OptionsResolution, ResolvedResources } from "./config/index.ts";
4
4
  import type { StormContext } from "./context.ts";
@@ -282,19 +282,22 @@ export type FittingResourceConfig<K> = {
282
282
  export declare const RESOURCE_CONFIGS: (import("./config/resource-config.ts").ResourceConfig<"githubFixtureRepo", import("./resources/github/resource.ts").GitHubFixtureRepoOptions, import("./resources/github/config.ts").GitHubFixtureRepoSettings, keyof import("./resources/github/resource.ts").GitHubFixtureRepoOptions> | import("./config/resource-config.ts").ResourceConfig<"testserverPool", import("./resources/testserver/resource.ts").TestserverPoolOptions, import("./resources/testserver/provider.ts").TestserverPoolRequest, keyof import("./resources/testserver/resource.ts").TestserverPoolOptions>)[];
283
283
  /** Each held resource's resolved options, by name; a resource the run doesn't hold is absent. */
284
284
  export type StormResourceOptions = ResolvedResources<typeof RESOURCE_CONFIGS>;
285
- /** The values `--set` gave, by resource, then by option. */
285
+ /**
286
+ * The resource options the command line gave, by resource, then by option: each from a `--set`, or from a run's own
287
+ * flag for the option (`exec`'s and `vitest`'s).
288
+ */
286
289
  export type StormSetValues = GivenResources<typeof RESOURCE_CONFIGS>;
287
290
  /** Every resource's reports: its cleanup and what a ran outcome says of it, and what the host does for it. */
288
291
  export declare const RESOURCE_REPORTS: import("./core/command-slots.ts").ResourceReports<Resources>;
289
292
  /** How every resource shows in a run's progress: its own events' lines, and its lane's rows and label. */
290
293
  export declare const RESOURCE_PRESENTATIONS: import("./core/presentations.ts").ResourcePresentations<Resources>;
291
294
  /** The run's cleanup, as every outcome after the run starts acquiring reports it: the runner's and each resource's. */
292
- export declare const RUN_CLEANUP: import("./commands/run/cleanup.ts").RunCleanup;
295
+ export declare const RUN_CLEANUP: import("./commands/exec/cleanup.ts").RunCleanup;
293
296
  /**
294
- * Every error a resource's command half defines, which the `run` command lists: the errors that end a run before it
297
+ * Every error a resource's command half defines, which `exec` and `vitest` list: the errors that end a run before it
295
298
  * holds anything, in provider order, then the refusal errors, in provider order, each carrying the run's cleanup.
296
299
  */
297
- export declare const RESOURCE_ERRORS: import("./commands/run/cleanup.ts").WithCleanup<{
300
+ export declare const RESOURCE_ERRORS: import("./commands/exec/cleanup.ts").WithCleanup<{
298
301
  readonly githubFixtureRepoUnavailable: import("@vercel/clinkr").DataErrorDefinition<import("zod").ZodObject<{
299
302
  repo: import("zod").ZodString;
300
303
  status: import("zod").ZodNullable<import("zod").ZodNumber>;
@@ -406,7 +409,7 @@ export declare const RESOURCE_ERRORS: import("./commands/run/cleanup.ts").WithCl
406
409
  }, import("zod/v4/core").$strip>;
407
410
  }>;
408
411
  /**
409
- * Every resource's command half, bound to its name: what the `run` command settles and reports through, and
412
+ * Every resource's command half, bound to its name: what `exec` and `vitest` settle and report through, and
410
413
  * `refusedError`, the error a run a resource refused ends with: the refusal error its facts name, built with the run's
411
414
  * cleanup.
412
415
  */
package/dist/resources.js CHANGED
@@ -5,7 +5,7 @@
5
5
  // `Resources`, so commands never spell the generic. A resource folder is reached only through its provider value, and
6
6
  // only this file takes one; `.oxlintrc.json` enforces it.
7
7
  import { combineErrors } from "./combine-errors.js";
8
- import { runCleanupOf } from "./commands/run/cleanup.js";
8
+ import { runCleanupOf } from "./commands/exec/cleanup.js";
9
9
  import { applyRunEvent, bindCommands, resourcePresentations, resourceReports, timeline, } from "./core/index.js";
10
10
  import { githubFixtureRepoProvider } from "./resources/github/index.js";
11
11
  import { testserverPoolProvider } from "./resources/testserver/index.js";
@@ -43,7 +43,7 @@ export const RUN_CLEANUP = runCleanupOf(RESOURCE_REPORTS);
43
43
  */
44
44
  const REFUSALS = RUN_CLEANUP.withCleanup(combineErrors(PROVIDERS.map(({ command }) => command.refusalErrors)));
45
45
  /**
46
- * Every error a resource's command half defines, which the `run` command lists: the errors that end a run before it
46
+ * Every error a resource's command half defines, which `exec` and `vitest` list: the errors that end a run before it
47
47
  * holds anything, in provider order, then the refusal errors, in provider order, each carrying the run's cleanup.
48
48
  */
49
49
  export const RESOURCE_ERRORS = combineErrors([
@@ -52,7 +52,7 @@ export const RESOURCE_ERRORS = combineErrors([
52
52
  ]);
53
53
  const BOUND = bindCommands(PROVIDER_LIST);
54
54
  /**
55
- * Every resource's command half, bound to its name: what the `run` command settles and reports through, and
55
+ * Every resource's command half, bound to its name: what `exec` and `vitest` settle and report through, and
56
56
  * `refusedError`, the error a run a resource refused ends with: the refusal error its facts name, built with the run's
57
57
  * cleanup.
58
58
  */