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