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