ravensight-playtest 0.16.0 → 0.17.0
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 +15 -0
- package/package.json +3 -3
- package/src/cli.js +5 -0
- package/src/commands/run.js +26 -5
- package/src/run/anygame/shared-hashes.json +3 -2
- package/src/run/anygame/shared.js +6 -5
- package/src/run/args.js +3 -0
- package/src/run/drivers/web.js +70 -2
- package/src/run/egress.js +282 -0
- package/src/run/networkRun.js +54 -0
- package/src/run/resume.js +3 -1
package/README.md
CHANGED
|
@@ -1342,6 +1342,21 @@ optional job id.
|
|
|
1342
1342
|
Opens the dashboard page for a job, or for the game. Takes `--game <gameId>` and
|
|
1343
1343
|
an optional job id.
|
|
1344
1344
|
|
|
1345
|
+
|
|
1346
|
+
### Let a run reach your game's servers
|
|
1347
|
+
|
|
1348
|
+
A browser build's run reaches nothing outside the build unless you ask. List the hosts your game's own servers
|
|
1349
|
+
answer on under Playtest, Network in the dashboard (an exact name such as `api.example.com`, or `*.example.com` for
|
|
1350
|
+
the names one level under it), then add `--allow-network`:
|
|
1351
|
+
|
|
1352
|
+
```
|
|
1353
|
+
ravensight-playtest run --driver playwright_web --build-dir ./export --allow-network
|
|
1354
|
+
```
|
|
1355
|
+
|
|
1356
|
+
The run reaches those hosts over https and wss and nothing else; the report's Network section lists the hosts it
|
|
1357
|
+
reached and the attempts that were blocked, by host. It costs the same. A Godot, desktop or native game is its own
|
|
1358
|
+
program on your machine, which the playtester cannot limit, so the flag is refused for it.
|
|
1359
|
+
|
|
1345
1360
|
## Playtest a live URL
|
|
1346
1361
|
|
|
1347
1362
|
`run --url` points a playtest at your web game where it already runs: a staging
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ravensight-playtest",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Local AI playtests and seeded game simulations with reports in Ravensight.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://ravensight.io/docs/playtest/",
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
"./api": "./src/api/index.js"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
|
-
"test": "node --test --test-reporter=spec 'src/**/!(godot-real|godot-draw.real|godot-inputs.real|godot-menus.real|godot-replay.real|godot-tester.real|web.e2e|web.containment.e2e|web.inputs.e2e|web.honesty.e2e|web.followups.e2e|web.replay.e2e|web.anygame.e2e|web.languages.e2e|web.events.e2e|web.tester.e2e|web.livesite.e2e|web.moving.e2e|web.urlrun.e2e|scaffold.godot|template3d.godot).test.js'",
|
|
52
|
+
"test": "node --test --test-reporter=spec 'src/**/!(godot-real|godot-draw.real|godot-inputs.real|godot-menus.real|godot-replay.real|godot-tester.real|web.e2e|web.containment.e2e|web.inputs.e2e|web.honesty.e2e|web.followups.e2e|web.replay.e2e|web.anygame.e2e|web.languages.e2e|web.events.e2e|web.tester.e2e|web.livesite.e2e|web.network.e2e|web.moving.e2e|web.urlrun.e2e|scaffold.godot|template3d.godot).test.js'",
|
|
53
53
|
"test:godot": "node scripts/gated-test.mjs RAVENSIGHT_RECORDING_E2E some -- --test --test-concurrency=1 --test-reporter=spec src/run/drivers/godot-real.test.js src/run/drivers/godot-draw.real.test.js src/run/drivers/godot-inputs.real.test.js src/run/drivers/godot-menus.real.test.js src/run/drivers/godot-replay.real.test.js src/run/drivers/godot-tester.real.test.js src/create/scaffold.godot.test.js src/create/template3d.godot.test.js",
|
|
54
|
-
"test:e2e": "node scripts/gated-test.mjs RAVENSIGHT_E2E all -- --test --test-reporter=spec src/run/drivers/web.e2e.test.js src/run/drivers/web.containment.e2e.test.js src/run/drivers/web.inputs.e2e.test.js src/run/drivers/web.honesty.e2e.test.js src/run/drivers/web.followups.e2e.test.js src/run/drivers/web.tester.e2e.test.js src/run/drivers/web.replay.e2e.test.js src/run/drivers/web.anygame.e2e.test.js src/run/drivers/web.languages.e2e.test.js src/run/drivers/web.events.e2e.test.js src/run/drivers/web.livesite.e2e.test.js src/run/drivers/web.moving.e2e.test.js src/commands/run.urlrun.e2e.test.js",
|
|
54
|
+
"test:e2e": "node scripts/gated-test.mjs RAVENSIGHT_E2E all -- --test --test-reporter=spec src/run/drivers/web.e2e.test.js src/run/drivers/web.containment.e2e.test.js src/run/drivers/web.inputs.e2e.test.js src/run/drivers/web.honesty.e2e.test.js src/run/drivers/web.followups.e2e.test.js src/run/drivers/web.tester.e2e.test.js src/run/drivers/web.replay.e2e.test.js src/run/drivers/web.anygame.e2e.test.js src/run/drivers/web.languages.e2e.test.js src/run/drivers/web.events.e2e.test.js src/run/drivers/web.livesite.e2e.test.js src/run/drivers/web.network.e2e.test.js src/run/drivers/web.moving.e2e.test.js src/commands/run.urlrun.e2e.test.js",
|
|
55
55
|
"lint": "node scripts/no-dashes.mjs",
|
|
56
56
|
"audit:honesty": "node --test --test-reporter=spec src/run/honestyCorpus.test.js",
|
|
57
57
|
"test:android": "node scripts/gated-test.mjs RAVENSIGHT_ANDROID_E2E all -- --test --test-timeout=240000 --test-concurrency=1 src/run/drivers/mobile/native-real.test.js",
|
package/src/cli.js
CHANGED
|
@@ -70,6 +70,11 @@ Run options (parsed by the runner, see src/run/args.js):
|
|
|
70
70
|
For a game made for touch; the report says when a game wanted touch and the
|
|
71
71
|
run was played with a mouse
|
|
72
72
|
--build-url <url> the web build to play
|
|
73
|
+
--allow-network a browser build only: let this run reach the hosts your game lists under Playtest,
|
|
74
|
+
Network in the dashboard, over https and wss, and nothing else outside the build.
|
|
75
|
+
Off unless given. The report lists the hosts it reached and what was blocked.
|
|
76
|
+
A Godot, desktop or native game is its own program on this machine and cannot be
|
|
77
|
+
limited this way, so the flag is refused for it. It costs the same
|
|
73
78
|
--url <url> playtest a live web game by its address (staging or production) on this machine. A
|
|
74
79
|
public host must be verified for the game first (a TXT record, from the Playtest page,
|
|
75
80
|
Test a live URL); localhost and private addresses are a local dev server and need none.
|
package/src/commands/run.js
CHANGED
|
@@ -47,6 +47,7 @@ import { serveBuildDir } from '../run/serveBuild.js';
|
|
|
47
47
|
import { stepLogSetting, stepLogUploadsLine } from '../config.js';
|
|
48
48
|
import { readLiveSite } from '../run/livesite/options.js';
|
|
49
49
|
import { domainCheckRefusal, finishLiveSiteRun, pinRefusal } from '../run/livesite/run.js';
|
|
50
|
+
import { finishNetworkRun, networkRefusal, NETWORK_NOT_GRANTED } from '../run/networkRun.js';
|
|
50
51
|
import { redactingLog, redactValue } from '../run/redaction.js';
|
|
51
52
|
|
|
52
53
|
/**
|
|
@@ -206,6 +207,9 @@ async function run(flags, injected, deps, log) {
|
|
|
206
207
|
const keyModifier = resolveKeyModifier(options.keyModifier);
|
|
207
208
|
if (keyModifier.error) { log(keyModifier.error); return EXIT.ENVIRONMENT; }
|
|
208
209
|
const driverName = options.driver || (context.config && context.config.driver) || 'playwright_web';
|
|
210
|
+
// --allow-network: a browser build's run only, refused before anything is priced (../run/networkRun.js).
|
|
211
|
+
const netRefusal = networkRefusal(options, driverName);
|
|
212
|
+
if (netRefusal) { log(netRefusal); return EXIT.ENVIRONMENT; }
|
|
209
213
|
if (options.liveSite && driverName !== 'playwright_web') {
|
|
210
214
|
log(`--url plays a web page in the browser, so it uses the playwright_web driver, not ${driverName}. Nothing was registered or charged.`);
|
|
211
215
|
return EXIT.ENVIRONMENT;
|
|
@@ -431,7 +435,9 @@ async function run(flags, injected, deps, log) {
|
|
|
431
435
|
repo: { commit: (context.config && context.config.commit) || '', dirty: Boolean(context.config && context.config.dirty) },
|
|
432
436
|
max_actions: Number.isInteger(options.maxActions) ? options.maxActions : null,
|
|
433
437
|
...(runLength !== 'standard' ? { run_length: runLength } : {}),
|
|
434
|
-
pack_versions: { pack: pack.pack_version }
|
|
438
|
+
pack_versions: { pack: pack.pack_version },
|
|
439
|
+
// The server records the game's listed hosts on the job and answers them: those, and only those, are reached.
|
|
440
|
+
...(options.allowNetwork ? { network: true } : {})
|
|
435
441
|
}, { idempotencyKey });
|
|
436
442
|
} catch (error) {
|
|
437
443
|
const handled = explainRegisterRefusal(error, log);
|
|
@@ -440,6 +446,9 @@ async function run(flags, injected, deps, log) {
|
|
|
440
446
|
}
|
|
441
447
|
|
|
442
448
|
const jobId = registered.job_id;
|
|
449
|
+
// The hosts this job may reach, as the server recorded them (never the flag's own idea of them).
|
|
450
|
+
options.network = registered.network && Array.isArray(registered.network.hosts) ? { hosts: registered.network.hosts } : null;
|
|
451
|
+
if (options.allowNetwork && !options.network) log(NETWORK_NOT_GRANTED);
|
|
443
452
|
const directory = jobDir(repoRoot, jobId);
|
|
444
453
|
await mkdir(directory, { recursive: true });
|
|
445
454
|
|
|
@@ -470,7 +479,9 @@ async function run(flags, injected, deps, log) {
|
|
|
470
479
|
uploadVideo: Boolean(options.uploadVideo),
|
|
471
480
|
uploadTranscript: Boolean(options.uploadTranscript),
|
|
472
481
|
// A live site run: where it starts and how it signs in, never a secret (resume asks for the same flags).
|
|
473
|
-
...(options.liveSite ? { liveUrl: liveSiteRecord(options.liveSite) } : {})
|
|
482
|
+
...(options.liveSite ? { liveUrl: liveSiteRecord(options.liveSite) } : {}),
|
|
483
|
+
// The hosts the job was given at register: a resume reaches the same ones.
|
|
484
|
+
...(options.network ? { network: options.network } : {})
|
|
474
485
|
}
|
|
475
486
|
});
|
|
476
487
|
for (const entry of registered.runs || []) {
|
|
@@ -553,6 +564,11 @@ export function explainRegisterRefusal(error, log) {
|
|
|
553
564
|
log('The server refused this job because the game has no complete expectations brief. Run "ravensight-playtest brief" and try again.');
|
|
554
565
|
return EXIT.ENVIRONMENT;
|
|
555
566
|
}
|
|
567
|
+
// --allow-network on a game that lists no hosts: the server says so before any charge, in its own words.
|
|
568
|
+
if (code === 'network_hosts_empty') {
|
|
569
|
+
log(`${body.message || 'This game lists no hosts its playtests may reach. Nothing was charged.'} Add them in the dashboard under Playtest, Network, or run without --allow-network.`);
|
|
570
|
+
return EXIT.ENVIRONMENT;
|
|
571
|
+
}
|
|
556
572
|
if (code === 'insufficient_balance' && Number.isFinite(body.minimum_balance_cents)) {
|
|
557
573
|
log(startBalanceShort(body));
|
|
558
574
|
return EXIT.ENVIRONMENT;
|
|
@@ -908,7 +924,7 @@ export async function playPersonaRun({
|
|
|
908
924
|
const runTarget = entry.target || target;
|
|
909
925
|
let driver;
|
|
910
926
|
try {
|
|
911
|
-
driver = await makeDriver(driverName, driverOptions({ headless, driverName, target: runTarget, directory, entry, jobId, keyModifier: options.keyModifier, godotPath: options.godotPath, realtime: options.realtime, phone: options.phone, native: options.nativePlan, mode: options.driverMode, nativeLock, liveSite: options.liveSite || null, apiUrl }));
|
|
927
|
+
driver = await makeDriver(driverName, driverOptions({ headless, driverName, target: runTarget, directory, entry, jobId, keyModifier: options.keyModifier, godotPath: options.godotPath, realtime: options.realtime, phone: options.phone, native: options.nativePlan, mode: options.driverMode, nativeLock, liveSite: options.liveSite || null, apiUrl, network: options.network || null }));
|
|
912
928
|
} catch (error) {
|
|
913
929
|
// A driver that cannot even be built (the browser package missing, say) is
|
|
914
930
|
// what a new machine hits first. The run is completed as failed now, with
|
|
@@ -1000,7 +1016,7 @@ export async function playPersonaRun({
|
|
|
1000
1016
|
edgePass: options.noEdgePass !== true,
|
|
1001
1017
|
replayFindings: options.noReplay !== true,
|
|
1002
1018
|
// A web run's findings are replayed in a second browser of the same kind, on the same target, with no recording.
|
|
1003
|
-
...(driverName === 'playwright_web' ? { replayDriver: () => makeDriver(driverName, driverOptions({ headless, driverName, target: runTarget, directory, entry, jobId, keyModifier: options.keyModifier, godotPath: options.godotPath, realtime: options.realtime, phone: options.phone, native: options.nativePlan, mode: options.driverMode, nativeLock, liveSite: options.liveSite || null, apiUrl })) } : {}),
|
|
1019
|
+
...(driverName === 'playwright_web' ? { replayDriver: () => makeDriver(driverName, driverOptions({ headless, driverName, target: runTarget, directory, entry, jobId, keyModifier: options.keyModifier, godotPath: options.godotPath, realtime: options.realtime, phone: options.phone, native: options.nativePlan, mode: options.driverMode, nativeLock, liveSite: options.liveSite || null, apiUrl, network: options.network || null })) } : {}),
|
|
1004
1020
|
// A run sold by the minute stops on the clock (../run/playClock.js).
|
|
1005
1021
|
playClock: playClockFor(options, entry),
|
|
1006
1022
|
...(options.phone === true && driverName === 'playwright_web' ? { viewport: PHONE_VIEWPORT } : {}),
|
|
@@ -1050,6 +1066,7 @@ export async function playPersonaRun({
|
|
|
1050
1066
|
});
|
|
1051
1067
|
// A live site run's report, step log and usage are scanned for its sign-in secrets before anything is sent.
|
|
1052
1068
|
await finishLiveSiteRun({ directory, driver, outcome: failed, liveSite: options.liveSite || null });
|
|
1069
|
+
await finishNetworkRun({ directory, driver, outcome: failed });
|
|
1053
1070
|
const delivery = {};
|
|
1054
1071
|
const answer = await deliver({ deps, api, gameId, jobId, runId, directory, outcome: failed, options, log, repoRoot, delivery });
|
|
1055
1072
|
// The server finishes a run that played past the proof bar and then reached
|
|
@@ -1113,6 +1130,8 @@ export async function playPersonaRun({
|
|
|
1113
1130
|
if (inFlight) inFlight.delete(runId);
|
|
1114
1131
|
// A live site run's report, step log and usage are scanned for its sign-in secrets before anything is sent.
|
|
1115
1132
|
await finishLiveSiteRun({ directory, driver, outcome, liveSite: options.liveSite || null });
|
|
1133
|
+
// A run with network access: the report's Network section and usage.json `network` (../run/networkRun.js).
|
|
1134
|
+
await finishNetworkRun({ directory, driver, outcome });
|
|
1116
1135
|
|
|
1117
1136
|
await stateFile.patchRun(repoRoot, journal, runId, {
|
|
1118
1137
|
state: outcome.state,
|
|
@@ -1836,7 +1855,7 @@ export async function resolveSetup(deps, options, log) {
|
|
|
1836
1855
|
*
|
|
1837
1856
|
* @returns {Object}
|
|
1838
1857
|
*/
|
|
1839
|
-
export function driverOptions({ headless, driverName, target, directory, entry, jobId, keyModifier, godotPath, realtime, phone = false, native = null, mode = 'webdriver', nativeLock, liveSite = null, apiUrl = null }) {
|
|
1858
|
+
export function driverOptions({ headless, driverName, target, directory, entry, jobId, keyModifier, godotPath, realtime, phone = false, native = null, mode = 'webdriver', nativeLock, liveSite = null, apiUrl = null, network = null }) {
|
|
1840
1859
|
// Only the browser driver sends key chords with a modifier.
|
|
1841
1860
|
const modifier = driverName === 'playwright_web' ? resolveKeyModifier(keyModifier).modifier : null;
|
|
1842
1861
|
const godot = driverName === 'godot_driver'
|
|
@@ -1855,6 +1874,8 @@ export function driverOptions({ headless, driverName, target, directory, entry,
|
|
|
1855
1874
|
...(driverName === 'playwright_web' && phone === true ? { touch: true } : {}),
|
|
1856
1875
|
// A live URL run (../run/livesite/): its network rules, sign-in and masking.
|
|
1857
1876
|
...(driverName === 'playwright_web' && liveSite ? { liveSite } : {}),
|
|
1877
|
+
// Network access: the hosts the job was given at register (../run/egress.js). A browser build only.
|
|
1878
|
+
...(driverName === 'playwright_web' && network && !liveSite ? { network } : {}),
|
|
1858
1879
|
// The Ravensight ingest origins the game's own SDK session can go to: the SDKs' default and this run's API (../run/sdkSession.js).
|
|
1859
1880
|
...(driverName === 'playwright_web' && apiUrl ? { ingestOrigins: ingestOriginsFor(apiUrl) } : {}),
|
|
1860
1881
|
...godot,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"comment": "Hashes of the files shared by the hosted runner (lib/anygame/*.mjs including gamenotes, and lib/claimwords.mjs, lib/events.mjs, lib/eventclaims.mjs) and the local CLI (src/run/anygame/*.js, and src/run/claimwords.js, src/run/events.js, src/run/eventclaims.js), taken over the code both carry (see shared.mjs or shared.js). The same file in both repos: update it in both, after copying the change.",
|
|
2
|
+
"comment": "Hashes of the files shared by the hosted runner (lib/anygame/*.mjs including gamenotes, and lib/claimwords.mjs, lib/events.mjs, lib/eventclaims.mjs, lib/egress.mjs) and the local CLI (src/run/anygame/*.js, and src/run/claimwords.js, src/run/events.js, src/run/eventclaims.js, src/run/egress.js), taken over the code both carry (see shared.mjs or shared.js). The same file in both repos: update it in both, after copying the change.",
|
|
3
3
|
"files": {
|
|
4
4
|
"language": "2b95828c77a8e82440c53d330381b7ba830796312d2ae9b7edc8fd95ff72e1ef",
|
|
5
5
|
"memory": "7cab932cd9e23ee84aa4f60d14b89e4ce2e4b0b9fc6e87c963b2d04e084256b8",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"gamenotes": "f0ab9c9be900c17824d6e37beeead7210bfe280573860e4d0ecd4ac2edd36678",
|
|
10
10
|
"claimwords": "6cd99897a09dae67d0b657a110476fb0f8b27ae4124da9c60b79b2b0d28133b7",
|
|
11
11
|
"events": "8b1cbb4cf48b1e1e1f1de064e2f3cbf4ecd8473d4a518c20caa3c8953a3a1708",
|
|
12
|
-
"eventclaims": "11dfdd3e0928447ce3e21408c7b2f9eedb499e92ada39ca8b48222646cadc23b"
|
|
12
|
+
"eventclaims": "11dfdd3e0928447ce3e21408c7b2f9eedb499e92ada39ca8b48222646cadc23b",
|
|
13
|
+
"egress": "65053e3fc47f9746f9662da8a5bfa2c31b7252d8c66528849fd0bf0b0006dd80"
|
|
13
14
|
}
|
|
14
15
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// The files this folder shares with the hosted runner (the platform repo,
|
|
2
2
|
// infrastructure/hosted-playtest/direct-runner/lib/anygame): language, memory, controlbook, genre, sound and gamenotes are
|
|
3
|
-
// the same code in both repos, and so are
|
|
4
|
-
// claim judge
|
|
3
|
+
// the same code in both repos, and so are four files one folder up that the
|
|
4
|
+
// claim judge, the game's own events and a run's network access use (claimwords, events, eventclaims, egress). Each repo checks its own copies against one
|
|
5
5
|
// table of hashes (shared-hashes.json, the same file in both), so a change to
|
|
6
6
|
// one copy fails that repo's test until the table is updated, and the table
|
|
7
7
|
// in the other repo then fails until the copy there is updated too.
|
|
@@ -11,10 +11,11 @@
|
|
|
11
11
|
// name the other repo, and how each gets its `noDashes`.
|
|
12
12
|
import crypto from 'node:crypto';
|
|
13
13
|
|
|
14
|
-
export const SHARED = ['language', 'memory', 'controlbook', 'genre', 'sound', 'gamenotes', 'claimwords', 'events', 'eventclaims'];
|
|
14
|
+
export const SHARED = ['language', 'memory', 'controlbook', 'genre', 'sound', 'gamenotes', 'claimwords', 'events', 'eventclaims', 'egress'];
|
|
15
15
|
|
|
16
|
-
// Where a shared file lives, from this folder: src/run/anygame/<name>.js, or one folder up for the
|
|
17
|
-
|
|
16
|
+
// Where a shared file lives, from this folder: src/run/anygame/<name>.js, or one folder up for the four that are not any-game code
|
|
17
|
+
// (egress is a run's network access to the game's listed servers, docs/playtest-network/CONTRACT.md).
|
|
18
|
+
const UP = new Set(['claimwords', 'events', 'eventclaims', 'egress']);
|
|
18
19
|
export const sharedPath = name => (UP.has(name) ? `../${name}.js` : `${name}.js`);
|
|
19
20
|
|
|
20
21
|
/** A shared file's text with what differs by design taken out. */
|
package/src/run/args.js
CHANGED
|
@@ -83,6 +83,9 @@ const BOOLEAN = new Map([
|
|
|
83
83
|
['--dry-upload', 'dryUpload'],
|
|
84
84
|
['--offline-upload', 'offlineUpload'],
|
|
85
85
|
['--headed', 'headed'],
|
|
86
|
+
// A local browser run may reach the hosts the game lists for it, and nothing else outside the build
|
|
87
|
+
// (the platform's docs/playtest-network/CONTRACT.md). Off unless given.
|
|
88
|
+
['--allow-network', 'allowNetwork'],
|
|
86
89
|
['--headless', 'headless'],
|
|
87
90
|
['--verbose', 'verbose'],
|
|
88
91
|
// A long persona run: twice the actions and wall time and a larger model budget than a
|
package/src/run/drivers/web.js
CHANGED
|
@@ -17,7 +17,9 @@ import { recordingLimits, recordingViewport, recordingDirectory, recordingMetada
|
|
|
17
17
|
import path from 'node:path';
|
|
18
18
|
import { gameRefusal, runnerGone } from '../gameRefusal.js';
|
|
19
19
|
import { createAvoidGuard } from '../avoid.js';
|
|
20
|
-
import { classifyRequest, createSafetyCounts, networkRules } from '../livesite/network.js';
|
|
20
|
+
import { classifyRequest, createSafetyCounts, networkRules, isIngestCall } from '../livesite/network.js';
|
|
21
|
+
// A run's network access to the game's listed servers (the platform's docs/playtest-network/CONTRACT.md).
|
|
22
|
+
import { createEgress, egressBrowserArgs, hostLabel, parseEntries } from '../egress.js';
|
|
21
23
|
import { hostResolverRules, ravensightHosts } from '../livesite/resolver.js';
|
|
22
24
|
import { LiveSiteError, MASKED_EMAIL, MASKED_PASSWORD, maskSecretsInit, outcomeMessage, performSignIn } from '../livesite/browser.js';
|
|
23
25
|
import {
|
|
@@ -1248,6 +1250,22 @@ export const CHECK_PLAYTEST_IDENTITY = Object.freeze({ token: 'check', runId: nu
|
|
|
1248
1250
|
* @param {{video: boolean, liveSite: Object|null, headless?: boolean}} args
|
|
1249
1251
|
* @returns {Array<string>}
|
|
1250
1252
|
*/
|
|
1253
|
+
/**
|
|
1254
|
+
* The build's own origin as `host:port`, which a run with network access lets the browser reach directly, as it
|
|
1255
|
+
* always did: the build is the game's own. Every other address, another port on this machine included, meets the proxy.
|
|
1256
|
+
* @param {string} url
|
|
1257
|
+
* @returns {Array<string>}
|
|
1258
|
+
*/
|
|
1259
|
+
export function buildHostsOf(url) {
|
|
1260
|
+
try {
|
|
1261
|
+
const u = new URL(String(url));
|
|
1262
|
+
if (!/^https?:$/.test(u.protocol) || !u.hostname) return [];
|
|
1263
|
+
return [`${u.hostname.toLowerCase()}:${u.port || (u.protocol === 'https:' ? '443' : '80')}`];
|
|
1264
|
+
} catch {
|
|
1265
|
+
return [];
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1251
1269
|
export function browserLaunchArgs({ video, liveSite, headless = false }) {
|
|
1252
1270
|
const args = [...(headless ? ['--disable-audio-output'] : []), ...(video ? ['--mute-audio'] : [])];
|
|
1253
1271
|
if (liveSite) {
|
|
@@ -1468,7 +1486,7 @@ function maskShare(mask) {
|
|
|
1468
1486
|
return mask.length ? n / mask.length : 1;
|
|
1469
1487
|
}
|
|
1470
1488
|
|
|
1471
|
-
export function createWebDriver({ importer, headless = true, playtest = null, platform = process.platform, modifier = null, recording = {}, now = () => Date.now(), inspectVideo = probeVideo, freezeTime = true, touch = false, frameStrip = true, liveSite = null, ingestOrigins = null } = {}) {
|
|
1489
|
+
export function createWebDriver({ importer, headless = true, playtest = null, platform = process.platform, modifier = null, recording = {}, now = () => Date.now(), inspectVideo = probeVideo, freezeTime = true, touch = false, frameStrip = true, liveSite = null, ingestOrigins = null, network = null, egressTest = null } = {}) {
|
|
1472
1490
|
const editModifier = modifier === 'Meta' || modifier === 'Control' ? modifier : platformModifier(platform);
|
|
1473
1491
|
// What the brief asks the run to stay out of (../avoid.js): an input on such a control is never sent (setAvoid).
|
|
1474
1492
|
let avoidGuard = createAvoidGuard([]);
|
|
@@ -1482,6 +1500,11 @@ export function createWebDriver({ importer, headless = true, playtest = null, pl
|
|
|
1482
1500
|
const sdkSessionReads = new Set();
|
|
1483
1501
|
// Only a POST to one of these origins is the game's Ravensight session; the game's own backend at the same path is not.
|
|
1484
1502
|
const sessionOrigins = Array.isArray(ingestOrigins) && ingestOrigins.length > 0 ? ingestOrigins : ingestOriginsFor();
|
|
1503
|
+
// Network access (`network: { hosts }`, the hosts recorded on the job at register): off when null. On, every request
|
|
1504
|
+
// off the build goes through `networkRoute` and every outside connection through the run's proxy (../egress.js).
|
|
1505
|
+
// `egressTest` is test-only (`{ resolve, connect, allowPrivate, browserArgs }`), handed in code, never read from a flag or a file.
|
|
1506
|
+
const netEntries = network && Array.isArray(network.hosts) ? parseEntries(network.hosts).entries.slice(0, 9) : [];
|
|
1507
|
+
let egress = null;
|
|
1485
1508
|
let target = null;
|
|
1486
1509
|
let runDirectory = null;
|
|
1487
1510
|
let videoRequested = false;
|
|
@@ -1628,6 +1651,34 @@ export function createWebDriver({ importer, headless = true, playtest = null, pl
|
|
|
1628
1651
|
}
|
|
1629
1652
|
}
|
|
1630
1653
|
|
|
1654
|
+
/**
|
|
1655
|
+
* The one route of a run with network access (docs/playtest-network/CONTRACT.md section 6): the build itself and what
|
|
1656
|
+
* the page makes in memory go on; the game's Ravensight SDK reaches its documented ingest calls and nothing else of
|
|
1657
|
+
* ours; a listed host over https or wss goes on, through the run's proxy; anything else is blocked and counted by
|
|
1658
|
+
* host. What goes on falls back to the build guard, so a navigation off the build is still kept on it.
|
|
1659
|
+
* @param {any} route
|
|
1660
|
+
*/
|
|
1661
|
+
function networkRoute(route) {
|
|
1662
|
+
const request = route.request();
|
|
1663
|
+
const address = request.url();
|
|
1664
|
+
let parsed = null;
|
|
1665
|
+
try { parsed = new URL(address); } catch { parsed = null; }
|
|
1666
|
+
if (!parsed || !/^(?:https?|wss?):$/.test(parsed.protocol) || onBuild(address)) return route.fallback();
|
|
1667
|
+
if (sessionOrigins.includes(parsed.origin) || ravensightHosts(sessionOrigins).includes(parsed.hostname)) {
|
|
1668
|
+
if (isIngestCall(request.method(), parsed)) return route.fallback();
|
|
1669
|
+
return route.fulfill({ status: 403, contentType: 'application/json', body: '{"error":"sandbox_refused"}' });
|
|
1670
|
+
}
|
|
1671
|
+
if (egress.allows(address)) return route.fallback();
|
|
1672
|
+
egress.noteBlocked(hostLabel(address));
|
|
1673
|
+
let topLevel = false;
|
|
1674
|
+
try { topLevel = request.isNavigationRequest() ? isTopLevel(request) : false; } catch { topLevel = false; }
|
|
1675
|
+
if (topLevel !== false) {
|
|
1676
|
+
if (guardArmed) recordOffSite(address, topLevel === null ? 'new window' : 'navigation');
|
|
1677
|
+
return route.fulfill({ status: 204, body: '' });
|
|
1678
|
+
}
|
|
1679
|
+
return route.abort('blockedbyclient');
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1631
1682
|
/** @param {string} candidate */
|
|
1632
1683
|
function onBuild(candidate) {
|
|
1633
1684
|
return buildTargets.some(base => isNavigationAllowed(candidate, base));
|
|
@@ -2563,6 +2614,7 @@ export function createWebDriver({ importer, headless = true, playtest = null, pl
|
|
|
2563
2614
|
if (marker) await marker.close().catch(() => {});
|
|
2564
2615
|
marker = null;
|
|
2565
2616
|
try { if (browser) await withTimeout(browser.close(), 15000); } catch { /* already closed or unavailable */ }
|
|
2617
|
+
if (egress) await egress.close().catch(() => {});
|
|
2566
2618
|
if (captureDirectory) await rm(captureDirectory, { recursive: true, force: true });
|
|
2567
2619
|
if (metadata) await saveRecording(runDirectory, metadata);
|
|
2568
2620
|
page = null;
|
|
@@ -3013,6 +3065,15 @@ export function createWebDriver({ importer, headless = true, playtest = null, pl
|
|
|
3013
3065
|
const playwright = await loadPlaywright(importer);
|
|
3014
3066
|
await mkdir(runDir, { recursive: true });
|
|
3015
3067
|
const launchArgs = browserLaunchArgs({ video: videoRequested, liveSite, headless: headless !== false });
|
|
3068
|
+
if (network && !liveSite) {
|
|
3069
|
+
// The game's own Ravensight SDK reaches its documented ingest calls (the route holds it to those paths); every
|
|
3070
|
+
// other outside host is the list's, and the build's own host stays the browser's own.
|
|
3071
|
+
const passthrough = sessionOrigins.map(origin => { try { return new URL(origin).hostname; } catch { return null; } }).filter(Boolean);
|
|
3072
|
+
const { browserArgs: testArgs = [], ...testEgress } = egressTest || {};
|
|
3073
|
+
egress = createEgress({ entries: netEntries, passthrough, ...testEgress });
|
|
3074
|
+
const proxy = await egress.start();
|
|
3075
|
+
launchArgs.push(...egressBrowserArgs(proxy.url, { direct: buildHostsOf(url) }), ...testArgs);
|
|
3076
|
+
}
|
|
3016
3077
|
browser = await playwright.chromium.launch({ headless, ...(launchArgs.length ? { args: launchArgs } : {}) });
|
|
3017
3078
|
const contextBase = { viewport, ...(touch ? { hasTouch: true, isMobile: true, deviceScaleFactor: 1, userAgent: PHONE_USER_AGENT } : {}) };
|
|
3018
3079
|
// A live site's sign-in happens first, in a context of its own with no recording of any kind; the
|
|
@@ -3031,6 +3092,8 @@ export function createWebDriver({ importer, headless = true, playtest = null, pl
|
|
|
3031
3092
|
context = await browser.newContext({
|
|
3032
3093
|
...contextBase,
|
|
3033
3094
|
...(storageState ? { storageState } : {}),
|
|
3095
|
+
// A run with access registers no service worker: what the page reaches stays the page's own requests.
|
|
3096
|
+
...(egress ? { serviceWorkers: 'block' } : {}),
|
|
3034
3097
|
...(videoRequested ? { recordVideo: { dir: captureDirectory, size: viewport }, permissions: [] } : {})
|
|
3035
3098
|
});
|
|
3036
3099
|
// The playtest identity goes in as an init script, not as
|
|
@@ -3095,6 +3158,8 @@ export function createWebDriver({ importer, headless = true, playtest = null, pl
|
|
|
3095
3158
|
}
|
|
3096
3159
|
// Registered after the build guard, so it decides first and hands what it allows back to the guard.
|
|
3097
3160
|
if (liveSite && typeof context.route === 'function') await context.route('**/*', route => liveRoute(route, { play: true }));
|
|
3161
|
+
// Network access: registered after the build guard as well, so it decides first and hands what it allows back.
|
|
3162
|
+
if (egress && typeof context.route === 'function') await context.route('**/*', route => networkRoute(route));
|
|
3098
3163
|
captureStartedAt = videoRequested ? now() : null;
|
|
3099
3164
|
page = await context.newPage();
|
|
3100
3165
|
// A new window that did get a document (one on the build, or a blank
|
|
@@ -3410,6 +3475,9 @@ export function createWebDriver({ importer, headless = true, playtest = null, pl
|
|
|
3410
3475
|
/** A live site run's blocked hosts and refused Ravensight paths, or null for any other run. */
|
|
3411
3476
|
liveSiteSafety() { return liveSite ? liveSafety.toJSON() : null; },
|
|
3412
3477
|
|
|
3478
|
+
/** A run with network access: the hosts it could reach, those it reached and the blocked attempts by host; else null. */
|
|
3479
|
+
networkSummary() { return egress ? egress.summary() : null; },
|
|
3480
|
+
|
|
3413
3481
|
/** The controls an input was refused on because the brief asks to stay out of them, by name. */
|
|
3414
3482
|
avoidedControls() { return avoidGuard.list(); },
|
|
3415
3483
|
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
// A playtest run's network access to the hosts a studio listed for its game (decision N3,
|
|
2
|
+
// docs/playtest-network/CONTRACT.md in the platform repo). The same code in the hosted runner and the local CLI.
|
|
3
|
+
//
|
|
4
|
+
// Off unless the run asked for it. On, the browser reaches the build's own origin and the listed hosts only, each
|
|
5
|
+
// over https or wss on the default port. Every connection to the outside goes through a small proxy in this process
|
|
6
|
+
// (`createEgress`): it sees the host of every request the page, a worker, a redirect hop, a WebSocket or a popup
|
|
7
|
+
// makes, because the browser sends each as one CONNECT naming its host. It refuses any host not on the list, resolves
|
|
8
|
+
// a listed name itself, refuses the connection when any answer is private, loopback or link-local, and connects to
|
|
9
|
+
// the address it checked, so a name that rebinds between the check and the connection reaches nothing else.
|
|
10
|
+
import net from 'node:net';
|
|
11
|
+
import http from 'node:http';
|
|
12
|
+
import dns from 'node:dns';
|
|
13
|
+
|
|
14
|
+
/** At most nine entries and 580 characters joined by spaces: the hosts ride in the cloud machine's start data. */
|
|
15
|
+
export const MAX_ENTRIES = 9;
|
|
16
|
+
export const MAX_JOINED_CHARS = 580;
|
|
17
|
+
export const LIMITS = Object.freeze({ tunnels: 64, connections: 5000, connectMs: 10000, idleMs: 120000, hostsTracked: 200 });
|
|
18
|
+
|
|
19
|
+
// Names that are never a studio's server: special-use and private suffixes, and our own.
|
|
20
|
+
const REFUSED_SUFFIXES = ['localhost', 'local', 'internal', 'test', 'example', 'invalid', 'home.arpa', 'arpa', 'onion', 'ravensight.io', 'realityse.com'];
|
|
21
|
+
// A wildcard on a name many unrelated owners share would open far more than one game's servers.
|
|
22
|
+
// Country second levels, and the shared site hosts studios most often publish a web build on.
|
|
23
|
+
const SHARED_PARENTS = ['co.uk', 'org.uk', 'ac.uk', 'gov.uk', 'com.au', 'net.au', 'org.au', 'co.jp', 'co.nz', 'co.kr', 'co.in', 'com.br', 'com.cn', 'com.mx', 'com.tr', 'com.tw',
|
|
24
|
+
'github.io', 'gitlab.io', 'itch.io', 'itch.zone', 'newgrounds.com', 'vercel.app', 'netlify.app', 'pages.dev', 'workers.dev', 'herokuapp.com',
|
|
25
|
+
'web.app', 'firebaseapp.com', 'appspot.com', 'onrender.com', 'fly.dev', 'glitch.me', 'repl.co', 'ngrok.io', 'ngrok-free.app',
|
|
26
|
+
// Wildcard DNS services: every name under them answers whatever address it spells.
|
|
27
|
+
'nip.io', 'sslip.io', 'xip.io', 'traefik.me', 'localtest.me', 'lvh.me'];
|
|
28
|
+
const LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
29
|
+
const under = (host, suffix) => host === suffix || host.endsWith(`.${suffix}`);
|
|
30
|
+
|
|
31
|
+
/** A host as it is stored (lower case, no trailing dot), or null: not an IP literal, not private, not ours, no port. */
|
|
32
|
+
export function normalizeHost(raw) {
|
|
33
|
+
if (typeof raw !== 'string') return null;
|
|
34
|
+
let h = raw.trim().toLowerCase();
|
|
35
|
+
if (h.endsWith('.')) h = h.slice(0, -1);
|
|
36
|
+
if (!h || h.length > 253) return null;
|
|
37
|
+
const labels = h.split('.');
|
|
38
|
+
if (labels.length < 2 || labels.length > 127) return null;
|
|
39
|
+
if (!labels.every(l => LABEL.test(l))) return null;
|
|
40
|
+
// An IP literal, or a name whose last label is all digits (no such top level name exists).
|
|
41
|
+
if (/^\d+$/.test(labels[labels.length - 1])) return null;
|
|
42
|
+
if (REFUSED_SUFFIXES.some(s => under(h, s))) return null;
|
|
43
|
+
return h;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** One entry of a game's list: `{ host, wildcard }` (`*.example.com` is `example.com` with wildcard true), or null. */
|
|
47
|
+
export function parseEntry(raw) {
|
|
48
|
+
if (typeof raw !== 'string') return null;
|
|
49
|
+
const t = raw.trim().toLowerCase();
|
|
50
|
+
const wildcard = t.startsWith('*.');
|
|
51
|
+
const host = normalizeHost(wildcard ? t.slice(2) : t);
|
|
52
|
+
if (!host || (wildcard && SHARED_PARENTS.includes(host))) return null;
|
|
53
|
+
return { host, wildcard };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const entryText = e => (e.wildcard ? `*.${e.host}` : e.host);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A whole list: `{ entries, invalid }`, the entries de-duplicated in their first order and `invalid` the indexes of
|
|
60
|
+
* those refused. A list over MAX_ENTRIES or MAX_JOINED_CHARS answers `tooMany` or `tooLong`.
|
|
61
|
+
*/
|
|
62
|
+
export function parseEntries(list) {
|
|
63
|
+
const entries = [], invalid = [];
|
|
64
|
+
if (!Array.isArray(list)) return { entries, invalid: [-1], tooMany: false, tooLong: false };
|
|
65
|
+
list.forEach((raw, i) => {
|
|
66
|
+
const e = parseEntry(raw);
|
|
67
|
+
if (!e) invalid.push(i);
|
|
68
|
+
else if (!entries.some(x => x.host === e.host && x.wildcard === e.wildcard)) entries.push(e);
|
|
69
|
+
});
|
|
70
|
+
return { entries, invalid, tooMany: entries.length > MAX_ENTRIES, tooLong: entries.map(entryText).join(' ').length > MAX_JOINED_CHARS };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Whether a host is on the list: an exact entry is only itself, a wildcard one label under its name (never the name). */
|
|
74
|
+
export function allowedHost(raw, entries) {
|
|
75
|
+
const h = normalizeHost(raw);
|
|
76
|
+
if (!h || !Array.isArray(entries)) return false;
|
|
77
|
+
return entries.some(e => {
|
|
78
|
+
if (!e || typeof e.host !== 'string') return false;
|
|
79
|
+
if (!e.wildcard) return h === e.host;
|
|
80
|
+
if (!h.endsWith(`.${e.host}`)) return false;
|
|
81
|
+
return !h.slice(0, -(e.host.length + 1)).includes('.');
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** A request's host as the report names it: the host and any port, or the scheme and host when it is not https or wss. */
|
|
86
|
+
export function hostLabel(raw) {
|
|
87
|
+
let u;
|
|
88
|
+
try { u = new URL(String(raw)); } catch { return 'unknown'; }
|
|
89
|
+
const tls = u.protocol === 'https:' || u.protocol === 'wss:';
|
|
90
|
+
const label = tls ? u.host : `${u.protocol}//${u.host}`;
|
|
91
|
+
return label.toLowerCase().replace(/[^a-z0-9.:/\[\]-]/g, '').slice(0, 120) || 'unknown';
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Whether the browser may ask for a URL at all: https or wss, the default port, no user info, a listed host. */
|
|
95
|
+
export function allowedUrl(raw, entries) {
|
|
96
|
+
let u;
|
|
97
|
+
try { u = new URL(String(raw)); } catch { return false; }
|
|
98
|
+
if (u.protocol !== 'https:' && u.protocol !== 'wss:') return false;
|
|
99
|
+
if (u.port || u.username || u.password) return false;
|
|
100
|
+
return allowedHost(u.hostname, entries);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Refused IPv4 ranges: unspecified, private, shared, loopback, link-local (the metadata address), documentation,
|
|
104
|
+
// benchmarking, multicast and reserved.
|
|
105
|
+
const REFUSED_RANGES = [
|
|
106
|
+
['0.0.0.0', 8], ['10.0.0.0', 8], ['100.64.0.0', 10], ['127.0.0.0', 8], ['169.254.0.0', 16], ['172.16.0.0', 12],
|
|
107
|
+
['192.0.0.0', 24], ['192.0.2.0', 24], ['192.88.99.0', 24], ['192.168.0.0', 16], ['198.18.0.0', 15], ['198.51.100.0', 24],
|
|
108
|
+
['203.0.113.0', 24], ['224.0.0.0', 4], ['240.0.0.0', 4], ['255.255.255.255', 32]
|
|
109
|
+
];
|
|
110
|
+
function ipv4(raw) {
|
|
111
|
+
if (typeof raw !== 'string' || !/^\d{1,3}(?:\.\d{1,3}){3}$/.test(raw)) return null;
|
|
112
|
+
const parts = raw.split('.').map(Number);
|
|
113
|
+
if (parts.some(p => p > 255)) return null;
|
|
114
|
+
return ((parts[0] << 24) >>> 0) + (parts[1] << 16) + (parts[2] << 8) + parts[3];
|
|
115
|
+
}
|
|
116
|
+
/** Whether an address is a public IPv4 address. IPv6 is never used, so it is never public here. */
|
|
117
|
+
export function isPublicAddress(raw) {
|
|
118
|
+
const n = ipv4(raw);
|
|
119
|
+
if (n === null) return false;
|
|
120
|
+
return !REFUSED_RANGES.some(([base, bits]) => {
|
|
121
|
+
const mask = (0xffffffff << (32 - bits)) >>> 0;
|
|
122
|
+
return ((n & mask) >>> 0) === ((ipv4(base) & mask) >>> 0);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** A fresh lookup of a name's IPv4 answers on this machine. */
|
|
127
|
+
export async function lookupAddresses(host, { lookup = dns.promises.lookup } = {}) {
|
|
128
|
+
const answers = await lookup(host, { all: true, family: 4 });
|
|
129
|
+
return [...new Set((answers || []).map(a => a && a.address).filter(Boolean))];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Chromium's arguments for a run with access: every outside connection through the proxy, and nothing else resolved.
|
|
134
|
+
* `direct` names the build itself as `host:port` (the runner's own server, a local run's --build-url): only that
|
|
135
|
+
* origin's host and port go direct. `<-loopback>` takes away Chromium's own bypass for loopback and link-local
|
|
136
|
+
* addresses, so a socket to another local port or the metadata address meets the proxy too, which refuses it.
|
|
137
|
+
*/
|
|
138
|
+
export function egressBrowserArgs(proxyUrl, { direct = [] } = {}) {
|
|
139
|
+
const own = [...new Set((direct || []).map(h => String(h || '').toLowerCase()).filter(h => /^(?:\[[0-9a-f:]+\]|[a-z0-9.-]+):\d{1,5}$/.test(h)))];
|
|
140
|
+
// The resolver rules reach an address literal too, so the build's own host is excluded whatever it is.
|
|
141
|
+
const names = [...new Set(own.map(h => h.replace(/:\d+$/, '')).filter(h => !h.startsWith('[')))];
|
|
142
|
+
return [`--proxy-server=${proxyUrl}`, `--proxy-bypass-list=${['<-loopback>', ...own].join(';')}`,
|
|
143
|
+
`--host-resolver-rules=${['MAP * ~NOTFOUND', 'EXCLUDE localhost', ...names.map(h => `EXCLUDE ${h}`)].join(', ')}`,
|
|
144
|
+
'--disable-quic', '--force-webrtc-ip-handling-policy=disable_non_proxied_udp'];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** A host's spelling only (lower case, no brackets or trailing dot), before any rule refuses it: how passthrough is matched. */
|
|
148
|
+
const spelled = raw => String(raw || '').trim().toLowerCase().replace(/^\[|\]$/g, '').replace(/\.$/, '');
|
|
149
|
+
|
|
150
|
+
const bump = (map, key, max) => { if (map.size < max || map.has(key)) map.set(key, Math.min(1e6, (map.get(key) || 0) + 1)); };
|
|
151
|
+
const listed = map => [...map.entries()].map(([host, count]) => ({ host, count })).sort((a, b) => b.count - a.count || a.host.localeCompare(b.host));
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* One run's access. `entries` are the run's listed hosts (parseEntries). `resolve(host)` answers the addresses to
|
|
155
|
+
* try (a fresh lookup on this machine, or the addresses the cloud machine opened at boot). `passthrough` names hosts
|
|
156
|
+
* let through that are not the studio's (the game's own analytics calls on a local run), never counted as reached.
|
|
157
|
+
* `allowPrivate` is a test-only option handed in code. `start()` opens the proxy on 127.0.0.1 and answers its URL.
|
|
158
|
+
*/
|
|
159
|
+
export function createEgress({ entries, resolve = host => lookupAddresses(host), passthrough = [], allowPrivate = false, limits = LIMITS, connect = net.connect } = {}) {
|
|
160
|
+
const list = Array.isArray(entries) ? entries.filter(e => e && typeof e.host === 'string') : [];
|
|
161
|
+
const through = new Set((passthrough || []).map(spelled).filter(Boolean));
|
|
162
|
+
const reached = new Map(), blocked = new Map(), refused = { notListed: 0, notHttps: 0, privateAddress: 0, unresolved: 0, unreachable: 0, limit: 0 };
|
|
163
|
+
let server = null, tunnels = 0, total = 0, passed = 0;
|
|
164
|
+
const sockets = new Set();
|
|
165
|
+
|
|
166
|
+
const noteBlocked = (label, reason = 'notListed') => {
|
|
167
|
+
if (Object.hasOwn(refused, reason)) refused[reason] = Math.min(1e6, refused[reason] + 1);
|
|
168
|
+
// Only what a host can spell reaches the report.
|
|
169
|
+
bump(blocked, String(label || 'unknown').toLowerCase().replace(/[^a-z0-9.:/\[\]-]/g, '').slice(0, 120) || 'unknown', limits.hostsTracked);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
/** What the proxy does with one CONNECT target: `{ host, port, pass }` to go on, or `{ reason, label }` to refuse. */
|
|
173
|
+
function decide(target) {
|
|
174
|
+
const m = /^\[?([^\]\s]+?)\]?:(\d{1,5})$/.exec(String(target || ''));
|
|
175
|
+
if (!m) return { reason: 'notListed', label: String(target || 'unknown').toLowerCase().slice(0, 120) };
|
|
176
|
+
const rawHost = m[1].toLowerCase(), port = Number(m[2]);
|
|
177
|
+
const label = port === 443 ? rawHost : `${rawHost}:${port}`;
|
|
178
|
+
// Our own ingest host is refused by the list rules, so a passthrough is matched by its spelling, never an address.
|
|
179
|
+
const pass = through.has(spelled(rawHost)) && !/^[\d.]+$|:/.test(spelled(rawHost));
|
|
180
|
+
const host = pass ? spelled(rawHost) : normalizeHost(rawHost);
|
|
181
|
+
if (!host || (!pass && !allowedHost(host, list))) return { reason: 'notListed', label };
|
|
182
|
+
if (port !== 443) return { reason: 'notHttps', label };
|
|
183
|
+
return { host, port, pass };
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async function onConnect(req, client, head) {
|
|
187
|
+
client.on('error', () => {});
|
|
188
|
+
const d = decide(req.url);
|
|
189
|
+
const deny = (status, reason, label) => {
|
|
190
|
+
noteBlocked(label, reason);
|
|
191
|
+
try { client.end(`HTTP/1.1 ${status} Blocked\r\nContent-Length: 0\r\nConnection: close\r\n\r\n`); } catch { /* gone */ }
|
|
192
|
+
};
|
|
193
|
+
if (d.reason) return deny(403, d.reason, d.label);
|
|
194
|
+
if (tunnels >= limits.tunnels || total >= limits.connections) return deny(429, 'limit', d.host);
|
|
195
|
+
total++;
|
|
196
|
+
let addresses;
|
|
197
|
+
try { addresses = await resolve(d.host); } catch { addresses = []; }
|
|
198
|
+
addresses = Array.isArray(addresses) ? addresses.filter(a => typeof a === 'string') : [];
|
|
199
|
+
if (!addresses.length) return deny(502, 'unresolved', d.host);
|
|
200
|
+
// One private answer refuses the name: a rebinding name mixes a public answer with an internal one.
|
|
201
|
+
if (!allowPrivate && addresses.some(a => !isPublicAddress(a))) return deny(403, 'privateAddress', d.host);
|
|
202
|
+
tunnels++;
|
|
203
|
+
let closed = false;
|
|
204
|
+
const done = () => { if (!closed) { closed = true; tunnels--; } };
|
|
205
|
+
const attempt = i => {
|
|
206
|
+
if (i >= addresses.length || client.destroyed) { done(); return deny(502, 'unreachable', d.host); }
|
|
207
|
+
const upstream = connect({ host: addresses[i], port: d.port });
|
|
208
|
+
sockets.add(upstream);
|
|
209
|
+
const timer = setTimeout(() => upstream.destroy(new Error('connect_timeout')), limits.connectMs);
|
|
210
|
+
upstream.once('error', () => { clearTimeout(timer); sockets.delete(upstream); if (!upstream.rsOpen) attempt(i + 1); else { done(); client.destroy(); } });
|
|
211
|
+
upstream.once('connect', () => {
|
|
212
|
+
clearTimeout(timer);
|
|
213
|
+
upstream.rsOpen = true;
|
|
214
|
+
// The page gave up while the address was dialled: nothing was reached.
|
|
215
|
+
if (client.destroyed) { done(); upstream.destroy(); sockets.delete(upstream); return; }
|
|
216
|
+
if (d.pass) passed++; else bump(reached, d.host, limits.hostsTracked);
|
|
217
|
+
client.write('HTTP/1.1 200 Connection Established\r\n\r\n');
|
|
218
|
+
if (head && head.length) upstream.write(head);
|
|
219
|
+
upstream.setTimeout(limits.idleMs, () => upstream.destroy());
|
|
220
|
+
client.setTimeout(limits.idleMs, () => client.destroy());
|
|
221
|
+
upstream.pipe(client);
|
|
222
|
+
client.pipe(upstream);
|
|
223
|
+
const end = () => { done(); upstream.destroy(); client.destroy(); sockets.delete(upstream); };
|
|
224
|
+
upstream.once('close', end);
|
|
225
|
+
client.once('close', end);
|
|
226
|
+
});
|
|
227
|
+
};
|
|
228
|
+
attempt(0);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// A plain http request through the proxy: never sent, counted by host.
|
|
232
|
+
function onRequest(req, res) {
|
|
233
|
+
let label = 'unknown';
|
|
234
|
+
try { label = hostLabel(req.url); } catch { label = 'unknown'; }
|
|
235
|
+
noteBlocked(label, 'notHttps');
|
|
236
|
+
res.writeHead(403, { 'content-type': 'text/plain', connection: 'close' });
|
|
237
|
+
res.end('blocked');
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
entries: list,
|
|
242
|
+
noteBlocked,
|
|
243
|
+
/** Whether the page may ask for a URL (the route's own check, before the proxy sees it). */
|
|
244
|
+
allows: raw => allowedUrl(raw, list),
|
|
245
|
+
async start() {
|
|
246
|
+
server = http.createServer(onRequest);
|
|
247
|
+
server.on('connect', (req, socket, head) => { sockets.add(socket); socket.once('close', () => sockets.delete(socket)); onConnect(req, socket, head).catch(() => socket.destroy()); });
|
|
248
|
+
server.on('clientError', (_e, socket) => socket.destroy());
|
|
249
|
+
await new Promise((ok, fail) => { server.once('error', fail); server.listen(0, '127.0.0.1', ok); });
|
|
250
|
+
const port = server.address().port;
|
|
251
|
+
return { port, url: `http://127.0.0.1:${port}` };
|
|
252
|
+
},
|
|
253
|
+
async close() {
|
|
254
|
+
for (const s of sockets) s.destroy();
|
|
255
|
+
sockets.clear();
|
|
256
|
+
if (server) await new Promise(ok => server.close(() => ok()));
|
|
257
|
+
server = null;
|
|
258
|
+
},
|
|
259
|
+
summary() {
|
|
260
|
+
return { on: true, hosts: list.map(entryText), reached: listed(reached), blocked: listed(blocked), refused: { ...refused }, passthrough: passed };
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** A run's summary when it had no access: the hosts the page asked for, blocked, by host. */
|
|
266
|
+
export function offSummary(blockedHosts = []) {
|
|
267
|
+
return { on: false, hosts: [], reached: [], blocked: (blockedHosts || []).map(b => ({ host: String(b.host), count: Number(b.count) || 0 })), refused: null, passthrough: 0 };
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? '' : 's'}`;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* The report's Network line, in plain words, for a run that had access: the hosts it could reach, those it did
|
|
274
|
+
* (connections) and the blocked attempts by host. `notes` are lines the runner adds (what was not enforced).
|
|
275
|
+
*/
|
|
276
|
+
export function networkLines(summary, { notes = [] } = {}) {
|
|
277
|
+
if (!summary || !summary.on) return [];
|
|
278
|
+
const hosts = summary.hosts.length ? summary.hosts.join(', ') : 'none';
|
|
279
|
+
const reached = summary.reached.length ? summary.reached.slice(0, 10).map(r => `${r.host} (${plural(r.count, 'connection')})`).join(', ') : 'none';
|
|
280
|
+
const blocked = summary.blocked.length ? summary.blocked.slice(0, 10).map(b => `${b.host} (${plural(b.count, 'attempt')})`).join(', ') : 'none';
|
|
281
|
+
return [`**Network:** this run could reach your game's servers: ${hosts}. Reached: ${reached}. Blocked: ${blocked}.`, ...notes];
|
|
282
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { RUN_FILES } from './paths.js';
|
|
4
|
+
import { networkLines } from './egress.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A local run's network access (`--allow-network`; the platform's docs/playtest-network/CONTRACT.md section 6).
|
|
8
|
+
*
|
|
9
|
+
* A browser build's run reaches the hosts the game lists for it, and nothing else outside the build: the run's route
|
|
10
|
+
* and its proxy (./egress.js) hold every request and connection to that list. A Godot, desktop, Unity, Unreal,
|
|
11
|
+
* native mobile or custom bridge run is the game's own program on this machine, which the playtester cannot limit,
|
|
12
|
+
* so the flag is refused for them rather than accepted with a promise it cannot keep.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** Said when the server answered no hosts for a run that asked (an older server): the run plays as before. */
|
|
16
|
+
export const NETWORK_NOT_GRANTED = 'This server did not record network access for the job, so the run plays as it always has, with nothing limited by the list.';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Why --allow-network cannot be used on this run, or null.
|
|
20
|
+
* @param {{allowNetwork?: boolean, liveSite?: Object|null}} options
|
|
21
|
+
* @param {string} driverName
|
|
22
|
+
* @returns {string|null}
|
|
23
|
+
*/
|
|
24
|
+
export function networkRefusal(options, driverName) {
|
|
25
|
+
if (!options || !options.allowNetwork) return null;
|
|
26
|
+
if (options.liveSite) return '--allow-network is for an uploaded or local build. A --url run already reaches its own site\'s hosts and nothing else. Nothing was registered or charged.';
|
|
27
|
+
if (driverName !== 'playwright_web') {
|
|
28
|
+
return `--allow-network holds a browser build to the hosts your game lists. A ${driverName} run is your game's own program on this machine, and the playtester cannot limit what it reaches, so it reaches what it always has. Run without --allow-network. Nothing was registered or charged.`;
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* After a run with access, before it is delivered: the "Network" section of report.md (and of the outcome's markdown
|
|
35
|
+
* the server is sent) and usage.json `network`. A run without access is left exactly as it was.
|
|
36
|
+
* @param {{directory: string, driver: Object|null, outcome: Object|null}} args
|
|
37
|
+
* @returns {Promise<Object|null>} the summary, or null
|
|
38
|
+
*/
|
|
39
|
+
export async function finishNetworkRun({ directory, driver, outcome }) {
|
|
40
|
+
const summary = driver && typeof driver.networkSummary === 'function' ? driver.networkSummary() : null;
|
|
41
|
+
if (!summary) return null;
|
|
42
|
+
const notes = summary.hosts.some(h => h.startsWith('*.')) ? ['A wildcard entry covers the names one level under it on this machine; a cloud run opens exact names only.'] : [];
|
|
43
|
+
const section = ['', '## Network', '', ...networkLines(summary, { notes }).flatMap((line, i) => (i ? ['', line] : [line]))].join('\n');
|
|
44
|
+
const markdownPath = path.join(directory, RUN_FILES.reportMd);
|
|
45
|
+
const markdown = await readFile(markdownPath, 'utf8').catch(() => null);
|
|
46
|
+
if (markdown !== null && !markdown.includes('\n## Network\n')) await writeFile(markdownPath, `${markdown.replace(/\s*$/, '')}\n${section}\n`, 'utf8');
|
|
47
|
+
if (outcome && typeof outcome.reportMarkdown === 'string' && !outcome.reportMarkdown.includes('\n## Network\n')) outcome.reportMarkdown = `${outcome.reportMarkdown.replace(/\s*$/, '')}\n${section}\n`;
|
|
48
|
+
const usagePath = path.join(directory, RUN_FILES.usageJson);
|
|
49
|
+
const usage = await readFile(usagePath, 'utf8').then(JSON.parse).catch(() => null);
|
|
50
|
+
if (usage) await writeFile(usagePath, `${JSON.stringify({ ...usage, network: { ...summary, notes } }, null, 2)}\n`, 'utf8');
|
|
51
|
+
return summary;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default { finishNetworkRun, networkRefusal, NETWORK_NOT_GRANTED };
|
package/src/run/resume.js
CHANGED
|
@@ -249,7 +249,9 @@ export async function resumeJob({ api, gameId, jobId, job, runs, state, repoRoot
|
|
|
249
249
|
concurrency: options.concurrency ?? (journal.options && journal.options.concurrency),
|
|
250
250
|
uploadVideo: options.uploadVideo ?? (journal.options && journal.options.uploadVideo),
|
|
251
251
|
uploadTranscript: options.uploadTranscript ?? (journal.options && journal.options.uploadTranscript),
|
|
252
|
-
...(liveSite ? { liveSite } : {})
|
|
252
|
+
...(liveSite ? { liveSite } : {}),
|
|
253
|
+
// The hosts the job was given at register, as its journal kept them: the same, never a new list.
|
|
254
|
+
...(journal.options?.network && Array.isArray(journal.options.network.hosts) ? { network: { hosts: journal.options.network.hosts } } : {})
|
|
253
255
|
};
|
|
254
256
|
|
|
255
257
|
let nativeLease = null;
|