@cnc-tools/storm 0.6.0 → 0.8.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 (174) hide show
  1. package/dist/build-info.js +1 -1
  2. package/dist/commands/exec/cleanup.d.ts +3 -3
  3. package/dist/commands/exec/cleanup.js +1 -1
  4. package/dist/commands/exec/command.d.ts +797 -1
  5. package/dist/commands/exec/command.js +1 -1
  6. package/dist/commands/exec/live-view.js +32 -15
  7. package/dist/commands/exec/metadata.d.ts +5 -2
  8. package/dist/commands/exec/metadata.js +4 -0
  9. package/dist/commands/exec/mint-failed.d.ts +28 -0
  10. package/dist/commands/exec/outcomes.d.ts +526 -0
  11. package/dist/commands/exec/outcomes.js +9 -0
  12. package/dist/commands/exec/progress.d.ts +14 -2
  13. package/dist/commands/exec/progress.js +57 -14
  14. package/dist/commands/exec/run-command.d.ts +10 -4
  15. package/dist/commands/exec/run-command.js +41 -8
  16. package/dist/commands/exec/run-metadata.d.ts +6 -3
  17. package/dist/commands/exec/run-metadata.js +6 -3
  18. package/dist/commands/exec/run-record.d.ts +83 -4
  19. package/dist/commands/exec/run-record.js +49 -1
  20. package/dist/commands/exec/tests-summary.d.ts +1 -1
  21. package/dist/commands/exec/tests-summary.js +1 -1
  22. package/dist/commands/exec/view.js +36 -4
  23. package/dist/commands/runs/facts.d.ts +25 -0
  24. package/dist/commands/runs/facts.js +36 -3
  25. package/dist/commands/runs/list/command.d.ts +154 -1
  26. package/dist/commands/runs/list/command.js +1 -1
  27. package/dist/commands/runs/list/outcomes.d.ts +41 -0
  28. package/dist/commands/runs/logs/command.d.ts +263 -1
  29. package/dist/commands/runs/logs/command.js +1 -1
  30. package/dist/commands/runs/logs/outcomes.d.ts +105 -0
  31. package/dist/commands/runs/show/command.d.ts +354 -1
  32. package/dist/commands/runs/show/command.js +1 -1
  33. package/dist/commands/runs/show/metadata.js +1 -1
  34. package/dist/commands/runs/show/outcomes.d.ts +96 -0
  35. package/dist/commands/runs/show/outcomes.js +30 -1
  36. package/dist/commands/vitest/command.d.ts +912 -1
  37. package/dist/commands/vitest/command.js +1 -1
  38. package/dist/commands/vitest/metadata.d.ts +5 -2
  39. package/dist/commands/vitest/metadata.js +4 -0
  40. package/dist/commands/vitest/outcomes.d.ts +320 -0
  41. package/dist/config/errors.d.ts +73 -0
  42. package/dist/config/schema.d.ts +1 -1
  43. package/dist/config-file/define.d.ts +4 -3
  44. package/dist/config-file/define.js +1 -1
  45. package/dist/config-file/toolchain.js +1 -1
  46. package/dist/core/command-slots.d.ts +8 -2
  47. package/dist/core/command-slots.js +6 -2
  48. package/dist/core/events.d.ts +9 -7
  49. package/dist/core/index.d.ts +1 -1
  50. package/dist/core/run-state.d.ts +30 -6
  51. package/dist/core/run-state.js +19 -4
  52. package/dist/core/run.d.ts +17 -4
  53. package/dist/core/run.js +61 -25
  54. package/dist/credential/index.d.ts +1 -0
  55. package/dist/credential/index.js +1 -0
  56. package/dist/credential/settle.d.ts +20 -0
  57. package/dist/credential/target.d.ts +6 -0
  58. package/dist/credential/target.js +7 -0
  59. package/dist/resources/github/command.d.ts +54 -2
  60. package/dist/resources/github/config.js +1 -1
  61. package/dist/resources/github/index.js +1 -1
  62. package/dist/resources/github/resource.js +2 -2
  63. package/dist/resources/testserver/command.d.ts +208 -10
  64. package/dist/resources/testserver/command.js +7 -0
  65. package/dist/resources/testserver/commands/create/command.d.ts +808 -1
  66. package/dist/resources/testserver/commands/create/command.js +64 -23
  67. package/dist/resources/testserver/commands/create/metadata.js +6 -2
  68. package/dist/resources/testserver/commands/create/outcomes.d.ts +347 -0
  69. package/dist/resources/testserver/commands/create/outcomes.js +14 -1
  70. package/dist/resources/testserver/commands/list/command.d.ts +84 -1
  71. package/dist/resources/testserver/commands/list/command.js +1 -1
  72. package/dist/resources/testserver/commands/list/outcomes.d.ts +16 -0
  73. package/dist/resources/testserver/config.js +14 -4
  74. package/dist/resources/testserver/events.d.ts +9 -0
  75. package/dist/resources/testserver/index.js +8 -7
  76. package/dist/resources/testserver/lane.js +1 -0
  77. package/dist/resources/testserver/live/gateways.d.ts +2 -0
  78. package/dist/resources/testserver/live/gateways.js +16 -3
  79. package/dist/resources/testserver/pool/channels.d.ts +5 -2
  80. package/dist/resources/testserver/pool/channels.js +1 -1
  81. package/dist/resources/testserver/pool/create.d.ts +6 -2
  82. package/dist/resources/testserver/pool/create.js +6 -5
  83. package/dist/resources/testserver/pool/index.d.ts +1 -0
  84. package/dist/resources/testserver/pool/index.js +1 -0
  85. package/dist/resources/testserver/pool/pull-request.d.ts +89 -0
  86. package/dist/resources/testserver/pool/pull-request.js +85 -0
  87. package/dist/resources/testserver/pr-build-facts.d.ts +130 -0
  88. package/dist/resources/testserver/pr-build-facts.js +261 -0
  89. package/dist/resources/testserver/presentation.d.ts +2 -2
  90. package/dist/resources/testserver/presentation.js +12 -3
  91. package/dist/resources/testserver/provider.d.ts +16 -6
  92. package/dist/resources/testserver/provider.js +46 -15
  93. package/dist/resources/testserver/pull-request/gateways.d.ts +117 -0
  94. package/dist/resources/testserver/pull-request/gateways.js +5 -0
  95. package/dist/resources/testserver/pull-request/index.d.ts +5 -0
  96. package/dist/resources/testserver/pull-request/index.js +6 -0
  97. package/dist/resources/testserver/pull-request/live/github-rest.d.ts +28 -0
  98. package/dist/resources/testserver/pull-request/live/github-rest.js +114 -0
  99. package/dist/resources/testserver/pull-request/live/github-token-gateway.d.ts +12 -0
  100. package/dist/resources/testserver/pull-request/live/github-token-gateway.js +39 -0
  101. package/dist/resources/testserver/pull-request/live/pull-request-gateway.d.ts +10 -0
  102. package/dist/resources/testserver/pull-request/live/pull-request-gateway.js +27 -0
  103. package/dist/resources/testserver/pull-request/live/testserver-workflow-gateway.d.ts +21 -0
  104. package/dist/resources/testserver/pull-request/live/testserver-workflow-gateway.js +64 -0
  105. package/dist/resources/testserver/ran.d.ts +5 -0
  106. package/dist/resources/testserver/ran.js +19 -3
  107. package/dist/resources/testserver/resource.d.ts +5 -1
  108. package/dist/resources/testserver/resource.js +2 -2
  109. package/dist/resources/testserver/sandbox/build-reference.d.ts +38 -0
  110. package/dist/resources/testserver/sandbox/build-reference.js +79 -0
  111. package/dist/resources/testserver/sandbox/index.d.ts +1 -0
  112. package/dist/resources/testserver/sandbox/index.js +1 -0
  113. package/dist/resources.d.ts +265 -15
  114. package/dist/runner/events.d.ts +64 -1
  115. package/dist/runner/gateways.d.ts +17 -6
  116. package/dist/runner/index.d.ts +5 -4
  117. package/dist/runner/index.js +4 -3
  118. package/dist/runner/live/snapshot-records.js +18 -4
  119. package/dist/runner/prepare.d.ts +23 -4
  120. package/dist/runner/prepare.js +13 -3
  121. package/dist/runner/ready.d.ts +7 -3
  122. package/dist/runner/ready.js +11 -5
  123. package/dist/runner/scope.d.ts +17 -1
  124. package/dist/runner/scope.js +4 -0
  125. package/dist/runner/snapshot-build.d.ts +3 -1
  126. package/dist/runner/snapshot-build.js +12 -2
  127. package/dist/runner/snapshot-cache.d.ts +46 -8
  128. package/dist/runner/snapshot-cache.js +60 -11
  129. package/dist/runner/snapshot-key.d.ts +12 -1
  130. package/dist/runner/snapshot-key.js +17 -1
  131. package/dist/runner/snapshot-save.d.ts +53 -0
  132. package/dist/runner/snapshot-save.js +148 -0
  133. package/dist/sdk/index.js +2 -2
  134. package/dist/story/align.d.ts +1 -1
  135. package/dist/story/align.js +1 -1
  136. package/dist/story/command-line.d.ts +34 -0
  137. package/dist/story/command-line.js +100 -0
  138. package/dist/story/definition.d.ts +22 -15
  139. package/dist/story/definition.js +2 -2
  140. package/dist/story/errors.js +1 -1
  141. package/dist/story/gateways.d.ts +45 -25
  142. package/dist/story/gateways.js +2 -2
  143. package/dist/story/host.d.ts +11 -8
  144. package/dist/story/host.js +37 -37
  145. package/dist/story/index.d.ts +2 -1
  146. package/dist/story/index.js +6 -5
  147. package/dist/story/json.d.ts +1 -1
  148. package/dist/story/json.js +2 -2
  149. package/dist/story/live/recording-gateway.d.ts +2 -0
  150. package/dist/story/live/{artifact-gateway.js → recording-gateway.js} +33 -12
  151. package/dist/story/mode.d.ts +2 -2
  152. package/dist/story/mode.js +1 -1
  153. package/dist/story/orphans.d.ts +23 -5
  154. package/dist/story/orphans.js +44 -8
  155. package/dist/story/recording.d.ts +62 -0
  156. package/dist/story/{artifact.js → recording.js} +31 -27
  157. package/dist/story/report.d.ts +21 -9
  158. package/dist/story/report.js +37 -25
  159. package/dist/story/settle.d.ts +23 -21
  160. package/dist/story/settle.js +17 -16
  161. package/dist/story/{run.d.ts → start.d.ts} +18 -17
  162. package/dist/story/{run.js → start.js} +66 -43
  163. package/dist/vercel-cli/context.js +1 -1
  164. package/dist/vercel-cli/index.js +1 -1
  165. package/dist/vitest/config.js +2 -2
  166. package/dist/vitest/fixtures.d.ts +1 -1
  167. package/dist/vitest/fixtures.js +1 -1
  168. package/dist/vitest/index.js +3 -3
  169. package/dist/vitest/plan.js +1 -1
  170. package/package.json +3 -3
  171. package/skills/overview.md +2 -0
  172. package/skills/testserver-builds.md +80 -0
  173. package/dist/story/artifact.d.ts +0 -60
  174. package/dist/story/live/artifact-gateway.d.ts +0 -2
@@ -1,5 +1,5 @@
1
- // What a story says about its calls: one event line per call, the report of a failed story, and the line for what a
2
- // passing story changed. Pure.
1
+ // What a story says about its calls: one event line per call, the report of a failed story, and what a passing story
2
+ // changed. Pure.
3
3
  import { describeObservationDiff } from "./diff.js";
4
4
  import { STORY_RECORD_VARIABLE } from "./mode.js";
5
5
  /** How much of a call's input its line keeps. */
@@ -10,22 +10,24 @@ export function describeCall(call) {
10
10
  return `${call.agent} calls ${call.tool} ${input.length > INPUT_CHARS ? `${input.slice(0, INPUT_CHARS - 1)}…` : input}`;
11
11
  }
12
12
  /**
13
- * One line per aligned call, then one per unreadable artifact and orphan, each with its status in brackets:
14
- * `matched`, `divergence`, `unrecorded` or `unmade`, `orphan` or `unreadable`. When the story's end `applied` its
15
- * change, an unrecorded call reads `recorded`, an accepted divergence `divergence accepted`, an unmade call
16
- * `unmade removed`, an unreadable artifact `unreadable rewritten` and an orphan `orphan removed`.
13
+ * One line per aligned call, then one per unreadable recording and orphan, each with its status in brackets:
14
+ * `matched`, `divergence`, `unrecorded` or `unmade`, `orphan` or `unreadable`. When the story's end `applied` the
15
+ * change to its recording, an unrecorded call reads `recorded`, an accepted divergence `divergence accepted`, an
16
+ * unmade call `unmade removed` and an unreadable recording `unreadable rewritten`; each orphan it removed reads
17
+ * `orphan removed`.
17
18
  */
18
19
  export function storyEventLines(settlement, applied) {
19
- const written = applied && settlement.change.kind !== "leave";
20
- const calls = settlement.aligned.map((each) => `${describeAligned(each)} [${callStatus(each, written, settlement.accepted)}]`);
21
- const files = settlement.stale.flatMap((entry) => entry.kind === "unreadable"
22
- ? [`artifact ${entry.path} [${written ? "unreadable rewritten" : "unreadable"}]`]
20
+ const calls = settlement.aligned.map((each) => `${describeAligned(each)} [${callStatus(each, applied.recording, settlement.accepted)}]`);
21
+ return [...calls, ...recordingLines(settlement, applied)];
22
+ }
23
+ /** One line per unreadable recording and orphan recording, each with its status, as `storyEventLines` gives it. */
24
+ function recordingLines(settlement, applied) {
25
+ const removed = new Set(applied.orphans);
26
+ return settlement.stale.flatMap((entry) => entry.kind === "unreadable"
27
+ ? [`recording ${entry.path} [${applied.recording ? "unreadable rewritten" : "unreadable"}]`]
23
28
  : entry.kind === "orphan"
24
- ? [
25
- `artifact ${entry.path} [${applied && settlement.removeOrphans.includes(entry.path) ? "orphan removed" : "orphan"}]`,
26
- ]
29
+ ? [`recording ${entry.path} [${removed.has(entry.path) ? "orphan removed" : "orphan"}]`]
27
30
  : []);
28
- return [...calls, ...files];
29
31
  }
30
32
  function describeAligned(each) {
31
33
  return describeCall(each.kind === "unmade" ? each.recorded : each.live);
@@ -85,18 +87,20 @@ function summary(input) {
85
87
  if (input.bodyFailed)
86
88
  return `${counts} The story threw, so nothing was written.`;
87
89
  if (divergences.length > 0) {
88
- return `${counts} A divergence means the tool behaved differently. If that is intended, record it with ${STORY_RECORD_VARIABLE}=all.`;
90
+ return `${counts} A divergence means the tool behaved differently. If that is intended, accept it with ${STORY_RECORD_VARIABLE}=all.`;
89
91
  }
90
- return `${counts} The recording no longer fits the story. Record it again with ${STORY_RECORD_VARIABLE}=stale.`;
92
+ return `${counts} The recording no longer fits the story. Rewrite it with ${STORY_RECORD_VARIABLE}=stale.`;
91
93
  }
92
94
  /**
93
- * The line for what a passing story's end changed, or `undefined` when it changed nothing: how many calls it
94
- * recorded, divergences it accepted, unmade calls it removed, unreadable artifacts it rewrote and orphans it removed.
95
+ * What a passing story's end `applied`, or `undefined` when it changed nothing. Its first line counts what it did: the
96
+ * calls it recorded, the divergences it accepted, the unmade calls it removed, an unreadable recording it rewrote and
97
+ * the orphans it removed. One line follows for each call it rewrote and each recording it rewrote or removed, as
98
+ * `storyEventLines` gives it, so a call whose input changed with its answer shows as the unmade call removed and the
99
+ * new call recorded.
95
100
  */
96
- export function storyChangeLine(story, path, settlement) {
101
+ export function storyChangeReport(story, path, settlement, applied) {
97
102
  const parts = [];
98
- const written = settlement.change.kind !== "leave";
99
- if (written) {
103
+ if (applied.recording) {
100
104
  const kinds = (kind) => settlement.stale.filter((entry) => entry.kind === kind).length;
101
105
  if (kinds("unrecorded") > 0)
102
106
  parts.push(`recorded ${count(kinds("unrecorded"), "call")}`);
@@ -105,13 +109,21 @@ export function storyChangeLine(story, path, settlement) {
105
109
  if (kinds("unmade") > 0)
106
110
  parts.push(`removed ${count(kinds("unmade"), "unmade call")}`);
107
111
  if (kinds("unreadable") > 0)
108
- parts.push("rewrote an unreadable artifact");
112
+ parts.push("rewrote an unreadable recording");
109
113
  }
110
- if (settlement.removeOrphans.length > 0)
111
- parts.push(`removed ${count(settlement.removeOrphans.length, "orphan")}`);
114
+ if (applied.orphans.length > 0)
115
+ parts.push(`removed ${count(applied.orphans.length, "orphan recording")}`);
112
116
  if (parts.length === 0)
113
117
  return undefined;
114
- return `story "${story.name}": ${parts.join(", ")} (${path})`;
118
+ const changed = [
119
+ ...(applied.recording ? rewrittenCallLines(settlement) : []),
120
+ ...recordingLines(settlement, applied),
121
+ ];
122
+ return [`story "${story.name}": ${parts.join(", ")} (${path})`, ...changed.map((line) => ` ${line}`)].join("\n");
123
+ }
124
+ /** The event line of each aligned call a written recording changed: every one but the matched ones. */
125
+ function rewrittenCallLines(settlement) {
126
+ return settlement.aligned.flatMap((each) => each.kind === "matched" ? [] : [`${describeAligned(each)} [${callStatus(each, true, settlement.accepted)}]`]);
115
127
  }
116
128
  function count(n, one, many = `${one}s`) {
117
129
  return `${n} ${n === 1 ? one : many}`;
@@ -1,5 +1,5 @@
1
1
  import { type StoryAlignedCall } from "./align.ts";
2
- import type { StoryArtifact, StoryCall, StoryIdentity } from "./artifact.ts";
2
+ import type { StoryRecording, StoryCall, StoryIdentity } from "./recording.ts";
3
3
  import type { StoryRecordLevel } from "./mode.ts";
4
4
  /** A recorded call and a live call with the same key and different observations: the tool behaved differently. */
5
5
  export interface StoryDivergence {
@@ -11,8 +11,9 @@ export interface StoryDivergence {
11
11
  *
12
12
  * - `unrecorded`: a live call with no recorded call.
13
13
  * - `unmade`: a recorded call with no live call.
14
- * - `orphan`: an artifact in the story file's artifact directory that belongs to no story in the file.
15
- * - `unreadable`: the story's artifact doesn't parse, or has another schema version.
14
+ * - `orphan`: a recording in the story file's recording directory that belongs to no story in the file, or one in the
15
+ * recording directory of a story file that is gone.
16
+ * - `unreadable`: the story's recording doesn't parse, or has another schema version.
16
17
  */
17
18
  export type StoryStaleEntry = {
18
19
  readonly kind: "unrecorded";
@@ -28,20 +29,20 @@ export type StoryStaleEntry = {
28
29
  readonly path: string;
29
30
  readonly problem: string;
30
31
  };
31
- /** The story's artifact as its run found it. */
32
- export type StoryRecording = {
32
+ /** The story's recording as the story's end read it: found, missing, or unreadable (a read that didn't fail). */
33
+ export type RecordingRead = {
33
34
  readonly kind: "found";
34
- readonly artifact: StoryArtifact;
35
+ readonly recording: StoryRecording;
35
36
  } | {
36
37
  readonly kind: "missing";
37
38
  } | {
38
39
  readonly kind: "unreadable";
39
40
  readonly problem: string;
40
41
  };
41
- /** What to do with the story's own artifact: write it, remove it, or leave it. */
42
- export type StoryArtifactChange = {
42
+ /** What to do with the story's own recording: write it, remove it, or leave it. */
43
+ export type RecordingChange = {
43
44
  readonly kind: "write";
44
- readonly artifact: StoryArtifact;
45
+ readonly recording: StoryRecording;
45
46
  } | {
46
47
  readonly kind: "remove";
47
48
  } | {
@@ -49,15 +50,15 @@ export type StoryArtifactChange = {
49
50
  };
50
51
  export interface StorySettleInput {
51
52
  readonly story: StoryIdentity;
52
- /** The story's artifact path, which an unreadable entry names. */
53
+ /** The story's recording path, which an unreadable entry names. */
53
54
  readonly path: string;
54
55
  readonly level: StoryRecordLevel;
55
56
  /** Whether the story's body returned without throwing. */
56
57
  readonly bodyPassed: boolean;
57
- readonly recording: StoryRecording;
58
+ readonly read: RecordingRead;
58
59
  /** The calls the story made, in order. */
59
60
  readonly live: readonly StoryCall[];
60
- /** The story file's orphans, when this story's end checks for them; none otherwise. */
61
+ /** The orphan recordings, when this story's end looks for them (`findOrphans`); none otherwise. */
61
62
  readonly orphans: readonly string[];
62
63
  }
63
64
  export interface StorySettlement {
@@ -70,9 +71,9 @@ export interface StorySettlement {
70
71
  readonly unreached: number;
71
72
  readonly divergences: readonly StoryDivergence[];
72
73
  readonly stale: readonly StoryStaleEntry[];
73
- readonly change: StoryArtifactChange;
74
- /** The orphans to remove. */
75
- readonly removeOrphans: readonly string[];
74
+ readonly change: RecordingChange;
75
+ /** Whether the end removes the orphan recordings, the `orphan` entries in `stale`. */
76
+ readonly removesOrphans: boolean;
76
77
  /** Whether the divergences are recorded as the new observations (`STORY_RECORD=all`). */
77
78
  readonly accepted: boolean;
78
79
  /** Why the story fails, beyond its body: a divergence, or a stale entry at `none`. */
@@ -80,15 +81,16 @@ export interface StorySettlement {
80
81
  }
81
82
  /**
82
83
  * Settles one story's end. Its live calls are aligned with the recorded ones (`alignCalls`); each `divergence` is a
83
- * divergence, and each `unrecorded` and `unmade` call, an unreadable artifact and each orphan is a stale entry. A
84
- * story whose body threw changes nothing and fails with its own error; the recorded calls after its last aligned call
85
- * count as unreached, not unmade. Otherwise, by level:
84
+ * divergence, and each `unrecorded` and `unmade` call, an unreadable recording and each orphan recording is a stale
85
+ * entry. A story whose body threw changes nothing and fails with its own error; the recorded calls after its last
86
+ * aligned call count as unreached, not unmade. Otherwise, by level:
86
87
  *
87
88
  * - `none` changes nothing, and fails on a divergence, else on a stale entry.
88
- * - `stale` fails on a divergence, changing nothing; otherwise it writes the artifact and removes the orphans.
89
- * - `all` writes the artifact and removes the orphans, accepting any divergence.
89
+ * - `stale` fails on a divergence, changing nothing; otherwise it writes the recording and removes the orphan
90
+ * recordings.
91
+ * - `all` writes the recording and removes the orphan recordings, accepting any divergence.
90
92
  *
91
- * The artifact written holds the live calls. A story that made no call has no artifact, so writing it removes one
93
+ * The recording written holds the live calls. A story that made no call has no recording, so writing it removes one
92
94
  * that is there.
93
95
  */
94
96
  export declare function settleStory(input: StorySettleInput): StorySettlement;
@@ -1,30 +1,31 @@
1
- // What a story's end decides: how its live calls compare with its artifact, which divergences and stale entries
1
+ // What a story's end decides: how its live calls compare with its recording, which divergences and stale entries
2
2
  // there are, what to write, and whether the story fails. Pure.
3
3
  import { alignCalls } from "./align.js";
4
- import { STORY_ARTIFACT_SCHEMA_VERSION } from "./artifact.js";
4
+ import { STORY_RECORDING_SCHEMA_VERSION } from "./recording.js";
5
5
  /**
6
6
  * Settles one story's end. Its live calls are aligned with the recorded ones (`alignCalls`); each `divergence` is a
7
- * divergence, and each `unrecorded` and `unmade` call, an unreadable artifact and each orphan is a stale entry. A
8
- * story whose body threw changes nothing and fails with its own error; the recorded calls after its last aligned call
9
- * count as unreached, not unmade. Otherwise, by level:
7
+ * divergence, and each `unrecorded` and `unmade` call, an unreadable recording and each orphan recording is a stale
8
+ * entry. A story whose body threw changes nothing and fails with its own error; the recorded calls after its last
9
+ * aligned call count as unreached, not unmade. Otherwise, by level:
10
10
  *
11
11
  * - `none` changes nothing, and fails on a divergence, else on a stale entry.
12
- * - `stale` fails on a divergence, changing nothing; otherwise it writes the artifact and removes the orphans.
13
- * - `all` writes the artifact and removes the orphans, accepting any divergence.
12
+ * - `stale` fails on a divergence, changing nothing; otherwise it writes the recording and removes the orphan
13
+ * recordings.
14
+ * - `all` writes the recording and removes the orphan recordings, accepting any divergence.
14
15
  *
15
- * The artifact written holds the live calls. A story that made no call has no artifact, so writing it removes one
16
+ * The recording written holds the live calls. A story that made no call has no recording, so writing it removes one
16
17
  * that is there.
17
18
  */
18
19
  export function settleStory(input) {
19
- const recorded = input.recording.kind === "found" ? input.recording.artifact.calls : [];
20
+ const recorded = input.read.kind === "found" ? input.read.recording.calls : [];
20
21
  const all = alignCalls(recorded, input.live);
21
22
  const reached = input.bodyPassed ? all.length : lastLiveIndex(all) + 1;
22
23
  const aligned = all.slice(0, reached);
23
24
  const unreached = all.length - reached;
24
25
  const divergences = aligned.flatMap((each) => each.kind === "divergence" ? [{ recorded: each.recorded, live: each.live }] : []);
25
26
  const stale = [
26
- ...(input.recording.kind === "unreadable"
27
- ? [{ kind: "unreadable", path: input.path, problem: input.recording.problem }]
27
+ ...(input.read.kind === "unreadable"
28
+ ? [{ kind: "unreadable", path: input.path, problem: input.read.problem }]
28
29
  : []),
29
30
  ...aligned.flatMap((each) => each.kind === "unrecorded"
30
31
  ? [{ kind: "unrecorded", call: each.live }]
@@ -34,7 +35,7 @@ export function settleStory(input) {
34
35
  ...input.orphans.map((path) => ({ kind: "orphan", path })),
35
36
  ];
36
37
  const settled = { aligned, unreached, divergences, stale };
37
- const leave = { change: { kind: "leave" }, removeOrphans: [], accepted: false };
38
+ const leave = { change: { kind: "leave" }, removesOrphans: false, accepted: false };
38
39
  if (!input.bodyPassed)
39
40
  return { ...settled, ...leave, failure: undefined };
40
41
  if (input.level === "none") {
@@ -49,20 +50,20 @@ export function settleStory(input) {
49
50
  return {
50
51
  ...settled,
51
52
  change: desiredChange(input),
52
- removeOrphans: input.orphans,
53
+ removesOrphans: true,
53
54
  accepted: divergences.length > 0,
54
55
  failure: undefined,
55
56
  };
56
57
  }
57
- /** The artifact that fits the story's live calls: one holding them, or none when it made no call. */
58
+ /** The recording that fits the story's live calls: one holding them, or none when it made no call. */
58
59
  function desiredChange(input) {
59
60
  if (input.live.length > 0) {
60
61
  return {
61
62
  kind: "write",
62
- artifact: { schemaVersion: STORY_ARTIFACT_SCHEMA_VERSION, story: input.story, calls: input.live },
63
+ recording: { schemaVersion: STORY_RECORDING_SCHEMA_VERSION, story: input.story, calls: input.live },
63
64
  };
64
65
  }
65
- return input.recording.kind === "missing" ? { kind: "leave" } : { kind: "remove" };
66
+ return input.read.kind === "missing" ? { kind: "leave" } : { kind: "remove" };
66
67
  }
67
68
  /** The index of the last aligned call the story made, -1 when it made none. */
68
69
  function lastLiveIndex(aligned) {
@@ -1,49 +1,50 @@
1
- import type { StoryIdentity } from "./artifact.ts";
1
+ import type { StoryIdentity } from "./recording.ts";
2
2
  import type { StoryAgents, StoryHandles, StoryHarness, StorySession } from "./definition.ts";
3
- import type { StoryArtifactGateway } from "./gateways.ts";
3
+ import type { StoryRecordingGateway } from "./gateways.ts";
4
4
  import type { StoryRecordLevel } from "./mode.ts";
5
- export interface StoryRunOptions {
5
+ export interface StoryStartOptions {
6
6
  readonly story: StoryIdentity;
7
- /** The story's artifact path (`artifactPath`). */
7
+ /** The story's recording path (`recordingPath`). */
8
8
  readonly path: string;
9
9
  readonly level: StoryRecordLevel;
10
10
  /**
11
11
  * Aborts when the story is stopped, as by a timeout. A story stopped before its end compares as one whose body
12
- * threw, so it changes nothing; one stopped while its end changes the artifact stops before the next change.
12
+ * threw, so it changes nothing; one stopped while its end changes the recording stops before the next change.
13
13
  */
14
14
  readonly signal?: AbortSignal;
15
15
  }
16
16
  /** How a story's end went. */
17
- export interface StoryRunEnd {
18
- /** One line per call, unreadable artifact and orphan (`storyEventLines`). */
17
+ export interface StoryEnd {
18
+ /** One line per call, unreadable recording and orphan recording (`storyEventLines`). */
19
19
  readonly events: readonly string[];
20
20
  /** The report, when the story fails or its body threw with something to report; otherwise `undefined`. */
21
21
  readonly report: string | undefined;
22
- /** What a passing story changed (`storyChangeLine`), or `undefined`. */
23
- readonly changeLine: string | undefined;
22
+ /** What a passing story changed, naming each call it rewrote (`storyChangeReport`), or `undefined`. */
23
+ readonly changeReport: string | undefined;
24
24
  /**
25
- * Why the story fails beyond its body: a `StoryDivergenceError`, a `StoryStaleError`, an artifact that couldn't be
25
+ * Why the story fails beyond its body: a `StoryDivergenceError`, a `StoryStaleError`, a recording that couldn't be
26
26
  * read, written or removed, or a session whose `close()` threw. `undefined` when nothing did.
27
27
  */
28
28
  readonly error: Error | undefined;
29
29
  }
30
- /** How a story's body ended, and the story file's orphans when this story's end checks for them (none otherwise). */
31
- export interface StoryRunFinish {
30
+ /** How a story's body ended, and the orphan recordings when this story's end looks for them (none otherwise). */
31
+ export interface StoryEndInput {
32
32
  readonly bodyPassed: boolean;
33
33
  readonly orphans: readonly string[];
34
34
  }
35
- export interface StoryRun<Agents> {
35
+ /** A story that started: its body calls tools through `handles` until the story ends. */
36
+ export interface StartedStory<Agents> {
36
37
  /** What the story's body gets: one handle per agent, each with a function per tool. */
37
38
  readonly handles: StoryHandles<Agents>;
38
39
  /**
39
- * Ends the story, once: whether its body passed, and the story file's orphans when this end checks for them.
40
+ * Ends the story, once: whether its body passed, and the orphan recordings when this end looks for them.
40
41
  * Closes the session, if one started, whatever else happens.
41
42
  */
42
- finish(end: StoryRunFinish): Promise<StoryRunEnd>;
43
+ end(input: StoryEndInput): Promise<StoryEnd>;
43
44
  }
44
45
  /**
45
- * Starts one story's run. Each tool call checks its input against the tool's schema (a `TypeError` when it doesn't
46
+ * Starts one story. Each tool call checks its input against the tool's schema (a `TypeError` when it doesn't
46
47
  * match), starts the session on the first call, runs the tool, and keeps its observation; a tool that throws keeps
47
48
  * nothing. Its input and observation must be JSON (a `TypeError` otherwise).
48
49
  */
49
- export declare function startStoryRun<Session extends StorySession, Agents extends StoryAgents<Session>>(harness: StoryHarness<Session, Agents>, options: StoryRunOptions, gateway: StoryArtifactGateway): StoryRun<Agents>;
50
+ export declare function startStory<Session extends StorySession, Agents extends StoryAgents<Session>>(harness: StoryHarness<Session, Agents>, options: StoryStartOptions, gateway: StoryRecordingGateway): StartedStory<Agents>;
@@ -1,25 +1,25 @@
1
- // One story's run, apart from Vitest: the handles its body calls tools through, and its end, which compares the
2
- // calls with the artifact, changes what the level allows, and closes the session. Domain logic over the artifact
3
- // gateway.
1
+ // One story from its start to its end, apart from Vitest: the handles its body calls tools through, and its end, which
2
+ // compares the calls with the recording, changes what the level allows, and closes the session. Domain logic over the
3
+ // recording gateway.
4
4
  import { StoryDivergenceError, StoryStaleError } from "./errors.js";
5
5
  import { toStoryJson } from "./json.js";
6
- import { storyChangeLine, storyEventLines, storyReport } from "./report.js";
6
+ import { storyChangeReport, storyEventLines, storyReport } from "./report.js";
7
7
  import { settleStory } from "./settle.js";
8
8
  /**
9
- * Starts one story's run. Each tool call checks its input against the tool's schema (a `TypeError` when it doesn't
9
+ * Starts one story. Each tool call checks its input against the tool's schema (a `TypeError` when it doesn't
10
10
  * match), starts the session on the first call, runs the tool, and keeps its observation; a tool that throws keeps
11
11
  * nothing. Its input and observation must be JSON (a `TypeError` otherwise).
12
12
  */
13
- export function startStoryRun(harness, options, gateway) {
13
+ export function startStory(harness, options, gateway) {
14
14
  const live = [];
15
15
  let session;
16
- let finished = false;
16
+ let ended = false;
17
17
  const startSession = () => {
18
18
  session ??= Promise.resolve().then(() => harness.start());
19
19
  return session;
20
20
  };
21
21
  const callTool = async (agent, name, raw) => {
22
- if (finished)
22
+ if (ended)
23
23
  throw new Error(`story: ${agent} calls ${name} after the story ended`);
24
24
  const tool = harness.agents[agent]?.tools[name];
25
25
  if (tool === undefined)
@@ -33,10 +33,10 @@ export function startStoryRun(harness, options, gateway) {
33
33
  const input = toStoryJson(parsed.data, `${agent} calls ${name} with input that must be JSON`);
34
34
  const index = live.push({ kind: "running" }) - 1;
35
35
  try {
36
- const result = await tool.run(await startSession(), parsed.data);
37
- const observation = toStoryJson(tool.observe(result), `${agent}'s ${name} tool observes its result as JSON`);
36
+ const returned = await tool.run(await startSession(), parsed.data);
37
+ const observation = toStoryJson(tool.observe(returned), `${agent}'s ${name} tool observes its return value as JSON`);
38
38
  live[index] = { kind: "done", call: { agent, tool: name, input, observation } };
39
- return result;
39
+ return returned;
40
40
  }
41
41
  catch (error) {
42
42
  live[index] = { kind: "threw" };
@@ -60,58 +60,79 @@ export function startStoryRun(harness, options, gateway) {
60
60
  return new Error(`story: the session's close() threw: ${messageOf(error)}`, { cause: error });
61
61
  }
62
62
  };
63
- const apply = async (settlement) => {
64
- const { change } = settlement;
63
+ /** Writes or removes the story's own recording, as `change` says; the error when that failed or was stopped. */
64
+ const changeRecording = async (change) => {
65
65
  const { signal } = options;
66
66
  if (change.kind === "write") {
67
- const written = await gateway.writeArtifact({
67
+ const written = await gateway.writeRecording({
68
68
  path: options.path,
69
- artifact: change.artifact,
69
+ recording: change.recording,
70
70
  ...signalOf(signal),
71
71
  });
72
72
  if (written.kind === "canceled")
73
- return stoppedBefore(`writing the artifact ${options.path}`);
73
+ return stoppedBefore(`writing the recording ${options.path}`);
74
74
  if (written.kind === "failed")
75
- return new Error(`story: couldn't write the artifact ${options.path}: ${written.message}`);
75
+ return new Error(`story: couldn't write the recording ${options.path}: ${written.message}`);
76
76
  }
77
77
  else if (change.kind === "remove") {
78
- const removed = await gateway.removeArtifact({ path: options.path, ...signalOf(signal) });
78
+ const removed = await gateway.removeRecording({ path: options.path, ...signalOf(signal) });
79
79
  if (removed.kind === "canceled")
80
- return stoppedBefore(`removing the artifact ${options.path}`);
80
+ return stoppedBefore(`removing the recording ${options.path}`);
81
81
  if (removed.kind === "failed")
82
- return new Error(`story: couldn't remove the artifact ${options.path}: ${removed.message}`);
82
+ return new Error(`story: couldn't remove the recording ${options.path}: ${removed.message}`);
83
83
  }
84
- for (const orphan of settlement.removeOrphans) {
85
- const removed = await gateway.removeArtifact({ path: orphan, ...signalOf(signal) });
84
+ return undefined;
85
+ };
86
+ /**
87
+ * Makes the changes `settlement` decided, in order: the story's own recording, then each orphan recording. Returns
88
+ * what it changed, up to the first change that failed or was stopped, and that change's error.
89
+ */
90
+ const apply = async (settlement) => {
91
+ const recordingError = await changeRecording(settlement.change);
92
+ if (recordingError !== undefined)
93
+ return { applied: { recording: false, orphans: [] }, error: recordingError };
94
+ const orphans = [];
95
+ const applied = (error) => ({
96
+ applied: { recording: settlement.change.kind !== "leave", orphans },
97
+ error,
98
+ });
99
+ if (!settlement.removesOrphans)
100
+ return applied(undefined);
101
+ // Two story files that end at once may both find a deleted story file's recordings, so one already gone
102
+ // (`missing`) is no failure.
103
+ for (const entry of settlement.stale) {
104
+ if (entry.kind !== "orphan")
105
+ continue;
106
+ const removed = await gateway.removeRecording({ path: entry.path, ...signalOf(options.signal) });
86
107
  if (removed.kind === "canceled")
87
- return stoppedBefore(`removing the orphan ${orphan}`);
88
- if (removed.kind === "failed")
89
- return new Error(`story: couldn't remove the orphan ${orphan}: ${removed.message}`);
108
+ return applied(stoppedBefore(`removing the orphan ${entry.path}`));
109
+ if (removed.kind === "failed") {
110
+ return applied(new Error(`story: couldn't remove the orphan ${entry.path}: ${removed.message}`));
111
+ }
112
+ orphans.push(entry.path);
90
113
  }
91
- return undefined;
114
+ return applied(undefined);
92
115
  };
93
- const settle = async (end) => {
116
+ const settle = async (input) => {
94
117
  const calls = live.flatMap((slot) => (slot.kind === "done" ? [slot.call] : []));
95
- const read = await gateway.readArtifact({ path: options.path });
118
+ const read = await gateway.readRecording({ path: options.path });
96
119
  if (read.kind === "failed") {
97
- const error = new Error(`story: couldn't read the artifact ${options.path}: ${read.message}`);
98
- return { events: [], report: undefined, changeLine: undefined, error };
120
+ const error = new Error(`story: couldn't read the recording ${options.path}: ${read.message}`);
121
+ return { events: [], report: undefined, changeReport: undefined, error };
99
122
  }
100
- const recording = read;
101
- // A story stopped while it ended, reading its artifact or finding its file's orphans, compares as one whose body
123
+ // A story stopped while it ended, reading its recording or finding orphan recordings, compares as one whose body
102
124
  // threw: the test has already failed, so nothing may be written for it.
103
- const bodyPassed = end.bodyPassed && options.signal?.aborted !== true;
125
+ const bodyPassed = input.bodyPassed && options.signal?.aborted !== true;
104
126
  const settlement = settleStory({
105
127
  story: options.story,
106
128
  path: options.path,
107
129
  level: options.level,
108
130
  bodyPassed,
109
- recording,
131
+ read,
110
132
  live: calls,
111
- orphans: end.orphans,
133
+ orphans: input.orphans,
112
134
  });
113
- const applyError = await apply(settlement);
114
- const applied = applyError === undefined;
135
+ const { applied, error: applyError } = await apply(settlement);
115
136
  const something = settlement.divergences.length > 0 || settlement.stale.length > 0 || settlement.unreached > 0;
116
137
  let report;
117
138
  let failure;
@@ -127,17 +148,19 @@ export function startStoryRun(harness, options, gateway) {
127
148
  return {
128
149
  events: storyEventLines(settlement, applied),
129
150
  report,
130
- changeLine: applied && bodyPassed ? storyChangeLine(options.story, options.path, settlement) : undefined,
151
+ changeReport: applyError === undefined && bodyPassed
152
+ ? storyChangeReport(options.story, options.path, settlement, applied)
153
+ : undefined,
131
154
  error: applyError ?? failure,
132
155
  };
133
156
  };
134
- const finish = async (end) => {
135
- if (finished)
157
+ const end = async (input) => {
158
+ if (ended)
136
159
  throw new Error("story: the story already ended");
137
- finished = true;
160
+ ended = true;
138
161
  let settled;
139
162
  try {
140
- settled = await settle(end);
163
+ settled = await settle(input);
141
164
  }
142
165
  finally {
143
166
  const closeError = await closeSession();
@@ -147,7 +170,7 @@ export function startStoryRun(harness, options, gateway) {
147
170
  }
148
171
  return settled;
149
172
  };
150
- return { handles, finish };
173
+ return { handles, end };
151
174
  }
152
175
  function signalOf(signal) {
153
176
  return signal === undefined ? {} : { signal };
@@ -1,6 +1,6 @@
1
1
  // The Vercel CLI driver's gateway seams: its Context (the process gateway and clock, which travel together), the
2
2
  // live Context, and `createVercelCli`, which takes a Context. Tests build the same shape over the fake and a clock
3
- // driven by hand. Not part of `@cnc-tools/storm/vercel-cli`'s published surface.
3
+ // driven by hand. Not part of `@vercel/storm/vercel-cli`'s published surface.
4
4
  import { systemVercelCliClock } from "./clock.js";
5
5
  import { liveVercelCliProcessGateway } from "./live/process-gateway.js";
6
6
  /** The live Context: real processes and the system clock. */
@@ -1,4 +1,4 @@
1
- // storm's Vercel CLI driver, exported as `@cnc-tools/storm/vercel-cli`: runs the production `vercel` CLI
1
+ // storm's Vercel CLI driver, exported as `@vercel/storm/vercel-cli`: runs the production `vercel` CLI
2
2
  // against a test's proxy, as a default identity or the token a call names, with `--token`, a saved login or logged
3
3
  // out, in directories the test's invocations share, and reports each invocation with tokens redacted. It builds on
4
4
  // the SDK only through `src/sdk/index.ts`, imports neither the Vitest adapter nor vitest, and depends otherwise only
@@ -1,5 +1,5 @@
1
- // storm's Vitest config helpers, exported as `@cnc-tools/storm/vitest/config`. A `vitest.config.ts` imports
2
- // this, never `@cnc-tools/storm/vitest`: loading the adapter's `test` extends vitest's, which throws inside a config
1
+ // storm's Vitest config helpers, exported as `@vercel/storm/vitest/config`. A `vitest.config.ts` imports
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
5
  import { sandboxCount } from "./sandbox.js";
@@ -18,7 +18,7 @@ declare module "vitest" {
18
18
  * Every test, whatever it asks for, appends test events to the run payload's `testEvents` file when it names one:
19
19
  * the file's start and finish, each attempt at a test, its start and how it ended, and each container start and how
20
20
  * long it took. A retried test reports each attempt; its final result comes from `stormReporter`
21
- * (`@cnc-tools/storm/vitest/config`), in vitest's main process. `stormEvents`, `stormFileEvents` and
21
+ * (`@vercel/storm/vitest/config`), in vitest's main process. `stormEvents`, `stormFileEvents` and
22
22
  * `stormTestEvents` are the adapter's own, which tests don't use.
23
23
  *
24
24
  * - `verbose` (per worker): whether the run is verbose, under a run's `--verbose`, from the run payload. Then
@@ -123,7 +123,7 @@ const fixtures = vitestTest
123
123
  * Every test, whatever it asks for, appends test events to the run payload's `testEvents` file when it names one:
124
124
  * the file's start and finish, each attempt at a test, its start and how it ended, and each container start and how
125
125
  * long it took. A retried test reports each attempt; its final result comes from `stormReporter`
126
- * (`@cnc-tools/storm/vitest/config`), in vitest's main process. `stormEvents`, `stormFileEvents` and
126
+ * (`@vercel/storm/vitest/config`), in vitest's main process. `stormEvents`, `stormFileEvents` and
127
127
  * `stormTestEvents` are the adapter's own, which tests don't use.
128
128
  *
129
129
  * - `verbose` (per worker): whether the run is verbose, under a run's `--verbose`, from the run payload. Then
@@ -1,9 +1,9 @@
1
- // storm's Vitest adapter, exported as `@cnc-tools/storm/vitest`: vitest's `test` extended with fixtures for
1
+ // storm's Vitest adapter, exported as `@vercel/storm/vitest`: vitest's `test` extended with fixtures for
2
2
  // the worker's Testserver sandbox, a container (shared by a test file's tests unless `containerScope` is `'test'`),
3
3
  // its seeder and its proxy. A `vitest.config.ts` can't import it, since extending vitest's `test` throws there;
4
- // `testserverWorkers` is in `./config.ts` (`@cnc-tools/storm/vitest/config`) for that reason, and isn't re-exported
4
+ // `testserverWorkers` is in `./config.ts` (`@vercel/storm/vitest/config`) for that reason, and isn't re-exported
5
5
  // here. It imports the SDK only through `src/sdk/index.ts`, and the SDK never imports it. Besides Node builtins and
6
- // the SDK, it depends only on `vitest`, an optional peer dependency of `@cnc-tools/storm`; `.oxlintrc.json` checks
6
+ // the SDK, it depends only on `vitest`, an optional peer dependency of `@vercel/storm`; `.oxlintrc.json` checks
7
7
  // the boundary.
8
8
  export { CONTAINER_SCOPE } from "./container-scope.js";
9
9
  export { test } from "./fixtures.js";
@@ -1,4 +1,4 @@
1
- // Planning a Vitest run before any Testserver sandbox is leased, exported as `@cnc-tools/storm/vitest/plan`: finding
1
+ // Planning a Vitest run before any Testserver sandbox is leased, exported as `@vercel/storm/vitest/plan`: finding
2
2
  // `vitest` in `node_modules/.bin`, counting the tests `vitest run <args>` would run, sizing the Testserver sandboxes
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cnc-tools/storm",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "Run a command against Vercel Testserver sandboxes",
5
5
  "repository": {
6
6
  "type": "git",
@@ -90,8 +90,8 @@
90
90
  "registry": "https://registry.npmjs.org/"
91
91
  },
92
92
  "dependencies": {
93
- "@cnc-tools/cli-kit": "^0.3.2",
94
- "@vercel/clinkr": "npm:clinkr@^0.8.2",
93
+ "@cnc-tools/cli-kit": "^0.3.3",
94
+ "@vercel/clinkr": "npm:clinkr@^0.9.1",
95
95
  "@vercel/sandbox": "3.9.0",
96
96
  "zod": "^4.6.5"
97
97
  },