@cnc-tools/storm 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build-info.js +1 -1
- package/dist/combine-errors.js +2 -2
- package/dist/commands/dashboard.js +1 -1
- package/dist/commands/{run → exec}/cleanup.d.ts +1 -1
- package/dist/commands/{run → exec}/cleanup.js +1 -1
- package/dist/commands/{run/outcomes.d.ts → exec/command.d.ts} +103 -112
- package/dist/commands/exec/command.js +23 -0
- package/dist/commands/{run → exec}/job-summary.d.ts +5 -1
- package/dist/commands/{run → exec}/job-summary.js +5 -2
- package/dist/commands/{run → exec}/live-view.js +29 -13
- package/dist/commands/exec/metadata.d.ts +69 -0
- package/dist/commands/exec/metadata.js +55 -0
- package/dist/commands/{run → exec}/mint-failed.js +4 -4
- package/dist/commands/exec/outcomes.d.ts +664 -0
- package/dist/commands/exec/outcomes.js +347 -0
- package/dist/commands/{run → exec}/progress.d.ts +14 -2
- package/dist/commands/{run → exec}/progress.js +54 -9
- package/dist/commands/exec/run-command.d.ts +227 -0
- package/dist/commands/exec/run-command.js +696 -0
- package/dist/commands/exec/run-metadata.d.ts +59 -0
- package/dist/commands/exec/run-metadata.js +61 -0
- package/dist/commands/{run → exec}/run-record.d.ts +110 -5
- package/dist/commands/{run → exec}/run-record.js +57 -1
- package/dist/commands/exec/testserver-flags.d.ts +48 -0
- package/dist/commands/exec/testserver-flags.js +80 -0
- package/dist/commands/{run → exec}/view.js +36 -4
- package/dist/commands/runs/facts.d.ts +25 -0
- package/dist/commands/runs/facts.js +38 -5
- package/dist/commands/runs/list/command.d.ts +25 -0
- package/dist/commands/runs/list/outcomes.d.ts +25 -0
- package/dist/commands/runs/logs/metadata.js +1 -1
- package/dist/commands/runs/logs/outcomes.js +4 -1
- package/dist/commands/runs/past-run.d.ts +2 -2
- package/dist/commands/runs/past-run.js +2 -2
- package/dist/commands/runs/show/command.d.ts +25 -0
- package/dist/commands/runs/show/metadata.js +2 -2
- package/dist/commands/runs/show/outcomes.d.ts +25 -0
- package/dist/commands/runs/show/outcomes.js +37 -5
- package/dist/commands/vitest/command.d.ts +325 -0
- package/dist/commands/vitest/command.js +138 -0
- package/dist/commands/vitest/metadata.d.ts +69 -0
- package/dist/commands/vitest/metadata.js +35 -0
- package/dist/commands/vitest/outcomes.d.ts +298 -0
- package/dist/commands/vitest/outcomes.js +77 -0
- package/dist/config/index.d.ts +2 -1
- package/dist/config/index.js +1 -0
- package/dist/config/resolve.d.ts +3 -3
- package/dist/config/resolve.js +3 -3
- package/dist/config/resource-config.d.ts +2 -2
- package/dist/config/schema.d.ts +1 -1
- package/dist/config/set.d.ts +15 -4
- package/dist/config/set.js +28 -12
- package/dist/config-file/define.d.ts +8 -6
- package/dist/context.d.ts +6 -3
- package/dist/context.js +4 -2
- package/dist/core/command-provider.d.ts +1 -1
- package/dist/core/events.d.ts +9 -7
- package/dist/core/presentation.js +1 -1
- package/dist/core/presentations.js +1 -1
- package/dist/core/run-state.d.ts +30 -6
- package/dist/core/run-state.js +19 -4
- package/dist/core/run.d.ts +17 -4
- package/dist/core/run.js +61 -25
- package/dist/resources/testserver/command.d.ts +1 -1
- package/dist/resources/testserver/command.js +1 -1
- package/dist/resources/testserver/config.d.ts +1 -1
- package/dist/resources/testserver/config.js +3 -2
- package/dist/resources/testserver/credential-facts.js +1 -1
- package/dist/resources/testserver/resource.d.ts +2 -2
- package/dist/resources/testserver/sandbox/create.d.ts +2 -2
- package/dist/resources/testserver/sandbox/create.js +2 -2
- package/dist/resources.d.ts +9 -6
- package/dist/resources.js +3 -3
- package/dist/runner/events.d.ts +64 -1
- package/dist/runner/gateways.d.ts +17 -6
- package/dist/runner/index.d.ts +5 -4
- package/dist/runner/index.js +4 -3
- package/dist/runner/live/snapshot-records.js +18 -4
- package/dist/runner/prepare.d.ts +23 -4
- package/dist/runner/prepare.js +13 -3
- package/dist/runner/ready.d.ts +7 -3
- package/dist/runner/ready.js +11 -5
- package/dist/runner/scope.d.ts +17 -1
- package/dist/runner/scope.js +4 -0
- package/dist/runner/snapshot-build.d.ts +3 -1
- package/dist/runner/snapshot-build.js +12 -2
- package/dist/runner/snapshot-cache.d.ts +46 -8
- package/dist/runner/snapshot-cache.js +60 -11
- package/dist/runner/snapshot-key.d.ts +12 -1
- package/dist/runner/snapshot-key.js +17 -1
- package/dist/runner/snapshot-save.d.ts +53 -0
- package/dist/runner/snapshot-save.js +148 -0
- package/dist/sdk/index.js +1 -1
- package/dist/sdk/payload/payload.d.ts +2 -2
- package/dist/sdk/payload/payload.js +2 -2
- package/dist/story/align.d.ts +1 -1
- package/dist/story/align.js +1 -1
- package/dist/story/definition.d.ts +22 -15
- package/dist/story/definition.js +2 -2
- package/dist/story/errors.js +1 -1
- package/dist/story/gateways.d.ts +45 -25
- package/dist/story/gateways.js +2 -2
- package/dist/story/host.d.ts +11 -8
- package/dist/story/host.js +37 -37
- package/dist/story/index.d.ts +1 -1
- package/dist/story/index.js +4 -4
- package/dist/story/json.d.ts +1 -1
- package/dist/story/json.js +2 -2
- package/dist/story/live/recording-gateway.d.ts +2 -0
- package/dist/story/live/{artifact-gateway.js → recording-gateway.js} +33 -12
- package/dist/story/mode.d.ts +2 -2
- package/dist/story/mode.js +1 -1
- package/dist/story/orphans.d.ts +23 -5
- package/dist/story/orphans.js +44 -8
- package/dist/story/recording.d.ts +62 -0
- package/dist/story/{artifact.js → recording.js} +31 -27
- package/dist/story/report.d.ts +21 -9
- package/dist/story/report.js +37 -25
- package/dist/story/settle.d.ts +23 -21
- package/dist/story/settle.js +17 -16
- package/dist/story/{run.d.ts → start.d.ts} +18 -17
- package/dist/story/{run.js → start.js} +66 -43
- package/dist/vercel-cli/driver.d.ts +1 -1
- package/dist/vercel-cli/entry.d.ts +1 -1
- package/dist/vercel-cli/entry.js +1 -1
- package/dist/vercel-cli/verbose.d.ts +2 -2
- package/dist/vercel-cli/verbose.js +2 -2
- package/dist/vitest/config.d.ts +5 -5
- package/dist/vitest/config.js +5 -5
- package/dist/vitest/find-vitest.d.ts +7 -0
- package/dist/vitest/find-vitest.js +28 -0
- package/dist/vitest/fixtures.d.ts +2 -2
- package/dist/vitest/fixtures.js +3 -3
- package/dist/vitest/gateways.d.ts +37 -6
- package/dist/vitest/gateways.js +3 -2
- package/dist/vitest/live/list-gateway.d.ts +7 -3
- package/dist/vitest/live/list-gateway.js +55 -8
- package/dist/vitest/plan.d.ts +41 -8
- package/dist/vitest/plan.js +47 -16
- package/dist/vitest/sandbox.d.ts +1 -1
- package/dist/vitest/sandbox.js +1 -1
- package/dist/vitest/test-events.d.ts +2 -2
- package/dist/vitest/test-events.js +3 -3
- package/dist/vitest/test-results.d.ts +1 -1
- package/dist/vitest/test-results.js +1 -1
- package/dist/vitest/types.d.ts +1 -1
- package/package.json +2 -2
- package/skills/overview.md +5 -4
- package/skills/read-run-output.md +1 -1
- package/dist/commands/run/command.d.ts +0 -327
- package/dist/commands/run/command.js +0 -620
- package/dist/commands/run/metadata.d.ts +0 -47
- package/dist/commands/run/metadata.js +0 -83
- package/dist/commands/run/outcomes.js +0 -332
- package/dist/story/artifact.d.ts +0 -60
- package/dist/story/live/artifact-gateway.d.ts +0 -2
- /package/dist/commands/{run → exec}/live-view.d.ts +0 -0
- /package/dist/commands/{run → exec}/mint-failed.d.ts +0 -0
- /package/dist/commands/{run → exec}/redaction.d.ts +0 -0
- /package/dist/commands/{run → exec}/redaction.js +0 -0
- /package/dist/commands/{run → exec}/run-collector.d.ts +0 -0
- /package/dist/commands/{run → exec}/run-collector.js +0 -0
- /package/dist/commands/{run → exec}/tests-summary.d.ts +0 -0
- /package/dist/commands/{run → exec}/tests-summary.js +0 -0
- /package/dist/commands/{run → exec}/text.d.ts +0 -0
- /package/dist/commands/{run → exec}/text.js +0 -0
- /package/dist/commands/{run → exec}/view.d.ts +0 -0
- /package/dist/commands/{run → exec}/waterfall.d.ts +0 -0
- /package/dist/commands/{run → exec}/waterfall.js +0 -0
- /package/dist/commands/{run → exec}/worker-chart.d.ts +0 -0
- /package/dist/commands/{run → exec}/worker-chart.js +0 -0
|
@@ -10,7 +10,10 @@ export const SNAPSHOT_EXPIRATION_MS = 7 * 24 * 60 * 60 * 1000;
|
|
|
10
10
|
export const SNAPSHOT_MIN_REMAINING_MS = 60 * 60 * 1000;
|
|
11
11
|
/**
|
|
12
12
|
* An entry's identity: the first 32 hex characters of sha256 over its team id, project id, region, runtime, recipe
|
|
13
|
-
* name, snapshot key and
|
|
13
|
+
* name, snapshot key, base and, for a branch snapshot only, branch and checkout root, joined with NUL. Entries with
|
|
14
|
+
* one identity replace each other: a base snapshot's entry replaces the base snapshot's at its base, and a branch
|
|
15
|
+
* snapshot's replaces that branch's in that checkout at its base. A base snapshot's identity is the one it had before
|
|
16
|
+
* branch snapshots existed.
|
|
14
17
|
*/
|
|
15
18
|
export function snapshotEntryIdentity(entry) {
|
|
16
19
|
return createHash("sha256")
|
|
@@ -22,10 +25,15 @@ export function snapshotEntryIdentity(entry) {
|
|
|
22
25
|
entry.recipeName,
|
|
23
26
|
entry.snapshotKey,
|
|
24
27
|
entry.base,
|
|
28
|
+
...(isBranchEntry(entry) ? [entry.branch, entry.repoRoot] : []),
|
|
25
29
|
].join("\0"))
|
|
26
30
|
.digest("hex")
|
|
27
31
|
.slice(0, 32);
|
|
28
32
|
}
|
|
33
|
+
/** Whether `entry` records a branch snapshot, saved from a run on its branch, rather than a base snapshot. */
|
|
34
|
+
export function isBranchEntry(entry) {
|
|
35
|
+
return entry.branch !== undefined && entry.head !== undefined && entry.repoRoot !== undefined;
|
|
36
|
+
}
|
|
29
37
|
/** The name of the file that records `entry`: its identity and `.json`. */
|
|
30
38
|
export function snapshotEntryFileName(entry) {
|
|
31
39
|
return `${snapshotEntryIdentity(entry)}.json`;
|
|
@@ -39,14 +47,16 @@ export function hasTimeLeft(entry, now) {
|
|
|
39
47
|
return Date.parse(entry.expiresAt) - now.getTime() > SNAPSHOT_MIN_REMAINING_MS;
|
|
40
48
|
}
|
|
41
49
|
/**
|
|
42
|
-
* Reads the cache for the runner snapshots a run of `recipe` may start from. It removes expired entries'
|
|
43
|
-
* keeps the entries for the recipe's region, runtime and name with more than an hour left, whose base HEAD
|
|
44
|
-
* (a base missing from the clone doesn't), and whose snapshot key, recomputed at that entry's base, is the
|
|
45
|
-
* recorded.
|
|
50
|
+
* Reads the cache for the runner snapshots a run of `recipe` on `branch` may start from. It removes expired entries'
|
|
51
|
+
* files, and keeps the entries for the recipe's region, runtime and name with more than an hour left, whose base HEAD
|
|
52
|
+
* contains (a base missing from the clone doesn't), and whose snapshot key, recomputed at that entry's base, is the
|
|
53
|
+
* one recorded. Of branch snapshots it keeps only `branch`'s saved from this checkout, `repoRoot`, whatever HEAD
|
|
54
|
+
* commit saved them; with `branch` null, a detached HEAD, it keeps none. A branch of the same name in another checkout
|
|
55
|
+
* may hold other code, so its snapshot never carries over. A failure along the way is a note, never a refusal.
|
|
46
56
|
*/
|
|
47
57
|
export async function findSnapshotCandidates(context, request) {
|
|
48
58
|
const { checkout, runnerSnapshots } = context;
|
|
49
|
-
const { repoRoot, recipe } = request;
|
|
59
|
+
const { repoRoot, recipe, branch } = request;
|
|
50
60
|
const notes = [];
|
|
51
61
|
const listed = await runnerSnapshots.listEntries();
|
|
52
62
|
if (!listed.ok)
|
|
@@ -63,6 +73,7 @@ export async function findSnapshotCandidates(context, request) {
|
|
|
63
73
|
if (entry.region === recipe.region &&
|
|
64
74
|
entry.runtime === recipe.runtime &&
|
|
65
75
|
entry.recipeName === recipe.name &&
|
|
76
|
+
(isBranchEntry(entry) ? entry.branch === branch && entry.repoRoot === repoRoot : entry.branch === undefined) &&
|
|
66
77
|
hasTimeLeft(entry, now))
|
|
67
78
|
live.push(entry);
|
|
68
79
|
}
|
|
@@ -113,14 +124,52 @@ export async function findSnapshotCandidates(context, request) {
|
|
|
113
124
|
return { candidates, notes };
|
|
114
125
|
}
|
|
115
126
|
/**
|
|
116
|
-
* Picks the runner snapshot a run starts from, once the credential names its team and project
|
|
117
|
-
*
|
|
118
|
-
*
|
|
127
|
+
* Picks the runner snapshot a run starts from, once the credential names its team and project. Of the candidates for
|
|
128
|
+
* them it finds the base nearest HEAD, the one every other candidate's base is an ancestor of; when bases are on
|
|
129
|
+
* separate lines of history, the newest commit. Of the candidates at that base it picks a branch snapshot over the
|
|
130
|
+
* base snapshot, then the one that expires later, so a branch snapshot of an older base never beats a nearer base.
|
|
131
|
+
* `undefined` when none is for them.
|
|
119
132
|
*/
|
|
120
133
|
export function pickSnapshot(candidates, owner) {
|
|
121
134
|
const owned = candidates
|
|
122
135
|
.filter(({ entry }) => entry.teamId === owner.teamId && entry.projectId === owner.projectId)
|
|
123
136
|
.toSorted((a, b) => b.commitTime - a.commitTime || Date.parse(b.entry.expiresAt) - Date.parse(a.entry.expiresAt));
|
|
124
|
-
const nearest = owned.find((candidate) => owned.every((other) => other.entry.base === candidate.entry.base || candidate.ancestorBases.includes(other.entry.base)));
|
|
125
|
-
|
|
137
|
+
const nearest = owned.find((candidate) => owned.every((other) => other.entry.base === candidate.entry.base || candidate.ancestorBases.includes(other.entry.base))) ?? owned[0];
|
|
138
|
+
if (nearest === undefined)
|
|
139
|
+
return undefined;
|
|
140
|
+
return owned
|
|
141
|
+
.filter(({ entry }) => entry.base === nearest.entry.base)
|
|
142
|
+
.toSorted((a, b) => Number(isBranchEntry(b.entry)) - Number(isBranchEntry(a.entry)) ||
|
|
143
|
+
Date.parse(b.entry.expiresAt) - Date.parse(a.entry.expiresAt))[0];
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Removes every cached branch snapshot entry of `branch` in the checkout at `repoRoot` for `owner`'s team and project
|
|
147
|
+
* and the recipe's region, runtime and name, whatever its base, so a run after `--rebuild-snapshot` doesn't start
|
|
148
|
+
* from a branch snapshot the rebuild meant to replace. The snapshots themselves are left to expire. A failure is
|
|
149
|
+
* reported, never a refusal.
|
|
150
|
+
*/
|
|
151
|
+
export async function dropBranchSnapshots(runnerSnapshots, request) {
|
|
152
|
+
const { branch, repoRoot, owner, recipe } = request;
|
|
153
|
+
const listed = await runnerSnapshots.listEntries();
|
|
154
|
+
if (!listed.ok)
|
|
155
|
+
return { snapshotIds: [], failures: [listed.failure] };
|
|
156
|
+
const snapshotIds = [];
|
|
157
|
+
const failures = [];
|
|
158
|
+
for (const entry of listed.value.entries) {
|
|
159
|
+
if (!isBranchEntry(entry) ||
|
|
160
|
+
entry.branch !== branch ||
|
|
161
|
+
entry.repoRoot !== repoRoot ||
|
|
162
|
+
entry.teamId !== owner.teamId ||
|
|
163
|
+
entry.projectId !== owner.projectId ||
|
|
164
|
+
entry.region !== recipe.region ||
|
|
165
|
+
entry.runtime !== recipe.runtime ||
|
|
166
|
+
entry.recipeName !== recipe.name)
|
|
167
|
+
continue;
|
|
168
|
+
const removed = await runnerSnapshots.removeEntry(entry);
|
|
169
|
+
if (removed.ok)
|
|
170
|
+
snapshotIds.push(entry.snapshotId);
|
|
171
|
+
else
|
|
172
|
+
failures.push(removed.failure);
|
|
173
|
+
}
|
|
174
|
+
return { snapshotIds, failures };
|
|
126
175
|
}
|
|
@@ -15,6 +15,12 @@ export declare const STAGED_FILES: {
|
|
|
15
15
|
readonly untrackedTarball: "untracked.tgz";
|
|
16
16
|
readonly untrackedFileList: "untracked-files";
|
|
17
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Resets the repository to its root commit, which holds the base's tracked files (`baseIndexScript`): the real base
|
|
20
|
+
* commit isn't in a sandbox's repository. Then removes untracked files and directories, nested Git repositories
|
|
21
|
+
* included, keeping ignored ones such as `node_modules` and build outputs.
|
|
22
|
+
*/
|
|
23
|
+
export declare const RESET_TO_BASE: readonly string[];
|
|
18
24
|
/** A bash script that stops at the first failure and runs in the repository's root. */
|
|
19
25
|
export declare function bashScript(lines: readonly string[]): string;
|
|
20
26
|
/**
|
|
@@ -22,7 +28,12 @@ export declare function bashScript(lines: readonly string[]): string;
|
|
|
22
28
|
* (`<staging>/base-files`), before the warm steps. `git add -A` would drop tracked files `.gitignore` matches.
|
|
23
29
|
*/
|
|
24
30
|
export declare function baseIndexScript(base: string, staging: string): string;
|
|
25
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Applies and commits a run's patch and untracked files, uploaded to `staging`, in a runner sandbox. It first resets
|
|
33
|
+
* the repository to its root commit, the base's tracked files, and removes untracked files and nested Git
|
|
34
|
+
* repositories `.gitignore` doesn't match, so a branch snapshot applies as cleanly as a base snapshot even when its
|
|
35
|
+
* save left something behind.
|
|
36
|
+
*/
|
|
26
37
|
export declare function applyScript(staging: string): string;
|
|
27
38
|
/**
|
|
28
39
|
* The snapshot key: sha256 hex over `format=<SNAPSHOT_FORMAT>`, each toolchain step's label and script, the
|
|
@@ -20,6 +20,16 @@ export const STAGED_FILES = {
|
|
|
20
20
|
};
|
|
21
21
|
/** The identity of the commits the scripts make, with no hook or signing in the way. */
|
|
22
22
|
const GIT_IDENTITY = "-c user.email=storm-runner@vercel.invalid -c user.name='storm runner' -c commit.gpgsign=false";
|
|
23
|
+
/**
|
|
24
|
+
* Resets the repository to its root commit, which holds the base's tracked files (`baseIndexScript`): the real base
|
|
25
|
+
* commit isn't in a sandbox's repository. Then removes untracked files and directories, nested Git repositories
|
|
26
|
+
* included, keeping ignored ones such as `node_modules` and build outputs.
|
|
27
|
+
*/
|
|
28
|
+
export const RESET_TO_BASE = [
|
|
29
|
+
"root=$(git rev-list --max-parents=0 HEAD)",
|
|
30
|
+
'git reset -q --hard "$root"',
|
|
31
|
+
"git clean -ffdq",
|
|
32
|
+
];
|
|
23
33
|
/** A bash script that stops at the first failure and runs in the repository's root. */
|
|
24
34
|
export function bashScript(lines) {
|
|
25
35
|
return ["set -euo pipefail", `cd ${REMOTE_ROOT}`, ...lines].join("\n");
|
|
@@ -40,12 +50,18 @@ export function baseIndexScript(base, staging) {
|
|
|
40
50
|
`git ${GIT_IDENTITY} commit -q --no-verify -m 'base ${base}'`,
|
|
41
51
|
]);
|
|
42
52
|
}
|
|
43
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Applies and commits a run's patch and untracked files, uploaded to `staging`, in a runner sandbox. It first resets
|
|
55
|
+
* the repository to its root commit, the base's tracked files, and removes untracked files and nested Git
|
|
56
|
+
* repositories `.gitignore` doesn't match, so a branch snapshot applies as cleanly as a base snapshot even when its
|
|
57
|
+
* save left something behind.
|
|
58
|
+
*/
|
|
44
59
|
export function applyScript(staging) {
|
|
45
60
|
const patch = `${staging}/${STAGED_FILES.patch}`;
|
|
46
61
|
const tarball = `${staging}/${STAGED_FILES.untrackedTarball}`;
|
|
47
62
|
const fileList = `${staging}/${STAGED_FILES.untrackedFileList}`;
|
|
48
63
|
return bashScript([
|
|
64
|
+
...RESET_TO_BASE,
|
|
49
65
|
// A build may have rewritten tracked files with the same content.
|
|
50
66
|
"git update-index -q --refresh || true",
|
|
51
67
|
`if [ -s ${patch} ]; then git apply --index --binary ${patch}; fi`,
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { RunnerContext } from "./context.ts";
|
|
2
|
+
import type { RunnerProgress, RunnerSave } from "./events.ts";
|
|
3
|
+
import type { ReadyRunner } from "./ready.ts";
|
|
4
|
+
import type { RunnerSandboxScope } from "./scope.ts";
|
|
5
|
+
/** The directories the temp scrub empties: `/tmp`, `/var/tmp`, and `$TMPDIR` when it is set. */
|
|
6
|
+
export declare const TEMP_DIRECTORIES: readonly string[];
|
|
7
|
+
/**
|
|
8
|
+
* Resets the working tree in `root` to its root commit, the base's tracked files (`baseIndexScript`), and removes
|
|
9
|
+
* untracked files and nested Git repositories that `.gitignore` doesn't match: the same reset the next run's apply
|
|
10
|
+
* starts with (`RESET_TO_BASE`). Ignored files, such as `node_modules`, build outputs and the turbo cache, stay.
|
|
11
|
+
*
|
|
12
|
+
* It leaves `.git` alone, so the run's commit and anything else the command put in Git stay in the snapshot. Cleaning
|
|
13
|
+
* history adds no correctness: the next run resets before it applies. Nor does it hide the run's changes: the ignored
|
|
14
|
+
* files the snapshot keeps hold their build outputs. And `git prune` can't promise it either, since it removes only
|
|
15
|
+
* loose objects, not packed ones.
|
|
16
|
+
*/
|
|
17
|
+
export declare function scrubGitScript(root?: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Empties each of `directories`, shell words that may expand to nothing: deletes what it holds, then, for anything
|
|
20
|
+
* left, tries again with `sudo -n`. Fails, naming the directory and what is left, when one still holds something.
|
|
21
|
+
*/
|
|
22
|
+
export declare function scrubTempScript(directories?: readonly string[]): string;
|
|
23
|
+
/** What saving a branch snapshot is asked to save: the ready runner sandbox, and the branch and commit it is for. */
|
|
24
|
+
export interface SaveBranchSnapshotRequest {
|
|
25
|
+
/** The runner sandbox the command ran in, and the runner snapshot it started from. */
|
|
26
|
+
readonly ready: ReadyRunner;
|
|
27
|
+
/** HEAD's branch as the run started, which the snapshot is for. */
|
|
28
|
+
readonly branch: string;
|
|
29
|
+
/** HEAD's commit as the run started, a full SHA. */
|
|
30
|
+
readonly head: string;
|
|
31
|
+
}
|
|
32
|
+
/** How a save that ran ended: a detached HEAD's `skipped` is decided before the run (`prepareRunner`). */
|
|
33
|
+
type BranchSnapshotSave = Exclude<RunnerSave, {
|
|
34
|
+
readonly kind: "skipped";
|
|
35
|
+
}>;
|
|
36
|
+
/**
|
|
37
|
+
* Saves the runner sandbox, once the command ended, as a branch snapshot of the run's branch. The run's plan gave the
|
|
38
|
+
* scope no keep time (`RunnerSandboxPlan`), so however the save ends, closing stops and deletes the sandbox. It resets
|
|
39
|
+
* the working tree to the base the sandbox started from, leaving `.git` alone, empties the temp directories, saves the
|
|
40
|
+
* sandbox as a runner snapshot, which the scope then deletes, and records the entry: the started-from entry's owner,
|
|
41
|
+
* recipe, snapshot key and base, with the branch, the HEAD commit and the checkout's root. Its entry replaces the
|
|
42
|
+
* branch's entry in that checkout at that base; the snapshot it replaces is left to expire, since a run on this
|
|
43
|
+
* machine may be starting from it. Nothing here changes the run's outcome: each way it ends is a note.
|
|
44
|
+
*
|
|
45
|
+
* It searches nothing for the run's secrets: the snapshot keeps what the command wrote to `$HOME` and the ignored
|
|
46
|
+
* files, such as a resource's token, as a kept runner sandbox does. The token is limited to one test resource, and
|
|
47
|
+
* only a later run on the branch from this checkout, which gets the same token, starts from the snapshot.
|
|
48
|
+
*/
|
|
49
|
+
export declare function saveBranchSnapshot(context: Pick<RunnerContext, "runnerSandboxes" | "runnerSnapshots" | "clock">, request: SaveBranchSnapshotRequest, control: {
|
|
50
|
+
readonly scope: RunnerSandboxScope;
|
|
51
|
+
readonly signal: AbortSignal;
|
|
52
|
+
}, progress: RunnerProgress): Promise<BranchSnapshotSave>;
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// Saving a runner run's runner sandbox as a branch snapshot once its command ended (`--save-snapshot`): reset the
|
|
2
|
+
// working tree to its base and empty the temp directories, save the sandbox as a runner snapshot, and record it in the
|
|
3
|
+
// cache for the run's branch in its checkout. The snapshot keeps the rest of what the command left, a run secret it
|
|
4
|
+
// wrote included.
|
|
5
|
+
import { lineSplitter, outputTail, splitLines } from "./output.js";
|
|
6
|
+
import { SNAPSHOT_EXPIRATION_MS } from "./snapshot-cache.js";
|
|
7
|
+
import { REMOTE_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 = REMOTE_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 branch snapshot of the run's branch. The run's plan gave the
|
|
46
|
+
* scope no keep time (`RunnerSandboxPlan`), so however the save ends, closing stops and deletes the sandbox. It resets
|
|
47
|
+
* the working tree to the base the sandbox started from, leaving `.git` alone, empties the temp directories, saves the
|
|
48
|
+
* sandbox as a runner snapshot, which the scope then deletes, and records the entry: the started-from entry's owner,
|
|
49
|
+
* recipe, snapshot key and base, with the branch, the HEAD commit and the checkout's root. Its entry replaces the
|
|
50
|
+
* branch's entry in that checkout at that base; the snapshot it replaces is left to expire, since a run on this
|
|
51
|
+
* machine may be starting from it. Nothing here changes the run's outcome: each way it ends is a note.
|
|
52
|
+
*
|
|
53
|
+
* It searches nothing for the run's secrets: the snapshot keeps what the command wrote to `$HOME` and the ignored
|
|
54
|
+
* files, such as a resource's token, as a kept runner sandbox does. The token is limited to one test resource, and
|
|
55
|
+
* only a later run on the branch from this checkout, which gets the same token, starts from the snapshot.
|
|
56
|
+
*/
|
|
57
|
+
export async function saveBranchSnapshot(context, request, control, progress) {
|
|
58
|
+
const save = await saveOnce(context, request, control, progress);
|
|
59
|
+
if (save.kind !== "saved")
|
|
60
|
+
await progress.emit({ kind: "branch-snapshot-not-saved", save });
|
|
61
|
+
return save;
|
|
62
|
+
}
|
|
63
|
+
async function saveOnce(context, request, control, progress) {
|
|
64
|
+
const { ready, branch, head } = request;
|
|
65
|
+
const { scope, signal } = control;
|
|
66
|
+
const stopped = () => signal.aborted || scope.closed;
|
|
67
|
+
if (stopped())
|
|
68
|
+
return { kind: "stopped" };
|
|
69
|
+
const { sandbox, startedFrom } = ready;
|
|
70
|
+
const startedAt = context.clock.now().getTime();
|
|
71
|
+
await progress.emit({ kind: "branch-snapshot-saving", branch });
|
|
72
|
+
for (const script of [scrubGitScript(), scrubTempScript()]) {
|
|
73
|
+
if (stopped())
|
|
74
|
+
return { kind: "stopped" };
|
|
75
|
+
const ran = await runSaveScript(context, sandbox, script, signal);
|
|
76
|
+
if (ran.kind === "stopped")
|
|
77
|
+
return ran;
|
|
78
|
+
if (ran.kind === "failed")
|
|
79
|
+
return { kind: "failed", step: "scrub", message: ran.message };
|
|
80
|
+
}
|
|
81
|
+
if (stopped())
|
|
82
|
+
return { kind: "stopped" };
|
|
83
|
+
const saved = await scope.saveSnapshot(sandbox, { expirationMs: SNAPSHOT_EXPIRATION_MS });
|
|
84
|
+
if (!saved.ok)
|
|
85
|
+
return saved.failure.kind === "aborted"
|
|
86
|
+
? { kind: "stopped" }
|
|
87
|
+
: { kind: "failed", step: "save-snapshot", message: saved.failure.message };
|
|
88
|
+
// A signal while the snapshot saved: the snapshot exists, but the run records nothing more.
|
|
89
|
+
if (signal.aborted)
|
|
90
|
+
return { kind: "stopped" };
|
|
91
|
+
const savedAt = context.clock.now();
|
|
92
|
+
const entry = {
|
|
93
|
+
teamId: startedFrom.teamId,
|
|
94
|
+
projectId: startedFrom.projectId,
|
|
95
|
+
region: startedFrom.region,
|
|
96
|
+
runtime: startedFrom.runtime,
|
|
97
|
+
recipeName: startedFrom.recipeName,
|
|
98
|
+
snapshotKey: startedFrom.snapshotKey,
|
|
99
|
+
base: startedFrom.base,
|
|
100
|
+
branch,
|
|
101
|
+
head,
|
|
102
|
+
repoRoot: ready.repoRoot,
|
|
103
|
+
snapshotId: saved.value.snapshotId,
|
|
104
|
+
createdAt: savedAt.toISOString(),
|
|
105
|
+
expiresAt: saved.value.expiresAt ?? new Date(savedAt.getTime() + SNAPSHOT_EXPIRATION_MS).toISOString(),
|
|
106
|
+
};
|
|
107
|
+
const written = await context.runnerSnapshots.writeEntry(entry);
|
|
108
|
+
if (!written.ok)
|
|
109
|
+
await progress.emit({ kind: "snapshot-entry-not-written", failure: written.failure });
|
|
110
|
+
const ms = savedAt.getTime() - startedAt;
|
|
111
|
+
await progress.emit({
|
|
112
|
+
kind: "branch-snapshot-saved",
|
|
113
|
+
snapshotId: entry.snapshotId,
|
|
114
|
+
branch,
|
|
115
|
+
head,
|
|
116
|
+
ms,
|
|
117
|
+
sizeBytes: saved.value.sizeBytes,
|
|
118
|
+
});
|
|
119
|
+
return {
|
|
120
|
+
kind: "saved",
|
|
121
|
+
snapshotId: entry.snapshotId,
|
|
122
|
+
base: entry.base,
|
|
123
|
+
branch,
|
|
124
|
+
head,
|
|
125
|
+
ms,
|
|
126
|
+
sizeBytes: saved.value.sizeBytes,
|
|
127
|
+
entryWritten: written.ok,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
async function runSaveScript(context, sandbox, script, signal) {
|
|
131
|
+
const splitters = { stdout: lineSplitter(), stderr: lineSplitter() };
|
|
132
|
+
const tail = outputTail(FAILURE_TAIL_LINES);
|
|
133
|
+
const keep = (text) => {
|
|
134
|
+
for (const line of splitLines(text))
|
|
135
|
+
tail.add(line);
|
|
136
|
+
};
|
|
137
|
+
const ran = await context.runnerSandboxes.runScript(sandbox, { script, env: STEP_ENV }, ({ stream, data }) => keep(splitters[stream].push(data)), signal);
|
|
138
|
+
keep(splitters.stdout.flush());
|
|
139
|
+
keep(splitters.stderr.flush());
|
|
140
|
+
if (!ran.ok)
|
|
141
|
+
return ran.failure.kind === "aborted" ? { kind: "stopped" } : { kind: "failed", message: ran.failure.message };
|
|
142
|
+
const { exitCode } = ran.value;
|
|
143
|
+
if (exitCode === 0)
|
|
144
|
+
return { kind: "ok" };
|
|
145
|
+
const lines = tail.lines();
|
|
146
|
+
const ended = exitCode === null ? "ended without an exit code" : `exited ${exitCode}`;
|
|
147
|
+
return { kind: "failed", message: lines.length === 0 ? ended : `${ended}: ${lines.join(" / ")}` };
|
|
148
|
+
}
|
package/dist/sdk/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// The storm SDK's published surface, exported as `@cnc-tools/storm/sdk`: only what a command uses. A command
|
|
2
|
-
// running under
|
|
2
|
+
// running under a storm run uses it to read the run payload, start containers, seed them through factories or
|
|
3
3
|
// the seeder's entity-level calls, send them API requests, warm their services, read their logs, and proxy clients
|
|
4
4
|
// that can't send a test id. The gateway seams the SDK's own tests and fakes need live on each SDK module's
|
|
5
5
|
// `index.ts`, not here. The Vitest adapter (`src/vitest/`, `@cnc-tools/storm/vitest`) builds on this surface;
|
|
@@ -26,7 +26,7 @@ export interface RunPayloadResources {
|
|
|
26
26
|
/**
|
|
27
27
|
* The run payload, version 2: the resources the run holds (`resources`); where the command may append test events
|
|
28
28
|
* (`testEvents`, a file path), when the run follows them; and whether the run is verbose (`verbose`, under
|
|
29
|
-
* `storm
|
|
29
|
+
* `storm vitest --verbose` or `storm exec --verbose`), so the command prints what each test did as it goes, passing or not.
|
|
30
30
|
*/
|
|
31
31
|
export interface RunPayload {
|
|
32
32
|
readonly version: 2;
|
|
@@ -41,7 +41,7 @@ export declare class RunPayloadError extends Error {
|
|
|
41
41
|
readonly name = "RunPayloadError";
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
* The run payload in `env`'s `STORM_RUN`, which
|
|
44
|
+
* The run payload in `env`'s `STORM_RUN`, which a storm run sets for its command. Throws a
|
|
45
45
|
* `RunPayloadError` saying what is wrong when the variable is missing or holds no valid version 2 run payload.
|
|
46
46
|
*/
|
|
47
47
|
export declare function readRunPayload(env?: Readonly<Record<string, string | undefined>>): RunPayload;
|
|
@@ -24,13 +24,13 @@ export class RunPayloadError extends Error {
|
|
|
24
24
|
name = "RunPayloadError";
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
|
-
* The run payload in `env`'s `STORM_RUN`, which
|
|
27
|
+
* The run payload in `env`'s `STORM_RUN`, which a storm run sets for its command. Throws a
|
|
28
28
|
* `RunPayloadError` saying what is wrong when the variable is missing or holds no valid version 2 run payload.
|
|
29
29
|
*/
|
|
30
30
|
export function readRunPayload(env = process.env) {
|
|
31
31
|
const raw = env[RUN_PAYLOAD_VARIABLE];
|
|
32
32
|
if (raw === undefined || raw === "") {
|
|
33
|
-
throw new RunPayloadError(`${RUN_PAYLOAD_VARIABLE} is not set: run this command under \`storm
|
|
33
|
+
throw new RunPayloadError(`${RUN_PAYLOAD_VARIABLE} is not set: run this command under \`storm vitest\` or \`storm exec\``);
|
|
34
34
|
}
|
|
35
35
|
let json;
|
|
36
36
|
try {
|
package/dist/story/align.d.ts
CHANGED
package/dist/story/align.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Aligning the calls a story made with the calls its
|
|
1
|
+
// Aligning the calls a story made with the calls in its recording. Pure.
|
|
2
2
|
import { canonicalJson, sameJson } from "./json.js";
|
|
3
3
|
import { diffSequences, MAX_SEQUENCE_CELLS } from "./sequence.js";
|
|
4
4
|
/** A call's key, (agent, tool, input), as one string: two calls have the same key when these are equal. */
|
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
import type { z } from "zod";
|
|
2
2
|
import type { StoryJson } from "./json.ts";
|
|
3
|
-
/** One story's session: what the tools run against. Story
|
|
3
|
+
/** One story's session: what the tools run against. Story core closes it once the story ends, pass or fail. */
|
|
4
4
|
export interface StorySession {
|
|
5
5
|
close(): void | Promise<void>;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* A tool an agent calls: `input`, the schema its input must match; `run`, which does the work against the story's
|
|
9
|
-
* session with the parsed input and returns a
|
|
10
|
-
*
|
|
11
|
-
* methods, so a tool of any input and
|
|
9
|
+
* session with the parsed input and returns a value; and `observe`, which turns that return value into the
|
|
10
|
+
* observation, the JSON story core records and compares. The story gets the return value itself; only the observation
|
|
11
|
+
* reaches the recording. `run` and `observe` are methods, so a tool of any input and return value fits an agent's
|
|
12
|
+
* `tools` map (`AnyStoryTool`).
|
|
12
13
|
*/
|
|
13
|
-
export interface StoryTool<Session, Schema extends z.ZodType,
|
|
14
|
+
export interface StoryTool<Session, Schema extends z.ZodType, Returned> {
|
|
14
15
|
readonly input: Schema;
|
|
15
|
-
run(session: Session, input: z.output<Schema>):
|
|
16
|
-
observe(
|
|
16
|
+
run(session: Session, input: z.output<Schema>): Returned | Promise<Returned>;
|
|
17
|
+
observe(returned: Returned): StoryJson;
|
|
17
18
|
}
|
|
18
|
-
/** A tool with any input and
|
|
19
|
+
/** A tool with any input and return value, as an agent's `tools` map holds it. */
|
|
19
20
|
export type AnyStoryTool<Session> = StoryTool<Session, z.ZodType, unknown>;
|
|
20
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* An agent: a name in the harness's `agents`, such as `tester` or `user`, with the tools a story calls through it. The
|
|
23
|
+
* name is part of each tool call's key; story core gives it no meaning.
|
|
24
|
+
*/
|
|
21
25
|
export interface StoryAgent<Session> {
|
|
22
26
|
readonly tools: {
|
|
23
27
|
readonly [tool: string]: AnyStoryTool<Session>;
|
|
@@ -27,14 +31,17 @@ export interface StoryAgent<Session> {
|
|
|
27
31
|
export type StoryAgents<Session> = {
|
|
28
32
|
readonly [agent: string]: StoryAgent<Session>;
|
|
29
33
|
};
|
|
30
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* What a set of stories declares once and passes to `createStory`: `start()`, which makes each story's session, and
|
|
36
|
+
* its agents with their tools.
|
|
37
|
+
*/
|
|
31
38
|
export interface StoryHarness<Session extends StorySession, Agents extends StoryAgents<Session>> {
|
|
32
39
|
/** Starts the story's session, at its first tool call. A story that calls no tool starts none. */
|
|
33
40
|
readonly start: () => Session | Promise<Session>;
|
|
34
41
|
readonly agents: Agents;
|
|
35
42
|
}
|
|
36
|
-
/** How a story calls one tool: with the tool's input, resolving with its
|
|
37
|
-
export type StoryToolCall<Tool> = Tool extends StoryTool<infer _Session, infer Schema, infer
|
|
43
|
+
/** How a story calls one tool: with the tool's input, resolving with its return value. */
|
|
44
|
+
export type StoryToolCall<Tool> = Tool extends StoryTool<infer _Session, infer Schema, infer Returned> ? (input: z.input<Schema>) => Promise<Returned> : never;
|
|
38
45
|
/** What a story's body gets: one handle per agent, each with a function per tool. */
|
|
39
46
|
export type StoryHandles<Agents> = {
|
|
40
47
|
readonly [Agent in keyof Agents]: {
|
|
@@ -46,7 +53,7 @@ export type StoryHandles<Agents> = {
|
|
|
46
53
|
};
|
|
47
54
|
};
|
|
48
55
|
/**
|
|
49
|
-
* `tool`, typed: TypeScript infers its input from `input`, its session from `run`'s first parameter, and its
|
|
50
|
-
* from what `run` returns, so `run` and `observe` need no other annotation. Annotate `run`'s session parameter.
|
|
56
|
+
* `tool`, typed: TypeScript infers its input from `input`, its session from `run`'s first parameter, and its return
|
|
57
|
+
* value from what `run` returns, so `run` and `observe` need no other annotation. Annotate `run`'s session parameter.
|
|
51
58
|
*/
|
|
52
|
-
export declare function storyTool<Session, Schema extends z.ZodType,
|
|
59
|
+
export declare function storyTool<Session, Schema extends z.ZodType, Returned>(tool: StoryTool<Session, Schema, Returned>): StoryTool<Session, Schema, Returned>;
|
package/dist/story/definition.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// What a story harness declares: how to start a session, and the agents with their tools. Types only, but for
|
|
2
2
|
// `storyTool`, which returns its argument.
|
|
3
3
|
/**
|
|
4
|
-
* `tool`, typed: TypeScript infers its input from `input`, its session from `run`'s first parameter, and its
|
|
5
|
-
* from what `run` returns, so `run` and `observe` need no other annotation. Annotate `run`'s session parameter.
|
|
4
|
+
* `tool`, typed: TypeScript infers its input from `input`, its session from `run`'s first parameter, and its return
|
|
5
|
+
* value from what `run` returns, so `run` and `observe` need no other annotation. Annotate `run`'s session parameter.
|
|
6
6
|
*/
|
|
7
7
|
export function storyTool(tool) {
|
|
8
8
|
return tool;
|
package/dist/story/errors.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The errors a story fails with when its body passed but its calls don't fit its
|
|
1
|
+
// The errors a story fails with when its body passed but its calls don't fit its recording.
|
|
2
2
|
/** A story made a call whose observation differs from the recorded one: the tool behaved differently. */
|
|
3
3
|
export class StoryDivergenceError extends Error {
|
|
4
4
|
name = "StoryDivergenceError";
|
package/dist/story/gateways.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
/**
|
|
3
|
-
export type
|
|
1
|
+
import type { StoryRecording } from "./recording.ts";
|
|
2
|
+
/** A recording, read: found, missing, unreadable (not a recording, with why), or a read that failed. */
|
|
3
|
+
export type StoryRecordingRead = {
|
|
4
4
|
readonly kind: "found";
|
|
5
|
-
readonly
|
|
5
|
+
readonly recording: StoryRecording;
|
|
6
6
|
} | {
|
|
7
7
|
readonly kind: "missing";
|
|
8
8
|
} | {
|
|
@@ -13,10 +13,10 @@ export type StoryArtifactRead = {
|
|
|
13
13
|
readonly message: string;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* A recording, written: written, unchanged (its bytes were already there, so nothing was written), canceled (the
|
|
17
17
|
* signal aborted first, so nothing was written), or failed.
|
|
18
18
|
*/
|
|
19
|
-
export type
|
|
19
|
+
export type StoryRecordingWrite = {
|
|
20
20
|
readonly kind: "written";
|
|
21
21
|
} | {
|
|
22
22
|
readonly kind: "unchanged";
|
|
@@ -26,8 +26,8 @@ export type StoryArtifactWrite = {
|
|
|
26
26
|
readonly kind: "failed";
|
|
27
27
|
readonly message: string;
|
|
28
28
|
};
|
|
29
|
-
/**
|
|
30
|
-
export type
|
|
29
|
+
/** A recording, removed: removed, missing (nothing was there), canceled (the signal aborted first), or failed. */
|
|
30
|
+
export type StoryRecordingRemove = {
|
|
31
31
|
readonly kind: "removed";
|
|
32
32
|
} | {
|
|
33
33
|
readonly kind: "missing";
|
|
@@ -37,38 +37,58 @@ export type StoryArtifactRemove = {
|
|
|
37
37
|
readonly kind: "failed";
|
|
38
38
|
readonly message: string;
|
|
39
39
|
};
|
|
40
|
-
/**
|
|
41
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Paths listed: the recordings in one story file's recording directory, or the recording directories in one
|
|
42
|
+
* `__story__/` directory, by absolute path, sorted; none when the directory doesn't exist.
|
|
43
|
+
*/
|
|
44
|
+
export type StoryRecordingList = {
|
|
42
45
|
readonly kind: "listed";
|
|
43
46
|
readonly paths: readonly string[];
|
|
44
47
|
} | {
|
|
45
48
|
readonly kind: "failed";
|
|
46
49
|
readonly message: string;
|
|
47
50
|
};
|
|
51
|
+
/** A story file, looked for: found, missing (no file is there), or a look that failed. */
|
|
52
|
+
export type StoryFileFind = {
|
|
53
|
+
readonly kind: "found";
|
|
54
|
+
} | {
|
|
55
|
+
readonly kind: "missing";
|
|
56
|
+
} | {
|
|
57
|
+
readonly kind: "failed";
|
|
58
|
+
readonly message: string;
|
|
59
|
+
};
|
|
48
60
|
/**
|
|
49
|
-
* Where story
|
|
50
|
-
* nothing and returns `canceled`; the signal is checked again just before
|
|
51
|
-
* while the method waits still stops it.
|
|
61
|
+
* Where story recordings live: one per story, by absolute path, in its story file's recording directory. A write or a
|
|
62
|
+
* removal given an aborted `signal` changes nothing and returns `canceled`; the signal is checked again just before
|
|
63
|
+
* the change is made, so one that aborts while the method waits still stops it.
|
|
52
64
|
*/
|
|
53
|
-
export interface
|
|
54
|
-
|
|
65
|
+
export interface StoryRecordingGateway {
|
|
66
|
+
readRecording(request: {
|
|
55
67
|
readonly path: string;
|
|
56
|
-
}): Promise<
|
|
68
|
+
}): Promise<StoryRecordingRead>;
|
|
57
69
|
/**
|
|
58
|
-
* Writes `
|
|
59
|
-
* already there. A reader never sees half
|
|
70
|
+
* Writes `recording` at `path` as `serializeRecording` gives it, making missing directories, unless those bytes are
|
|
71
|
+
* already there. A reader never sees half a recording.
|
|
60
72
|
*/
|
|
61
|
-
|
|
73
|
+
writeRecording(request: {
|
|
62
74
|
readonly path: string;
|
|
63
|
-
readonly
|
|
75
|
+
readonly recording: StoryRecording;
|
|
64
76
|
readonly signal?: AbortSignal;
|
|
65
|
-
}): Promise<
|
|
66
|
-
|
|
77
|
+
}): Promise<StoryRecordingWrite>;
|
|
78
|
+
removeRecording(request: {
|
|
67
79
|
readonly path: string;
|
|
68
80
|
readonly signal?: AbortSignal;
|
|
69
|
-
}): Promise<
|
|
81
|
+
}): Promise<StoryRecordingRemove>;
|
|
70
82
|
/** The `.json` files directly in `directory`. */
|
|
71
|
-
|
|
83
|
+
listRecordings(request: {
|
|
72
84
|
readonly directory: string;
|
|
73
|
-
}): Promise<
|
|
85
|
+
}): Promise<StoryRecordingList>;
|
|
86
|
+
/** The directories directly in `root`, a `__story__/` directory: each a story file's recording directory. */
|
|
87
|
+
listRecordingDirectories(request: {
|
|
88
|
+
readonly root: string;
|
|
89
|
+
}): Promise<StoryRecordingList>;
|
|
90
|
+
/** Whether a story file is at `path`. */
|
|
91
|
+
findStoryFile(request: {
|
|
92
|
+
readonly path: string;
|
|
93
|
+
}): Promise<StoryFileFind>;
|
|
74
94
|
}
|