@cnc-tools/storm 0.10.0 → 0.11.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 (198) hide show
  1. package/dist/bin/storm.js +17 -9
  2. package/dist/build-info.js +1 -1
  3. package/dist/chunks/{chunk-YF3ICDBY.js → chunk-3ZZVZPMG.js} +1 -1
  4. package/dist/chunks/{chunk-JQ2HK4RN.js → chunk-4EU4AH7E.js} +141 -6
  5. package/dist/chunks/{chunk-ZJ2USLAT.js → chunk-4PRAB24Y.js} +2 -22
  6. package/dist/chunks/chunk-AMTYHUYB.js +257 -0
  7. package/dist/chunks/{chunk-WF4KJ7YG.js → chunk-ETCZ6WP7.js} +1 -1
  8. package/dist/chunks/chunk-FVMQKYTT.js +10 -0
  9. package/dist/chunks/{chunk-XHJGHJBW.js → chunk-GRMD7G4J.js} +33 -275
  10. package/dist/chunks/chunk-ICB4BZJX.js +22 -0
  11. package/dist/chunks/{chunk-AGWW3HDT.js → chunk-KR7WIYLG.js} +1826 -2201
  12. package/dist/chunks/{chunk-OVXD7GES.js → chunk-L4ZPMSKQ.js} +4 -37
  13. package/dist/chunks/chunk-NPPJ57W7.js +569 -0
  14. package/dist/chunks/{chunk-VJQLMGOH.js → chunk-O4BUT7BE.js} +361 -1716
  15. package/dist/chunks/chunk-OJOKQRM6.js +1457 -0
  16. package/dist/chunks/chunk-SLNKW4ZM.js +40 -0
  17. package/dist/chunks/{chunk-AKKNF3WZ.js → chunk-TRFEAYNC.js} +277 -348
  18. package/dist/chunks/chunk-VZZTHCBW.js +93 -0
  19. package/dist/chunks/chunk-WNIQA5J6.js +19 -0
  20. package/dist/chunks/chunk-WSIF7SR6.js +10 -0
  21. package/dist/chunks/{live-app-RIJM3QFD.js → live-app-LOGYUBKB.js} +52 -7
  22. package/dist/commands/exec/cleanup.d.ts +3 -3
  23. package/dist/commands/exec/cleanup.js +6 -2
  24. package/dist/commands/exec/command.d.ts +3 -3
  25. package/dist/commands/exec/command.js +17 -10
  26. package/dist/commands/exec/job-summary.d.ts +1 -1
  27. package/dist/commands/exec/job-summary.js +1 -1
  28. package/dist/commands/exec/live-view.js +5 -5
  29. package/dist/commands/exec/mint-failed.js +1 -1
  30. package/dist/commands/exec/outcomes.d.ts +2 -2
  31. package/dist/commands/exec/outcomes.js +7 -8
  32. package/dist/commands/exec/plan-run.d.ts +3 -5
  33. package/dist/commands/exec/progress.d.ts +3 -3
  34. package/dist/commands/exec/progress.js +6 -6
  35. package/dist/commands/exec/resource-refusals.d.ts +1 -1
  36. package/dist/commands/exec/resource-refusals.js +1 -1
  37. package/dist/commands/exec/run-command.d.ts +14 -9
  38. package/dist/commands/exec/run-command.js +91 -202
  39. package/dist/commands/exec/run-metadata.d.ts +2 -2
  40. package/dist/commands/exec/run-metadata.js +3 -3
  41. package/dist/commands/exec/test-plan.d.ts +1 -35
  42. package/dist/commands/exec/test-plan.js +4 -24
  43. package/dist/commands/exec/view.js +3 -3
  44. package/dist/commands/exec/waterfall.d.ts +3 -1
  45. package/dist/commands/exec/waterfall.js +18 -1
  46. package/dist/commands/runs/facts.d.ts +2 -1
  47. package/dist/commands/runs/facts.js +1 -1
  48. package/dist/commands/runs/list/command.js +10 -9
  49. package/dist/commands/runs/logs/command.js +14 -12
  50. package/dist/commands/runs/past-run.d.ts +3 -27
  51. package/dist/commands/runs/past-run.js +3 -37
  52. package/dist/commands/runs/show/command.js +24 -21
  53. package/dist/commands/runs/show/outcomes.js +2 -2
  54. package/dist/commands/vitest/command.d.ts +3 -3
  55. package/dist/commands/vitest/command.js +24 -17
  56. package/dist/commands/vitest/outcomes.d.ts +1 -1
  57. package/dist/commands/vitest/outcomes.js +1 -1
  58. package/dist/config/credential-resolver.d.ts +6 -3
  59. package/dist/config/credential-resolver.js +6 -5
  60. package/dist/context.d.ts +27 -9
  61. package/dist/context.js +19 -8
  62. package/dist/core/before-run.d.ts +5 -4
  63. package/dist/core/before-run.js +6 -6
  64. package/dist/core/definition-lookup.d.ts +22 -0
  65. package/dist/core/definition-lookup.js +34 -0
  66. package/dist/core/events.d.ts +5 -19
  67. package/dist/core/gateways.d.ts +22 -162
  68. package/dist/core/index.d.ts +10 -11
  69. package/dist/core/index.js +9 -11
  70. package/dist/core/launcher-supplies.js +2 -2
  71. package/dist/core/live/terminal-command-gateway.d.ts +8 -0
  72. package/dist/core/live/terminal-command-gateway.js +49 -0
  73. package/dist/core/presentations.d.ts +4 -3
  74. package/dist/core/presentations.js +4 -5
  75. package/dist/core/resource-registry.d.ts +35 -51
  76. package/dist/core/resource-registry.js +27 -54
  77. package/dist/core/resource-reports.d.ts +37 -4
  78. package/dist/core/resource-reports.js +34 -5
  79. package/dist/core/resources.d.ts +4 -3
  80. package/dist/core/resources.js +2 -4
  81. package/dist/core/run-state.d.ts +1 -1
  82. package/dist/core/run-state.js +1 -1
  83. package/dist/core/run.d.ts +19 -37
  84. package/dist/core/run.js +59 -114
  85. package/dist/core/timeline.js +2 -1
  86. package/dist/credential/events.d.ts +20 -0
  87. package/dist/credential/events.js +4 -0
  88. package/dist/credential/index.d.ts +2 -1
  89. package/dist/credential/index.js +6 -5
  90. package/dist/credential/source.d.ts +38 -26
  91. package/dist/credential/source.js +25 -34
  92. package/dist/extension-commands.d.ts +12 -6
  93. package/dist/extension-commands.js +18 -11
  94. package/dist/extensions/story/command-tree.d.ts +6 -0
  95. package/dist/extensions/story/command-tree.js +21 -0
  96. package/dist/extensions/story/commands/app.d.ts +23 -0
  97. package/dist/extensions/story/commands/app.js +5 -0
  98. package/dist/extensions/story/commands/run/command.d.ts +211 -0
  99. package/dist/extensions/story/commands/run/command.js +259 -0
  100. package/dist/extensions/story/commands/run/metadata.d.ts +4 -0
  101. package/dist/extensions/story/commands/run/metadata.js +8 -0
  102. package/dist/extensions/story/commands/run/outcomes.d.ts +101 -0
  103. package/dist/extensions/story/commands/run/outcomes.js +73 -0
  104. package/dist/extensions/story/commands/tree.d.ts +2 -0
  105. package/dist/extensions/story/commands/tree.js +6 -0
  106. package/dist/extensions/story/extension.d.ts +2 -0
  107. package/dist/extensions/story/extension.js +8 -0
  108. package/dist/extensions/testserver/command-tree.d.ts +1 -1
  109. package/dist/extensions/testserver/command-tree.js +0 -1
  110. package/dist/extensions/testserver/commands/pool/create/command.js +14 -8
  111. package/dist/extensions/testserver/commands/pool/list/command.js +8 -4
  112. package/dist/extensions/testserver/vitest/config.d.ts +7 -5
  113. package/dist/extensions/testserver/vitest/config.js +7 -5
  114. package/dist/extensions/testserver/vitest/fixtures.d.ts +2 -0
  115. package/dist/extensions/testserver/vitest/fixtures.js +36 -5
  116. package/dist/extensions.d.ts +12 -21
  117. package/dist/extensions.js +22 -34
  118. package/dist/forward-sigterm.d.ts +8 -0
  119. package/dist/forward-sigterm.js +18 -0
  120. package/dist/launcher-resolvers/index.d.ts +1 -0
  121. package/dist/launcher-resolvers/index.js +2 -1
  122. package/dist/launcher-resolvers/local-services.d.ts +57 -0
  123. package/dist/launcher-resolvers/local-services.js +7 -0
  124. package/dist/live-app.js +2 -1
  125. package/dist/local-services.d.ts +19 -0
  126. package/dist/local-services.js +37 -0
  127. package/dist/run-directory/gateways.d.ts +167 -0
  128. package/dist/run-directory/gateways.js +2 -0
  129. package/dist/run-directory/index.d.ts +8 -0
  130. package/dist/run-directory/index.js +13 -0
  131. package/dist/run-directory/plan.d.ts +35 -0
  132. package/dist/run-directory/plan.js +24 -0
  133. package/dist/run-directory/reader.d.ts +70 -0
  134. package/dist/run-directory/reader.js +51 -0
  135. package/dist/run-directory/recording.d.ts +92 -0
  136. package/dist/run-directory/recording.js +85 -0
  137. package/dist/{commands/exec → run-directory}/run-collector.d.ts +9 -8
  138. package/dist/{commands/exec → run-directory}/run-collector.js +8 -10
  139. package/dist/{core → run-directory}/run-directory.d.ts +3 -3
  140. package/dist/{core → run-directory}/run-directory.js +2 -2
  141. package/dist/{commands/exec → run-directory}/run-record.d.ts +29 -7
  142. package/dist/{commands/exec → run-directory}/run-record.js +79 -5
  143. package/dist/{commands/exec → run-directory}/timeline-facts.d.ts +4 -8
  144. package/dist/{commands/exec → run-directory}/timeline-facts.js +8 -24
  145. package/dist/runner/events.d.ts +6 -5
  146. package/dist/runner/index.d.ts +13 -17
  147. package/dist/runner/index.js +10 -14
  148. package/dist/runner/prepare.d.ts +28 -6
  149. package/dist/runner/prepare.js +15 -9
  150. package/dist/runner/recipe.d.ts +14 -0
  151. package/dist/runner/recipe.js +12 -0
  152. package/dist/runner/scope.d.ts +18 -11
  153. package/dist/runner/scope.js +12 -10
  154. package/dist/runner/session.d.ts +100 -0
  155. package/dist/runner/session.js +109 -0
  156. package/dist/runner/snapshot-save.d.ts +3 -2
  157. package/dist/runner/snapshot-save.js +6 -5
  158. package/dist/sdk/extension/ci.d.ts +2 -0
  159. package/dist/sdk/extension/ci.js +6 -0
  160. package/dist/sdk/extension/commands.d.ts +11 -13
  161. package/dist/sdk/extension/commands.js +5 -5
  162. package/dist/sdk/extension/index.d.ts +1 -0
  163. package/dist/sdk/extension/index.js +1 -0
  164. package/dist/sdk/extension/lifecycle.d.ts +4 -3
  165. package/dist/sdk/extension/progress.js +2 -2
  166. package/dist/sdk/extension/resource.js +1 -1
  167. package/dist/story/align.d.ts +1 -1
  168. package/dist/story/align.js +1 -1
  169. package/dist/story/command-line.d.ts +6 -16
  170. package/dist/story/command-line.js +11 -23
  171. package/dist/story/errors.d.ts +1 -1
  172. package/dist/story/errors.js +1 -1
  173. package/dist/story/host.d.ts +1 -1
  174. package/dist/story/host.js +2 -2
  175. package/dist/story/index.d.ts +2 -2
  176. package/dist/story/index.js +4 -3
  177. package/dist/story/launch.d.ts +70 -0
  178. package/dist/story/launch.js +77 -0
  179. package/dist/story/report.d.ts +2 -2
  180. package/dist/story/report.js +3 -4
  181. package/dist/story/settle.d.ts +7 -7
  182. package/dist/story/settle.js +5 -5
  183. package/dist/story/start.d.ts +2 -2
  184. package/dist/vendor/testserver-sdk/container/container.d.ts +11 -6
  185. package/dist/vendor/testserver-sdk/container/container.js +38 -16
  186. package/dist/vendor/testserver-sdk/testserver/failure.d.ts +4 -3
  187. package/dist/vendor/testserver-sdk/testserver/failure.js +4 -3
  188. package/package.json +1 -1
  189. package/skills/overview.md +3 -0
  190. package/skills/read-run-output.md +2 -2
  191. package/dist/chunks/chunk-H2VCSNVU.js +0 -351
  192. package/dist/chunks/chunk-J6ZNYUDV.js +0 -21
  193. package/dist/core/mint.d.ts +0 -10
  194. package/dist/core/mint.js +0 -14
  195. package/dist/story/mode.d.ts +0 -17
  196. package/dist/story/mode.js +0 -21
  197. /package/dist/{core → run-directory}/live/run-directory-gateway.d.ts +0 -0
  198. /package/dist/{core → run-directory}/live/run-directory-gateway.js +0 -0
@@ -1,16 +1,14 @@
1
1
  // What a run keeps while it goes: its folded state, compact test events for the summary, and the facts needed to read
2
2
  // workers' times. Full redacted test events stream to the run directory's private partial file as they arrive, so a
3
3
  // run keeps no test output or test errors in memory after it has handed them on.
4
- import { EMPTY_RUN_STATE } from "../../core/index.js";
5
- import { applyStormEvent } from "../../extensions.js";
6
- import { parseTestEvent, testEventLine } from "../../sdk/run/launcher.js";
7
- import { redactStrings } from "./redaction.js";
4
+ import { EMPTY_RUN_STATE } from "../core/index.js";
5
+ import { parseTestEvent, testEventLine } from "../sdk/run/launcher.js";
8
6
  /**
9
- * A collector that folds every event but a runner step's output into the run's state. Each test event it hears or
10
- * reads is appended whole to `directory`'s private test events file, when there is one, and kept for the summary
11
- * without a final result's errors and test output.
7
+ * A collector that folds every event but a runner step's output into the run's state, through `registry`. Each test
8
+ * event it hears or reads is appended whole to `directory`'s private test events file, when there is one, and kept for
9
+ * the summary without a final result's errors and test output.
12
10
  */
13
- export function runCollector(directory) {
11
+ export function runCollector(registry, directory) {
14
12
  let state = EMPTY_RUN_STATE;
15
13
  const events = [];
16
14
  let unreadable = 0;
@@ -26,7 +24,7 @@ export function runCollector(directory) {
26
24
  const { event } = timed;
27
25
  if (event.kind === "runner" && event.event.kind === "step-output")
28
26
  return;
29
- state = applyStormEvent(state, timed);
27
+ state = registry.applyEvent(state, timed);
30
28
  if (event.kind === "test") {
31
29
  collect(event.event);
32
30
  if (event.event.kind !== "test-result")
@@ -44,7 +42,7 @@ export function runCollector(directory) {
44
42
  if (event === undefined)
45
43
  unreadable += 1;
46
44
  else
47
- collect(redactStrings(event, redact));
45
+ collect(redact(event));
48
46
  });
49
47
  if (!read.ok)
50
48
  incomplete ??= read.failure.message;
@@ -1,4 +1,4 @@
1
- import type { RunObserver } from "./events.ts";
1
+ import type { RunObserver } from "../core/index.ts";
2
2
  import type { RunDirectory, RunDirectoryStep, RunLog } from "./gateways.ts";
3
3
  /** The subpath of storm's state directory that holds the run directories. */
4
4
  export declare const RUNS_SUBPATH: readonly string[];
@@ -9,8 +9,8 @@ export declare const RUNS_SUBPATH: readonly string[];
9
9
  export declare const RUN_DIRECTORIES_KEPT = 1000;
10
10
  /**
11
11
  * The file that records what a run was, written as its run directory opens and replaced once the run ends: the run's
12
- * start, working directory, config file, command and kind, and then how it ended. Its contents are the composition
13
- * layer's; the run directory only stores them.
12
+ * start, working directory, config file, command and kind, and then how it ended. Its shape is `run-record.ts`'s; the
13
+ * gateway only stores its text.
14
14
  */
15
15
  export declare const RUN_FILE = "run.json";
16
16
  /**
@@ -10,8 +10,8 @@ export const RUNS_SUBPATH = ["runs"];
10
10
  export const RUN_DIRECTORIES_KEPT = 1000;
11
11
  /**
12
12
  * The file that records what a run was, written as its run directory opens and replaced once the run ends: the run's
13
- * start, working directory, config file, command and kind, and then how it ended. Its contents are the composition
14
- * layer's; the run directory only stores them.
13
+ * start, working directory, config file, command and kind, and then how it ended. Its shape is `run-record.ts`'s; the
14
+ * gateway only stores its text.
15
15
  */
16
16
  export const RUN_FILE = "run.json";
17
17
  /**
@@ -1,7 +1,10 @@
1
- import type { Row } from "@vercel/clinkr";
2
1
  import { z } from "zod";
3
- import type { TestEvent } from "../../sdk/run/launcher.ts";
4
- import { type TestPlanFacts } from "./test-plan.ts";
2
+ import { type ResourceReports, type RunOutcome, type RunRequest, type RunState } from "../core/index.ts";
3
+ import type { RunnerSave } from "../runner/index.ts";
4
+ import type { Row } from "../sdk/extension/index.ts";
5
+ import type { TestEvent } from "../sdk/run/launcher.ts";
6
+ import { type TestPlanFacts } from "./plan.ts";
7
+ import type { RunTestEvents } from "./run-collector.ts";
5
8
  declare const testTotalsSchema: z.ZodObject<{
6
9
  passed: z.ZodNumber;
7
10
  failed: z.ZodNumber;
@@ -62,8 +65,7 @@ declare const snapshotSchema: z.ZodObject<{
62
65
  */
63
66
  export type RunRecordSnapshot = Readonly<z.output<typeof snapshotSchema>>;
64
67
  /**
65
- * How saving the runner sandbox as a branch snapshot ended (`--save-snapshot`), as a `ran` outcome and `run.json`
66
- * report it.
68
+ * How saving the runner sandbox as a branch snapshot ended, as a `ran` outcome and `run.json` report it.
67
69
  */
68
70
  export declare const saveSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
69
71
  kind: z.ZodLiteral<"saved">;
@@ -138,7 +140,7 @@ declare const whereSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
138
140
  * with `baseRef`, all known as the run starts; then, once the run is over, the runner sandbox's name and the runner
139
141
  * snapshot it started from, each null when the run stopped before it, when the runner sandbox's timeout stops it, as an
140
142
  * ISO time, when the run kept it running (null when it stopped and deleted it), and how saving it as a branch snapshot
141
- * ended (null without `--save-snapshot`). A reused runner snapshot can be of an older base.
143
+ * ended (null when the run started no save). A reused runner snapshot can be of an older base.
142
144
  */
143
145
  export type RunRecordWhere = Readonly<z.output<typeof whereSchema>>;
144
146
  declare const gitSchema: z.ZodObject<{
@@ -153,7 +155,7 @@ declare const gitSchema: z.ZodObject<{
153
155
  export type RunRecordGit = Readonly<z.output<typeof gitSchema>>;
154
156
  /**
155
157
  * A `storm vitest` run's test plan: how many tests `vitest list` counted, in how many files, and each resource option
156
- * whose default is a function of the planned run, with its value and where that came from (`test-plan.ts`).
158
+ * whose default is a function of the planned run, with its value and where that came from (`plan.ts`).
157
159
  */
158
160
  export type RunRecordPlan = TestPlanFacts;
159
161
  declare const runRecordSchema: z.ZodObject<{
@@ -255,4 +257,24 @@ export declare function runRecordText(record: RunRecord): string;
255
257
  export declare function parseRunRecord(text: string | undefined): RunRecord | undefined;
256
258
  /** The totals of `events`' final results; null without one. */
257
259
  export declare function testTotals(events: readonly TestEvent[]): RunTestTotals | null;
260
+ /**
261
+ * How the run ended, for `run.json`: its outcome's kind; for a run whose command ran, the status storm exits with
262
+ * and the signal that ended the command; how long the command took, from the command's state once it ended on its own
263
+ * (a command the run stopped has none); the totals of its tests' final results, and why they may be incomplete; and a
264
+ * ran outcome's acquired resources' result facts, with the rows `storm runs show` lists for them, each rendered when
265
+ * the resource's acquire answered, so a past run shows them without the definitions that made them.
266
+ */
267
+ export declare function runEnd(outcome: RunOutcome, ran: RunState["command"], tests: RunTestEvents, reports: ResourceReports): RunRecordEnd;
268
+ /**
269
+ * Where the run's command runs, as `run.json` records it as the run starts: unsandboxed, or in a runner sandbox, with
270
+ * no sandbox or snapshot yet.
271
+ */
272
+ export declare function startedWhere(run: RunRequest): RunRecordWhere;
273
+ /**
274
+ * `where` once the run is over, from the runner's final state: for a sandboxed run, the runner sandbox the run started,
275
+ * the runner snapshot it started from, which the run reused or built, when its timeout stops the runner sandbox it
276
+ * kept running, and how saving it as a branch snapshot ended (`save`). Each is null when the run stopped before it,
277
+ * kept no runner sandbox, or saved none.
278
+ */
279
+ export declare function endedWhere(where: RunRecordWhere, runner: RunState["runner"], save: RunnerSave | null): RunRecordWhere;
258
280
  export {};
@@ -1,10 +1,12 @@
1
1
  // What a run records about itself in its run directory's `run.json`, which `storm runs` reads back: written as
2
- // the run directory opens, then replaced with how the run ended once it is over. The run directory stores the text;
3
- // this module owns its shape, version 3. Reading it back asks the registry nothing: each resource instance's facts
2
+ // the run directory opens, then replaced with how the run ended once it is over. The run directory gateway stores the
3
+ // text; this file owns its shape, version 3, and what goes in it: where the run's command runs, as the run starts and
4
+ // once it is over, and how the run ended. Reading it back asks the registry nothing: each resource instance's facts
4
5
  // read as recorded, beside its definition's name, and `runs show` lists the rows storm rendered for them when the run
5
6
  // ended, so a past run reads the same after a resource definition is renamed or its extension removed.
6
7
  import { z } from "zod";
7
- import { planSchema } from "./test-plan.js";
8
+ import { commandExitStatus, } from "../core/index.js";
9
+ import { planSchema } from "./plan.js";
8
10
  const testTotalsSchema = z.object({
9
11
  passed: z.number().int().nonnegative(),
10
12
  failed: z.number().int().nonnegative(),
@@ -28,8 +30,7 @@ const snapshotSchema = z.object({
28
30
  head: z.string().nullable(),
29
31
  });
30
32
  /**
31
- * How saving the runner sandbox as a branch snapshot ended (`--save-snapshot`), as a `ran` outcome and `run.json`
32
- * report it.
33
+ * How saving the runner sandbox as a branch snapshot ended, as a `ran` outcome and `run.json` report it.
33
34
  */
34
35
  export const saveSchema = z.discriminatedUnion("kind", [
35
36
  z.object({
@@ -133,3 +134,76 @@ export function testTotals(events) {
133
134
  }
134
135
  return any ? { passed, failed, skipped } : null;
135
136
  }
137
+ /**
138
+ * How the run ended, for `run.json`: its outcome's kind; for a run whose command ran, the status storm exits with
139
+ * and the signal that ended the command; how long the command took, from the command's state once it ended on its own
140
+ * (a command the run stopped has none); the totals of its tests' final results, and why they may be incomplete; and a
141
+ * ran outcome's acquired resources' result facts, with the rows `storm runs show` lists for them, each rendered when
142
+ * the resource's acquire answered, so a past run shows them without the definitions that made them.
143
+ */
144
+ export function runEnd(outcome, ran, tests, reports) {
145
+ const command = outcome.kind === "ran" ? outcome.command : undefined;
146
+ const ranRecords = outcome.kind === "ran" ? outcome.resources : undefined;
147
+ const ms = ran?.outcome === undefined || ran.outcome === "stopped" || ran.endedAt === undefined
148
+ ? null
149
+ : ran.endedAt - ran.startedAt;
150
+ return {
151
+ outcome: outcome.kind,
152
+ exitCode: command === undefined ? null : commandExitStatus(command),
153
+ signal: command?.kind === "signaled" ? command.signal : null,
154
+ ms,
155
+ tests: testTotals(tests.events),
156
+ testsIncomplete: tests.incomplete ?? null,
157
+ resources: ranRecords === undefined ? null : reports.ranFacts(ranRecords),
158
+ resourceRows: ranRecords === undefined ? [] : reports.ranRows(ranRecords),
159
+ };
160
+ }
161
+ /**
162
+ * Where the run's command runs, as `run.json` records it as the run starts: unsandboxed, or in a runner sandbox, with
163
+ * no sandbox or snapshot yet.
164
+ */
165
+ export function startedWhere(run) {
166
+ if (run.runner === undefined)
167
+ return { kind: "unsandboxed" };
168
+ const { prepared, target } = run.runner;
169
+ return {
170
+ kind: "runner",
171
+ team: target.team,
172
+ project: target.project,
173
+ region: prepared.recipe.region,
174
+ runtime: prepared.recipe.runtime,
175
+ vcpus: prepared.vcpus,
176
+ base: prepared.base,
177
+ baseRef: prepared.baseRef,
178
+ sandbox: null,
179
+ snapshot: null,
180
+ keptUntil: null,
181
+ save: null,
182
+ };
183
+ }
184
+ /**
185
+ * `where` once the run is over, from the runner's final state: for a sandboxed run, the runner sandbox the run started,
186
+ * the runner snapshot it started from, which the run reused or built, when its timeout stops the runner sandbox it
187
+ * kept running, and how saving it as a branch snapshot ended (`save`). Each is null when the run stopped before it,
188
+ * kept no runner sandbox, or saved none.
189
+ */
190
+ export function endedWhere(where, runner, save) {
191
+ if (where.kind === "unsandboxed")
192
+ return where;
193
+ const snapshot = runner?.snapshot;
194
+ return {
195
+ ...where,
196
+ sandbox: runner?.sandbox?.name ?? null,
197
+ snapshot: snapshot === undefined || snapshot.kind === "building"
198
+ ? null
199
+ : {
200
+ id: snapshot.id,
201
+ base: snapshot.base,
202
+ built: snapshot.kind === "built",
203
+ branch: snapshot.branch,
204
+ head: snapshot.head,
205
+ },
206
+ keptUntil: runner?.kept?.stopsAt ?? null,
207
+ save,
208
+ };
209
+ }
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { type Timeline } from "../../core/index.ts";
2
+ import type { LaneKind, Timeline } from "../core/index.ts";
3
3
  /** A run's waterfall, times in milliseconds since the run started, as `timeline.json` holds it. */
4
4
  export declare const timelineSchema: z.ZodObject<{
5
5
  startedAt: z.ZodString;
@@ -46,12 +46,8 @@ export declare const timelineSchema: z.ZodObject<{
46
46
  export type TimelineFacts = z.output<typeof timelineSchema>;
47
47
  /** One row of a timeline as storm reports and keeps it. */
48
48
  export type TimelineFactsRow = TimelineFacts["rows"][number];
49
- /** `timeline` as storm reports and keeps it, each row labeled as the waterfall names it now. */
50
- export declare function timelineFacts(timeline: Timeline): TimelineFacts;
51
49
  /**
52
- * The labels of the core's lanes, which the waterfall's label column always makes room for, with each resource lane's
53
- * label, so it lines up the same from run to run.
50
+ * `timeline` as storm reports and keeps it, each row labeled as the waterfall names it now, a resource lane by its
51
+ * definition's lane kind among `laneKinds` (the registry's `presentations.laneKinds`).
54
52
  */
55
- export declare const LANE_LABELS: readonly string[];
56
- /** A critical path step: its row's label, and for the runner what it did with its runner snapshot. */
57
- export declare function criticalPathStep(step: TimelineFacts["criticalPath"][number], timeline: TimelineFacts): string;
53
+ export declare function timelineFacts(timeline: Timeline, laneKinds: readonly LaneKind[]): TimelineFacts;
@@ -4,8 +4,6 @@
4
4
  // draws as it was after a resource's lane or steps are renamed, or its extension removed: reading it back asks the
5
5
  // registry nothing.
6
6
  import { z } from "zod";
7
- import { sameRow } from "../../core/index.js";
8
- import { RESOURCE_PRESENTATIONS } from "../../extensions.js";
9
7
  /** Which row of the timeline: its name, and for a resource instance's lane the resource key, null for any other. */
10
8
  const rowRefShape = {
11
9
  /** The row's name: `mint`, a resource lane's name, `runner`, `tests` or `cleanup`. */
@@ -49,44 +47,30 @@ export const timelineSchema = z.object({
49
47
  /** The lanes the command waited on, then the command, each by its row; empty when the command didn't start. */
50
48
  criticalPath: z.array(z.object(rowRefShape)),
51
49
  });
52
- /** `timeline` as storm reports and keeps it, each row labeled as the waterfall names it now. */
53
- export function timelineFacts(timeline) {
50
+ /**
51
+ * `timeline` as storm reports and keeps it, each row labeled as the waterfall names it now, a resource lane by its
52
+ * definition's lane kind among `laneKinds` (the registry's `presentations.laneKinds`).
53
+ */
54
+ export function timelineFacts(timeline, laneKinds) {
54
55
  return {
55
56
  startedAt: timeline.startedAt,
56
57
  totalMs: timeline.totalMs,
57
58
  rows: timeline.rows.map((row) => ({
58
59
  ...row,
59
- label: laneLabel(row.name),
60
+ label: laneLabel(row.name, laneKinds),
60
61
  steps: row.steps.map((step) => ({ ...step })),
61
62
  })),
62
63
  criticalPath: timeline.criticalPath.map((step) => ({ ...step })),
63
64
  };
64
65
  }
65
- /**
66
- * The labels of the core's lanes, which the waterfall's label column always makes room for, with each resource lane's
67
- * label, so it lines up the same from run to run.
68
- */
69
- export const LANE_LABELS = [
70
- "credential",
71
- "runner-setup",
72
- "tests",
73
- "cleanup",
74
- ...RESOURCE_PRESENTATIONS.laneKinds.map(({ label }) => label),
75
- ];
76
66
  /**
77
67
  * A lane as the waterfall and the job summary name it: the credential, each resource lane by its presentation's label,
78
68
  * such as `<lane>-setup`, the runner's setup, the tests and the cleanup.
79
69
  */
80
- function laneLabel(name) {
70
+ function laneLabel(name, laneKinds) {
81
71
  if (name === "mint")
82
72
  return "credential";
83
73
  if (name === "runner")
84
74
  return "runner-setup";
85
- return RESOURCE_PRESENTATIONS.laneKinds.find(({ lane }) => lane === name)?.label ?? name;
86
- }
87
- /** A critical path step: its row's label, and for the runner what it did with its runner snapshot. */
88
- export function criticalPathStep(step, timeline) {
89
- const row = timeline.rows.find((candidate) => sameRow(candidate, step));
90
- const label = row?.label ?? step.name;
91
- return row?.snapshot === undefined ? label : `${label} (snapshot ${row.snapshot})`;
75
+ return laneKinds.find(({ lane }) => lane === name)?.label ?? name;
92
76
  }
@@ -54,7 +54,7 @@ export interface NotKeptSandbox {
54
54
  * - `waiting-for-snapshot`: closing waits up to `settleMs` for a runner snapshot still saving.
55
55
  * - `sandbox-kept`: closing kept runner sandbox `name` running until `stopsAt`, an ISO time.
56
56
  * - `branch-snapshot-saving`: the run saves the runner sandbox as a branch snapshot of `branch`, once the command
57
- * ended (`--save-snapshot`).
57
+ * ended.
58
58
  * - `branch-snapshot-saved`: it did, as runner snapshot `snapshotId` of `branch` at HEAD commit `head`, in `ms`.
59
59
  * - `branch-snapshot-not-saved`: it didn't, and `save` says why.
60
60
  * - `branch-snapshots-dropped`: `--rebuild-snapshot` removed `branch`'s branch snapshot entries from the cache.
@@ -192,16 +192,17 @@ export type RunnerFailure = {
192
192
  readonly failure: CheckoutFailure;
193
193
  };
194
194
  /**
195
- * How saving the runner sandbox as a branch snapshot ended (`--save-snapshot`).
195
+ * How saving the runner sandbox as a branch snapshot ended.
196
196
  *
197
197
  * - `saved`: it is runner snapshot `snapshotId` of `base`, for `branch` at HEAD commit `head`, saved in `ms` from the
198
198
  * save's start; `entryWritten` says whether the cache recorded it.
199
- * - `skipped`: HEAD was detached as the run started, so there is no branch to save it for (`prepareRunner`); the run
200
- * keeps its runner sandbox as without the flag.
199
+ * - `skipped`: in a run that saves always, HEAD was detached as the run started, so there is no branch to save it for
200
+ * (`prepareRunner`); the run keeps its runner sandbox as a run that saves none.
201
201
  * - `failed`: the scrub or the save failed with `message`.
202
202
  * - `stopped`: a signal stopped it before it saved, or before the cache recorded the snapshot.
203
203
  *
204
- * A run on a branch never keeps its runner sandbox, whether the save ran or how it ended (`RunnerSandboxPlan`).
204
+ * A run whose save started never keeps its runner sandbox, however the save ended; a run whose save never started
205
+ * has none of these, and keeps its runner sandbox for the keep time (`RunnerSandboxPlan`).
205
206
  */
206
207
  export type RunnerSave = {
207
208
  readonly kind: "saved";
@@ -1,21 +1,17 @@
1
- export { type BaseResolution, type RefusedBaseRef, resolveBase } from "./base.ts";
2
1
  export type { RunnerContext } from "./context.ts";
3
- export { type KeptSandbox, type NotDeletedSandbox, type NotKeptSandbox, type NotStoppedSandbox, type RunnerEvent, type RunnerFailure, type RunnerOutputSection, type RunnerProgress, type RunnerSandboxCall, type RunnerSave, type RunnerStage, type RunnerStepPhase, } from "./events.ts";
4
- export type { BaseArchive, BaseCandidate, CheckoutFailure, CheckoutHead, CheckoutGateway, CheckoutResult, CheckoutUpload, FileAtCommit, SandboxExit, SandboxOutputChunk, RunnerKeepFailure, RunnerSandbox, RunnerSandboxFailure, RunnerSandboxGateway, RunnerSandboxOperation, RunnerSandboxPlacement, RunnerSandboxResult, RunnerSandboxRole, RunnerSnapshotCacheFailure, RunnerSnapshotCacheGateway, RunnerSnapshotCacheOperation, RunnerSnapshotCacheResult, RunnerSnapshotEntry, RunnerSnapshotListing, RunnerStartFailure, RunnerTerminal, SandboxAccess, SavedSnapshot, StagedFile, UnreadableSnapshotEntry, } from "./gateways.ts";
2
+ export { type KeptSandbox, type RunnerEvent, type RunnerFailure, type RunnerProgress, type RunnerSave, type RunnerStepPhase, } from "./events.ts";
3
+ export type { CheckoutFailure, CheckoutGateway, RunnerSandboxGateway, RunnerSnapshotCacheFailure, RunnerSnapshotCacheGateway, RunnerSnapshotEntry, RunnerTerminal, } from "./gateways.ts";
5
4
  export { liveCheckoutGateway } from "./live/checkout-gateway.ts";
6
5
  export { liveRunnerSandboxGateway } from "./live/sandbox-gateway.ts";
7
- export { liveRunnerTerminal, type TerminalStream } from "./live/terminal.ts";
6
+ export { liveRunnerTerminal } from "./live/terminal.ts";
8
7
  export { localUserName } from "./live/user.ts";
9
- export { liveRunnerSnapshotCacheGateway, type LiveRunnerSnapshotCacheOptions, unavailableRunnerSnapshotCacheGateway, } from "./live/snapshot-cache-gateway.ts";
10
- export { lineSplitter, type LineSplitter, OUTPUT_TAIL_LINES, outputRule, outputTail, type OutputTail, rewritePaths, splitLines, } from "./output.ts";
11
- export { type PreparedRunner, prepareRunner, type PrepareRunnerOutcome, type PrepareRunnerRequest, type RunnerPrepareContext, } from "./prepare.ts";
12
- export { APPLY_LABEL, type ReadyRunner, readyRunner, type ReadyRunnerOutcome, type ReadyRunnerRequest, } from "./ready.ts";
13
- export { type CheckedRecipe, checkRecipe, type RecipeCheck, type RecipeProblem, resolveSteps, resolveVcpus, type RunnerRecipe, type ResolvedRunnerStep, type RunnerStep, type RunnerStepContext, type RunnerSteps, type VcpusRun, } from "./recipe.ts";
14
- export { SANDBOX_TEST_EVENTS_PATH, type SandboxedCommandOutcome, sandboxedCommand, sandboxEnvironment, type SandboxTestEvents, runCommandInSandbox, } from "./sandboxed-command.ts";
15
- export { readRunnerSecrets, RUNNER_SECRET_MIN_LENGTH, stepSecrets, type RunnerSecretProblem, type RunnerSecrets, type RunnerSecretsRead, } from "./secrets.ts";
16
- export { CREATE_SETTLE_MS, keptMs, type RunnerSandboxPlan, type RunnerSandboxScope, runnerSandboxScope, type RunnerScopeFacts, SNAPSHOT_SETTLE_MS, } from "./scope.ts";
17
- export { BASE_INDEX_LABEL, buildSnapshot, type BuildSnapshotRequest, type BuiltSnapshot } from "./snapshot-build.ts";
18
- export { dropBranchSnapshots, type DroppedBranchSnapshots, findSnapshotCandidates, isBranchEntry, pickSnapshot, RUNNER_SNAPSHOTS_SUBPATH, type RunnerSnapshotCandidate, SNAPSHOT_EXPIRATION_MS, type SnapshotCacheContext, type SnapshotCacheNote, snapshotEntryFileName, snapshotEntryIdentity, } from "./snapshot-cache.ts";
19
- export { applyScript, baseIndexScript, RESET_TO_BASE, snapshotKey, type SnapshotStepsAt, snapshotStepsAt, } from "./snapshot-key.ts";
20
- export { saveBranchSnapshot, type SaveBranchSnapshotRequest, scrubGitScript, scrubTempScript, TEMP_DIRECTORIES, } from "./snapshot-save.ts";
21
- export { STEP_ENV, type StepOutcome } from "./steps.ts";
8
+ export { liveRunnerSnapshotCacheGateway, unavailableRunnerSnapshotCacheGateway, } from "./live/snapshot-cache-gateway.ts";
9
+ export { lineSplitter } from "./output.ts";
10
+ export { prepareRunner, type PrepareRunnerOutcome, type RunnerSaveMode } from "./prepare.ts";
11
+ export type { ReadyRunnerOutcome } from "./ready.ts";
12
+ export { type CheckedRecipe, checkRecipe, runStepTakesSecret } from "./recipe.ts";
13
+ export { SANDBOX_TEST_EVENTS_PATH } from "./sandboxed-command.ts";
14
+ export { readRunnerSecrets, RUNNER_SECRET_MIN_LENGTH, type RunnerSecrets } from "./secrets.ts";
15
+ export type { RunnerSandboxPlan } from "./scope.ts";
16
+ export { type RunnerCleanupFacts, openRunnerSession, type RunnerSession, type RunnerSessionRequest, } from "./session.ts";
17
+ export { RUNNER_SNAPSHOTS_SUBPATH, type SnapshotCacheNote } from "./snapshot-cache.ts";
@@ -1,20 +1,16 @@
1
- // The `runner` module's public surface: running a command in a runner sandbox. Other modules import only from here.
2
- export { resolveBase } from "./base.js";
1
+ // The `runner` module's public surface: running a command in a runner sandbox, through a run's runner session. Other
2
+ // modules import only from here, and it holds only what another module under `src/` imports; the runner's own tests
3
+ // import the files that declare the rest (`README.md`).
3
4
  export {} from "./events.js";
4
5
  export { liveCheckoutGateway } from "./live/checkout-gateway.js";
5
6
  export { liveRunnerSandboxGateway } from "./live/sandbox-gateway.js";
6
7
  export { liveRunnerTerminal } from "./live/terminal.js";
7
8
  export { localUserName } from "./live/user.js";
8
9
  export { liveRunnerSnapshotCacheGateway, unavailableRunnerSnapshotCacheGateway, } from "./live/snapshot-cache-gateway.js";
9
- export { lineSplitter, OUTPUT_TAIL_LINES, outputRule, outputTail, rewritePaths, splitLines, } from "./output.js";
10
- export { prepareRunner, } from "./prepare.js";
11
- export { APPLY_LABEL, readyRunner, } from "./ready.js";
12
- export { checkRecipe, resolveSteps, resolveVcpus, } from "./recipe.js";
13
- export { SANDBOX_TEST_EVENTS_PATH, sandboxedCommand, sandboxEnvironment, runCommandInSandbox, } from "./sandboxed-command.js";
14
- export { readRunnerSecrets, RUNNER_SECRET_MIN_LENGTH, stepSecrets, } from "./secrets.js";
15
- export { CREATE_SETTLE_MS, keptMs, runnerSandboxScope, SNAPSHOT_SETTLE_MS, } from "./scope.js";
16
- export { BASE_INDEX_LABEL, buildSnapshot } from "./snapshot-build.js";
17
- export { dropBranchSnapshots, findSnapshotCandidates, isBranchEntry, pickSnapshot, RUNNER_SNAPSHOTS_SUBPATH, SNAPSHOT_EXPIRATION_MS, snapshotEntryFileName, snapshotEntryIdentity, } from "./snapshot-cache.js";
18
- export { applyScript, baseIndexScript, RESET_TO_BASE, snapshotKey, snapshotStepsAt, } from "./snapshot-key.js";
19
- export { saveBranchSnapshot, scrubGitScript, scrubTempScript, TEMP_DIRECTORIES, } from "./snapshot-save.js";
20
- export { STEP_ENV } from "./steps.js";
10
+ export { lineSplitter } from "./output.js";
11
+ export { prepareRunner } from "./prepare.js";
12
+ export { checkRecipe, runStepTakesSecret } from "./recipe.js";
13
+ export { SANDBOX_TEST_EVENTS_PATH } from "./sandboxed-command.js";
14
+ export { readRunnerSecrets, RUNNER_SECRET_MIN_LENGTH } from "./secrets.js";
15
+ export { openRunnerSession, } from "./session.js";
16
+ export { RUNNER_SNAPSHOTS_SUBPATH } from "./snapshot-cache.js";
@@ -4,6 +4,18 @@ import { type CheckedRecipe, type ResolvedRunnerStep, type VcpusRun } from "./re
4
4
  import { type RunnerSnapshotCandidate, type SnapshotCacheContext, type SnapshotCacheNote } from "./snapshot-cache.ts";
5
5
  /** What `prepareRunner` needs: the checkout, the runner snapshot cache and the clock. */
6
6
  export type RunnerPrepareContext = SnapshotCacheContext;
7
+ /**
8
+ * Whether a run saves its runner sandbox as a branch snapshot of HEAD's branch once the command ends.
9
+ *
10
+ * - `new-head`: when the command exited 0 and the run didn't start from a branch snapshot HEAD's commit saved;
11
+ * nothing, and no word of it, with a detached HEAD. What a run does when neither `--save-snapshot` nor the
12
+ * recipe's `saveSnapshot` is given.
13
+ * - `always`: whatever the command's exit code and whatever runner snapshot the run started from; with a detached HEAD
14
+ * the run says it saves nothing (`--save-snapshot`, or the recipe's `saveSnapshot: true`).
15
+ * - `never`: `--save-snapshot=false`, or the recipe's `saveSnapshot: false`; with neither given, `CI` set, or a
16
+ * recipe whose install or build step names a runner secret.
17
+ */
18
+ export type RunnerSaveMode = "new-head" | "always" | "never";
7
19
  /** What `prepareRunner` checks a run with; `Run` is what the recipe's `vcpus` function is called with. */
8
20
  export interface PrepareRunnerRequest<Run> {
9
21
  /** The directory the run started in, inside the checkout. */
@@ -13,8 +25,14 @@ export interface PrepareRunnerRequest<Run> {
13
25
  readonly vcpusRun: VcpusRun<Run>;
14
26
  /** `--rebuild-snapshot`: the run builds a runner snapshot whatever the cache holds, so the cache isn't read. */
15
27
  readonly rebuild: boolean;
16
- /** `--save-snapshot`: the run saves the runner sandbox as a branch snapshot of HEAD's branch once the command ends. */
17
- readonly saveSnapshot: boolean;
28
+ /** Whether the run saves the runner sandbox as a branch snapshot of HEAD's branch once the command ends. */
29
+ readonly save: RunnerSaveMode;
30
+ /**
31
+ * Whether `--save-snapshot`, or the recipe's `saveSnapshot: true` without `--save-snapshot=false`, trusts commands
32
+ * that ran on this branch with the install and build steps' runner secrets. Without that trust, a recipe whose
33
+ * install or build step names one starts only from a base snapshot.
34
+ */
35
+ readonly trustBranchSnapshots: boolean;
18
36
  }
19
37
  /** The runner, checked on this machine, ready for the runner sandbox. */
20
38
  export interface PreparedRunner {
@@ -41,12 +59,15 @@ export interface PreparedRunner {
41
59
  /** What the cache read noticed, for the run to report. */
42
60
  readonly notes: readonly SnapshotCacheNote[];
43
61
  /**
44
- * `--save-snapshot`: the branch the run saves a branch snapshot of, or why it saves none (`skipped`, with a
45
- * detached HEAD); null without the flag.
62
+ * The branch the run saves a branch snapshot of, and whether it saves whatever the command's exit code and whatever
63
+ * runner snapshot it started from (`always`) or only when the command exits 0 and that isn't a branch snapshot
64
+ * HEAD's commit saved; in a run that saves always, why it saves none (`skipped`, with a detached HEAD); null when
65
+ * the run saves none and says nothing of it: a run that saves never, or a detached HEAD in any other.
46
66
  */
47
67
  readonly save: {
48
68
  readonly kind: "branch";
49
69
  readonly branch: string;
70
+ readonly always: boolean;
50
71
  } | {
51
72
  readonly kind: "skipped";
52
73
  readonly reason: "detached-head";
@@ -82,7 +103,8 @@ export type PrepareRunnerOutcome = {
82
103
  };
83
104
  /**
84
105
  * Runs the local checks in order: the repository's root, HEAD, the base, the submodule refusal, the snapshot steps at
85
- * the base and their key, the runner's vCPUs, the upload, and the cache read. It never mints, acquires or creates. Under
86
- * `--save-snapshot` it decides what the run saves: HEAD's branch, or nothing with a detached HEAD.
106
+ * the base and their key, the runner's vCPUs, the upload, and the cache read. It never mints, acquires or creates. It
107
+ * decides what the run saves: HEAD's branch, or nothing with a detached HEAD or when the run saves none (`never`). An
108
+ * untrusted recipe whose install or build step names a runner secret gets no branch snapshot candidates.
87
109
  */
88
110
  export declare function prepareRunner<Run>(context: RunnerPrepareContext, request: PrepareRunnerRequest<Run>): Promise<PrepareRunnerOutcome>;
@@ -2,13 +2,14 @@
2
2
  // anything, so a missing base, a checkout with submodules or a recipe storm can't use fails with nothing to
3
3
  // clean up.
4
4
  import { resolveBase } from "./base.js";
5
- import { resolveVcpus } from "./recipe.js";
5
+ import { resolveVcpus, runStepTakesSecret, } from "./recipe.js";
6
6
  import { findSnapshotCandidates, } from "./snapshot-cache.js";
7
7
  import { snapshotStepsAt } from "./snapshot-key.js";
8
8
  /**
9
9
  * Runs the local checks in order: the repository's root, HEAD, the base, the submodule refusal, the snapshot steps at
10
- * the base and their key, the runner's vCPUs, the upload, and the cache read. It never mints, acquires or creates. Under
11
- * `--save-snapshot` it decides what the run saves: HEAD's branch, or nothing with a detached HEAD.
10
+ * the base and their key, the runner's vCPUs, the upload, and the cache read. It never mints, acquires or creates. It
11
+ * decides what the run saves: HEAD's branch, or nothing with a detached HEAD or when the run saves none (`never`). An
12
+ * untrusted recipe whose install or build step names a runner secret gets no branch snapshot candidates.
12
13
  */
13
14
  export async function prepareRunner(context, request) {
14
15
  const { checkout } = context;
@@ -40,9 +41,10 @@ export async function prepareRunner(context, request) {
40
41
  const upload = await checkout.assembleUpload({ repoRoot, base });
41
42
  if (!upload.ok)
42
43
  return { kind: "checkout-failed", failure: upload.failure };
44
+ const reuseBranch = request.trustBranchSnapshots || !runStepTakesSecret(recipe);
43
45
  const cache = request.rebuild
44
46
  ? { candidates: [], notes: [] }
45
- : await findSnapshotCandidates(context, { repoRoot, recipe, branch: head.value.branch });
47
+ : await findSnapshotCandidates(context, { repoRoot, recipe, branch: reuseBranch ? head.value.branch : null });
46
48
  return {
47
49
  kind: "ok",
48
50
  prepared: {
@@ -59,11 +61,15 @@ export async function prepareRunner(context, request) {
59
61
  candidates: cache.candidates,
60
62
  rebuild: request.rebuild,
61
63
  notes: cache.notes,
62
- save: !request.saveSnapshot
63
- ? null
64
- : head.value.branch === null
65
- ? { kind: "skipped", reason: "detached-head" }
66
- : { kind: "branch", branch: head.value.branch },
64
+ save: plannedSave(request.save, head.value.branch),
67
65
  },
68
66
  };
69
67
  }
68
+ /** What a run in `mode` saves with HEAD on `branch`, null when detached. */
69
+ function plannedSave(mode, branch) {
70
+ if (mode === "never")
71
+ return null;
72
+ if (branch !== null)
73
+ return { kind: "branch", branch, always: mode === "always" };
74
+ return mode === "always" ? { kind: "skipped", reason: "detached-head" } : null;
75
+ }
@@ -12,6 +12,11 @@ export interface RunnerStep {
12
12
  export interface ResolvedRunnerStep extends RunnerStep {
13
13
  readonly secrets: readonly string[];
14
14
  }
15
+ /**
16
+ * Whether the recipe's install or build step names a runner secret. A branch snapshot holds what an earlier command
17
+ * wrote, shell startup files and `node_modules/.bin` included, and those steps run on top of it as the same user.
18
+ */
19
+ export declare function runStepTakesSecret(recipe: Pick<CheckedRecipe, "run">): boolean;
15
20
  /** What a step function may read about the base it is evaluated at. */
16
21
  export interface RunnerStepContext {
17
22
  /** The base's full SHA. */
@@ -70,6 +75,15 @@ export interface RunnerRecipe<Run = never> {
70
75
  * it, or up to `5h`. `run --keep-sandbox` overrides it; without either, `30m`, or `0` when `CI` is set.
71
76
  */
72
77
  readonly keepSandbox?: string;
78
+ /**
79
+ * Whether a run saves its runner sandbox as a branch snapshot of HEAD's branch, when neither `run --save-snapshot`
80
+ * nor a `run --keep-sandbox` above 0 says: `false` saves none, and `true` saves once the command ends on its own,
81
+ * whatever its exit code and whatever runner snapshot the run started from, with `CI` set too. Without it, a run
82
+ * saves once per commit, once a command exits 0, and none when `CI` is set or when `run.install` or `run.build`
83
+ * names a runner secret: a branch snapshot holds what the command wrote, and those steps run on top of it in later
84
+ * runs, so only `true` or `--save-snapshot` lets such a recipe save or reuse a branch snapshot, trusting every command run on the branch with those secrets.
85
+ */
86
+ readonly saveSnapshot?: boolean;
73
87
  /** The refs a base can come from, preferred first; `["main", "origin/main"]` by default. */
74
88
  readonly baseRefs?: readonly string[];
75
89
  /** The Vercel region of the runner sandbox and its snapshots; `iad1` by default. */
@@ -5,6 +5,13 @@
5
5
  import { parseKeepTime, parseTtl } from "../time/index.js";
6
6
  import { RUN_PAYLOAD_VARIABLE } from "../sdk/run/launcher.js";
7
7
  import { STEP_ENV } from "./steps.js";
8
+ /**
9
+ * Whether the recipe's install or build step names a runner secret. A branch snapshot holds what an earlier command
10
+ * wrote, shell startup files and `node_modules/.bin` included, and those steps run on top of it as the same user.
11
+ */
12
+ export function runStepTakesSecret(recipe) {
13
+ return recipe.run.install.secrets.length > 0 || recipe.run.build.secrets.length > 0;
14
+ }
8
15
  /** The defaults of a recipe's optional keys. */
9
16
  export const RECIPE_DEFAULTS = {
10
17
  cwd: ".",
@@ -23,6 +30,7 @@ const RECIPE_KEYS = new Set([
23
30
  "secrets",
24
31
  "timeout",
25
32
  "keepSandbox",
33
+ "saveSnapshot",
26
34
  "baseRefs",
27
35
  "region",
28
36
  "runtime",
@@ -86,6 +94,9 @@ export function checkRecipe(value) {
86
94
  const keepSandboxMinutes = typeof keepSandbox === "string" ? parseKeepTime(keepSandbox) : undefined;
87
95
  if (keepSandbox !== undefined && keepSandboxMinutes === undefined)
88
96
  report(["keepSandbox"], `must be 0, or a whole number of minutes or hours up to 5h, not ${describeRecipeValue(keepSandbox)}`);
97
+ const saveSnapshot = value["saveSnapshot"];
98
+ if (saveSnapshot !== undefined && typeof saveSnapshot !== "boolean")
99
+ report(["saveSnapshot"], `must be true or false, not ${describeRecipeValue(saveSnapshot)}`);
89
100
  const baseRefs = checkBaseRefs(value["baseRefs"], report);
90
101
  const region = orDefault(value["region"], RECIPE_DEFAULTS.region);
91
102
  if (!isNonEmptyString(region))
@@ -114,6 +125,7 @@ export function checkRecipe(value) {
114
125
  timeout: timeout,
115
126
  timeoutMinutes,
116
127
  keepSandboxMinutes,
128
+ ...(typeof saveSnapshot === "boolean" ? { saveSnapshot } : {}),
117
129
  baseRefs,
118
130
  region: region,
119
131
  runtime: runtime,