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