@cnc-tools/storm 0.15.0 → 0.16.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 (109) hide show
  1. package/dist/bin/storm.js +1 -1
  2. package/dist/build-info.js +1 -1
  3. package/dist/chunks/{chunk-QUHY6FGN.js → chunk-2MAD5NKK.js} +1 -1
  4. package/dist/chunks/{chunk-XEVHP5ZW.js → chunk-3L52KNQA.js} +1 -1
  5. package/dist/chunks/{chunk-E4PJNZVG.js → chunk-7EENF73W.js} +12 -13
  6. package/dist/chunks/{chunk-4U4DZ7VG.js → chunk-CK2GZEPK.js} +1 -1
  7. package/dist/chunks/{chunk-L36GBUBB.js → chunk-DC2CDHNK.js} +398 -158
  8. package/dist/chunks/{chunk-PN5ULTTH.js → chunk-DWEAHX4T.js} +1 -1
  9. package/dist/chunks/{chunk-5GBMR4HM.js → chunk-FCQUJDA4.js} +4 -7
  10. package/dist/chunks/{chunk-YV7GE6EV.js → chunk-FOZWA52V.js} +1 -1
  11. package/dist/chunks/{chunk-OX7X4B2L.js → chunk-G3PHMXH5.js} +1 -1
  12. package/dist/chunks/{chunk-CXAT7ZKP.js → chunk-HVNK3I45.js} +1 -1
  13. package/dist/chunks/{chunk-QVS7HRU7.js → chunk-OIY3DMF2.js} +2 -2
  14. package/dist/chunks/{chunk-SZEURWRS.js → chunk-P357TZAY.js} +2 -2
  15. package/dist/chunks/{chunk-KC4KDJ5K.js → chunk-V4IKA3WI.js} +153 -139
  16. package/dist/chunks/{chunk-RAQEXKL6.js → chunk-Z5PBVG3Y.js} +26 -18
  17. package/dist/chunks/{live-app-PI3BAN6Y.js → live-app-WECQOQ4C.js} +4 -4
  18. package/dist/commands/exec/across-sandboxes-outcomes.js +2 -1
  19. package/dist/commands/exec/command.d.ts +8 -2
  20. package/dist/commands/exec/command.js +11 -11
  21. package/dist/commands/exec/metadata.js +1 -1
  22. package/dist/commands/exec/outcomes.d.ts +4 -1
  23. package/dist/commands/exec/outcomes.js +2 -2
  24. package/dist/commands/exec/plan-only.js +1 -2
  25. package/dist/commands/exec/planned-outcome.js +8 -1
  26. package/dist/commands/exec/run-command.d.ts +6 -7
  27. package/dist/commands/exec/run-command.js +8 -9
  28. package/dist/commands/exec/run-metadata.js +1 -1
  29. package/dist/commands/runs/facts.d.ts +2 -1
  30. package/dist/commands/runs/facts.js +11 -3
  31. package/dist/commands/runs/list/command.d.ts +2 -0
  32. package/dist/commands/runs/list/command.js +6 -6
  33. package/dist/commands/runs/list/outcomes.d.ts +1 -0
  34. package/dist/commands/runs/logs/command.d.ts +6 -2
  35. package/dist/commands/runs/logs/command.js +6 -6
  36. package/dist/commands/runs/logs/outcomes.d.ts +3 -1
  37. package/dist/commands/runs/past-run.d.ts +14 -5
  38. package/dist/commands/runs/past-run.js +16 -5
  39. package/dist/commands/runs/show/command.d.ts +6 -2
  40. package/dist/commands/runs/show/command.js +9 -9
  41. package/dist/commands/runs/show/outcomes.d.ts +3 -1
  42. package/dist/commands/snapshots/build/command.js +11 -11
  43. package/dist/commands/snapshots/list/command.d.ts +3 -3
  44. package/dist/commands/snapshots/list/command.js +6 -6
  45. package/dist/commands/snapshots/list/metadata.js +1 -1
  46. package/dist/commands/suites/list/command.js +7 -6
  47. package/dist/commands/suites/list/outcomes.js +2 -2
  48. package/dist/commands/test/command.d.ts +8 -2
  49. package/dist/commands/test/command.js +38 -40
  50. package/dist/commands/test/metadata.js +1 -1
  51. package/dist/commands/test/outcomes.d.ts +4 -1
  52. package/dist/commands/test/outcomes.js +2 -2
  53. package/dist/commands/test/plan.d.ts +2 -2
  54. package/dist/commands/test/plan.js +2 -5
  55. package/dist/config/check-runner.d.ts +4 -2
  56. package/dist/config/check-runner.js +27 -2
  57. package/dist/config/check-suites.js +1 -0
  58. package/dist/config/gateways.d.ts +7 -3
  59. package/dist/config/index.d.ts +2 -3
  60. package/dist/config/index.js +2 -3
  61. package/dist/config/live/config-gateway.js +5 -2
  62. package/dist/config/load.d.ts +21 -4
  63. package/dist/config/load.js +129 -15
  64. package/dist/config/runner.d.ts +5 -6
  65. package/dist/config/runner.js +1 -1
  66. package/dist/config/schema.d.ts +15 -3
  67. package/dist/config/schema.js +10 -2
  68. package/dist/config/typed-options.d.ts +1 -6
  69. package/dist/config/typed-options.js +2 -10
  70. package/dist/config-file/define.d.ts +1 -11
  71. package/dist/config-file/define.js +3 -3
  72. package/dist/config-file/runner.d.ts +2 -3
  73. package/dist/config-file/toolchain.d.ts +13 -7
  74. package/dist/config-file/toolchain.js +51 -35
  75. package/dist/extensions/github/resource.d.ts +1 -1
  76. package/dist/extensions/github/resource.js +1 -1
  77. package/dist/extensions/testserver/commands/pool/create/command.js +1 -1
  78. package/dist/extensions/testserver/resource.d.ts +2 -2
  79. package/dist/extensions/testserver/resource.js +2 -2
  80. package/dist/planning/plan-only.d.ts +4 -1
  81. package/dist/planning/plan-only.js +5 -2
  82. package/dist/planning/run-plan.d.ts +1 -2
  83. package/dist/planning/test-plan.js +1 -2
  84. package/dist/runner/base.d.ts +0 -6
  85. package/dist/runner/base.js +0 -15
  86. package/dist/runner/build-snapshots.js +7 -8
  87. package/dist/runner/gateways.d.ts +5 -0
  88. package/dist/runner/index.d.ts +1 -1
  89. package/dist/runner/live/sandbox-gateway.js +12 -0
  90. package/dist/runner/prepare.d.ts +16 -15
  91. package/dist/runner/prepare.js +11 -12
  92. package/dist/runner/recipe.d.ts +66 -67
  93. package/dist/runner/recipe.js +204 -120
  94. package/dist/runner/snapshot-build.d.ts +1 -1
  95. package/dist/runner/snapshot-build.js +10 -3
  96. package/dist/runner/snapshot-inspect.d.ts +4 -4
  97. package/dist/runner/snapshot-inspect.js +7 -7
  98. package/dist/runner/snapshot-key.d.ts +23 -15
  99. package/dist/runner/snapshot-key.js +46 -27
  100. package/dist/sdk/extension/resource-definition.d.ts +3 -2
  101. package/dist/sdk/extension/resource-definition.js +3 -2
  102. package/dist/sdk/extension/resource-factory.js +3 -4
  103. package/dist/sdk/run/present.d.ts +3 -3
  104. package/dist/sdk/run/present.js +1 -3
  105. package/package.json +1 -1
  106. package/skills/overview.md +2 -0
  107. package/skills/plan-runs.md +1 -1
  108. package/dist/config/recipe-run.d.ts +0 -33
  109. package/dist/config/recipe-run.js +0 -28
@@ -1,7 +1,7 @@
1
1
  // The runner recipe, the `runner` key of `storm.config.ts`: what a repository's runner snapshot holds and what
2
- // each run does on top of it. `checkRecipe` holds the recipe's static rules; `resolveSteps` and `resolveVcpus`
3
- // evaluate the parts a recipe may give as functions, and check what they return. The module names no resource: a
4
- // `vcpus` function's run is a type parameter, which the config module declares (`RecipeRun`).
2
+ // each run does on top of it. `checkRecipe` holds the recipe's static rules; `resolveVcpus` and
3
+ // `resolveSandboxCountDefault` evaluate the declared scaling rules for a run. Every recipe value is plain data
4
+ // (no functions), and the module names no resource.
5
5
  import { parseKeepTime, parseTtl } from "../time/index.js";
6
6
  import { RUN_PAYLOAD_VARIABLE } from "../sdk/run/launcher.js";
7
7
  import { describeRecipeValue, reportUnknownKeys } from "./recipe-check.js";
@@ -38,16 +38,18 @@ const RECIPE_KEYS = new Set([
38
38
  "sandboxes",
39
39
  ]);
40
40
  const SANDBOXES_KEYS = new Set(["max", "default"]);
41
+ const SANDBOXES_DEFAULT_RULE_KEYS = new Set(["filesPerSandbox", "max"]);
42
+ const VCPUS_RULE_KEYS = new Set(["resource", "option", "per", "min", "max"]);
41
43
  const SNAPSHOT_KEYS = new Set(["vcpus", "summary", "toolchains", "prebuild"]);
42
44
  const RUN_KEYS = new Set(["install", "build"]);
43
45
  const STEP_KEYS = new Set(["label", "script"]);
46
+ const TOOLCHAIN_STEP_KEYS = new Set(["label", "script", "baseFiles"]);
44
47
  const NAME_PATTERN = /^[a-z0-9][a-z0-9-]*$/;
45
48
  /** A domain the recipe's `allowedDomains` lists: a bare hostname, or one with a leading `*.`. */
46
49
  const ALLOWED_DOMAIN_PATTERN = /^(?:\*\.)?(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;
47
50
  /**
48
- * Checks a recipe against its static rules: the keys it may hold and each value's shape. Functions are checked only
49
- * for being functions, so a `vcpus` function is taken to take `Run`; `resolveSteps` and `resolveVcpus` check what they
50
- * return. Every problem is reported.
51
+ * Checks a recipe against its static rules: the keys it may hold and each value's shape. Every value must be plain
52
+ * data; functions are refused with the declared form to use instead. Every problem is reported.
51
53
  */
52
54
  export function checkRecipe(value) {
53
55
  const problems = [];
@@ -65,9 +67,7 @@ export function checkRecipe(value) {
65
67
  const cwd = orDefault(value["cwd"], RECIPE_DEFAULTS.cwd);
66
68
  if (!isRelativePath(cwd))
67
69
  report(["cwd"], `must be a path relative to the repository's root, without "..", not ${describeRecipeValue(cwd)}`);
68
- const vcpus = value["vcpus"];
69
- if (typeof vcpus !== "function" && !isPositiveInteger(vcpus))
70
- report(["vcpus"], `must be a positive whole number, or a function of the run, not ${describeRecipeValue(vcpus)}`);
70
+ const vcpus = checkVcpus(value["vcpus"], report);
71
71
  const env = checkEnv(value["env"], report);
72
72
  const credentials = checkCredentials(value["credentials"], report);
73
73
  const unsafeSecretEnvVars = checkUnsafeSecretEnvVars(value["unsafeSecretEnvVars"], env, credentials, report);
@@ -96,6 +96,7 @@ export function checkRecipe(value) {
96
96
  if (problems.length > 0 ||
97
97
  snapshot === undefined ||
98
98
  run === undefined ||
99
+ vcpus === undefined ||
99
100
  env === undefined ||
100
101
  credentials === undefined ||
101
102
  unsafeSecretEnvVars === undefined ||
@@ -111,7 +112,7 @@ export function checkRecipe(value) {
111
112
  snapshot,
112
113
  run,
113
114
  cwd: cwd,
114
- vcpus: vcpus,
115
+ vcpus,
115
116
  env,
116
117
  credentials,
117
118
  unsafeSecretEnvVars,
@@ -126,11 +127,61 @@ export function checkRecipe(value) {
126
127
  },
127
128
  };
128
129
  }
130
+ function checkVcpus(value, report) {
131
+ if (isPositiveInteger(value))
132
+ return value;
133
+ if (typeof value === "function") {
134
+ report(["vcpus"], "can't be a function: use a positive whole number, or { resource, option, per, min, max }");
135
+ return undefined;
136
+ }
137
+ if (!isRecord(value)) {
138
+ report(["vcpus"], `must be a positive whole number, or { resource, option, per, min, max }, not ${describeRecipeValue(value)}`);
139
+ return undefined;
140
+ }
141
+ let ok = reportUnknownKeys(value, VCPUS_RULE_KEYS, ["vcpus"], "a runner recipe vcpus rule key", report);
142
+ const resource = value["resource"];
143
+ if (!isNonEmptyString(resource)) {
144
+ report(["vcpus", "resource"], `must be a non-empty string, not ${describeRecipeValue(resource)}`);
145
+ ok = false;
146
+ }
147
+ const option = value["option"];
148
+ if (!isNonEmptyString(option)) {
149
+ report(["vcpus", "option"], `must be a non-empty string, not ${describeRecipeValue(option)}`);
150
+ ok = false;
151
+ }
152
+ const per = value["per"];
153
+ if (!isPositiveInteger(per)) {
154
+ report(["vcpus", "per"], `must be a positive whole number, not ${describeRecipeValue(per)}`);
155
+ ok = false;
156
+ }
157
+ const min = value["min"];
158
+ if (!isPositiveInteger(min)) {
159
+ report(["vcpus", "min"], `must be a positive whole number, not ${describeRecipeValue(min)}`);
160
+ ok = false;
161
+ }
162
+ const max = value["max"];
163
+ if (!isPositiveInteger(max)) {
164
+ report(["vcpus", "max"], `must be a positive whole number, not ${describeRecipeValue(max)}`);
165
+ ok = false;
166
+ }
167
+ else if (isPositiveInteger(min) && max < min) {
168
+ report(["vcpus", "max"], `must be at least vcpus.min (${min}), not ${max}`);
169
+ ok = false;
170
+ }
171
+ return ok
172
+ ? {
173
+ resource: resource,
174
+ option: option,
175
+ per: per,
176
+ min: min,
177
+ max: max,
178
+ }
179
+ : undefined;
180
+ }
129
181
  /**
130
182
  * The recipe's `sandboxes`: an object whose `max` is a whole number from 1 to `MAX_RUNNER_SANDBOXES`, and whose
131
- * optional `default` is a whole number from 1 to `MAX_RUNNER_SANDBOXES` or a function, which is checked only for being
132
- * one (`resolveSandboxCountDefault` checks what it returns); undefined when absent, and false when it is wrong, which
133
- * is reported.
183
+ * optional `default` is a whole number from 1 to `MAX_RUNNER_SANDBOXES` or a declared `{ filesPerSandbox, max? }` rule;
184
+ * undefined when absent, and false when it is wrong, which is reported.
134
185
  */
135
186
  function checkSandboxes(value, report) {
136
187
  if (value === undefined)
@@ -145,12 +196,14 @@ function checkSandboxes(value, report) {
145
196
  report(["sandboxes", "max"], `must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, not ${describeRecipeValue(max)}`);
146
197
  ok = false;
147
198
  }
148
- const sandboxesDefault = value["default"];
149
- if (sandboxesDefault !== undefined &&
150
- typeof sandboxesDefault !== "function" &&
151
- !(isPositiveInteger(sandboxesDefault) && sandboxesDefault <= MAX_RUNNER_SANDBOXES)) {
152
- report(["sandboxes", "default"], `must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, or a function of the run's test plan, not ${describeRecipeValue(sandboxesDefault)}`);
153
- ok = false;
199
+ const rawDefault = value["default"];
200
+ let sandboxesDefault;
201
+ if (rawDefault !== undefined) {
202
+ const checkedDefault = checkSandboxesDefault(rawDefault, report);
203
+ if (checkedDefault === undefined)
204
+ ok = false;
205
+ else
206
+ sandboxesDefault = checkedDefault;
154
207
  }
155
208
  if (!ok)
156
209
  return false;
@@ -159,6 +212,35 @@ function checkSandboxes(value, report) {
159
212
  ...(sandboxesDefault === undefined ? {} : { default: sandboxesDefault }),
160
213
  };
161
214
  }
215
+ function checkSandboxesDefault(value, report) {
216
+ if (isPositiveInteger(value) && value <= MAX_RUNNER_SANDBOXES)
217
+ return value;
218
+ if (typeof value === "function") {
219
+ report(["sandboxes", "default"], `can't be a function: use a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, or { filesPerSandbox, max? }`);
220
+ return undefined;
221
+ }
222
+ if (!isRecord(value)) {
223
+ report(["sandboxes", "default"], `must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, or { filesPerSandbox, max? }, not ${describeRecipeValue(value)}`);
224
+ return undefined;
225
+ }
226
+ let ok = reportUnknownKeys(value, SANDBOXES_DEFAULT_RULE_KEYS, ["sandboxes", "default"], "a runner recipe sandboxes default rule key", report);
227
+ const filesPerSandbox = value["filesPerSandbox"];
228
+ if (!isPositiveInteger(filesPerSandbox)) {
229
+ report(["sandboxes", "default", "filesPerSandbox"], `must be a positive whole number, not ${describeRecipeValue(filesPerSandbox)}`);
230
+ ok = false;
231
+ }
232
+ const max = value["max"];
233
+ if (max !== undefined && (!isPositiveInteger(max) || max > MAX_RUNNER_SANDBOXES)) {
234
+ report(["sandboxes", "default", "max"], `must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, not ${describeRecipeValue(max)}`);
235
+ ok = false;
236
+ }
237
+ if (!ok)
238
+ return undefined;
239
+ return {
240
+ filesPerSandbox: filesPerSandbox,
241
+ ...(max === undefined ? {} : { max: max }),
242
+ };
243
+ }
162
244
  function checkSnapshot(value, report) {
163
245
  if (!isRecord(value)) {
164
246
  report(["snapshot"], `must be an object of vcpus, toolchains, prebuild, and an optional summary, not ${describeRecipeValue(value)}`);
@@ -175,8 +257,8 @@ function checkSnapshot(value, report) {
175
257
  report(["snapshot", "summary"], `must be a non-empty string, not ${describeRecipeValue(summary)}`);
176
258
  ok = false;
177
259
  }
178
- const toolchains = checkSteps(value["toolchains"], ["snapshot", "toolchains"], report);
179
- const prebuild = checkSteps(value["prebuild"], ["snapshot", "prebuild"], report);
260
+ const toolchains = checkSteps(value["toolchains"], ["snapshot", "toolchains"], true, report);
261
+ const prebuild = checkSteps(value["prebuild"], ["snapshot", "prebuild"], false, report);
180
262
  if (!ok || toolchains === undefined || prebuild === undefined)
181
263
  return undefined;
182
264
  return {
@@ -192,36 +274,42 @@ function checkRun(value, report) {
192
274
  return undefined;
193
275
  }
194
276
  const ok = reportUnknownKeys(value, RUN_KEYS, ["run"], "a runner recipe run key", report);
195
- const install = checkStep(value["install"], ["run", "install"], report);
196
- const build = checkStep(value["build"], ["run", "build"], report);
277
+ const install = checkStep(value["install"], ["run", "install"], false, report);
278
+ const build = checkStep(value["build"], ["run", "build"], false, report);
197
279
  return ok && install !== undefined && build !== undefined ? { install, build } : undefined;
198
280
  }
199
- function checkSteps(value, path, report) {
200
- if (typeof value === "function")
201
- return value;
281
+ function checkSteps(value, path, allowBaseFiles, report) {
282
+ if (typeof value === "function") {
283
+ report(path, allowBaseFiles
284
+ ? "can't be a function: use a list of { label, script, baseFiles? } steps and declare the base files each step reads"
285
+ : "can't be a function: use a list of { label, script } steps (prebuild steps already see the base's files)");
286
+ return undefined;
287
+ }
202
288
  if (!Array.isArray(value)) {
203
- report(path, `must be a list of steps, or a function that returns one, not ${describeRecipeValue(value)}`);
289
+ report(path, `must be a list of steps, not ${describeRecipeValue(value)}`);
204
290
  return undefined;
205
291
  }
206
- const steps = value.map((step, index) => checkStep(step, [...path, String(index)], report));
292
+ const steps = value.map((step, index) => allowBaseFiles
293
+ ? checkStep(step, [...path, String(index)], true, report)
294
+ : checkStep(step, [...path, String(index)], false, report));
207
295
  return steps.every((step) => step !== undefined) ? steps : undefined;
208
296
  }
209
- /**
210
- * One step: a label and a script. A step's `secrets` key is refused with its own problem, since every recipe step gets
211
- * every credential the recipe declares and a step names none itself.
212
- */
213
- function checkStep(value, path, report) {
297
+ function checkStep(value, path, allowBaseFiles, report) {
214
298
  if (!isRecord(value)) {
215
- report(path, `must be a step, { label, script }, not ${describeRecipeValue(value)}`);
299
+ const shape = allowBaseFiles ? "{ label, script, baseFiles? }" : "{ label, script }";
300
+ report(path, `must be a step, ${shape}, not ${describeRecipeValue(value)}`);
216
301
  return undefined;
217
302
  }
303
+ const allowedKeys = allowBaseFiles ? TOOLCHAIN_STEP_KEYS : STEP_KEYS;
218
304
  let ok = true;
219
305
  for (const key of Object.keys(value)) {
220
- if (STEP_KEYS.has(key))
306
+ if (allowedKeys.has(key))
221
307
  continue;
222
308
  report([...path, key], key === "secrets"
223
309
  ? "is not a step key: every recipe step gets every credential runner.credentials declares"
224
- : "is not a step key");
310
+ : key === "baseFiles"
311
+ ? "is only allowed on snapshot.toolchains steps: this step already sees the base's files"
312
+ : "is not a step key");
225
313
  ok = false;
226
314
  }
227
315
  const label = value["label"];
@@ -234,7 +322,45 @@ function checkStep(value, path, report) {
234
322
  report([...path, "script"], `must be a non-empty string, not ${describeRecipeValue(script)}`);
235
323
  ok = false;
236
324
  }
237
- return ok ? { label: label, script: script } : undefined;
325
+ if (!allowBaseFiles)
326
+ return ok ? { label: label, script: script } : undefined;
327
+ const baseFiles = checkBaseFiles(value["baseFiles"], [...path, "baseFiles"], report);
328
+ if (baseFiles === null)
329
+ ok = false;
330
+ if (!ok || baseFiles === null)
331
+ return undefined;
332
+ return {
333
+ label: label,
334
+ script: script,
335
+ ...(baseFiles === undefined || baseFiles.length === 0 ? {} : { baseFiles }),
336
+ };
337
+ }
338
+ function checkBaseFiles(value, path, report) {
339
+ if (value === undefined)
340
+ return undefined;
341
+ if (!Array.isArray(value)) {
342
+ report(path, `must be a list of relative file paths, not ${describeRecipeValue(value)}`);
343
+ return null;
344
+ }
345
+ let ok = true;
346
+ const seen = new Set();
347
+ const checked = [];
348
+ value.forEach((entry, index) => {
349
+ const at = [...path, String(index)];
350
+ if (!isRelativeFilePath(entry)) {
351
+ report(at, `must be a relative file path without leading "/", "./", "..", or trailing "/", not ${describeRecipeValue(entry)}`);
352
+ ok = false;
353
+ }
354
+ else if (seen.has(entry)) {
355
+ report(at, `lists ${entry} again`);
356
+ ok = false;
357
+ }
358
+ else {
359
+ seen.add(entry);
360
+ checked.push(entry);
361
+ }
362
+ });
363
+ return ok ? checked : null;
238
364
  }
239
365
  function checkEnv(value, report) {
240
366
  if (value === undefined)
@@ -311,101 +437,51 @@ function checkBaseRefs(value, report) {
311
437
  });
312
438
  return ok ? [...value] : undefined;
313
439
  }
314
- /**
315
- * What a recipe's steps are at one base: the list as given, or what the function returns for `context`, checked. A
316
- * function that throws or rejects, or returns anything but a list of steps, is a problem worded to follow the key.
317
- */
318
- export async function resolveSteps(steps, context) {
319
- // A list passed `checkRecipe`.
320
- if (typeof steps !== "function")
321
- return { ok: true, steps: steps.map(({ label, script }) => ({ label, script })) };
322
- let returned;
323
- try {
324
- returned = await steps(context);
325
- }
326
- catch (error) {
327
- return { ok: false, problem: `threw at base ${context.base.slice(0, 12)}: ${errorMessage(error)}` };
328
- }
329
- if (!Array.isArray(returned))
330
- return { ok: false, problem: `must return a list of steps, not ${describeRecipeValue(returned)}` };
331
- const problems = [];
332
- const checked = returned.map((step, index) => checkStep(step, [String(index)], (path, problem) => problems.push({ path, problem })));
333
- const first = problems[0];
334
- if (first !== undefined)
335
- return {
336
- ok: false,
337
- problem: `must return a list of { label, script } steps, but item ${first.path.join(".")} ${first.problem}`,
338
- };
339
- return { ok: true, steps: checked };
440
+ /** The sorted, unique repository-relative base file paths declared across `toolchains`. */
441
+ export function declaredBaseFilePaths(toolchains) {
442
+ const paths = new Set();
443
+ for (const step of toolchains) {
444
+ if (step.baseFiles === undefined)
445
+ continue;
446
+ for (const file of step.baseFiles)
447
+ paths.add(file);
448
+ }
449
+ return [...paths].toSorted((a, b) => (a < b ? -1 : a > b ? 1 : 0));
340
450
  }
341
451
  /**
342
- * The runner sandbox's vCPUs for `run`: the recipe's number, or what its function returns for the run, which must be a
343
- * positive whole number.
452
+ * The runner sandbox's vCPUs for `run`: the recipe's number, or the declared resource-scaling rule evaluated against
453
+ * `run.resources` and `run.sandboxes`. When the named resource is absent from the run, `min` is used. When the named
454
+ * resource is present and its named option is missing or not a non-negative finite number, returns a problem.
344
455
  */
345
- export function resolveVcpus(recipe, { run, resourceKeys }) {
346
- if (typeof recipe.vcpus !== "function")
456
+ export function resolveVcpus(recipe, run) {
457
+ if (typeof recipe.vcpus === "number")
347
458
  return { ok: true, vcpus: recipe.vcpus };
348
- let returned;
349
- try {
350
- returned = recipe.vcpus(run);
351
- }
352
- catch (error) {
353
- return { ok: false, problem: `threw for ${describeResourceKeys(resourceKeys)}: ${errorMessage(error)}` };
354
- }
355
- return isPositiveInteger(returned)
356
- ? { ok: true, vcpus: returned }
357
- : {
459
+ const { resource, option, per, min, max } = recipe.vcpus;
460
+ const options = Object.hasOwn(run.resources, resource) ? run.resources[resource] : undefined;
461
+ if (options === undefined)
462
+ return { ok: true, vcpus: min };
463
+ const raw = Object.hasOwn(options, option) ? options[option] : undefined;
464
+ if (typeof raw !== "number" || !Number.isFinite(raw) || raw < 0) {
465
+ return {
358
466
  ok: false,
359
- problem: `must return a positive whole number, not ${describeRecipeValue(returned)} for ${describeResourceKeys(resourceKeys)}`,
467
+ problem: `resource "${resource}" option "${option}" must be a non-negative number, not ${describeRecipeValue(raw)}`,
360
468
  };
469
+ }
470
+ const perSandbox = Math.ceil(raw / Math.max(1, run.sandboxes));
471
+ return { ok: true, vcpus: Math.min(max, Math.max(min, per * perSandbox)) };
361
472
  }
362
473
  /**
363
474
  * The number of runner sandboxes `runner.sandboxes.default` gives a run with test plan `testPlan`: the recipe's number,
364
- * or what its function returns for `{ testPlan }`, which must be a whole number from 1. A number above the limit is not
365
- * a problem here: the run lowers it to `max` and says so. A function that throws, or returns anything else, is a
366
- * problem worded to follow the key, which names the test plan.
475
+ * or the declared `{ filesPerSandbox, max? }` rule evaluated against `testPlan`. A number above `sandboxes.max` is not
476
+ * a problem here: the run lowers it to `sandboxes.max` and says so.
367
477
  */
368
478
  export function resolveSandboxCountDefault(sandboxesDefault, testPlan) {
369
- if (typeof sandboxesDefault !== "function")
370
- return { ok: true, sandboxes: sandboxesDefault };
371
- let returned;
372
- try {
373
- returned = sandboxesDefault(Object.freeze({ testPlan }));
374
- }
375
- catch (error) {
376
- return { ok: false, problem: `threw for ${describeTestPlan(testPlan)}: ${errorMessage(error)}` };
377
- }
378
- return isPositiveInteger(returned)
379
- ? { ok: true, sandboxes: returned }
380
- : {
381
- ok: false,
382
- problem: `must return a whole number from 1, not ${describeRecipeValue(returned)} for ${describeTestPlan(testPlan)}`,
383
- };
384
- }
385
- /**
386
- * A test plan as a problem names it: `a test plan of 57 test files`, `a test plan of 65 tests in 19 test files`, or
387
- * `a test plan that counted nothing`.
388
- */
389
- function describeTestPlan(testPlan) {
479
+ if (typeof sandboxesDefault === "number")
480
+ return sandboxesDefault;
390
481
  if (testPlan.kind !== "counted")
391
- return "a test plan that counted nothing";
392
- const files = `${testPlan.files} test ${testPlan.files === 1 ? "file" : "files"}`;
393
- return testPlan.tests === undefined
394
- ? `a test plan of ${files}`
395
- : `a test plan of ${testPlan.tests} ${testPlan.tests === 1 ? "test" : "tests"} in ${files}`;
396
- }
397
- /**
398
- * The run as a problem names it, by the keys of its resources: `a run with no resource`, or `a run with` and the
399
- * keys, as `a`, `a and b` or `a, b and c`.
400
- */
401
- function describeResourceKeys(names) {
402
- const last = names.at(-1);
403
- if (last === undefined)
404
- return "a run with no resource";
405
- return `a run with ${names.length === 1 ? last : `${names.slice(0, -1).join(", ")} and ${last}`}`;
406
- }
407
- function errorMessage(error) {
408
- return error instanceof Error ? error.message : String(error);
482
+ return 1;
483
+ const limit = sandboxesDefault.max ?? MAX_RUNNER_SANDBOXES;
484
+ return Math.max(1, Math.min(limit, Math.ceil(testPlan.files / sandboxesDefault.filesPerSandbox)));
409
485
  }
410
486
  /** `value`, or `fallback` when the key is absent or set to `undefined`. A `null` stays, to be refused. */
411
487
  function orDefault(value, fallback) {
@@ -423,3 +499,11 @@ function isPositiveInteger(value) {
423
499
  function isRelativePath(value) {
424
500
  return (typeof value === "string" && value.length > 0 && !value.startsWith("/") && !value.split(/[/\\]/).includes(".."));
425
501
  }
502
+ function isRelativeFilePath(value) {
503
+ if (typeof value !== "string" || value.length === 0)
504
+ return false;
505
+ if (value.startsWith("/") || value.endsWith("/") || value.includes("\\") || value.includes("\0"))
506
+ return false;
507
+ const segments = value.split("/");
508
+ return segments.every((segment) => segment.length > 0 && segment !== "." && segment !== "..");
509
+ }
@@ -21,7 +21,7 @@ export interface BuiltSnapshot {
21
21
  * What a base snapshot build reads of a prepared run, or of a `storm snapshots build` plan: the recipe, the
22
22
  * checkout, the base, its snapshot steps and key, and how many commits HEAD has after the base.
23
23
  */
24
- export interface BaseSnapshotPlan extends Pick<PreparedRunner, "recipe" | "repoRoot" | "base" | "toolchains" | "prebuild" | "snapshotKey"> {
24
+ export interface BaseSnapshotPlan extends Pick<PreparedRunner, "recipe" | "repoRoot" | "base" | "baseFiles" | "snapshotKey"> {
25
25
  /** How many commits HEAD has after the base; null for a `--base` commit that isn't HEAD's merge-base. */
26
26
  readonly commitsAfterBase: number | null;
27
27
  }
@@ -26,7 +26,8 @@ export async function buildSnapshot(context, request, control, progress) {
26
26
  kind: "snapshot-build-started",
27
27
  base,
28
28
  why: request.why,
29
- summary: recipe.snapshot.summary ?? [...prepared.toolchains, ...prepared.prebuild].map(({ label }) => label).join(", "),
29
+ summary: recipe.snapshot.summary ??
30
+ [...recipe.snapshot.toolchains, ...recipe.snapshot.prebuild].map(({ label }) => label).join(", "),
30
31
  });
31
32
  const [started, archive] = await Promise.all([
32
33
  scope.startBuildSandbox(access, {
@@ -57,14 +58,20 @@ export async function buildSnapshot(context, request, control, progress) {
57
58
  ], signal);
58
59
  if (!staged.ok)
59
60
  return sandboxStop("upload", staged.failure);
61
+ if (prepared.baseFiles.length > 0) {
62
+ const encoder = new TextEncoder();
63
+ const placed = await context.runnerSandboxes.placeBaseFiles(sandbox, prepared.baseFiles.map(({ path, text }) => ({ name: path, content: encoder.encode(text) })), signal);
64
+ if (!placed.ok)
65
+ return sandboxStop("upload", placed.failure);
66
+ }
60
67
  // Every credential the recipe declares goes on the steps' requests, from before the first toolchain step until
61
68
  // `saveSnapshot` revokes them before saving (or the scope's fence revokes them if a step fails or the build is
62
69
  // canceled). storm's own base-index step falls inside: it runs only tar and git on the uploaded files, so it makes no
63
70
  // request, and revoking and granting again around it would add two writes and their failures for nothing.
64
71
  const steps = [
65
- ...prepared.toolchains,
72
+ ...recipe.snapshot.toolchains,
66
73
  { label: BASE_INDEX_LABEL, script: baseIndexScript(base, staged.value.directory) },
67
- ...prepared.prebuild,
74
+ ...recipe.snapshot.prebuild,
68
75
  ];
69
76
  await progress.emit({ kind: "output-started", section: "snapshot", sandbox: sandbox.name, region: recipe.region });
70
77
  let stop;
@@ -50,8 +50,8 @@ export interface SnapshotCacheInspection {
50
50
  }
51
51
  /**
52
52
  * How an inspection ended: what it found; the cache it couldn't list; git failing while it checked the checkout or a
53
- * snapshot (`checkout-failed`); or a step function of the recipe that failed or returned something storm can't use at
54
- * the merge-base (`invalid-recipe`), as a run's local checks refuse it, with `path` the key inside the recipe.
53
+ * snapshot (`checkout-failed`); or a declared base file of the recipe that couldn't be read at the merge-base
54
+ * (`invalid-recipe`), as a run's local checks refuse it, with `path` the key inside the recipe.
55
55
  */
56
56
  export type SnapshotCacheInspectionOutcome = {
57
57
  readonly kind: "ok";
@@ -72,8 +72,8 @@ export type SnapshotCacheInspectionOutcome = {
72
72
  * Inspects the cache from `cwd` for `recipe`, the runner recipe that applies there, if any. With a recipe, in a Git
73
73
  * checkout whose HEAD shares history with one of its base refs, it marks for each team and project the snapshot a run
74
74
  * here starts from, by a run's own rule (`classifySnapshotEntries`, `pickSnapshot`), and gives each other
75
- * snapshot of the recipe the reason it isn't picked. It runs the recipe's snapshot steps at the merge-base for the
76
- * run's snapshot key, as a run does. Otherwise it picks none and
75
+ * snapshot of the recipe the reason it isn't picked. It reads the recipe's declared base files at the merge-base for
76
+ * the run's snapshot key, as a run does. Otherwise it picks none and
77
77
  * says why. `all` adds the snapshots of other recipes, and of the recipe's other regions and runtimes, as
78
78
  * `other-recipe`. It lists the cache once and classifies that listing, which removes no file, so an expired entry of
79
79
  * the recipe stays and is `expired`. A git failure ends it with `checkout-failed`, as it ends a run.
@@ -3,13 +3,13 @@
3
3
  // the cache and Git, and changes nothing: no file is removed, nothing is minted, and no sandbox starts.
4
4
  import { resolveBase } from "./base.js";
5
5
  import { classifySnapshotEntries, isExpiredEntry, pickSnapshot, } from "./snapshot-cache.js";
6
- import { snapshotStepsAt } from "./snapshot-key.js";
6
+ import { snapshotInputsAt } from "./snapshot-key.js";
7
7
  /**
8
8
  * Inspects the cache from `cwd` for `recipe`, the runner recipe that applies there, if any. With a recipe, in a Git
9
9
  * checkout whose HEAD shares history with one of its base refs, it marks for each team and project the snapshot a run
10
10
  * here starts from, by a run's own rule (`classifySnapshotEntries`, `pickSnapshot`), and gives each other
11
- * snapshot of the recipe the reason it isn't picked. It runs the recipe's snapshot steps at the merge-base for the
12
- * run's snapshot key, as a run does. Otherwise it picks none and
11
+ * snapshot of the recipe the reason it isn't picked. It reads the recipe's declared base files at the merge-base for
12
+ * the run's snapshot key, as a run does. Otherwise it picks none and
13
13
  * says why. `all` adds the snapshots of other recipes, and of the recipe's other regions and runtimes, as
14
14
  * `other-recipe`. It lists the cache once and classifies that listing, which removes no file, so an expired entry of
15
15
  * the recipe stays and is `expired`. A git failure ends it with `checkout-failed`, as it ends a run.
@@ -59,9 +59,9 @@ export async function inspectSnapshotCache(context, request) {
59
59
  };
60
60
  }
61
61
  const mergeBase = resolved.base;
62
- const steps = await snapshotStepsAt(checkout, { repoRoot, base: mergeBase, recipe });
63
- if (!steps.ok)
64
- return { kind: "invalid-recipe", path: steps.path, problem: steps.problem };
62
+ const inputs = await snapshotInputsAt(checkout, { repoRoot, base: mergeBase, recipe });
63
+ if (!inputs.ok)
64
+ return { kind: "invalid-recipe", path: inputs.path, problem: inputs.problem };
65
65
  const afterBase = await checkout.commitCount({ repoRoot, from: mergeBase, to: "HEAD" });
66
66
  if (!afterBase.ok)
67
67
  return { kind: "checkout-failed", failure: afterBase.failure };
@@ -70,7 +70,7 @@ export async function inspectSnapshotCache(context, request) {
70
70
  entries,
71
71
  recipe,
72
72
  base: mergeBase,
73
- snapshotKey: steps.key,
73
+ snapshotKey: inputs.key,
74
74
  commitsAfterBase: afterBase.value,
75
75
  });
76
76
  // The choice is per team and project, since the credential that names them isn't minted here. Every entry that isn't
@@ -4,9 +4,14 @@ import { type CheckedRecipe, type RunnerStep } from "./recipe.ts";
4
4
  * Bump when a runner snapshot changes in a way its steps' text doesn't show (the scripts between the steps, what is
5
5
  * uploaded, the build sandbox), or the key's encoding changes, so earlier snapshots stop matching. 2 added each step's
6
6
  * runner secret names. 3 dropped dev snapshots. 4 replaced per-step runner secret names with the recipe's credential
7
- * source identities (`credentials=`).
7
+ * source identities (`credentials=`). 5 added declared base files' paths and contents (`baseFiles=`).
8
8
  */
9
- export declare const SNAPSHOT_FORMAT = 4;
9
+ export declare const SNAPSHOT_FORMAT = 5;
10
+ /** One declared base file read from the base commit, to stage into `/vercel/sandbox/<path>` before toolchain steps. */
11
+ export interface DeclaredBaseFile {
12
+ readonly path: string;
13
+ readonly text: string;
14
+ }
10
15
  /** Where the repository lives in every runner and build sandbox. */
11
16
  export declare const SANDBOX_ROOT = "/vercel/sandbox";
12
17
  /** The names of the files uploaded to a sandbox's staging directory. */
@@ -34,22 +39,24 @@ export declare function baseIndexScript(base: string, staging: string): string;
34
39
  export declare function applyScript(staging: string, root?: string): string;
35
40
  /**
36
41
  * The snapshot key: sha256 hex over `format=<SNAPSHOT_FORMAT>`, `credentials=<the secret source identities the recipe's
37
- * credentials read, sorted, once each, joined with ",">`, each toolchain step's label and script, the base-index script
38
- * with the placeholders `<base>` and `<staging>`, and each prebuild step's label and script, joined with NUL. A recipe
39
- * without credentials gives `credentials=`. Every snapshot step gets every credential, so the source identities are in
40
- * the key once, never the values, domains, or headers: a recipe that reads another source builds another snapshot, and
41
- * every machine with the same recipe shares one. The base isn't in the key: a cache entry records it beside the key.
42
+ * credentials read, sorted, once each, joined with ",">`, `baseFiles=<count>` followed by each sorted declared base
43
+ * file's path and text, each toolchain step's label and script, the base-index script with the placeholders `<base>`
44
+ * and `<staging>`, and each prebuild step's label and script, joined with NUL. A recipe without credentials gives
45
+ * `credentials=`, and one without declared base files gives `baseFiles=0`. Every snapshot step gets every credential,
46
+ * so the source identities are in the key once, never the values, domains, or headers: a recipe that reads another
47
+ * source builds another snapshot, and every machine with the same recipe shares one. The base isn't in the key: a
48
+ * cache entry records it beside the key.
42
49
  */
43
50
  export declare function snapshotKey(steps: {
44
51
  readonly credentials: readonly string[];
52
+ readonly baseFiles: readonly DeclaredBaseFile[];
45
53
  readonly toolchains: readonly RunnerStep[];
46
54
  readonly prebuild: readonly RunnerStep[];
47
55
  }): string;
48
- /** A recipe's snapshot steps at one base and their key, or the step key whose function failed there and why. */
49
- export type SnapshotStepsAt = {
56
+ /** A recipe's snapshot inputs at one base and their key, or why a declared base file couldn't be read there. */
57
+ export type SnapshotInputsAt = {
50
58
  readonly ok: true;
51
- readonly toolchains: readonly RunnerStep[];
52
- readonly prebuild: readonly RunnerStep[];
59
+ readonly baseFiles: readonly DeclaredBaseFile[];
53
60
  readonly key: string;
54
61
  } | {
55
62
  readonly ok: false;
@@ -57,14 +64,15 @@ export type SnapshotStepsAt = {
57
64
  readonly problem: string;
58
65
  };
59
66
  /**
60
- * Evaluates `recipe`'s toolchain and prebuild steps at `base`, and computes their snapshot key with the secret source
61
- * identities the recipe's credentials read.
67
+ * Reads `recipe`'s declared base files at `base` and computes its snapshot key with the secret source identities the
68
+ * recipe's credentials read. Fails with `path: ["snapshot", "toolchains"]` if any declared base file is missing or
69
+ * unreadable at `base`.
62
70
  */
63
- export declare function snapshotStepsAt(checkout: CheckoutGateway, request: {
71
+ export declare function snapshotInputsAt(checkout: CheckoutGateway, request: {
64
72
  readonly repoRoot: string;
65
73
  readonly base: string;
66
74
  readonly recipe: {
67
75
  readonly snapshot: Pick<CheckedRecipe["snapshot"], "toolchains" | "prebuild">;
68
76
  readonly credentials: CheckedRecipe["credentials"];
69
77
  };
70
- }): Promise<SnapshotStepsAt>;
78
+ }): Promise<SnapshotInputsAt>;