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