@cnc-tools/storm 0.12.0 → 0.13.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 (96) hide show
  1. package/dist/bin/storm.js +1 -1
  2. package/dist/build-info.js +1 -1
  3. package/dist/chunks/{chunk-4XT5RC5T.js → chunk-2NZXL6OH.js} +6 -42
  4. package/dist/chunks/{chunk-ISGQJIQM.js → chunk-5UMJNVKT.js} +1 -1
  5. package/dist/chunks/{chunk-FSP3SJ35.js → chunk-6EQKA7LI.js} +16 -46
  6. package/dist/chunks/{chunk-Y3BUNNRG.js → chunk-AX4EQZUS.js} +4 -4
  7. package/dist/chunks/{chunk-RYRJNHL7.js → chunk-DOFB2ACU.js} +3 -9
  8. package/dist/chunks/{chunk-SXW6XN4R.js → chunk-EGNP3S6C.js} +3 -3
  9. package/dist/chunks/{chunk-FK4RLDEK.js → chunk-N7E6DAUE.js} +1 -1
  10. package/dist/chunks/{chunk-U7M3ZB3Z.js → chunk-Q4TKRILH.js} +33 -167
  11. package/dist/chunks/{chunk-TMQQYHUX.js → chunk-RTILVSYQ.js} +1 -1
  12. package/dist/chunks/{chunk-7D6LC5JY.js → chunk-X4WBJIOF.js} +7 -39
  13. package/dist/chunks/{chunk-TEEZL3GA.js → chunk-YGS5VRQT.js} +11 -68
  14. package/dist/chunks/{chunk-ODQHQJLE.js → chunk-ZDJLKF2G.js} +742 -1117
  15. package/dist/chunks/{live-app-AZ5N5HBD.js → live-app-QFHS54SX.js} +4 -4
  16. package/dist/commands/exec/command.d.ts +2 -90
  17. package/dist/commands/exec/command.js +10 -10
  18. package/dist/commands/exec/define-run-command.d.ts +2 -90
  19. package/dist/commands/exec/live-view.js +18 -22
  20. package/dist/commands/exec/outcomes.d.ts +2 -106
  21. package/dist/commands/exec/outcomes.js +4 -35
  22. package/dist/commands/exec/progress.d.ts +3 -19
  23. package/dist/commands/exec/progress.js +16 -60
  24. package/dist/commands/exec/run-command.d.ts +4 -23
  25. package/dist/commands/exec/run-command.js +5 -79
  26. package/dist/commands/exec/run-metadata.d.ts +0 -6
  27. package/dist/commands/exec/run-metadata.js +2 -8
  28. package/dist/commands/exec/snapshot-text.d.ts +7 -16
  29. package/dist/commands/exec/snapshot-text.js +9 -49
  30. package/dist/commands/exec/view.js +2 -12
  31. package/dist/commands/playwright/command.d.ts +2 -90
  32. package/dist/commands/playwright/command.js +11 -11
  33. package/dist/commands/runs/facts.d.ts +1 -37
  34. package/dist/commands/runs/facts.js +4 -36
  35. package/dist/commands/runs/list/command.d.ts +0 -72
  36. package/dist/commands/runs/list/command.js +5 -5
  37. package/dist/commands/runs/list/outcomes.d.ts +0 -36
  38. package/dist/commands/runs/logs/command.js +5 -5
  39. package/dist/commands/runs/show/command.d.ts +0 -72
  40. package/dist/commands/runs/show/command.js +13 -40
  41. package/dist/commands/runs/show/metadata.js +1 -1
  42. package/dist/commands/runs/show/outcomes.d.ts +0 -36
  43. package/dist/commands/runs/show/outcomes.js +8 -42
  44. package/dist/commands/snapshots/build/command.d.ts +14 -411
  45. package/dist/commands/snapshots/build/command.js +56 -231
  46. package/dist/commands/snapshots/build/metadata.js +10 -7
  47. package/dist/commands/snapshots/build/outcomes.d.ts +11 -241
  48. package/dist/commands/snapshots/build/outcomes.js +29 -196
  49. package/dist/commands/snapshots/list/command.d.ts +2 -36
  50. package/dist/commands/snapshots/list/command.js +17 -53
  51. package/dist/commands/snapshots/list/metadata.js +1 -1
  52. package/dist/commands/snapshots/list/outcomes.d.ts +2 -37
  53. package/dist/commands/snapshots/list/outcomes.js +13 -53
  54. package/dist/commands/vitest/command.d.ts +2 -90
  55. package/dist/commands/vitest/command.js +11 -11
  56. package/dist/core/events.d.ts +5 -6
  57. package/dist/core/run-state.d.ts +7 -29
  58. package/dist/core/run-state.js +3 -26
  59. package/dist/core/run.d.ts +6 -14
  60. package/dist/core/run.js +17 -28
  61. package/dist/extensions/testserver/commands/pool/create/command.js +1 -1
  62. package/dist/run-directory/index.d.ts +1 -1
  63. package/dist/run-directory/index.js +0 -1
  64. package/dist/run-directory/recording.js +2 -2
  65. package/dist/run-directory/run-record.d.ts +14 -132
  66. package/dist/run-directory/run-record.js +8 -68
  67. package/dist/runner/build-snapshots.d.ts +50 -114
  68. package/dist/runner/build-snapshots.js +70 -159
  69. package/dist/runner/events.d.ts +4 -88
  70. package/dist/runner/gateways.d.ts +5 -23
  71. package/dist/runner/index.d.ts +5 -6
  72. package/dist/runner/index.js +1 -1
  73. package/dist/runner/live/snapshot-records.js +7 -18
  74. package/dist/runner/prepare.d.ts +11 -22
  75. package/dist/runner/prepare.js +6 -17
  76. package/dist/runner/ready.d.ts +16 -45
  77. package/dist/runner/ready.js +34 -59
  78. package/dist/runner/recipe.d.ts +0 -44
  79. package/dist/runner/recipe.js +0 -41
  80. package/dist/runner/scope.d.ts +8 -25
  81. package/dist/runner/scope.js +4 -8
  82. package/dist/runner/session.d.ts +18 -65
  83. package/dist/runner/session.js +15 -83
  84. package/dist/runner/snapshot-build.d.ts +2 -2
  85. package/dist/runner/snapshot-cache.d.ts +22 -74
  86. package/dist/runner/snapshot-cache.js +15 -107
  87. package/dist/runner/snapshot-inspect.d.ts +9 -13
  88. package/dist/runner/snapshot-inspect.js +48 -57
  89. package/dist/runner/snapshot-key.d.ts +9 -14
  90. package/dist/runner/snapshot-key.js +15 -22
  91. package/package.json +1 -1
  92. package/skills/read-run-output.md +8 -9
  93. package/dist/runner/snapshot-save.d.ts +0 -70
  94. package/dist/runner/snapshot-save.js +0 -160
  95. package/dist/runner/snapshot-start.d.ts +0 -25
  96. package/dist/runner/snapshot-start.js +0 -16
@@ -1,70 +0,0 @@
1
- import type { RunnerContext } from "./context.ts";
2
- import type { RunnerProgress, RunnerSave } from "./events.ts";
3
- import type { RunnerSnapshotCacheFailure, RunnerSnapshotEntry } from "./gateways.ts";
4
- import type { ReadyRunner } from "./ready.ts";
5
- import type { RunnerSandboxScope } from "./scope.ts";
6
- /** The directories the temp scrub empties: `/tmp`, `/var/tmp`, and `$TMPDIR` when it is set. */
7
- export declare const TEMP_DIRECTORIES: readonly string[];
8
- /**
9
- * Resets the working tree in `root` to its root commit, the base's tracked files (`baseIndexScript`), and removes
10
- * untracked files and nested Git repositories that `.gitignore` doesn't match: the same reset the next run's apply
11
- * starts with (`RESET_TO_BASE`). Ignored files, such as `node_modules`, build outputs and the turbo cache, stay.
12
- *
13
- * It leaves `.git` alone, so the run's commit and anything else the command put in Git stay in the snapshot. Cleaning
14
- * history adds no correctness: the next run resets before it applies. Nor does it hide the run's changes: the ignored
15
- * files the snapshot keeps hold their build outputs. And `git prune` can't promise it either, since it removes only
16
- * loose objects, not packed ones.
17
- */
18
- export declare function scrubGitScript(root?: string): string;
19
- /**
20
- * Empties each of `directories`, shell words that may expand to nothing: deletes what it holds, then, for anything
21
- * left, tries again with `sudo -n`. Fails, naming the directory and what is left, when one still holds something.
22
- */
23
- export declare function scrubTempScript(directories?: readonly string[]): string;
24
- /** What saving a dev snapshot is asked to save: the ready runner sandbox, and the commit it is for. */
25
- export interface SaveDevSnapshotRequest {
26
- /** The runner sandbox the command ran in, and the runner snapshot it started from. */
27
- readonly ready: ReadyRunner;
28
- /** HEAD's branch as the run started, null when detached, which the entry records for display. */
29
- readonly branch: string | null;
30
- /** HEAD's commit as the run started, a full SHA. */
31
- readonly head: string;
32
- }
33
- /**
34
- * How saving a dev snapshot ended (`save`), with the cache entry it recorded for a saved one (`entry`, else null) and
35
- * why the cache couldn't write that entry (`cacheFailure`, else null). A run reads only `save`; `storm snapshots build`
36
- * reports the entry, and fails when it isn't cached.
37
- */
38
- export type DevSnapshotSave = {
39
- readonly save: Extract<RunnerSave, {
40
- readonly kind: "saved";
41
- }>;
42
- readonly entry: RunnerSnapshotEntry;
43
- readonly cacheFailure: RunnerSnapshotCacheFailure | null;
44
- } | {
45
- readonly save: Exclude<RunnerSave, {
46
- readonly kind: "saved";
47
- }>;
48
- readonly entry: null;
49
- readonly cacheFailure: null;
50
- };
51
- /**
52
- * Saves the runner sandbox, once the command ended, as a dev snapshot at the run's HEAD commit. The session gives the
53
- * scope no keep time once a save starts (`session.ts`), so however the save ends, closing stops and deletes the
54
- * sandbox. It resets the working tree to the base the sandbox started from, leaving `.git` alone, empties the temp
55
- * directories, saves the sandbox as a runner snapshot, which the scope then deletes, and records the entry: the
56
- * started-from entry's owner, recipe, snapshot key and base, with the HEAD commit, the checkout's root and, when HEAD
57
- * is on one, the branch. Its entry replaces only the entry this checkout saved at that commit; the snapshot it
58
- * replaces is left to expire, since a run on this machine may be starting from it. Nothing here changes the run's
59
- * outcome: each way it ends is a note.
60
- *
61
- * It searches nothing for the run's secrets: the snapshot keeps what the command and the recipe's steps wrote to
62
- * `$HOME`, the ignored files and `.git`, as a kept runner sandbox does. A resource's token is limited to one test
63
- * resource. A runner secret a step that got it left behind is not: the recipe must not leave one, since later steps
64
- * and commands on the snapshot can read it (`README.md`). Only a later run from this checkout, with that commit as
65
- * HEAD or in HEAD's history, starts from the snapshot.
66
- */
67
- export declare function saveDevSnapshot(context: Pick<RunnerContext, "runnerSandboxes" | "runnerSnapshots" | "clock">, request: SaveDevSnapshotRequest, control: {
68
- readonly scope: RunnerSandboxScope;
69
- readonly signal: AbortSignal;
70
- }, progress: RunnerProgress): Promise<DevSnapshotSave>;
@@ -1,160 +0,0 @@
1
- // Saving the runner sandbox as a dev snapshot once its command ended: reset the working tree to its base and empty
2
- // the temp directories, save the sandbox as a runner snapshot, and record it in the cache for the run's checkout at
3
- // HEAD's commit. The snapshot keeps the rest of what the command and the recipe's steps left, a resource's token or a
4
- // runner secret they wrote included.
5
- import { lineSplitter, outputTail, splitLines } from "./output.js";
6
- import { SNAPSHOT_EXPIRATION_MS } from "./snapshot-cache.js";
7
- import { SANDBOX_ROOT, RESET_TO_BASE } from "./snapshot-key.js";
8
- import { STEP_ENV } from "./steps.js";
9
- /** How many of a failed script's last output lines its note keeps. */
10
- const FAILURE_TAIL_LINES = 3;
11
- /** The directories the temp scrub empties: `/tmp`, `/var/tmp`, and `$TMPDIR` when it is set. */
12
- export const TEMP_DIRECTORIES = ["/tmp", "/var/tmp", '"${TMPDIR:-}"'];
13
- /**
14
- * Resets the working tree in `root` to its root commit, the base's tracked files (`baseIndexScript`), and removes
15
- * untracked files and nested Git repositories that `.gitignore` doesn't match: the same reset the next run's apply
16
- * starts with (`RESET_TO_BASE`). Ignored files, such as `node_modules`, build outputs and the turbo cache, stay.
17
- *
18
- * It leaves `.git` alone, so the run's commit and anything else the command put in Git stay in the snapshot. Cleaning
19
- * history adds no correctness: the next run resets before it applies. Nor does it hide the run's changes: the ignored
20
- * files the snapshot keeps hold their build outputs. And `git prune` can't promise it either, since it removes only
21
- * loose objects, not packed ones.
22
- */
23
- export function scrubGitScript(root = SANDBOX_ROOT) {
24
- return ["set -euo pipefail", `cd ${root}`, ...RESET_TO_BASE].join("\n");
25
- }
26
- /**
27
- * Empties each of `directories`, shell words that may expand to nothing: deletes what it holds, then, for anything
28
- * left, tries again with `sudo -n`. Fails, naming the directory and what is left, when one still holds something.
29
- */
30
- export function scrubTempScript(directories = TEMP_DIRECTORIES) {
31
- return [
32
- "set -euo pipefail",
33
- `for dir in ${directories.join(" ")}; do`,
34
- ' [ -n "$dir" ] && [ -d "$dir" ] || continue',
35
- ' find "$dir" -mindepth 1 -maxdepth 1 -exec rm -rf -- {} + 2>/dev/null || true',
36
- ' if [ -n "$(find "$dir" -mindepth 1 -maxdepth 1 -print -quit)" ]; then',
37
- ' sudo -n find "$dir" -mindepth 1 -maxdepth 1 -exec rm -rf -- {} + 2>/dev/null || true',
38
- " fi",
39
- ' left=$(find "$dir" -mindepth 1 -maxdepth 1 -print -quit)',
40
- ' if [ -n "$left" ]; then echo "couldn\'t empty $dir: $left is left" >&2; exit 1; fi',
41
- "done",
42
- ].join("\n");
43
- }
44
- /**
45
- * Saves the runner sandbox, once the command ended, as a dev snapshot at the run's HEAD commit. The session gives the
46
- * scope no keep time once a save starts (`session.ts`), so however the save ends, closing stops and deletes the
47
- * sandbox. It resets the working tree to the base the sandbox started from, leaving `.git` alone, empties the temp
48
- * directories, saves the sandbox as a runner snapshot, which the scope then deletes, and records the entry: the
49
- * started-from entry's owner, recipe, snapshot key and base, with the HEAD commit, the checkout's root and, when HEAD
50
- * is on one, the branch. Its entry replaces only the entry this checkout saved at that commit; the snapshot it
51
- * replaces is left to expire, since a run on this machine may be starting from it. Nothing here changes the run's
52
- * outcome: each way it ends is a note.
53
- *
54
- * It searches nothing for the run's secrets: the snapshot keeps what the command and the recipe's steps wrote to
55
- * `$HOME`, the ignored files and `.git`, as a kept runner sandbox does. A resource's token is limited to one test
56
- * resource. A runner secret a step that got it left behind is not: the recipe must not leave one, since later steps
57
- * and commands on the snapshot can read it (`README.md`). Only a later run from this checkout, with that commit as
58
- * HEAD or in HEAD's history, starts from the snapshot.
59
- */
60
- export async function saveDevSnapshot(context, request, control, progress) {
61
- const saved = await saveOnce(context, request, control, progress);
62
- if (saved.save.kind !== "saved")
63
- await progress.emit({ kind: "dev-snapshot-not-saved", save: saved.save });
64
- return saved;
65
- }
66
- async function saveOnce(context, request, control, progress) {
67
- const unsaved = (save) => ({
68
- save,
69
- entry: null,
70
- cacheFailure: null,
71
- });
72
- const { ready, branch, head } = request;
73
- const { scope, signal } = control;
74
- const stopped = () => signal.aborted || scope.closed;
75
- if (stopped())
76
- return unsaved({ kind: "stopped" });
77
- const { sandbox, startedFrom } = ready;
78
- const startedAt = context.clock.now().getTime();
79
- await progress.emit({ kind: "dev-snapshot-saving", branch });
80
- for (const script of [scrubGitScript(), scrubTempScript()]) {
81
- if (stopped())
82
- return unsaved({ kind: "stopped" });
83
- const ran = await runSaveScript(context, sandbox, script, signal);
84
- if (ran.kind === "stopped")
85
- return unsaved(ran);
86
- if (ran.kind === "failed")
87
- return unsaved({ kind: "failed", step: "scrub", message: ran.message });
88
- }
89
- if (stopped())
90
- return unsaved({ kind: "stopped" });
91
- const saved = await scope.saveSnapshot(sandbox, { expirationMs: SNAPSHOT_EXPIRATION_MS });
92
- if (!saved.ok)
93
- return unsaved(saved.failure.kind === "aborted"
94
- ? { kind: "stopped" }
95
- : { kind: "failed", step: "save-snapshot", message: saved.failure.message });
96
- // A signal while the snapshot saved: the snapshot exists, but the run records nothing more.
97
- if (signal.aborted)
98
- return unsaved({ kind: "stopped" });
99
- const savedAt = context.clock.now();
100
- const entry = {
101
- teamId: startedFrom.teamId,
102
- projectId: startedFrom.projectId,
103
- region: startedFrom.region,
104
- runtime: startedFrom.runtime,
105
- recipeName: startedFrom.recipeName,
106
- snapshotKey: startedFrom.snapshotKey,
107
- base: startedFrom.base,
108
- ...(branch === null ? {} : { branch }),
109
- head,
110
- repoRoot: ready.repoRoot,
111
- snapshotId: saved.value.snapshotId,
112
- createdAt: savedAt.toISOString(),
113
- expiresAt: saved.value.expiresAt ?? new Date(savedAt.getTime() + SNAPSHOT_EXPIRATION_MS).toISOString(),
114
- };
115
- const written = await context.runnerSnapshots.writeEntry(entry);
116
- if (!written.ok)
117
- await progress.emit({ kind: "snapshot-entry-not-written", failure: written.failure });
118
- const ms = savedAt.getTime() - startedAt;
119
- await progress.emit({
120
- kind: "dev-snapshot-saved",
121
- snapshotId: entry.snapshotId,
122
- branch,
123
- head,
124
- ms,
125
- sizeBytes: saved.value.sizeBytes,
126
- });
127
- return {
128
- save: {
129
- kind: "saved",
130
- snapshotId: entry.snapshotId,
131
- base: entry.base,
132
- branch,
133
- head,
134
- ms,
135
- sizeBytes: saved.value.sizeBytes,
136
- entryWritten: written.ok,
137
- },
138
- entry,
139
- cacheFailure: written.ok ? null : written.failure,
140
- };
141
- }
142
- async function runSaveScript(context, sandbox, script, signal) {
143
- const splitters = { stdout: lineSplitter(), stderr: lineSplitter() };
144
- const tail = outputTail(FAILURE_TAIL_LINES);
145
- const keep = (text) => {
146
- for (const line of splitLines(text))
147
- tail.add(line);
148
- };
149
- const ran = await context.runnerSandboxes.runScript(sandbox, { script, env: STEP_ENV }, ({ stream, data }) => keep(splitters[stream].push(data)), signal);
150
- keep(splitters.stdout.flush());
151
- keep(splitters.stderr.flush());
152
- if (!ran.ok)
153
- return ran.failure.kind === "aborted" ? { kind: "stopped" } : { kind: "failed", message: ran.failure.message };
154
- const { exitCode } = ran.value;
155
- if (exitCode === 0)
156
- return { kind: "ok" };
157
- const lines = tail.lines();
158
- const ended = exitCode === null ? "ended without an exit code" : `exited ${exitCode}`;
159
- return { kind: "failed", message: lines.length === 0 ? ended : `${ended}: ${lines.join(" / ")}` };
160
- }
@@ -1,25 +0,0 @@
1
- import type { SnapshotBuildReason } from "./events.ts";
2
- import { type RunnerSnapshotCandidate, type SnapshotCacheRead } from "./snapshot-cache.ts";
3
- /**
4
- * What a runner sandbox starts from: the cached `candidate` (`reuse`), or a base snapshot built at the merge-base
5
- * first, and why (`build`). `storm snapshots build --base` builds no start, so `base` is no reason here.
6
- */
7
- export type SnapshotStart = {
8
- readonly kind: "reuse";
9
- readonly candidate: RunnerSnapshotCandidate;
10
- } | {
11
- readonly kind: "build";
12
- readonly why: Exclude<SnapshotBuildReason, {
13
- readonly kind: "base";
14
- }>;
15
- };
16
- /**
17
- * Chooses what a runner sandbox for `owner`'s team and project starts from. Of the candidates it picks as a run does
18
- * (`pickSnapshot`): with no pick, it builds, saying why each cached snapshot of the recipe doesn't fit
19
- * (`no-snapshot`, `snapshotRejections`); otherwise it reuses the pick. `storm snapshots build --full` makes its own
20
- * `full` start instead of asking.
21
- */
22
- export declare function chooseSnapshotStart(read: SnapshotCacheRead, owner: {
23
- readonly teamId: string;
24
- readonly projectId: string;
25
- }): SnapshotStart;
@@ -1,16 +0,0 @@
1
- // The one rule that decides what a runner sandbox starts from, for a run, `storm snapshots build` and
2
- // `storm snapshots list`: reuse a cached runner snapshot, or build a base snapshot, and why. It reads a cache read and
3
- // changes nothing; carrying the choice out is `obtainSnapshot`'s (`ready.ts`).
4
- import { pickSnapshot, snapshotRejections, } from "./snapshot-cache.js";
5
- /**
6
- * Chooses what a runner sandbox for `owner`'s team and project starts from. Of the candidates it picks as a run does
7
- * (`pickSnapshot`): with no pick, it builds, saying why each cached snapshot of the recipe doesn't fit
8
- * (`no-snapshot`, `snapshotRejections`); otherwise it reuses the pick. `storm snapshots build --full` makes its own
9
- * `full` start instead of asking.
10
- */
11
- export function chooseSnapshotStart(read, owner) {
12
- const pick = pickSnapshot(read.candidates, owner);
13
- if (pick === undefined)
14
- return { kind: "build", why: { kind: "no-snapshot", rejected: snapshotRejections(read, owner) } };
15
- return { kind: "reuse", candidate: pick };
16
- }