ravensight-playtest 0.7.5 → 0.8.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 +57 -29
- package/docs/ADAPTERS.md +1 -1
- package/package.json +1 -1
- package/src/cli.js +25 -17
- package/src/commands/build.js +3 -1
- package/src/commands/hosted.js +100 -23
- package/src/commands/run.js +42 -10
- package/src/hosted/archivePreflight.js +112 -4
- package/src/hosted/buildStatus.js +2 -0
- package/src/hosted/buildUpload.js +22 -3
- package/src/hosted/recordedRun.js +272 -61
- package/src/hosted/status.js +26 -4
- package/src/run/comparison.js +7 -5
- package/src/run/controllers.js +14 -2
- package/src/run/drivers/web.js +45 -3
- package/src/run/personaLoop.js +89 -4
- package/src/run/resume.js +11 -1
- package/src/run/serveBuild.js +137 -0
package/src/commands/run.js
CHANGED
|
@@ -7,7 +7,7 @@ import { reportPrOutcomes } from '../run/labsOutcome.js';
|
|
|
7
7
|
import { finishJob } from '../run/settle.js';
|
|
8
8
|
import { driverStartReason, failureReason } from '../run/failureReason.js';
|
|
9
9
|
import { optionsFrom, unknownOptionNotes } from '../run/args.js';
|
|
10
|
-
import { controllerPlan, quoteMatchesPlan, runsMatchPlan } from '../run/controllers.js';
|
|
10
|
+
import { controllerPlan, displayName, quoteMatchesPlan, runsMatchPlan, wireId } from '../run/controllers.js';
|
|
11
11
|
import { getDeps } from '../run/deps.js';
|
|
12
12
|
import { createDriver } from '../run/drivers/index.js';
|
|
13
13
|
import EXIT from '../run/exit.js';
|
|
@@ -32,6 +32,7 @@ import { bold } from '../ui/index.js';
|
|
|
32
32
|
import { reconcileDroppedFindings } from '../run/dropped.js';
|
|
33
33
|
import * as stateFile from '../run/state.js';
|
|
34
34
|
import { emitRunEvents } from '../run/synthetic.js';
|
|
35
|
+
import { serveBuildDir } from '../run/serveBuild.js';
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
38
|
* `ravensight-playtest run`: register a job, play it, upload it, finish it.
|
|
@@ -114,13 +115,16 @@ async function run(flags, injected, deps, log) {
|
|
|
114
115
|
let controllers;
|
|
115
116
|
try { controllers = controllerPlan(options); } catch (error) { log(error.message); return EXIT.ENVIRONMENT; }
|
|
116
117
|
options.controllers = controllers;
|
|
118
|
+
if (options.controller) options.controller = wireId(options.controller);
|
|
117
119
|
const keyModifier = resolveKeyModifier(options.keyModifier);
|
|
118
120
|
if (keyModifier.error) { log(keyModifier.error); return EXIT.ENVIRONMENT; }
|
|
119
121
|
const driverName = options.driver || (context.config && context.config.driver) || 'playwright_web';
|
|
120
122
|
if (controllers?.length > 1 && !['playwright_web', 'godot_driver'].includes(driverName)) { log('Comparisons currently require a web or Godot build. Nothing was charged.'); return EXIT.ENVIRONMENT; }
|
|
123
|
+
const served = await serveBuildDirOption({ options, driverName, log, serve: injected.serveBuildDir });
|
|
124
|
+
if (served === false) return EXIT.ENVIRONMENT;
|
|
121
125
|
const target = resolveTarget(options, context.config, driverName, repoRoot);
|
|
122
126
|
if (!target) {
|
|
123
|
-
log('Point the run at a build: --build-url for a web build, --godot-project for Godot, or --driver-config for a native or text bridge.');
|
|
127
|
+
log('Point the run at a build: --build-url or --build-dir for a web build, --godot-project for Godot, or --driver-config for a native or text bridge.');
|
|
124
128
|
return EXIT.ENVIRONMENT;
|
|
125
129
|
}
|
|
126
130
|
|
|
@@ -173,7 +177,7 @@ async function run(flags, injected, deps, log) {
|
|
|
173
177
|
}
|
|
174
178
|
const modules = [...RUN_MODULES];
|
|
175
179
|
const pack = await deps.packs.get({ api, gameId, modules });
|
|
176
|
-
if (controllers && (!pack.routing?.controller_plans || controllers.some(controller => !pack.routing?.action_controllers?.includes(controller)))) { log('This server does not currently support the requested
|
|
180
|
+
if (controllers && (!pack.routing?.controller_plans || controllers.some(controller => !pack.routing?.action_controllers?.includes(controller)))) { log('This server does not currently support the requested playtesters. No job was registered or charged.'); return EXIT.ENVIRONMENT; }
|
|
177
181
|
const personaSlugs = resolvePersonas(options, context.config, pack);
|
|
178
182
|
const unknownSlugs = unknownPersonas(personaSlugs, pack.personas || []);
|
|
179
183
|
if (unknownSlugs.length > 0) {
|
|
@@ -226,9 +230,9 @@ async function run(flags, injected, deps, log) {
|
|
|
226
230
|
}
|
|
227
231
|
throw error;
|
|
228
232
|
}
|
|
229
|
-
if (!quoteMatchesPlan(estimate, controllers, personaSlugs)) { log('The server did not quote every requested
|
|
230
|
-
if (controllers) log(`
|
|
231
|
-
if (controllers?.length > 1) log('Each
|
|
233
|
+
if (!quoteMatchesPlan(estimate, controllers, personaSlugs)) { log('The server did not quote every requested playtester run. Nothing was registered or charged.'); return EXIT.ENVIRONMENT; }
|
|
234
|
+
if (controllers) log(`Playtesters: ${controllers.map(displayName).join(' + ')}. ${personas.length * controllers.length} independent playthrough(s); each run is included in the total quote.`);
|
|
235
|
+
if (controllers?.length > 1) log('Each playtester gets a fresh game process or browser session. Server-side game progress and randomness may differ; comparison is evidence, not proof of identical starting state.');
|
|
232
236
|
// A long run is its own unit on the server. An older server that ignores
|
|
233
237
|
// run_length prices a standard run, and confirming that would buy a run
|
|
234
238
|
// the CLI then plays as long.
|
|
@@ -309,6 +313,7 @@ async function run(flags, injected, deps, log) {
|
|
|
309
313
|
modules,
|
|
310
314
|
driver: driverName,
|
|
311
315
|
target,
|
|
316
|
+
...(served ? { buildDir: served.root } : {}),
|
|
312
317
|
priceCents: registered.price && registered.price.price_cents,
|
|
313
318
|
options: {
|
|
314
319
|
maxActions: options.maxActions ?? null,
|
|
@@ -329,7 +334,7 @@ async function run(flags, injected, deps, log) {
|
|
|
329
334
|
}
|
|
330
335
|
await stateFile.save(repoRoot, journal);
|
|
331
336
|
if (!runsMatchPlan(registered.runs || [], controllers, personaSlugs)) {
|
|
332
|
-
log(`The registered
|
|
337
|
+
log(`The registered playtester plan does not match the quote. Job ${jobId} is saved for reconciliation; no playthrough or model call was started.`);
|
|
333
338
|
return EXIT.FAILED;
|
|
334
339
|
}
|
|
335
340
|
log(`job ${jobId}${registered.replayed ? ' (replayed)' : ''}: ${formatCents(registered.price && registered.price.price_cents)} charged. ${directory}`);
|
|
@@ -469,12 +474,39 @@ export function unusedFlagWarnings(options) {
|
|
|
469
474
|
if (options.offlineUpload !== undefined) {
|
|
470
475
|
warnings.push('--offline-upload is not applied by this release: uploads already queue and can be drained later with "ravensight-playtest upload <job>".');
|
|
471
476
|
}
|
|
472
|
-
if (options.buildDir !== undefined) {
|
|
473
|
-
warnings.push('--build-dir is not applied by this release: serve the build and pass --build-url instead.');
|
|
474
|
-
}
|
|
475
477
|
return warnings;
|
|
476
478
|
}
|
|
477
479
|
|
|
480
|
+
/**
|
|
481
|
+
* `--build-dir`: serve an exported web build from this machine and point the
|
|
482
|
+
* run at it, with the headers engines' web exports need (see
|
|
483
|
+
* ../run/serveBuild.js). Answers the served build, null when the flag is not
|
|
484
|
+
* given, or false after saying why it cannot be used; nothing is registered
|
|
485
|
+
* or charged either way.
|
|
486
|
+
*
|
|
487
|
+
* @returns {Promise<{url: string, root: string, entry: string}|null|false>}
|
|
488
|
+
*/
|
|
489
|
+
export async function serveBuildDirOption({ options, driverName, log, serve = serveBuildDir }) {
|
|
490
|
+
if (options.buildDir === undefined) return null;
|
|
491
|
+
if (driverName !== 'playwright_web') {
|
|
492
|
+
log(`--build-dir serves a web build, and this run uses ${driverName}. Nothing was registered or charged.`);
|
|
493
|
+
return false;
|
|
494
|
+
}
|
|
495
|
+
if (options.buildUrl) {
|
|
496
|
+
log('Pass --build-dir or --build-url, not both. Nothing was registered or charged.');
|
|
497
|
+
return false;
|
|
498
|
+
}
|
|
499
|
+
try {
|
|
500
|
+
const served = await serve(options.buildDir);
|
|
501
|
+
options.buildUrl = served.url;
|
|
502
|
+
log(`Serving ${served.root} at ${served.url} (wasm, compressed engine files and cross-origin isolation for threaded builds).`);
|
|
503
|
+
return served;
|
|
504
|
+
} catch (error) {
|
|
505
|
+
log(`${error.message} Nothing was registered or charged.`);
|
|
506
|
+
return false;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
478
510
|
/**
|
|
479
511
|
* Play every unfinished run of a registered job, aggregate, finish.
|
|
480
512
|
*
|
|
@@ -182,14 +182,58 @@ async function nativeHeader(archive, file, format, requirements) {
|
|
|
182
182
|
return { os, architecture, binaryFormat, runtimeCompatibilityProven: false };
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
+
// What a build that is not a web build is, by file names alone, and what to
|
|
186
|
+
// do instead. Asked only once a web upload has already failed (no entry page,
|
|
187
|
+
// or an entry file that is not a page), so it never refuses a web build.
|
|
188
|
+
const NATIVE_ADVICE = Object.freeze({
|
|
189
|
+
unity: 'this is a Unity desktop or mobile build. Cloud playtests play web builds: build for the Web platform and upload that output, or run a local playtest with --driver unity_driver',
|
|
190
|
+
unreal: 'this is an Unreal Engine build, and Unreal has no supported web export, so a cloud playtest cannot play it. Run a local playtest with --driver unreal_driver',
|
|
191
|
+
godot: 'this is a Godot desktop export. Cloud playtests play web builds: export with the Web preset and upload that folder, or run a local playtest with --driver godot_driver',
|
|
192
|
+
love: 'this is a LÖVE game file. Cloud playtests play web builds: package it with love.js and upload that folder, or run a local playtest with --driver desktop_driver',
|
|
193
|
+
android: 'this is an Android app. Android builds play only in a local playtest: --driver android_driver on your own device or emulator',
|
|
194
|
+
ios: 'this is an iOS app. iOS builds play only in a local playtest: --driver ios_driver on your own device or simulator',
|
|
195
|
+
desktop: 'this is a desktop program, not a web build. Cloud playtests play web builds only (HTML and WebAssembly): build for the web, or run a local playtest with --driver desktop_driver'
|
|
196
|
+
});
|
|
197
|
+
const any = (paths, pattern) => paths.some(name => pattern.test(name));
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* The engine or platform a non-web build came from, or null.
|
|
201
|
+
* @param {string[]} names archive file names
|
|
202
|
+
* @returns {keyof NATIVE_ADVICE|null}
|
|
203
|
+
*/
|
|
204
|
+
export function nativeBuildKind(names) {
|
|
205
|
+
const paths = names.map(name => name.toLowerCase());
|
|
206
|
+
if (any(paths, /\.(?:apk|aab)$/)) return 'android';
|
|
207
|
+
if (any(paths, /\.ipa$|(?:^|\/)payload\/[^/]+\.app\//)) return 'ios';
|
|
208
|
+
if (any(paths, /\.uproject$|(?:^|\/)engine\/binaries\/|(?:^|\/)content\/paks\/[^/]+\.(?:pak|utoc|ucas)$/)) return 'unreal';
|
|
209
|
+
if (any(paths, /(?:^|\/)(?:unityplayer|gameassembly)\.(?:dll|so|dylib)$|(?:^|\/)[^/]+_data\/(?:globalgamemanagers|data\.unity3d|managed\/|il2cpp_data\/)|\.app\/contents\/resources\/data\/(?:globalgamemanagers|data\.unity3d)$/)) return 'unity';
|
|
210
|
+
if (any(paths, /\.love$/)) return 'love';
|
|
211
|
+
if (any(paths, /\.pck$/) && !any(paths, /\.wasm$/) && any(paths, /\.(?:exe|x86_64|x86_32|arm64|arm32)$|\.app\/contents\/macos\//)) return 'godot';
|
|
212
|
+
if (any(paths, /\.(?:exe|dll|so|dylib|x86_64|x86_32|appimage|msi)$|\.app\/contents\/macos\//)) return 'desktop';
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** The entry-file kind of a web upload that names a program or package. */
|
|
217
|
+
function nativeEntryKind(entrypoint) {
|
|
218
|
+
const name = String(entrypoint || '').toLowerCase();
|
|
219
|
+
if (/\.(?:apk|aab)$/.test(name)) return 'android';
|
|
220
|
+
if (/\.ipa$/.test(name)) return 'ios';
|
|
221
|
+
if (/\.uproject$/.test(name)) return 'unreal';
|
|
222
|
+
if (/(?:^|\/)project\.godot$|\.pck$/.test(name)) return 'godot';
|
|
223
|
+
if (/\.love$/.test(name)) return 'love';
|
|
224
|
+
if (/\.(?:exe|x86_64|x86_32|arm64|app|appimage|dll|so|dylib)$/.test(name)) return 'desktop';
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
|
|
185
228
|
export async function inspectBuildArchive(archive, { limits: supplied, format, entrypoint, requirements } = {}) {
|
|
186
229
|
const limits = buildLimits(supplied);
|
|
187
230
|
if (!['web', 'godot-project', 'linux-executable', 'windows-executable'].includes(format)) reject('the selected runtime format is unsupported');
|
|
231
|
+
if (format === 'web' && typeof entrypoint === 'string' && !/\.html?$/i.test(entrypoint) && nativeEntryKind(entrypoint)) reject(NATIVE_ADVICE[nativeEntryKind(entrypoint)]);
|
|
188
232
|
if (typeof entrypoint !== 'string' || entrypoint.length > 240 || !/^[A-Za-z0-9_.-]+(?:\/[A-Za-z0-9_.-]+)*$/.test(entrypoint)) reject('the entrypoint does not match the current server path policy');
|
|
189
233
|
const wanted = safePath(entrypoint, limits.depth);
|
|
190
234
|
if (format === 'web' && !wanted.endsWith('.html') || format === 'godot-project' && wanted.split('/').at(-1) !== 'project.godot'
|
|
191
235
|
|| format === 'windows-executable' && !wanted.toLowerCase().endsWith('.exe')) reject('the entrypoint does not match the selected format');
|
|
192
|
-
const dir = await directory(archive, limits), paths = new Map(), explicit = new Set(), ranges = [];
|
|
236
|
+
const dir = await directory(archive, limits), paths = new Map(), explicit = new Set(), ranges = [], fileNames = [];
|
|
193
237
|
let cursor = dir.offset, expandedBytes = 0, files = 0, found = false, pathBytes = 0, nativeFile;
|
|
194
238
|
for (let index = 0; index < dir.count; index++) {
|
|
195
239
|
const h = await archive.read(cursor, 46);
|
|
@@ -221,10 +265,11 @@ export async function inspectBuildArchive(archive, { limits: supplied, format, e
|
|
|
221
265
|
const dataEnd = size.offset + 30 + nameBytes + local.readUInt16LE(28) + size.compressed;
|
|
222
266
|
if (!Number.isSafeInteger(dataEnd) || dataEnd > dir.offset) reject('file data overlaps the ZIP directory');
|
|
223
267
|
ranges.push([size.offset, dataEnd]);
|
|
224
|
-
if (!isDirectory) { files++; if (name === wanted) { if (!size.expanded) reject('the entrypoint is empty'); found = true;
|
|
268
|
+
if (!isDirectory) { files++; if (fileNames.length < 5000) fileNames.push(name); if (name === wanted) { if (!size.expanded) reject('the entrypoint is empty'); found = true;
|
|
225
269
|
nativeFile = { ...size, method, dataOffset: size.offset + 30 + nameBytes + local.readUInt16LE(28), dataEnd }; } }
|
|
226
270
|
cursor += 46 + nameBytes + extraBytes + commentBytes;
|
|
227
271
|
}
|
|
272
|
+
if (!found && format === 'web' && nativeBuildKind(fileNames)) reject(NATIVE_ADVICE[nativeBuildKind(fileNames)]);
|
|
228
273
|
if (cursor !== dir.offset + dir.size || !found) reject('the declared entrypoint is absent or the directory is inconsistent');
|
|
229
274
|
ranges.sort((a, b) => a[0] - b[0]);
|
|
230
275
|
for (let i = 1; i < ranges.length; i++) if (ranges[i][0] < ranges[i - 1][1]) reject('ZIP file data overlaps');
|
|
@@ -234,7 +279,70 @@ export async function inspectBuildArchive(archive, { limits: supplied, format, e
|
|
|
234
279
|
zip64: dir.zip64, metadataVerified: true, nativeBinaryMetadata, contentsVerified: false, serverValidationRequired: true, runtimeCompatibilityProven: false };
|
|
235
280
|
}
|
|
236
281
|
|
|
237
|
-
|
|
282
|
+
// The file names in the central directory, read with the same bounded
|
|
283
|
+
// metadata reads as the full inspection. Only names: inspectBuildArchive still
|
|
284
|
+
// checks every entry once the entry file is chosen.
|
|
285
|
+
async function archiveFileNames(archive, limits) {
|
|
286
|
+
const dir = await directory(archive, limits), names = [];
|
|
287
|
+
let cursor = dir.offset;
|
|
288
|
+
for (let index = 0; index < dir.count; index++) {
|
|
289
|
+
const h = await archive.read(cursor, 46);
|
|
290
|
+
if (h.readUInt32LE(0) !== 0x02014b50) reject('a ZIP directory entry is invalid');
|
|
291
|
+
const nameBytes = h.readUInt16LE(28), extraBytes = h.readUInt16LE(30), commentBytes = h.readUInt16LE(32);
|
|
292
|
+
if (!nameBytes || nameBytes > MAX_PATH_BYTES || cursor + 46 + nameBytes + extraBytes + commentBytes > dir.offset + dir.size) reject('a ZIP directory entry is oversized');
|
|
293
|
+
const name = (await archive.read(cursor + 46, nameBytes)).toString('utf8');
|
|
294
|
+
if (!name.endsWith('/')) names.push(name);
|
|
295
|
+
cursor += 46 + nameBytes + extraBytes + commentBytes;
|
|
296
|
+
}
|
|
297
|
+
return names;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const ENTRY_KINDS = Object.freeze({
|
|
301
|
+
web: { noun: 'HTML file', preferred: 'index.html', match: name => name.endsWith('.html') },
|
|
302
|
+
'godot-project': { noun: 'project.godot file', preferred: 'project.godot', match: name => name.split('/').at(-1) === 'project.godot' },
|
|
303
|
+
'windows-executable': { noun: '.exe file', preferred: null, match: name => name.toLowerCase().endsWith('.exe') }
|
|
304
|
+
});
|
|
305
|
+
const MAX_LISTED = 10;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* The entry file to use when --entrypoint is not given. An index.html (or
|
|
309
|
+
* project.godot) at the top wins; otherwise the only candidate at the top,
|
|
310
|
+
* looking inside one wrapping folder when everything sits in one; otherwise
|
|
311
|
+
* the only candidate anywhere. With several, the error lists them so the
|
|
312
|
+
* person can choose: nothing is guessed.
|
|
313
|
+
* @returns {Promise<{entrypoint: string, reason: 'root'|'only-top-level'|'wrapped-folder'|'only-one'}>}
|
|
314
|
+
*/
|
|
315
|
+
export async function chooseEntrypoint(archive, { limits: supplied, format } = {}) {
|
|
316
|
+
const kind = ENTRY_KINDS[format];
|
|
317
|
+
if (!kind) throw new CliError('Choose the entry file inside the ZIP with --entrypoint. No upload reservation was requested.');
|
|
318
|
+
const names = await archiveFileNames(archive, buildLimits(supplied));
|
|
319
|
+
const tops = new Set(names.map(name => name.split('/')[0]));
|
|
320
|
+
const wrapped = names.length > 0 && names.every(name => name.includes('/')) && tops.size === 1;
|
|
321
|
+
const base = wrapped ? `${[...tops][0]}/` : '';
|
|
322
|
+
const level = names.filter(name => name.startsWith(base) && !name.slice(base.length).includes('/'));
|
|
323
|
+
if (kind.preferred && level.includes(base + kind.preferred)) return { entrypoint: base + kind.preferred, reason: wrapped ? 'wrapped-folder' : 'root' };
|
|
324
|
+
const top = level.filter(kind.match);
|
|
325
|
+
if (top.length === 1) return { entrypoint: top[0], reason: wrapped ? 'wrapped-folder' : 'only-top-level' };
|
|
326
|
+
const every = top.length ? top : names.filter(kind.match).sort((a, b) => a.split('/').length - b.split('/').length || a.localeCompare(b));
|
|
327
|
+
if (every.length === 1) return { entrypoint: every[0], reason: 'only-one' };
|
|
328
|
+
if (!every.length && format === 'web' && nativeBuildKind(names)) reject(NATIVE_ADVICE[nativeBuildKind(names)]);
|
|
329
|
+
if (!every.length) throw new CliError(`No ${kind.noun} was found in the archive to start the game from. Check the ZIP holds the exported build, or name the entry file with --entrypoint. No upload reservation was requested.`);
|
|
330
|
+
const listed = every.slice(0, MAX_LISTED).join(', ') + (every.length > MAX_LISTED ? `, and ${every.length - MAX_LISTED} more` : '');
|
|
331
|
+
throw new CliError(`Several files could be the entry file: ${listed}. Choose one with --entrypoint. No upload reservation was requested.`);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/** One plain sentence saying which entry file was chosen and why. */
|
|
335
|
+
export function entrypointChoiceLine({ entrypoint, reason }) {
|
|
336
|
+
const why = { root: 'found at the root of the archive', 'only-top-level': 'the only one at the top of the archive',
|
|
337
|
+
'wrapped-folder': 'inside the one folder that holds the build', 'only-one': 'the only one in the archive' }[reason];
|
|
338
|
+
return `Entry file: ${entrypoint}, ${why}. Pass --entrypoint to choose another.`;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export async function preflightBuildArchive(filename, options = {}) {
|
|
238
342
|
const archive = await openBuildArchive(filename, options);
|
|
239
|
-
try {
|
|
343
|
+
try {
|
|
344
|
+
if (options.entrypoint) return await inspectBuildArchive(archive, options);
|
|
345
|
+
const chosen = await chooseEntrypoint(archive, options);
|
|
346
|
+
return { ...await inspectBuildArchive(archive, { ...options, entrypoint: chosen.entrypoint }), entrypointChosen: chosen.reason };
|
|
347
|
+
} finally { await archive.close(); }
|
|
240
348
|
}
|
|
@@ -19,6 +19,8 @@ export function buildStatusLines(build) {
|
|
|
19
19
|
const state = build?.state === 'deleting' && build.rejection ? 'not accepted, being removed' : (LABELS[build?.state] || line(build?.state) || 'unknown');
|
|
20
20
|
const lines = [`${line(build?.buildId)}${build?.entrypoint ? ` (${line(build.entrypoint)})` : ''}: ${state}.`];
|
|
21
21
|
if (build?.rejection?.message) lines.push(` Why: ${line(build.rejection.message)}`);
|
|
22
|
+
// Waiting for the daily build check limit to reset: the server says when.
|
|
23
|
+
else if (build?.state === 'awaiting_validation' && build.waiting?.message) lines.push(` Waiting: ${line(build.waiting.message)}`);
|
|
22
24
|
else if (build?.state === 'awaiting_validation') lines.push(' Validation is required before a run. Check again in a minute.');
|
|
23
25
|
if (build?.holdReturn?.message) lines.push(` ${line(build.holdReturn.message)}`);
|
|
24
26
|
if (build?.safetyHold) lines.push(' A run of this build was stopped by the safety check, so it cannot be quoted until that hold is cleared.');
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
-
import { mkdir, open } from 'node:fs/promises';
|
|
2
|
+
import { mkdir, open, rm } from 'node:fs/promises';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { Readable } from 'node:stream';
|
|
5
5
|
import { CliError } from '../errors.js';
|
|
6
6
|
import { ApiError } from '../api/errors.js';
|
|
7
7
|
import { writeJson } from '../fsutil.js';
|
|
8
|
-
import {
|
|
8
|
+
import { printable } from '../ui/index.js';
|
|
9
|
+
import { openBuildArchive, inspectBuildArchive, buildLimits, limitsFromProfile, chooseEntrypoint } from './archivePreflight.js';
|
|
9
10
|
|
|
10
11
|
const fail = message => { throw new CliError(message); };
|
|
11
12
|
const base = game => `/api/v1/games/${encodeURIComponent(game)}/playtest/hosted`;
|
|
@@ -42,6 +43,9 @@ export async function putArchive(archive, transfer, { fetchImpl = globalThis.fet
|
|
|
42
43
|
} finally { stream.destroy(); }
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
// Server text is one plain sentence; still print it as one bounded line.
|
|
47
|
+
const serverSentence = text => printable(String(text || '')).replace(/\s+/g, ' ').trim().slice(0, 300);
|
|
48
|
+
|
|
45
49
|
/**
|
|
46
50
|
* The profile to upload under: the one named, or the only one advertised. With
|
|
47
51
|
* several and none named, the error lists them so the person can pick one.
|
|
@@ -92,14 +96,22 @@ export async function uploadHostedBuild({ filename, gameId, profileVersion, entr
|
|
|
92
96
|
if (!offer || offer.amountCents !== 49 || offer.currency !== 'USD' || offer.purpose !== 'validation_hold'
|
|
93
97
|
|| offer.refund !== 'after_cleanup' || !/^[a-f0-9]{64}$/.test(offer.version || '')) fail('The server did not provide the supported validation-hold offer.');
|
|
94
98
|
if (caps.funding?.eligible === false) fail('The server reports insufficient prepaid funding. No reservation or top-up was requested.');
|
|
99
|
+
// Today's build checks are used up: the server would refuse the upload, so
|
|
100
|
+
// say why and when before any archive work or hold.
|
|
101
|
+
if (caps.validationLimit?.available === false) fail(`${serverSentence(caps.validationLimit.message) || 'Your studio has used today\'s build checks. The next one is available at 00:00 UTC.'} No reservation was requested.`);
|
|
95
102
|
const archive = await openBuildArchive(filename, { signal });
|
|
96
103
|
try {
|
|
97
104
|
onProgress({ phase: 'preflight' });
|
|
105
|
+
// No --entrypoint: an index.html at the root, or the only candidate, is
|
|
106
|
+
// used and said so; several candidates are listed, never guessed.
|
|
107
|
+
const chosen = entrypoint ? null : await chooseEntrypoint(archive, { limits, format: profile.format });
|
|
108
|
+
if (chosen) entrypoint = chosen.entrypoint;
|
|
98
109
|
const measurement = await inspectBuildArchive(archive, { limits, format: profile.format, entrypoint, requirements: profile.capacity?.requirements });
|
|
99
110
|
onProgress({ phase: 'hash', completedBytes: 0, totalBytes: archive.size });
|
|
100
111
|
const sha256 = await archive.sha256({ onProgress: (completedBytes, totalBytes) => onProgress({ phase: 'hash', completedBytes, totalBytes }) });
|
|
101
112
|
const prepared = { ...measurement, sha256, profileVersion, limits, capacity: profile.capacity || null,
|
|
102
|
-
validationHoldCents: offer.amountCents, funding: caps.funding || null, gameplayQuoteRequired: true
|
|
113
|
+
validationHoldCents: offer.amountCents, funding: caps.funding || null, gameplayQuoteRequired: true,
|
|
114
|
+
...(chosen ? { entrypointChosen: chosen.reason } : {}) };
|
|
103
115
|
await onPrepared(prepared);
|
|
104
116
|
if (dryRun) return { state: 'preflight_only', ...prepared, walletMutationRequested: false };
|
|
105
117
|
if (!await confirm(`Reserve ${money(offer.amountCents)} from prepaid funds for this build’s static validation? It is returned after safe cleanup and is separate from the gameplay quote.`)) {
|
|
@@ -130,6 +142,13 @@ export async function uploadHostedBuild({ filename, gameId, profileVersion, entr
|
|
|
130
142
|
return { state: state.phase, buildId: state.buildId, journal, walletMutationRequested: true, validationHoldCents: offer.amountCents,
|
|
131
143
|
multipartSupported: false, uploadResumeSupported: false, gameplayStarted: false };
|
|
132
144
|
} catch (error) {
|
|
145
|
+
// A definite refusal before any hold (the server checks the daily build
|
|
146
|
+
// check limit inside the same transaction): nothing to reconcile, so
|
|
147
|
+
// the journal goes and the same upload can be tried after the reset.
|
|
148
|
+
if (error instanceof ApiError && error.code === 'hosted_validation_limit' && state.phase === 'reservation_unknown') {
|
|
149
|
+
await rm(journal, { force: true });
|
|
150
|
+
fail(serverSentence(error.message === error.code ? '' : error.message) || 'Your studio has used today\'s build checks. The next one is available at 00:00 UTC. Nothing was charged.');
|
|
151
|
+
}
|
|
133
152
|
if (error instanceof ApiError && [401, 403].includes(error.status)) {
|
|
134
153
|
error.message += ` Original upload journal: ${journal}; no replacement reservation was requested.`;
|
|
135
154
|
throw error;
|