@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.
- package/LICENSE +21 -0
- package/README.md +52 -2
- package/dist/agent.d.ts +15 -0
- package/dist/agent.js +19 -0
- package/dist/agent.js.map +1 -0
- package/dist/chunk-5YAARMW5.js +36 -0
- package/dist/chunk-5YAARMW5.js.map +1 -0
- package/dist/chunk-6WQODT37.js +1019 -0
- package/dist/chunk-6WQODT37.js.map +1 -0
- package/dist/chunk-CKFT2ZJE.js +801 -0
- package/dist/chunk-CKFT2ZJE.js.map +1 -0
- package/dist/chunk-ER3Q2C4G.js +358 -0
- package/dist/chunk-ER3Q2C4G.js.map +1 -0
- package/dist/chunk-GUEZP773.js +851 -0
- package/dist/chunk-GUEZP773.js.map +1 -0
- package/dist/chunk-HIDNI56E.js +33 -0
- package/dist/chunk-HIDNI56E.js.map +1 -0
- package/dist/chunk-QKXS5D35.js +43 -0
- package/dist/chunk-QKXS5D35.js.map +1 -0
- package/dist/chunk-S4LSCEVE.js +261 -0
- package/dist/chunk-S4LSCEVE.js.map +1 -0
- package/dist/chunk-VKMJO6VN.js +360 -0
- package/dist/chunk-VKMJO6VN.js.map +1 -0
- package/dist/chunk-WFUR3MXY.js +67 -0
- package/dist/chunk-WFUR3MXY.js.map +1 -0
- package/dist/chunk-XEMR7KUE.js +361 -0
- package/dist/chunk-XEMR7KUE.js.map +1 -0
- package/dist/chunk-ZLPD7FY5.js +191 -0
- package/dist/chunk-ZLPD7FY5.js.map +1 -0
- package/dist/context.d.ts +13 -0
- package/dist/context.js +9 -0
- package/dist/context.js.map +1 -0
- package/dist/controller.d.ts +41 -0
- package/dist/controller.js +30 -0
- package/dist/controller.js.map +1 -0
- package/dist/dev.d.ts +15 -0
- package/dist/dev.js +20 -0
- package/dist/dev.js.map +1 -0
- package/dist/game-session-broker.d.ts +57 -0
- package/dist/game-session-broker.js +235 -0
- package/dist/game-session-broker.js.map +1 -0
- package/dist/game-session.d.ts +13 -0
- package/dist/game-session.js +24 -0
- package/dist/game-session.js.map +1 -0
- package/dist/games.d.ts +21 -0
- package/dist/games.js +14 -0
- package/dist/games.js.map +1 -0
- package/dist/harness/visual.d.ts +321 -0
- package/dist/harness/visual.js +41 -0
- package/dist/harness/visual.js.map +1 -0
- package/dist/logs.d.ts +9 -0
- package/dist/logs.js +58 -0
- package/dist/logs.js.map +1 -0
- package/dist/mcp-config.d.ts +63 -0
- package/dist/mcp-config.js +190 -0
- package/dist/mcp-config.js.map +1 -0
- package/dist/platform-auth.d.ts +112 -0
- package/dist/platform-auth.js +37 -0
- package/dist/platform-auth.js.map +1 -0
- package/dist/platform-game-media.d.ts +309 -0
- package/dist/platform-game-media.js +168 -0
- package/dist/platform-game-media.js.map +1 -0
- package/dist/platform-games.d.ts +65 -0
- package/dist/platform-games.js +251 -0
- package/dist/platform-games.js.map +1 -0
- package/dist/quality.d.ts +10 -0
- package/dist/quality.js +63 -0
- package/dist/quality.js.map +1 -0
- package/dist/release.d.ts +1094 -0
- package/dist/release.js +1347 -0
- package/dist/release.js.map +1 -0
- package/dist/tooling/agent-contract.d.ts +2 -0
- package/dist/tooling/agent-contract.js +193 -0
- package/dist/tooling/agent-contract.js.map +1 -0
- package/dist/tooling/hold-runtime-host.d.ts +2 -0
- package/dist/tooling/hold-runtime-host.js +229 -0
- package/dist/tooling/hold-runtime-host.js.map +1 -0
- package/dist/tooling/inspect-airjam-agent.d.ts +2 -0
- package/dist/tooling/inspect-airjam-agent.js +37 -0
- package/dist/tooling/inspect-airjam-agent.js.map +1 -0
- package/dist/tooling/list-visual-scenarios.d.ts +2 -0
- package/dist/tooling/list-visual-scenarios.js +62 -0
- package/dist/tooling/list-visual-scenarios.js.map +1 -0
- package/dist/tooling/managed-dev-supervisor.d.ts +2 -0
- package/dist/tooling/managed-dev-supervisor.js +51 -0
- package/dist/tooling/managed-dev-supervisor.js.map +1 -0
- package/dist/tooling/run-visual-capture.d.ts +2 -0
- package/dist/tooling/run-visual-capture.js +167 -0
- package/dist/tooling/run-visual-capture.js.map +1 -0
- package/dist/types-C6NrHt88.d.ts +775 -0
- package/dist/visual.d.ts +15 -0
- package/dist/visual.js +263 -0
- package/dist/visual.js.map +1 -0
- package/package.json +113 -3
- package/src/agent.ts +380 -0
- package/src/commands.ts +40 -0
- package/src/context.ts +229 -0
- package/src/controller.ts +1376 -0
- package/src/dev.ts +999 -0
- package/src/fs-utils.ts +93 -0
- package/src/game-action-observation.ts +96 -0
- package/src/game-session-broker.ts +301 -0
- package/src/game-session.ts +459 -0
- package/src/games.ts +266 -0
- package/src/harness/visual/prefab-contract.ts +29 -0
- package/src/harness/visual/prefab-runner.ts +178 -0
- package/src/harness/visual/runner.ts +546 -0
- package/src/harness/visual/scenario-contract.ts +9 -0
- package/src/harness/visual/scenario-helpers.ts +63 -0
- package/src/harness/visual/session.ts +369 -0
- package/src/harness/visual/types.ts +181 -0
- package/src/harness/visual.ts +7 -0
- package/src/helper-scripts.ts +49 -0
- package/src/logs.ts +67 -0
- package/src/mcp-config.ts +262 -0
- package/src/platform-auth.ts +455 -0
- package/src/platform-game-media.ts +209 -0
- package/src/platform-games.ts +315 -0
- package/src/quality.ts +82 -0
- package/src/release.ts +1697 -0
- package/src/runtime-owner-protocol.ts +130 -0
- package/src/tooling/agent-contract.ts +232 -0
- package/src/tooling/agent-declaration.ts +36 -0
- package/src/tooling/airjam-agent-inspection.ts +45 -0
- package/src/tooling/airjam-agent.ts +118 -0
- package/src/tooling/hold-runtime-host.ts +224 -0
- package/src/tooling/inspect-airjam-agent.ts +20 -0
- package/src/tooling/list-visual-scenarios.ts +64 -0
- package/src/tooling/managed-dev-supervisor.ts +71 -0
- package/src/tooling/run-visual-capture.ts +217 -0
- package/src/tooling/runtime-owner-actions.ts +42 -0
- package/src/tooling/visual-pack.ts +46 -0
- package/src/types.ts +951 -0
- package/src/visual.ts +304 -0
- package/src/workspace-contract.ts +32 -0
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import type { Browser, Page } from "playwright-core";
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_HOST_VIEWPORT,
|
|
6
|
+
dismissHarnessControllerFullscreenPrompt,
|
|
7
|
+
launchHarnessBrowser,
|
|
8
|
+
openVisualHarnessSession,
|
|
9
|
+
} from "./session.js";
|
|
10
|
+
import type {
|
|
11
|
+
AnyAirJamAgentContract,
|
|
12
|
+
InferVisualScenarioSnapshot,
|
|
13
|
+
VisualCaptureScenarioMetadata,
|
|
14
|
+
VisualCaptureSummary,
|
|
15
|
+
VisualHarnessMode,
|
|
16
|
+
VisualHarnessUrls,
|
|
17
|
+
VisualScenario,
|
|
18
|
+
VisualScenarioAgent,
|
|
19
|
+
VisualScenarioContext,
|
|
20
|
+
VisualScenarioPack,
|
|
21
|
+
VisualScreenshotRecord,
|
|
22
|
+
VisualViewport,
|
|
23
|
+
} from "./types.js";
|
|
24
|
+
|
|
25
|
+
const ensureDir = (dir: string): void => {
|
|
26
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const writeJson = (filePath: string, value: unknown): void => {
|
|
30
|
+
ensureDir(path.dirname(filePath));
|
|
31
|
+
fs.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const resetDir = (dir: string): void => {
|
|
35
|
+
fs.rmSync(dir, { force: true, recursive: true });
|
|
36
|
+
ensureDir(dir);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const appendFailureScreenshot = async ({
|
|
40
|
+
page,
|
|
41
|
+
surface,
|
|
42
|
+
scenarioDir,
|
|
43
|
+
screenshotRecords,
|
|
44
|
+
}: {
|
|
45
|
+
page: Page;
|
|
46
|
+
surface: "host" | "controller";
|
|
47
|
+
scenarioDir: string;
|
|
48
|
+
screenshotRecords: VisualScreenshotRecord[];
|
|
49
|
+
}): Promise<void> => {
|
|
50
|
+
const viewport = page.viewportSize() ?? DEFAULT_HOST_VIEWPORT;
|
|
51
|
+
const fileName = `${surface}-failure.png`;
|
|
52
|
+
const filePath = path.join(scenarioDir, fileName);
|
|
53
|
+
|
|
54
|
+
await page.screenshot({
|
|
55
|
+
path: filePath,
|
|
56
|
+
fullPage: true,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
screenshotRecords.push({
|
|
60
|
+
surface,
|
|
61
|
+
viewportName: "failure",
|
|
62
|
+
width: viewport.width,
|
|
63
|
+
height: viewport.height,
|
|
64
|
+
fileName,
|
|
65
|
+
filePath,
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const captureFailureScreenshots = async (
|
|
70
|
+
runContext: VisualScenarioContext<AnyAirJamAgentContract> | null,
|
|
71
|
+
): Promise<void> => {
|
|
72
|
+
if (!runContext) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
await Promise.allSettled([
|
|
77
|
+
appendFailureScreenshot({
|
|
78
|
+
page: runContext.host.page,
|
|
79
|
+
surface: "host",
|
|
80
|
+
scenarioDir: runContext.scenarioDir,
|
|
81
|
+
screenshotRecords: runContext.screenshotRecords,
|
|
82
|
+
}),
|
|
83
|
+
appendFailureScreenshot({
|
|
84
|
+
page: runContext.controller.page,
|
|
85
|
+
surface: "controller",
|
|
86
|
+
scenarioDir: runContext.scenarioDir,
|
|
87
|
+
screenshotRecords: runContext.screenshotRecords,
|
|
88
|
+
}),
|
|
89
|
+
]);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const createUnavailableAgentClient = <
|
|
93
|
+
TSnapshot extends Record<string, unknown>,
|
|
94
|
+
>(): VisualScenarioAgent<TSnapshot> => {
|
|
95
|
+
const unavailable = async (): Promise<never> => {
|
|
96
|
+
throw new Error(
|
|
97
|
+
"This visual scenario run does not have an agent session attached. Start visual capture through Air Jam devtools so scenarios can invoke canonical agent actions.",
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
listActions: async () => [],
|
|
103
|
+
read: unavailable,
|
|
104
|
+
waitFor: unavailable,
|
|
105
|
+
invoke: unavailable,
|
|
106
|
+
close: async () => {},
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const createLazyAgentClient = <TSnapshot extends Record<string, unknown>>({
|
|
111
|
+
createAgentSession,
|
|
112
|
+
}: {
|
|
113
|
+
createAgentSession?: () => Promise<VisualScenarioAgent<TSnapshot>>;
|
|
114
|
+
}): VisualScenarioAgent<TSnapshot> => {
|
|
115
|
+
let sessionPromise: Promise<VisualScenarioAgent<TSnapshot>> | null = null;
|
|
116
|
+
|
|
117
|
+
const getSession = async (): Promise<VisualScenarioAgent<TSnapshot>> => {
|
|
118
|
+
if (!createAgentSession) {
|
|
119
|
+
return createUnavailableAgentClient<TSnapshot>();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (!sessionPromise) {
|
|
123
|
+
sessionPromise = createAgentSession();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return sessionPromise;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
listActions: async () => (await getSession()).listActions(),
|
|
131
|
+
read: async () => (await getSession()).read(),
|
|
132
|
+
waitFor: async (predicate, description, timeout) =>
|
|
133
|
+
(await getSession()).waitFor(predicate, description, timeout),
|
|
134
|
+
invoke: async (actionId, payload, options) =>
|
|
135
|
+
(await getSession()).invoke(actionId, payload, options),
|
|
136
|
+
close: async () => {
|
|
137
|
+
if (!sessionPromise) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const session = await sessionPromise.catch(() => null);
|
|
142
|
+
await session?.close().catch(() => null);
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const createScenarioRunContext = async <TAgent extends AnyAirJamAgentContract>({
|
|
148
|
+
browser,
|
|
149
|
+
gameId,
|
|
150
|
+
scenario,
|
|
151
|
+
scenarioDir,
|
|
152
|
+
urls,
|
|
153
|
+
mode,
|
|
154
|
+
secure,
|
|
155
|
+
createAgentSession,
|
|
156
|
+
}: {
|
|
157
|
+
browser: Browser;
|
|
158
|
+
gameId: string;
|
|
159
|
+
scenario: VisualScenario<TAgent>;
|
|
160
|
+
scenarioDir: string;
|
|
161
|
+
urls: Omit<VisualHarnessUrls, "controllerJoinUrl">;
|
|
162
|
+
mode: VisualHarnessMode;
|
|
163
|
+
secure: boolean;
|
|
164
|
+
createAgentSession?: (options: {
|
|
165
|
+
gameId: string;
|
|
166
|
+
scenarioId: string;
|
|
167
|
+
urls: VisualHarnessUrls;
|
|
168
|
+
mode: VisualHarnessMode;
|
|
169
|
+
secure: boolean;
|
|
170
|
+
}) => Promise<VisualScenarioAgent<InferVisualScenarioSnapshot<TAgent>>>;
|
|
171
|
+
}): Promise<VisualScenarioContext<TAgent>> => {
|
|
172
|
+
const session = await openVisualHarnessSession({
|
|
173
|
+
browser,
|
|
174
|
+
urls,
|
|
175
|
+
mode,
|
|
176
|
+
});
|
|
177
|
+
const hostPage = session.host.page;
|
|
178
|
+
const controllerPage = session.controller.page;
|
|
179
|
+
|
|
180
|
+
const screenshotRecords: VisualScreenshotRecord[] = [];
|
|
181
|
+
const notes: string[] = [];
|
|
182
|
+
notes.push(`Resolved controller join URL: ${session.urls.controllerJoinUrl}`);
|
|
183
|
+
if (session.controller.fullscreenPromptDismissed) {
|
|
184
|
+
notes.push("Dismissed controller fullscreen prompt before capture.");
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const captureSurface = async ({
|
|
188
|
+
surface,
|
|
189
|
+
viewportName,
|
|
190
|
+
width,
|
|
191
|
+
height,
|
|
192
|
+
fullPage = true,
|
|
193
|
+
}: {
|
|
194
|
+
surface: "host" | "controller";
|
|
195
|
+
viewportName: string;
|
|
196
|
+
width: number;
|
|
197
|
+
height: number;
|
|
198
|
+
fullPage?: boolean;
|
|
199
|
+
}): Promise<void> => {
|
|
200
|
+
const targetPage = surface === "host" ? hostPage : controllerPage;
|
|
201
|
+
await targetPage.setViewportSize({ width, height });
|
|
202
|
+
await targetPage.waitForTimeout(300);
|
|
203
|
+
|
|
204
|
+
const fileName = `${surface}-${viewportName}.png`;
|
|
205
|
+
const filePath = path.join(scenarioDir, fileName);
|
|
206
|
+
await targetPage.screenshot({
|
|
207
|
+
path: filePath,
|
|
208
|
+
fullPage,
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
screenshotRecords.push({
|
|
212
|
+
surface,
|
|
213
|
+
viewportName,
|
|
214
|
+
width,
|
|
215
|
+
height,
|
|
216
|
+
fileName,
|
|
217
|
+
filePath,
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const agent = createLazyAgentClient<InferVisualScenarioSnapshot<TAgent>>({
|
|
222
|
+
createAgentSession: createAgentSession
|
|
223
|
+
? () =>
|
|
224
|
+
createAgentSession({
|
|
225
|
+
gameId,
|
|
226
|
+
scenarioId: scenario.id,
|
|
227
|
+
urls: session.urls,
|
|
228
|
+
mode,
|
|
229
|
+
secure,
|
|
230
|
+
})
|
|
231
|
+
: undefined,
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
return {
|
|
235
|
+
gameId,
|
|
236
|
+
scenario,
|
|
237
|
+
scenarioDir,
|
|
238
|
+
urls: session.urls,
|
|
239
|
+
host: session.host,
|
|
240
|
+
controller: session.controller,
|
|
241
|
+
note: (value: string) => {
|
|
242
|
+
notes.push(value);
|
|
243
|
+
},
|
|
244
|
+
sleep: (ms: number) => hostPage.waitForTimeout(ms),
|
|
245
|
+
ensureControllerInteractive: async () => {
|
|
246
|
+
await dismissHarnessControllerFullscreenPrompt(controllerPage);
|
|
247
|
+
},
|
|
248
|
+
agent,
|
|
249
|
+
captureHost: async (viewportName: string, viewport: VisualViewport) =>
|
|
250
|
+
captureSurface({ surface: "host", viewportName, ...viewport }),
|
|
251
|
+
captureController: async (viewportName: string, viewport: VisualViewport) =>
|
|
252
|
+
captureSurface({ surface: "controller", viewportName, ...viewport }),
|
|
253
|
+
screenshotRecords,
|
|
254
|
+
notes,
|
|
255
|
+
close: async () => {
|
|
256
|
+
await Promise.allSettled([agent.close(), session.close()]);
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
const buildScenarioMetadata = ({
|
|
262
|
+
artifactRoot,
|
|
263
|
+
gameId,
|
|
264
|
+
scenario,
|
|
265
|
+
mode,
|
|
266
|
+
urls,
|
|
267
|
+
screenshotRecords,
|
|
268
|
+
notes,
|
|
269
|
+
status,
|
|
270
|
+
error,
|
|
271
|
+
}: {
|
|
272
|
+
artifactRoot: string;
|
|
273
|
+
gameId: string;
|
|
274
|
+
scenario: VisualScenario<AnyAirJamAgentContract>;
|
|
275
|
+
mode: VisualHarnessMode;
|
|
276
|
+
urls: Omit<VisualHarnessUrls, "controllerJoinUrl"> | VisualHarnessUrls;
|
|
277
|
+
screenshotRecords: VisualScreenshotRecord[];
|
|
278
|
+
notes: string[];
|
|
279
|
+
status: "captured" | "failed";
|
|
280
|
+
error: unknown;
|
|
281
|
+
}): VisualCaptureScenarioMetadata => ({
|
|
282
|
+
gameId,
|
|
283
|
+
scenarioId: scenario.id,
|
|
284
|
+
scenarioDescription: scenario.description ?? null,
|
|
285
|
+
runtimeMode: mode,
|
|
286
|
+
capturedAt: new Date().toISOString(),
|
|
287
|
+
status,
|
|
288
|
+
urls,
|
|
289
|
+
screenshots: screenshotRecords.map((record) => ({
|
|
290
|
+
surface: record.surface,
|
|
291
|
+
viewportName: record.viewportName,
|
|
292
|
+
width: record.width,
|
|
293
|
+
height: record.height,
|
|
294
|
+
fileName: record.fileName,
|
|
295
|
+
relativePath: path.relative(artifactRoot, record.filePath),
|
|
296
|
+
})),
|
|
297
|
+
notes,
|
|
298
|
+
error:
|
|
299
|
+
error instanceof Error
|
|
300
|
+
? {
|
|
301
|
+
message: error.message,
|
|
302
|
+
stack: error.stack ?? null,
|
|
303
|
+
}
|
|
304
|
+
: null,
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
const runScenarioCapture = async <TAgent extends AnyAirJamAgentContract>({
|
|
308
|
+
artifactRoot,
|
|
309
|
+
browser,
|
|
310
|
+
gameId,
|
|
311
|
+
scenario,
|
|
312
|
+
urls,
|
|
313
|
+
mode,
|
|
314
|
+
secure,
|
|
315
|
+
createAgentSession,
|
|
316
|
+
}: {
|
|
317
|
+
artifactRoot: string;
|
|
318
|
+
browser: Browser;
|
|
319
|
+
gameId: string;
|
|
320
|
+
scenario: VisualScenario<TAgent>;
|
|
321
|
+
urls: Omit<VisualHarnessUrls, "controllerJoinUrl">;
|
|
322
|
+
mode: VisualHarnessMode;
|
|
323
|
+
secure: boolean;
|
|
324
|
+
createAgentSession?: (options: {
|
|
325
|
+
gameId: string;
|
|
326
|
+
scenarioId: string;
|
|
327
|
+
urls: VisualHarnessUrls;
|
|
328
|
+
mode: VisualHarnessMode;
|
|
329
|
+
secure: boolean;
|
|
330
|
+
}) => Promise<VisualScenarioAgent<InferVisualScenarioSnapshot<TAgent>>>;
|
|
331
|
+
}): Promise<VisualCaptureScenarioMetadata> => {
|
|
332
|
+
const scenarioDir = path.join(artifactRoot, gameId, scenario.id);
|
|
333
|
+
resetDir(scenarioDir);
|
|
334
|
+
|
|
335
|
+
let runContext: VisualScenarioContext<TAgent> | null = null;
|
|
336
|
+
let metadata: VisualCaptureScenarioMetadata | null = null;
|
|
337
|
+
let scenarioError: unknown = null;
|
|
338
|
+
|
|
339
|
+
try {
|
|
340
|
+
runContext = await createScenarioRunContext({
|
|
341
|
+
browser,
|
|
342
|
+
gameId,
|
|
343
|
+
scenario,
|
|
344
|
+
scenarioDir,
|
|
345
|
+
urls,
|
|
346
|
+
mode,
|
|
347
|
+
secure,
|
|
348
|
+
createAgentSession,
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
await scenario.run(runContext);
|
|
352
|
+
metadata = buildScenarioMetadata({
|
|
353
|
+
artifactRoot,
|
|
354
|
+
gameId,
|
|
355
|
+
scenario,
|
|
356
|
+
mode,
|
|
357
|
+
urls: runContext.urls,
|
|
358
|
+
screenshotRecords: runContext.screenshotRecords,
|
|
359
|
+
notes: runContext.notes,
|
|
360
|
+
status: "captured",
|
|
361
|
+
error: null,
|
|
362
|
+
});
|
|
363
|
+
} catch (error) {
|
|
364
|
+
scenarioError = error;
|
|
365
|
+
await captureFailureScreenshots(runContext);
|
|
366
|
+
runContext?.note(
|
|
367
|
+
"Scenario failed; best-effort failure screenshots were captured for the current host and controller state.",
|
|
368
|
+
);
|
|
369
|
+
metadata = buildScenarioMetadata({
|
|
370
|
+
artifactRoot,
|
|
371
|
+
gameId,
|
|
372
|
+
scenario,
|
|
373
|
+
mode,
|
|
374
|
+
urls: runContext?.urls ?? urls,
|
|
375
|
+
screenshotRecords: runContext?.screenshotRecords ?? [],
|
|
376
|
+
notes: runContext?.notes ?? [],
|
|
377
|
+
status: "failed",
|
|
378
|
+
error,
|
|
379
|
+
});
|
|
380
|
+
throw Object.assign(
|
|
381
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
382
|
+
{
|
|
383
|
+
visualMetadata: metadata,
|
|
384
|
+
},
|
|
385
|
+
);
|
|
386
|
+
} finally {
|
|
387
|
+
if (!metadata) {
|
|
388
|
+
metadata = buildScenarioMetadata({
|
|
389
|
+
artifactRoot,
|
|
390
|
+
gameId,
|
|
391
|
+
scenario,
|
|
392
|
+
mode,
|
|
393
|
+
urls,
|
|
394
|
+
screenshotRecords: runContext?.screenshotRecords ?? [],
|
|
395
|
+
notes: runContext?.notes ?? [],
|
|
396
|
+
status: "failed",
|
|
397
|
+
error:
|
|
398
|
+
scenarioError ??
|
|
399
|
+
new Error("Scenario setup failed before capture completed."),
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
writeJson(path.join(scenarioDir, "metadata.json"), metadata);
|
|
404
|
+
if (runContext) {
|
|
405
|
+
await runContext.close();
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
return metadata;
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
const listScenarioIds = (
|
|
413
|
+
scenarioPack: VisualScenarioPack<AnyAirJamAgentContract>,
|
|
414
|
+
): string[] => scenarioPack.scenarios.map((scenario) => scenario.id);
|
|
415
|
+
|
|
416
|
+
export type VisualHarnessStackHandle = {
|
|
417
|
+
urls: Omit<VisualHarnessUrls, "controllerJoinUrl">;
|
|
418
|
+
shutdown: () => Promise<void> | void;
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
export type RunVisualHarnessOptions = {
|
|
422
|
+
gameId: string;
|
|
423
|
+
scenarioId?: string | null;
|
|
424
|
+
mode?: VisualHarnessMode;
|
|
425
|
+
secure?: boolean;
|
|
426
|
+
artifactRoot: string;
|
|
427
|
+
loadScenarioPack: (
|
|
428
|
+
gameId: string,
|
|
429
|
+
) => Promise<VisualScenarioPack<AnyAirJamAgentContract>>;
|
|
430
|
+
startStack: (options: {
|
|
431
|
+
gameId: string;
|
|
432
|
+
mode: VisualHarnessMode;
|
|
433
|
+
secure: boolean;
|
|
434
|
+
}) => Promise<VisualHarnessStackHandle>;
|
|
435
|
+
createAgentSession?: (options: {
|
|
436
|
+
gameId: string;
|
|
437
|
+
scenarioId: string;
|
|
438
|
+
urls: VisualHarnessUrls;
|
|
439
|
+
mode: VisualHarnessMode;
|
|
440
|
+
secure: boolean;
|
|
441
|
+
}) => Promise<VisualScenarioAgent<Record<string, unknown>>>;
|
|
442
|
+
onScenarioStart?: (scenario: VisualScenario<AnyAirJamAgentContract>) => void;
|
|
443
|
+
onCaptureStart?: (info: {
|
|
444
|
+
gameId: string;
|
|
445
|
+
mode: VisualHarnessMode;
|
|
446
|
+
scenarioCount: number;
|
|
447
|
+
}) => void;
|
|
448
|
+
onComplete?: (summary: VisualCaptureSummary) => void;
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
export const runVisualHarness = async ({
|
|
452
|
+
gameId,
|
|
453
|
+
scenarioId = null,
|
|
454
|
+
mode = "standalone-dev",
|
|
455
|
+
secure = false,
|
|
456
|
+
artifactRoot,
|
|
457
|
+
loadScenarioPack,
|
|
458
|
+
startStack,
|
|
459
|
+
createAgentSession,
|
|
460
|
+
onScenarioStart,
|
|
461
|
+
onCaptureStart,
|
|
462
|
+
onComplete,
|
|
463
|
+
}: RunVisualHarnessOptions): Promise<VisualCaptureSummary> => {
|
|
464
|
+
if (mode !== "arcade-built" && mode !== "standalone-dev") {
|
|
465
|
+
throw new Error(
|
|
466
|
+
`Unsupported visual capture mode "${mode}". Phase 1 currently supports "standalone-dev" and "arcade-built".`,
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
const scenarioPack = await loadScenarioPack(gameId);
|
|
471
|
+
const scenarios = scenarioId
|
|
472
|
+
? scenarioPack.scenarios.filter((scenario) => scenario.id === scenarioId)
|
|
473
|
+
: scenarioPack.scenarios;
|
|
474
|
+
|
|
475
|
+
if (scenarios.length === 0) {
|
|
476
|
+
throw new Error(
|
|
477
|
+
`No visual capture scenario matched "${scenarioId}" for "${gameId}". Available scenarios: ${listScenarioIds(scenarioPack).join(", ")}`,
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
const gameArtifactRoot = path.join(artifactRoot, gameId);
|
|
482
|
+
if (!scenarioId) {
|
|
483
|
+
resetDir(gameArtifactRoot);
|
|
484
|
+
} else {
|
|
485
|
+
ensureDir(gameArtifactRoot);
|
|
486
|
+
}
|
|
487
|
+
fs.rmSync(path.join(gameArtifactRoot, "capture-summary.json"), {
|
|
488
|
+
force: true,
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
const stack = await startStack({
|
|
492
|
+
gameId,
|
|
493
|
+
mode,
|
|
494
|
+
secure,
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
const browser = await launchHarnessBrowser();
|
|
498
|
+
|
|
499
|
+
const results: VisualCaptureScenarioMetadata[] = [];
|
|
500
|
+
|
|
501
|
+
try {
|
|
502
|
+
onCaptureStart?.({
|
|
503
|
+
gameId,
|
|
504
|
+
mode,
|
|
505
|
+
scenarioCount: scenarios.length,
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
for (const scenario of scenarios) {
|
|
509
|
+
onScenarioStart?.(scenario);
|
|
510
|
+
const metadata = await runScenarioCapture({
|
|
511
|
+
artifactRoot,
|
|
512
|
+
browser,
|
|
513
|
+
gameId,
|
|
514
|
+
scenario,
|
|
515
|
+
urls: stack.urls,
|
|
516
|
+
mode,
|
|
517
|
+
secure,
|
|
518
|
+
createAgentSession,
|
|
519
|
+
});
|
|
520
|
+
results.push(metadata);
|
|
521
|
+
}
|
|
522
|
+
} finally {
|
|
523
|
+
await browser.close().catch(() => null);
|
|
524
|
+
await stack.shutdown();
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
const summary: VisualCaptureSummary = {
|
|
528
|
+
gameId,
|
|
529
|
+
mode,
|
|
530
|
+
secure,
|
|
531
|
+
capturedAt: new Date().toISOString(),
|
|
532
|
+
scenarios: results.map((result) => ({
|
|
533
|
+
scenarioId: result.scenarioId,
|
|
534
|
+
status: result.status,
|
|
535
|
+
screenshotCount: result.screenshots.length,
|
|
536
|
+
relativeDir: path.relative(
|
|
537
|
+
artifactRoot,
|
|
538
|
+
path.join(artifactRoot, gameId, result.scenarioId),
|
|
539
|
+
),
|
|
540
|
+
})),
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
writeJson(path.join(gameArtifactRoot, "capture-summary.json"), summary);
|
|
544
|
+
onComplete?.(summary);
|
|
545
|
+
return summary;
|
|
546
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AnyAirJamAgentContract } from "@air-jam/sdk";
|
|
2
|
+
import type { VisualScenario, VisualScenarioPack } from "./types.js";
|
|
3
|
+
|
|
4
|
+
export const defineVisualScenarios = <
|
|
5
|
+
TAgent extends AnyAirJamAgentContract,
|
|
6
|
+
>(pack: {
|
|
7
|
+
agent: TAgent;
|
|
8
|
+
scenarios: ReadonlyArray<VisualScenario<TAgent>>;
|
|
9
|
+
}): VisualScenarioPack<TAgent> => pack;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { VisualScenarioContext, VisualViewport } from "./types.js";
|
|
2
|
+
|
|
3
|
+
export const STANDARD_HOST_VIEWPORTS = [
|
|
4
|
+
["mac-desktop", { width: 3016, height: 1504 }],
|
|
5
|
+
["desktop", { width: 1440, height: 1024 }],
|
|
6
|
+
["tablet", { width: 1024, height: 1180 }],
|
|
7
|
+
] as const satisfies readonly [string, VisualViewport][];
|
|
8
|
+
|
|
9
|
+
export const STANDARD_CONTROLLER_VIEWPORTS = [
|
|
10
|
+
["mobile", { width: 390, height: 844 }],
|
|
11
|
+
["small-mobile", { width: 360, height: 640 }],
|
|
12
|
+
] as const satisfies readonly [string, VisualViewport][];
|
|
13
|
+
|
|
14
|
+
export const STANDARD_CONTROLLER_LANDSCAPE_VIEWPORTS = [
|
|
15
|
+
["mobile", { width: 844, height: 390 }],
|
|
16
|
+
["small-mobile", { width: 640, height: 360 }],
|
|
17
|
+
] as const satisfies readonly [string, VisualViewport][];
|
|
18
|
+
|
|
19
|
+
export const captureStandardSurfaces = async (
|
|
20
|
+
context: VisualScenarioContext,
|
|
21
|
+
options?: {
|
|
22
|
+
controllerOrientation?: "portrait" | "landscape";
|
|
23
|
+
},
|
|
24
|
+
): Promise<void> => {
|
|
25
|
+
for (const [viewportName, viewport] of STANDARD_HOST_VIEWPORTS) {
|
|
26
|
+
await context.captureHost(viewportName, viewport);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
await context.ensureControllerInteractive();
|
|
30
|
+
const controllerOrientation = options?.controllerOrientation ?? "portrait";
|
|
31
|
+
const controllerViewports =
|
|
32
|
+
controllerOrientation === "landscape"
|
|
33
|
+
? STANDARD_CONTROLLER_LANDSCAPE_VIEWPORTS
|
|
34
|
+
: STANDARD_CONTROLLER_VIEWPORTS;
|
|
35
|
+
context.note(
|
|
36
|
+
`Captured controller surfaces in ${controllerOrientation} orientation.`,
|
|
37
|
+
);
|
|
38
|
+
for (const [viewportName, viewport] of controllerViewports) {
|
|
39
|
+
await context.captureController(viewportName, viewport);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const waitForHostText = async (
|
|
44
|
+
context: VisualScenarioContext,
|
|
45
|
+
text: string | RegExp,
|
|
46
|
+
timeout = 30_000,
|
|
47
|
+
): Promise<void> => {
|
|
48
|
+
await context.host.game
|
|
49
|
+
.getByText(text)
|
|
50
|
+
.first()
|
|
51
|
+
.waitFor({ state: "visible", timeout });
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const waitForControllerText = async (
|
|
55
|
+
context: VisualScenarioContext,
|
|
56
|
+
text: string | RegExp,
|
|
57
|
+
timeout = 30_000,
|
|
58
|
+
): Promise<void> => {
|
|
59
|
+
await context.controller.game
|
|
60
|
+
.getByText(text)
|
|
61
|
+
.first()
|
|
62
|
+
.waitFor({ state: "visible", timeout });
|
|
63
|
+
};
|