@air-jam/devtools 0.9.3 → 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/README.md +60 -0
- package/dist/{chunk-VKMJO6VN.js → chunk-2O67AXCU.js} +150 -40
- 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-CKFT2ZJE.js → chunk-MEIMOSZC.js} +53 -105
- package/dist/chunk-MEIMOSZC.js.map +1 -0
- package/dist/{chunk-GUEZP773.js → chunk-O3XG3FNL.js} +204 -41
- 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 +9 -3
- package/dist/context.js +2 -1
- package/dist/controller.d.ts +33 -7
- package/dist/controller.js +18 -8
- package/dist/dependencies.d.ts +44 -0
- package/dist/dependencies.js +10 -0
- package/dist/dev.d.ts +9 -3
- package/dist/dev.js +3 -4
- 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 -57
- package/dist/game-session-broker.js +33 -228
- package/dist/game-session-broker.js.map +1 -1
- package/dist/game-session.d.ts +3931 -10
- package/dist/game-session.js +186 -15
- package/dist/game-session.js.map +1 -1
- 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 +11 -4
- package/dist/games.js +4 -2
- package/dist/harness/visual.d.ts +34 -151
- package/dist/harness/visual.js +6 -1
- package/dist/logs.d.ts +8 -2
- package/dist/logs.js +3 -4
- package/dist/logs.js.map +1 -1
- package/dist/managed-process-scope-BicYi_t9.d.ts +3 -0
- package/dist/mcp-config.js +2 -1
- package/dist/mcp-config.js.map +1 -1
- package/dist/platform-auth.d.ts +8 -111
- package/dist/platform-auth.js +9 -1
- 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 +40 -2
- package/dist/platform-game-media.js +1 -1
- package/dist/platform-games.d.ts +24 -2
- package/dist/platform-games.js +16 -84
- package/dist/platform-games.js.map +1 -1
- package/dist/quality.d.ts +9 -3
- package/dist/quality.js +3 -4
- package/dist/quality.js.map +1 -1
- package/dist/release.d.ts +226 -16
- package/dist/release.js +18 -1331
- package/dist/release.js.map +1 -1
- 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.js +54 -0
- package/dist/tooling/describe-game.js.map +1 -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.js +769 -67
- package/dist/tooling/hold-runtime-host.js.map +1 -1
- package/dist/tooling/list-visual-scenarios.js +18 -55
- package/dist/tooling/list-visual-scenarios.js.map +1 -1
- 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.js +70 -34
- package/dist/tooling/run-visual-capture.js.map +1 -1
- 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-C6NrHt88.d.ts → types-CdYrgrG_.d.ts} +337 -76
- package/dist/types-DyRD-ym1.d.ts +141 -0
- package/dist/visual.d.ts +9 -3
- package/dist/visual.js +24 -68
- package/dist/visual.js.map +1 -1
- package/package.json +51 -14
- package/src/bounded-response.ts +28 -0
- package/src/built-game-runtime.ts +152 -0
- package/src/context.ts +2 -13
- package/src/controller-protocol.ts +22 -0
- package/src/controller.ts +747 -597
- 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 +46 -50
- package/src/game-action-observation.ts +11 -1
- 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 +689 -197
- 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 +164 -417
- package/src/game-settings.ts +295 -0
- package/src/games.ts +88 -92
- package/src/harness/visual/browser.ts +100 -0
- package/src/harness/visual/controller-observation.ts +181 -0
- package/src/harness/visual/runner.ts +24 -21
- package/src/harness/visual/runtime-controller-observations.ts +151 -0
- package/src/harness/visual/scenario-contract.ts +1 -2
- package/src/harness/visual/scenario-helpers.ts +5 -1
- package/src/harness/visual/screencast.ts +155 -0
- package/src/harness/visual/session.ts +72 -41
- package/src/harness/visual/types.ts +8 -5
- 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 +25 -5
- package/src/installed-dependencies.ts +74 -0
- package/src/managed-process-scope.ts +481 -0
- package/src/node-process-environment.ts +10 -0
- package/src/platform-auth.ts +194 -55
- package/src/platform-game-analytics.ts +50 -0
- package/src/platform-game-app-id.ts +99 -0
- package/src/platform-games.ts +13 -111
- 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/release.ts +28 -42
- 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 +106 -18
- 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 +255 -38
- package/src/tooling/list-visual-scenarios.ts +19 -62
- package/src/tooling/load-game.ts +79 -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 +37 -23
- package/src/tooling/runtime-owner-actions.ts +23 -0
- package/src/tooling/seal-game-build.ts +118 -0
- package/src/tooling/visual-pack.ts +10 -45
- package/src/types.ts +54 -77
- package/src/visual.ts +14 -22
- package/src/windows-process-scopes.ts +189 -0
- package/dist/agent.d.ts +0 -15
- package/dist/agent.js +0 -19
- package/dist/chunk-5YAARMW5.js +0 -36
- package/dist/chunk-5YAARMW5.js.map +0 -1
- package/dist/chunk-6WQODT37.js +0 -1019
- package/dist/chunk-6WQODT37.js.map +0 -1
- package/dist/chunk-CKFT2ZJE.js.map +0 -1
- package/dist/chunk-ER3Q2C4G.js +0 -358
- package/dist/chunk-ER3Q2C4G.js.map +0 -1
- package/dist/chunk-GUEZP773.js.map +0 -1
- package/dist/chunk-HIDNI56E.js +0 -33
- package/dist/chunk-HIDNI56E.js.map +0 -1
- package/dist/chunk-QKXS5D35.js +0 -43
- package/dist/chunk-QKXS5D35.js.map +0 -1
- package/dist/chunk-S4LSCEVE.js +0 -261
- package/dist/chunk-S4LSCEVE.js.map +0 -1
- package/dist/chunk-VKMJO6VN.js.map +0 -1
- package/dist/chunk-WFUR3MXY.js +0 -67
- package/dist/chunk-WFUR3MXY.js.map +0 -1
- package/dist/chunk-XEMR7KUE.js +0 -361
- package/dist/chunk-XEMR7KUE.js.map +0 -1
- package/dist/chunk-ZLPD7FY5.js +0 -191
- package/dist/chunk-ZLPD7FY5.js.map +0 -1
- package/dist/tooling/agent-contract.js +0 -193
- package/dist/tooling/agent-contract.js.map +0 -1
- package/dist/tooling/inspect-airjam-agent.js +0 -37
- package/dist/tooling/inspect-airjam-agent.js.map +0 -1
- package/src/agent.ts +0 -380
- package/src/tooling/agent-contract.ts +0 -232
- package/src/tooling/agent-declaration.ts +0 -36
- package/src/tooling/airjam-agent-inspection.ts +0 -45
- package/src/tooling/airjam-agent.ts +0 -118
- package/src/tooling/inspect-airjam-agent.ts +0 -20
- /package/dist/{agent.js.map → dependencies.js.map} +0 -0
- /package/dist/tooling/{agent-contract.d.ts → describe-game.d.ts} +0 -0
- /package/dist/tooling/{inspect-airjam-agent.d.ts → game-session-broker.d.ts} +0 -0
|
@@ -0,0 +1,717 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_ROOMS_CHECK_SCENARIOS,
|
|
3
|
+
ROOMS_CHECK_SCENARIOS,
|
|
4
|
+
describeLinkProblem,
|
|
5
|
+
deviceEventSchema,
|
|
6
|
+
sharedNow,
|
|
7
|
+
summarizeLatency
|
|
8
|
+
} from "./chunk-GDFAWHGA.js";
|
|
9
|
+
import {
|
|
10
|
+
resolveDevtoolsHelperArgs,
|
|
11
|
+
resolveDevtoolsHelperScript
|
|
12
|
+
} from "./chunk-PKD4WVX5.js";
|
|
13
|
+
|
|
14
|
+
// src/rooms-check.ts
|
|
15
|
+
import { createRoomKey } from "@air-jam/sdk/room-session";
|
|
16
|
+
import { availableParallelism } from "os";
|
|
17
|
+
|
|
18
|
+
// src/rooms-check-fleet.ts
|
|
19
|
+
import { spawn } from "child_process";
|
|
20
|
+
var ScenarioFailure = class extends Error {
|
|
21
|
+
};
|
|
22
|
+
var isOpen = (event) => event.type === "status" && event.status.phase === "open";
|
|
23
|
+
var ConnectionPacer = class {
|
|
24
|
+
constructor(perMinute, now = sharedNow) {
|
|
25
|
+
this.now = now;
|
|
26
|
+
this.spacingMs = Math.floor(6e4 / Math.max(perMinute - 1, 1)) + 1;
|
|
27
|
+
}
|
|
28
|
+
spacingMs;
|
|
29
|
+
next = Number.NEGATIVE_INFINITY;
|
|
30
|
+
/** Reserves the next open and returns when it may happen. */
|
|
31
|
+
reserve() {
|
|
32
|
+
const slot = Math.max(this.now(), this.next);
|
|
33
|
+
this.next = slot + this.spacingMs;
|
|
34
|
+
return slot;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var Device = class {
|
|
38
|
+
constructor(name, child, pacer) {
|
|
39
|
+
this.name = name;
|
|
40
|
+
this.child = child;
|
|
41
|
+
child.on("message", (message) => {
|
|
42
|
+
const event = deviceEventSchema.parse(message);
|
|
43
|
+
if (event.type === "dial") {
|
|
44
|
+
const grant = () => {
|
|
45
|
+
if (child.connected) child.send({ type: "dial", id: event.id });
|
|
46
|
+
};
|
|
47
|
+
if (pacer) setTimeout(grant, pacer.reserve() - sharedNow());
|
|
48
|
+
else grant();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
this.events.push(event);
|
|
52
|
+
for (const waiter of [...this.waiters]) waiter();
|
|
53
|
+
});
|
|
54
|
+
child.on("exit", () => {
|
|
55
|
+
this.exited = true;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
events = [];
|
|
59
|
+
waiters = /* @__PURE__ */ new Set();
|
|
60
|
+
exited = false;
|
|
61
|
+
send(command) {
|
|
62
|
+
this.child.send(command);
|
|
63
|
+
}
|
|
64
|
+
freeze() {
|
|
65
|
+
this.child.kill("SIGSTOP");
|
|
66
|
+
}
|
|
67
|
+
thaw() {
|
|
68
|
+
this.child.kill("SIGCONT");
|
|
69
|
+
}
|
|
70
|
+
kill() {
|
|
71
|
+
if (this.exited) return;
|
|
72
|
+
this.child.kill("SIGCONT");
|
|
73
|
+
this.child.kill("SIGKILL");
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The first event since `since` that `find` accepts, or a failure naming
|
|
77
|
+
* `what`; a device that reports it failed fails whatever waits on it.
|
|
78
|
+
*/
|
|
79
|
+
until(find, what, deadlineMs, since = 0) {
|
|
80
|
+
const search = () => {
|
|
81
|
+
for (const event of this.events)
|
|
82
|
+
if (event.at >= since) {
|
|
83
|
+
if (event.type === "failed") return { failed: event.message };
|
|
84
|
+
const found = find(event);
|
|
85
|
+
if (found !== void 0) return { found };
|
|
86
|
+
}
|
|
87
|
+
return void 0;
|
|
88
|
+
};
|
|
89
|
+
return new Promise((resolve, reject) => {
|
|
90
|
+
const check = () => {
|
|
91
|
+
const outcome = search();
|
|
92
|
+
if (outcome === void 0) return;
|
|
93
|
+
clearTimeout(timer);
|
|
94
|
+
this.waiters.delete(check);
|
|
95
|
+
if ("found" in outcome) resolve(outcome.found);
|
|
96
|
+
else reject(new ScenarioFailure(`${this.name}: ${outcome.failed}`));
|
|
97
|
+
};
|
|
98
|
+
const timer = setTimeout(() => {
|
|
99
|
+
this.waiters.delete(check);
|
|
100
|
+
reject(
|
|
101
|
+
new ScenarioFailure(
|
|
102
|
+
`${this.name}: ${what} did not happen within ${deadlineMs} ms.`
|
|
103
|
+
)
|
|
104
|
+
);
|
|
105
|
+
}, deadlineMs);
|
|
106
|
+
this.waiters.add(check);
|
|
107
|
+
check();
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
since(type, from = 0, to = Number.POSITIVE_INFINITY) {
|
|
111
|
+
return this.events.filter(
|
|
112
|
+
(event) => event.type === type && event.at >= from && event.at <= to
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
var Fleet = class {
|
|
117
|
+
constructor(target, pacer) {
|
|
118
|
+
this.pacer = pacer;
|
|
119
|
+
this.link = target.link;
|
|
120
|
+
this.hostCredentialCommand = target.hostCredentialCommand;
|
|
121
|
+
}
|
|
122
|
+
devices = [];
|
|
123
|
+
script = resolveDevtoolsHelperScript(
|
|
124
|
+
"rooms-check-device.ts"
|
|
125
|
+
);
|
|
126
|
+
link;
|
|
127
|
+
hostCredentialCommand;
|
|
128
|
+
device(name) {
|
|
129
|
+
const child = spawn(
|
|
130
|
+
process.execPath,
|
|
131
|
+
resolveDevtoolsHelperArgs(this.script),
|
|
132
|
+
{
|
|
133
|
+
stdio: ["ignore", "ignore", "inherit", "ipc"]
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
const device = new Device(name, child, this.pacer);
|
|
137
|
+
this.devices.push(device);
|
|
138
|
+
return device;
|
|
139
|
+
}
|
|
140
|
+
/** Every connection problem the devices reported, timed from `startedAt`. */
|
|
141
|
+
problems(startedAt) {
|
|
142
|
+
return this.devices.flatMap(
|
|
143
|
+
(device) => device.since("problem").map((event) => ({
|
|
144
|
+
device: device.name,
|
|
145
|
+
atMs: Math.round(event.at - startedAt),
|
|
146
|
+
problem: event.problem
|
|
147
|
+
}))
|
|
148
|
+
).sort((left, right) => left.atMs - right.atMs);
|
|
149
|
+
}
|
|
150
|
+
close() {
|
|
151
|
+
for (const device of this.devices) device.kill();
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// src/rooms-check.ts
|
|
156
|
+
var PRESS_COUNTER_SIZE = 128;
|
|
157
|
+
var OPEN_DEADLINE_MS = 15e3;
|
|
158
|
+
var GRANT_DEADLINE_MS = 30 * 6e4;
|
|
159
|
+
var WIRE_FRAMING_BYTES = 78;
|
|
160
|
+
var HOUR_MS = 36e5;
|
|
161
|
+
var dialed = (device) => device.until(
|
|
162
|
+
(event) => event.type === "dialing" ? event.at : void 0,
|
|
163
|
+
"dialing",
|
|
164
|
+
GRANT_DEADLINE_MS
|
|
165
|
+
);
|
|
166
|
+
var firstOpen = async (device, what) => {
|
|
167
|
+
const dialedAt = await dialed(device);
|
|
168
|
+
const outcome = await device.until(
|
|
169
|
+
(event) => event.type === "status" && (event.status.phase === "open" || event.status.phase === "closed") ? event : void 0,
|
|
170
|
+
what,
|
|
171
|
+
OPEN_DEADLINE_MS
|
|
172
|
+
);
|
|
173
|
+
if (outcome.status.phase === "closed")
|
|
174
|
+
throw new ScenarioFailure(
|
|
175
|
+
`${device.name}: ${what} ended with the room closing it as ${outcome.status.reason}.`
|
|
176
|
+
);
|
|
177
|
+
return { opened: outcome, openMs: outcome.at - dialedAt };
|
|
178
|
+
};
|
|
179
|
+
var field = (value, what) => {
|
|
180
|
+
if (value === void 0)
|
|
181
|
+
throw new ScenarioFailure(`The room did not report its ${what}.`);
|
|
182
|
+
return value;
|
|
183
|
+
};
|
|
184
|
+
var joinPhone = async (fleet, name, room, options) => {
|
|
185
|
+
const device = fleet.device(name);
|
|
186
|
+
const key = options.key ?? createRoomKey();
|
|
187
|
+
device.send({
|
|
188
|
+
type: "phone",
|
|
189
|
+
link: fleet.link,
|
|
190
|
+
key,
|
|
191
|
+
code: room.code,
|
|
192
|
+
instance: options.instance,
|
|
193
|
+
inputsPerSecond: options.inputsPerSecond
|
|
194
|
+
});
|
|
195
|
+
const { opened, openMs } = await firstOpen(device, "joining");
|
|
196
|
+
return {
|
|
197
|
+
device,
|
|
198
|
+
key,
|
|
199
|
+
seat: field(opened.seat, "seat"),
|
|
200
|
+
instance: field(opened.instance, "instance"),
|
|
201
|
+
joinMs: openMs
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
var openRoom = async (fleet, options) => {
|
|
205
|
+
const host = fleet.device("host");
|
|
206
|
+
const hostKey = createRoomKey();
|
|
207
|
+
host.send({
|
|
208
|
+
type: "host",
|
|
209
|
+
link: fleet.link,
|
|
210
|
+
credentialCommand: fleet.hostCredentialCommand,
|
|
211
|
+
key: hostKey,
|
|
212
|
+
seats: Math.max(options.phones, 2),
|
|
213
|
+
statesPerSecond: options.statesPerSecond ?? 0,
|
|
214
|
+
heartbeat: options.hostHeartbeat ?? true
|
|
215
|
+
});
|
|
216
|
+
const { opened, openMs } = await firstOpen(host, "opening the room");
|
|
217
|
+
const code = field(opened.code, "code");
|
|
218
|
+
const joined = await Promise.all(
|
|
219
|
+
Array.from(
|
|
220
|
+
{ length: options.phones },
|
|
221
|
+
(_, index) => joinPhone(
|
|
222
|
+
fleet,
|
|
223
|
+
`phone ${index + 1}`,
|
|
224
|
+
{ code },
|
|
225
|
+
{
|
|
226
|
+
inputsPerSecond: options.inputsPerSecond ?? 30
|
|
227
|
+
}
|
|
228
|
+
)
|
|
229
|
+
)
|
|
230
|
+
);
|
|
231
|
+
return {
|
|
232
|
+
host,
|
|
233
|
+
hostKey,
|
|
234
|
+
code,
|
|
235
|
+
instance: field(opened.instance, "instance"),
|
|
236
|
+
hostGraceMs: field(opened.hostGraceMs, "host grace"),
|
|
237
|
+
openMs,
|
|
238
|
+
phones: joined,
|
|
239
|
+
joinMs: joined.map((phone) => phone.joinMs)
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
var wait = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
243
|
+
var sameCount = (left, right) => left % PRESS_COUNTER_SIZE === right % PRESS_COUNTER_SIZE;
|
|
244
|
+
var measureInput = (host, phones, from, to) => {
|
|
245
|
+
const latencies = [];
|
|
246
|
+
let pressed = 0;
|
|
247
|
+
let lost = 0;
|
|
248
|
+
for (const phone of phones) {
|
|
249
|
+
const received = host.since("received", from).filter((event) => event.seat === phone.seat);
|
|
250
|
+
for (const press of phone.device.since("pressed", from, to)) {
|
|
251
|
+
pressed += 1;
|
|
252
|
+
const arrival = received.find(
|
|
253
|
+
(event) => event.at >= press.at && event.at - press.at < 1e3 && sameCount(event.presses, press.presses)
|
|
254
|
+
);
|
|
255
|
+
if (arrival) latencies.push(arrival.at - press.at);
|
|
256
|
+
else lost += 1;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return { pressed, lost, latency: summarizeLatency(latencies) };
|
|
260
|
+
};
|
|
261
|
+
var measureState = (host, phones, from) => {
|
|
262
|
+
const published = new Map(
|
|
263
|
+
host.since("published", from).map((event) => [event.tick, event.at])
|
|
264
|
+
);
|
|
265
|
+
return summarizeLatency(
|
|
266
|
+
phones.flatMap(
|
|
267
|
+
(phone) => phone.device.since("state", from).flatMap((event) => {
|
|
268
|
+
const at = published.get(event.tick);
|
|
269
|
+
return at === void 0 ? [] : [event.at - at];
|
|
270
|
+
})
|
|
271
|
+
)
|
|
272
|
+
);
|
|
273
|
+
};
|
|
274
|
+
var requireState = (host, phones, from, to) => {
|
|
275
|
+
const settled = host.since("published", from).filter((event) => event.at <= to).at(-1);
|
|
276
|
+
if (!settled) throw new ScenarioFailure("The host published no state.");
|
|
277
|
+
const behind = phones.filter(
|
|
278
|
+
(phone) => !phone.device.since("state", from).some((event) => event.tick >= settled.tick)
|
|
279
|
+
).length;
|
|
280
|
+
if (behind > 0)
|
|
281
|
+
throw new ScenarioFailure(
|
|
282
|
+
`${behind} of ${phones.length} phones never saw the host's state.`
|
|
283
|
+
);
|
|
284
|
+
};
|
|
285
|
+
var firstInputAfter = (host, seat, after) => host.until(
|
|
286
|
+
(event) => event.type === "received" && (seat === null || event.seat === seat) ? event.at : void 0,
|
|
287
|
+
"an input arriving",
|
|
288
|
+
OPEN_DEADLINE_MS,
|
|
289
|
+
after
|
|
290
|
+
);
|
|
291
|
+
var seatDropped = (host, seat, from) => host.since("seats", from).some(
|
|
292
|
+
(event) => event.seats.some((view) => view.id === seat && !view.connected)
|
|
293
|
+
);
|
|
294
|
+
var scenarios = {
|
|
295
|
+
/** The smallest room: a host and one phone, input one way and state the other. */
|
|
296
|
+
join: async ({ fleet }) => {
|
|
297
|
+
const room = await openRoom(fleet, { phones: 1, statesPerSecond: 20 });
|
|
298
|
+
const from = sharedNow();
|
|
299
|
+
await wait(2e3);
|
|
300
|
+
const to = sharedNow() - 500;
|
|
301
|
+
const input = measureInput(room.host, room.phones, from, to);
|
|
302
|
+
if (input.pressed === 0 || input.lost > 0)
|
|
303
|
+
throw new ScenarioFailure(
|
|
304
|
+
`${input.lost} of ${input.pressed} presses never reached the host.`
|
|
305
|
+
);
|
|
306
|
+
requireState(room.host, room.phones, from, to);
|
|
307
|
+
return {
|
|
308
|
+
roomOpenMs: room.openMs,
|
|
309
|
+
phoneJoinMs: room.joinMs[0],
|
|
310
|
+
input: input.latency,
|
|
311
|
+
state: measureState(room.host, room.phones, from)
|
|
312
|
+
};
|
|
313
|
+
},
|
|
314
|
+
/** A phone locked for a moment keeps its seat and its link. */
|
|
315
|
+
"phone-brief-freeze": async ({ fleet, options }) => {
|
|
316
|
+
const room = await openRoom(fleet, { phones: 1 });
|
|
317
|
+
const [phone] = room.phones;
|
|
318
|
+
if (!phone) throw new ScenarioFailure("No phone joined.");
|
|
319
|
+
const frozenAt = sharedNow();
|
|
320
|
+
phone.device.freeze();
|
|
321
|
+
await wait(options.briefFreezeMs);
|
|
322
|
+
const thawedAt = sharedNow();
|
|
323
|
+
phone.device.thaw();
|
|
324
|
+
const arrived = await firstInputAfter(room.host, phone.seat, thawedAt);
|
|
325
|
+
if (seatDropped(room.host, phone.seat, frozenAt))
|
|
326
|
+
throw new ScenarioFailure(
|
|
327
|
+
`The host saw the seat drop during a ${options.briefFreezeMs} ms lock.`
|
|
328
|
+
);
|
|
329
|
+
return {
|
|
330
|
+
freezeMs: options.briefFreezeMs,
|
|
331
|
+
thawToInputMs: arrived - thawedAt
|
|
332
|
+
};
|
|
333
|
+
},
|
|
334
|
+
/** A phone locked past the server's liveness window gets its seat back on waking. */
|
|
335
|
+
"phone-long-freeze": async ({ fleet }) => {
|
|
336
|
+
const room = await openRoom(fleet, { phones: 1 });
|
|
337
|
+
const [phone] = room.phones;
|
|
338
|
+
if (!phone) throw new ScenarioFailure("No phone joined.");
|
|
339
|
+
const frozenAt = sharedNow();
|
|
340
|
+
phone.device.freeze();
|
|
341
|
+
const droppedAt = await room.host.until(
|
|
342
|
+
(event) => event.type === "seats" && event.seats.some((view) => view.id === phone.seat && !view.connected) ? event.at : void 0,
|
|
343
|
+
"the server noticing the silent phone",
|
|
344
|
+
12e4,
|
|
345
|
+
frozenAt
|
|
346
|
+
);
|
|
347
|
+
const thawedAt = sharedNow();
|
|
348
|
+
phone.device.thaw();
|
|
349
|
+
const reopened = await phone.device.until(
|
|
350
|
+
(event) => isOpen(event) ? event : void 0,
|
|
351
|
+
"rejoining",
|
|
352
|
+
OPEN_DEADLINE_MS,
|
|
353
|
+
thawedAt
|
|
354
|
+
);
|
|
355
|
+
if (reopened.seat !== phone.seat)
|
|
356
|
+
throw new ScenarioFailure(
|
|
357
|
+
`The phone came back as ${reopened.seat}, not ${phone.seat}.`
|
|
358
|
+
);
|
|
359
|
+
const arrived = await firstInputAfter(room.host, phone.seat, thawedAt);
|
|
360
|
+
return {
|
|
361
|
+
silenceNoticedMs: droppedAt - frozenAt,
|
|
362
|
+
thawToRejoinMs: reopened.at - thawedAt,
|
|
363
|
+
thawToInputMs: arrived - thawedAt
|
|
364
|
+
};
|
|
365
|
+
},
|
|
366
|
+
/** Wi-Fi to cellular: a new link with the key takes the seat at once; the dead one stays out. */
|
|
367
|
+
"network-switch": async ({ fleet }) => {
|
|
368
|
+
const room = await openRoom(fleet, { phones: 1 });
|
|
369
|
+
const [wifi] = room.phones;
|
|
370
|
+
if (!wifi) throw new ScenarioFailure("No phone joined.");
|
|
371
|
+
wifi.device.freeze();
|
|
372
|
+
const cellular = await joinPhone(fleet, "phone on cellular", room, {
|
|
373
|
+
key: wifi.key,
|
|
374
|
+
instance: wifi.instance,
|
|
375
|
+
inputsPerSecond: 30
|
|
376
|
+
});
|
|
377
|
+
if (cellular.seat !== wifi.seat)
|
|
378
|
+
throw new ScenarioFailure(
|
|
379
|
+
`The new link took ${cellular.seat}, not ${wifi.seat}.`
|
|
380
|
+
);
|
|
381
|
+
const takenAt = sharedNow();
|
|
382
|
+
wifi.device.thaw();
|
|
383
|
+
await wifi.device.until(
|
|
384
|
+
(event) => event.type === "status" && event.status.phase === "closed" && event.status.reason === "replaced" ? true : void 0,
|
|
385
|
+
"the old link stopping as replaced",
|
|
386
|
+
OPEN_DEADLINE_MS,
|
|
387
|
+
takenAt
|
|
388
|
+
);
|
|
389
|
+
await wait(2e3);
|
|
390
|
+
if (seatDropped(room.host, wifi.seat, takenAt))
|
|
391
|
+
throw new ScenarioFailure("The seat changed hands back and forth.");
|
|
392
|
+
await firstInputAfter(room.host, wifi.seat, sharedNow() - 1e3);
|
|
393
|
+
return { takeoverMs: cellular.joinMs };
|
|
394
|
+
},
|
|
395
|
+
/**
|
|
396
|
+
* A phone's network stalls while its player keeps pressing; when it
|
|
397
|
+
* returns, the backlog arrives in one burst. The phone keeps its link and
|
|
398
|
+
* seat, and its input flows again.
|
|
399
|
+
*/
|
|
400
|
+
"network-stall": async ({ fleet, options }) => {
|
|
401
|
+
const room = await openRoom(fleet, { phones: 1, inputsPerSecond: 60 });
|
|
402
|
+
const [phone] = room.phones;
|
|
403
|
+
if (!phone) throw new ScenarioFailure("No phone joined.");
|
|
404
|
+
const stalledAt = sharedNow();
|
|
405
|
+
phone.device.send({ type: "network", stalled: true });
|
|
406
|
+
await wait(options.stallMs);
|
|
407
|
+
const resumedAt = sharedNow();
|
|
408
|
+
phone.device.send({ type: "network", stalled: false });
|
|
409
|
+
const arrived = await firstInputAfter(room.host, phone.seat, resumedAt);
|
|
410
|
+
await wait(3e3);
|
|
411
|
+
const lostLink = phone.device.since("status", stalledAt).find((event) => event.status.phase !== "open");
|
|
412
|
+
if (lostLink)
|
|
413
|
+
throw new ScenarioFailure(
|
|
414
|
+
`The phone went ${lostLink.status.phase}${lostLink.status.reason ? ` (${lostLink.status.reason})` : ""} after a ${options.stallMs} ms stall.`
|
|
415
|
+
);
|
|
416
|
+
if (seatDropped(room.host, phone.seat, stalledAt))
|
|
417
|
+
throw new ScenarioFailure("The host saw the seat drop during the stall.");
|
|
418
|
+
const input = measureInput(
|
|
419
|
+
room.host,
|
|
420
|
+
[phone],
|
|
421
|
+
resumedAt + 1500,
|
|
422
|
+
sharedNow() - 500
|
|
423
|
+
);
|
|
424
|
+
if (input.pressed === 0 || input.lost > 0)
|
|
425
|
+
throw new ScenarioFailure(
|
|
426
|
+
`${input.lost} of ${input.pressed} presses after the stall never reached the host.`
|
|
427
|
+
);
|
|
428
|
+
return {
|
|
429
|
+
stallMs: options.stallMs,
|
|
430
|
+
resumeToInputMs: arrived - resumedAt,
|
|
431
|
+
inputAfter: input.latency
|
|
432
|
+
};
|
|
433
|
+
},
|
|
434
|
+
/** Two tabs join with one key at once: one seat, and the older tab stops. */
|
|
435
|
+
"duplicate-join": async ({ fleet }) => {
|
|
436
|
+
const room = await openRoom(fleet, { phones: 0 });
|
|
437
|
+
const key = createRoomKey();
|
|
438
|
+
const tabs = ["tab 1", "tab 2"].map((name) => {
|
|
439
|
+
const device = fleet.device(name);
|
|
440
|
+
device.send({
|
|
441
|
+
type: "phone",
|
|
442
|
+
link: fleet.link,
|
|
443
|
+
key,
|
|
444
|
+
code: room.code,
|
|
445
|
+
inputsPerSecond: 0
|
|
446
|
+
});
|
|
447
|
+
return device;
|
|
448
|
+
});
|
|
449
|
+
await Promise.all(tabs.map(dialed));
|
|
450
|
+
const outcomes = await Promise.all(
|
|
451
|
+
tabs.map(
|
|
452
|
+
(tab) => tab.until(
|
|
453
|
+
(event) => event.type === "status" && event.status.phase === "closed" ? event.status.reason ?? "closed" : void 0,
|
|
454
|
+
"one tab replacing the other",
|
|
455
|
+
3e3
|
|
456
|
+
).catch(() => "open")
|
|
457
|
+
)
|
|
458
|
+
);
|
|
459
|
+
const seats = room.host.since("seats").at(-1)?.seats ?? [];
|
|
460
|
+
if (outcomes.filter((outcome) => outcome === "open").length !== 1 || !outcomes.includes("replaced"))
|
|
461
|
+
throw new ScenarioFailure(`The tabs ended ${outcomes.join(" and ")}.`);
|
|
462
|
+
if (seats.length !== 1 || !seats[0]?.connected)
|
|
463
|
+
throw new ScenarioFailure(`The host saw ${seats.length} seats.`);
|
|
464
|
+
return { seats: seats.length };
|
|
465
|
+
},
|
|
466
|
+
/** A host that reloads within its grace gets its room, seats and input back. */
|
|
467
|
+
"host-reload": async ({ fleet }) => {
|
|
468
|
+
const room = await openRoom(fleet, { phones: 2 });
|
|
469
|
+
const killedAt = sharedNow();
|
|
470
|
+
room.host.kill();
|
|
471
|
+
await Promise.all(
|
|
472
|
+
room.phones.map(
|
|
473
|
+
(phone) => phone.device.until(
|
|
474
|
+
(event) => event.type === "host" && !event.present ? true : void 0,
|
|
475
|
+
"seeing the screen go away",
|
|
476
|
+
OPEN_DEADLINE_MS,
|
|
477
|
+
killedAt
|
|
478
|
+
)
|
|
479
|
+
)
|
|
480
|
+
);
|
|
481
|
+
const reloaded = fleet.device("reloaded host");
|
|
482
|
+
reloaded.send({
|
|
483
|
+
type: "host",
|
|
484
|
+
link: fleet.link,
|
|
485
|
+
credentialCommand: fleet.hostCredentialCommand,
|
|
486
|
+
key: room.hostKey,
|
|
487
|
+
code: room.code,
|
|
488
|
+
instance: room.instance,
|
|
489
|
+
seats: 2,
|
|
490
|
+
statesPerSecond: 0,
|
|
491
|
+
heartbeat: true
|
|
492
|
+
});
|
|
493
|
+
const { opened } = await firstOpen(reloaded, "reclaiming the room");
|
|
494
|
+
if (opened.code !== room.code)
|
|
495
|
+
throw new ScenarioFailure(`The host came back to ${opened.code}.`);
|
|
496
|
+
const seats = await reloaded.until(
|
|
497
|
+
(event) => event.type === "seats" ? event.seats : void 0,
|
|
498
|
+
"seeing the seats",
|
|
499
|
+
OPEN_DEADLINE_MS
|
|
500
|
+
);
|
|
501
|
+
if (seats.length !== 2)
|
|
502
|
+
throw new ScenarioFailure(
|
|
503
|
+
`The reloaded host found ${seats.length} seats.`
|
|
504
|
+
);
|
|
505
|
+
const arrived = await firstInputAfter(reloaded, null, opened.at);
|
|
506
|
+
return {
|
|
507
|
+
killToReclaimMs: opened.at - killedAt,
|
|
508
|
+
killToInputMs: arrived - killedAt
|
|
509
|
+
};
|
|
510
|
+
},
|
|
511
|
+
/** A host gone past its grace ends the room, and its phones stop for good. */
|
|
512
|
+
"host-gone": async ({ fleet }) => {
|
|
513
|
+
const room = await openRoom(fleet, { phones: 1 });
|
|
514
|
+
const [phone] = room.phones;
|
|
515
|
+
if (!phone) throw new ScenarioFailure("No phone joined.");
|
|
516
|
+
const killedAt = sharedNow();
|
|
517
|
+
room.host.kill();
|
|
518
|
+
const closedAt = await phone.device.until(
|
|
519
|
+
(event) => event.type === "status" && event.status.phase === "closed" && event.status.reason === "closed" ? event.at : void 0,
|
|
520
|
+
"the room closing",
|
|
521
|
+
room.hostGraceMs + OPEN_DEADLINE_MS,
|
|
522
|
+
killedAt
|
|
523
|
+
);
|
|
524
|
+
return {
|
|
525
|
+
hostGraceMs: room.hostGraceMs,
|
|
526
|
+
killToClosedMs: closedAt - killedAt
|
|
527
|
+
};
|
|
528
|
+
},
|
|
529
|
+
/** A hidden host tab sends no pings of its own; the server's keep it, idle or not. */
|
|
530
|
+
"background-host": async ({ fleet, options }) => {
|
|
531
|
+
const room = await openRoom(fleet, {
|
|
532
|
+
phones: 1,
|
|
533
|
+
inputsPerSecond: 0,
|
|
534
|
+
hostHeartbeat: false
|
|
535
|
+
});
|
|
536
|
+
const [phone] = room.phones;
|
|
537
|
+
if (!phone) throw new ScenarioFailure("No phone joined.");
|
|
538
|
+
const idleFrom = sharedNow();
|
|
539
|
+
await wait(options.idleMs);
|
|
540
|
+
const tappedAt = sharedNow();
|
|
541
|
+
phone.device.send({ type: "press" });
|
|
542
|
+
const arrived = await firstInputAfter(room.host, phone.seat, tappedAt);
|
|
543
|
+
const away = phone.device.since("host", idleFrom).some((event) => !event.present);
|
|
544
|
+
if (away) throw new ScenarioFailure("The idle host was dropped.");
|
|
545
|
+
return { idleMs: options.idleMs, tapToHostMs: arrived - tappedAt };
|
|
546
|
+
},
|
|
547
|
+
/** Sixteen phones at 30 Hz and a host publishing at 20 Hz. */
|
|
548
|
+
crowd: async ({ fleet, options }) => {
|
|
549
|
+
const room = await openRoom(fleet, { phones: 16, statesPerSecond: 20 });
|
|
550
|
+
const from = sharedNow();
|
|
551
|
+
await wait(options.crowdDurationMs);
|
|
552
|
+
const to = sharedNow() - 500;
|
|
553
|
+
const input = measureInput(room.host, room.phones, from, to);
|
|
554
|
+
if (input.lost > 0)
|
|
555
|
+
throw new ScenarioFailure(
|
|
556
|
+
`${input.lost} of ${input.pressed} presses never reached the host.`
|
|
557
|
+
);
|
|
558
|
+
requireState(room.host, room.phones, from, to);
|
|
559
|
+
return {
|
|
560
|
+
phoneJoinMs: summarizeLatency(room.joinMs),
|
|
561
|
+
input: input.latency,
|
|
562
|
+
state: measureState(room.host, room.phones, from)
|
|
563
|
+
};
|
|
564
|
+
},
|
|
565
|
+
/** Many rooms at once: the numbers a hosting decision needs. */
|
|
566
|
+
load: async ({ fleet, options }) => {
|
|
567
|
+
const { rooms, phonesPerRoom, durationMs, workers } = options.load;
|
|
568
|
+
const shares = Array.from(
|
|
569
|
+
{ length: workers },
|
|
570
|
+
(_, index) => Math.floor(rooms / workers) + (index < rooms % workers ? 1 : 0)
|
|
571
|
+
).filter((share) => share > 0);
|
|
572
|
+
const results = await Promise.all(
|
|
573
|
+
shares.map((share, index) => {
|
|
574
|
+
const worker = fleet.device(`load worker ${index + 1}`);
|
|
575
|
+
worker.send({
|
|
576
|
+
type: "load",
|
|
577
|
+
link: fleet.link,
|
|
578
|
+
credentialCommand: fleet.hostCredentialCommand,
|
|
579
|
+
rooms: share,
|
|
580
|
+
phonesPerRoom,
|
|
581
|
+
inputsPerSecond: 30,
|
|
582
|
+
statesPerSecond: 20,
|
|
583
|
+
durationMs
|
|
584
|
+
});
|
|
585
|
+
return worker.until(
|
|
586
|
+
(event) => event.type === "load" || event.type === "failed" ? event : void 0,
|
|
587
|
+
"finishing its rooms",
|
|
588
|
+
GRANT_DEADLINE_MS + durationMs
|
|
589
|
+
);
|
|
590
|
+
})
|
|
591
|
+
);
|
|
592
|
+
return summarizeLoad(
|
|
593
|
+
results.map((event) => {
|
|
594
|
+
if (event.type === "failed") throw new ScenarioFailure(event.message);
|
|
595
|
+
return event.result;
|
|
596
|
+
}),
|
|
597
|
+
{ rooms, phonesPerRoom, durationMs }
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
var summarizeLoad = (results, {
|
|
602
|
+
rooms,
|
|
603
|
+
phonesPerRoom,
|
|
604
|
+
durationMs
|
|
605
|
+
}) => {
|
|
606
|
+
const total = (key) => results.reduce((sum, result) => sum + result[key], 0);
|
|
607
|
+
const all = (key) => results.flatMap((result) => result[key]);
|
|
608
|
+
const traffic = results.reduce(
|
|
609
|
+
(sum, result) => ({
|
|
610
|
+
messagesIn: sum.messagesIn + result.traffic.messagesIn,
|
|
611
|
+
bytesIn: sum.bytesIn + result.traffic.bytesIn,
|
|
612
|
+
messagesOut: sum.messagesOut + result.traffic.messagesOut,
|
|
613
|
+
bytesOut: sum.bytesOut + result.traffic.bytesOut
|
|
614
|
+
}),
|
|
615
|
+
{ messagesIn: 0, bytesIn: 0, messagesOut: 0, bytesOut: 0 }
|
|
616
|
+
);
|
|
617
|
+
const roomHours = total("roomsOpened") * durationMs / HOUR_MS;
|
|
618
|
+
const perRoomHour = (value) => roomHours === 0 ? null : Math.round(value / roomHours);
|
|
619
|
+
const roomsOpened = total("roomsOpened");
|
|
620
|
+
const phonesJoined = total("phonesJoined");
|
|
621
|
+
const pressesLost = total("pressesLost");
|
|
622
|
+
const phonesWithoutState = total("phonesWithoutState");
|
|
623
|
+
if (roomsOpened < rooms || phonesJoined < rooms * phonesPerRoom || pressesLost > 0 || phonesWithoutState > 0)
|
|
624
|
+
throw new ScenarioFailure(
|
|
625
|
+
`${roomsOpened} of ${rooms} rooms opened, ${phonesJoined} of ${rooms * phonesPerRoom} phones joined, ${pressesLost} presses lost, ${phonesWithoutState} phones without the host's state.`
|
|
626
|
+
);
|
|
627
|
+
return {
|
|
628
|
+
rooms: roomsOpened,
|
|
629
|
+
phones: phonesJoined,
|
|
630
|
+
durationMs,
|
|
631
|
+
roomOpen: summarizeLatency(all("roomOpenMs")),
|
|
632
|
+
phoneJoin: summarizeLatency(all("phoneJoinMs")),
|
|
633
|
+
input: summarizeLatency(all("inputLatencyMs")),
|
|
634
|
+
pressesSent: total("pressesSent"),
|
|
635
|
+
pressesLost,
|
|
636
|
+
state: summarizeLatency(all("stateLatencyMs")),
|
|
637
|
+
perRoomHour: {
|
|
638
|
+
messagesIn: perRoomHour(traffic.messagesIn),
|
|
639
|
+
messagesOut: perRoomHour(traffic.messagesOut),
|
|
640
|
+
payloadBytesOut: perRoomHour(traffic.bytesOut),
|
|
641
|
+
wireBytesOutWithTls: perRoomHour(
|
|
642
|
+
traffic.bytesOut + WIRE_FRAMING_BYTES * traffic.messagesOut
|
|
643
|
+
)
|
|
644
|
+
},
|
|
645
|
+
clientCpuMs: Math.round(total("cpuMs"))
|
|
646
|
+
};
|
|
647
|
+
};
|
|
648
|
+
var runRoomsCheck = async (options) => {
|
|
649
|
+
const pacer = options.connectionsPerMinute === void 0 ? null : new ConnectionPacer(options.connectionsPerMinute);
|
|
650
|
+
const target = {
|
|
651
|
+
link: { url: options.url, origin: options.origin },
|
|
652
|
+
hostCredentialCommand: options.hostCredentialCommand
|
|
653
|
+
};
|
|
654
|
+
const resolved = {
|
|
655
|
+
briefFreezeMs: options.briefFreezeMs ?? 5e3,
|
|
656
|
+
stallMs: options.stallMs ?? 1e4,
|
|
657
|
+
idleMs: options.idleMs ?? 6e4,
|
|
658
|
+
crowdDurationMs: options.crowdDurationMs ?? 1e4,
|
|
659
|
+
load: {
|
|
660
|
+
rooms: options.load?.rooms ?? 100,
|
|
661
|
+
phonesPerRoom: options.load?.phonesPerRoom ?? 4,
|
|
662
|
+
durationMs: options.load?.durationMs ?? 6e4,
|
|
663
|
+
workers: options.load?.workers ?? Math.max(1, Math.min(8, Math.floor(availableParallelism() / 2)))
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
const results = [];
|
|
667
|
+
for (const scenario of options.scenarios ?? DEFAULT_ROOMS_CHECK_SCENARIOS) {
|
|
668
|
+
const fleet = new Fleet(target, pacer);
|
|
669
|
+
const startedAt = sharedNow();
|
|
670
|
+
let result;
|
|
671
|
+
try {
|
|
672
|
+
const measurements = await scenarios[scenario]({
|
|
673
|
+
fleet,
|
|
674
|
+
options: resolved
|
|
675
|
+
});
|
|
676
|
+
result = {
|
|
677
|
+
scenario,
|
|
678
|
+
passed: true,
|
|
679
|
+
durationMs: Math.round(sharedNow() - startedAt),
|
|
680
|
+
measurements: roundAll(measurements),
|
|
681
|
+
connectionProblems: fleet.problems(startedAt)
|
|
682
|
+
};
|
|
683
|
+
} catch (error) {
|
|
684
|
+
if (!(error instanceof ScenarioFailure)) throw error;
|
|
685
|
+
result = {
|
|
686
|
+
scenario,
|
|
687
|
+
passed: false,
|
|
688
|
+
failure: error.message,
|
|
689
|
+
durationMs: Math.round(sharedNow() - startedAt),
|
|
690
|
+
measurements: {},
|
|
691
|
+
connectionProblems: fleet.problems(startedAt)
|
|
692
|
+
};
|
|
693
|
+
} finally {
|
|
694
|
+
fleet.close();
|
|
695
|
+
}
|
|
696
|
+
results.push(result);
|
|
697
|
+
options.onResult?.(result);
|
|
698
|
+
}
|
|
699
|
+
return {
|
|
700
|
+
url: options.url,
|
|
701
|
+
passed: results.every((result) => result.passed),
|
|
702
|
+
scenarios: results
|
|
703
|
+
};
|
|
704
|
+
};
|
|
705
|
+
var roundAll = (measurements) => Object.fromEntries(
|
|
706
|
+
Object.entries(measurements).map(([key, value]) => [
|
|
707
|
+
key,
|
|
708
|
+
typeof value === "number" ? Math.round(value * 100) / 100 : value
|
|
709
|
+
])
|
|
710
|
+
);
|
|
711
|
+
export {
|
|
712
|
+
DEFAULT_ROOMS_CHECK_SCENARIOS,
|
|
713
|
+
ROOMS_CHECK_SCENARIOS,
|
|
714
|
+
describeLinkProblem,
|
|
715
|
+
runRoomsCheck
|
|
716
|
+
};
|
|
717
|
+
//# sourceMappingURL=rooms-check.js.map
|