@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,1014 @@
|
|
|
1
|
+
import {
|
|
2
|
+
processScopeAdmittedSchema,
|
|
3
|
+
processScopeMarker
|
|
4
|
+
} from "./chunk-SPYN66UV.js";
|
|
5
|
+
import {
|
|
6
|
+
inspectGame
|
|
7
|
+
} from "./chunk-ART5TEYT.js";
|
|
8
|
+
|
|
9
|
+
// src/harness/visual/prefab-contract.ts
|
|
10
|
+
var definePrefabCaptureHarness = (harness) => harness;
|
|
11
|
+
|
|
12
|
+
// src/harness/visual/prefab-runner.ts
|
|
13
|
+
import fs from "fs";
|
|
14
|
+
import path from "path";
|
|
15
|
+
import { pathToFileURL } from "url";
|
|
16
|
+
import { z } from "zod";
|
|
17
|
+
|
|
18
|
+
// src/harness/visual/session.ts
|
|
19
|
+
import {
|
|
20
|
+
fixedControllerOrientation
|
|
21
|
+
} from "@air-jam/sdk/metadata";
|
|
22
|
+
import {
|
|
23
|
+
AIR_JAM_RUNTIME_INSPECTION_KEY,
|
|
24
|
+
readRuntimeInspectionContract
|
|
25
|
+
} from "@air-jam/sdk/runtime-inspection";
|
|
26
|
+
import {
|
|
27
|
+
AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX,
|
|
28
|
+
resolveRuntimeTopology
|
|
29
|
+
} from "@air-jam/sdk/runtime-topology";
|
|
30
|
+
|
|
31
|
+
// src/harness/visual/browser.ts
|
|
32
|
+
import {
|
|
33
|
+
AIR_JAM_RUNTIME_TOPOLOGY_WINDOW_KEY
|
|
34
|
+
} from "@air-jam/sdk/runtime-topology";
|
|
35
|
+
import {
|
|
36
|
+
chromium
|
|
37
|
+
} from "playwright-core";
|
|
38
|
+
|
|
39
|
+
// src/process-scope-admission.ts
|
|
40
|
+
import { randomUUID } from "crypto";
|
|
41
|
+
function processScopeToken() {
|
|
42
|
+
const token = process.argv.find((value) => value.startsWith("--airjam-process-scope="))?.split("=")[1];
|
|
43
|
+
if (!process.connected || !token)
|
|
44
|
+
throw new Error(
|
|
45
|
+
"process_scope_unavailable: A scoped helper requires its owner's admission channel."
|
|
46
|
+
);
|
|
47
|
+
return token;
|
|
48
|
+
}
|
|
49
|
+
async function admitProcessScopeMember(processId) {
|
|
50
|
+
const token = processScopeToken();
|
|
51
|
+
const id = randomUUID();
|
|
52
|
+
await new Promise((resolve, reject) => {
|
|
53
|
+
const finish = (error) => {
|
|
54
|
+
clearTimeout(timer);
|
|
55
|
+
process.off("message", receive);
|
|
56
|
+
process.off("disconnect", disconnected);
|
|
57
|
+
if (error) reject(error);
|
|
58
|
+
else resolve();
|
|
59
|
+
};
|
|
60
|
+
const receive = (value) => {
|
|
61
|
+
const result = processScopeAdmittedSchema.safeParse(value);
|
|
62
|
+
if (result.success && result.data.id === id)
|
|
63
|
+
finish(result.data.error ? new Error(result.data.error) : void 0);
|
|
64
|
+
};
|
|
65
|
+
const disconnected = () => finish(
|
|
66
|
+
new Error("process_scope_unavailable: Admission owner disconnected.")
|
|
67
|
+
);
|
|
68
|
+
const timer = setTimeout(
|
|
69
|
+
() => finish(new Error("process_scope_unavailable: Admission timed out.")),
|
|
70
|
+
1e4
|
|
71
|
+
);
|
|
72
|
+
process.on("message", receive);
|
|
73
|
+
process.once("disconnect", disconnected);
|
|
74
|
+
process.send?.(
|
|
75
|
+
{ type: "airjam-process-scope/admit", id, token, processId },
|
|
76
|
+
void 0,
|
|
77
|
+
void 0,
|
|
78
|
+
(error) => {
|
|
79
|
+
if (error) finish(error);
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/harness/visual/browser.ts
|
|
86
|
+
async function installHarnessRuntimeTopology(context, topology) {
|
|
87
|
+
await context.addInitScript(
|
|
88
|
+
({ key, topology: topology2 }) => {
|
|
89
|
+
if (window.location.origin === topology2.appOrigin)
|
|
90
|
+
window[key] = topology2;
|
|
91
|
+
},
|
|
92
|
+
{ key: AIR_JAM_RUNTIME_TOPOLOGY_WINDOW_KEY, topology }
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
var launchHarnessBrowserOptions = () => {
|
|
96
|
+
return {
|
|
97
|
+
headless: true,
|
|
98
|
+
args: [
|
|
99
|
+
// Without a GPU, compositing through SwiftShader took about three
|
|
100
|
+
// quarters of a one-CPU project and ran games at a quarter speed;
|
|
101
|
+
// software compositing reaches 60 fps there, and WebGL keeps SwiftShader.
|
|
102
|
+
"--disable-gpu-compositing",
|
|
103
|
+
"--enable-webgl",
|
|
104
|
+
"--ignore-gpu-blocklist",
|
|
105
|
+
"--use-angle=swiftshader"
|
|
106
|
+
]
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
var launchConfiguredBrowser = async (launch) => {
|
|
110
|
+
const options = launchHarnessBrowserOptions();
|
|
111
|
+
if (process.env.AIRJAM_BROWSER_EXECUTABLE_PATH) {
|
|
112
|
+
return launch({
|
|
113
|
+
...options,
|
|
114
|
+
executablePath: process.env.AIRJAM_BROWSER_EXECUTABLE_PATH
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
return await launch(options);
|
|
119
|
+
} catch (bundledBrowserError) {
|
|
120
|
+
try {
|
|
121
|
+
return await launch({ ...options, channel: "chrome" });
|
|
122
|
+
} catch (systemBrowserError) {
|
|
123
|
+
throw new Error(
|
|
124
|
+
[
|
|
125
|
+
"Air Jam could not launch a browser runtime for semantic sessions.",
|
|
126
|
+
"Install Playwright Chromium or set AIRJAM_BROWSER_EXECUTABLE_PATH to a Chromium-compatible browser.",
|
|
127
|
+
`Bundled browser: ${bundledBrowserError instanceof Error ? bundledBrowserError.message : String(bundledBrowserError)}`,
|
|
128
|
+
`System Chrome: ${systemBrowserError instanceof Error ? systemBrowserError.message : String(systemBrowserError)}`
|
|
129
|
+
].join("\n\n")
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
var launchHarnessBrowser = () => launchConfiguredBrowser((options) => chromium.launch(options));
|
|
135
|
+
async function launchScopedHarnessBrowser() {
|
|
136
|
+
const marker = processScopeMarker(processScopeToken());
|
|
137
|
+
const server = await launchConfiguredBrowser(
|
|
138
|
+
(options) => chromium.launchServer({
|
|
139
|
+
...options,
|
|
140
|
+
args: [...options.args ?? [], marker]
|
|
141
|
+
})
|
|
142
|
+
);
|
|
143
|
+
try {
|
|
144
|
+
const processId = server.process().pid;
|
|
145
|
+
if (!processId)
|
|
146
|
+
throw new Error(
|
|
147
|
+
"process_scope_unavailable: Browser process identity unavailable."
|
|
148
|
+
);
|
|
149
|
+
await admitProcessScopeMember(processId);
|
|
150
|
+
const browser = await chromium.connect(server.wsEndpoint());
|
|
151
|
+
return { browser, close: () => server.close() };
|
|
152
|
+
} catch (error) {
|
|
153
|
+
await server.close();
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/harness/visual/session.ts
|
|
159
|
+
var DEFAULT_HOST_VIEWPORT = {
|
|
160
|
+
width: 1440,
|
|
161
|
+
height: 1024
|
|
162
|
+
};
|
|
163
|
+
var DEFAULT_CONTROLLER_VIEWPORT = {
|
|
164
|
+
width: 390,
|
|
165
|
+
height: 844
|
|
166
|
+
};
|
|
167
|
+
var isEmbeddedMode = (mode) => mode !== "standalone-dev";
|
|
168
|
+
var dismissHarnessControllerFullscreenPrompt = async (page) => {
|
|
169
|
+
const openPrompt = page.locator(
|
|
170
|
+
'[data-testid="controller-fullscreen-prompt"][data-state="open"]'
|
|
171
|
+
);
|
|
172
|
+
await openPrompt.waitFor({ state: "visible", timeout: 5e3 }).catch(() => null);
|
|
173
|
+
if (!await openPrompt.isVisible().catch(() => false)) {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
await page.getByTestId("controller-fullscreen-prompt-dismiss").click({ force: true });
|
|
177
|
+
await openPrompt.waitFor({ state: "hidden", timeout: 1e4 });
|
|
178
|
+
return true;
|
|
179
|
+
};
|
|
180
|
+
var waitForFrameToLoad = async ({
|
|
181
|
+
page,
|
|
182
|
+
testId,
|
|
183
|
+
timeoutMs = 3e4
|
|
184
|
+
}) => {
|
|
185
|
+
const iframe = page.getByTestId(testId);
|
|
186
|
+
await iframe.waitFor({ state: "visible", timeout: timeoutMs });
|
|
187
|
+
const iframeHandle = await iframe.elementHandle({ timeout: timeoutMs });
|
|
188
|
+
if (!iframeHandle) {
|
|
189
|
+
throw new Error(`Could not resolve iframe handle for "${testId}".`);
|
|
190
|
+
}
|
|
191
|
+
const startedAt = Date.now();
|
|
192
|
+
let resolvedFrame = null;
|
|
193
|
+
while (Date.now() - startedAt < timeoutMs) {
|
|
194
|
+
const nextFrame = await iframeHandle.contentFrame();
|
|
195
|
+
const frameUrl = nextFrame?.url() ?? "";
|
|
196
|
+
if (nextFrame && frameUrl.length > 0 && frameUrl !== "about:blank") {
|
|
197
|
+
resolvedFrame = nextFrame;
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
await page.waitForTimeout(100);
|
|
201
|
+
}
|
|
202
|
+
if (!resolvedFrame) {
|
|
203
|
+
throw new Error(`Timed out waiting for iframe "${testId}" to resolve.`);
|
|
204
|
+
}
|
|
205
|
+
await resolvedFrame.waitForLoadState("domcontentloaded", {
|
|
206
|
+
timeout: Math.max(1, timeoutMs - (Date.now() - startedAt))
|
|
207
|
+
});
|
|
208
|
+
return page.frameLocator(`iframe[data-testid="${testId}"]`);
|
|
209
|
+
};
|
|
210
|
+
var readRuntimeHref = async ({
|
|
211
|
+
page,
|
|
212
|
+
game,
|
|
213
|
+
embedded
|
|
214
|
+
}) => embedded ? game.locator("body").evaluate(() => window.location.href) : page.evaluate(() => window.location.href);
|
|
215
|
+
var readHostRuntimeInspection = async ({
|
|
216
|
+
page,
|
|
217
|
+
game,
|
|
218
|
+
embedded
|
|
219
|
+
}) => {
|
|
220
|
+
const rawInspection = embedded ? await game.locator("body").evaluate(
|
|
221
|
+
(_, key) => window[key] ?? null,
|
|
222
|
+
AIR_JAM_RUNTIME_INSPECTION_KEY
|
|
223
|
+
) : await page.evaluate(
|
|
224
|
+
(key) => window[key] ?? null,
|
|
225
|
+
AIR_JAM_RUNTIME_INSPECTION_KEY
|
|
226
|
+
);
|
|
227
|
+
const inspection = readRuntimeInspectionContract({
|
|
228
|
+
[AIR_JAM_RUNTIME_INSPECTION_KEY]: rawInspection
|
|
229
|
+
});
|
|
230
|
+
return inspection?.role === "host" ? inspection : null;
|
|
231
|
+
};
|
|
232
|
+
function bindHarnessControllerUrl(resolvedJoinUrl, controllerBaseUrl) {
|
|
233
|
+
const joinUrl = new URL(resolvedJoinUrl);
|
|
234
|
+
const controllerUrl = new URL(controllerBaseUrl);
|
|
235
|
+
joinUrl.protocol = controllerUrl.protocol;
|
|
236
|
+
joinUrl.host = controllerUrl.host;
|
|
237
|
+
for (const [key, value] of controllerUrl.searchParams)
|
|
238
|
+
if (key.startsWith(AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX))
|
|
239
|
+
joinUrl.searchParams.set(key, value);
|
|
240
|
+
return joinUrl.toString();
|
|
241
|
+
}
|
|
242
|
+
var resolveControllerJoinUrl = async ({
|
|
243
|
+
hostPage,
|
|
244
|
+
hostGame,
|
|
245
|
+
hostEmbedded,
|
|
246
|
+
controllerBaseUrl
|
|
247
|
+
}) => {
|
|
248
|
+
let resolvedJoinUrl = null;
|
|
249
|
+
for (let attempt = 0; attempt < 80; attempt += 1) {
|
|
250
|
+
const inspection = await readHostRuntimeInspection({
|
|
251
|
+
page: hostPage,
|
|
252
|
+
game: hostGame,
|
|
253
|
+
embedded: hostEmbedded
|
|
254
|
+
});
|
|
255
|
+
if (inspection?.joinUrlStatus === "ready" && inspection.joinUrl) {
|
|
256
|
+
resolvedJoinUrl = inspection.joinUrl;
|
|
257
|
+
}
|
|
258
|
+
if (!resolvedJoinUrl) {
|
|
259
|
+
const runtimeUrl = new URL(
|
|
260
|
+
await readRuntimeHref({
|
|
261
|
+
page: hostPage,
|
|
262
|
+
game: hostGame,
|
|
263
|
+
embedded: hostEmbedded
|
|
264
|
+
})
|
|
265
|
+
);
|
|
266
|
+
resolvedJoinUrl = runtimeUrl.searchParams.get("aj_join_url");
|
|
267
|
+
}
|
|
268
|
+
if (resolvedJoinUrl) {
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
await hostPage.waitForTimeout(250);
|
|
272
|
+
}
|
|
273
|
+
if (!resolvedJoinUrl) {
|
|
274
|
+
throw new Error(
|
|
275
|
+
"Could not resolve a controller join URL from the host runtime inspection contract or runtime URL."
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
return bindHarnessControllerUrl(resolvedJoinUrl, controllerBaseUrl);
|
|
279
|
+
};
|
|
280
|
+
var openVisualHarnessHostSession = async ({
|
|
281
|
+
browser,
|
|
282
|
+
runtimeTopology,
|
|
283
|
+
onDiagnostic,
|
|
284
|
+
urls,
|
|
285
|
+
mode
|
|
286
|
+
}) => {
|
|
287
|
+
const embedded = isEmbeddedMode(mode);
|
|
288
|
+
const hostContext = await browser.newContext({
|
|
289
|
+
viewport: DEFAULT_HOST_VIEWPORT
|
|
290
|
+
});
|
|
291
|
+
try {
|
|
292
|
+
if (runtimeTopology)
|
|
293
|
+
await installHarnessRuntimeTopology(hostContext, runtimeTopology);
|
|
294
|
+
const hostPage = await hostContext.newPage();
|
|
295
|
+
if (onDiagnostic) {
|
|
296
|
+
hostPage.on(
|
|
297
|
+
"pageerror",
|
|
298
|
+
(error) => onDiagnostic(`Page error: ${error.message}`)
|
|
299
|
+
);
|
|
300
|
+
hostPage.on("console", (message) => {
|
|
301
|
+
if (message.type() === "error")
|
|
302
|
+
onDiagnostic(`Browser error: ${message.text()}`);
|
|
303
|
+
});
|
|
304
|
+
hostPage.on("requestfailed", (request) => {
|
|
305
|
+
const url = new URL(request.url());
|
|
306
|
+
onDiagnostic(
|
|
307
|
+
`Request failed: ${url.origin}${url.pathname}: ${request.failure()?.errorText}`
|
|
308
|
+
);
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
await hostPage.goto(urls.hostUrl, { waitUntil: "domcontentloaded" });
|
|
312
|
+
const hostGame = embedded ? await waitForFrameToLoad({
|
|
313
|
+
page: hostPage,
|
|
314
|
+
testId: "arcade-host-game-frame"
|
|
315
|
+
}) : hostPage;
|
|
316
|
+
return {
|
|
317
|
+
urls: { ...urls, controllerJoinUrl: null },
|
|
318
|
+
host: {
|
|
319
|
+
page: hostPage,
|
|
320
|
+
game: hostGame,
|
|
321
|
+
embedded
|
|
322
|
+
},
|
|
323
|
+
close: () => hostContext.close()
|
|
324
|
+
};
|
|
325
|
+
} catch (error) {
|
|
326
|
+
await hostContext.close().catch(() => null);
|
|
327
|
+
throw error;
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
var openVisualHarnessControllerSession = async ({
|
|
331
|
+
browser,
|
|
332
|
+
inputModalities,
|
|
333
|
+
runtimeTopology,
|
|
334
|
+
urls,
|
|
335
|
+
host
|
|
336
|
+
}) => {
|
|
337
|
+
const controllerContext = await browser.newContext({
|
|
338
|
+
viewport: fixedControllerOrientation(inputModalities ?? []) === "landscape" ? {
|
|
339
|
+
width: DEFAULT_CONTROLLER_VIEWPORT.height,
|
|
340
|
+
height: DEFAULT_CONTROLLER_VIEWPORT.width
|
|
341
|
+
} : DEFAULT_CONTROLLER_VIEWPORT
|
|
342
|
+
});
|
|
343
|
+
try {
|
|
344
|
+
if (runtimeTopology)
|
|
345
|
+
await installHarnessRuntimeTopology(
|
|
346
|
+
controllerContext,
|
|
347
|
+
resolveRuntimeTopology({
|
|
348
|
+
...runtimeTopology,
|
|
349
|
+
surfaceRole: "controller"
|
|
350
|
+
})
|
|
351
|
+
);
|
|
352
|
+
const controllerJoinUrl = await resolveControllerJoinUrl({
|
|
353
|
+
hostPage: host.page,
|
|
354
|
+
hostGame: host.game,
|
|
355
|
+
hostEmbedded: host.embedded,
|
|
356
|
+
controllerBaseUrl: urls.controllerBaseUrl
|
|
357
|
+
});
|
|
358
|
+
const controllerPage = await controllerContext.newPage();
|
|
359
|
+
await controllerPage.goto(controllerJoinUrl, {
|
|
360
|
+
waitUntil: "domcontentloaded"
|
|
361
|
+
});
|
|
362
|
+
const fullscreenPromptDismissed = await dismissHarnessControllerFullscreenPrompt(controllerPage);
|
|
363
|
+
const controllerGame = host.embedded ? await waitForFrameToLoad({
|
|
364
|
+
page: controllerPage,
|
|
365
|
+
testId: "arcade-controller-game-frame"
|
|
366
|
+
}) : controllerPage;
|
|
367
|
+
return {
|
|
368
|
+
urls: { ...urls, controllerJoinUrl },
|
|
369
|
+
controller: {
|
|
370
|
+
page: controllerPage,
|
|
371
|
+
game: controllerGame,
|
|
372
|
+
embedded: host.embedded,
|
|
373
|
+
fullscreenPromptDismissed
|
|
374
|
+
},
|
|
375
|
+
close: () => controllerContext.close()
|
|
376
|
+
};
|
|
377
|
+
} catch (error) {
|
|
378
|
+
await controllerContext.close().catch(() => null);
|
|
379
|
+
throw error;
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
var openVisualHarnessSession = async ({
|
|
383
|
+
browser,
|
|
384
|
+
inputModalities,
|
|
385
|
+
runtimeTopology,
|
|
386
|
+
onDiagnostic,
|
|
387
|
+
urls,
|
|
388
|
+
mode
|
|
389
|
+
}) => {
|
|
390
|
+
const hostSession = await openVisualHarnessHostSession({
|
|
391
|
+
browser,
|
|
392
|
+
runtimeTopology,
|
|
393
|
+
onDiagnostic,
|
|
394
|
+
urls,
|
|
395
|
+
mode
|
|
396
|
+
});
|
|
397
|
+
try {
|
|
398
|
+
const controllerSession = await openVisualHarnessControllerSession({
|
|
399
|
+
browser,
|
|
400
|
+
inputModalities,
|
|
401
|
+
runtimeTopology,
|
|
402
|
+
urls,
|
|
403
|
+
host: hostSession.host
|
|
404
|
+
});
|
|
405
|
+
return {
|
|
406
|
+
urls: controllerSession.urls,
|
|
407
|
+
host: hostSession.host,
|
|
408
|
+
controller: controllerSession.controller,
|
|
409
|
+
close: async () => {
|
|
410
|
+
await Promise.allSettled([
|
|
411
|
+
hostSession.close(),
|
|
412
|
+
controllerSession.close()
|
|
413
|
+
]);
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
} catch (error) {
|
|
417
|
+
await hostSession.close().catch(() => null);
|
|
418
|
+
throw error;
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
// src/harness/visual/prefab-runner.ts
|
|
423
|
+
var prefabHarnessSchema = z.object({
|
|
424
|
+
gameId: z.string(),
|
|
425
|
+
prefabs: z.array(
|
|
426
|
+
z.object({
|
|
427
|
+
id: z.string(),
|
|
428
|
+
prefabId: z.string(),
|
|
429
|
+
description: z.string().optional(),
|
|
430
|
+
viewport: z.object({
|
|
431
|
+
width: z.number().int().positive(),
|
|
432
|
+
height: z.number().int().positive()
|
|
433
|
+
}).optional(),
|
|
434
|
+
waitForTestId: z.string().optional(),
|
|
435
|
+
buildHostUrl: z.custom(
|
|
436
|
+
(value) => typeof value === "function"
|
|
437
|
+
)
|
|
438
|
+
})
|
|
439
|
+
)
|
|
440
|
+
});
|
|
441
|
+
var artifactSegment = (value) => {
|
|
442
|
+
const segment = value.replace(/[^a-zA-Z0-9._-]+/g, "-");
|
|
443
|
+
if (!segment || segment === "." || segment === "..") {
|
|
444
|
+
throw new Error(`Invalid prefab artifact segment "${value}".`);
|
|
445
|
+
}
|
|
446
|
+
return segment;
|
|
447
|
+
};
|
|
448
|
+
var loadPrefabCapture = async ({
|
|
449
|
+
gameId,
|
|
450
|
+
gameDirectory,
|
|
451
|
+
prefabId,
|
|
452
|
+
variantPairs = [],
|
|
453
|
+
mode = "standalone-dev",
|
|
454
|
+
secure = false
|
|
455
|
+
}) => {
|
|
456
|
+
if (mode !== "standalone-dev" && mode !== "arcade-built") {
|
|
457
|
+
throw new Error(`Unsupported visual prefab capture mode "${mode}".`);
|
|
458
|
+
}
|
|
459
|
+
if (!gameId || gameId === "." || gameId === "..") {
|
|
460
|
+
throw new Error(`Invalid prefab capture game id "${gameId}".`);
|
|
461
|
+
}
|
|
462
|
+
const modulePath = ["prefabs.ts", "prefabs.mjs"].map((fileName) => path.join(gameDirectory, "visual", fileName)).find((filePath) => fs.existsSync(filePath));
|
|
463
|
+
if (!modulePath) {
|
|
464
|
+
throw new Error(
|
|
465
|
+
`No prefab capture harness found in ${path.join(gameDirectory, "visual")}.`
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
const loaded = await import(pathToFileURL(modulePath).href);
|
|
469
|
+
const parsed = prefabHarnessSchema.safeParse(loaded.prefabCaptureHarness);
|
|
470
|
+
if (!parsed.success || parsed.data.gameId !== gameId) {
|
|
471
|
+
throw new Error(
|
|
472
|
+
`Invalid prefab capture harness for "${gameId}" at ${modulePath}.`
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
const harness = parsed.data;
|
|
476
|
+
const prefab = harness.prefabs.find(
|
|
477
|
+
(candidate) => candidate.id === prefabId || candidate.prefabId === prefabId
|
|
478
|
+
);
|
|
479
|
+
if (!prefab) {
|
|
480
|
+
throw new Error(
|
|
481
|
+
`No prefab capture matched "${prefabId}" for "${gameId}". Available prefab captures: ${harness.prefabs.map((entry) => `${entry.id} -> ${entry.prefabId}`).join(", ")}`
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
const variants = Object.fromEntries(
|
|
485
|
+
variantPairs.map((pair) => {
|
|
486
|
+
const separator = pair.indexOf("=");
|
|
487
|
+
const key = pair.slice(0, separator).trim();
|
|
488
|
+
const value = pair.slice(separator + 1).trim();
|
|
489
|
+
if (separator <= 0 || !key || !value) {
|
|
490
|
+
throw new Error(
|
|
491
|
+
`Invalid --variant value "${pair}". Expected key=value.`
|
|
492
|
+
);
|
|
493
|
+
}
|
|
494
|
+
return [key, value];
|
|
495
|
+
})
|
|
496
|
+
);
|
|
497
|
+
const suffix = Object.entries(variants).sort(([left], [right]) => left.localeCompare(right)).map(([key, value]) => `${artifactSegment(key)}-${artifactSegment(value)}`).join("__");
|
|
498
|
+
const artifactId = [artifactSegment(prefab.id), suffix].filter(Boolean).join("__");
|
|
499
|
+
return { gameId, prefab, variants, artifactId, mode, secure };
|
|
500
|
+
};
|
|
501
|
+
var capturePrefabAtRuntime = async ({
|
|
502
|
+
capture,
|
|
503
|
+
hostUrl,
|
|
504
|
+
artifactRoot
|
|
505
|
+
}) => {
|
|
506
|
+
const { gameId, prefab, variants, artifactId, mode, secure } = capture;
|
|
507
|
+
const artifactDirectory = path.join(
|
|
508
|
+
artifactRoot,
|
|
509
|
+
encodeURIComponent(gameId),
|
|
510
|
+
"prefabs",
|
|
511
|
+
artifactId
|
|
512
|
+
);
|
|
513
|
+
fs.rmSync(artifactDirectory, { force: true, recursive: true });
|
|
514
|
+
fs.mkdirSync(artifactDirectory, { recursive: true });
|
|
515
|
+
const targetUrl = prefab.buildHostUrl(hostUrl, {
|
|
516
|
+
prefabId: prefab.prefabId,
|
|
517
|
+
variants,
|
|
518
|
+
mode
|
|
519
|
+
});
|
|
520
|
+
const browser = await launchHarnessBrowser();
|
|
521
|
+
try {
|
|
522
|
+
const viewport = prefab.viewport ?? { width: 1024, height: 1024 };
|
|
523
|
+
const context = await browser.newContext({ viewport });
|
|
524
|
+
try {
|
|
525
|
+
const page = await context.newPage();
|
|
526
|
+
let pageError = null;
|
|
527
|
+
page.on("pageerror", (error) => {
|
|
528
|
+
pageError ??= error;
|
|
529
|
+
});
|
|
530
|
+
await page.goto(targetUrl, { waitUntil: "domcontentloaded" });
|
|
531
|
+
const game = mode === "arcade-built" ? page.frameLocator('iframe[data-testid="arcade-host-game-frame"]') : page;
|
|
532
|
+
if (prefab.waitForTestId) {
|
|
533
|
+
await game.getByTestId(prefab.waitForTestId).waitFor({
|
|
534
|
+
state: "visible",
|
|
535
|
+
timeout: 3e4
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
await page.waitForTimeout(900);
|
|
539
|
+
if (pageError) throw pageError;
|
|
540
|
+
const screenshotPath = path.join(artifactDirectory, "prefab.png");
|
|
541
|
+
await page.screenshot({ path: screenshotPath, fullPage: true });
|
|
542
|
+
const metadata = {
|
|
543
|
+
gameId,
|
|
544
|
+
captureId: prefab.id,
|
|
545
|
+
prefabId: prefab.prefabId,
|
|
546
|
+
runtimeMode: mode,
|
|
547
|
+
secure,
|
|
548
|
+
capturedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
549
|
+
viewport,
|
|
550
|
+
variants,
|
|
551
|
+
url: targetUrl,
|
|
552
|
+
screenshot: {
|
|
553
|
+
fileName: "prefab.png",
|
|
554
|
+
relativePath: path.relative(artifactRoot, screenshotPath)
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
const metadataPath = path.join(artifactDirectory, "metadata.json");
|
|
558
|
+
fs.writeFileSync(metadataPath, `${JSON.stringify(metadata, null, 2)}
|
|
559
|
+
`);
|
|
560
|
+
return { artifactDirectory, metadataPath, metadata };
|
|
561
|
+
} finally {
|
|
562
|
+
await context.close();
|
|
563
|
+
}
|
|
564
|
+
} finally {
|
|
565
|
+
await browser.close();
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
// src/harness/visual/runner.ts
|
|
570
|
+
import fs2 from "fs";
|
|
571
|
+
import path2 from "path";
|
|
572
|
+
var ensureDir = (dir) => {
|
|
573
|
+
fs2.mkdirSync(dir, { recursive: true });
|
|
574
|
+
};
|
|
575
|
+
var writeJson = (filePath, value) => {
|
|
576
|
+
ensureDir(path2.dirname(filePath));
|
|
577
|
+
fs2.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}
|
|
578
|
+
`, "utf8");
|
|
579
|
+
};
|
|
580
|
+
var resetDir = (dir) => {
|
|
581
|
+
fs2.rmSync(dir, { force: true, recursive: true });
|
|
582
|
+
ensureDir(dir);
|
|
583
|
+
};
|
|
584
|
+
var appendFailureScreenshot = async ({
|
|
585
|
+
page,
|
|
586
|
+
surface,
|
|
587
|
+
scenarioDir,
|
|
588
|
+
screenshotRecords
|
|
589
|
+
}) => {
|
|
590
|
+
const viewport = page.viewportSize() ?? DEFAULT_HOST_VIEWPORT;
|
|
591
|
+
const fileName = `${surface}-failure.png`;
|
|
592
|
+
const filePath = path2.join(scenarioDir, fileName);
|
|
593
|
+
await page.screenshot({
|
|
594
|
+
path: filePath,
|
|
595
|
+
fullPage: true
|
|
596
|
+
});
|
|
597
|
+
screenshotRecords.push({
|
|
598
|
+
surface,
|
|
599
|
+
viewportName: "failure",
|
|
600
|
+
width: viewport.width,
|
|
601
|
+
height: viewport.height,
|
|
602
|
+
fileName,
|
|
603
|
+
filePath
|
|
604
|
+
});
|
|
605
|
+
};
|
|
606
|
+
var captureFailureScreenshots = async (runContext) => {
|
|
607
|
+
if (!runContext) {
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
await Promise.allSettled([
|
|
611
|
+
appendFailureScreenshot({
|
|
612
|
+
page: runContext.host.page,
|
|
613
|
+
surface: "host",
|
|
614
|
+
scenarioDir: runContext.scenarioDir,
|
|
615
|
+
screenshotRecords: runContext.screenshotRecords
|
|
616
|
+
}),
|
|
617
|
+
appendFailureScreenshot({
|
|
618
|
+
page: runContext.controller.page,
|
|
619
|
+
surface: "controller",
|
|
620
|
+
scenarioDir: runContext.scenarioDir,
|
|
621
|
+
screenshotRecords: runContext.screenshotRecords
|
|
622
|
+
})
|
|
623
|
+
]);
|
|
624
|
+
};
|
|
625
|
+
var createUnavailableAgentClient = () => {
|
|
626
|
+
const unavailable = async () => {
|
|
627
|
+
throw new Error(
|
|
628
|
+
"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."
|
|
629
|
+
);
|
|
630
|
+
};
|
|
631
|
+
return {
|
|
632
|
+
listActions: async () => [],
|
|
633
|
+
read: unavailable,
|
|
634
|
+
waitFor: unavailable,
|
|
635
|
+
invoke: unavailable,
|
|
636
|
+
close: async () => {
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
};
|
|
640
|
+
var createLazyAgentClient = ({
|
|
641
|
+
createAgentSession
|
|
642
|
+
}) => {
|
|
643
|
+
let sessionPromise = null;
|
|
644
|
+
const getSession = async () => {
|
|
645
|
+
if (!createAgentSession) {
|
|
646
|
+
return createUnavailableAgentClient();
|
|
647
|
+
}
|
|
648
|
+
if (!sessionPromise) {
|
|
649
|
+
sessionPromise = createAgentSession();
|
|
650
|
+
}
|
|
651
|
+
return sessionPromise;
|
|
652
|
+
};
|
|
653
|
+
return {
|
|
654
|
+
listActions: async () => (await getSession()).listActions(),
|
|
655
|
+
read: async () => (await getSession()).read(),
|
|
656
|
+
waitFor: async (predicate, description, timeout) => (await getSession()).waitFor(predicate, description, timeout),
|
|
657
|
+
invoke: async (actionId, payload, options) => (await getSession()).invoke(actionId, payload, options),
|
|
658
|
+
close: async () => {
|
|
659
|
+
if (!sessionPromise) {
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
const session = await sessionPromise.catch(() => null);
|
|
663
|
+
await session?.close().catch(() => null);
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
};
|
|
667
|
+
var createScenarioRunContext = async ({
|
|
668
|
+
browser,
|
|
669
|
+
gameId,
|
|
670
|
+
scenario,
|
|
671
|
+
scenarioDir,
|
|
672
|
+
urls,
|
|
673
|
+
mode,
|
|
674
|
+
secure,
|
|
675
|
+
createAgentSession
|
|
676
|
+
}) => {
|
|
677
|
+
const { declaration } = await inspectGame({ gameId });
|
|
678
|
+
const session = await openVisualHarnessSession({
|
|
679
|
+
inputModalities: declaration.metadata.inputModalities,
|
|
680
|
+
browser,
|
|
681
|
+
urls,
|
|
682
|
+
mode
|
|
683
|
+
});
|
|
684
|
+
const hostPage = session.host.page;
|
|
685
|
+
const controllerPage = session.controller.page;
|
|
686
|
+
const screenshotRecords = [];
|
|
687
|
+
const notes = [];
|
|
688
|
+
notes.push(`Resolved controller join URL: ${session.urls.controllerJoinUrl}`);
|
|
689
|
+
if (session.controller.fullscreenPromptDismissed) {
|
|
690
|
+
notes.push("Dismissed controller fullscreen prompt before capture.");
|
|
691
|
+
}
|
|
692
|
+
const captureSurface = async ({
|
|
693
|
+
surface,
|
|
694
|
+
viewportName,
|
|
695
|
+
width,
|
|
696
|
+
height,
|
|
697
|
+
fullPage = true
|
|
698
|
+
}) => {
|
|
699
|
+
const targetPage = surface === "host" ? hostPage : controllerPage;
|
|
700
|
+
await targetPage.setViewportSize({ width, height });
|
|
701
|
+
await targetPage.waitForTimeout(300);
|
|
702
|
+
const fileName = `${surface}-${viewportName}.png`;
|
|
703
|
+
const filePath = path2.join(scenarioDir, fileName);
|
|
704
|
+
await targetPage.screenshot({
|
|
705
|
+
path: filePath,
|
|
706
|
+
fullPage
|
|
707
|
+
});
|
|
708
|
+
screenshotRecords.push({
|
|
709
|
+
surface,
|
|
710
|
+
viewportName,
|
|
711
|
+
width,
|
|
712
|
+
height,
|
|
713
|
+
fileName,
|
|
714
|
+
filePath
|
|
715
|
+
});
|
|
716
|
+
};
|
|
717
|
+
const agent = createLazyAgentClient({
|
|
718
|
+
createAgentSession: createAgentSession ? () => createAgentSession({
|
|
719
|
+
gameId,
|
|
720
|
+
scenarioId: scenario.id,
|
|
721
|
+
host: session.host,
|
|
722
|
+
urls: session.urls,
|
|
723
|
+
mode,
|
|
724
|
+
secure
|
|
725
|
+
}) : void 0
|
|
726
|
+
});
|
|
727
|
+
return {
|
|
728
|
+
gameId,
|
|
729
|
+
scenario,
|
|
730
|
+
scenarioDir,
|
|
731
|
+
urls: session.urls,
|
|
732
|
+
host: session.host,
|
|
733
|
+
controller: session.controller,
|
|
734
|
+
note: (value) => {
|
|
735
|
+
notes.push(value);
|
|
736
|
+
},
|
|
737
|
+
sleep: (ms) => hostPage.waitForTimeout(ms),
|
|
738
|
+
ensureControllerInteractive: async () => {
|
|
739
|
+
await dismissHarnessControllerFullscreenPrompt(controllerPage);
|
|
740
|
+
},
|
|
741
|
+
agent,
|
|
742
|
+
captureHost: async (viewportName, viewport) => captureSurface({ surface: "host", viewportName, ...viewport }),
|
|
743
|
+
captureController: async (viewportName, viewport) => captureSurface({ surface: "controller", viewportName, ...viewport }),
|
|
744
|
+
inputModalities: declaration.metadata.inputModalities,
|
|
745
|
+
screenshotRecords,
|
|
746
|
+
notes,
|
|
747
|
+
close: async () => {
|
|
748
|
+
await Promise.allSettled([agent.close(), session.close()]);
|
|
749
|
+
}
|
|
750
|
+
};
|
|
751
|
+
};
|
|
752
|
+
var buildScenarioMetadata = ({
|
|
753
|
+
artifactRoot,
|
|
754
|
+
gameId,
|
|
755
|
+
scenario,
|
|
756
|
+
mode,
|
|
757
|
+
urls,
|
|
758
|
+
screenshotRecords,
|
|
759
|
+
notes,
|
|
760
|
+
status,
|
|
761
|
+
error
|
|
762
|
+
}) => ({
|
|
763
|
+
gameId,
|
|
764
|
+
scenarioId: scenario.id,
|
|
765
|
+
scenarioDescription: scenario.description ?? null,
|
|
766
|
+
runtimeMode: mode,
|
|
767
|
+
capturedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
768
|
+
status,
|
|
769
|
+
urls,
|
|
770
|
+
screenshots: screenshotRecords.map((record) => ({
|
|
771
|
+
surface: record.surface,
|
|
772
|
+
viewportName: record.viewportName,
|
|
773
|
+
width: record.width,
|
|
774
|
+
height: record.height,
|
|
775
|
+
fileName: record.fileName,
|
|
776
|
+
relativePath: path2.relative(artifactRoot, record.filePath)
|
|
777
|
+
})),
|
|
778
|
+
notes,
|
|
779
|
+
error: error instanceof Error ? {
|
|
780
|
+
message: error.message,
|
|
781
|
+
stack: error.stack ?? null
|
|
782
|
+
} : null
|
|
783
|
+
});
|
|
784
|
+
var runScenarioCapture = async ({
|
|
785
|
+
artifactRoot,
|
|
786
|
+
browser,
|
|
787
|
+
gameId,
|
|
788
|
+
scenario,
|
|
789
|
+
urls,
|
|
790
|
+
mode,
|
|
791
|
+
secure,
|
|
792
|
+
createAgentSession
|
|
793
|
+
}) => {
|
|
794
|
+
const scenarioDir = path2.join(artifactRoot, gameId, scenario.id);
|
|
795
|
+
resetDir(scenarioDir);
|
|
796
|
+
let runContext = null;
|
|
797
|
+
let metadata = null;
|
|
798
|
+
let scenarioError = null;
|
|
799
|
+
try {
|
|
800
|
+
runContext = await createScenarioRunContext({
|
|
801
|
+
browser,
|
|
802
|
+
gameId,
|
|
803
|
+
scenario,
|
|
804
|
+
scenarioDir,
|
|
805
|
+
urls,
|
|
806
|
+
mode,
|
|
807
|
+
secure,
|
|
808
|
+
createAgentSession
|
|
809
|
+
});
|
|
810
|
+
await scenario.run(runContext);
|
|
811
|
+
metadata = buildScenarioMetadata({
|
|
812
|
+
artifactRoot,
|
|
813
|
+
gameId,
|
|
814
|
+
scenario,
|
|
815
|
+
mode,
|
|
816
|
+
urls: runContext.urls,
|
|
817
|
+
screenshotRecords: runContext.screenshotRecords,
|
|
818
|
+
notes: runContext.notes,
|
|
819
|
+
status: "captured",
|
|
820
|
+
error: null
|
|
821
|
+
});
|
|
822
|
+
} catch (error) {
|
|
823
|
+
scenarioError = error;
|
|
824
|
+
await captureFailureScreenshots(runContext);
|
|
825
|
+
runContext?.note(
|
|
826
|
+
"Scenario failed; best-effort failure screenshots were captured for the current host and controller state."
|
|
827
|
+
);
|
|
828
|
+
metadata = buildScenarioMetadata({
|
|
829
|
+
artifactRoot,
|
|
830
|
+
gameId,
|
|
831
|
+
scenario,
|
|
832
|
+
mode,
|
|
833
|
+
urls: runContext?.urls ?? urls,
|
|
834
|
+
screenshotRecords: runContext?.screenshotRecords ?? [],
|
|
835
|
+
notes: runContext?.notes ?? [],
|
|
836
|
+
status: "failed",
|
|
837
|
+
error
|
|
838
|
+
});
|
|
839
|
+
throw Object.assign(
|
|
840
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
841
|
+
{
|
|
842
|
+
visualMetadata: metadata
|
|
843
|
+
}
|
|
844
|
+
);
|
|
845
|
+
} finally {
|
|
846
|
+
if (!metadata) {
|
|
847
|
+
metadata = buildScenarioMetadata({
|
|
848
|
+
artifactRoot,
|
|
849
|
+
gameId,
|
|
850
|
+
scenario,
|
|
851
|
+
mode,
|
|
852
|
+
urls,
|
|
853
|
+
screenshotRecords: runContext?.screenshotRecords ?? [],
|
|
854
|
+
notes: runContext?.notes ?? [],
|
|
855
|
+
status: "failed",
|
|
856
|
+
error: scenarioError ?? new Error("Scenario setup failed before capture completed.")
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
writeJson(path2.join(scenarioDir, "metadata.json"), metadata);
|
|
860
|
+
if (runContext) {
|
|
861
|
+
await runContext.close();
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
return metadata;
|
|
865
|
+
};
|
|
866
|
+
var listScenarioIds = (scenarioPack) => scenarioPack.scenarios.map((scenario) => scenario.id);
|
|
867
|
+
var runVisualHarness = async ({
|
|
868
|
+
gameId,
|
|
869
|
+
scenarioId = null,
|
|
870
|
+
mode = "standalone-dev",
|
|
871
|
+
secure = false,
|
|
872
|
+
artifactRoot,
|
|
873
|
+
loadScenarioPack,
|
|
874
|
+
startStack,
|
|
875
|
+
createAgentSession,
|
|
876
|
+
onScenarioStart,
|
|
877
|
+
onCaptureStart,
|
|
878
|
+
onComplete
|
|
879
|
+
}) => {
|
|
880
|
+
if (mode !== "arcade-built" && mode !== "standalone-dev") {
|
|
881
|
+
throw new Error(
|
|
882
|
+
`Unsupported visual capture mode "${mode}". Phase 1 currently supports "standalone-dev" and "arcade-built".`
|
|
883
|
+
);
|
|
884
|
+
}
|
|
885
|
+
const scenarioPack = await loadScenarioPack(gameId);
|
|
886
|
+
const scenarios = scenarioId ? scenarioPack.scenarios.filter((scenario) => scenario.id === scenarioId) : scenarioPack.scenarios;
|
|
887
|
+
if (scenarios.length === 0) {
|
|
888
|
+
throw new Error(
|
|
889
|
+
`No visual capture scenario matched "${scenarioId}" for "${gameId}". Available scenarios: ${listScenarioIds(scenarioPack).join(", ")}`
|
|
890
|
+
);
|
|
891
|
+
}
|
|
892
|
+
const gameArtifactRoot = path2.join(artifactRoot, gameId);
|
|
893
|
+
if (!scenarioId) {
|
|
894
|
+
resetDir(gameArtifactRoot);
|
|
895
|
+
} else {
|
|
896
|
+
ensureDir(gameArtifactRoot);
|
|
897
|
+
}
|
|
898
|
+
fs2.rmSync(path2.join(gameArtifactRoot, "capture-summary.json"), {
|
|
899
|
+
force: true
|
|
900
|
+
});
|
|
901
|
+
const stack = await startStack({
|
|
902
|
+
gameId,
|
|
903
|
+
mode,
|
|
904
|
+
secure
|
|
905
|
+
});
|
|
906
|
+
const browser = await launchHarnessBrowser();
|
|
907
|
+
const results = [];
|
|
908
|
+
try {
|
|
909
|
+
onCaptureStart?.({
|
|
910
|
+
gameId,
|
|
911
|
+
mode,
|
|
912
|
+
scenarioCount: scenarios.length
|
|
913
|
+
});
|
|
914
|
+
for (const scenario of scenarios) {
|
|
915
|
+
onScenarioStart?.(scenario);
|
|
916
|
+
const metadata = await runScenarioCapture({
|
|
917
|
+
artifactRoot,
|
|
918
|
+
browser,
|
|
919
|
+
gameId,
|
|
920
|
+
scenario,
|
|
921
|
+
urls: stack.urls,
|
|
922
|
+
mode,
|
|
923
|
+
secure,
|
|
924
|
+
createAgentSession
|
|
925
|
+
});
|
|
926
|
+
results.push(metadata);
|
|
927
|
+
}
|
|
928
|
+
} finally {
|
|
929
|
+
await browser.close().catch(() => null);
|
|
930
|
+
await stack.shutdown();
|
|
931
|
+
}
|
|
932
|
+
const summary = {
|
|
933
|
+
gameId,
|
|
934
|
+
mode,
|
|
935
|
+
secure,
|
|
936
|
+
capturedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
937
|
+
scenarios: results.map((result) => ({
|
|
938
|
+
scenarioId: result.scenarioId,
|
|
939
|
+
status: result.status,
|
|
940
|
+
screenshotCount: result.screenshots.length,
|
|
941
|
+
relativeDir: path2.relative(
|
|
942
|
+
artifactRoot,
|
|
943
|
+
path2.join(artifactRoot, gameId, result.scenarioId)
|
|
944
|
+
)
|
|
945
|
+
}))
|
|
946
|
+
};
|
|
947
|
+
writeJson(path2.join(gameArtifactRoot, "capture-summary.json"), summary);
|
|
948
|
+
onComplete?.(summary);
|
|
949
|
+
return summary;
|
|
950
|
+
};
|
|
951
|
+
|
|
952
|
+
// src/harness/visual/scenario-contract.ts
|
|
953
|
+
var defineVisualScenarios = (pack) => pack;
|
|
954
|
+
|
|
955
|
+
// src/harness/visual/scenario-helpers.ts
|
|
956
|
+
import { fixedControllerOrientation as fixedControllerOrientation2 } from "@air-jam/sdk/metadata";
|
|
957
|
+
var STANDARD_HOST_VIEWPORTS = [
|
|
958
|
+
["mac-desktop", { width: 3016, height: 1504 }],
|
|
959
|
+
["desktop", { width: 1440, height: 1024 }],
|
|
960
|
+
["tablet", { width: 1024, height: 1180 }]
|
|
961
|
+
];
|
|
962
|
+
var STANDARD_CONTROLLER_VIEWPORTS = [
|
|
963
|
+
["mobile", { width: 390, height: 844 }],
|
|
964
|
+
["small-mobile", { width: 360, height: 640 }]
|
|
965
|
+
];
|
|
966
|
+
var STANDARD_CONTROLLER_LANDSCAPE_VIEWPORTS = [
|
|
967
|
+
["mobile", { width: 844, height: 390 }],
|
|
968
|
+
["small-mobile", { width: 640, height: 360 }]
|
|
969
|
+
];
|
|
970
|
+
var captureStandardSurfaces = async (context, options) => {
|
|
971
|
+
for (const [viewportName, viewport] of STANDARD_HOST_VIEWPORTS) {
|
|
972
|
+
await context.captureHost(viewportName, viewport);
|
|
973
|
+
}
|
|
974
|
+
await context.ensureControllerInteractive();
|
|
975
|
+
const controllerOrientation = fixedControllerOrientation2(context.inputModalities ?? []) ?? options?.controllerOrientation ?? "portrait";
|
|
976
|
+
const controllerViewports = controllerOrientation === "landscape" ? STANDARD_CONTROLLER_LANDSCAPE_VIEWPORTS : STANDARD_CONTROLLER_VIEWPORTS;
|
|
977
|
+
context.note(
|
|
978
|
+
`Captured controller surfaces in ${controllerOrientation} orientation.`
|
|
979
|
+
);
|
|
980
|
+
for (const [viewportName, viewport] of controllerViewports) {
|
|
981
|
+
await context.captureController(viewportName, viewport);
|
|
982
|
+
}
|
|
983
|
+
};
|
|
984
|
+
var waitForHostText = async (context, text, timeout = 3e4) => {
|
|
985
|
+
await context.host.game.getByText(text).first().waitFor({ state: "visible", timeout });
|
|
986
|
+
};
|
|
987
|
+
var waitForControllerText = async (context, text, timeout = 3e4) => {
|
|
988
|
+
await context.controller.game.getByText(text).first().waitFor({ state: "visible", timeout });
|
|
989
|
+
};
|
|
990
|
+
|
|
991
|
+
export {
|
|
992
|
+
definePrefabCaptureHarness,
|
|
993
|
+
installHarnessRuntimeTopology,
|
|
994
|
+
launchHarnessBrowser,
|
|
995
|
+
launchScopedHarnessBrowser,
|
|
996
|
+
DEFAULT_HOST_VIEWPORT,
|
|
997
|
+
DEFAULT_CONTROLLER_VIEWPORT,
|
|
998
|
+
dismissHarnessControllerFullscreenPrompt,
|
|
999
|
+
bindHarnessControllerUrl,
|
|
1000
|
+
openVisualHarnessHostSession,
|
|
1001
|
+
openVisualHarnessControllerSession,
|
|
1002
|
+
openVisualHarnessSession,
|
|
1003
|
+
loadPrefabCapture,
|
|
1004
|
+
capturePrefabAtRuntime,
|
|
1005
|
+
runVisualHarness,
|
|
1006
|
+
defineVisualScenarios,
|
|
1007
|
+
STANDARD_HOST_VIEWPORTS,
|
|
1008
|
+
STANDARD_CONTROLLER_VIEWPORTS,
|
|
1009
|
+
STANDARD_CONTROLLER_LANDSCAPE_VIEWPORTS,
|
|
1010
|
+
captureStandardSurfaces,
|
|
1011
|
+
waitForHostText,
|
|
1012
|
+
waitForControllerText
|
|
1013
|
+
};
|
|
1014
|
+
//# sourceMappingURL=chunk-O3XG3FNL.js.map
|