@cnc-tools/storm 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/dist/bin/storm.js +17 -9
  2. package/dist/build-info.js +1 -1
  3. package/dist/chunks/{chunk-YF3ICDBY.js → chunk-3ZZVZPMG.js} +1 -1
  4. package/dist/chunks/{chunk-JQ2HK4RN.js → chunk-4EU4AH7E.js} +141 -6
  5. package/dist/chunks/{chunk-ZJ2USLAT.js → chunk-4PRAB24Y.js} +2 -22
  6. package/dist/chunks/chunk-AMTYHUYB.js +257 -0
  7. package/dist/chunks/{chunk-WF4KJ7YG.js → chunk-ETCZ6WP7.js} +1 -1
  8. package/dist/chunks/chunk-FVMQKYTT.js +10 -0
  9. package/dist/chunks/{chunk-XHJGHJBW.js → chunk-GRMD7G4J.js} +33 -275
  10. package/dist/chunks/chunk-ICB4BZJX.js +22 -0
  11. package/dist/chunks/{chunk-AGWW3HDT.js → chunk-KR7WIYLG.js} +1826 -2201
  12. package/dist/chunks/{chunk-OVXD7GES.js → chunk-L4ZPMSKQ.js} +4 -37
  13. package/dist/chunks/chunk-NPPJ57W7.js +569 -0
  14. package/dist/chunks/{chunk-VJQLMGOH.js → chunk-O4BUT7BE.js} +361 -1716
  15. package/dist/chunks/chunk-OJOKQRM6.js +1457 -0
  16. package/dist/chunks/chunk-SLNKW4ZM.js +40 -0
  17. package/dist/chunks/{chunk-AKKNF3WZ.js → chunk-TRFEAYNC.js} +277 -348
  18. package/dist/chunks/chunk-VZZTHCBW.js +93 -0
  19. package/dist/chunks/chunk-WNIQA5J6.js +19 -0
  20. package/dist/chunks/chunk-WSIF7SR6.js +10 -0
  21. package/dist/chunks/{live-app-RIJM3QFD.js → live-app-LOGYUBKB.js} +52 -7
  22. package/dist/commands/exec/cleanup.d.ts +3 -3
  23. package/dist/commands/exec/cleanup.js +6 -2
  24. package/dist/commands/exec/command.d.ts +3 -3
  25. package/dist/commands/exec/command.js +17 -10
  26. package/dist/commands/exec/job-summary.d.ts +1 -1
  27. package/dist/commands/exec/job-summary.js +1 -1
  28. package/dist/commands/exec/live-view.js +5 -5
  29. package/dist/commands/exec/mint-failed.js +1 -1
  30. package/dist/commands/exec/outcomes.d.ts +2 -2
  31. package/dist/commands/exec/outcomes.js +7 -8
  32. package/dist/commands/exec/plan-run.d.ts +3 -5
  33. package/dist/commands/exec/progress.d.ts +3 -3
  34. package/dist/commands/exec/progress.js +6 -6
  35. package/dist/commands/exec/resource-refusals.d.ts +1 -1
  36. package/dist/commands/exec/resource-refusals.js +1 -1
  37. package/dist/commands/exec/run-command.d.ts +14 -9
  38. package/dist/commands/exec/run-command.js +91 -202
  39. package/dist/commands/exec/run-metadata.d.ts +2 -2
  40. package/dist/commands/exec/run-metadata.js +3 -3
  41. package/dist/commands/exec/test-plan.d.ts +1 -35
  42. package/dist/commands/exec/test-plan.js +4 -24
  43. package/dist/commands/exec/view.js +3 -3
  44. package/dist/commands/exec/waterfall.d.ts +3 -1
  45. package/dist/commands/exec/waterfall.js +18 -1
  46. package/dist/commands/runs/facts.d.ts +2 -1
  47. package/dist/commands/runs/facts.js +1 -1
  48. package/dist/commands/runs/list/command.js +10 -9
  49. package/dist/commands/runs/logs/command.js +14 -12
  50. package/dist/commands/runs/past-run.d.ts +3 -27
  51. package/dist/commands/runs/past-run.js +3 -37
  52. package/dist/commands/runs/show/command.js +24 -21
  53. package/dist/commands/runs/show/outcomes.js +2 -2
  54. package/dist/commands/vitest/command.d.ts +3 -3
  55. package/dist/commands/vitest/command.js +24 -17
  56. package/dist/commands/vitest/outcomes.d.ts +1 -1
  57. package/dist/commands/vitest/outcomes.js +1 -1
  58. package/dist/config/credential-resolver.d.ts +6 -3
  59. package/dist/config/credential-resolver.js +6 -5
  60. package/dist/context.d.ts +27 -9
  61. package/dist/context.js +19 -8
  62. package/dist/core/before-run.d.ts +5 -4
  63. package/dist/core/before-run.js +6 -6
  64. package/dist/core/definition-lookup.d.ts +22 -0
  65. package/dist/core/definition-lookup.js +34 -0
  66. package/dist/core/events.d.ts +5 -19
  67. package/dist/core/gateways.d.ts +22 -162
  68. package/dist/core/index.d.ts +10 -11
  69. package/dist/core/index.js +9 -11
  70. package/dist/core/launcher-supplies.js +2 -2
  71. package/dist/core/live/terminal-command-gateway.d.ts +8 -0
  72. package/dist/core/live/terminal-command-gateway.js +49 -0
  73. package/dist/core/presentations.d.ts +4 -3
  74. package/dist/core/presentations.js +4 -5
  75. package/dist/core/resource-registry.d.ts +35 -51
  76. package/dist/core/resource-registry.js +27 -54
  77. package/dist/core/resource-reports.d.ts +37 -4
  78. package/dist/core/resource-reports.js +34 -5
  79. package/dist/core/resources.d.ts +4 -3
  80. package/dist/core/resources.js +2 -4
  81. package/dist/core/run-state.d.ts +1 -1
  82. package/dist/core/run-state.js +1 -1
  83. package/dist/core/run.d.ts +19 -37
  84. package/dist/core/run.js +59 -114
  85. package/dist/core/timeline.js +2 -1
  86. package/dist/credential/events.d.ts +20 -0
  87. package/dist/credential/events.js +4 -0
  88. package/dist/credential/index.d.ts +2 -1
  89. package/dist/credential/index.js +6 -5
  90. package/dist/credential/source.d.ts +38 -26
  91. package/dist/credential/source.js +25 -34
  92. package/dist/extension-commands.d.ts +12 -6
  93. package/dist/extension-commands.js +18 -11
  94. package/dist/extensions/story/command-tree.d.ts +6 -0
  95. package/dist/extensions/story/command-tree.js +21 -0
  96. package/dist/extensions/story/commands/app.d.ts +23 -0
  97. package/dist/extensions/story/commands/app.js +5 -0
  98. package/dist/extensions/story/commands/run/command.d.ts +211 -0
  99. package/dist/extensions/story/commands/run/command.js +259 -0
  100. package/dist/extensions/story/commands/run/metadata.d.ts +4 -0
  101. package/dist/extensions/story/commands/run/metadata.js +8 -0
  102. package/dist/extensions/story/commands/run/outcomes.d.ts +101 -0
  103. package/dist/extensions/story/commands/run/outcomes.js +73 -0
  104. package/dist/extensions/story/commands/tree.d.ts +2 -0
  105. package/dist/extensions/story/commands/tree.js +6 -0
  106. package/dist/extensions/story/extension.d.ts +2 -0
  107. package/dist/extensions/story/extension.js +8 -0
  108. package/dist/extensions/testserver/command-tree.d.ts +1 -1
  109. package/dist/extensions/testserver/command-tree.js +0 -1
  110. package/dist/extensions/testserver/commands/pool/create/command.js +14 -8
  111. package/dist/extensions/testserver/commands/pool/list/command.js +8 -4
  112. package/dist/extensions/testserver/vitest/config.d.ts +7 -5
  113. package/dist/extensions/testserver/vitest/config.js +7 -5
  114. package/dist/extensions/testserver/vitest/fixtures.d.ts +2 -0
  115. package/dist/extensions/testserver/vitest/fixtures.js +36 -5
  116. package/dist/extensions.d.ts +12 -21
  117. package/dist/extensions.js +22 -34
  118. package/dist/forward-sigterm.d.ts +8 -0
  119. package/dist/forward-sigterm.js +18 -0
  120. package/dist/launcher-resolvers/index.d.ts +1 -0
  121. package/dist/launcher-resolvers/index.js +2 -1
  122. package/dist/launcher-resolvers/local-services.d.ts +57 -0
  123. package/dist/launcher-resolvers/local-services.js +7 -0
  124. package/dist/live-app.js +2 -1
  125. package/dist/local-services.d.ts +19 -0
  126. package/dist/local-services.js +37 -0
  127. package/dist/run-directory/gateways.d.ts +167 -0
  128. package/dist/run-directory/gateways.js +2 -0
  129. package/dist/run-directory/index.d.ts +8 -0
  130. package/dist/run-directory/index.js +13 -0
  131. package/dist/run-directory/plan.d.ts +35 -0
  132. package/dist/run-directory/plan.js +24 -0
  133. package/dist/run-directory/reader.d.ts +70 -0
  134. package/dist/run-directory/reader.js +51 -0
  135. package/dist/run-directory/recording.d.ts +92 -0
  136. package/dist/run-directory/recording.js +85 -0
  137. package/dist/{commands/exec → run-directory}/run-collector.d.ts +9 -8
  138. package/dist/{commands/exec → run-directory}/run-collector.js +8 -10
  139. package/dist/{core → run-directory}/run-directory.d.ts +3 -3
  140. package/dist/{core → run-directory}/run-directory.js +2 -2
  141. package/dist/{commands/exec → run-directory}/run-record.d.ts +29 -7
  142. package/dist/{commands/exec → run-directory}/run-record.js +79 -5
  143. package/dist/{commands/exec → run-directory}/timeline-facts.d.ts +4 -8
  144. package/dist/{commands/exec → run-directory}/timeline-facts.js +8 -24
  145. package/dist/runner/events.d.ts +6 -5
  146. package/dist/runner/index.d.ts +13 -17
  147. package/dist/runner/index.js +10 -14
  148. package/dist/runner/prepare.d.ts +28 -6
  149. package/dist/runner/prepare.js +15 -9
  150. package/dist/runner/recipe.d.ts +14 -0
  151. package/dist/runner/recipe.js +12 -0
  152. package/dist/runner/scope.d.ts +18 -11
  153. package/dist/runner/scope.js +12 -10
  154. package/dist/runner/session.d.ts +100 -0
  155. package/dist/runner/session.js +109 -0
  156. package/dist/runner/snapshot-save.d.ts +3 -2
  157. package/dist/runner/snapshot-save.js +6 -5
  158. package/dist/sdk/extension/ci.d.ts +2 -0
  159. package/dist/sdk/extension/ci.js +6 -0
  160. package/dist/sdk/extension/commands.d.ts +11 -13
  161. package/dist/sdk/extension/commands.js +5 -5
  162. package/dist/sdk/extension/index.d.ts +1 -0
  163. package/dist/sdk/extension/index.js +1 -0
  164. package/dist/sdk/extension/lifecycle.d.ts +4 -3
  165. package/dist/sdk/extension/progress.js +2 -2
  166. package/dist/sdk/extension/resource.js +1 -1
  167. package/dist/story/align.d.ts +1 -1
  168. package/dist/story/align.js +1 -1
  169. package/dist/story/command-line.d.ts +6 -16
  170. package/dist/story/command-line.js +11 -23
  171. package/dist/story/errors.d.ts +1 -1
  172. package/dist/story/errors.js +1 -1
  173. package/dist/story/host.d.ts +1 -1
  174. package/dist/story/host.js +2 -2
  175. package/dist/story/index.d.ts +2 -2
  176. package/dist/story/index.js +4 -3
  177. package/dist/story/launch.d.ts +70 -0
  178. package/dist/story/launch.js +77 -0
  179. package/dist/story/report.d.ts +2 -2
  180. package/dist/story/report.js +3 -4
  181. package/dist/story/settle.d.ts +7 -7
  182. package/dist/story/settle.js +5 -5
  183. package/dist/story/start.d.ts +2 -2
  184. package/dist/vendor/testserver-sdk/container/container.d.ts +11 -6
  185. package/dist/vendor/testserver-sdk/container/container.js +38 -16
  186. package/dist/vendor/testserver-sdk/testserver/failure.d.ts +4 -3
  187. package/dist/vendor/testserver-sdk/testserver/failure.js +4 -3
  188. package/package.json +1 -1
  189. package/skills/overview.md +3 -0
  190. package/skills/read-run-output.md +2 -2
  191. package/dist/chunks/chunk-H2VCSNVU.js +0 -351
  192. package/dist/chunks/chunk-J6ZNYUDV.js +0 -21
  193. package/dist/core/mint.d.ts +0 -10
  194. package/dist/core/mint.js +0 -14
  195. package/dist/story/mode.d.ts +0 -17
  196. package/dist/story/mode.js +0 -21
  197. /package/dist/{core → run-directory}/live/run-directory-gateway.d.ts +0 -0
  198. /package/dist/{core → run-directory}/live/run-directory-gateway.js +0 -0
@@ -0,0 +1,37 @@
1
+ // The local services, which reach this machine: the vitest service, which finds `vitest` on this machine as
2
+ // `storm vitest` does for a run on this machine, and the terminal service, which runs a command in the launcher's
3
+ // terminal. `localServices` (`context.ts`) builds them over the app's context; their types are in
4
+ // `launcher-resolvers/local-services.ts`.
5
+ import { parse } from "node:path";
6
+ import { commandExitStatus } from "./core/index.js";
7
+ import { forwardSigterm } from "./forward-sigterm.js";
8
+ /**
9
+ * The vitest service over `checkout`, which says the repository's root, and `vitestList`, which looks for `vitest`
10
+ * in each directory from `from` up to that root, or up to the filesystem's root outside a repository.
11
+ */
12
+ export function vitestService(context) {
13
+ return {
14
+ find: async (from) => {
15
+ const root = await context.checkout.repositoryRoot({ cwd: from });
16
+ return await context.vitestList.findVitest({ from, root: root.ok ? root.value : parse(from).root });
17
+ },
18
+ };
19
+ }
20
+ /**
21
+ * The terminal service over `terminalCommands`. It passes on only a SIGTERM that aborts the command's signal
22
+ * (`forwardSigterm`), and waits for the command either way.
23
+ */
24
+ export function terminalService(context) {
25
+ return {
26
+ run: async ({ argv, env, cwd, signal }) => {
27
+ const sigterm = forwardSigterm(signal);
28
+ try {
29
+ const ended = await context.terminalCommands.run({ argv, env, cwd, terminate: sigterm.terminate });
30
+ return ended.kind === "spawn-failed" ? ended : { ...ended, status: commandExitStatus(ended) };
31
+ }
32
+ finally {
33
+ sigterm.release();
34
+ }
35
+ },
36
+ };
37
+ }
@@ -0,0 +1,167 @@
1
+ import type { RunnerStepPhase } from "../runner/index.ts";
2
+ /** What a run directory operation couldn't do: the path and what the OS said, or why there is no place for it. */
3
+ export interface RunDirectoryFailure {
4
+ readonly path: string;
5
+ readonly message: string;
6
+ }
7
+ /** The output of a step in a run directory: a snapshot build's steps, applying the changes, the install, the build. */
8
+ export type RunDirectoryStep = RunnerStepPhase;
9
+ /** A run log: a step's log, or the command log (`command`), the command's output, in a run directory. */
10
+ export type RunLog = RunDirectoryStep | "command";
11
+ /**
12
+ * One run's run directory, open for writing: `run.json` (what the run was, and once it ended how), `events.jsonl` (the
13
+ * run's events, one JSON object a line), a log of each step's output (`snapshot.log`, `apply.log`, `install.log`,
14
+ * `build.log`), `command.log` (the command's stdout and stderr in arrival order, wherever it runs),
15
+ * `.test-events.jsonl` (the test events the command stages here, unredacted, while it runs, which `close` removes),
16
+ * `.tests.jsonl.partial` (the run's redacted test events as storm gets them), `tests.jsonl` (that file, published once
17
+ * the run is over) and `timeline.json`. While it is open, `active.json` marks it active, so no run prunes it. Writes
18
+ * never throw; `run.json`, `tests.jsonl` and `timeline.json` each appear whole, one after another in the order asked,
19
+ * so a reader sees a file whole or not at all; the first write that fails stops the rest, and `close` answers it.
20
+ */
21
+ export interface RunDirectory {
22
+ readonly path: string;
23
+ /** Its run id, the directory's name. */
24
+ readonly id: string;
25
+ /** Replaces `run.json` whole. */
26
+ writeRun(text: string): void;
27
+ /** Appends one line to `events.jsonl`. */
28
+ appendEvent(line: string): void;
29
+ /** Appends one line of a step's output to its log. */
30
+ appendStepOutput(step: RunDirectoryStep, line: string): void;
31
+ /** Appends the command's output, as it came. */
32
+ appendCommandOutput(text: string): void;
33
+ /** Appends one redacted test event line to the private file that becomes `tests.jsonl`. */
34
+ appendTestEvent(line: string): void;
35
+ /**
36
+ * Publishes the redacted test events appended so far as `tests.jsonl`, after any earlier replacement. A run that
37
+ * appended none publishes an empty file. Appends after this are dropped.
38
+ */
39
+ publishTestEvents(): void;
40
+ /** Writes `timeline.json` whole, after any earlier replacement. */
41
+ writeTimeline(text: string): void;
42
+ /**
43
+ * Streams the non-empty lines the command staged in `.test-events.jsonl`, the test events file its run payload names,
44
+ * to `onLine`, in order. A file that doesn't exist reads as empty; any other read failure is returned after the lines
45
+ * read before it.
46
+ */
47
+ readTestEvents(onLine: (line: string) => void): Promise<StagedTestEventsRead>;
48
+ /**
49
+ * Waits for every write so far, ends writing, removes the test events the command staged whatever failed before, and
50
+ * removes the active marker, so the run directory is completed; answers the first write that failed, or else a staged
51
+ * test events file or a marker it couldn't remove, if any.
52
+ */
53
+ close(): Promise<RunDirectoryFailure | undefined>;
54
+ }
55
+ /** How reading the command's staged test events went: read whole, or stopped by a failure. */
56
+ export type StagedTestEventsRead = {
57
+ readonly ok: true;
58
+ } | {
59
+ readonly ok: false;
60
+ readonly failure: RunDirectoryFailure;
61
+ };
62
+ /** How opening a run directory went: the directory, and what pruning older ones couldn't remove; or a failure. */
63
+ export type OpenRunDirectoryResult = {
64
+ readonly ok: true;
65
+ readonly directory: RunDirectory;
66
+ readonly pruneFailures: readonly RunDirectoryFailure[];
67
+ } | {
68
+ readonly ok: false;
69
+ readonly failure: RunDirectoryFailure;
70
+ };
71
+ /** A run directory as a listing finds it: its run id, path, whether it is active, and its `run.json`, if readable. */
72
+ export interface ListedRunDirectory {
73
+ readonly id: string;
74
+ readonly path: string;
75
+ readonly active: boolean;
76
+ /** `run.json` as it reads; undefined when the run directory has none or it can't be read. */
77
+ readonly run: string | undefined;
78
+ }
79
+ /** How listing the run directories went: each one, newest first; or a failure. */
80
+ export type ListRunDirectoriesResult = {
81
+ readonly ok: true;
82
+ readonly runs: readonly ListedRunDirectory[];
83
+ } | {
84
+ readonly ok: false;
85
+ readonly failure: RunDirectoryFailure;
86
+ };
87
+ /**
88
+ * A run directory as reading it finds it: its listing, its test events and timeline as they read, and the run logs it
89
+ * holds.
90
+ */
91
+ export interface PastRunDirectory extends ListedRunDirectory {
92
+ /**
93
+ * The lines of `tests.jsonl`, the run's redacted test events; undefined until the run has written it, once it was
94
+ * over. The test events the command stages while it runs are never read back.
95
+ */
96
+ readonly tests: readonly string[] | undefined;
97
+ /** `timeline.json` as it reads; undefined when there is none. */
98
+ readonly timeline: string | undefined;
99
+ /** The run logs it holds, in `RUN_LOGS`' order. */
100
+ readonly logs: readonly RunLog[];
101
+ }
102
+ /**
103
+ * How reading a run log went: `found`, its `text` as it is now, less a UTF-8 character still being written at its end;
104
+ * `not-found` when the run directory or the log doesn't exist; or a failure.
105
+ */
106
+ export type ReadRunLogResult = {
107
+ readonly kind: "found";
108
+ readonly path: string;
109
+ readonly text: string;
110
+ } | {
111
+ readonly kind: "not-found";
112
+ } | {
113
+ readonly kind: "failed";
114
+ readonly failure: RunDirectoryFailure;
115
+ };
116
+ /** How reading one run directory went: found, not found, or a failure. */
117
+ export type ReadRunDirectoryResult = {
118
+ readonly kind: "found";
119
+ readonly directory: PastRunDirectory;
120
+ } | {
121
+ readonly kind: "not-found";
122
+ } | {
123
+ readonly kind: "failed";
124
+ readonly failure: RunDirectoryFailure;
125
+ };
126
+ /**
127
+ * The run directories: `${XDG_STATE_HOME:-~/.local/state}/storm/runs/<run id>/`, one for each recent run. A
128
+ * run id is the run's start in UTC, `YYYYMMDDTHHMMSS`, a dash and a short random suffix, so runs started in the
129
+ * same second from different worktrees don't collide.
130
+ *
131
+ * A run directory is active from when it is opened until it is closed, and completed after. One whose run ended
132
+ * without closing it, its holder gone, is completed too: on the same host, once its process no longer runs; held on
133
+ * another host, or with a marker that can't be read, 24 hours after.
134
+ */
135
+ export interface RunDirectoryGateway {
136
+ /**
137
+ * Makes a run directory for a run started at `startedAt`, active, holding `run` as its `run.json`, then removes
138
+ * every completed run directory but the newest `keep`, and removes the private test event files a run that ended without
139
+ * closing its run directory left in each completed one it keeps. Active run directories, this one among them, all
140
+ * stay as they are.
141
+ */
142
+ open(request: {
143
+ readonly startedAt: Date;
144
+ readonly keep: number;
145
+ readonly run: string;
146
+ }): Promise<OpenRunDirectoryResult>;
147
+ /**
148
+ * Every run directory, newest first, with whether it is active at `now` and its `run.json`. A run directory whose
149
+ * `run.json` can't be read is listed without it. No run directories yet is an empty list.
150
+ */
151
+ list(request: {
152
+ readonly now: Date;
153
+ }): Promise<ListRunDirectoriesResult>;
154
+ /**
155
+ * Run directory `id`, with whether it is active at `now`, its `run.json`, test events and timeline, and the run logs
156
+ * it holds.
157
+ */
158
+ read(request: {
159
+ readonly id: string;
160
+ readonly now: Date;
161
+ }): Promise<ReadRunDirectoryResult>;
162
+ /** Run log `log` of run directory `id`, as it is now. */
163
+ readLog(request: {
164
+ readonly id: string;
165
+ readonly log: RunLog;
166
+ }): Promise<ReadRunLogResult>;
167
+ }
@@ -0,0 +1,2 @@
1
+ // The run directory module's gateway: the run directories on disk, which a run writes and `storm runs` reads back.
2
+ export {};
@@ -0,0 +1,8 @@
1
+ export type { RunDirectoryFailure, RunDirectoryGateway, RunLog } from "./gateways.ts";
2
+ export { liveRunDirectoryGateway, unavailableRunDirectoryGateway } from "./live/run-directory-gateway.ts";
3
+ export { RUNS_SUBPATH } from "./run-directory.ts";
4
+ export { recordRun, type RunRecorded, type RunRecording } from "./recording.ts";
5
+ export { type ListedRun, pastRuns } from "./reader.ts";
6
+ export { type PlanOption, planSchema, type TestPlanFacts } from "./plan.ts";
7
+ export { type RunRecordGit, type RunRecordWhere, saveSchema } from "./run-record.ts";
8
+ export { type TimelineFacts, type TimelineFactsRow, timelineSchema } from "./timeline-facts.ts";
@@ -0,0 +1,13 @@
1
+ // The `run-directory` module's caller-facing interface: a run's record in its run directory, which `storm runs` reads
2
+ // back. Two things: the recording of one run (`recordRun`), which the composition layer starts once the run is
3
+ // planned, and the reader of past runs (`pastRuns`). Beside them, the shapes of what they hold, which outcomes report
4
+ // and `--json-schema` shows (`run.json`'s, `timeline.json`'s and the test plan's), and the gateway the context holds,
5
+ // with its live adapter. It holds only what another module under `src/` imports; the module's own tests and fakes
6
+ // import its internal files. It names no resource, and reading a past run asks the registry nothing.
7
+ export { liveRunDirectoryGateway, unavailableRunDirectoryGateway } from "./live/run-directory-gateway.js";
8
+ export { RUNS_SUBPATH } from "./run-directory.js";
9
+ export { recordRun } from "./recording.js";
10
+ export { pastRuns } from "./reader.js";
11
+ export { planSchema } from "./plan.js";
12
+ export { saveSchema } from "./run-record.js";
13
+ export { timelineSchema } from "./timeline-facts.js";
@@ -0,0 +1,35 @@
1
+ import { z } from "zod";
2
+ declare const planOptionSchema: z.ZodObject<{
3
+ path: z.ZodString;
4
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
5
+ from: z.ZodEnum<{
6
+ default: "default";
7
+ file: "file";
8
+ flag: "flag";
9
+ }>;
10
+ }, z.core.$strip>;
11
+ /**
12
+ * One resource option whose default is a function of the planned run: its key path, value and where the value came
13
+ * from.
14
+ */
15
+ export type PlanOption = Readonly<z.output<typeof planOptionSchema>>;
16
+ /** A run's test plan, as `vitest`'s `ran` outcome, `run.json` and `runs show` hold it. */
17
+ export declare const planSchema: z.ZodObject<{
18
+ tests: z.ZodNumber;
19
+ files: z.ZodNumber;
20
+ options: z.ZodArray<z.ZodObject<{
21
+ path: z.ZodString;
22
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
23
+ from: z.ZodEnum<{
24
+ default: "default";
25
+ file: "file";
26
+ flag: "flag";
27
+ }>;
28
+ }, z.core.$strip>>;
29
+ }, z.core.$strip>;
30
+ /**
31
+ * A run's test plan: how many tests `vitest list` counted, in how many files, and each resource option whose default is
32
+ * a function of the planned run, with its value and where that came from.
33
+ */
34
+ export type TestPlanFacts = Readonly<z.output<typeof planSchema>>;
35
+ export {};
@@ -0,0 +1,24 @@
1
+ // A run's test plan as storm records it: what `vitest` counted before the run, and each resource option whose default is
2
+ // a function of the planned run, with its value and where that came from. `vitest`'s `ran` outcome, `run.json` and
3
+ // `runs show` share its shape; the composition layer says it (`commands/exec/test-plan.ts`).
4
+ import { z } from "zod";
5
+ const planOptionSchema = z.object({
6
+ /** The option's key path, `resources.<key>.<option>`, under its resource key. */
7
+ path: z.string(),
8
+ /** Its value. */
9
+ value: z.union([z.string(), z.number(), z.boolean()]),
10
+ /** Where the value came from: its flag (`flag`), storm.config.ts (`file`), or its default, given the test plan (`default`). */
11
+ from: z.enum(["flag", "file", "default"]),
12
+ });
13
+ /** A run's test plan, as `vitest`'s `ran` outcome, `run.json` and `runs show` hold it. */
14
+ export const planSchema = z.object({
15
+ /** How many tests `vitest list --json <args>` counted. */
16
+ tests: z.number().int().nonnegative(),
17
+ /** How many distinct test files they are in. */
18
+ files: z.number().int().nonnegative(),
19
+ /**
20
+ * Each resource option whose default is a function of the test plan, with its value and where that came from; empty
21
+ * when the run has none.
22
+ */
23
+ options: z.array(planOptionSchema),
24
+ });
@@ -0,0 +1,70 @@
1
+ import { type TestEvent } from "../sdk/run/launcher.ts";
2
+ import type { ReadRunLogResult, RunDirectoryFailure, RunDirectoryGateway, RunLog } from "./gateways.ts";
3
+ import { type RunRecord } from "./run-record.ts";
4
+ import { type TimelineFacts } from "./timeline-facts.ts";
5
+ /** A listed run directory with what its `run.json` records; `record` undefined when it has none it can read. */
6
+ export interface ListedRun {
7
+ /** Its run id, the run directory's name. */
8
+ readonly id: string;
9
+ readonly path: string;
10
+ /** Whether its run is still going. */
11
+ readonly active: boolean;
12
+ readonly record: RunRecord | undefined;
13
+ }
14
+ /** A run log a past run holds, and where it is. */
15
+ export interface PastRunLog {
16
+ readonly log: RunLog;
17
+ readonly path: string;
18
+ }
19
+ /**
20
+ * A past run read whole: its listing and record; its tests' final results, from its `tests.jsonl`, which storm
21
+ * writes only once the run is over and only redacted, with how many lines held no test event; its timeline's facts,
22
+ * when it parses, which the waterfall draws as they are; and the run logs it holds.
23
+ */
24
+ export interface PastRun extends ListedRun {
25
+ /** Whether its test results were saved: it finished, so its `tests.jsonl` exists. */
26
+ readonly finished: boolean;
27
+ /** Its test events, in the order its `tests.jsonl` holds them; empty unless `finished`. */
28
+ readonly events: readonly TestEvent[];
29
+ readonly unreadableTestLines: number;
30
+ readonly timeline: TimelineFacts | undefined;
31
+ /** The run logs it holds, in the order the run writes them: each step's, then the command's. */
32
+ readonly logs: readonly PastRunLog[];
33
+ }
34
+ /** How listing the past runs went: each one, newest first; or a failure. */
35
+ export type ListedRuns = {
36
+ readonly ok: true;
37
+ readonly runs: readonly ListedRun[];
38
+ } | {
39
+ readonly ok: false;
40
+ readonly failure: RunDirectoryFailure;
41
+ };
42
+ /** How reading one past run went: found, not found, or a failure. */
43
+ export type ReadPastRun = {
44
+ readonly kind: "found";
45
+ readonly run: PastRun;
46
+ } | {
47
+ readonly kind: "not-found";
48
+ } | {
49
+ readonly kind: "failed";
50
+ readonly failure: RunDirectoryFailure;
51
+ };
52
+ /** The past runs in the run directories. */
53
+ export interface PastRuns {
54
+ /** Every past run, newest first, with whether it is active at `now` and what its `run.json` records. */
55
+ list(request: {
56
+ readonly now: Date;
57
+ }): Promise<ListedRuns>;
58
+ /** Past run `id`, read whole, with whether it is active at `now`. */
59
+ read(request: {
60
+ readonly id: string;
61
+ readonly now: Date;
62
+ }): Promise<ReadPastRun>;
63
+ /** Run log `log` of past run `id`, as it is now. */
64
+ readLog(request: {
65
+ readonly id: string;
66
+ readonly log: RunLog;
67
+ }): Promise<ReadRunLogResult>;
68
+ }
69
+ /** The past runs in the run directories `gateway` reads. */
70
+ export declare function pastRuns(gateway: RunDirectoryGateway): PastRuns;
@@ -0,0 +1,51 @@
1
+ // Past runs as `storm runs` reads them back from their run directories: the run directory module's reading half. It
2
+ // lists the run directories with what each one's `run.json` records, and reads one whole: its record, its test
3
+ // events from `tests.jsonl`, its timeline from `timeline.json`, and the run logs it holds; and it reads one run log.
4
+ // Reading asks the registry nothing: rows and step names read as plain strings, and each resource instance's facts as
5
+ // recorded. Files it can't read, or from an older storm, leave facts unknown, never an error.
6
+ import { parseTestEvent } from "../sdk/run/launcher.js";
7
+ import { runLogFile } from "./run-directory.js";
8
+ import { parseRunRecord } from "./run-record.js";
9
+ import { timelineSchema } from "./timeline-facts.js";
10
+ /** The past runs in the run directories `gateway` reads. */
11
+ export function pastRuns(gateway) {
12
+ return {
13
+ list: async (request) => {
14
+ const listed = await gateway.list(request);
15
+ return listed.ok ? { ok: true, runs: listed.runs.map(listedRun) } : listed;
16
+ },
17
+ read: async (request) => {
18
+ const read = await gateway.read(request);
19
+ return read.kind === "found" ? { kind: "found", run: pastRun(read.directory) } : read;
20
+ },
21
+ readLog: async (request) => await gateway.readLog(request),
22
+ };
23
+ }
24
+ function listedRun({ id, path, active, run }) {
25
+ return { id, path, active, record: parseRunRecord(run) };
26
+ }
27
+ function pastRun(directory) {
28
+ const parsed = (directory.tests ?? []).map(parseTestEvent);
29
+ return {
30
+ ...listedRun(directory),
31
+ finished: directory.tests !== undefined,
32
+ events: parsed.filter((event) => event !== undefined),
33
+ unreadableTestLines: parsed.filter((event) => event === undefined).length,
34
+ timeline: parseTimeline(directory.timeline),
35
+ logs: directory.logs.map((log) => ({ log, path: `${directory.path}/${runLogFile(log)}` })),
36
+ };
37
+ }
38
+ /** `timeline.json`'s text as timeline facts; undefined when there is none, or it doesn't parse. */
39
+ function parseTimeline(text) {
40
+ if (text === undefined)
41
+ return undefined;
42
+ let json;
43
+ try {
44
+ json = JSON.parse(text);
45
+ }
46
+ catch {
47
+ return undefined;
48
+ }
49
+ const parsed = timelineSchema.safeParse(json);
50
+ return parsed.success ? parsed.data : undefined;
51
+ }
@@ -0,0 +1,92 @@
1
+ import { type ResourceRegistry, type RunObserver, type RunOutcome, type RunRequest, type RunState } from "../core/index.ts";
2
+ import type { RunnerTerminal } from "../runner/index.ts";
3
+ import type { RunDirectoryFailure, RunDirectoryGateway } from "./gateways.ts";
4
+ import type { TestPlanFacts } from "./plan.ts";
5
+ import { type RunTestEvents } from "./run-collector.ts";
6
+ import { type RunRecordGit } from "./run-record.ts";
7
+ import { type TimelineFacts } from "./timeline-facts.ts";
8
+ /** `value` with the run's secrets hidden in every string in it, through arrays and plain objects. */
9
+ export type Redaction = <T>(value: T) => T;
10
+ /** What a run's recording starts from: the registry, the run's start facts, and how to hide the run's secrets. */
11
+ export interface RunRecordingStart {
12
+ /** The registry the run runs over, which folds its state, projects its timeline and reports its resources. */
13
+ readonly registry: ResourceRegistry;
14
+ readonly startedAt: Date;
15
+ /** The working directory the run started in. */
16
+ readonly cwd: string;
17
+ /** The config file its settings came from; null when none applied. */
18
+ readonly configFile: string | null;
19
+ /** The run's command. */
20
+ readonly argv: readonly string[];
21
+ /** A `storm vitest` run's test plan; undefined for a run that counted nothing. */
22
+ readonly plan: TestPlanFacts | undefined;
23
+ /** The run's request, which says where its command runs. */
24
+ readonly run: RunRequest;
25
+ /** The Git checkout it started from; null outside one, or when git couldn't say. */
26
+ readonly git: RunRecordGit | null;
27
+ /** Hides the run's secrets: in `run.json`, and in each test event the command staged, before it is kept or written. */
28
+ readonly redact: Redaction;
29
+ }
30
+ /**
31
+ * How opening the run directory went: its run id and path, and what pruning older ones couldn't remove; or why it
32
+ * couldn't open, which the run goes on without.
33
+ */
34
+ export type RunRecordingOpened = {
35
+ readonly ok: true;
36
+ readonly id: string;
37
+ readonly path: string;
38
+ readonly pruneFailures: readonly RunDirectoryFailure[];
39
+ } | {
40
+ readonly ok: false;
41
+ readonly failure: RunDirectoryFailure;
42
+ };
43
+ /** What a run recorded once it is over: what its summary and its `ran` outcome read. */
44
+ export interface RunRecorded {
45
+ /** The run's final state, folded from every event. */
46
+ readonly state: RunState;
47
+ /** Its timeline, each row labeled, as `timeline.json` holds it. */
48
+ readonly timeline: TimelineFacts;
49
+ /** Its test events for the summary, without a final result's errors and test output. */
50
+ readonly tests: RunTestEvents;
51
+ /**
52
+ * What to add to the workers' clock to read the run's, from when the run heard each worker test event it followed;
53
+ * 0 when it followed none.
54
+ */
55
+ readonly workerOffsetMs: number;
56
+ /** The first write to the run directory that failed, or a file closing couldn't remove; undefined when none did. */
57
+ readonly writeFailure: RunDirectoryFailure | undefined;
58
+ }
59
+ /** One run's recording. Each method behaves the same when the run directory couldn't open, and writes nothing. */
60
+ export interface RunRecording {
61
+ readonly opened: RunRecordingOpened;
62
+ /**
63
+ * The test events file a command that stages its test events appends to, which the run payload names; undefined
64
+ * when the run directory couldn't open.
65
+ */
66
+ readonly testEvents: string | undefined;
67
+ /**
68
+ * The run's one observer, which hears every event, already redacted: folds it into the run's state and streams each
69
+ * test event to the private file that becomes `tests.jsonl`, then hands it to `beside`, the run's view, then writes
70
+ * it to `events.jsonl`, or a step's output to its log.
71
+ */
72
+ observer(beside: RunObserver): RunObserver;
73
+ /** `terminal`, also writing the command's output, already redacted, to `command.log`. */
74
+ terminal(terminal: RunnerTerminal): RunnerTerminal;
75
+ /** Where step `step`'s whole output is; undefined for a step that writes no log, or without a run directory. */
76
+ stepLog(step: string): string | undefined;
77
+ /**
78
+ * Ends the recording of a run that ended as `outcome`, already redacted: reads the staged test events, publishes
79
+ * `tests.jsonl`, writes `timeline.json`, writes `run.json` with how the run ended, and closes the run directory.
80
+ */
81
+ end(outcome: RunOutcome): Promise<RunRecorded>;
82
+ /**
83
+ * Ends the recording of a run that threw: closes the run directory, which completes it and removes the staged test
84
+ * events, unpublished.
85
+ */
86
+ abandon(): Promise<void>;
87
+ }
88
+ /**
89
+ * Starts recording a run in a run directory `gateway` opens, holding `run.json` as the run starts, redacted, and
90
+ * pruning older run directories to the newest `RUN_DIRECTORIES_KEPT`.
91
+ */
92
+ export declare function recordRun(gateway: RunDirectoryGateway, start: RunRecordingStart): Promise<RunRecording>;
@@ -0,0 +1,85 @@
1
+ // One run's recording in its run directory: the run directory module's writing half. It opens the run directory with
2
+ // `run.json` as the run starts, folds the run's state from its events while it writes them, its step logs, the
3
+ // command log and its test events, and once the run is over writes how it ended, in one order, then closes it. A run
4
+ // whose run directory couldn't open goes on without one: the recording still folds its state and answers the same,
5
+ // and writes nothing.
6
+ //
7
+ // The order at the end is the reader's contract: the test events the command staged are read and redacted, then
8
+ // `tests.jsonl` is published, then `timeline.json` is written, then `run.json` says how the run ended, and then the run
9
+ // directory closes, which removes the staged test events. A run that threw is abandoned: its run directory closes and
10
+ // its test events are never published, since the run didn't end.
11
+ //
12
+ // The recording's one observer folds each event, hands it to the observer beside it (the run's view), and writes it
13
+ // last. Lanes beside each other emit at once, and the view awaits as it prints, so writing last keeps `events.jsonl` in
14
+ // the order storm has always written it.
15
+ import { observeAll, } from "../core/index.js";
16
+ import { runCollector } from "./run-collector.js";
17
+ import { RUN_DIRECTORIES_KEPT, runDirectoryObserver, stepLog, testEventsPath } from "./run-directory.js";
18
+ import { endedWhere, runEnd, runRecordText, startedWhere } from "./run-record.js";
19
+ import { timelineFacts } from "./timeline-facts.js";
20
+ /**
21
+ * Starts recording a run in a run directory `gateway` opens, holding `run.json` as the run starts, redacted, and
22
+ * pruning older run directories to the newest `RUN_DIRECTORIES_KEPT`.
23
+ */
24
+ export async function recordRun(gateway, start) {
25
+ const { registry } = start;
26
+ const record = start.redact({
27
+ version: 3,
28
+ startedAt: start.startedAt.toISOString(),
29
+ cwd: start.cwd,
30
+ configFile: start.configFile,
31
+ argv: start.argv,
32
+ ...(start.plan === undefined ? {} : { plan: start.plan }),
33
+ where: startedWhere(start.run),
34
+ git: start.git,
35
+ });
36
+ const result = await gateway.open({
37
+ startedAt: start.startedAt,
38
+ keep: RUN_DIRECTORIES_KEPT,
39
+ run: runRecordText(record),
40
+ });
41
+ const directory = result.ok ? result.directory : undefined;
42
+ const opened = result.ok
43
+ ? { ok: true, id: result.directory.id, path: result.directory.path, pruneFailures: result.pruneFailures }
44
+ : { ok: false, failure: result.failure };
45
+ const collector = runCollector(registry, directory);
46
+ return {
47
+ opened,
48
+ testEvents: directory === undefined ? undefined : testEventsPath(directory.path),
49
+ observer: (beside) => directory === undefined
50
+ ? observeAll(collector.observer, beside)
51
+ : observeAll(collector.observer, beside, runDirectoryObserver(directory)),
52
+ terminal: (terminal) => directory === undefined
53
+ ? terminal
54
+ : {
55
+ color: terminal.color,
56
+ writeStdout: (text) => {
57
+ directory.appendCommandOutput(text);
58
+ terminal.writeStdout(text);
59
+ },
60
+ writeStderr: (text) => {
61
+ directory.appendCommandOutput(text);
62
+ terminal.writeStderr(text);
63
+ },
64
+ },
65
+ stepLog: (step) => (directory === undefined ? undefined : stepLog(directory.path, step)),
66
+ end: async (outcome) => {
67
+ if (directory !== undefined)
68
+ await collector.readStaged(directory, start.redact);
69
+ const { state, tests, workerOffsetMs } = collector.finish();
70
+ const timeline = timelineFacts(registry.timeline(state), registry.presentations.laneKinds);
71
+ directory?.publishTestEvents();
72
+ directory?.writeTimeline(JSON.stringify(timeline, null, 2));
73
+ directory?.writeRun(runRecordText({
74
+ ...record,
75
+ where: endedWhere(record.where, state.runner, outcome.kind === "ran" ? (outcome.runner?.save ?? null) : null),
76
+ ended: runEnd(outcome, state.command, tests, registry.reports),
77
+ }));
78
+ const writeFailure = await directory?.close();
79
+ return { state, timeline, tests, workerOffsetMs, writeFailure };
80
+ },
81
+ abandon: async () => {
82
+ await directory?.close();
83
+ },
84
+ };
85
+ }
@@ -1,6 +1,7 @@
1
- import { type RunDirectory, type RunObserver, type RunState } from "../../core/index.ts";
2
- import { type TestEvent } from "../../sdk/run/launcher.ts";
3
- import { type Redact } from "./redaction.ts";
1
+ import { type ResourceRegistry, type RunObserver, type RunState } from "../core/index.ts";
2
+ import { type TestEvent } from "../sdk/run/launcher.ts";
3
+ import type { RunDirectory } from "./gateways.ts";
4
+ import type { Redaction } from "./recording.ts";
4
5
  /** The test events the summary reads, how many lines held none, and why they may be incomplete, when they may. */
5
6
  export interface RunTestEvents {
6
7
  readonly events: readonly TestEvent[];
@@ -24,12 +25,12 @@ export interface RunCollector {
24
25
  * Reads the test events the command staged in the run directory, if it staged any, once, redacting each event before
25
26
  * it is kept or written.
26
27
  */
27
- readStaged(directory: RunDirectory, redact: Redact): Promise<void>;
28
+ readStaged(directory: RunDirectory, redact: Redaction): Promise<void>;
28
29
  finish(): CollectedRun;
29
30
  }
30
31
  /**
31
- * A collector that folds every event but a runner step's output into the run's state. Each test event it hears or
32
- * reads is appended whole to `directory`'s private test events file, when there is one, and kept for the summary
33
- * without a final result's errors and test output.
32
+ * A collector that folds every event but a runner step's output into the run's state, through `registry`. Each test
33
+ * event it hears or reads is appended whole to `directory`'s private test events file, when there is one, and kept for
34
+ * the summary without a final result's errors and test output.
34
35
  */
35
- export declare function runCollector(directory: RunDirectory | undefined): RunCollector;
36
+ export declare function runCollector(registry: ResourceRegistry, directory: RunDirectory | undefined): RunCollector;