shiplane 0.0.0 → 0.1.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/LICENSE +21 -0
- package/README.md +133 -0
- package/dist/budget-C8_aayQk.js +328 -0
- package/dist/budget-C8_aayQk.js.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +503 -0
- package/dist/cli.js.map +1 -0
- package/dist/display-DM0xtQbT.js +55 -0
- package/dist/display-DM0xtQbT.js.map +1 -0
- package/dist/index-QneBUiDD.d.ts +867 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/dist/issues-C5fKq1Jv.js +6 -0
- package/dist/issues-C5fKq1Jv.js.map +1 -0
- package/dist/plugin.d.ts +16 -0
- package/dist/plugin.js +7 -0
- package/dist/readStatus-D5YVR5ZC.js +2921 -0
- package/dist/readStatus-D5YVR5ZC.js.map +1 -0
- package/dist/shell-server-hosting.adapter-Bgl6-IWw.js +49 -0
- package/dist/shell-server-hosting.adapter-Bgl6-IWw.js.map +1 -0
- package/dist/src-Dlr2Sgs8.js +32 -0
- package/dist/src-Dlr2Sgs8.js.map +1 -0
- package/dist/tags-DL74ni09.d.ts +19 -0
- package/dist/testing.d.ts +992 -0
- package/dist/testing.js +1349 -0
- package/dist/testing.js.map +1 -0
- package/dist/web-app.module-Bw-npC4Z.js +83 -0
- package/dist/web-app.module-Bw-npC4Z.js.map +1 -0
- package/package.json +58 -9
package/dist/testing.js
ADDED
|
@@ -0,0 +1,1349 @@
|
|
|
1
|
+
import { a as releaseFlow, o as perEnv } from "./web-app.module-Bw-npC4Z.js";
|
|
2
|
+
import { C as ENVIRONMENTS, S as optionsFor, T as nodeFiles, _ as addUnit, b as doctor, c as shipTo, f as openReleasePr, g as loadRelease, i as releaseToPreview, l as prepareRelease, m as docsFor, n as systemShell, p as newAdapter, s as promote, t as readStatus, u as planShips, v as removeUnit, x as refreshEditorSchema, y as initRelease } from "./readStatus-D5YVR5ZC.js";
|
|
3
|
+
import { _ as nextPatch, x as DEFAULT_TAG_FORMAT } from "./budget-C8_aayQk.js";
|
|
4
|
+
import { t as issueName } from "./issues-C5fKq1Jv.js";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
9
|
+
import { describe, expect, it } from "vitest";
|
|
10
|
+
import os from "node:os";
|
|
11
|
+
//#region src/adapters/shell/__fakes__/shell.fake.ts
|
|
12
|
+
/** A shell that runs nothing: it keeps every call and answers from what was seeded. */
|
|
13
|
+
var RecordingShell = class {
|
|
14
|
+
calls = [];
|
|
15
|
+
answers = [];
|
|
16
|
+
variables = {};
|
|
17
|
+
seedEnv(variables) {
|
|
18
|
+
this.variables = {
|
|
19
|
+
...this.variables,
|
|
20
|
+
...variables
|
|
21
|
+
};
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
env = (name) => this.variables[name];
|
|
25
|
+
/** Answers every call whose `command args` line starts with `prefix`. */
|
|
26
|
+
seed(prefix, result) {
|
|
27
|
+
this.answers.push({
|
|
28
|
+
prefix,
|
|
29
|
+
result
|
|
30
|
+
});
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
/** Answers the next call starting with `prefix` only, ahead of what `seed` answers. */
|
|
34
|
+
seedOnce(prefix, result) {
|
|
35
|
+
this.answers.unshift({
|
|
36
|
+
prefix,
|
|
37
|
+
result,
|
|
38
|
+
once: true
|
|
39
|
+
});
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
answer(command, args, options) {
|
|
43
|
+
this.calls.push({
|
|
44
|
+
command,
|
|
45
|
+
args: [...args],
|
|
46
|
+
cwd: options.cwd,
|
|
47
|
+
env: options.env
|
|
48
|
+
});
|
|
49
|
+
const line = [command, ...args].join(" ");
|
|
50
|
+
const found = this.answers.find(({ prefix }) => line.startsWith(prefix));
|
|
51
|
+
if (found?.once) this.answers.splice(this.answers.indexOf(found), 1);
|
|
52
|
+
return {
|
|
53
|
+
status: 0,
|
|
54
|
+
stdout: "",
|
|
55
|
+
stderr: "",
|
|
56
|
+
...found?.result
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
capture = (command, args, options = {}) => Promise.resolve(this.answer(command, args, options));
|
|
60
|
+
attach = (command, args, options = {}) => Promise.resolve(this.answer(command, args, options).status);
|
|
61
|
+
};
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/adapters/ci-pipeline/__fakes__/ci-pipeline.fake.ts
|
|
64
|
+
/** A CI pipeline held in memory: seed its runs and minutes, read back what was dispatched. */
|
|
65
|
+
var CiPipelineFake = class {
|
|
66
|
+
state = {
|
|
67
|
+
workflowRuns: {},
|
|
68
|
+
minutes: null,
|
|
69
|
+
measured: {}
|
|
70
|
+
};
|
|
71
|
+
received = [];
|
|
72
|
+
constructor(shipWorkflow = "ship.yml") {
|
|
73
|
+
this.shipWorkflow = shipWorkflow;
|
|
74
|
+
}
|
|
75
|
+
seed(state) {
|
|
76
|
+
this.state = {
|
|
77
|
+
...this.state,
|
|
78
|
+
...state
|
|
79
|
+
};
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
workflowRuns = (workflow) => Promise.resolve(this.state.workflowRuns[workflow] ?? []);
|
|
83
|
+
dispatch = (workflow, ref, inputs) => {
|
|
84
|
+
this.received.push({
|
|
85
|
+
type: "dispatch",
|
|
86
|
+
workflow,
|
|
87
|
+
ref,
|
|
88
|
+
inputs
|
|
89
|
+
});
|
|
90
|
+
return Promise.resolve();
|
|
91
|
+
};
|
|
92
|
+
minutes = () => Promise.resolve(this.state.minutes);
|
|
93
|
+
measuredMinutes = (workflow) => Promise.resolve(this.state.measured[workflow] ?? []);
|
|
94
|
+
};
|
|
95
|
+
/** The Fake as a config holds an adapter; `.fake` is what a test seeds and reads. */
|
|
96
|
+
const ciPipelineFake = (fake = new CiPipelineFake()) => ({
|
|
97
|
+
name: "fake",
|
|
98
|
+
create: () => fake,
|
|
99
|
+
fake
|
|
100
|
+
});
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/adapters/code-host/__fakes__/code-host.fake.ts
|
|
103
|
+
/** A code host held in memory: seed its pull requests and deploys, read back what it received. */
|
|
104
|
+
var CodeHostFake = class {
|
|
105
|
+
state = {
|
|
106
|
+
openPrs: [],
|
|
107
|
+
prStates: {},
|
|
108
|
+
merges: {
|
|
109
|
+
allowed: [
|
|
110
|
+
"--squash",
|
|
111
|
+
"--merge",
|
|
112
|
+
"--rebase"
|
|
113
|
+
],
|
|
114
|
+
preselected: "--squash"
|
|
115
|
+
},
|
|
116
|
+
releasedTags: [],
|
|
117
|
+
deployments: [],
|
|
118
|
+
nextPrNumber: 1800,
|
|
119
|
+
pullRequests: {},
|
|
120
|
+
comments: {}
|
|
121
|
+
};
|
|
122
|
+
received = [];
|
|
123
|
+
/** Each pull request number, once per state check. */
|
|
124
|
+
polled = [];
|
|
125
|
+
/** Each batched read of pull requests or comments, in order. */
|
|
126
|
+
reads = [];
|
|
127
|
+
seed(state) {
|
|
128
|
+
this.state = {
|
|
129
|
+
...this.state,
|
|
130
|
+
...state
|
|
131
|
+
};
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
openPrsFrom = (branchPrefix) => Promise.resolve(this.state.openPrs.filter(({ branch }) => branch.startsWith(branchPrefix)).map(({ pr }) => pr));
|
|
135
|
+
createPr = (pr) => {
|
|
136
|
+
const number = this.state.nextPrNumber++;
|
|
137
|
+
const created = {
|
|
138
|
+
number,
|
|
139
|
+
url: `https://github.com/acme/repo/pull/${number}`
|
|
140
|
+
};
|
|
141
|
+
this.received.push({
|
|
142
|
+
type: "pr",
|
|
143
|
+
pr: created,
|
|
144
|
+
...pr
|
|
145
|
+
});
|
|
146
|
+
this.state.openPrs.push({
|
|
147
|
+
branch: pr.head,
|
|
148
|
+
pr: created
|
|
149
|
+
});
|
|
150
|
+
return Promise.resolve(created);
|
|
151
|
+
};
|
|
152
|
+
closeError = null;
|
|
153
|
+
/** Every pull request close throws `error`. */
|
|
154
|
+
failClose(error) {
|
|
155
|
+
this.closeError = error;
|
|
156
|
+
return this;
|
|
157
|
+
}
|
|
158
|
+
closePr = (pr, comment) => {
|
|
159
|
+
if (this.closeError) return Promise.reject(this.closeError);
|
|
160
|
+
this.received.push({
|
|
161
|
+
type: "close",
|
|
162
|
+
pr,
|
|
163
|
+
comment
|
|
164
|
+
});
|
|
165
|
+
this.state.openPrs = this.state.openPrs.filter((open) => open.pr.number !== pr.number);
|
|
166
|
+
this.state.prStates[pr.number] = ["CLOSED"];
|
|
167
|
+
return Promise.resolve();
|
|
168
|
+
};
|
|
169
|
+
prState = (pr) => {
|
|
170
|
+
this.polled.push(pr.number);
|
|
171
|
+
const [state = "OPEN", ...rest] = this.state.prStates[pr.number] ?? ["OPEN"];
|
|
172
|
+
if (rest.length > 0) this.state.prStates[pr.number] = rest;
|
|
173
|
+
return Promise.resolve(state);
|
|
174
|
+
};
|
|
175
|
+
mergeMethods = () => Promise.resolve(this.state.merges);
|
|
176
|
+
merge = (pr, method) => {
|
|
177
|
+
this.received.push({
|
|
178
|
+
type: "merge",
|
|
179
|
+
pr,
|
|
180
|
+
method
|
|
181
|
+
});
|
|
182
|
+
this.state.prStates[pr.number] = ["MERGED"];
|
|
183
|
+
return Promise.resolve();
|
|
184
|
+
};
|
|
185
|
+
showDiff = () => Promise.resolve();
|
|
186
|
+
openInBrowser = () => Promise.resolve();
|
|
187
|
+
releasedTags = () => Promise.resolve(new Set(this.state.releasedTags));
|
|
188
|
+
releaseError = null;
|
|
189
|
+
/** Every release notes publish throws `error`. */
|
|
190
|
+
failRelease(error) {
|
|
191
|
+
this.releaseError = error;
|
|
192
|
+
return this;
|
|
193
|
+
}
|
|
194
|
+
createRelease = (tag, notes, latest) => {
|
|
195
|
+
if (this.releaseError) return Promise.reject(this.releaseError);
|
|
196
|
+
this.received.push({
|
|
197
|
+
type: "release",
|
|
198
|
+
tag,
|
|
199
|
+
notes,
|
|
200
|
+
latest
|
|
201
|
+
});
|
|
202
|
+
this.state.releasedTags.push(tag);
|
|
203
|
+
return Promise.resolve();
|
|
204
|
+
};
|
|
205
|
+
deployments = () => Promise.resolve(this.state.deployments);
|
|
206
|
+
recordDeployment = (ref, environment) => {
|
|
207
|
+
this.received.push({
|
|
208
|
+
type: "record",
|
|
209
|
+
ref,
|
|
210
|
+
environment
|
|
211
|
+
});
|
|
212
|
+
this.state.deployments.push({
|
|
213
|
+
title: `Deploy ${ref} to ${environment}`,
|
|
214
|
+
state: "done"
|
|
215
|
+
});
|
|
216
|
+
return Promise.resolve();
|
|
217
|
+
};
|
|
218
|
+
pullRequests = (numbers) => {
|
|
219
|
+
this.reads.push("pull-requests");
|
|
220
|
+
const missing = numbers.find((number) => !this.state.pullRequests[number]);
|
|
221
|
+
if (missing !== void 0) return Promise.reject(/* @__PURE__ */ new Error(`no pull request #${missing}`));
|
|
222
|
+
return Promise.resolve(numbers.flatMap((number) => this.state.pullRequests[number] ?? []));
|
|
223
|
+
};
|
|
224
|
+
comments = (on) => {
|
|
225
|
+
this.reads.push("comments");
|
|
226
|
+
return Promise.resolve(on.map((ref) => this.state.comments[issueName(ref)] ?? []));
|
|
227
|
+
};
|
|
228
|
+
commentError = null;
|
|
229
|
+
/** Every comment throws `error`. */
|
|
230
|
+
failComment(error) {
|
|
231
|
+
this.commentError = error;
|
|
232
|
+
return this;
|
|
233
|
+
}
|
|
234
|
+
comment = (on, body) => {
|
|
235
|
+
if (this.commentError) return Promise.reject(this.commentError);
|
|
236
|
+
this.received.push({
|
|
237
|
+
type: "comment",
|
|
238
|
+
issue: issueName(on),
|
|
239
|
+
body
|
|
240
|
+
});
|
|
241
|
+
this.state.comments[issueName(on)] = [...this.state.comments[issueName(on)] ?? [], body];
|
|
242
|
+
return Promise.resolve();
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
/** The Fake as a config holds an adapter; `.fake` is what a test seeds and reads. */
|
|
246
|
+
const codeHostFake = (fake = new CodeHostFake()) => ({
|
|
247
|
+
name: "fake",
|
|
248
|
+
create: () => fake,
|
|
249
|
+
fake
|
|
250
|
+
});
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/adapters/source-control/__fakes__/source-control.fake.ts
|
|
253
|
+
/** A repository held in memory: seed what it contains, read back what it received. */
|
|
254
|
+
var SourceControlFake = class {
|
|
255
|
+
state = {
|
|
256
|
+
position: {
|
|
257
|
+
branch: "main",
|
|
258
|
+
head: "head",
|
|
259
|
+
originMain: "head"
|
|
260
|
+
},
|
|
261
|
+
clean: true,
|
|
262
|
+
tags: {},
|
|
263
|
+
versionCommits: {},
|
|
264
|
+
subjects: {},
|
|
265
|
+
files: {},
|
|
266
|
+
diffs: {},
|
|
267
|
+
commits: {},
|
|
268
|
+
changed: []
|
|
269
|
+
};
|
|
270
|
+
received = [];
|
|
271
|
+
failures = [];
|
|
272
|
+
seed(state) {
|
|
273
|
+
this.state = {
|
|
274
|
+
...this.state,
|
|
275
|
+
...state
|
|
276
|
+
};
|
|
277
|
+
return this;
|
|
278
|
+
}
|
|
279
|
+
/** The `nth` call of this kind throws `error`, after it is recorded. */
|
|
280
|
+
failAt(type, nth, error) {
|
|
281
|
+
this.failures.push({
|
|
282
|
+
type,
|
|
283
|
+
nth,
|
|
284
|
+
error
|
|
285
|
+
});
|
|
286
|
+
return this;
|
|
287
|
+
}
|
|
288
|
+
record(event) {
|
|
289
|
+
this.received.push(event);
|
|
290
|
+
const count = this.received.filter(({ type }) => type === event.type).length;
|
|
291
|
+
const failure = this.failures.find(({ type, nth }) => type === event.type && nth === count);
|
|
292
|
+
return failure ? Promise.reject(failure.error) : Promise.resolve();
|
|
293
|
+
}
|
|
294
|
+
position = () => Promise.resolve(this.state.position);
|
|
295
|
+
isClean = () => Promise.resolve(this.state.clean);
|
|
296
|
+
tagCommit = (tag) => Promise.resolve(this.state.tags[tag] ?? null);
|
|
297
|
+
versionCommit = (dir, _manifest, version) => Promise.resolve(this.state.versionCommits[`${dir}@${version}`] ?? null);
|
|
298
|
+
subjectsSince = (sha, dir) => Promise.resolve(this.state.subjects[`${sha}:${dir}`] ?? []);
|
|
299
|
+
changedFiles = () => Promise.resolve(this.state.changed);
|
|
300
|
+
diffNames = (from, to) => Promise.resolve(this.state.diffs[`${from}..${to}`] ?? []);
|
|
301
|
+
commitsBetween = (from, to) => Promise.resolve(this.state.commits[`${from}..${to}`] ?? []);
|
|
302
|
+
fileAt = (ref, file) => Promise.resolve(this.state.files[`${ref}:${file}`] ?? null);
|
|
303
|
+
tags = () => Promise.resolve(new Set(Object.keys(this.state.tags)));
|
|
304
|
+
createBranch = async (name) => {
|
|
305
|
+
await this.record({
|
|
306
|
+
type: "branch",
|
|
307
|
+
name
|
|
308
|
+
});
|
|
309
|
+
this.state.position = {
|
|
310
|
+
...this.state.position,
|
|
311
|
+
branch: name
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
switchTo = async (branch) => {
|
|
315
|
+
await this.record({
|
|
316
|
+
type: "switch",
|
|
317
|
+
branch
|
|
318
|
+
});
|
|
319
|
+
this.state.position = {
|
|
320
|
+
...this.state.position,
|
|
321
|
+
branch
|
|
322
|
+
};
|
|
323
|
+
};
|
|
324
|
+
commit = async (files, title, body) => {
|
|
325
|
+
await this.record({
|
|
326
|
+
type: "commit",
|
|
327
|
+
files,
|
|
328
|
+
title,
|
|
329
|
+
body
|
|
330
|
+
});
|
|
331
|
+
this.state.changed = this.state.changed.filter((file) => !files.includes(file));
|
|
332
|
+
};
|
|
333
|
+
push = (branch) => this.record({
|
|
334
|
+
type: "push",
|
|
335
|
+
branch
|
|
336
|
+
});
|
|
337
|
+
pull = () => this.record({ type: "pull" });
|
|
338
|
+
tag = async (name, sha, message) => {
|
|
339
|
+
await this.record({
|
|
340
|
+
type: "tag",
|
|
341
|
+
name,
|
|
342
|
+
sha,
|
|
343
|
+
message
|
|
344
|
+
});
|
|
345
|
+
this.state.tags[name] = sha;
|
|
346
|
+
};
|
|
347
|
+
pushTags = (names) => this.record({
|
|
348
|
+
type: "push-tags",
|
|
349
|
+
names
|
|
350
|
+
});
|
|
351
|
+
discard = async (files) => {
|
|
352
|
+
await this.record({
|
|
353
|
+
type: "discard",
|
|
354
|
+
files
|
|
355
|
+
});
|
|
356
|
+
this.state.changed = this.state.changed.filter((file) => !files.includes(file));
|
|
357
|
+
};
|
|
358
|
+
deleteBranch = (name) => this.record({
|
|
359
|
+
type: "delete-branch",
|
|
360
|
+
name
|
|
361
|
+
});
|
|
362
|
+
deleteRemoteBranch = (branch) => this.record({
|
|
363
|
+
type: "delete-remote",
|
|
364
|
+
branch
|
|
365
|
+
});
|
|
366
|
+
deleteTag = async (name) => {
|
|
367
|
+
await this.record({
|
|
368
|
+
type: "delete-tag",
|
|
369
|
+
name
|
|
370
|
+
});
|
|
371
|
+
this.state.tags = Object.fromEntries(Object.entries(this.state.tags).filter(([tag]) => tag !== name));
|
|
372
|
+
};
|
|
373
|
+
};
|
|
374
|
+
/** The Fake as a config holds an adapter; `.fake` is what a test seeds and reads. */
|
|
375
|
+
const sourceControlFake = (fake = new SourceControlFake()) => ({
|
|
376
|
+
name: "fake",
|
|
377
|
+
create: () => fake,
|
|
378
|
+
fake
|
|
379
|
+
});
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region src/adapters/terminal/__fakes__/progress.fake.ts
|
|
382
|
+
/** Progress kept as events; what it says also goes to the output, as a terminal would print it. */
|
|
383
|
+
var RecordingProgress = class {
|
|
384
|
+
events = [];
|
|
385
|
+
constructor(output) {
|
|
386
|
+
this.output = output;
|
|
387
|
+
}
|
|
388
|
+
stage = (stages, index) => {
|
|
389
|
+
this.events.push({
|
|
390
|
+
kind: "stage",
|
|
391
|
+
text: stages[index] ?? "",
|
|
392
|
+
step: {
|
|
393
|
+
index,
|
|
394
|
+
total: stages.length
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
};
|
|
398
|
+
during = (label, mood, work, step) => {
|
|
399
|
+
this.events.push({
|
|
400
|
+
kind: "during",
|
|
401
|
+
mood,
|
|
402
|
+
text: label,
|
|
403
|
+
...step ? { step } : {}
|
|
404
|
+
});
|
|
405
|
+
return work();
|
|
406
|
+
};
|
|
407
|
+
say = (mood, text) => {
|
|
408
|
+
this.events.push({
|
|
409
|
+
kind: "say",
|
|
410
|
+
mood,
|
|
411
|
+
text
|
|
412
|
+
});
|
|
413
|
+
this.output.line(text);
|
|
414
|
+
};
|
|
415
|
+
};
|
|
416
|
+
//#endregion
|
|
417
|
+
//#region src/adapters/terminal/__fakes__/terminal.fake.ts
|
|
418
|
+
/** Everything the CLI printed, in order, without colours. */
|
|
419
|
+
var MemoryOutput = class {
|
|
420
|
+
lines = [];
|
|
421
|
+
line = (text = "") => {
|
|
422
|
+
this.lines.push(text.replace(/\u001B\[[0-9;]*m/g, ""));
|
|
423
|
+
};
|
|
424
|
+
get text() {
|
|
425
|
+
return this.lines.join("\n");
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
/** A person who answers from a script, in order; every question asked is kept. */
|
|
429
|
+
var ScriptedPrompter = class {
|
|
430
|
+
asked = [];
|
|
431
|
+
/** The answer each choice question offered first, by question. */
|
|
432
|
+
initials = {};
|
|
433
|
+
/** The choices each select question offered, by question. */
|
|
434
|
+
choices = {};
|
|
435
|
+
answers = [];
|
|
436
|
+
constructor(interactive = true) {
|
|
437
|
+
this.interactive = interactive;
|
|
438
|
+
}
|
|
439
|
+
answer(...answers) {
|
|
440
|
+
this.answers.push(...answers);
|
|
441
|
+
return this;
|
|
442
|
+
}
|
|
443
|
+
next(question) {
|
|
444
|
+
this.asked.push(question);
|
|
445
|
+
if (this.answers.length === 0) throw new Error(`Unexpected question: ${question}`);
|
|
446
|
+
return this.answers.shift() ?? null;
|
|
447
|
+
}
|
|
448
|
+
confirm = (question, initial = false) => {
|
|
449
|
+
this.initials[question] = initial;
|
|
450
|
+
return Promise.resolve(this.next(question) === true);
|
|
451
|
+
};
|
|
452
|
+
typed = (question, word) => Promise.resolve(this.next(question) === word);
|
|
453
|
+
select = (message, choices, initial) => {
|
|
454
|
+
this.initials[message] = initial;
|
|
455
|
+
this.choices[message] = choices;
|
|
456
|
+
return Promise.resolve(this.next(message));
|
|
457
|
+
};
|
|
458
|
+
multiselect = (message, _choices) => Promise.resolve(this.next(message));
|
|
459
|
+
text = (message) => Promise.resolve(this.next(message));
|
|
460
|
+
/** No key is ever pressed: every wait times out, unless keys were queued with `press`. */
|
|
461
|
+
keys = [];
|
|
462
|
+
press(...keys) {
|
|
463
|
+
this.keys.push(...keys);
|
|
464
|
+
return this;
|
|
465
|
+
}
|
|
466
|
+
waitForKey = () => Promise.resolve(this.keys.shift() ?? null);
|
|
467
|
+
};
|
|
468
|
+
/** A clock fixed at one moment, whose waits return at once. */
|
|
469
|
+
var FixedClock = class {
|
|
470
|
+
constructor(at) {
|
|
471
|
+
this.at = at;
|
|
472
|
+
}
|
|
473
|
+
now = () => this.at;
|
|
474
|
+
sleep = () => Promise.resolve();
|
|
475
|
+
};
|
|
476
|
+
//#endregion
|
|
477
|
+
//#region src/adapters/versioning/__fakes__/versioning.fake.ts
|
|
478
|
+
/** A changeset as its file reads: one `"package": bump` line each, then the summary. */
|
|
479
|
+
const changesetText$1 = ({ releases, summary }) => `---\n${releases.map(({ name, type }) => `"${name}": ${type}`).join("\n")}\n---\n\n${summary}\n`;
|
|
480
|
+
/** Versioning held in memory: seed the pending changes and the plan, read back what it received. */
|
|
481
|
+
var VersioningFake = class {
|
|
482
|
+
state = {
|
|
483
|
+
pending: [],
|
|
484
|
+
plan: () => ({
|
|
485
|
+
changesets: [],
|
|
486
|
+
releases: []
|
|
487
|
+
}),
|
|
488
|
+
dependencies: {},
|
|
489
|
+
folders: {}
|
|
490
|
+
};
|
|
491
|
+
applied = [];
|
|
492
|
+
written = [];
|
|
493
|
+
seed(state) {
|
|
494
|
+
this.state = {
|
|
495
|
+
...this.state,
|
|
496
|
+
...state
|
|
497
|
+
};
|
|
498
|
+
return this;
|
|
499
|
+
}
|
|
500
|
+
pending = () => Promise.resolve(this.state.pending);
|
|
501
|
+
plan = (added, held) => Promise.resolve(this.state.plan(added, held));
|
|
502
|
+
dependencies = () => Promise.resolve(this.state.dependencies);
|
|
503
|
+
folders = () => Promise.resolve(this.state.folders);
|
|
504
|
+
apply = (added, held) => {
|
|
505
|
+
this.applied.push({
|
|
506
|
+
added,
|
|
507
|
+
held
|
|
508
|
+
});
|
|
509
|
+
return Promise.resolve();
|
|
510
|
+
};
|
|
511
|
+
write = (changeset) => {
|
|
512
|
+
this.written.push(changeset);
|
|
513
|
+
this.state.pending = [...this.state.pending.filter(({ id }) => id !== changeset.id), {
|
|
514
|
+
id: changeset.id,
|
|
515
|
+
text: changesetText$1(changeset)
|
|
516
|
+
}];
|
|
517
|
+
return Promise.resolve();
|
|
518
|
+
};
|
|
519
|
+
changesetFile = (id) => `.changeset/${id}.md`;
|
|
520
|
+
changelogFile = (dir) => `${dir}/CHANGELOG.md`;
|
|
521
|
+
};
|
|
522
|
+
/** The Fake as a config holds an adapter; `.fake` is what a test seeds and reads. */
|
|
523
|
+
const versioningFake = (fake = new VersioningFake()) => ({
|
|
524
|
+
name: "fake",
|
|
525
|
+
create: () => fake,
|
|
526
|
+
fake
|
|
527
|
+
});
|
|
528
|
+
//#endregion
|
|
529
|
+
//#region src/testing/releaseContext.ts
|
|
530
|
+
const testUnit = (name, overrides = {}) => ({
|
|
531
|
+
name,
|
|
532
|
+
dir: `apps/${name}`,
|
|
533
|
+
file: `apps/${name}/shiplane.unit.yml`,
|
|
534
|
+
packageName: `@acme/${name}`,
|
|
535
|
+
version: "0.1.0",
|
|
536
|
+
module: "web-app",
|
|
537
|
+
options: {},
|
|
538
|
+
after: [],
|
|
539
|
+
...overrides
|
|
540
|
+
});
|
|
541
|
+
/**
|
|
542
|
+
* A release over a Fake of every port the flow runs on, answered by a scripted person. The apps are
|
|
543
|
+
* in release order as given: the first is the Latest release.
|
|
544
|
+
*/
|
|
545
|
+
const testContext = ({ units, modules = [], features = [], yes = false, interactive = true, root = "/repo", tagFormat = DEFAULT_TAG_FORMAT, commitsWithoutChangeset = "release" }) => {
|
|
546
|
+
const sourceControl = sourceControlFake();
|
|
547
|
+
const codeHost = codeHostFake();
|
|
548
|
+
const ciPipeline = ciPipelineFake();
|
|
549
|
+
const versioning = versioningFake();
|
|
550
|
+
const prompter = new ScriptedPrompter(interactive);
|
|
551
|
+
const output = new MemoryOutput();
|
|
552
|
+
const progress = new RecordingProgress(output);
|
|
553
|
+
const shell = new RecordingShell();
|
|
554
|
+
const fakes = {
|
|
555
|
+
sourceControl,
|
|
556
|
+
codeHost,
|
|
557
|
+
ciPipeline,
|
|
558
|
+
versioning
|
|
559
|
+
};
|
|
560
|
+
const release = {
|
|
561
|
+
root,
|
|
562
|
+
flow: releaseFlow(fakes),
|
|
563
|
+
modules,
|
|
564
|
+
features: typeof features === "function" ? features(fakes) : features,
|
|
565
|
+
units,
|
|
566
|
+
problems: [],
|
|
567
|
+
tagFormat,
|
|
568
|
+
releasesCommits: commitsWithoutChangeset === "release"
|
|
569
|
+
};
|
|
570
|
+
return {
|
|
571
|
+
context: {
|
|
572
|
+
release,
|
|
573
|
+
load: () => Promise.resolve(release),
|
|
574
|
+
services: {
|
|
575
|
+
sourceControl: sourceControl.fake,
|
|
576
|
+
codeHost: codeHost.fake,
|
|
577
|
+
ciPipeline: ciPipeline.fake,
|
|
578
|
+
versioning: versioning.fake
|
|
579
|
+
},
|
|
580
|
+
open: (adapter) => adapter.create({
|
|
581
|
+
root,
|
|
582
|
+
shell
|
|
583
|
+
}),
|
|
584
|
+
prompter,
|
|
585
|
+
output,
|
|
586
|
+
progress,
|
|
587
|
+
clock: new FixedClock(/* @__PURE__ */ new Date("2026-10-12T09:00:00Z")),
|
|
588
|
+
shell,
|
|
589
|
+
options: {
|
|
590
|
+
yes,
|
|
591
|
+
ci: false
|
|
592
|
+
}
|
|
593
|
+
},
|
|
594
|
+
flow: fakes,
|
|
595
|
+
source: sourceControl.fake,
|
|
596
|
+
host: codeHost.fake,
|
|
597
|
+
ci: ciPipeline.fake,
|
|
598
|
+
versioning: versioning.fake,
|
|
599
|
+
prompter,
|
|
600
|
+
output,
|
|
601
|
+
progress,
|
|
602
|
+
shell
|
|
603
|
+
};
|
|
604
|
+
};
|
|
605
|
+
const changesetText = (packages, summary) => `---\n${Object.entries(packages).map(([name, type]) => `"${name}": ${type}`).join("\n")}\n---\n\n${summary}\n`;
|
|
606
|
+
//#endregion
|
|
607
|
+
//#region src/testing/deliveryContract.ts
|
|
608
|
+
const EMPTY_FOLDER = {
|
|
609
|
+
dir: "apps/empty",
|
|
610
|
+
name: "empty",
|
|
611
|
+
files: [],
|
|
612
|
+
has: () => false,
|
|
613
|
+
read: () => null
|
|
614
|
+
};
|
|
615
|
+
/** What every adapter of a delivery port must do, whatever its provider; `more` adds the port's own. */
|
|
616
|
+
const deliveryContract = (kind, cases, more = () => void 0) => describe.each(cases.map((entry) => [entry.adapter.name, entry]))(`%s, as ${kind}`, (_name, { adapter, settings }) => {
|
|
617
|
+
const port = adapter.create({
|
|
618
|
+
root: "/repo",
|
|
619
|
+
shell: new RecordingShell()
|
|
620
|
+
});
|
|
621
|
+
const unit = testUnit("app", {
|
|
622
|
+
module: "app",
|
|
623
|
+
options: settings
|
|
624
|
+
});
|
|
625
|
+
const inputFor = (environment) => ({
|
|
626
|
+
unit,
|
|
627
|
+
tag: "app@0.1.0",
|
|
628
|
+
environment,
|
|
629
|
+
options: optionsFor({
|
|
630
|
+
...unit,
|
|
631
|
+
options: adapter.settings.parse(settings)
|
|
632
|
+
}, environment, [unit]),
|
|
633
|
+
commit: "abc1234"
|
|
634
|
+
});
|
|
635
|
+
it("given an app's settings, when its unit file is read, then the adapter's schema takes them", () => {
|
|
636
|
+
expect(adapter.settings.safeParse(settings).success).toBe(true);
|
|
637
|
+
});
|
|
638
|
+
it("given a tag on each environment, when it says where the tag lands, then a person can read it", () => {
|
|
639
|
+
ENVIRONMENTS.forEach((environment) => expect(port.describe(inputFor(environment)).trim()).not.toBe(""));
|
|
640
|
+
});
|
|
641
|
+
it("given a tag on each environment, when its jobs are built, then each says what it does and what it runs", () => {
|
|
642
|
+
ENVIRONMENTS.forEach((environment) => port.jobs(inputFor(environment)).forEach((job) => {
|
|
643
|
+
expect(job.label.trim()).not.toBe("");
|
|
644
|
+
expect(job.local.length).toBeGreaterThan(0);
|
|
645
|
+
job.local.forEach(({ command }) => expect(command.trim()).not.toBe(""));
|
|
646
|
+
}));
|
|
647
|
+
});
|
|
648
|
+
it("given a folder with nothing in it, when init looks at it, then the adapter recognises nothing", () => {
|
|
649
|
+
expect(adapter.detect?.(EMPTY_FOLDER) ?? null).toBeNull();
|
|
650
|
+
});
|
|
651
|
+
it("given an app it ships, when doctor asks what it needs, then each need has a name and a check", () => {
|
|
652
|
+
(adapter.requirements?.(unit) ?? []).forEach(({ label, check }) => {
|
|
653
|
+
expect(label.trim()).not.toBe("");
|
|
654
|
+
expect(check.command.trim()).not.toBe("");
|
|
655
|
+
});
|
|
656
|
+
});
|
|
657
|
+
more(adapter, port);
|
|
658
|
+
});
|
|
659
|
+
//#endregion
|
|
660
|
+
//#region src/adapters/server-hosting/server-hosting.contract.ts
|
|
661
|
+
/** What every server host does, whatever its provider. */
|
|
662
|
+
const serverHostingContract = (cases) => deliveryContract("server hosting", cases, (_adapter, port) => {
|
|
663
|
+
it("given a server host, when its kind is read, then it hosts servers", () => {
|
|
664
|
+
expect(port.capability).toBe("server-hosting");
|
|
665
|
+
});
|
|
666
|
+
});
|
|
667
|
+
//#endregion
|
|
668
|
+
//#region src/adapters/static-hosting/static-hosting.contract.ts
|
|
669
|
+
/** What every static host does, whatever its provider. */
|
|
670
|
+
const staticHostingContract = (cases) => deliveryContract("static hosting", cases, (_adapter, port) => {
|
|
671
|
+
it("given a static host, when its kind is read, then it hosts static sites", () => {
|
|
672
|
+
expect(port.capability).toBe("static-hosting");
|
|
673
|
+
});
|
|
674
|
+
});
|
|
675
|
+
//#endregion
|
|
676
|
+
//#region src/adapters/mobile-distribution/mobile-distribution.contract.ts
|
|
677
|
+
/** What every mobile distribution does, whatever its provider. */
|
|
678
|
+
const mobileDistributionContract = (cases) => deliveryContract("mobile distribution", cases, (adapter, port) => {
|
|
679
|
+
it("given a mobile distribution, when status asks who decides, then its platform is named", () => {
|
|
680
|
+
expect(port.capability).toBe("mobile-distribution");
|
|
681
|
+
expect(adapter.decidedBy?.platform.trim() ?? "").not.toBe("");
|
|
682
|
+
});
|
|
683
|
+
});
|
|
684
|
+
//#endregion
|
|
685
|
+
//#region src/adapters/package-registry/package-registry.contract.ts
|
|
686
|
+
/** What every package registry does, whatever its provider. */
|
|
687
|
+
const packageRegistryContract = (cases) => deliveryContract("a package registry", cases, (_adapter, port) => {
|
|
688
|
+
it("given a package registry, when its kind is read, then it publishes packages", () => {
|
|
689
|
+
expect(port.capability).toBe("package-registry");
|
|
690
|
+
});
|
|
691
|
+
});
|
|
692
|
+
//#endregion
|
|
693
|
+
//#region src/adapters/source-control/source-control.contract.ts
|
|
694
|
+
/** What every source control does, whatever its provider. */
|
|
695
|
+
const sourceControlContract = (name, subject) => describe(`${name}, as source control`, () => {
|
|
696
|
+
it("given a fresh checkout, when its position is read, then it is on main with nothing to commit", async () => {
|
|
697
|
+
const { port } = await subject();
|
|
698
|
+
expect((await port.position()).branch).toBe("main");
|
|
699
|
+
expect(await port.isClean()).toBe(true);
|
|
700
|
+
});
|
|
701
|
+
it("given a commit tagged, when the tags are read, then the tag is there and names that commit", async () => {
|
|
702
|
+
const { port, head } = await subject();
|
|
703
|
+
const sha = await head();
|
|
704
|
+
await port.tag("app@1.0.0", sha, "app 1.0.0");
|
|
705
|
+
expect(await port.tags()).toContain("app@1.0.0");
|
|
706
|
+
expect(await port.tagCommit("app@1.0.0")).toBe(sha);
|
|
707
|
+
});
|
|
708
|
+
it("given tags in every format a config names, when the tags are read, then each one is there", async () => {
|
|
709
|
+
const { port, head } = await subject();
|
|
710
|
+
const sha = await head();
|
|
711
|
+
for (const tag of [
|
|
712
|
+
"arnaud-zg--v0.2.1",
|
|
713
|
+
"v1.0.0",
|
|
714
|
+
"app@1.0.0"
|
|
715
|
+
]) await port.tag(tag, sha, tag);
|
|
716
|
+
expect([...await port.tags()].sort()).toEqual([
|
|
717
|
+
"app@1.0.0",
|
|
718
|
+
"arnaud-zg--v0.2.1",
|
|
719
|
+
"v1.0.0"
|
|
720
|
+
]);
|
|
721
|
+
});
|
|
722
|
+
it("given a tag deleted, when the tags are read, then it is gone and names no commit", async () => {
|
|
723
|
+
const { port, head } = await subject();
|
|
724
|
+
await port.tag("app@1.0.0", await head(), "app 1.0.0");
|
|
725
|
+
await port.deleteTag("app@1.0.0");
|
|
726
|
+
expect(await port.tags()).not.toContain("app@1.0.0");
|
|
727
|
+
expect(await port.tagCommit("app@1.0.0")).toBeNull();
|
|
728
|
+
});
|
|
729
|
+
it("given a branch created, when the position is read, then it is on it, and switching back returns to main", async () => {
|
|
730
|
+
const { port } = await subject();
|
|
731
|
+
await port.createBranch("release/next");
|
|
732
|
+
const onBranch = (await port.position()).branch;
|
|
733
|
+
await port.switchTo("main");
|
|
734
|
+
expect(onBranch).toBe("release/next");
|
|
735
|
+
expect((await port.position()).branch).toBe("main");
|
|
736
|
+
});
|
|
737
|
+
it("given a new file committed, when the changes are read, then it is no longer among them", async () => {
|
|
738
|
+
const { port, change } = await subject();
|
|
739
|
+
await change("notes.md", "notes\n");
|
|
740
|
+
const before = await port.changedFiles();
|
|
741
|
+
await port.commit(["notes.md"], "docs: notes");
|
|
742
|
+
expect(before).toContain("notes.md");
|
|
743
|
+
expect(await port.changedFiles()).not.toContain("notes.md");
|
|
744
|
+
});
|
|
745
|
+
});
|
|
746
|
+
//#endregion
|
|
747
|
+
//#region src/adapters/code-host/code-host.contract.ts
|
|
748
|
+
/** What every code host does, whatever its provider. */
|
|
749
|
+
const codeHostContract = (name, subject) => describe(`${name}, as a code host`, () => {
|
|
750
|
+
it("given a pull request opened, when the open ones are read, then it is there and open", async () => {
|
|
751
|
+
const { port, branch } = await subject();
|
|
752
|
+
const head = await branch("release/contract-open");
|
|
753
|
+
const pr = await port.createPr({
|
|
754
|
+
base: "main",
|
|
755
|
+
head,
|
|
756
|
+
title: "chore: contract",
|
|
757
|
+
body: "Opened by the contract suite.",
|
|
758
|
+
label: "release"
|
|
759
|
+
});
|
|
760
|
+
expect(await port.openPrsFrom("release/contract-open")).toContainEqual(pr);
|
|
761
|
+
expect(await port.prState(pr)).toBe("OPEN");
|
|
762
|
+
});
|
|
763
|
+
it("given a pull request closed, when the open ones are read, then it is gone and closed", async () => {
|
|
764
|
+
const { port, branch } = await subject();
|
|
765
|
+
const head = await branch("release/contract-close");
|
|
766
|
+
const pr = await port.createPr({
|
|
767
|
+
base: "main",
|
|
768
|
+
head,
|
|
769
|
+
title: "chore: contract",
|
|
770
|
+
body: "Opened by the contract suite.",
|
|
771
|
+
label: "release"
|
|
772
|
+
});
|
|
773
|
+
await port.closePr(pr, "Closed by the contract suite.");
|
|
774
|
+
expect(await port.openPrsFrom("release/contract-close")).not.toContainEqual(pr);
|
|
775
|
+
expect(await port.prState(pr)).toBe("CLOSED");
|
|
776
|
+
});
|
|
777
|
+
it("given release notes published for a tag, when the released tags are read, then it is among them", async () => {
|
|
778
|
+
const { port, tag } = await subject();
|
|
779
|
+
const name = await tag();
|
|
780
|
+
await port.createRelease(name, "Published by the contract suite.", false);
|
|
781
|
+
expect(await port.releasedTags()).toContain(name);
|
|
782
|
+
});
|
|
783
|
+
it("given a deploy recorded, when the deploys are read, then it is there and done", async () => {
|
|
784
|
+
const { port, tag } = await subject();
|
|
785
|
+
const name = await tag();
|
|
786
|
+
await port.recordDeployment(name, "preview");
|
|
787
|
+
expect(await port.deployments()).toContainEqual({
|
|
788
|
+
title: `Deploy ${name} to preview`,
|
|
789
|
+
state: "done"
|
|
790
|
+
});
|
|
791
|
+
});
|
|
792
|
+
it("given a comment posted, when the comments are read, then it is among them", async () => {
|
|
793
|
+
const { port, issue } = await subject();
|
|
794
|
+
const body = `Posted by the contract suite at ${(/* @__PURE__ */ new Date()).toISOString()}.`;
|
|
795
|
+
await port.comment(issue, body);
|
|
796
|
+
expect((await port.comments([issue])).flat()).toContain(body);
|
|
797
|
+
});
|
|
798
|
+
});
|
|
799
|
+
//#endregion
|
|
800
|
+
//#region src/adapters/ci-pipeline/ci-pipeline.contract.ts
|
|
801
|
+
/** What every CI pipeline does, whatever its provider. */
|
|
802
|
+
const ciPipelineContract = (name, subject) => describe(`${name}, as a CI pipeline`, () => {
|
|
803
|
+
it("given a workflow that never ran, when its runs are read, then there are none", async () => {
|
|
804
|
+
const { port, idle } = await subject();
|
|
805
|
+
expect(await port.workflowRuns(idle)).toEqual([]);
|
|
806
|
+
});
|
|
807
|
+
it("given a workflow that never succeeded, when its billed minutes are read, then none are measured", async () => {
|
|
808
|
+
const { port, idle } = await subject();
|
|
809
|
+
expect(await port.measuredMinutes(idle)).toEqual([]);
|
|
810
|
+
});
|
|
811
|
+
it("given this month's budget, when it is read, then what is left is never more than included", async () => {
|
|
812
|
+
const { port } = await subject();
|
|
813
|
+
const minutes = await port.minutes();
|
|
814
|
+
if (minutes) expect(minutes.left).toBeLessThanOrEqual(minutes.included);
|
|
815
|
+
else expect(minutes).toBeNull();
|
|
816
|
+
});
|
|
817
|
+
});
|
|
818
|
+
//#endregion
|
|
819
|
+
//#region src/adapters/versioning/versioning.contract.ts
|
|
820
|
+
/** What every versioning does, whatever its provider. */
|
|
821
|
+
const versioningContract = (name, subject) => describe(`${name}, as versioning`, () => {
|
|
822
|
+
it("given a change written, when the pending changes are read, then it is there naming its package and bump", async () => {
|
|
823
|
+
const { port, workspace } = await subject();
|
|
824
|
+
await port.write({
|
|
825
|
+
id: "contract-change",
|
|
826
|
+
releases: [{
|
|
827
|
+
name: workspace.name,
|
|
828
|
+
type: "minor"
|
|
829
|
+
}],
|
|
830
|
+
summary: "Written by the contract suite."
|
|
831
|
+
});
|
|
832
|
+
const pending = await port.pending();
|
|
833
|
+
expect(pending.map(({ id }) => id)).toContain("contract-change");
|
|
834
|
+
expect(pending.find(({ id }) => id === "contract-change")?.text).toContain(`"${workspace.name}": minor`);
|
|
835
|
+
});
|
|
836
|
+
it("given a workspace package, when the folders are read, then it is found in its folder", async () => {
|
|
837
|
+
const { port, workspace } = await subject();
|
|
838
|
+
expect(await port.folders()).toMatchObject({ [workspace.name]: workspace.folder });
|
|
839
|
+
});
|
|
840
|
+
it("given a change and a folder, when their files are named, then they sit where a person looks", async () => {
|
|
841
|
+
const { port, workspace } = await subject();
|
|
842
|
+
expect(port.changesetFile("contract-change")).toBe(".changeset/contract-change.md");
|
|
843
|
+
expect(port.changelogFile(workspace.folder)).toBe(`${workspace.folder}/CHANGELOG.md`);
|
|
844
|
+
});
|
|
845
|
+
});
|
|
846
|
+
//#endregion
|
|
847
|
+
//#region src/adapters/server-hosting/__fakes__/server-hosting.fake.ts
|
|
848
|
+
const ServerSettings = z.object({
|
|
849
|
+
service: z.string().describe("The service it deploys"),
|
|
850
|
+
url: perEnv(z.string()).optional().describe("Where it answers, for other apps to read")
|
|
851
|
+
});
|
|
852
|
+
const Resolved = z.object({ service: z.string() });
|
|
853
|
+
/** A server host held in memory: it deploys nothing, and records each deploy it was asked for. */
|
|
854
|
+
var ServerHostingFake = class {
|
|
855
|
+
capability = "server-hosting";
|
|
856
|
+
needs = [];
|
|
857
|
+
received = [];
|
|
858
|
+
/** What doctor checks for each app it ships. */
|
|
859
|
+
seed({ requirements }) {
|
|
860
|
+
this.needs = requirements;
|
|
861
|
+
return this;
|
|
862
|
+
}
|
|
863
|
+
describe = ({ options }) => `${Resolved.parse(options).service} (fake)`;
|
|
864
|
+
jobs = ({ tag, environment, options }) => {
|
|
865
|
+
const { service } = Resolved.parse(options);
|
|
866
|
+
this.received.push({
|
|
867
|
+
tag,
|
|
868
|
+
environment,
|
|
869
|
+
service
|
|
870
|
+
});
|
|
871
|
+
return [{
|
|
872
|
+
label: `deploy ${tag} to ${service} (fake)`,
|
|
873
|
+
local: [{
|
|
874
|
+
command: "echo",
|
|
875
|
+
args: [
|
|
876
|
+
"deploy",
|
|
877
|
+
service,
|
|
878
|
+
tag
|
|
879
|
+
]
|
|
880
|
+
}],
|
|
881
|
+
ci: { ref: tag },
|
|
882
|
+
record: true
|
|
883
|
+
}];
|
|
884
|
+
};
|
|
885
|
+
requirements = () => this.needs;
|
|
886
|
+
};
|
|
887
|
+
/** The Fake as a config holds an adapter; `.fake` is what a test seeds and reads. */
|
|
888
|
+
const serverHostingFake = (fake = new ServerHostingFake()) => ({
|
|
889
|
+
name: "fake",
|
|
890
|
+
capability: "server-hosting",
|
|
891
|
+
settings: ServerSettings,
|
|
892
|
+
typicalMinutes: 1,
|
|
893
|
+
requirements: () => fake.requirements(),
|
|
894
|
+
create: () => fake,
|
|
895
|
+
fake
|
|
896
|
+
});
|
|
897
|
+
//#endregion
|
|
898
|
+
//#region src/adapters/static-hosting/__fakes__/static-hosting.fake.ts
|
|
899
|
+
const StaticSettings = z.object({ site: z.string().describe("The site it uploads to") });
|
|
900
|
+
/** A static host held in memory: it uploads nothing, and records each upload it was asked for. */
|
|
901
|
+
var StaticHostingFake = class {
|
|
902
|
+
capability = "static-hosting";
|
|
903
|
+
needs = [];
|
|
904
|
+
received = [];
|
|
905
|
+
/** What doctor checks for each app it ships. */
|
|
906
|
+
seed({ requirements }) {
|
|
907
|
+
this.needs = requirements;
|
|
908
|
+
return this;
|
|
909
|
+
}
|
|
910
|
+
describe = ({ options, environment }) => `${StaticSettings.parse(options).site} (fake, ${environment})`;
|
|
911
|
+
jobs = ({ tag, environment, options }) => {
|
|
912
|
+
const { site } = StaticSettings.parse(options);
|
|
913
|
+
this.received.push({
|
|
914
|
+
tag,
|
|
915
|
+
environment,
|
|
916
|
+
site
|
|
917
|
+
});
|
|
918
|
+
return [{
|
|
919
|
+
label: `build ${tag} and upload it to ${site} (fake)`,
|
|
920
|
+
local: [{
|
|
921
|
+
command: "echo",
|
|
922
|
+
args: [
|
|
923
|
+
"upload",
|
|
924
|
+
site,
|
|
925
|
+
tag
|
|
926
|
+
]
|
|
927
|
+
}],
|
|
928
|
+
ci: { ref: tag },
|
|
929
|
+
record: true
|
|
930
|
+
}];
|
|
931
|
+
};
|
|
932
|
+
requirements = () => this.needs;
|
|
933
|
+
};
|
|
934
|
+
/** The Fake as a config holds an adapter; `.fake` is what a test seeds and reads. */
|
|
935
|
+
const staticHostingFake = (fake = new StaticHostingFake()) => ({
|
|
936
|
+
name: "fake",
|
|
937
|
+
capability: "static-hosting",
|
|
938
|
+
settings: StaticSettings,
|
|
939
|
+
typicalMinutes: 1,
|
|
940
|
+
requirements: () => fake.requirements(),
|
|
941
|
+
create: () => fake,
|
|
942
|
+
fake
|
|
943
|
+
});
|
|
944
|
+
//#endregion
|
|
945
|
+
//#region src/adapters/mobile-distribution/__fakes__/mobile-distribution.fake.ts
|
|
946
|
+
const MobileSettings = z.object({ app: z.string().describe("The app it ships to the stores and over the air") });
|
|
947
|
+
const DECIDED_BY = {
|
|
948
|
+
platform: "the fake platform",
|
|
949
|
+
choice: "update or nothing",
|
|
950
|
+
check: "shiplane status"
|
|
951
|
+
};
|
|
952
|
+
/**
|
|
953
|
+
* A mobile platform held in memory: seed what each environment runs and how a tag does; a version
|
|
954
|
+
* not live yet ships as an update.
|
|
955
|
+
*/
|
|
956
|
+
var MobileDistributionFake = class {
|
|
957
|
+
capability = "mobile-distribution";
|
|
958
|
+
state = {
|
|
959
|
+
live: {},
|
|
960
|
+
health: {},
|
|
961
|
+
requirements: []
|
|
962
|
+
};
|
|
963
|
+
received = [];
|
|
964
|
+
seed(state) {
|
|
965
|
+
this.state = {
|
|
966
|
+
...this.state,
|
|
967
|
+
...state
|
|
968
|
+
};
|
|
969
|
+
return this;
|
|
970
|
+
}
|
|
971
|
+
ask(stage, { tag, environment }) {
|
|
972
|
+
this.received.push({
|
|
973
|
+
stage,
|
|
974
|
+
tag,
|
|
975
|
+
environment
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
describe = ({ options, environment }) => `${MobileSettings.parse(options).app} on ${environment} (fake)`;
|
|
979
|
+
jobs = (input) => {
|
|
980
|
+
this.ask("jobs", input);
|
|
981
|
+
const { tag, environment, options } = input;
|
|
982
|
+
const { app } = MobileSettings.parse(options);
|
|
983
|
+
return [{
|
|
984
|
+
label: `publish ${tag} to ${app} on ${environment} (fake)`,
|
|
985
|
+
local: [{
|
|
986
|
+
command: "echo",
|
|
987
|
+
args: [
|
|
988
|
+
"update",
|
|
989
|
+
app,
|
|
990
|
+
tag
|
|
991
|
+
]
|
|
992
|
+
}],
|
|
993
|
+
ci: { ref: tag }
|
|
994
|
+
}];
|
|
995
|
+
};
|
|
996
|
+
decide = (_context, input) => {
|
|
997
|
+
this.ask("decide", input);
|
|
998
|
+
const { unit, environment } = input;
|
|
999
|
+
const decision = this.state.live[environment] === unit.version ? {
|
|
1000
|
+
action: "none",
|
|
1001
|
+
status: `${unit.name} ${unit.version} is on ${environment}`
|
|
1002
|
+
} : {
|
|
1003
|
+
action: "ship",
|
|
1004
|
+
kind: "update",
|
|
1005
|
+
jobs: this.jobs(input)
|
|
1006
|
+
};
|
|
1007
|
+
return Promise.resolve(decision);
|
|
1008
|
+
};
|
|
1009
|
+
health = (_context, input) => {
|
|
1010
|
+
this.ask("health", input);
|
|
1011
|
+
return Promise.resolve(this.state.health[input.tag] ?? null);
|
|
1012
|
+
};
|
|
1013
|
+
inspect = (_context, input) => {
|
|
1014
|
+
this.ask("inspect", input);
|
|
1015
|
+
return Promise.resolve({ live: this.state.live[input.environment] ?? null });
|
|
1016
|
+
};
|
|
1017
|
+
requirements = () => this.state.requirements;
|
|
1018
|
+
};
|
|
1019
|
+
/** The Fake as a config holds an adapter; `.fake` is what a test seeds and reads. */
|
|
1020
|
+
const mobileDistributionFake = (fake = new MobileDistributionFake()) => ({
|
|
1021
|
+
name: "fake",
|
|
1022
|
+
capability: "mobile-distribution",
|
|
1023
|
+
settings: MobileSettings,
|
|
1024
|
+
typicalMinutes: 1,
|
|
1025
|
+
decidedBy: DECIDED_BY,
|
|
1026
|
+
requirements: () => fake.requirements(),
|
|
1027
|
+
create: () => fake,
|
|
1028
|
+
fake
|
|
1029
|
+
});
|
|
1030
|
+
//#endregion
|
|
1031
|
+
//#region src/adapters/package-registry/__fakes__/package-registry.fake.ts
|
|
1032
|
+
const PackageSettings = z.object({ tag: z.string().default("latest").describe("The dist-tag a release moves") });
|
|
1033
|
+
/** A package registry held in memory: seed what is published, a version not there yet publishes. */
|
|
1034
|
+
var PackageRegistryFake = class {
|
|
1035
|
+
capability = "package-registry";
|
|
1036
|
+
/** `<package>@<version>` already published. */
|
|
1037
|
+
published = /* @__PURE__ */ new Set();
|
|
1038
|
+
needs = [];
|
|
1039
|
+
received = [];
|
|
1040
|
+
seed({ published = [], requirements = [] }) {
|
|
1041
|
+
this.published = new Set(published);
|
|
1042
|
+
this.needs = requirements;
|
|
1043
|
+
return this;
|
|
1044
|
+
}
|
|
1045
|
+
describe = ({ unit, options }) => `${unit.packageName} (fake, ${PackageSettings.parse(options).tag})`;
|
|
1046
|
+
jobs = ({ unit, tag, environment, options }) => {
|
|
1047
|
+
this.received.push({
|
|
1048
|
+
stage: "jobs",
|
|
1049
|
+
tag,
|
|
1050
|
+
environment
|
|
1051
|
+
});
|
|
1052
|
+
return [{
|
|
1053
|
+
label: `publish ${unit.packageName}@${unit.version} under ${PackageSettings.parse(options).tag} (fake)`,
|
|
1054
|
+
local: [{
|
|
1055
|
+
command: "echo",
|
|
1056
|
+
args: [
|
|
1057
|
+
"publish",
|
|
1058
|
+
unit.packageName,
|
|
1059
|
+
unit.version
|
|
1060
|
+
]
|
|
1061
|
+
}]
|
|
1062
|
+
}];
|
|
1063
|
+
};
|
|
1064
|
+
decide = (_context, input) => {
|
|
1065
|
+
const { unit, tag, environment } = input;
|
|
1066
|
+
this.received.push({
|
|
1067
|
+
stage: "decide",
|
|
1068
|
+
tag,
|
|
1069
|
+
environment
|
|
1070
|
+
});
|
|
1071
|
+
const decision = this.published.has(`${unit.packageName}@${unit.version}`) ? {
|
|
1072
|
+
action: "none",
|
|
1073
|
+
status: `${unit.packageName}@${unit.version} is published`
|
|
1074
|
+
} : {
|
|
1075
|
+
action: "ship",
|
|
1076
|
+
kind: "publish",
|
|
1077
|
+
jobs: this.jobs(input)
|
|
1078
|
+
};
|
|
1079
|
+
return Promise.resolve(decision);
|
|
1080
|
+
};
|
|
1081
|
+
live = (_context, { unit }) => Promise.resolve(this.published.has(`${unit.packageName}@${unit.version}`));
|
|
1082
|
+
requirements = () => this.needs;
|
|
1083
|
+
};
|
|
1084
|
+
/** The Fake as a config holds an adapter; `.fake` is what a test seeds and reads. */
|
|
1085
|
+
const packageRegistryFake = (fake = new PackageRegistryFake()) => ({
|
|
1086
|
+
name: "fake",
|
|
1087
|
+
capability: "package-registry",
|
|
1088
|
+
settings: PackageSettings,
|
|
1089
|
+
typicalMinutes: 1,
|
|
1090
|
+
requirements: () => fake.requirements(),
|
|
1091
|
+
create: () => fake,
|
|
1092
|
+
fake
|
|
1093
|
+
});
|
|
1094
|
+
//#endregion
|
|
1095
|
+
//#region src/testing/sample.ts
|
|
1096
|
+
/** This repository's four shipping units, as the rule tests were written against them. */
|
|
1097
|
+
const SAMPLE_UNITS = [
|
|
1098
|
+
"expo",
|
|
1099
|
+
"api",
|
|
1100
|
+
"admin",
|
|
1101
|
+
"landing"
|
|
1102
|
+
].map((name) => ({
|
|
1103
|
+
name,
|
|
1104
|
+
packageName: `@acme/${name}`
|
|
1105
|
+
}));
|
|
1106
|
+
const SAMPLE_VERSION_FILES = new Set([
|
|
1107
|
+
"apps/expo/app-version.json",
|
|
1108
|
+
"apps/api/public/app-version.preview.json",
|
|
1109
|
+
"apps/api/public/app-version.production.json"
|
|
1110
|
+
]);
|
|
1111
|
+
//#endregion
|
|
1112
|
+
//#region src/testing/live.ts
|
|
1113
|
+
/**
|
|
1114
|
+
* Contract suites against hosted services run only with RELEASE_CONTRACT_LIVE=1, on a sandbox
|
|
1115
|
+
* repository checked out at RELEASE_CONTRACT_REPO: they open pull requests, publish releases and
|
|
1116
|
+
* dispatch workflows there.
|
|
1117
|
+
*/
|
|
1118
|
+
const LIVE = systemShell.env("RELEASE_CONTRACT_LIVE") === "1";
|
|
1119
|
+
/** The sandbox checkout, refused when unset so a live run never touches this repository. */
|
|
1120
|
+
const sandbox = () => z.string({ message: "RELEASE_CONTRACT_REPO names a sandbox checkout for live contracts" }).min(1).parse(systemShell.env("RELEASE_CONTRACT_REPO"));
|
|
1121
|
+
/** Runs git in the sandbox and returns what it printed. */
|
|
1122
|
+
const inSandbox = (args) => execFileSync("git", args, {
|
|
1123
|
+
cwd: sandbox(),
|
|
1124
|
+
encoding: "utf8"
|
|
1125
|
+
}).trim();
|
|
1126
|
+
//#endregion
|
|
1127
|
+
//#region src/testing/plans.ts
|
|
1128
|
+
const bump = (version, type) => {
|
|
1129
|
+
const [major = 0, minor = 0] = version.split(".").map(Number);
|
|
1130
|
+
if (type === "major") return `${major + 1}.0.0`;
|
|
1131
|
+
if (type === "minor") return `${major}.${minor + 1}.0`;
|
|
1132
|
+
return nextPatch(version);
|
|
1133
|
+
};
|
|
1134
|
+
/**
|
|
1135
|
+
* What `changeset status` answers for these pending changesets, plus the ones a release adds, minus
|
|
1136
|
+
* the lines it holds back: every named package moves once, by its biggest bump.
|
|
1137
|
+
*/
|
|
1138
|
+
const planFrom = (pending, versions) => (added, held) => {
|
|
1139
|
+
const heldLines = new Set(held.flatMap(({ id, releases }) => releases.map(({ name }) => `${id}:${name}`)));
|
|
1140
|
+
const changesets = [...pending, ...added].map((changeset) => ({
|
|
1141
|
+
...changeset,
|
|
1142
|
+
releases: changeset.releases.filter(({ name }) => !heldLines.has(`${changeset.id}:${name}`))
|
|
1143
|
+
})).filter(({ releases }) => releases.length > 0);
|
|
1144
|
+
const order = [
|
|
1145
|
+
"major",
|
|
1146
|
+
"minor",
|
|
1147
|
+
"patch"
|
|
1148
|
+
];
|
|
1149
|
+
return {
|
|
1150
|
+
changesets,
|
|
1151
|
+
releases: [...new Set(changesets.flatMap(({ releases }) => releases.map(({ name }) => name)))].map((name) => {
|
|
1152
|
+
const lines = changesets.filter(({ releases }) => releases.some((line) => line.name === name));
|
|
1153
|
+
const type = order.find((candidate) => lines.some(({ releases }) => releases.some((line) => line.name === name && line.type === candidate))) ?? "patch";
|
|
1154
|
+
const oldVersion = versions[name] ?? "0.1.0";
|
|
1155
|
+
return {
|
|
1156
|
+
name,
|
|
1157
|
+
type,
|
|
1158
|
+
oldVersion,
|
|
1159
|
+
newVersion: bump(oldVersion, type),
|
|
1160
|
+
changesets: lines.map(({ id }) => id)
|
|
1161
|
+
};
|
|
1162
|
+
})
|
|
1163
|
+
};
|
|
1164
|
+
};
|
|
1165
|
+
//#endregion
|
|
1166
|
+
//#region src/testing/consumer.ts
|
|
1167
|
+
const CORE = "shiplane";
|
|
1168
|
+
const coreDir = (from) => {
|
|
1169
|
+
const manifest = path.join(from, "package.json");
|
|
1170
|
+
if (fs.existsSync(manifest)) {
|
|
1171
|
+
const { name } = JSON.parse(fs.readFileSync(manifest, "utf8"));
|
|
1172
|
+
if (name === CORE) return from;
|
|
1173
|
+
}
|
|
1174
|
+
const parent = path.dirname(from);
|
|
1175
|
+
if (parent === from) throw new Error(`${CORE} not found above ${import.meta.dirname}`);
|
|
1176
|
+
return coreDir(parent);
|
|
1177
|
+
};
|
|
1178
|
+
/** The built CLI, as `pnpm add shiplane` installs it. */
|
|
1179
|
+
const builtCli = () => {
|
|
1180
|
+
const cli = path.join(coreDir(import.meta.dirname), "dist", "cli.js");
|
|
1181
|
+
if (!fs.existsSync(cli)) throw new Error(`shiplane is not built: run pnpm turbo run build --filter=${CORE}`);
|
|
1182
|
+
return cli;
|
|
1183
|
+
};
|
|
1184
|
+
const LEAKS = new Set([
|
|
1185
|
+
"GITHUB_ACTIONS",
|
|
1186
|
+
"CI",
|
|
1187
|
+
"GITHUB_TOKEN",
|
|
1188
|
+
"GH_TOKEN"
|
|
1189
|
+
]);
|
|
1190
|
+
const hermeticEnv = (home, bin) => ({
|
|
1191
|
+
...Object.fromEntries(Object.entries(process.env).filter(([name]) => !LEAKS.has(name))),
|
|
1192
|
+
PATH: [bin, systemShell.env("PATH") ?? ""].join(path.delimiter),
|
|
1193
|
+
HOME: home,
|
|
1194
|
+
GIT_CONFIG_GLOBAL: path.join(home, ".gitconfig"),
|
|
1195
|
+
GIT_CONFIG_NOSYSTEM: "1",
|
|
1196
|
+
NO_COLOR: "1",
|
|
1197
|
+
GIT_AUTHOR_DATE: "2026-01-01T00:00:00Z",
|
|
1198
|
+
GIT_COMMITTER_DATE: "2026-01-01T00:00:00Z"
|
|
1199
|
+
});
|
|
1200
|
+
const OFFLINE = [
|
|
1201
|
+
"gh",
|
|
1202
|
+
"npm",
|
|
1203
|
+
"flyctl"
|
|
1204
|
+
];
|
|
1205
|
+
const offlineTools = (bin) => {
|
|
1206
|
+
fs.mkdirSync(bin);
|
|
1207
|
+
OFFLINE.forEach((tool) => {
|
|
1208
|
+
const file = path.join(bin, tool);
|
|
1209
|
+
fs.writeFileSync(file, `#!/bin/sh\necho "${tool}: offline in this repository" >&2\nexit 1\n`);
|
|
1210
|
+
fs.chmodSync(file, 493);
|
|
1211
|
+
});
|
|
1212
|
+
};
|
|
1213
|
+
/**
|
|
1214
|
+
* A repository as a consumer has it: its files, the packages it installed linked in its
|
|
1215
|
+
* node_modules, one commit pushed to a local bare origin. gh, npm and flyctl answer offline.
|
|
1216
|
+
*/
|
|
1217
|
+
const consumerRepository = ({ files, packages = {}, branch = "main" }) => {
|
|
1218
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "shiplane-consumer-"));
|
|
1219
|
+
const root = path.join(dir, "checkout");
|
|
1220
|
+
const origin = path.join(dir, "origin.git");
|
|
1221
|
+
const home = path.join(dir, "home");
|
|
1222
|
+
fs.mkdirSync(home);
|
|
1223
|
+
fs.writeFileSync(path.join(home, ".gitconfig"), "[user]\n name = Shiplane Consumer\n email = consumer@example.com\n[commit]\n gpgsign = false\n[tag]\n gpgsign = false\n[core]\n hooksPath = /dev/null\n");
|
|
1224
|
+
const bin = path.join(dir, "bin");
|
|
1225
|
+
offlineTools(bin);
|
|
1226
|
+
const env = hermeticEnv(home, bin);
|
|
1227
|
+
const git = (args, where) => execFileSync("git", args, {
|
|
1228
|
+
cwd: where ? origin : root,
|
|
1229
|
+
env,
|
|
1230
|
+
stdio: "pipe",
|
|
1231
|
+
encoding: "utf8"
|
|
1232
|
+
}).trim();
|
|
1233
|
+
const write = (file, text) => {
|
|
1234
|
+
const target = path.join(root, file);
|
|
1235
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
1236
|
+
fs.writeFileSync(target, text);
|
|
1237
|
+
};
|
|
1238
|
+
fs.mkdirSync(root);
|
|
1239
|
+
execFileSync("git", [
|
|
1240
|
+
"init",
|
|
1241
|
+
"--quiet",
|
|
1242
|
+
"--bare",
|
|
1243
|
+
`--initial-branch=${branch}`,
|
|
1244
|
+
origin
|
|
1245
|
+
], { env });
|
|
1246
|
+
git([
|
|
1247
|
+
"init",
|
|
1248
|
+
"--quiet",
|
|
1249
|
+
`--initial-branch=${branch}`
|
|
1250
|
+
]);
|
|
1251
|
+
git([
|
|
1252
|
+
"remote",
|
|
1253
|
+
"add",
|
|
1254
|
+
"origin",
|
|
1255
|
+
origin
|
|
1256
|
+
]);
|
|
1257
|
+
write(".gitignore", "node_modules\n");
|
|
1258
|
+
Object.entries(files).forEach(([file, text]) => write(file, text));
|
|
1259
|
+
Object.entries({
|
|
1260
|
+
[CORE]: coreDir(import.meta.dirname),
|
|
1261
|
+
...packages
|
|
1262
|
+
}).forEach(([name, from]) => {
|
|
1263
|
+
const link = path.join(root, "node_modules", name);
|
|
1264
|
+
fs.mkdirSync(path.dirname(link), { recursive: true });
|
|
1265
|
+
fs.symlinkSync(from, link, "dir");
|
|
1266
|
+
});
|
|
1267
|
+
const commitAndPush = (title) => {
|
|
1268
|
+
git(["add", "--all"]);
|
|
1269
|
+
git([
|
|
1270
|
+
"commit",
|
|
1271
|
+
"--quiet",
|
|
1272
|
+
"-m",
|
|
1273
|
+
title
|
|
1274
|
+
]);
|
|
1275
|
+
git([
|
|
1276
|
+
"push",
|
|
1277
|
+
"--quiet",
|
|
1278
|
+
"origin",
|
|
1279
|
+
branch
|
|
1280
|
+
]);
|
|
1281
|
+
};
|
|
1282
|
+
commitAndPush("chore: start");
|
|
1283
|
+
const cli = builtCli();
|
|
1284
|
+
return {
|
|
1285
|
+
root,
|
|
1286
|
+
origin,
|
|
1287
|
+
write,
|
|
1288
|
+
read: (file) => fs.readFileSync(path.join(root, file), "utf8"),
|
|
1289
|
+
git,
|
|
1290
|
+
commitAndPush,
|
|
1291
|
+
shiplane: (args) => {
|
|
1292
|
+
const run = spawnSync(process.execPath, [cli, ...args], {
|
|
1293
|
+
cwd: root,
|
|
1294
|
+
env,
|
|
1295
|
+
encoding: "utf8",
|
|
1296
|
+
stdio: [
|
|
1297
|
+
"ignore",
|
|
1298
|
+
"pipe",
|
|
1299
|
+
"pipe"
|
|
1300
|
+
]
|
|
1301
|
+
});
|
|
1302
|
+
return {
|
|
1303
|
+
status: run.status ?? 1,
|
|
1304
|
+
output: `${run.stdout}${run.stderr}`
|
|
1305
|
+
};
|
|
1306
|
+
},
|
|
1307
|
+
remove: () => fs.rmSync(dir, {
|
|
1308
|
+
recursive: true,
|
|
1309
|
+
force: true
|
|
1310
|
+
})
|
|
1311
|
+
};
|
|
1312
|
+
};
|
|
1313
|
+
//#endregion
|
|
1314
|
+
//#region src/testing/workspace.ts
|
|
1315
|
+
/** The public API a test config imports, resolved to source since tests run before any build. */
|
|
1316
|
+
const SOURCE_ALIASES = {
|
|
1317
|
+
shiplane: path.resolve(import.meta.dirname, "../index.ts"),
|
|
1318
|
+
"shiplane/plugin": path.resolve(import.meta.dirname, "../plugin.ts"),
|
|
1319
|
+
"shiplane/testing": path.resolve(import.meta.dirname, "public.ts")
|
|
1320
|
+
};
|
|
1321
|
+
/** A throwaway repository on disk, one entry per file, removed by `remove()`. */
|
|
1322
|
+
const createWorkspace = (files) => {
|
|
1323
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "release-workspace-"));
|
|
1324
|
+
const write = (file, text) => {
|
|
1325
|
+
const target = path.join(root, file);
|
|
1326
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
1327
|
+
fs.writeFileSync(target, text);
|
|
1328
|
+
};
|
|
1329
|
+
Object.entries(files).forEach(([file, text]) => write(file, text));
|
|
1330
|
+
return {
|
|
1331
|
+
root,
|
|
1332
|
+
write,
|
|
1333
|
+
read: (file) => fs.readFileSync(path.join(root, file), "utf8"),
|
|
1334
|
+
exists: (file) => fs.existsSync(path.join(root, file)),
|
|
1335
|
+
remove: () => fs.rmSync(root, {
|
|
1336
|
+
recursive: true,
|
|
1337
|
+
force: true
|
|
1338
|
+
})
|
|
1339
|
+
};
|
|
1340
|
+
};
|
|
1341
|
+
const packageJson = (name, version = "1.0.0", extra = {}) => JSON.stringify({
|
|
1342
|
+
name,
|
|
1343
|
+
version,
|
|
1344
|
+
...extra
|
|
1345
|
+
}, null, 2);
|
|
1346
|
+
//#endregion
|
|
1347
|
+
export { LIVE, MemoryOutput, RecordingShell, SAMPLE_UNITS, SAMPLE_VERSION_FILES, SOURCE_ALIASES, ScriptedPrompter, addUnit, builtCli, changesetText, ciPipelineContract, ciPipelineFake, codeHostContract, codeHostFake, consumerRepository, createWorkspace, docsFor, doctor, inSandbox, initRelease, loadRelease, mobileDistributionContract, mobileDistributionFake, newAdapter, nodeFiles, openReleasePr, packageJson, packageRegistryContract, packageRegistryFake, planFrom, planShips, prepareRelease, promote, readStatus, refreshEditorSchema, releaseToPreview, removeUnit, sandbox, serverHostingContract, serverHostingFake, shipTo, sourceControlContract, sourceControlFake, staticHostingContract, staticHostingFake, systemShell, testContext, testUnit, versioningContract, versioningFake };
|
|
1348
|
+
|
|
1349
|
+
//# sourceMappingURL=testing.js.map
|