@cnc-tools/storm 0.8.1 → 0.9.1

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 (108) hide show
  1. package/bin/storm.js +3 -14
  2. package/dist/application.d.ts +18 -10
  3. package/dist/application.js +10 -11
  4. package/dist/bin/storm.js +97 -41
  5. package/dist/build-info.js +1 -1
  6. package/dist/chunks/chunk-5CQCRX2L.js +5768 -0
  7. package/dist/chunks/chunk-5U5Q6VZR.js +556 -0
  8. package/dist/chunks/chunk-7O6UN63H.js +63 -0
  9. package/dist/chunks/chunk-I5GZLOLQ.js +38 -0
  10. package/dist/chunks/chunk-NX55IJ5S.js +1842 -0
  11. package/dist/chunks/chunk-OCZJE5XV.js +910 -0
  12. package/dist/chunks/chunk-RRQ2ZGSE.js +1512 -0
  13. package/dist/chunks/chunk-S5NAIZYS.js +13 -0
  14. package/dist/chunks/chunk-UHO5OCEX.js +360 -0
  15. package/dist/chunks/chunk-WBIHJM7D.js +188 -0
  16. package/dist/chunks/chunk-WV6WQFC6.js +436 -0
  17. package/dist/chunks/live-app-X3PW2W42.js +89 -0
  18. package/dist/chunks/version-X7RMSKZI.js +12 -0
  19. package/dist/commands/exec/command.d.ts +32 -0
  20. package/dist/commands/exec/command.js +35 -21
  21. package/dist/commands/exec/metadata.js +66 -58
  22. package/dist/commands/exec/outcomes.d.ts +67 -0
  23. package/dist/commands/exec/outcomes.js +50 -0
  24. package/dist/commands/exec/redaction.js +1 -1
  25. package/dist/commands/exec/run-collector.d.ts +1 -1
  26. package/dist/commands/exec/run-collector.js +1 -1
  27. package/dist/commands/exec/run-command.d.ts +17 -11
  28. package/dist/commands/exec/run-command.js +33 -16
  29. package/dist/commands/exec/run-record.d.ts +1 -1
  30. package/dist/commands/exec/tests-summary.d.ts +1 -1
  31. package/dist/commands/exec/worker-chart.d.ts +1 -1
  32. package/dist/commands/runs/list/command.js +136 -33
  33. package/dist/commands/runs/list/metadata.js +22 -18
  34. package/dist/commands/runs/logs/command.js +131 -48
  35. package/dist/commands/runs/logs/metadata.js +24 -20
  36. package/dist/commands/runs/metadata.js +6 -2
  37. package/dist/commands/runs/past-run.d.ts +1 -1
  38. package/dist/commands/runs/past-run.js +1 -1
  39. package/dist/commands/runs/show/command.js +396 -74
  40. package/dist/commands/runs/show/metadata.js +24 -20
  41. package/dist/commands/vitest/command.d.ts +32 -0
  42. package/dist/commands/vitest/command.js +195 -128
  43. package/dist/commands/vitest/metadata.js +45 -37
  44. package/dist/commands/vitest/outcomes.d.ts +16 -0
  45. package/dist/context.d.ts +1 -1
  46. package/dist/core/events.d.ts +1 -1
  47. package/dist/core/payload.d.ts +1 -1
  48. package/dist/core/payload.js +1 -1
  49. package/dist/core/provider.d.ts +12 -2
  50. package/dist/core/run.d.ts +6 -1
  51. package/dist/core/run.js +2 -2
  52. package/dist/live-app.d.ts +9 -0
  53. package/dist/live-app.js +21 -0
  54. package/dist/resource-commands.d.ts +13 -0
  55. package/dist/resource-commands.js +22 -0
  56. package/dist/resources/github/provider.d.ts +1 -1
  57. package/dist/resources/testserver/command-tree.d.ts +4 -0
  58. package/dist/resources/testserver/command-tree.js +12 -0
  59. package/dist/resources/testserver/commands/create/command.js +373 -194
  60. package/dist/resources/testserver/commands/create/metadata.js +52 -48
  61. package/dist/resources/testserver/commands/list/command.js +195 -50
  62. package/dist/resources/testserver/commands/list/metadata.js +12 -8
  63. package/dist/resources/testserver/provider.d.ts +1 -1
  64. package/dist/resources/testserver/resource-provider.js +2 -8
  65. package/dist/resources.d.ts +0 -3
  66. package/dist/resources.js +5 -10
  67. package/dist/runner/index.d.ts +2 -1
  68. package/dist/runner/index.js +1 -0
  69. package/dist/runner/prepare.d.ts +7 -6
  70. package/dist/runner/prepare.js +1 -1
  71. package/dist/runner/ready.d.ts +6 -0
  72. package/dist/runner/ready.js +33 -5
  73. package/dist/runner/recipe.d.ts +33 -6
  74. package/dist/runner/recipe.js +151 -23
  75. package/dist/runner/remote-command.js +1 -1
  76. package/dist/runner/secrets.d.ts +42 -0
  77. package/dist/runner/secrets.js +44 -0
  78. package/dist/runner/snapshot-build.d.ts +5 -2
  79. package/dist/runner/snapshot-build.js +12 -5
  80. package/dist/runner/snapshot-cache.d.ts +3 -3
  81. package/dist/runner/snapshot-cache.js +2 -2
  82. package/dist/runner/snapshot-key.d.ts +19 -12
  83. package/dist/runner/snapshot-key.js +25 -16
  84. package/dist/runner/snapshot-save.d.ts +5 -3
  85. package/dist/runner/snapshot-save.js +7 -5
  86. package/dist/runner/steps.d.ts +6 -1
  87. package/dist/runner/steps.js +5 -2
  88. package/dist/sdk/host.d.ts +2 -0
  89. package/dist/sdk/host.js +7 -0
  90. package/dist/version.d.ts +2 -2
  91. package/dist/version.js +10 -11
  92. package/dist/vitest/config.d.ts +4 -8
  93. package/dist/vitest/config.js +5 -9
  94. package/dist/vitest/container-scope.d.ts +12 -5
  95. package/dist/vitest/container-scope.js +27 -4
  96. package/dist/vitest/diagnostics.d.ts +8 -2
  97. package/dist/vitest/diagnostics.js +7 -4
  98. package/dist/vitest/fixtures.d.ts +4 -1
  99. package/dist/vitest/fixtures.js +17 -6
  100. package/dist/vitest/plan.d.ts +1 -1
  101. package/dist/vitest/plan.js +2 -2
  102. package/dist/vitest/sandbox.d.ts +6 -0
  103. package/dist/vitest/sandbox.js +6 -0
  104. package/package.json +4 -3
  105. package/skills/overview.md +1 -0
  106. package/bin/node-version.js +0 -24
  107. package/dist/closed-terminal.d.ts +0 -7
  108. package/dist/closed-terminal.js +0 -18
@@ -1,13 +1,15 @@
1
1
  // What a runner snapshot is built from, and the scripts that commit a base in a build sandbox and a run's changes in
2
- // a runner sandbox. The snapshot key hashes the steps' text, so editing a step means a new snapshot.
2
+ // a runner sandbox. The snapshot key hashes the steps' text and the names of the runner secrets each gets, so editing
3
+ // a step means a new snapshot.
3
4
  import { createHash } from "node:crypto";
4
5
  import { baseStepContext } from "./base.js";
5
6
  import { resolveSteps } from "./recipe.js";
6
7
  /**
7
8
  * Bump when a runner snapshot changes in a way its steps' text doesn't show (the scripts between the steps, what is
8
- * uploaded, the build sandbox), so earlier snapshots stop matching.
9
+ * uploaded, the build sandbox), or the key's encoding changes, so earlier snapshots stop matching. 2 added each step's
10
+ * runner secret names.
9
11
  */
10
- export const SNAPSHOT_FORMAT = 1;
12
+ export const SNAPSHOT_FORMAT = 2;
11
13
  /** Where the repository lives in every runner and build sandbox. */
12
14
  export const REMOTE_ROOT = "/vercel/sandbox";
13
15
  /** The names of the files uploaded to a sandbox's staging directory. */
@@ -36,7 +38,7 @@ export function bashScript(lines) {
36
38
  }
37
39
  /**
38
40
  * Extracts the base's files from `<staging>/base.tgz` and commits exactly its tracked files
39
- * (`<staging>/base-files`), before the warm steps. `git add -A` would drop tracked files `.gitignore` matches.
41
+ * (`<staging>/base-files`), before the prebuild steps. `git add -A` would drop tracked files `.gitignore` matches.
40
42
  */
41
43
  export function baseIndexScript(base, staging) {
42
44
  const tarball = `${staging}/${STAGED_FILES.baseTarball}`;
@@ -74,34 +76,41 @@ export function applyScript(staging) {
74
76
  ]);
75
77
  }
76
78
  /**
77
- * The snapshot key: sha256 hex over `format=<SNAPSHOT_FORMAT>`, each toolchain step's label and script, the
78
- * base-index script with the placeholders `<base>` and `<staging>`, and each warm step's label and script, joined
79
- * with NUL. The base isn't in the key: a cache entry records it beside the key.
79
+ * The snapshot key: sha256 hex over `format=<SNAPSHOT_FORMAT>`, each toolchain step's label, script and
80
+ * `secrets=<its runner secret names, sorted, joined with ",">`, the base-index script with the placeholders `<base>`
81
+ * and `<staging>`, and each prebuild step's three fields the same way, joined with NUL. Every step gives all three, so a
82
+ * step without runner secrets gives `secrets=`. The names are in the key, never the values: a step that gets another
83
+ * secret may build another snapshot, and every machine with the same recipe shares one. The base isn't in the key: a
84
+ * cache entry records it beside the key.
80
85
  */
81
86
  export function snapshotKey(steps) {
82
- const text = (list) => list.flatMap(({ label, script }) => [label, script]);
87
+ const text = (list) => list.flatMap(({ label, script, secrets }) => [label, script, `secrets=${(secrets ?? []).toSorted().join(",")}`]);
83
88
  return createHash("sha256")
84
89
  .update([
85
90
  `format=${SNAPSHOT_FORMAT}`,
86
91
  ...text(steps.toolchains),
87
92
  baseIndexScript("<base>", "<staging>"),
88
- ...text(steps.warm),
93
+ ...text(steps.prebuild),
89
94
  ].join("\0"))
90
95
  .digest("hex");
91
96
  }
92
- /** Evaluates `recipe`'s toolchain and warm steps at `base` and computes their snapshot key. */
97
+ /**
98
+ * Evaluates `recipe`'s toolchain and prebuild steps at `base`, each step's runner secrets checked against the recipe's
99
+ * `secrets`, and computes their snapshot key.
100
+ */
93
101
  export async function snapshotStepsAt(checkout, request) {
94
102
  const context = baseStepContext(checkout, request);
95
- const toolchains = await resolveSteps(request.recipe.snapshot.toolchains, context);
103
+ const { snapshot, secrets } = request.recipe;
104
+ const toolchains = await resolveSteps(snapshot.toolchains, context, secrets);
96
105
  if (!toolchains.ok)
97
106
  return { ok: false, path: ["snapshot", "toolchains"], problem: toolchains.problem };
98
- const warm = await resolveSteps(request.recipe.snapshot.warm, context);
99
- if (!warm.ok)
100
- return { ok: false, path: ["snapshot", "warm"], problem: warm.problem };
107
+ const prebuild = await resolveSteps(snapshot.prebuild, context, secrets);
108
+ if (!prebuild.ok)
109
+ return { ok: false, path: ["snapshot", "prebuild"], problem: prebuild.problem };
101
110
  return {
102
111
  ok: true,
103
112
  toolchains: toolchains.steps,
104
- warm: warm.steps,
105
- key: snapshotKey({ toolchains: toolchains.steps, warm: warm.steps }),
113
+ prebuild: prebuild.steps,
114
+ key: snapshotKey({ toolchains: toolchains.steps, prebuild: prebuild.steps }),
106
115
  };
107
116
  }
@@ -42,9 +42,11 @@ type BranchSnapshotSave = Exclude<RunnerSave, {
42
42
  * branch's entry in that checkout at that base; the snapshot it replaces is left to expire, since a run on this
43
43
  * machine may be starting from it. Nothing here changes the run's outcome: each way it ends is a note.
44
44
  *
45
- * It searches nothing for the run's secrets: the snapshot keeps what the command wrote to `$HOME` and the ignored
46
- * files, such as a resource's token, as a kept runner sandbox does. The token is limited to one test resource, and
47
- * only a later run on the branch from this checkout, which gets the same token, starts from the snapshot.
45
+ * It searches nothing for the run's secrets: the snapshot keeps what the command and the recipe's steps wrote to
46
+ * `$HOME`, the ignored files and `.git`, as a kept runner sandbox does. A resource's token is limited to one test
47
+ * resource. A runner secret a step that got it left behind is not: the recipe must not leave one, since later steps
48
+ * and commands on the snapshot can read it (`README.md`). Only a later run on the branch from this checkout starts
49
+ * from the snapshot.
48
50
  */
49
51
  export declare function saveBranchSnapshot(context: Pick<RunnerContext, "runnerSandboxes" | "runnerSnapshots" | "clock">, request: SaveBranchSnapshotRequest, control: {
50
52
  readonly scope: RunnerSandboxScope;
@@ -1,7 +1,7 @@
1
1
  // Saving a runner run's runner sandbox as a branch snapshot once its command ended (`--save-snapshot`): reset the
2
2
  // working tree to its base and empty the temp directories, save the sandbox as a runner snapshot, and record it in the
3
- // cache for the run's branch in its checkout. The snapshot keeps the rest of what the command left, a run secret it
4
- // wrote included.
3
+ // cache for the run's branch in its checkout. The snapshot keeps the rest of what the command and the recipe's steps
4
+ // left, a resource's token or a runner secret they wrote included.
5
5
  import { lineSplitter, outputTail, splitLines } from "./output.js";
6
6
  import { SNAPSHOT_EXPIRATION_MS } from "./snapshot-cache.js";
7
7
  import { REMOTE_ROOT, RESET_TO_BASE } from "./snapshot-key.js";
@@ -50,9 +50,11 @@ export function scrubTempScript(directories = TEMP_DIRECTORIES) {
50
50
  * branch's entry in that checkout at that base; the snapshot it replaces is left to expire, since a run on this
51
51
  * machine may be starting from it. Nothing here changes the run's outcome: each way it ends is a note.
52
52
  *
53
- * It searches nothing for the run's secrets: the snapshot keeps what the command wrote to `$HOME` and the ignored
54
- * files, such as a resource's token, as a kept runner sandbox does. The token is limited to one test resource, and
55
- * only a later run on the branch from this checkout, which gets the same token, starts from the snapshot.
53
+ * It searches nothing for the run's secrets: the snapshot keeps what the command and the recipe's steps wrote to
54
+ * `$HOME`, the ignored files and `.git`, as a kept runner sandbox does. A resource's token is limited to one test
55
+ * resource. A runner secret a step that got it left behind is not: the recipe must not leave one, since later steps
56
+ * and commands on the snapshot can read it (`README.md`). Only a later run on the branch from this checkout starts
57
+ * from the snapshot.
56
58
  */
57
59
  export async function saveBranchSnapshot(context, request, control, progress) {
58
60
  const save = await saveOnce(context, request, control, progress);
@@ -1,6 +1,7 @@
1
1
  import type { Clock } from "../time/index.ts";
2
2
  import { type RunnerFailure, type RunnerProgress, type RunnerSandboxCall, type RunnerStage, type RunnerStepPhase } from "./events.ts";
3
3
  import type { RunnerSandbox, RunnerSandboxFailure, RunnerSandboxGateway, RunnerStartFailure } from "./gateways.ts";
4
+ import type { RunnerSecrets } from "./secrets.ts";
4
5
  /** Every step's environment: no Git hook, prompt or update check gets in the way. */
5
6
  export declare const STEP_ENV: Readonly<Record<string, string>>;
6
7
  /**
@@ -21,7 +22,10 @@ export type StepOutcome = {
21
22
  readonly kind: "sandbox-failed";
22
23
  readonly failure: RunnerSandboxFailure;
23
24
  };
24
- /** Runs `script` in `sandbox` with `STEP_ENV` as a step labeled `label`, reporting it under `phase`. */
25
+ /**
26
+ * Runs `script` in `sandbox` as a step labeled `label`, reporting it under `phase`. Its environment is `STEP_ENV` and
27
+ * `secrets`: for a recipe's step, the runner secrets that step names; storm's own steps pass none.
28
+ */
25
29
  export declare function runStep(context: {
26
30
  readonly runnerSandboxes: RunnerSandboxGateway;
27
31
  readonly clock: Clock;
@@ -30,6 +34,7 @@ export declare function runStep(context: {
30
34
  readonly phase: RunnerStepPhase;
31
35
  readonly label: string;
32
36
  readonly script: string;
37
+ readonly secrets?: RunnerSecrets;
33
38
  }, progress: RunnerProgress, signal: AbortSignal): Promise<StepOutcome>;
34
39
  /** A Sandbox failure other than an abort, as the runner reports it. */
35
40
  export declare function sandboxApiFailure(operation: RunnerSandboxCall, failure: Exclude<RunnerStartFailure, {
@@ -9,7 +9,10 @@ export const STEP_ENV = {
9
9
  COREPACK_ENABLE_STRICT: "0",
10
10
  npm_config_update_notifier: "false",
11
11
  };
12
- /** Runs `script` in `sandbox` with `STEP_ENV` as a step labeled `label`, reporting it under `phase`. */
12
+ /**
13
+ * Runs `script` in `sandbox` as a step labeled `label`, reporting it under `phase`. Its environment is `STEP_ENV` and
14
+ * `secrets`: for a recipe's step, the runner secrets that step names; storm's own steps pass none.
15
+ */
13
16
  export async function runStep(context, request, progress, signal) {
14
17
  const { phase, label } = request;
15
18
  const startedAt = context.clock.now().getTime();
@@ -23,7 +26,7 @@ export async function runStep(context, request, progress, signal) {
23
26
  queue.add({ kind: "step-output", phase, stream, line });
24
27
  }
25
28
  };
26
- const ran = await context.runnerSandboxes.runScript(request.sandbox, { script: request.script, env: STEP_ENV }, ({ stream, data }) => emit(stream, splitters[stream].push(data)), signal);
29
+ const ran = await context.runnerSandboxes.runScript(request.sandbox, { script: request.script, env: { ...STEP_ENV, ...request.secrets } }, ({ stream, data }) => emit(stream, splitters[stream].push(data)), signal);
27
30
  emit("stdout", splitters.stdout.flush());
28
31
  emit("stderr", splitters.stderr.flush());
29
32
  await queue.flush();
@@ -0,0 +1,2 @@
1
+ export { parseTestEvent, RUN_PAYLOAD_VARIABLE, type RunPayload, type RunPayloadGitHubFixtureRepo, type RunPayloadResources, type TestEvent, testEventLine, type TestResultEvent, type WorkerTestEvent, } from "./payload/index.ts";
2
+ export { redactSecrets } from "./records/index.ts";
@@ -0,0 +1,7 @@
1
+ // The SDK's narrow entry for storm's host: what storm's own modules and commands use of the SDK, from the run payload
2
+ // and the records, and nothing that starts containers, seeds data, or proxies requests. The full surface
3
+ // (`index.ts`) loads `node:http`, `node:https`, and the container, factory, seed, and proxy modules, which cost every
4
+ // storm command ~15ms though only a command running under a storm run uses them. It is not a published export:
5
+ // commands, the Vitest adapter, and the Vercel CLI driver import `index.ts`, `@vercel/storm/sdk`.
6
+ export { parseTestEvent, RUN_PAYLOAD_VARIABLE, testEventLine, } from "./payload/index.js";
7
+ export { redactSecrets } from "./records/index.js";
package/dist/version.d.ts CHANGED
@@ -8,8 +8,8 @@ export declare function commitText(commit: GitCommit): string;
8
8
  /** The version as root `--version` and a run print it: `0.0.1 (3f2a9c1b7d4e)`, or `0.0.1` with no commit. */
9
9
  export declare function versionText(version: string, commit: string | null): string;
10
10
  /**
11
- * Reads the commit checked out in `directory` from git (`git rev-parse HEAD`, then `git status --porcelain`).
12
- * Any failure, git missing or `directory` outside a git worktree, gives `undefined`.
11
+ * Reads the commit checked out in `directory` from git (`git rev-parse HEAD` and `git status --porcelain`, at the
12
+ * same time). Any failure, git missing or `directory` outside a git worktree, gives `undefined`.
13
13
  */
14
14
  export declare function readGitCommit(directory: string): Promise<GitCommit | undefined>;
15
15
  /**
package/dist/version.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // The version line: storm's version and the git commit it was built from. `scripts/write-build-info.js` stamps
2
2
  // the commit into `dist/build-info.js` at build time; running from source in the cnc workspace, storm reads it
3
- // from git at startup.
3
+ // from git, only when root `--version` prints it or a command builds the app.
4
4
  var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
5
5
  if (typeof path === "string" && /^\.\.?\//.test(path)) {
6
6
  return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
@@ -21,20 +21,19 @@ export function versionText(version, commit) {
21
21
  return commit === null ? version : `${version} (${commit})`;
22
22
  }
23
23
  /**
24
- * Reads the commit checked out in `directory` from git (`git rev-parse HEAD`, then `git status --porcelain`).
25
- * Any failure, git missing or `directory` outside a git worktree, gives `undefined`.
24
+ * Reads the commit checked out in `directory` from git (`git rev-parse HEAD` and `git status --porcelain`, at the
25
+ * same time). Any failure, git missing or `directory` outside a git worktree, gives `undefined`.
26
26
  */
27
27
  export async function readGitCommit(directory) {
28
28
  const git = async (...args) => (await promisify(execFile)("git", args, { cwd: directory, encoding: "utf8" })).stdout;
29
- try {
30
- const sha = (await git("rev-parse", "HEAD")).trim();
31
- if (!/^[0-9a-f]{40,64}$/.test(sha))
32
- return undefined;
33
- return { sha, dirty: (await git("status", "--porcelain")).trim() !== "" };
34
- }
35
- catch {
29
+ // Both finish before this returns, even when one fails, so no git process outlives the call.
30
+ const [head, status] = await Promise.allSettled([git("rev-parse", "HEAD"), git("status", "--porcelain")]);
31
+ if (head.status === "rejected" || status.status === "rejected")
36
32
  return undefined;
37
- }
33
+ const sha = head.value.trim();
34
+ if (!/^[0-9a-f]{40,64}$/.test(sha))
35
+ return undefined;
36
+ return { sha, dirty: status.value.trim() !== "" };
38
37
  }
39
38
  /**
40
39
  * The commit storm was built from, as the version line shows it. `binUrl` is the `import.meta.url` of
@@ -1,16 +1,12 @@
1
1
  import { type StormReporter } from "./test-results.ts";
2
2
  export type { ReportedConsoleLog, ReportedTestCase, ReportedTestError, ReportedTestModule, StormReporter, } from "./test-results.ts";
3
- /**
4
- * The vitest workers per Testserver sandbox `testserverWorkers` sizes for by default: about the number of
5
- * concurrent test ids a Testserver sandbox serves before its service boots slow down.
6
- */
7
- export declare const WORKERS_PER_SANDBOX = 4;
3
+ export { WORKERS_PER_SANDBOX } from "./sandbox.ts";
8
4
  /**
9
5
  * A vitest `retry` for a testserver project: one more attempt for a test that failed because a Testserver call's
10
6
  * connection failed (`TESTSERVER_CONNECTION_FAILURE`), such as a `read ECONNRESET` between the runner and the
11
- * Testserver URL, and none for any other failure. The adapter ends a file's container when a test fails, so the retry
12
- * runs on a new container, where a factory call that half-happened on the old one can't collide with it. vitest's
13
- * own output marks a test it rescued `(retry x1)`. Spread it to change the count:
7
+ * Testserver URL, and none for any other failure. The adapter ends a file's container after a test whose factory call
8
+ * or API request failed, so the retry runs on a new container, where a factory call that half-happened on the old one
9
+ * can't collide with it. vitest's own output marks a test it rescued `(retry x1)`. Spread it to change the count:
14
10
  * `retry: { ...testserverConnectionRetry, count: 2 }`.
15
11
  */
16
12
  export declare const testserverConnectionRetry: {
@@ -2,19 +2,15 @@
2
2
  // this, never `@vercel/storm/vitest`: loading the adapter's `test` extends vitest's, which throws inside a config
3
3
  // file. So nothing here imports `./fixtures.ts` or vitest.
4
4
  import { readRunPayload, RUN_PAYLOAD_VARIABLE, TESTSERVER_CONNECTION_FAILURE } from "../sdk/index.js";
5
- import { sandboxCount } from "./sandbox.js";
5
+ import { sandboxCount, WORKERS_PER_SANDBOX } from "./sandbox.js";
6
6
  import { testResultReporter } from "./test-results.js";
7
- /**
8
- * The vitest workers per Testserver sandbox `testserverWorkers` sizes for by default: about the number of
9
- * concurrent test ids a Testserver sandbox serves before its service boots slow down.
10
- */
11
- export const WORKERS_PER_SANDBOX = 4;
7
+ export { WORKERS_PER_SANDBOX } from "./sandbox.js";
12
8
  /**
13
9
  * A vitest `retry` for a testserver project: one more attempt for a test that failed because a Testserver call's
14
10
  * connection failed (`TESTSERVER_CONNECTION_FAILURE`), such as a `read ECONNRESET` between the runner and the
15
- * Testserver URL, and none for any other failure. The adapter ends a file's container when a test fails, so the retry
16
- * runs on a new container, where a factory call that half-happened on the old one can't collide with it. vitest's
17
- * own output marks a test it rescued `(retry x1)`. Spread it to change the count:
11
+ * Testserver URL, and none for any other failure. The adapter ends a file's container after a test whose factory call
12
+ * or API request failed, so the retry runs on a new container, where a factory call that half-happened on the old one
13
+ * can't collide with it. vitest's own output marks a test it rescued `(retry x1)`. Spread it to change the count:
18
14
  * `retry: { ...testserverConnectionRetry, count: 2 }`.
19
15
  */
20
16
  export const testserverConnectionRetry = {
@@ -1,7 +1,8 @@
1
1
  import type { Container, ServiceWarmup, TestserverServiceId } from "../sdk/index.ts";
2
2
  /**
3
3
  * How long the Vitest adapter's container lives: `'file'`, one container shared by a test file's tests and replaced
4
- * after a failed test or for a test with different feature flags, or `'test'`, one per test.
4
+ * after a test that failed because of a Testserver failure (`endsSharedContainer`) or for a test with different
5
+ * feature flags, or `'test'`, one per test.
5
6
  */
6
7
  export type ContainerScope = "file" | "test";
7
8
  /** The default container scope: a test file's tests share one container. */
@@ -64,6 +65,11 @@ export interface ContainerRequest<C extends SharedContainer> {
64
65
  readonly isConcurrent: boolean;
65
66
  /** Whether the test has failed so far: its body or `afterEach`, when asked in the fixture's cleanup. */
66
67
  readonly failed: () => boolean;
68
+ /**
69
+ * Whether a fixture saw Testserver fail the test in a way the container's own records don't hold, such as a
70
+ * request a fault rule on the test's proxy forwarded, asked in the failure handler.
71
+ */
72
+ readonly testserverFailed: () => boolean;
67
73
  /** The canonical key of the test's feature flags (`featureFlagsKey`), which the file's container must match. */
68
74
  readonly featureFlagsKey: string;
69
75
  /** Starts the file's container, in `'file'` scope, saying whether it replaces one with other feature flags. */
@@ -84,10 +90,11 @@ export interface ContainerRequest<C extends SharedContainer> {
84
90
  * flags differ from the test's. A test that aborts while it is starting never gets it, but the container stays the
85
91
  * file's, for its next test. A test handed a container an
86
92
  * earlier test used notes its container log's last record, so its report can print only the records after it.
87
- * After a failed test, the container log is read and the container ended in the test's failure handler, which
88
- * Vitest awaits even when a fixture's cleanup throws, so the next test that asks starts a new one; the failure
89
- * report covers only this test's factory calls, API requests and container log, and says whether ending the
90
- * container succeeded. A concurrent test can't share the file's container, and fails before anything starts.
93
+ * After a failed test, the test's failure handler, which Vitest awaits even when a fixture's cleanup throws, reads
94
+ * the container log, then ends the container when the failure may come from it (`endsSharedContainer`), so the next
95
+ * test that asks starts a new one, and otherwise keeps it for the next test. The failure report covers only this
96
+ * test's factory calls, API requests and container log, and says whether the container was kept, ended, or failed to
97
+ * end. A concurrent test can't share the file's container, and fails before anything starts.
91
98
  */
92
99
  export declare function provideContainer<C extends SharedContainer>(request: ContainerRequest<C>): Promise<C>;
93
100
  /**
@@ -96,10 +96,11 @@ export class FileContainer {
96
96
  * flags differ from the test's. A test that aborts while it is starting never gets it, but the container stays the
97
97
  * file's, for its next test. A test handed a container an
98
98
  * earlier test used notes its container log's last record, so its report can print only the records after it.
99
- * After a failed test, the container log is read and the container ended in the test's failure handler, which
100
- * Vitest awaits even when a fixture's cleanup throws, so the next test that asks starts a new one; the failure
101
- * report covers only this test's factory calls, API requests and container log, and says whether ending the
102
- * container succeeded. A concurrent test can't share the file's container, and fails before anything starts.
99
+ * After a failed test, the test's failure handler, which Vitest awaits even when a fixture's cleanup throws, reads
100
+ * the container log, then ends the container when the failure may come from it (`endsSharedContainer`), so the next
101
+ * test that asks starts a new one, and otherwise keeps it for the next test. The failure report covers only this
102
+ * test's factory calls, API requests and container log, and says whether the container was kept, ended, or failed to
103
+ * end. A concurrent test can't share the file's container, and fails before anything starts.
103
104
  */
104
105
  export async function provideContainer(request) {
105
106
  const { signal, onCleanup, onTestFailed, report } = request;
@@ -130,6 +131,11 @@ export async function provideContainer(request) {
130
131
  const before = { factoryCalls: container.factoryCalls.length, apiRequests: container.apiRequests.length };
131
132
  onTestFailed(async () => {
132
133
  const log = await readLog(container, (records) => sliceAfter(records, note));
134
+ const testserverFailed = request.testserverFailed();
135
+ if (!endsSharedContainer({ container, before, log, aborted: signal.aborted, testserverFailed })) {
136
+ report(sharedContainerFailureReport(reportOf(container), before, log, { kind: "kept" }));
137
+ return;
138
+ }
133
139
  try {
134
140
  await fileContainer.discard(container);
135
141
  }
@@ -141,6 +147,23 @@ export async function provideContainer(request) {
141
147
  });
142
148
  return container;
143
149
  }
150
+ /**
151
+ * Whether a failed test's failure may come from the file's container, so `'file'` scope ends the container rather
152
+ * than hand it to the file's next test. It reads what the adapter recorded of the test, never the test's errors: the
153
+ * test was aborted (a timeout aborts it); one of the factory calls or API requests it made, those after the counts in
154
+ * `before`, failed, whether the test caught the error or not; a fixture saw Testserver fail the test
155
+ * (`testserverFailed`, `ContainerRequest.testserverFailed`), as `proxy` does when a fault rule forwarded a request and
156
+ * Testserver failed; or the failure handler couldn't read the container log. Any other failure, such as a failed
157
+ * assertion or an error the test threw, says nothing about the container.
158
+ */
159
+ function endsSharedContainer(test) {
160
+ const { container, before } = test;
161
+ return (test.aborted ||
162
+ test.testserverFailed ||
163
+ test.log.kind === "unreadable" ||
164
+ container.factoryCalls.slice(before.factoryCalls).some((call) => !call.outcome.ok) ||
165
+ container.apiRequests.slice(before.apiRequests).some((request) => request.error !== undefined));
166
+ }
144
167
  /** Notes the last record of a reused container's log. A read that fails is noted, not thrown: the test runs on. */
145
168
  async function noteLog(container) {
146
169
  try {
@@ -86,8 +86,13 @@ export declare function containerFailureReport(report: ContainerReport): string;
86
86
  * `all: env-var-config-secret-ui=true; team: x="y"`; `undefined` for none.
87
87
  */
88
88
  export declare function describeFeatureFlags(flags: FeatureFlags): string | undefined;
89
- /** Whether ending a shared container after a failed test succeeded, and why it failed if not. */
89
+ /**
90
+ * What became of a shared container after a failed test: `kept` for the file's next test, since the failure said
91
+ * nothing about the container, `ended`, or `failed` to end, with why.
92
+ */
90
93
  export type SharedContainerEnding = {
94
+ readonly kind: "kept";
95
+ } | {
91
96
  readonly kind: "ended";
92
97
  } | {
93
98
  readonly kind: "failed";
@@ -96,7 +101,8 @@ export type SharedContainerEnding = {
96
101
  /**
97
102
  * What a failed test prints about the container its file's tests share: `containerFailureReport` over only the
98
103
  * factory calls and API requests the test made, those after the counts in `before`, and a line saying the
99
- * container is shared, how many of each earlier tests made, and whether ending it after this failure succeeded.
104
+ * container is shared, how many of each earlier tests made, and whether it was kept for the file's next test, or
105
+ * ended after this failure, or failed to end.
100
106
  */
101
107
  export declare function sharedContainerFailureReport(container: Omit<ContainerReport, "log">, before: {
102
108
  readonly factoryCalls: number;
@@ -193,7 +193,8 @@ function countFeatureFlags(flags) {
193
193
  /**
194
194
  * What a failed test prints about the container its file's tests share: `containerFailureReport` over only the
195
195
  * factory calls and API requests the test made, those after the counts in `before`, and a line saying the
196
- * container is shared, how many of each earlier tests made, and whether ending it after this failure succeeded.
196
+ * container is shared, how many of each earlier tests made, and whether it was kept for the file's next test, or
197
+ * ended after this failure, or failed to end.
197
198
  */
198
199
  export function sharedContainerFailureReport(container, before, log, ending) {
199
200
  const own = containerFailureReport({
@@ -211,9 +212,11 @@ export function sharedContainerFailureReport(container, before, log, ending) {
211
212
  : [`${before.apiRequests} API ${before.apiRequests === 1 ? "request" : "requests"}`]),
212
213
  ];
213
214
  const earlier = counts.length === 0 ? "" : `, after ${counts.join(" and ")} by earlier tests`;
214
- const end = ending.kind === "ended"
215
- ? "ended after this failure"
216
- : `ending it after this failure failed: ${container.redact(ending.message)}`;
215
+ const end = ending.kind === "kept"
216
+ ? "kept for the file's next test (not a Testserver failure)"
217
+ : ending.kind === "ended"
218
+ ? "ended after this failure"
219
+ : `ending it after this failure failed: ${container.redact(ending.message)}`;
217
220
  return `${own}\n(container shared by this file's tests${earlier}; ${end})`;
218
221
  }
219
222
  /**
@@ -42,7 +42,10 @@ declare module "vitest" {
42
42
  * or `describe` with `test.override({ featureFlags })`; a value replaces the whole object. In `'file'` scope, a
43
43
  * test whose feature flags differ from those of the file's container ends it and starts a new one.
44
44
  * - `container`: in `'file'` scope, the file's container, labeled with the file's path, started by the file's first
45
- * test that asks for it and ended after a failed test that used it, so the next test that asks starts a new one.
45
+ * test that asks for it. A failed test that used it ends it when its failure may come from the container, such as
46
+ * a failed factory call or API request, a fault rule's forwarded request Testserver failed, or a timeout, so the
47
+ * next test that asks starts a new one, and leaves it for the next test otherwise, such as after a failed
48
+ * assertion.
46
49
  * A concurrent test fails instead. In `'test'` scope, a container started for the test, labeled with the test's
47
50
  * name, and ended after it. The test's `task.meta.storm` records the Testserver URL and, once the test has the
48
51
  * container, its test id.
@@ -56,10 +56,14 @@ const fixtures = vitestTest
56
56
  onCleanup(() => closeFile(file.container, file.acquisitions));
57
57
  return file;
58
58
  })
59
+ // Per test: whether a fixture saw Testserver fail the test in a way the container's own records don't hold, which
60
+ // the container's failure handler reads. `proxy` sets it; vitest sets it up again for each attempt.
61
+ // oxlint-disable-next-line no-empty-pattern -- vitest requires a fixture to destructure its first argument
62
+ .extend("stormTestserverFailure", ({}) => ({ failed: false }))
59
63
  .extend("containerScope", CONTAINER_SCOPE)
60
64
  .extend("warmServices", NO_SERVICES)
61
65
  .extend("featureFlags", NO_FEATURE_FLAGS)
62
- .extend("container", async ({ containerScope, warmServices, featureFlags, stormFile, stormEvents, testserverUrl, verbose, task, signal, onTestFailed, }, { onCleanup }) => {
66
+ .extend("container", async ({ containerScope, warmServices, featureFlags, stormFile, stormTestserverFailure, stormEvents, testserverUrl, verbose, task, signal, onTestFailed, }, { onCleanup }) => {
63
67
  // Starts a container labeled `name` with `featureFlags`, then warms `warmServices`, both the start's test's, in
64
68
  // it, reporting both as one container start. Under a verbose run, each container start prints as it ends, for
65
69
  // passing tests too, saying when it replaced the file's container because the feature flags differ.
@@ -88,6 +92,7 @@ const fixtures = vitestTest
88
92
  onTestFailed,
89
93
  isConcurrent: task.concurrent === true,
90
94
  failed: () => task.result?.state === "fail",
95
+ testserverFailed: () => stormTestserverFailure.failed,
91
96
  featureFlagsKey: featureFlagsKey(featureFlags),
92
97
  startShared: (replacing) => startWarmed("file", task.file.name, replacing),
93
98
  startOwn: () => startWarmed("test", task.name),
@@ -97,19 +102,22 @@ const fixtures = vitestTest
97
102
  return container;
98
103
  })
99
104
  .extend("seed", ({ container }) => seeder(container))
100
- .extend("proxy", async ({ container, stormFile, verbose, signal, onTestFailed }, { onCleanup }) => {
105
+ .extend("proxy", async ({ container, stormFile, stormTestserverFailure, verbose, signal, onTestFailed }, { onCleanup }) => {
101
106
  // Under a verbose run, each request prints as the proxy records it, for passing tests too.
102
107
  const onRequest = verbose
103
108
  ? (record) => console.error(proxyRequestReport(container.testId, record, (text) => container.redact(text)))
104
109
  : undefined;
105
110
  const proxy = await stormFile.acquisitions.track(signal, acquireOwned(signal, onCleanup, () => startProxy({ container, ...(onRequest === undefined ? {} : { onRequest }) }),
106
111
  // Checked once closed, when every record has ended: a test whose fault rule forwarded a request Testserver
107
- // failed fails, since its premise, what Testserver answered, never held.
112
+ // failed fails, since its premise, what Testserver answered, never held, and in `'file'` scope ends the
113
+ // file's container.
108
114
  async (owned) => {
109
115
  await owned.close();
110
116
  const failure = faultUpstreamFailure(owned.requests, (text) => owned.redact(text));
111
- if (failure !== undefined)
112
- throw new Error(failure);
117
+ if (failure === undefined)
118
+ return;
119
+ stormTestserverFailure.failed = true;
120
+ throw new Error(failure);
113
121
  }));
114
122
  onTestFailed(() => {
115
123
  console.error(proxyFailureReport(container.testId, proxy.requests, (text) => proxy.redact(text), proxy.faults));
@@ -147,7 +155,10 @@ const fixtures = vitestTest
147
155
  * or `describe` with `test.override({ featureFlags })`; a value replaces the whole object. In `'file'` scope, a
148
156
  * test whose feature flags differ from those of the file's container ends it and starts a new one.
149
157
  * - `container`: in `'file'` scope, the file's container, labeled with the file's path, started by the file's first
150
- * test that asks for it and ended after a failed test that used it, so the next test that asks starts a new one.
158
+ * test that asks for it. A failed test that used it ends it when its failure may come from the container, such as
159
+ * a failed factory call or API request, a fault rule's forwarded request Testserver failed, or a timeout, so the
160
+ * next test that asks starts a new one, and leaves it for the next test otherwise, such as after a failed
161
+ * assertion.
151
162
  * A concurrent test fails instead. In `'test'` scope, a container started for the test, labeled with the test's
152
163
  * name, and ended after it. The test's `task.meta.storm` records the Testserver URL and, once the test has the
153
164
  * container, its test id.
@@ -2,7 +2,7 @@ import type { VitestListFailure, VitestListGateway } from "./gateways.ts";
2
2
  export { VITEST_BIN, vitestSearchDirectories } from "./find-vitest.ts";
3
3
  export type { FindVitestRequest, FindVitestResult, ListedTest, VitestListFailure, VitestListGateway, VitestListRequest, VitestListResult, } from "./gateways.ts";
4
4
  export { liveVitestListGateway } from "./live/list-gateway.ts";
5
- export { WORKERS_PER_SANDBOX } from "./config.ts";
5
+ export { WORKERS_PER_SANDBOX } from "./sandbox.ts";
6
6
  /** How long `listVitestTests` lets `vitest list` run by default. */
7
7
  export declare const LIST_TIMEOUT_MS = 60000;
8
8
  /** How many tests a Vitest run would run, and in how many files. */
@@ -3,12 +3,12 @@
3
3
  // for them, and the `vitest run` argv. It is the adapter's one entry point for the CLI: `storm vitest` imports it
4
4
  // and nothing else of the adapter. Like `config.ts`, it imports neither `./fixtures.ts` nor vitest: the CLI and a
5
5
  // launcher script run outside a Vitest run, where the adapter's `test` throws.
6
- import { WORKERS_PER_SANDBOX } from "./config.js";
6
+ import { WORKERS_PER_SANDBOX } from "./sandbox.js";
7
7
  import { readVitestList } from "./list-output.js";
8
8
  import { liveVitestListGateway } from "./live/list-gateway.js";
9
9
  export { VITEST_BIN, vitestSearchDirectories } from "./find-vitest.js";
10
10
  export { liveVitestListGateway } from "./live/list-gateway.js";
11
- export { WORKERS_PER_SANDBOX } from "./config.js";
11
+ export { WORKERS_PER_SANDBOX } from "./sandbox.js";
12
12
  /** How long `listVitestTests` lets `vitest list` run by default. */
13
13
  export const LIST_TIMEOUT_MS = 60_000;
14
14
  /**
@@ -1,4 +1,10 @@
1
1
  import type { RunPayload } from "../sdk/index.ts";
2
+ /**
3
+ * The vitest workers per Testserver sandbox `testserverWorkers` sizes for by default: about the number of
4
+ * concurrent test ids a Testserver sandbox serves before its service boots slow down. It lives here, not in
5
+ * `config.ts`, so `plan.ts`, which the CLI loads, reads it without loading the SDK's run payload reader.
6
+ */
7
+ export declare const WORKERS_PER_SANDBOX = 4;
2
8
  /** What a test that needs a Testserver sandbox fails with in a run that holds none. */
3
9
  export declare const NO_TESTSERVER_MESSAGE = "this run has no Testserver; add resources.testserverPool to storm.config.ts or pass --testserver-sandboxes <n>";
4
10
  /**
@@ -1,5 +1,11 @@
1
1
  // Which Testserver sandbox a vitest worker uses, and how many Testserver sandboxes a run counts for sizing workers.
2
2
  // Pure: no vitest import, so `config.ts`, which a `vitest.config.ts` loads, can use it.
3
+ /**
4
+ * The vitest workers per Testserver sandbox `testserverWorkers` sizes for by default: about the number of
5
+ * concurrent test ids a Testserver sandbox serves before its service boots slow down. It lives here, not in
6
+ * `config.ts`, so `plan.ts`, which the CLI loads, reads it without loading the SDK's run payload reader.
7
+ */
8
+ export const WORKERS_PER_SANDBOX = 4;
3
9
  /** What a test that needs a Testserver sandbox fails with in a run that holds none. */
4
10
  export const NO_TESTSERVER_MESSAGE = "this run has no Testserver; add resources.testserverPool to storm.config.ts or pass --testserver-sandboxes <n>";
5
11
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cnc-tools/storm",
3
- "version": "0.8.1",
3
+ "version": "0.9.1",
4
4
  "description": "Run a command against Vercel Testserver sandboxes",
5
5
  "repository": {
6
6
  "type": "git",
@@ -90,13 +90,14 @@
90
90
  "registry": "https://registry.npmjs.org/"
91
91
  },
92
92
  "dependencies": {
93
- "@vercel/clinkr": "npm:clinkr@^0.10.0",
93
+ "@vercel/clinkr": "npm:clinkr@^0.10.1",
94
94
  "@vercel/sandbox": "3.9.0",
95
95
  "zod": "^4.6.5"
96
96
  },
97
97
  "devDependencies": {
98
98
  "@types/node": "^24.19.1",
99
99
  "@xterm/headless": "^6.0.0",
100
+ "esbuild": "^0.27.7",
100
101
  "typescript": "^7.0.2",
101
102
  "typescript-5": "npm:typescript@5.9.3",
102
103
  "vitest": "4.1.10"
@@ -113,7 +114,7 @@
113
114
  "node": ">=22.19.0"
114
115
  },
115
116
  "scripts": {
116
- "build": "tsc -p tsconfig.build.json && node scripts/write-build-info.js",
117
+ "build": "tsc -p tsconfig.build.json && node scripts/bundle.js && node scripts/write-build-info.js",
117
118
  "typecheck": "tsc --noEmit && tsc -p tsconfig.sdk.json",
118
119
  "test": "pnpm run test:default && pnpm run test:integration",
119
120
  "test:default": "vitest run --project default --project sanity",
@@ -19,6 +19,7 @@ commands: all
19
19
  - A run is **active** while it goes on. A run is **finished** when it has ended and saved its test results. `runs show` shows test results only for a finished run.
20
20
  - A **test result** is the final result of one test: `pass`, `fail` or `skip`, with its errors. The command saves test results only with the Vitest adapter's `stormReporter`.
21
21
  - **Test output** is what one test printed to the console, stdout and stderr together. storm keeps the last 8 MiB of the test output of each test. `droppedChars` counts the characters that storm did not keep.
22
+ - A **runner secret** is a variable in your environment that the `secrets` key of the runner recipe declares, such as an npm token for a private package. A runner run reads it on the machine that starts the run. The run does not start when the variable is not set, is empty, holds a line break or has fewer than 8 characters. A step of the recipe gets the variable only when the `secrets` key of that step names it. The command does not get it. storm shows the value as `<token>` in all that it prints and writes. storm does not write the value to a file. A step can leave the value in the sandbox, and a runner snapshot then keeps it. Do not let a step leave the value.
22
23
  - A **run log** is a log in the run directory. The **command log** (`command`) holds all the output of the command. It also holds output that no test owns: output from a `beforeAll`, a global setup, a raw `process.stdout.write`, or a child process. A **step log** (`install`, `build`, `apply`, `snapshot`) holds the output of one step of a runner run.
23
24
 
24
25
  ## Commands