Open History to see the last commit
1// @effect-diagnostics nodeBuiltinImport:off - expectations mirror the host path joins the script under test performs.
2import * as NodePath from "node:path";
3import { assert, it } from "@effect/vitest";
4import { PNG } from "pngjs";
5
6import showcaseConfig, {
7 DEFAULT_SHOWCASE_THEME,
8 resolveShowcaseAndroidAbi,
9 SHOWCASE_THEMES,
10 type ShowcaseConfig,
11 type ShowcaseStoreAssetSpec,
12} from "./mobile-showcase.config.ts";
13import {
14 SHOWCASE_ENVIRONMENTS,
15 SHOWCASE_PROJECTS,
16 SHOWCASE_THREADS,
17} from "./mobile-showcase-environment.ts";
18import {
19 encodeAndroidPairingUrls,
20 normalizeStorePng,
21 parseShowcaseCliArgs,
22 parsePairingCredentialOutput,
23 planShowcaseCaptures,
24 readPngDimensions,
25 readPngMetadata,
26 resolveAndroidSdkRoot,
27 selectLanIpv4Address,
28 showcaseCaptureDirectory,
29 validateStoreAsset,
30 validateStoreAssetCount,
31} from "./mobile-showcase.ts";
32
33const appleSpec: ShowcaseStoreAssetSpec = {
34 store: "apple",
35 directory: "apple/iphone-test",
36 width: 1284,
37 height: 2778,
38 minimumUploadCount: 1,
39 maximumUploadCount: 10,
40};
41
42const googleSpec: ShowcaseStoreAssetSpec = {
43 store: "google-play",
44 directory: "google-play/phone",
45 width: 1080,
46 height: 1920,
47 minimumUploadCount: 2,
48 maximumUploadCount: 8,
49 maximumFileSizeBytes: 8 * 1024 * 1024,
50};
51
52const config: ShowcaseConfig = {
53 outputDirectory: "artifacts",
54 metroPort: 8199,
55 settleDelayMs: 1,
56 devices: [
57 {
58 id: "phone",
59 platform: "ios",
60 simulator: "iPhone Test",
61 appearance: "dark",
62 theme: "t3-code",
63 scenes: ["thread", "review"],
64 storeAsset: appleSpec,
65 },
66 {
67 id: "pixel",
68 platform: "android",
69 avd: "Pixel_Test",
70 appearance: "light",
71 theme: "t3-code",
72 scenes: ["thread", "terminal"],
73 storeAsset: googleSpec,
74 },
75 ],
76};
77
78it("parses repeatable capture filters", () => {
79 const options = parseShowcaseCliArgs([
80 "--platform",
81 "ios",
82 "--device",
83 "phone",
84 "--scene",
85 "review",
86 "--appearance",
87 "both",
88 "--skip-build",
89 ]);
90 assert.deepStrictEqual([...options.platforms], ["ios"]);
91 assert.deepStrictEqual([...options.deviceIds], ["phone"]);
92 assert.deepStrictEqual([...options.scenes], ["review"]);
93 assert.deepStrictEqual([...options.appearances], ["light", "dark"]);
94 assert.equal(options.skipBuild, true);
95});
96
97it("rejects unsupported system appearances", () => {
98 assert.throws(
99 () => parseShowcaseCliArgs(["--appearance", "sepia"]),
100 /Unsupported appearance 'sepia'/u,
101 );
102});
103
104it("parses repeatable and expanded theme filters", () => {
105 assert.deepStrictEqual(
106 [...parseShowcaseCliArgs(["--theme", "ocean", "--theme", "ember"]).themes],
107 ["ocean", "ember"],
108 );
109 assert.deepStrictEqual(
110 [...parseShowcaseCliArgs(["--theme", "all"]).themes],
111 [...SHOWCASE_THEMES],
112 );
113});
114
115it("rejects unsupported themes instead of capturing the default palette", () => {
116 assert.throws(() => parseShowcaseCliArgs(["--theme", "sunset"]), /Unsupported theme 'sunset'/u);
117});
118
119it("parses validation-only mode", () => {
120 assert.equal(parseShowcaseCliArgs(["--validate-only"]).validateOnly, true);
121});
122
123it("selects an explicit CI Android ABI without changing the local default", () => {
124 assert.equal(resolveShowcaseAndroidAbi(undefined), "arm64-v8a");
125 assert.equal(resolveShowcaseAndroidAbi("x86_64"), "x86_64");
126 assert.throws(() => resolveShowcaseAndroidAbi("mips"), /Unsupported T3_SHOWCASE_ANDROID_ABI/u);
127});
128
129it("uses platform-correct default Android SDK roots", () => {
130 assert.equal(
131 resolveAndroidSdkRoot({ HOME: "/Users/showcase" }, "darwin"),
132 "/Users/showcase/Library/Android/sdk",
133 );
134 assert.equal(
135 resolveAndroidSdkRoot({ HOME: "/home/showcase" }, "linux"),
136 "/home/showcase/Android/Sdk",
137 );
138 assert.equal(
139 resolveAndroidSdkRoot(
140 { HOME: "/home/showcase", ANDROID_SDK_ROOT: "/opt/android-sdk" },
141 "linux",
142 ),
143 "/opt/android-sdk",
144 );
145});
146
147it("plans only scenes supported by each selected device", () => {
148 const options = parseShowcaseCliArgs(["--platform", "all", "--scene", "terminal"]);
149 const captures = planShowcaseCaptures(config, options);
150 assert.deepStrictEqual(
151 captures.map((capture) => ({
152 id: capture.device.id,
153 appearance: capture.appearance,
154 scenes: capture.scenes,
155 })),
156 [{ id: "pixel", appearance: "light", scenes: ["terminal"] }],
157 );
158});
159
160it("expands both appearances into independent upload-ready directories", () => {
161 const options = parseShowcaseCliArgs(["--device", "phone", "--appearance", "both"]);
162 const captures = planShowcaseCaptures(config, options);
163
164 assert.deepStrictEqual(
165 captures.map((capture) => ({
166 appearance: capture.appearance,
167 directory: showcaseCaptureDirectory("/captures", capture),
168 })),
169 [
170 {
171 appearance: "light",
172 directory: NodePath.join("/captures", "apple", "iphone-test", "light", "t3-code"),
173 },
174 {
175 appearance: "dark",
176 directory: NodePath.join("/captures", "apple", "iphone-test", "dark", "t3-code"),
177 },
178 ],
179 );
180});
181
182it("expands themes into independent upload-ready directories per appearance", () => {
183 const options = parseShowcaseCliArgs([
184 "--device",
185 "phone",
186 "--appearance",
187 "both",
188 "--theme",
189 "ocean",
190 "--theme",
191 "ember",
192 ]);
193
194 assert.deepStrictEqual(
195 planShowcaseCaptures(config, options).map((capture) =>
196 showcaseCaptureDirectory("/captures", capture),
197 ),
198 [
199 NodePath.join("/captures", "apple", "iphone-test", "light", "ocean"),
200 NodePath.join("/captures", "apple", "iphone-test", "light", "ember"),
201 NodePath.join("/captures", "apple", "iphone-test", "dark", "ocean"),
202 NodePath.join("/captures", "apple", "iphone-test", "dark", "ember"),
203 ],
204 );
205});
206
207it("rejects unknown devices instead of silently capturing another target", () => {
208 const options = parseShowcaseCliArgs(["--device", "missing"]);
209 assert.throws(() => planShowcaseCaptures(config, options), /Unknown device 'missing'/u);
210});
211
212it("reads captured PNG dimensions from the IHDR header", () => {
213 const bytes = new Uint8Array(26);
214 bytes.set([137, 80, 78, 71, 13, 10, 26, 10]);
215 const view = new DataView(bytes.buffer);
216 view.setUint32(16, 1320);
217 view.setUint32(20, 2868);
218 view.setUint8(24, 8);
219 view.setUint8(25, 2);
220 assert.deepStrictEqual(readPngDimensions(bytes), { width: 1320, height: 2868 });
221 assert.deepStrictEqual(readPngMetadata(bytes), {
222 width: 1320,
223 height: 2868,
224 bitDepth: 8,
225 colorType: 2,
226 hasAlpha: false,
227 });
228});
229
230function rgbaPng(width: number, height: number): Buffer {
231 const png = new PNG({ width, height });
232 png.data.fill(255);
233 return PNG.sync.write(png);
234}
235
236it("converts simulator RGBA captures to upload-safe 24-bit RGB PNGs", () => {
237 const normalized = normalizeStorePng(rgbaPng(2, 3));
238 assert.deepStrictEqual(readPngMetadata(normalized), {
239 width: 2,
240 height: 3,
241 bitDepth: 8,
242 colorType: 2,
243 hasAlpha: false,
244 });
245});
246
247it("validates exact Apple and Google Play upload assets", () => {
248 const apple = normalizeStorePng(rgbaPng(appleSpec.width, appleSpec.height));
249 const google = normalizeStorePng(rgbaPng(googleSpec.width, googleSpec.height));
250 assert.equal(validateStoreAsset(appleSpec, apple).width, 1284);
251 assert.equal(validateStoreAsset(googleSpec, google).height, 1920);
252});
253
254it("rejects wrong dimensions and alpha-bearing PNGs", () => {
255 const wrongSize = normalizeStorePng(rgbaPng(1242, 2688));
256 assert.throws(() => validateStoreAsset(appleSpec, wrongSize), /requires 1284×2778/u);
257 assert.throws(() => validateStoreAsset(appleSpec, rgbaPng(1284, 2778)), /without alpha/u);
258});
259
260it("enforces store screenshot count limits", () => {
261 assert.doesNotThrow(() => validateStoreAssetCount(googleSpec, 5, true));
262 assert.throws(() => validateStoreAssetCount(googleSpec, 1, true), /requires at least 2/u);
263 assert.throws(() => validateStoreAssetCount(googleSpec, 9, false), /allows at most 8/u);
264});
265
266it("defaults every device to the app's own palette", () => {
267 assert.equal(DEFAULT_SHOWCASE_THEME, "t3-code");
268 assert.equal(
269 showcaseConfig.devices.every((device) => device.theme === DEFAULT_SHOWCASE_THEME),
270 true,
271 );
272});
273
274it("configures every default device with an exact upload-ready store target", () => {
275 assert.deepStrictEqual(
276 showcaseConfig.devices.map((device) => [
277 device.id,
278 device.platform === "ios" ? (device.orientation ?? "portrait") : null,
279 device.storeAsset.directory,
280 device.storeAsset.width,
281 device.storeAsset.height,
282 ]),
283 [
284 ["iphone-6.9", "portrait", "apple/iphone-6.9", 1320, 2868],
285 ["iphone-6.5", "portrait", "apple/iphone-6.5", 1284, 2778],
286 ["ipad-13", "landscape", "apple/ipad-13", 2752, 2064],
287 ["pixel", null, "google-play/phone", 1080, 1920],
288 ["android-tablet-7", null, "google-play/tablet-7", 1080, 1920],
289 ["android-tablet-10", null, "google-play/tablet-10", 1440, 2560],
290 ],
291 );
292});
293
294it("selects a reachable LAN IPv4 address", () => {
295 assert.equal(
296 selectLanIpv4Address([
297 { address: "127.0.0.1", family: "IPv4", internal: true },
298 { address: "fe80::1", family: "IPv6", internal: false },
299 { address: "169.254.2.4", family: "IPv4", internal: false },
300 { address: "192.168.1.80", family: "IPv4", internal: false },
301 ]),
302 "192.168.1.80",
303 );
304});
305
306it("seeds a playful multi-environment project spectrum", () => {
307 assert.deepStrictEqual(
308 SHOWCASE_PROJECTS.map((project) => project.title),
309 ["T3 Code", "React", "Linux"],
310 );
311 assert.deepStrictEqual(
312 SHOWCASE_ENVIRONMENTS.map((environment) => environment.label),
313 ["Moonbase Terminal", "Suspense Station", "Kernel Cabin"],
314 );
315 assert.equal(SHOWCASE_THREADS.length, 9);
316 assert.equal(new Set(SHOWCASE_THREADS.map((thread) => thread.projectId)).size, 3);
317 const snoozedThreads = SHOWCASE_THREADS.filter((thread) => "snoozeMinutes" in thread);
318 assert.equal(snoozedThreads.length, 2);
319 assert.deepStrictEqual(
320 snoozedThreads.map((thread) => thread.id),
321 ["hydration-haikus", "patient-penguins"],
322 );
323 assert.equal(new Set(snoozedThreads.map((thread) => thread.snoozeMinutes)).size, 2);
324 for (const thread of snoozedThreads) {
325 assert.equal(thread.response !== null, true, `${thread.title} is not completed`);
326 assert.equal("state" in thread, false, `${thread.title} is blocked or working`);
327 assert.equal("settled" in thread, false, `${thread.title} is settled`);
328 assert.equal(thread.snoozeMinutes > 60, true, `${thread.title} wakes too soon`);
329 }
330 const primaryThread = SHOWCASE_THREADS.find((thread) => thread.id === "remote-command-center");
331 assert.equal(primaryThread !== undefined && !("snoozeMinutes" in primaryThread), true);
332 for (const project of SHOWCASE_PROJECTS) {
333 const projectThreads = SHOWCASE_THREADS.filter((thread) => thread.projectId === project.id);
334 assert.equal(
335 projectThreads.some((thread) => "settled" in thread && thread.settled),
336 true,
337 `${project.title} has no settled thread`,
338 );
339 assert.equal(
340 projectThreads.some((thread) => !("settled" in thread && thread.settled)),
341 true,
342 `${project.title} has no active thread`,
343 );
344 }
345 assert.equal(
346 SHOWCASE_PROJECTS.every((project) => project.favicon.includes("<svg")),
347 true,
348 );
349});
350
351it("reads multiline JSON from the pairing CLI", () => {
352 assert.equal(
353 parsePairingCredentialOutput('server log\n{\n "credential": "PAIR-ME"\n}\n'),
354 "PAIR-ME",
355 );
356});
357
358it("encodes Android pairing URLs without shell-sensitive JSON quotes", () => {
359 const urls = ["http://10.0.2.2:65164/#token=ONE", "http://10.0.2.2:65198/#token=TWO"];
360 const encoded = encodeAndroidPairingUrls(urls);
361 assert.equal(encoded.startsWith("json-uri:"), true);
362 assert.deepStrictEqual(JSON.parse(decodeURIComponent(encoded.slice("json-uri:".length))), urls);
363 assert.equal(encoded.includes('"'), false);
364});