@air-jam/devtools 0.0.0-stage → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +52 -2
  3. package/dist/agent.d.ts +15 -0
  4. package/dist/agent.js +19 -0
  5. package/dist/agent.js.map +1 -0
  6. package/dist/chunk-5YAARMW5.js +36 -0
  7. package/dist/chunk-5YAARMW5.js.map +1 -0
  8. package/dist/chunk-6WQODT37.js +1019 -0
  9. package/dist/chunk-6WQODT37.js.map +1 -0
  10. package/dist/chunk-CKFT2ZJE.js +801 -0
  11. package/dist/chunk-CKFT2ZJE.js.map +1 -0
  12. package/dist/chunk-ER3Q2C4G.js +358 -0
  13. package/dist/chunk-ER3Q2C4G.js.map +1 -0
  14. package/dist/chunk-GUEZP773.js +851 -0
  15. package/dist/chunk-GUEZP773.js.map +1 -0
  16. package/dist/chunk-HIDNI56E.js +33 -0
  17. package/dist/chunk-HIDNI56E.js.map +1 -0
  18. package/dist/chunk-QKXS5D35.js +43 -0
  19. package/dist/chunk-QKXS5D35.js.map +1 -0
  20. package/dist/chunk-S4LSCEVE.js +261 -0
  21. package/dist/chunk-S4LSCEVE.js.map +1 -0
  22. package/dist/chunk-VKMJO6VN.js +360 -0
  23. package/dist/chunk-VKMJO6VN.js.map +1 -0
  24. package/dist/chunk-WFUR3MXY.js +67 -0
  25. package/dist/chunk-WFUR3MXY.js.map +1 -0
  26. package/dist/chunk-XEMR7KUE.js +361 -0
  27. package/dist/chunk-XEMR7KUE.js.map +1 -0
  28. package/dist/chunk-ZLPD7FY5.js +191 -0
  29. package/dist/chunk-ZLPD7FY5.js.map +1 -0
  30. package/dist/context.d.ts +13 -0
  31. package/dist/context.js +9 -0
  32. package/dist/context.js.map +1 -0
  33. package/dist/controller.d.ts +41 -0
  34. package/dist/controller.js +30 -0
  35. package/dist/controller.js.map +1 -0
  36. package/dist/dev.d.ts +15 -0
  37. package/dist/dev.js +20 -0
  38. package/dist/dev.js.map +1 -0
  39. package/dist/game-session-broker.d.ts +57 -0
  40. package/dist/game-session-broker.js +235 -0
  41. package/dist/game-session-broker.js.map +1 -0
  42. package/dist/game-session.d.ts +13 -0
  43. package/dist/game-session.js +24 -0
  44. package/dist/game-session.js.map +1 -0
  45. package/dist/games.d.ts +21 -0
  46. package/dist/games.js +14 -0
  47. package/dist/games.js.map +1 -0
  48. package/dist/harness/visual.d.ts +321 -0
  49. package/dist/harness/visual.js +41 -0
  50. package/dist/harness/visual.js.map +1 -0
  51. package/dist/logs.d.ts +9 -0
  52. package/dist/logs.js +58 -0
  53. package/dist/logs.js.map +1 -0
  54. package/dist/mcp-config.d.ts +63 -0
  55. package/dist/mcp-config.js +190 -0
  56. package/dist/mcp-config.js.map +1 -0
  57. package/dist/platform-auth.d.ts +112 -0
  58. package/dist/platform-auth.js +37 -0
  59. package/dist/platform-auth.js.map +1 -0
  60. package/dist/platform-game-media.d.ts +309 -0
  61. package/dist/platform-game-media.js +168 -0
  62. package/dist/platform-game-media.js.map +1 -0
  63. package/dist/platform-games.d.ts +65 -0
  64. package/dist/platform-games.js +251 -0
  65. package/dist/platform-games.js.map +1 -0
  66. package/dist/quality.d.ts +10 -0
  67. package/dist/quality.js +63 -0
  68. package/dist/quality.js.map +1 -0
  69. package/dist/release.d.ts +1094 -0
  70. package/dist/release.js +1347 -0
  71. package/dist/release.js.map +1 -0
  72. package/dist/tooling/agent-contract.d.ts +2 -0
  73. package/dist/tooling/agent-contract.js +193 -0
  74. package/dist/tooling/agent-contract.js.map +1 -0
  75. package/dist/tooling/hold-runtime-host.d.ts +2 -0
  76. package/dist/tooling/hold-runtime-host.js +229 -0
  77. package/dist/tooling/hold-runtime-host.js.map +1 -0
  78. package/dist/tooling/inspect-airjam-agent.d.ts +2 -0
  79. package/dist/tooling/inspect-airjam-agent.js +37 -0
  80. package/dist/tooling/inspect-airjam-agent.js.map +1 -0
  81. package/dist/tooling/list-visual-scenarios.d.ts +2 -0
  82. package/dist/tooling/list-visual-scenarios.js +62 -0
  83. package/dist/tooling/list-visual-scenarios.js.map +1 -0
  84. package/dist/tooling/managed-dev-supervisor.d.ts +2 -0
  85. package/dist/tooling/managed-dev-supervisor.js +51 -0
  86. package/dist/tooling/managed-dev-supervisor.js.map +1 -0
  87. package/dist/tooling/run-visual-capture.d.ts +2 -0
  88. package/dist/tooling/run-visual-capture.js +167 -0
  89. package/dist/tooling/run-visual-capture.js.map +1 -0
  90. package/dist/types-C6NrHt88.d.ts +775 -0
  91. package/dist/visual.d.ts +15 -0
  92. package/dist/visual.js +263 -0
  93. package/dist/visual.js.map +1 -0
  94. package/package.json +113 -3
  95. package/src/agent.ts +380 -0
  96. package/src/commands.ts +40 -0
  97. package/src/context.ts +229 -0
  98. package/src/controller.ts +1376 -0
  99. package/src/dev.ts +999 -0
  100. package/src/fs-utils.ts +93 -0
  101. package/src/game-action-observation.ts +96 -0
  102. package/src/game-session-broker.ts +301 -0
  103. package/src/game-session.ts +459 -0
  104. package/src/games.ts +266 -0
  105. package/src/harness/visual/prefab-contract.ts +29 -0
  106. package/src/harness/visual/prefab-runner.ts +178 -0
  107. package/src/harness/visual/runner.ts +546 -0
  108. package/src/harness/visual/scenario-contract.ts +9 -0
  109. package/src/harness/visual/scenario-helpers.ts +63 -0
  110. package/src/harness/visual/session.ts +369 -0
  111. package/src/harness/visual/types.ts +181 -0
  112. package/src/harness/visual.ts +7 -0
  113. package/src/helper-scripts.ts +49 -0
  114. package/src/logs.ts +67 -0
  115. package/src/mcp-config.ts +262 -0
  116. package/src/platform-auth.ts +455 -0
  117. package/src/platform-game-media.ts +209 -0
  118. package/src/platform-games.ts +315 -0
  119. package/src/quality.ts +82 -0
  120. package/src/release.ts +1697 -0
  121. package/src/runtime-owner-protocol.ts +130 -0
  122. package/src/tooling/agent-contract.ts +232 -0
  123. package/src/tooling/agent-declaration.ts +36 -0
  124. package/src/tooling/airjam-agent-inspection.ts +45 -0
  125. package/src/tooling/airjam-agent.ts +118 -0
  126. package/src/tooling/hold-runtime-host.ts +224 -0
  127. package/src/tooling/inspect-airjam-agent.ts +20 -0
  128. package/src/tooling/list-visual-scenarios.ts +64 -0
  129. package/src/tooling/managed-dev-supervisor.ts +71 -0
  130. package/src/tooling/run-visual-capture.ts +217 -0
  131. package/src/tooling/runtime-owner-actions.ts +42 -0
  132. package/src/tooling/visual-pack.ts +46 -0
  133. package/src/types.ts +951 -0
  134. package/src/visual.ts +304 -0
  135. package/src/workspace-contract.ts +32 -0
package/src/games.ts ADDED
@@ -0,0 +1,266 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { detectProjectContext } from "./context.js";
4
+ import {
5
+ listDirectories,
6
+ pathExists,
7
+ readJsonFile,
8
+ readPackageJson,
9
+ resolveCandidatePath,
10
+ } from "./fs-utils.js";
11
+ import type {
12
+ AirJamGameInspection,
13
+ AirJamGameSummary,
14
+ AirJamProjectContext,
15
+ AirJamQualityGate,
16
+ AirJamVisualCaptureInspection,
17
+ AirJamVisualCaptureSummary,
18
+ JsonObject,
19
+ } from "./types.js";
20
+
21
+ export type {
22
+ AirJamGameInspection,
23
+ AirJamGameSummary,
24
+ AirJamVisualCaptureInspection,
25
+ AirJamVisualCaptureSummary,
26
+ } from "./types.js";
27
+
28
+ const REPO_GAME_MANIFEST = "airjam-template.json";
29
+
30
+ const toStringOrNull = (value: unknown): string | null =>
31
+ typeof value === "string" ? value : null;
32
+
33
+ const toBooleanOrNull = (value: unknown): boolean | null =>
34
+ typeof value === "boolean" ? value : null;
35
+
36
+ const inferGameIdFromRoot = (
37
+ rootDir: string,
38
+ packageName: string | null,
39
+ ): string => packageName ?? path.basename(rootDir);
40
+
41
+ const getConfigPath = async (rootDir: string): Promise<string | null> =>
42
+ resolveCandidatePath(rootDir, [
43
+ "src/airjam.config.ts",
44
+ "src/airjam.config.tsx",
45
+ "src/airjam.config.js",
46
+ "src/airjam.config.mjs",
47
+ "airjam.config.ts",
48
+ "airjam.config.tsx",
49
+ "airjam.config.js",
50
+ "airjam.config.mjs",
51
+ ]);
52
+
53
+ const readRepoGameSummary = async (
54
+ rootDir: string,
55
+ ): Promise<AirJamGameSummary | null> => {
56
+ const manifestPath = path.join(rootDir, REPO_GAME_MANIFEST);
57
+ if (!(await pathExists(manifestPath))) {
58
+ return null;
59
+ }
60
+
61
+ const manifest = await readJsonFile<JsonObject>(manifestPath);
62
+ const packageJson = await readPackageJson(rootDir);
63
+ const packageName = packageJson?.value.name ?? null;
64
+ const configPath = await getConfigPath(rootDir);
65
+
66
+ return {
67
+ id:
68
+ toStringOrNull(manifest.id) ?? inferGameIdFromRoot(rootDir, packageName),
69
+ name:
70
+ toStringOrNull(manifest.name) ?? packageName ?? path.basename(rootDir),
71
+ rootDir,
72
+ packageName,
73
+ description: toStringOrNull(manifest.description),
74
+ category: toStringOrNull(manifest.category),
75
+ scaffold: toBooleanOrNull(manifest.scaffold),
76
+ manifestPath,
77
+ configPath,
78
+ };
79
+ };
80
+
81
+ const readStandaloneGameSummary = async (
82
+ context: AirJamProjectContext,
83
+ ): Promise<AirJamGameSummary> => {
84
+ const packageName = context.packageJson?.name ?? null;
85
+ const configPath = await getConfigPath(context.rootDir);
86
+
87
+ return {
88
+ id: inferGameIdFromRoot(context.rootDir, packageName),
89
+ name: packageName ?? path.basename(context.rootDir),
90
+ rootDir: context.rootDir,
91
+ packageName,
92
+ description: toStringOrNull(context.packageJson?.description),
93
+ category: null,
94
+ scaffold: null,
95
+ manifestPath: null,
96
+ configPath,
97
+ };
98
+ };
99
+
100
+ export const listGames = async ({
101
+ cwd = process.cwd(),
102
+ }: {
103
+ cwd?: string;
104
+ } = {}): Promise<AirJamGameSummary[]> => {
105
+ const context = await detectProjectContext({ cwd });
106
+
107
+ if (context.mode === "monorepo") {
108
+ const gameDirs = await listDirectories(path.join(context.rootDir, "games"));
109
+ const summaries = await Promise.all(gameDirs.map(readRepoGameSummary));
110
+ return summaries
111
+ .filter((game): game is AirJamGameSummary => Boolean(game))
112
+ .sort((left, right) => left.name.localeCompare(right.name));
113
+ }
114
+
115
+ if (context.mode === "standalone-game") {
116
+ return [await readStandaloneGameSummary(context)];
117
+ }
118
+
119
+ return [];
120
+ };
121
+
122
+ const inferControllerPath = (configSource: string): string | null => {
123
+ const match = /controllerPath:\s*["'`]([^"'`]+)["'`]/.exec(configSource);
124
+ return match?.[1] ?? null;
125
+ };
126
+
127
+ const inferQualityGates = (
128
+ scripts: Record<string, string>,
129
+ contextMode: AirJamProjectContext["mode"],
130
+ ): AirJamQualityGate[] => {
131
+ const gates: AirJamQualityGate[] = [];
132
+ if (scripts.typecheck) {
133
+ gates.push("typecheck");
134
+ }
135
+ if (scripts.lint) {
136
+ gates.push("lint");
137
+ }
138
+ if (scripts.test) {
139
+ gates.push("test");
140
+ }
141
+ if (scripts.build) {
142
+ gates.push("build");
143
+ }
144
+ if (scripts["format:check"]) {
145
+ gates.push("format-check");
146
+ }
147
+ if (contextMode === "monorepo") {
148
+ if (scripts["test:scaffold"]) {
149
+ gates.push("scaffold-smoke");
150
+ }
151
+ if (scripts["check:release"]) {
152
+ gates.push("release-check");
153
+ }
154
+ }
155
+ return gates;
156
+ };
157
+
158
+ export const inspectGame = async ({
159
+ cwd = process.cwd(),
160
+ gameId,
161
+ }: {
162
+ cwd?: string;
163
+ gameId?: string;
164
+ } = {}): Promise<AirJamGameInspection> => {
165
+ const context = await detectProjectContext({ cwd });
166
+ const games = await listGames({ cwd });
167
+ const game = gameId
168
+ ? games.find((candidate) => candidate.id === gameId)
169
+ : games[0];
170
+
171
+ if (!game) {
172
+ throw new Error(
173
+ gameId
174
+ ? `Unable to find Air Jam game "${gameId}".`
175
+ : "Unable to find an Air Jam game in this project.",
176
+ );
177
+ }
178
+
179
+ const packageJson = await readPackageJson(game.rootDir);
180
+ const scripts = packageJson?.value.scripts ?? {};
181
+ const configSource = game.configPath
182
+ ? await readFile(game.configPath, "utf8").catch(() => "")
183
+ : "";
184
+
185
+ return {
186
+ ...game,
187
+ packageJsonPath: packageJson?.path ?? null,
188
+ scripts,
189
+ metadataExportLikely: /\bgameMetadata\b/.test(configSource),
190
+ controllerPathLikely: inferControllerPath(configSource),
191
+ qualityGates: inferQualityGates(
192
+ context.mode === "monorepo"
193
+ ? (context.packageJson?.scripts ?? {})
194
+ : scripts,
195
+ context.mode,
196
+ ),
197
+ };
198
+ };
199
+
200
+ const resolveVisualArtifactRoot = async (
201
+ context: AirJamProjectContext,
202
+ ): Promise<string> => {
203
+ if (context.mode === "monorepo") {
204
+ return path.join(context.rootDir, ".airjam", "artifacts", "visual");
205
+ }
206
+
207
+ return path.join(context.rootDir, ".airjam", "artifacts", "visual");
208
+ };
209
+
210
+ export const readVisualCaptureSummary = async ({
211
+ cwd = process.cwd(),
212
+ gameId,
213
+ }: {
214
+ cwd?: string;
215
+ gameId?: string;
216
+ } = {}): Promise<AirJamVisualCaptureInspection> => {
217
+ const context = await detectProjectContext({ cwd });
218
+ const game = await inspectGame({ cwd, gameId });
219
+ const artifactRoot = await resolveVisualArtifactRoot(context);
220
+ const summaryPath = path.join(artifactRoot, game.id, "capture-summary.json");
221
+
222
+ if (!(await pathExists(summaryPath))) {
223
+ throw new Error(
224
+ `No visual capture summary found for "${game.id}" at ${summaryPath}.`,
225
+ );
226
+ }
227
+
228
+ return {
229
+ gameId: game.id,
230
+ summaryPath,
231
+ summary: await readJsonFile<AirJamVisualCaptureSummary>(summaryPath),
232
+ };
233
+ };
234
+
235
+ export const listVisualCaptureSummaries = async ({
236
+ cwd = process.cwd(),
237
+ }: {
238
+ cwd?: string;
239
+ } = {}): Promise<AirJamVisualCaptureInspection[]> => {
240
+ const context = await detectProjectContext({ cwd });
241
+ const artifactRoot = await resolveVisualArtifactRoot(context);
242
+ const gameDirs = await listDirectories(artifactRoot);
243
+
244
+ const captures = await Promise.all(
245
+ gameDirs.map(async (gameDir) => {
246
+ const summaryPath = path.join(gameDir, "capture-summary.json");
247
+ if (!(await pathExists(summaryPath))) {
248
+ return null;
249
+ }
250
+
251
+ const summary =
252
+ await readJsonFile<AirJamVisualCaptureSummary>(summaryPath);
253
+ return {
254
+ gameId: summary.gameId,
255
+ summaryPath,
256
+ summary,
257
+ } satisfies AirJamVisualCaptureInspection;
258
+ }),
259
+ );
260
+
261
+ return captures
262
+ .filter(
263
+ (capture): capture is AirJamVisualCaptureInspection => capture !== null,
264
+ )
265
+ .sort((left, right) => left.gameId.localeCompare(right.gameId));
266
+ };
@@ -0,0 +1,29 @@
1
+ import type { VisualHarnessMode, VisualViewport } from "./types.js";
2
+
3
+ export type PrefabCaptureVariants = Readonly<Record<string, string>>;
4
+
5
+ export type PrefabCaptureRequest = {
6
+ prefabId: string;
7
+ variants: PrefabCaptureVariants;
8
+ mode: VisualHarnessMode;
9
+ };
10
+
11
+ export type PrefabCaptureDefinition = {
12
+ id: string;
13
+ prefabId: string;
14
+ description?: string;
15
+ viewport?: VisualViewport;
16
+ waitForTestId?: string;
17
+ buildHostUrl: (hostUrl: string, request: PrefabCaptureRequest) => string;
18
+ };
19
+
20
+ export type PrefabCaptureHarness = {
21
+ gameId: string;
22
+ prefabs: readonly PrefabCaptureDefinition[];
23
+ };
24
+
25
+ export const definePrefabCaptureHarness = <
26
+ const THarness extends PrefabCaptureHarness,
27
+ >(
28
+ harness: THarness,
29
+ ): THarness => harness;
@@ -0,0 +1,178 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+ import { z } from "zod";
5
+ import type { PrefabCaptureDefinition } from "./prefab-contract.js";
6
+ import { launchHarnessBrowser } from "./session.js";
7
+ import type { VisualHarnessMode } from "./types.js";
8
+
9
+ const prefabHarnessSchema = z.object({
10
+ gameId: z.string(),
11
+ prefabs: z.array(
12
+ z.object({
13
+ id: z.string(),
14
+ prefabId: z.string(),
15
+ description: z.string().optional(),
16
+ viewport: z
17
+ .object({
18
+ width: z.number().int().positive(),
19
+ height: z.number().int().positive(),
20
+ })
21
+ .optional(),
22
+ waitForTestId: z.string().optional(),
23
+ buildHostUrl: z.custom<PrefabCaptureDefinition["buildHostUrl"]>(
24
+ (value) => typeof value === "function",
25
+ ),
26
+ }),
27
+ ),
28
+ });
29
+
30
+ const artifactSegment = (value: string): string => {
31
+ const segment = value.replace(/[^a-zA-Z0-9._-]+/g, "-");
32
+ if (!segment || segment === "." || segment === "..") {
33
+ throw new Error(`Invalid prefab artifact segment "${value}".`);
34
+ }
35
+ return segment;
36
+ };
37
+
38
+ export const loadPrefabCapture = async ({
39
+ gameId,
40
+ gameDirectory,
41
+ prefabId,
42
+ variantPairs = [],
43
+ mode = "standalone-dev",
44
+ secure = false,
45
+ }: {
46
+ gameId: string;
47
+ gameDirectory: string;
48
+ prefabId: string;
49
+ variantPairs?: string[];
50
+ mode?: VisualHarnessMode;
51
+ secure?: boolean;
52
+ }) => {
53
+ if (mode !== "standalone-dev" && mode !== "arcade-built") {
54
+ throw new Error(`Unsupported visual prefab capture mode "${mode}".`);
55
+ }
56
+ if (!gameId || gameId === "." || gameId === "..") {
57
+ throw new Error(`Invalid prefab capture game id "${gameId}".`);
58
+ }
59
+ const modulePath = ["prefabs.ts", "prefabs.mjs"]
60
+ .map((fileName) => path.join(gameDirectory, "visual", fileName))
61
+ .find((filePath) => fs.existsSync(filePath));
62
+ if (!modulePath) {
63
+ throw new Error(
64
+ `No prefab capture harness found in ${path.join(gameDirectory, "visual")}.`,
65
+ );
66
+ }
67
+ const loaded = await import(pathToFileURL(modulePath).href);
68
+ const parsed = prefabHarnessSchema.safeParse(loaded.prefabCaptureHarness);
69
+ if (!parsed.success || parsed.data.gameId !== gameId) {
70
+ throw new Error(
71
+ `Invalid prefab capture harness for "${gameId}" at ${modulePath}.`,
72
+ );
73
+ }
74
+ const harness = parsed.data;
75
+ const prefab = harness.prefabs.find(
76
+ (candidate) => candidate.id === prefabId || candidate.prefabId === prefabId,
77
+ );
78
+ if (!prefab) {
79
+ throw new Error(
80
+ `No prefab capture matched "${prefabId}" for "${gameId}". Available prefab captures: ${harness.prefabs.map((entry) => `${entry.id} -> ${entry.prefabId}`).join(", ")}`,
81
+ );
82
+ }
83
+ const variants = Object.fromEntries(
84
+ variantPairs.map((pair) => {
85
+ const separator = pair.indexOf("=");
86
+ const key = pair.slice(0, separator).trim();
87
+ const value = pair.slice(separator + 1).trim();
88
+ if (separator <= 0 || !key || !value) {
89
+ throw new Error(
90
+ `Invalid --variant value "${pair}". Expected key=value.`,
91
+ );
92
+ }
93
+ return [key, value];
94
+ }),
95
+ );
96
+ const suffix = Object.entries(variants)
97
+ .sort(([left], [right]) => left.localeCompare(right))
98
+ .map(([key, value]) => `${artifactSegment(key)}-${artifactSegment(value)}`)
99
+ .join("__");
100
+ const artifactId = [artifactSegment(prefab.id), suffix]
101
+ .filter(Boolean)
102
+ .join("__");
103
+ return { gameId, prefab, variants, artifactId, mode, secure };
104
+ };
105
+
106
+ export const capturePrefabAtRuntime = async ({
107
+ capture,
108
+ hostUrl,
109
+ artifactRoot,
110
+ }: {
111
+ capture: Awaited<ReturnType<typeof loadPrefabCapture>>;
112
+ hostUrl: string;
113
+ artifactRoot: string;
114
+ }) => {
115
+ const { gameId, prefab, variants, artifactId, mode, secure } = capture;
116
+ const artifactDirectory = path.join(
117
+ artifactRoot,
118
+ encodeURIComponent(gameId),
119
+ "prefabs",
120
+ artifactId,
121
+ );
122
+ fs.rmSync(artifactDirectory, { force: true, recursive: true });
123
+ fs.mkdirSync(artifactDirectory, { recursive: true });
124
+ const targetUrl = prefab.buildHostUrl(hostUrl, {
125
+ prefabId: prefab.prefabId,
126
+ variants,
127
+ mode,
128
+ });
129
+ const browser = await launchHarnessBrowser();
130
+ try {
131
+ const viewport = prefab.viewport ?? { width: 1024, height: 1024 };
132
+ const context = await browser.newContext({ viewport });
133
+ try {
134
+ const page = await context.newPage();
135
+ let pageError: Error | null = null;
136
+ page.on("pageerror", (error) => {
137
+ pageError ??= error;
138
+ });
139
+ await page.goto(targetUrl, { waitUntil: "domcontentloaded" });
140
+ const game =
141
+ mode === "arcade-built"
142
+ ? page.frameLocator('iframe[data-testid="arcade-host-game-frame"]')
143
+ : page;
144
+ if (prefab.waitForTestId) {
145
+ await game.getByTestId(prefab.waitForTestId).waitFor({
146
+ state: "visible",
147
+ timeout: 30_000,
148
+ });
149
+ }
150
+ await page.waitForTimeout(900);
151
+ if (pageError) throw pageError;
152
+ const screenshotPath = path.join(artifactDirectory, "prefab.png");
153
+ await page.screenshot({ path: screenshotPath, fullPage: true });
154
+ const metadata = {
155
+ gameId,
156
+ captureId: prefab.id,
157
+ prefabId: prefab.prefabId,
158
+ runtimeMode: mode,
159
+ secure,
160
+ capturedAt: new Date().toISOString(),
161
+ viewport,
162
+ variants,
163
+ url: targetUrl,
164
+ screenshot: {
165
+ fileName: "prefab.png",
166
+ relativePath: path.relative(artifactRoot, screenshotPath),
167
+ },
168
+ };
169
+ const metadataPath = path.join(artifactDirectory, "metadata.json");
170
+ fs.writeFileSync(metadataPath, `${JSON.stringify(metadata, null, 2)}\n`);
171
+ return { artifactDirectory, metadataPath, metadata };
172
+ } finally {
173
+ await context.close();
174
+ }
175
+ } finally {
176
+ await browser.close();
177
+ }
178
+ };