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.storeAsset.directory,
220 device.storeAsset.width,
221 device.storeAsset.height,
222 ]),
223 [
224 ["iphone-6.9", "apple/iphone-6.9", 1320, 2868],
225 ["iphone-6.5", "apple/iphone-6.5", 1284, 2778],
226 ["ipad-13", "apple/ipad-13", 2064, 2752],
227 ["pixel", "google-play/phone", 1080, 1920],
228 ["android-tablet-7", "google-play/tablet-7", 1080, 1920],
229 ["android-tablet-10", "google-play/tablet-10", 1440, 2560],
230 ],
231 );
232});
233
234it("selects a reachable LAN IPv4 address", () => {
235 assert.equal(
236 selectLanIpv4Address([
237 { address: "127.0.0.1", family: "IPv4", internal: true },
238 { address: "fe80::1", family: "IPv6", internal: false },
239 { address: "169.254.2.4", family: "IPv4", internal: false },
240 { address: "192.168.1.80", family: "IPv4", internal: false },
241 ]),
242 "192.168.1.80",
243 );
244});
245
246it("maps capture scenes to the real application routes", () => {
247 assert.equal(showcaseSceneUrl("threads", "environment-1"), "t3code-dev://");
248 assert.equal(
249 showcaseSceneUrl("environments", "environment-1"),
250 "t3code-dev://settings/environments",
251 );
252 assert.equal(
253 showcaseSceneUrl("thread", "environment-1"),
254 "t3code-dev://threads/environment-1/remote-command-center",
255 );
256 assert.equal(
257 showcaseSceneUrl("terminal", "environment-1"),
258 "t3code-dev://threads/environment-1/remote-command-center/terminal?terminalId=term-1",
259 );
260 assert.equal(
261 showcaseSceneUrl("review", "environment-1"),
262 "t3code-dev://threads/environment-1/remote-command-center/review",
263 );
264});
265
266it("seeds a playful multi-environment project spectrum", () => {
267 assert.deepStrictEqual(
268 SHOWCASE_PROJECTS.map((project) => project.title),
269 ["T3 Code", "React", "Linux"],
270 );
271 assert.deepStrictEqual(
272 SHOWCASE_ENVIRONMENTS.map((environment) => environment.label),
273 ["Moonbase Terminal", "Suspense Station", "Kernel Cabin"],
274 );
275 assert.equal(SHOWCASE_THREADS.length, 6);
276 assert.equal(new Set(SHOWCASE_THREADS.map((thread) => thread.projectId)).size, 3);
277 assert.equal(
278 SHOWCASE_PROJECTS.every((project) => project.favicon.includes("<svg")),
279 true,
280 );
281});
282
283it("reads multiline JSON from the pairing CLI", () => {
284 assert.equal(
285 parsePairingCredentialOutput('server log\n{\n "credential": "PAIR-ME"\n}\n'),
286 "PAIR-ME",
287 );
288});
289
290it("encodes Android pairing URLs without shell-sensitive JSON quotes", () => {
291 const urls = ["http://10.0.2.2:65164/#token=ONE", "http://10.0.2.2:65198/#token=TWO"];
292 const encoded = encodeAndroidPairingUrls(urls);
293 assert.equal(encoded.startsWith("json-uri:"), true);
294 assert.deepStrictEqual(JSON.parse(decodeURIComponent(encoded.slice("json-uri:".length))), urls);
295 assert.equal(encoded.includes('"'), false);
296});