Open History to see the last commit
1import * as NodeServices from "@effect/platform-node/NodeServices";
2import { assert, describe, it } from "@effect/vitest";
3import { Effect, FileSystem, Path } from "effect";
4import { Command, CliError } from "effect/unstable/cli";
5
6import {
7 mergePlatformUpdateManifests,
8 mergeUpdateManifestsCommand,
9 parsePlatformUpdateManifest,
10 serializePlatformUpdateManifest,
11} from "./merge-update-manifests.ts";
12
13const runCli = Command.runWith(mergeUpdateManifestsCommand, { version: "0.0.0" });
14
15describe("merge-update-manifests", () => {
16 it("merges arm64 and x64 macOS update manifests into one multi-arch manifest", () => {
17 const arm64 = parsePlatformUpdateManifest(
18 "mac",
19 `version: 0.0.4
20files:
21 - url: T3-Code-0.0.4-arm64.zip
22 sha512: arm64zip
23 size: 125621344
24 - url: T3-Code-0.0.4-arm64.dmg
25 sha512: arm64dmg
26 size: 131754935
27path: T3-Code-0.0.4-arm64.zip
28sha512: arm64zip
29releaseDate: '2026-03-07T10:32:14.587Z'
30`,
31 "latest-mac.yml",
32 );
33
34 const x64 = parsePlatformUpdateManifest(
35 "mac",
36 `version: 0.0.4
37files:
38 - url: T3-Code-0.0.4-x64.zip
39 sha512: x64zip
40 size: 132000112
41 - url: T3-Code-0.0.4-x64.dmg
42 sha512: x64dmg
43 size: 138148807
44path: T3-Code-0.0.4-x64.zip
45sha512: x64zip
46releaseDate: '2026-03-07T10:36:07.540Z'
47`,
48 "latest-mac-x64.yml",
49 );
50
51 const merged = mergePlatformUpdateManifests("mac", arm64, x64);
52
53 assert.equal(merged.version, "0.0.4");
54 assert.equal(merged.releaseDate, "2026-03-07T10:36:07.540Z");
55 assert.deepStrictEqual(
56 merged.files.map((file) => file.url),
57 [
58 "T3-Code-0.0.4-arm64.zip",
59 "T3-Code-0.0.4-arm64.dmg",
60 "T3-Code-0.0.4-x64.zip",
61 "T3-Code-0.0.4-x64.dmg",
62 ],
63 );
64
65 const serialized = serializePlatformUpdateManifest("mac", merged);
66 assert.ok(!serialized.includes("path:"));
67 assert.equal((serialized.match(/- url:/g) ?? []).length, 4);
68 });
69
70 it("merges arm64 and x64 Windows update manifests into one multi-arch manifest", () => {
71 const arm64 = parsePlatformUpdateManifest(
72 "win",
73 `version: 0.0.4
74files:
75 - url: T3-Code-0.0.4-arm64.exe
76 sha512: arm64exe
77 size: 125621344
78 - url: T3-Code-0.0.4-arm64.exe.blockmap
79 sha512: arm64blockmap
80 size: 131754
81path: T3-Code-0.0.4-arm64.exe
82sha512: arm64exe
83releaseDate: '2026-03-07T10:32:14.587Z'
84`,
85 "latest-win-arm64.yml",
86 );
87
88 const x64 = parsePlatformUpdateManifest(
89 "win",
90 `version: 0.0.4
91files:
92 - url: T3-Code-0.0.4-x64.exe
93 sha512: x64exe
94 size: 132000112
95 - url: T3-Code-0.0.4-x64.exe.blockmap
96 sha512: x64blockmap
97 size: 138148
98path: T3-Code-0.0.4-x64.exe
99sha512: x64exe
100releaseDate: '2026-03-07T10:36:07.540Z'
101`,
102 "latest-win-x64.yml",
103 );
104
105 const merged = mergePlatformUpdateManifests("win", arm64, x64);
106
107 assert.equal(merged.version, "0.0.4");
108 assert.equal(merged.releaseDate, "2026-03-07T10:36:07.540Z");
109 assert.deepStrictEqual(
110 merged.files.map((file) => file.url),
111 [
112 "T3-Code-0.0.4-arm64.exe",
113 "T3-Code-0.0.4-arm64.exe.blockmap",
114 "T3-Code-0.0.4-x64.exe",
115 "T3-Code-0.0.4-x64.exe.blockmap",
116 ],
117 );
118
119 const serialized = serializePlatformUpdateManifest("win", merged);
120 assert.ok(!serialized.includes("path:"));
121 assert.equal((serialized.match(/- url:/g) ?? []).length, 4);
122 });
123
124 it("rejects mismatched manifest versions", () => {
125 const primary = parsePlatformUpdateManifest(
126 "win",
127 `version: 0.0.4
128files:
129 - url: T3-Code-0.0.4-arm64.exe
130 sha512: arm64exe
131 size: 1
132releaseDate: '2026-03-07T10:32:14.587Z'
133`,
134 "latest-win-arm64.yml",
135 );
136
137 const secondary = parsePlatformUpdateManifest(
138 "win",
139 `version: 0.0.5
140files:
141 - url: T3-Code-0.0.5-x64.exe
142 sha512: x64exe
143 size: 1
144releaseDate: '2026-03-07T10:36:07.540Z'
145`,
146 "latest-win-x64.yml",
147 );
148
149 assert.throws(
150 () => mergePlatformUpdateManifests("win", primary, secondary),
151 /different versions/,
152 );
153 });
154
155 it("preserves quoted scalars as strings", () => {
156 const manifest = parsePlatformUpdateManifest(
157 "mac",
158 `version: '1.0'
159files:
160 - url: T3-Code-1.0-x64.zip
161 sha512: zipsha
162 size: 1
163releaseName: 'true'
164minimumSystemVersion: '13.0'
165stagingPercentage: 50
166releaseDate: '2026-03-07T10:36:07.540Z'
167`,
168 "latest-mac.yml",
169 );
170
171 assert.equal(manifest.version, "1.0");
172 assert.equal(manifest.extras.releaseName, "true");
173 assert.equal(manifest.extras.minimumSystemVersion, "13.0");
174 assert.equal(manifest.extras.stagingPercentage, 50);
175 });
176
177 it("round-trips numeric-looking versions as strings", () => {
178 const original = parsePlatformUpdateManifest(
179 "win",
180 `version: '1.0'
181files:
182 - url: T3-Code-1.0-x64.exe
183 sha512: exesha
184 size: 1
185releaseDate: '2026-03-07T10:36:07.540Z'
186`,
187 "latest-win-x64.yml",
188 );
189
190 const serialized = serializePlatformUpdateManifest("win", original);
191 assert.ok(serialized.includes("version: '1.0'"));
192
193 const reparsed = parsePlatformUpdateManifest("win", serialized, "latest-win-x64.yml");
194 assert.equal(reparsed.version, "1.0");
195 });
196});
197
198it.layer(NodeServices.layer)("merge-update-manifests cli", (it) => {
199 const arm64MacManifest = `version: 0.0.4
200files:
201 - url: T3-Code-0.0.4-arm64.zip
202 sha512: arm64zip
203 size: 125621344
204 - url: T3-Code-0.0.4-arm64.dmg
205 sha512: arm64dmg
206 size: 131754935
207path: T3-Code-0.0.4-arm64.zip
208sha512: arm64zip
209releaseDate: '2026-03-07T10:32:14.587Z'
210`;
211
212 const x64MacManifest = `version: 0.0.4
213files:
214 - url: T3-Code-0.0.4-x64.zip
215 sha512: x64zip
216 size: 132000112
217 - url: T3-Code-0.0.4-x64.dmg
218 sha512: x64dmg
219 size: 138148807
220path: T3-Code-0.0.4-x64.zip
221sha512: x64zip
222releaseDate: '2026-03-07T10:36:07.540Z'
223`;
224
225 it.effect("writes the merged manifest back to the primary path by default", () =>
226 Effect.gen(function* () {
227 const fs = yield* FileSystem.FileSystem;
228 const path = yield* Path.Path;
229 const baseDir = yield* fs.makeTempDirectoryScoped({
230 prefix: "merge-update-manifests-cli-",
231 });
232 const primaryPath = path.join(baseDir, "latest-mac.yml");
233 const secondaryPath = path.join(baseDir, "latest-mac-x64.yml");
234
235 yield* fs.writeFileString(primaryPath, arm64MacManifest);
236 yield* fs.writeFileString(secondaryPath, x64MacManifest);
237
238 yield* runCli(["--platform", "mac", primaryPath, secondaryPath]);
239
240 const merged = yield* fs.readFileString(primaryPath);
241 assert.ok(merged.includes("T3-Code-0.0.4-arm64.zip"));
242 assert.ok(merged.includes("T3-Code-0.0.4-x64.zip"));
243 assert.ok(!merged.includes("path:"));
244 }),
245 );
246
247 it.effect("writes the merged manifest to an explicit output path", () =>
248 Effect.gen(function* () {
249 const fs = yield* FileSystem.FileSystem;
250 const path = yield* Path.Path;
251 const baseDir = yield* fs.makeTempDirectoryScoped({
252 prefix: "merge-update-manifests-cli-output-",
253 });
254 const primaryPath = path.join(baseDir, "latest-win-arm64.yml");
255 const secondaryPath = path.join(baseDir, "latest-win-x64.yml");
256 const outputPath = path.join(baseDir, "latest-win.yml");
257
258 yield* fs.writeFileString(
259 primaryPath,
260 `version: 0.0.4
261files:
262 - url: T3-Code-0.0.4-arm64.exe
263 sha512: arm64exe
264 size: 125621344
265releaseDate: '2026-03-07T10:32:14.587Z'
266`,
267 );
268 yield* fs.writeFileString(
269 secondaryPath,
270 `version: 0.0.4
271files:
272 - url: T3-Code-0.0.4-x64.exe
273 sha512: x64exe
274 size: 132000112
275releaseDate: '2026-03-07T10:36:07.540Z'
276`,
277 );
278
279 yield* runCli(["--platform", "win", primaryPath, secondaryPath, outputPath]);
280
281 const merged = yield* fs.readFileString(outputPath);
282 assert.ok(merged.includes("T3-Code-0.0.4-arm64.exe"));
283 assert.ok(merged.includes("T3-Code-0.0.4-x64.exe"));
284 }),
285 );
286
287 it.effect("rejects invalid platform values during cli parsing", () =>
288 Effect.gen(function* () {
289 const error = yield* runCli(["--platform", "linux", "a.yml", "b.yml"]).pipe(Effect.flip);
290
291 if (!CliError.isCliError(error)) {
292 assert.fail(`Expected CliError, got ${String(error)}`);
293 }
294
295 const platformError =
296 error._tag === "ShowHelp" ? (error.errors[0] as CliError.CliError | undefined) : error;
297
298 if (!platformError || platformError._tag !== "InvalidValue") {
299 assert.fail(`Expected InvalidValue, got ${String(platformError?._tag)}`);
300 }
301
302 assert.equal(platformError.option, "platform");
303 assert.equal(platformError.value, "linux");
304 }),
305 );
306});