@cnc-tools/storm 0.8.1 → 0.9.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.
- package/dist/build-info.js +1 -1
- package/dist/commands/exec/command.d.ts +32 -0
- package/dist/commands/exec/metadata.js +1 -1
- package/dist/commands/exec/outcomes.d.ts +67 -0
- package/dist/commands/exec/outcomes.js +50 -0
- package/dist/commands/exec/run-command.d.ts +17 -11
- package/dist/commands/exec/run-command.js +33 -16
- package/dist/commands/vitest/command.d.ts +32 -0
- package/dist/commands/vitest/outcomes.d.ts +16 -0
- package/dist/core/run.d.ts +6 -1
- package/dist/core/run.js +1 -1
- package/dist/runner/index.d.ts +2 -1
- package/dist/runner/index.js +1 -0
- package/dist/runner/prepare.d.ts +7 -6
- package/dist/runner/prepare.js +1 -1
- package/dist/runner/ready.d.ts +6 -0
- package/dist/runner/ready.js +33 -5
- package/dist/runner/recipe.d.ts +33 -6
- package/dist/runner/recipe.js +150 -22
- package/dist/runner/secrets.d.ts +42 -0
- package/dist/runner/secrets.js +44 -0
- package/dist/runner/snapshot-build.d.ts +5 -2
- package/dist/runner/snapshot-build.js +12 -5
- package/dist/runner/snapshot-cache.d.ts +3 -3
- package/dist/runner/snapshot-cache.js +2 -2
- package/dist/runner/snapshot-key.d.ts +19 -12
- package/dist/runner/snapshot-key.js +25 -16
- package/dist/runner/snapshot-save.d.ts +5 -3
- package/dist/runner/snapshot-save.js +7 -5
- package/dist/runner/steps.d.ts +6 -1
- package/dist/runner/steps.js +5 -2
- package/package.json +1 -1
- package/skills/overview.md +1 -0
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { CheckoutGateway } from "./gateways.ts";
|
|
2
|
-
import { type
|
|
2
|
+
import { type CheckedRecipe, type ResolvedRunnerStep, type RunnerStep } from "./recipe.ts";
|
|
3
3
|
/**
|
|
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
|
-
* uploaded, the build sandbox), so earlier snapshots stop matching.
|
|
5
|
+
* uploaded, the build sandbox), or the key's encoding changes, so earlier snapshots stop matching. 2 added each step's
|
|
6
|
+
* runner secret names.
|
|
6
7
|
*/
|
|
7
|
-
export declare const SNAPSHOT_FORMAT =
|
|
8
|
+
export declare const SNAPSHOT_FORMAT = 2;
|
|
8
9
|
/** Where the repository lives in every runner and build sandbox. */
|
|
9
10
|
export declare const REMOTE_ROOT = "/vercel/sandbox";
|
|
10
11
|
/** The names of the files uploaded to a sandbox's staging directory. */
|
|
@@ -25,7 +26,7 @@ export declare const RESET_TO_BASE: readonly string[];
|
|
|
25
26
|
export declare function bashScript(lines: readonly string[]): string;
|
|
26
27
|
/**
|
|
27
28
|
* Extracts the base's files from `<staging>/base.tgz` and commits exactly its tracked files
|
|
28
|
-
* (`<staging>/base-files`), before the
|
|
29
|
+
* (`<staging>/base-files`), before the prebuild steps. `git add -A` would drop tracked files `.gitignore` matches.
|
|
29
30
|
*/
|
|
30
31
|
export declare function baseIndexScript(base: string, staging: string): string;
|
|
31
32
|
/**
|
|
@@ -36,28 +37,34 @@ export declare function baseIndexScript(base: string, staging: string): string;
|
|
|
36
37
|
*/
|
|
37
38
|
export declare function applyScript(staging: string): string;
|
|
38
39
|
/**
|
|
39
|
-
* The snapshot key: sha256 hex over `format=<SNAPSHOT_FORMAT>`, each toolchain step's label
|
|
40
|
-
* base-index script with the placeholders `<base>`
|
|
41
|
-
*
|
|
40
|
+
* The snapshot key: sha256 hex over `format=<SNAPSHOT_FORMAT>`, each toolchain step's label, script and
|
|
41
|
+
* `secrets=<its runner secret names, sorted, joined with ",">`, the base-index script with the placeholders `<base>`
|
|
42
|
+
* and `<staging>`, and each prebuild step's three fields the same way, joined with NUL. Every step gives all three, so a
|
|
43
|
+
* step without runner secrets gives `secrets=`. The names are in the key, never the values: a step that gets another
|
|
44
|
+
* secret may build another snapshot, and every machine with the same recipe shares one. The base isn't in the key: a
|
|
45
|
+
* cache entry records it beside the key.
|
|
42
46
|
*/
|
|
43
47
|
export declare function snapshotKey(steps: {
|
|
44
48
|
readonly toolchains: readonly RunnerStep[];
|
|
45
|
-
readonly
|
|
49
|
+
readonly prebuild: readonly RunnerStep[];
|
|
46
50
|
}): string;
|
|
47
51
|
/** A recipe's snapshot steps at one base and their key, or the step key whose function failed there and why. */
|
|
48
52
|
export type SnapshotStepsAt = {
|
|
49
53
|
readonly ok: true;
|
|
50
|
-
readonly toolchains: readonly
|
|
51
|
-
readonly
|
|
54
|
+
readonly toolchains: readonly ResolvedRunnerStep[];
|
|
55
|
+
readonly prebuild: readonly ResolvedRunnerStep[];
|
|
52
56
|
readonly key: string;
|
|
53
57
|
} | {
|
|
54
58
|
readonly ok: false;
|
|
55
59
|
readonly path: readonly string[];
|
|
56
60
|
readonly problem: string;
|
|
57
61
|
};
|
|
58
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* Evaluates `recipe`'s toolchain and prebuild steps at `base`, each step's runner secrets checked against the recipe's
|
|
64
|
+
* `secrets`, and computes their snapshot key.
|
|
65
|
+
*/
|
|
59
66
|
export declare function snapshotStepsAt(checkout: CheckoutGateway, request: {
|
|
60
67
|
readonly repoRoot: string;
|
|
61
68
|
readonly base: string;
|
|
62
|
-
readonly recipe: Pick<
|
|
69
|
+
readonly recipe: Pick<CheckedRecipe, "snapshot" | "secrets">;
|
|
63
70
|
}): Promise<SnapshotStepsAt>;
|
|
@@ -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
|
|
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 =
|
|
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
|
|
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
|
|
78
|
-
* base-index script with the placeholders `<base>`
|
|
79
|
-
*
|
|
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.
|
|
93
|
+
...text(steps.prebuild),
|
|
89
94
|
].join("\0"))
|
|
90
95
|
.digest("hex");
|
|
91
96
|
}
|
|
92
|
-
/**
|
|
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
|
|
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
|
|
99
|
-
if (!
|
|
100
|
-
return { ok: false, path: ["snapshot", "
|
|
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
|
-
|
|
105
|
-
key: snapshotKey({ toolchains: toolchains.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
|
|
46
|
-
*
|
|
47
|
-
*
|
|
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
|
|
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
|
|
54
|
-
*
|
|
55
|
-
*
|
|
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);
|
package/dist/runner/steps.d.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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, {
|
package/dist/runner/steps.js
CHANGED
|
@@ -9,7 +9,10 @@ export const STEP_ENV = {
|
|
|
9
9
|
COREPACK_ENABLE_STRICT: "0",
|
|
10
10
|
npm_config_update_notifier: "false",
|
|
11
11
|
};
|
|
12
|
-
/**
|
|
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();
|
package/package.json
CHANGED
package/skills/overview.md
CHANGED
|
@@ -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
|