shiplane 0.0.0 → 0.2.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-BqtW-Ekk.js +355 -0
- package/dist/budget-BqtW-Ekk.js.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +548 -0
- package/dist/cli.js.map +1 -0
- package/dist/display-IqkJ6uCw.js +96 -0
- package/dist/display-IqkJ6uCw.js.map +1 -0
- package/dist/index-D4qsXAis.d.ts +214 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -0
- package/dist/issues-TcWtMTv5.js +6 -0
- package/dist/issues-TcWtMTv5.js.map +1 -0
- package/dist/memory.d.ts +2 -0
- package/dist/memory.js +2 -0
- package/dist/package-registry.fake-CC37ptzf.d.ts +444 -0
- package/dist/package-registry.fake-Ciqc4ujx.js +633 -0
- package/dist/package-registry.fake-Ciqc4ujx.js.map +1 -0
- package/dist/perEnv-B7AiYnW_.js +11 -0
- package/dist/perEnv-B7AiYnW_.js.map +1 -0
- package/dist/plugin.d.ts +24 -0
- package/dist/plugin.js +8 -0
- package/dist/readStatus-YTZXH_Hh.js +3789 -0
- package/dist/readStatus-YTZXH_Hh.js.map +1 -0
- package/dist/shell-server-hosting.adapter-DobfDqFm.js +49 -0
- package/dist/shell-server-hosting.adapter-DobfDqFm.js.map +1 -0
- package/dist/src-CGASfBy2.js +32 -0
- package/dist/src-CGASfBy2.js.map +1 -0
- package/dist/static-hosting.port-mknLsxwR.d.ts +684 -0
- package/dist/tags-Bn3JrgPI.d.ts +19 -0
- package/dist/testing.d.ts +585 -0
- package/dist/testing.js +735 -0
- package/dist/testing.js.map +1 -0
- package/dist/web-app.module-6KrXIU7j.js +76 -0
- package/dist/web-app.module-6KrXIU7j.js.map +1 -0
- package/package.json +63 -9
package/dist/testing.js
ADDED
|
@@ -0,0 +1,735 @@
|
|
|
1
|
+
import { a as releaseFlow } from "./web-app.module-6KrXIU7j.js";
|
|
2
|
+
import { C as refreshEditorSchema, D as nodeFiles, T as ENVIRONMENTS, _ as loadRelease, a as releaseToPreview, b as initRelease, c as promote, f as openReleasePr, h as docsFor, i as setup, l as shipTo, m as newAdapter, n as systemShell, p as prepareRelease, t as readStatus, u as planShips, v as addUnit, w as optionsFor, x as doctor, y as removeUnit } from "./readStatus-YTZXH_Hh.js";
|
|
3
|
+
import { v as nextPatch, x as DEFAULT_TAG_FORMAT } from "./budget-BqtW-Ekk.js";
|
|
4
|
+
import { a as versioningFake, c as sourceControlFake, i as serverHostingFake, n as mobileDistributionFake, o as ciPipelineFake, r as staticHostingFake, s as codeHostFake, t as packageRegistryFake } from "./package-registry.fake-Ciqc4ujx.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/terminal/__fakes__/progress.fake.ts
|
|
64
|
+
/** Progress kept as events; what it says also goes to the output, as a terminal would print it. */
|
|
65
|
+
var RecordingProgress = class {
|
|
66
|
+
events = [];
|
|
67
|
+
constructor(output) {
|
|
68
|
+
this.output = output;
|
|
69
|
+
}
|
|
70
|
+
stage = (stages, index) => {
|
|
71
|
+
this.events.push({
|
|
72
|
+
kind: "stage",
|
|
73
|
+
text: stages[index] ?? "",
|
|
74
|
+
step: {
|
|
75
|
+
index,
|
|
76
|
+
total: stages.length
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
during = (label, mood, work, step) => {
|
|
81
|
+
this.events.push({
|
|
82
|
+
kind: "during",
|
|
83
|
+
mood,
|
|
84
|
+
text: label,
|
|
85
|
+
...step ? { step } : {}
|
|
86
|
+
});
|
|
87
|
+
return work();
|
|
88
|
+
};
|
|
89
|
+
say = (mood, text) => {
|
|
90
|
+
this.events.push({
|
|
91
|
+
kind: "say",
|
|
92
|
+
mood,
|
|
93
|
+
text
|
|
94
|
+
});
|
|
95
|
+
this.output.line(text);
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/adapters/terminal/__fakes__/terminal.fake.ts
|
|
100
|
+
/** Everything the CLI printed, in order, without colours. */
|
|
101
|
+
var MemoryOutput = class {
|
|
102
|
+
lines = [];
|
|
103
|
+
line = (text = "") => {
|
|
104
|
+
this.lines.push(text.replace(/\u001B\[[0-9;]*m/g, ""));
|
|
105
|
+
};
|
|
106
|
+
get text() {
|
|
107
|
+
return this.lines.join("\n");
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
/** A person who answers from a script, in order; every question asked is kept. */
|
|
111
|
+
var ScriptedPrompter = class {
|
|
112
|
+
asked = [];
|
|
113
|
+
/** The answer each choice question offered first, by question. */
|
|
114
|
+
initials = {};
|
|
115
|
+
/** The choices each select question offered, by question. */
|
|
116
|
+
choices = {};
|
|
117
|
+
answers = [];
|
|
118
|
+
constructor(interactive = true) {
|
|
119
|
+
this.interactive = interactive;
|
|
120
|
+
}
|
|
121
|
+
answer(...answers) {
|
|
122
|
+
this.answers.push(...answers);
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
next(question) {
|
|
126
|
+
this.asked.push(question);
|
|
127
|
+
if (this.answers.length === 0) throw new Error(`Unexpected question: ${question}`);
|
|
128
|
+
return this.answers.shift() ?? null;
|
|
129
|
+
}
|
|
130
|
+
confirm = (question, initial = false) => {
|
|
131
|
+
this.initials[question] = initial;
|
|
132
|
+
return Promise.resolve(this.next(question) === true);
|
|
133
|
+
};
|
|
134
|
+
typed = (question, word) => Promise.resolve(this.next(question) === word);
|
|
135
|
+
select = (message, choices, initial) => {
|
|
136
|
+
this.initials[message] = initial;
|
|
137
|
+
this.choices[message] = choices;
|
|
138
|
+
return Promise.resolve(this.next(message));
|
|
139
|
+
};
|
|
140
|
+
multiselect = (message, _choices) => Promise.resolve(this.next(message));
|
|
141
|
+
text = (message) => Promise.resolve(this.next(message));
|
|
142
|
+
/** No key is ever pressed: every wait times out, unless keys were queued with `press`. */
|
|
143
|
+
keys = [];
|
|
144
|
+
press(...keys) {
|
|
145
|
+
this.keys.push(...keys);
|
|
146
|
+
return this;
|
|
147
|
+
}
|
|
148
|
+
waitForKey = () => Promise.resolve(this.keys.shift() ?? null);
|
|
149
|
+
};
|
|
150
|
+
/** A clock fixed at one moment, whose waits return at once. */
|
|
151
|
+
var FixedClock = class {
|
|
152
|
+
constructor(at) {
|
|
153
|
+
this.at = at;
|
|
154
|
+
}
|
|
155
|
+
now = () => this.at;
|
|
156
|
+
sleep = () => Promise.resolve();
|
|
157
|
+
};
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/testing/releaseContext.ts
|
|
160
|
+
const testUnit = (name, overrides = {}) => ({
|
|
161
|
+
name,
|
|
162
|
+
dir: `apps/${name}`,
|
|
163
|
+
file: `apps/${name}/shiplane.unit.yml`,
|
|
164
|
+
packageName: `@acme/${name}`,
|
|
165
|
+
version: "0.1.0",
|
|
166
|
+
module: "web-app",
|
|
167
|
+
options: {},
|
|
168
|
+
after: [],
|
|
169
|
+
...overrides
|
|
170
|
+
});
|
|
171
|
+
/**
|
|
172
|
+
* A release over a Fake of every port the flow runs on, answered by a scripted person. The apps are
|
|
173
|
+
* in release order as given: the first is the Latest release.
|
|
174
|
+
*/
|
|
175
|
+
const testContext = ({ units, modules = [], features = [], yes = false, interactive = true, root = "/repo", tagFormat = DEFAULT_TAG_FORMAT, commitsWithoutChangeset = "release", approval }) => {
|
|
176
|
+
const sourceControl = sourceControlFake();
|
|
177
|
+
const codeHost = codeHostFake();
|
|
178
|
+
const ciPipeline = ciPipelineFake();
|
|
179
|
+
const versioning = versioningFake();
|
|
180
|
+
const prompter = new ScriptedPrompter(interactive);
|
|
181
|
+
const output = new MemoryOutput();
|
|
182
|
+
const progress = new RecordingProgress(output);
|
|
183
|
+
const shell = new RecordingShell();
|
|
184
|
+
const fakes = {
|
|
185
|
+
sourceControl,
|
|
186
|
+
codeHost,
|
|
187
|
+
ciPipeline,
|
|
188
|
+
versioning
|
|
189
|
+
};
|
|
190
|
+
const release = {
|
|
191
|
+
root,
|
|
192
|
+
flow: releaseFlow({
|
|
193
|
+
...fakes,
|
|
194
|
+
approval
|
|
195
|
+
}),
|
|
196
|
+
modules,
|
|
197
|
+
features: typeof features === "function" ? features(fakes) : features,
|
|
198
|
+
units,
|
|
199
|
+
problems: [],
|
|
200
|
+
tagFormat,
|
|
201
|
+
releasesCommits: commitsWithoutChangeset === "release"
|
|
202
|
+
};
|
|
203
|
+
return {
|
|
204
|
+
context: {
|
|
205
|
+
release,
|
|
206
|
+
load: () => Promise.resolve(release),
|
|
207
|
+
services: {
|
|
208
|
+
sourceControl: sourceControl.fake,
|
|
209
|
+
codeHost: codeHost.fake,
|
|
210
|
+
ciPipeline: ciPipeline.fake,
|
|
211
|
+
versioning: versioning.fake
|
|
212
|
+
},
|
|
213
|
+
open: (adapter) => adapter.create({
|
|
214
|
+
root,
|
|
215
|
+
shell
|
|
216
|
+
}),
|
|
217
|
+
prompter,
|
|
218
|
+
output,
|
|
219
|
+
progress,
|
|
220
|
+
clock: new FixedClock(/* @__PURE__ */ new Date("2026-10-12T09:00:00Z")),
|
|
221
|
+
shell,
|
|
222
|
+
options: {
|
|
223
|
+
yes,
|
|
224
|
+
ci: false
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
flow: fakes,
|
|
228
|
+
source: sourceControl.fake,
|
|
229
|
+
host: codeHost.fake,
|
|
230
|
+
ci: ciPipeline.fake,
|
|
231
|
+
versioning: versioning.fake,
|
|
232
|
+
prompter,
|
|
233
|
+
output,
|
|
234
|
+
progress,
|
|
235
|
+
shell
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
const changesetText = (packages, summary) => `---\n${Object.entries(packages).map(([name, type]) => `"${name}": ${type}`).join("\n")}\n---\n\n${summary}\n`;
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/testing/deliveryContract.ts
|
|
241
|
+
const EMPTY_FOLDER = {
|
|
242
|
+
dir: "apps/empty",
|
|
243
|
+
name: "empty",
|
|
244
|
+
files: [],
|
|
245
|
+
has: () => false,
|
|
246
|
+
read: () => null
|
|
247
|
+
};
|
|
248
|
+
/** What every adapter of a delivery port must do, whatever its provider; `more` adds the port's own. */
|
|
249
|
+
const deliveryContract = (kind, cases, more = () => void 0) => describe.each(cases.map((entry) => [entry.adapter.name, entry]))(`%s, as ${kind}`, (_name, { adapter, settings }) => {
|
|
250
|
+
const port = adapter.create({
|
|
251
|
+
root: "/repo",
|
|
252
|
+
shell: new RecordingShell()
|
|
253
|
+
});
|
|
254
|
+
const unit = testUnit("app", {
|
|
255
|
+
module: "app",
|
|
256
|
+
options: settings
|
|
257
|
+
});
|
|
258
|
+
const inputFor = (environment) => ({
|
|
259
|
+
unit,
|
|
260
|
+
tag: "app@0.1.0",
|
|
261
|
+
environment,
|
|
262
|
+
options: optionsFor({
|
|
263
|
+
...unit,
|
|
264
|
+
options: adapter.settings.parse(settings)
|
|
265
|
+
}, environment, [unit]),
|
|
266
|
+
commit: "abc1234"
|
|
267
|
+
});
|
|
268
|
+
it("given an app's settings, when its unit file is read, then the adapter's schema takes them", () => {
|
|
269
|
+
expect(adapter.settings.safeParse(settings).success).toBe(true);
|
|
270
|
+
});
|
|
271
|
+
it("given a tag on each environment, when it says where the tag lands, then a person can read it", () => {
|
|
272
|
+
ENVIRONMENTS.forEach((environment) => expect(port.describe(inputFor(environment)).trim()).not.toBe(""));
|
|
273
|
+
});
|
|
274
|
+
it("given a tag on each environment, when its jobs are built, then each says what it does and what it runs", () => {
|
|
275
|
+
ENVIRONMENTS.forEach((environment) => port.jobs(inputFor(environment)).forEach((job) => {
|
|
276
|
+
expect(job.label.trim()).not.toBe("");
|
|
277
|
+
expect(job.local.length).toBeGreaterThan(0);
|
|
278
|
+
job.local.forEach(({ command }) => expect(command.trim()).not.toBe(""));
|
|
279
|
+
}));
|
|
280
|
+
});
|
|
281
|
+
it("given a folder with nothing in it, when init looks at it, then the adapter recognises nothing", () => {
|
|
282
|
+
expect(adapter.detect?.(EMPTY_FOLDER) ?? null).toBeNull();
|
|
283
|
+
});
|
|
284
|
+
it("given an app it ships, when doctor asks what it needs, then each need has a name and a check", () => {
|
|
285
|
+
(adapter.requirements?.(unit) ?? []).forEach(({ label, check }) => {
|
|
286
|
+
expect(label.trim()).not.toBe("");
|
|
287
|
+
expect(check.command.trim()).not.toBe("");
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
more(adapter, port);
|
|
291
|
+
});
|
|
292
|
+
//#endregion
|
|
293
|
+
//#region src/adapters/server-hosting/server-hosting.contract.ts
|
|
294
|
+
/** What every server host does, whatever its provider. */
|
|
295
|
+
const serverHostingContract = (cases) => deliveryContract("server hosting", cases, (_adapter, port) => {
|
|
296
|
+
it("given a server host, when its kind is read, then it hosts servers", () => {
|
|
297
|
+
expect(port.capability).toBe("server-hosting");
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
//#endregion
|
|
301
|
+
//#region src/adapters/static-hosting/static-hosting.contract.ts
|
|
302
|
+
/** What every static host does, whatever its provider. */
|
|
303
|
+
const staticHostingContract = (cases) => deliveryContract("static hosting", cases, (_adapter, port) => {
|
|
304
|
+
it("given a static host, when its kind is read, then it hosts static sites", () => {
|
|
305
|
+
expect(port.capability).toBe("static-hosting");
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
//#endregion
|
|
309
|
+
//#region src/adapters/mobile-distribution/mobile-distribution.contract.ts
|
|
310
|
+
/** What every mobile distribution does, whatever its provider. */
|
|
311
|
+
const mobileDistributionContract = (cases) => deliveryContract("mobile distribution", cases, (adapter, port) => {
|
|
312
|
+
it("given a mobile distribution, when status asks who decides, then its platform is named", () => {
|
|
313
|
+
expect(port.capability).toBe("mobile-distribution");
|
|
314
|
+
expect(adapter.decidedBy?.platform.trim() ?? "").not.toBe("");
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
//#endregion
|
|
318
|
+
//#region src/adapters/package-registry/package-registry.contract.ts
|
|
319
|
+
/** What every package registry does, whatever its provider. */
|
|
320
|
+
const packageRegistryContract = (cases) => deliveryContract("a package registry", cases, (_adapter, port) => {
|
|
321
|
+
it("given a package registry, when its kind is read, then it publishes packages", () => {
|
|
322
|
+
expect(port.capability).toBe("package-registry");
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
//#endregion
|
|
326
|
+
//#region src/adapters/source-control/source-control.contract.ts
|
|
327
|
+
/** What every source control does, whatever its provider. */
|
|
328
|
+
const sourceControlContract = (name, subject) => describe(`${name}, as source control`, () => {
|
|
329
|
+
it("given a fresh checkout, when its position is read, then it is on main with nothing to commit", async () => {
|
|
330
|
+
const { port } = await subject();
|
|
331
|
+
expect((await port.position()).branch).toBe("main");
|
|
332
|
+
expect(await port.isClean()).toBe(true);
|
|
333
|
+
});
|
|
334
|
+
it("given a commit tagged, when the tags are read, then the tag is there and names that commit", async () => {
|
|
335
|
+
const { port, head } = await subject();
|
|
336
|
+
const sha = await head();
|
|
337
|
+
await port.tag("app@1.0.0", sha, "app 1.0.0");
|
|
338
|
+
expect(await port.tags()).toContain("app@1.0.0");
|
|
339
|
+
expect(await port.tagCommit("app@1.0.0")).toBe(sha);
|
|
340
|
+
});
|
|
341
|
+
it("given tags in every format a config names, when the tags are read, then each one is there", async () => {
|
|
342
|
+
const { port, head } = await subject();
|
|
343
|
+
const sha = await head();
|
|
344
|
+
for (const tag of [
|
|
345
|
+
"arnaud-zg--v0.2.1",
|
|
346
|
+
"v1.0.0",
|
|
347
|
+
"app@1.0.0"
|
|
348
|
+
]) await port.tag(tag, sha, tag);
|
|
349
|
+
expect([...await port.tags()].sort()).toEqual([
|
|
350
|
+
"app@1.0.0",
|
|
351
|
+
"arnaud-zg--v0.2.1",
|
|
352
|
+
"v1.0.0"
|
|
353
|
+
]);
|
|
354
|
+
});
|
|
355
|
+
it("given a tag deleted, when the tags are read, then it is gone and names no commit", async () => {
|
|
356
|
+
const { port, head } = await subject();
|
|
357
|
+
await port.tag("app@1.0.0", await head(), "app 1.0.0");
|
|
358
|
+
await port.deleteTag("app@1.0.0");
|
|
359
|
+
expect(await port.tags()).not.toContain("app@1.0.0");
|
|
360
|
+
expect(await port.tagCommit("app@1.0.0")).toBeNull();
|
|
361
|
+
});
|
|
362
|
+
it("given a branch created, when the position is read, then it is on it, and switching back returns to main", async () => {
|
|
363
|
+
const { port } = await subject();
|
|
364
|
+
await port.createBranch("release/next");
|
|
365
|
+
const onBranch = (await port.position()).branch;
|
|
366
|
+
await port.switchTo("main");
|
|
367
|
+
expect(onBranch).toBe("release/next");
|
|
368
|
+
expect((await port.position()).branch).toBe("main");
|
|
369
|
+
});
|
|
370
|
+
it("given a new file committed, when the changes are read, then it is no longer among them", async () => {
|
|
371
|
+
const { port, change } = await subject();
|
|
372
|
+
await change("notes.md", "notes\n");
|
|
373
|
+
const before = await port.changedFiles();
|
|
374
|
+
await port.commit(["notes.md"], "docs: notes");
|
|
375
|
+
expect(before).toContain("notes.md");
|
|
376
|
+
expect(await port.changedFiles()).not.toContain("notes.md");
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
//#endregion
|
|
380
|
+
//#region src/adapters/code-host/code-host.contract.ts
|
|
381
|
+
/** What every code host does, whatever its provider. */
|
|
382
|
+
const codeHostContract = (name, subject) => describe(`${name}, as a code host`, () => {
|
|
383
|
+
it("given a pull request opened, when the open ones are read, then it is there and open", async () => {
|
|
384
|
+
const { port, branch } = await subject();
|
|
385
|
+
const head = await branch("release/contract-open");
|
|
386
|
+
const pr = await port.createPr({
|
|
387
|
+
base: "main",
|
|
388
|
+
head,
|
|
389
|
+
title: "chore: contract",
|
|
390
|
+
body: "Opened by the contract suite.",
|
|
391
|
+
label: "release"
|
|
392
|
+
});
|
|
393
|
+
expect(pr.head).toEqual(expect.any(String));
|
|
394
|
+
expect(await port.openPrsFrom("release/contract-open")).toContainEqual(pr);
|
|
395
|
+
expect(await port.prState(pr)).toBe("OPEN");
|
|
396
|
+
});
|
|
397
|
+
it("given a pull request closed, when the open ones are read, then it is gone and closed", async () => {
|
|
398
|
+
const { port, branch } = await subject();
|
|
399
|
+
const head = await branch("release/contract-close");
|
|
400
|
+
const pr = await port.createPr({
|
|
401
|
+
base: "main",
|
|
402
|
+
head,
|
|
403
|
+
title: "chore: contract",
|
|
404
|
+
body: "Opened by the contract suite.",
|
|
405
|
+
label: "release"
|
|
406
|
+
});
|
|
407
|
+
await port.closePr(pr, "Closed by the contract suite.");
|
|
408
|
+
expect(await port.openPrsFrom("release/contract-close")).not.toContainEqual(pr);
|
|
409
|
+
expect(await port.prState(pr)).toBe("CLOSED");
|
|
410
|
+
});
|
|
411
|
+
it("given release notes published for a tag, when the released tags are read, then it is among them", async () => {
|
|
412
|
+
const { port, tag } = await subject();
|
|
413
|
+
const name = await tag();
|
|
414
|
+
await port.createRelease(name, "Published by the contract suite.", false);
|
|
415
|
+
expect(await port.releasedTags()).toContain(name);
|
|
416
|
+
});
|
|
417
|
+
it("given a deploy recorded, when the deploys are read, then it is there and done", async () => {
|
|
418
|
+
const { port, tag } = await subject();
|
|
419
|
+
const name = await tag();
|
|
420
|
+
await port.recordDeployment(name, "preview");
|
|
421
|
+
expect(await port.deployments()).toContainEqual({
|
|
422
|
+
title: `Deploy ${name} to preview`,
|
|
423
|
+
state: "done"
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
it("given a comment posted, when the comments are read, then it is among them", async () => {
|
|
427
|
+
const { port, issue } = await subject();
|
|
428
|
+
const body = `Posted by the contract suite at ${(/* @__PURE__ */ new Date()).toISOString()}.`;
|
|
429
|
+
await port.comment(issue, body);
|
|
430
|
+
expect((await port.comments([issue])).flat()).toContain(body);
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
//#endregion
|
|
434
|
+
//#region src/adapters/ci-pipeline/ci-pipeline.contract.ts
|
|
435
|
+
/** What every CI pipeline does, whatever its provider. */
|
|
436
|
+
const ciPipelineContract = (name, subject) => describe(`${name}, as a CI pipeline`, () => {
|
|
437
|
+
it("given a workflow that never ran, when its runs are read, then there are none", async () => {
|
|
438
|
+
const { port, idle } = await subject();
|
|
439
|
+
expect(await port.workflowRuns(idle)).toEqual([]);
|
|
440
|
+
});
|
|
441
|
+
it("given a workflow that never succeeded, when its billed minutes are read, then none are measured", async () => {
|
|
442
|
+
const { port, idle } = await subject();
|
|
443
|
+
expect(await port.measuredMinutes(idle)).toEqual([]);
|
|
444
|
+
});
|
|
445
|
+
it("given this month's budget, when it is read, then what is left is never more than included", async () => {
|
|
446
|
+
const { port } = await subject();
|
|
447
|
+
const minutes = await port.minutes();
|
|
448
|
+
if (minutes) expect(minutes.left).toBeLessThanOrEqual(minutes.included);
|
|
449
|
+
else expect(minutes).toBeNull();
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
|
+
//#endregion
|
|
453
|
+
//#region src/adapters/versioning/versioning.contract.ts
|
|
454
|
+
/** What every versioning does, whatever its provider. */
|
|
455
|
+
const versioningContract = (name, subject) => describe(`${name}, as versioning`, () => {
|
|
456
|
+
it("given a change written, when the pending changes are read, then it is there naming its package and bump", async () => {
|
|
457
|
+
const { port, workspace } = await subject();
|
|
458
|
+
await port.write({
|
|
459
|
+
id: "contract-change",
|
|
460
|
+
releases: [{
|
|
461
|
+
name: workspace.name,
|
|
462
|
+
type: "minor"
|
|
463
|
+
}],
|
|
464
|
+
summary: "Written by the contract suite."
|
|
465
|
+
});
|
|
466
|
+
const pending = await port.pending();
|
|
467
|
+
expect(pending.map(({ id }) => id)).toContain("contract-change");
|
|
468
|
+
expect(pending.find(({ id }) => id === "contract-change")?.text).toContain(`"${workspace.name}": minor`);
|
|
469
|
+
});
|
|
470
|
+
it("given a workspace package, when the folders are read, then it is found in its folder", async () => {
|
|
471
|
+
const { port, workspace } = await subject();
|
|
472
|
+
expect(await port.folders()).toMatchObject({ [workspace.name]: workspace.folder });
|
|
473
|
+
});
|
|
474
|
+
it("given a change and a folder, when their files are named, then they sit where a person looks", async () => {
|
|
475
|
+
const { port, workspace } = await subject();
|
|
476
|
+
expect(port.changesetFile("contract-change")).toBe(".changeset/contract-change.md");
|
|
477
|
+
expect(port.changelogFile(workspace.folder)).toBe(`${workspace.folder}/CHANGELOG.md`);
|
|
478
|
+
});
|
|
479
|
+
});
|
|
480
|
+
//#endregion
|
|
481
|
+
//#region src/testing/sample.ts
|
|
482
|
+
/** This repository's four shipping units, as the rule tests were written against them. */
|
|
483
|
+
const SAMPLE_UNITS = [
|
|
484
|
+
"expo",
|
|
485
|
+
"api",
|
|
486
|
+
"admin",
|
|
487
|
+
"landing"
|
|
488
|
+
].map((name) => ({
|
|
489
|
+
name,
|
|
490
|
+
packageName: `@acme/${name}`
|
|
491
|
+
}));
|
|
492
|
+
const SAMPLE_VERSION_FILES = new Set([
|
|
493
|
+
"apps/expo/app-version.json",
|
|
494
|
+
"apps/api/public/app-version.preview.json",
|
|
495
|
+
"apps/api/public/app-version.production.json"
|
|
496
|
+
]);
|
|
497
|
+
//#endregion
|
|
498
|
+
//#region src/testing/live.ts
|
|
499
|
+
/**
|
|
500
|
+
* Contract suites against hosted services run only with RELEASE_CONTRACT_LIVE=1, on a sandbox
|
|
501
|
+
* repository checked out at RELEASE_CONTRACT_REPO: they open pull requests, publish releases and
|
|
502
|
+
* dispatch workflows there.
|
|
503
|
+
*/
|
|
504
|
+
const LIVE = systemShell.env("RELEASE_CONTRACT_LIVE") === "1";
|
|
505
|
+
/** The sandbox checkout, refused when unset so a live run never touches this repository. */
|
|
506
|
+
const sandbox = () => z.string({ message: "RELEASE_CONTRACT_REPO names a sandbox checkout for live contracts" }).min(1).parse(systemShell.env("RELEASE_CONTRACT_REPO"));
|
|
507
|
+
/** Runs git in the sandbox and returns what it printed. */
|
|
508
|
+
const inSandbox = (args) => execFileSync("git", args, {
|
|
509
|
+
cwd: sandbox(),
|
|
510
|
+
encoding: "utf8"
|
|
511
|
+
}).trim();
|
|
512
|
+
//#endregion
|
|
513
|
+
//#region src/testing/plans.ts
|
|
514
|
+
const bump = (version, type) => {
|
|
515
|
+
const [major = 0, minor = 0] = version.split(".").map(Number);
|
|
516
|
+
if (type === "major") return `${major + 1}.0.0`;
|
|
517
|
+
if (type === "minor") return `${major}.${minor + 1}.0`;
|
|
518
|
+
return nextPatch(version);
|
|
519
|
+
};
|
|
520
|
+
/**
|
|
521
|
+
* What `changeset status` answers for these pending changesets, plus the ones a release adds, minus
|
|
522
|
+
* the lines it holds back: every named package moves once, by its biggest bump.
|
|
523
|
+
*/
|
|
524
|
+
const planFrom = (pending, versions) => (added, held) => {
|
|
525
|
+
const heldLines = new Set(held.flatMap(({ id, releases }) => releases.map(({ name }) => `${id}:${name}`)));
|
|
526
|
+
const changesets = [...pending, ...added].map((changeset) => ({
|
|
527
|
+
...changeset,
|
|
528
|
+
releases: changeset.releases.filter(({ name }) => !heldLines.has(`${changeset.id}:${name}`))
|
|
529
|
+
})).filter(({ releases }) => releases.length > 0);
|
|
530
|
+
const order = [
|
|
531
|
+
"major",
|
|
532
|
+
"minor",
|
|
533
|
+
"patch"
|
|
534
|
+
];
|
|
535
|
+
return {
|
|
536
|
+
changesets,
|
|
537
|
+
releases: [...new Set(changesets.flatMap(({ releases }) => releases.map(({ name }) => name)))].map((name) => {
|
|
538
|
+
const lines = changesets.filter(({ releases }) => releases.some((line) => line.name === name));
|
|
539
|
+
const type = order.find((candidate) => lines.some(({ releases }) => releases.some((line) => line.name === name && line.type === candidate))) ?? "patch";
|
|
540
|
+
const oldVersion = versions[name] ?? "0.1.0";
|
|
541
|
+
return {
|
|
542
|
+
name,
|
|
543
|
+
type,
|
|
544
|
+
oldVersion,
|
|
545
|
+
newVersion: bump(oldVersion, type),
|
|
546
|
+
changesets: lines.map(({ id }) => id)
|
|
547
|
+
};
|
|
548
|
+
})
|
|
549
|
+
};
|
|
550
|
+
};
|
|
551
|
+
//#endregion
|
|
552
|
+
//#region src/testing/consumer.ts
|
|
553
|
+
const CORE = "shiplane";
|
|
554
|
+
const coreDir = (from) => {
|
|
555
|
+
const manifest = path.join(from, "package.json");
|
|
556
|
+
if (fs.existsSync(manifest)) {
|
|
557
|
+
const { name } = JSON.parse(fs.readFileSync(manifest, "utf8"));
|
|
558
|
+
if (name === CORE) return from;
|
|
559
|
+
}
|
|
560
|
+
const parent = path.dirname(from);
|
|
561
|
+
if (parent === from) throw new Error(`${CORE} not found above ${import.meta.dirname}`);
|
|
562
|
+
return coreDir(parent);
|
|
563
|
+
};
|
|
564
|
+
/** The built CLI, as `pnpm add shiplane` installs it. */
|
|
565
|
+
const builtCli = () => {
|
|
566
|
+
const cli = path.join(coreDir(import.meta.dirname), "dist", "cli.js");
|
|
567
|
+
if (!fs.existsSync(cli)) throw new Error(`shiplane is not built: run pnpm turbo run build --filter=${CORE}`);
|
|
568
|
+
return cli;
|
|
569
|
+
};
|
|
570
|
+
const LEAKS = new Set([
|
|
571
|
+
"GITHUB_ACTIONS",
|
|
572
|
+
"CI",
|
|
573
|
+
"GITHUB_TOKEN",
|
|
574
|
+
"GH_TOKEN"
|
|
575
|
+
]);
|
|
576
|
+
const hermeticEnv = (home, bin) => ({
|
|
577
|
+
...Object.fromEntries(Object.entries(process.env).filter(([name]) => !LEAKS.has(name))),
|
|
578
|
+
PATH: [bin, systemShell.env("PATH") ?? ""].join(path.delimiter),
|
|
579
|
+
HOME: home,
|
|
580
|
+
GIT_CONFIG_GLOBAL: path.join(home, ".gitconfig"),
|
|
581
|
+
GIT_CONFIG_NOSYSTEM: "1",
|
|
582
|
+
NO_COLOR: "1",
|
|
583
|
+
GIT_AUTHOR_DATE: "2026-01-01T00:00:00Z",
|
|
584
|
+
GIT_COMMITTER_DATE: "2026-01-01T00:00:00Z"
|
|
585
|
+
});
|
|
586
|
+
const OFFLINE = [
|
|
587
|
+
"gh",
|
|
588
|
+
"npm",
|
|
589
|
+
"flyctl"
|
|
590
|
+
];
|
|
591
|
+
const offlineTools = (bin) => {
|
|
592
|
+
fs.mkdirSync(bin);
|
|
593
|
+
OFFLINE.forEach((tool) => {
|
|
594
|
+
const file = path.join(bin, tool);
|
|
595
|
+
fs.writeFileSync(file, `#!/bin/sh\necho "${tool}: offline in this repository" >&2\nexit 1\n`);
|
|
596
|
+
fs.chmodSync(file, 493);
|
|
597
|
+
});
|
|
598
|
+
};
|
|
599
|
+
/**
|
|
600
|
+
* A repository as a consumer has it: its files, the packages it installed linked in its
|
|
601
|
+
* node_modules, one commit pushed to a local bare origin. gh, npm and flyctl answer offline.
|
|
602
|
+
*/
|
|
603
|
+
const consumerRepository = ({ files, packages = {}, branch = "main" }) => {
|
|
604
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "shiplane-consumer-"));
|
|
605
|
+
const root = path.join(dir, "checkout");
|
|
606
|
+
const origin = path.join(dir, "origin.git");
|
|
607
|
+
const home = path.join(dir, "home");
|
|
608
|
+
fs.mkdirSync(home);
|
|
609
|
+
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");
|
|
610
|
+
const bin = path.join(dir, "bin");
|
|
611
|
+
offlineTools(bin);
|
|
612
|
+
const env = hermeticEnv(home, bin);
|
|
613
|
+
const git = (args, where) => execFileSync("git", args, {
|
|
614
|
+
cwd: where ? origin : root,
|
|
615
|
+
env,
|
|
616
|
+
stdio: "pipe",
|
|
617
|
+
encoding: "utf8"
|
|
618
|
+
}).trim();
|
|
619
|
+
const write = (file, text) => {
|
|
620
|
+
const target = path.join(root, file);
|
|
621
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
622
|
+
fs.writeFileSync(target, text);
|
|
623
|
+
};
|
|
624
|
+
fs.mkdirSync(root);
|
|
625
|
+
execFileSync("git", [
|
|
626
|
+
"init",
|
|
627
|
+
"--quiet",
|
|
628
|
+
"--bare",
|
|
629
|
+
`--initial-branch=${branch}`,
|
|
630
|
+
origin
|
|
631
|
+
], { env });
|
|
632
|
+
git([
|
|
633
|
+
"init",
|
|
634
|
+
"--quiet",
|
|
635
|
+
`--initial-branch=${branch}`
|
|
636
|
+
]);
|
|
637
|
+
git([
|
|
638
|
+
"remote",
|
|
639
|
+
"add",
|
|
640
|
+
"origin",
|
|
641
|
+
origin
|
|
642
|
+
]);
|
|
643
|
+
write(".gitignore", "node_modules\n");
|
|
644
|
+
Object.entries(files).forEach(([file, text]) => write(file, text));
|
|
645
|
+
Object.entries({
|
|
646
|
+
[CORE]: coreDir(import.meta.dirname),
|
|
647
|
+
...packages
|
|
648
|
+
}).forEach(([name, from]) => {
|
|
649
|
+
const link = path.join(root, "node_modules", name);
|
|
650
|
+
fs.mkdirSync(path.dirname(link), { recursive: true });
|
|
651
|
+
fs.symlinkSync(from, link, "dir");
|
|
652
|
+
});
|
|
653
|
+
const commitAndPush = (title) => {
|
|
654
|
+
git(["add", "--all"]);
|
|
655
|
+
git([
|
|
656
|
+
"commit",
|
|
657
|
+
"--quiet",
|
|
658
|
+
"-m",
|
|
659
|
+
title
|
|
660
|
+
]);
|
|
661
|
+
git([
|
|
662
|
+
"push",
|
|
663
|
+
"--quiet",
|
|
664
|
+
"origin",
|
|
665
|
+
branch
|
|
666
|
+
]);
|
|
667
|
+
};
|
|
668
|
+
commitAndPush("chore: start");
|
|
669
|
+
const cli = builtCli();
|
|
670
|
+
return {
|
|
671
|
+
root,
|
|
672
|
+
origin,
|
|
673
|
+
write,
|
|
674
|
+
read: (file) => fs.readFileSync(path.join(root, file), "utf8"),
|
|
675
|
+
git,
|
|
676
|
+
commitAndPush,
|
|
677
|
+
shiplane: (args) => {
|
|
678
|
+
const run = spawnSync(process.execPath, [cli, ...args], {
|
|
679
|
+
cwd: root,
|
|
680
|
+
env,
|
|
681
|
+
encoding: "utf8",
|
|
682
|
+
stdio: [
|
|
683
|
+
"ignore",
|
|
684
|
+
"pipe",
|
|
685
|
+
"pipe"
|
|
686
|
+
]
|
|
687
|
+
});
|
|
688
|
+
return {
|
|
689
|
+
status: run.status ?? 1,
|
|
690
|
+
output: `${run.stdout}${run.stderr}`
|
|
691
|
+
};
|
|
692
|
+
},
|
|
693
|
+
remove: () => fs.rmSync(dir, {
|
|
694
|
+
recursive: true,
|
|
695
|
+
force: true
|
|
696
|
+
})
|
|
697
|
+
};
|
|
698
|
+
};
|
|
699
|
+
//#endregion
|
|
700
|
+
//#region src/testing/workspace.ts
|
|
701
|
+
/** The public API a test config imports, resolved to source since tests run before any build. */
|
|
702
|
+
const SOURCE_ALIASES = {
|
|
703
|
+
shiplane: path.resolve(import.meta.dirname, "../index.ts"),
|
|
704
|
+
"shiplane/plugin": path.resolve(import.meta.dirname, "../plugin.ts"),
|
|
705
|
+
"shiplane/testing": path.resolve(import.meta.dirname, "public.ts")
|
|
706
|
+
};
|
|
707
|
+
/** A throwaway repository on disk, one entry per file, removed by `remove()`. */
|
|
708
|
+
const createWorkspace = (files) => {
|
|
709
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "release-workspace-"));
|
|
710
|
+
const write = (file, text) => {
|
|
711
|
+
const target = path.join(root, file);
|
|
712
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
713
|
+
fs.writeFileSync(target, text);
|
|
714
|
+
};
|
|
715
|
+
Object.entries(files).forEach(([file, text]) => write(file, text));
|
|
716
|
+
return {
|
|
717
|
+
root,
|
|
718
|
+
write,
|
|
719
|
+
read: (file) => fs.readFileSync(path.join(root, file), "utf8"),
|
|
720
|
+
exists: (file) => fs.existsSync(path.join(root, file)),
|
|
721
|
+
remove: () => fs.rmSync(root, {
|
|
722
|
+
recursive: true,
|
|
723
|
+
force: true
|
|
724
|
+
})
|
|
725
|
+
};
|
|
726
|
+
};
|
|
727
|
+
const packageJson = (name, version = "1.0.0", extra = {}) => JSON.stringify({
|
|
728
|
+
name,
|
|
729
|
+
version,
|
|
730
|
+
...extra
|
|
731
|
+
}, null, 2);
|
|
732
|
+
//#endregion
|
|
733
|
+
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, setup, shipTo, sourceControlContract, sourceControlFake, staticHostingContract, staticHostingFake, systemShell, testContext, testUnit, versioningContract, versioningFake };
|
|
734
|
+
|
|
735
|
+
//# sourceMappingURL=testing.js.map
|