ravensight-playtest 0.20.2 → 0.21.2

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 CHANGED
@@ -295,7 +295,8 @@ ravensight-playtest login
295
295
 
296
296
  Nothing is downloaded until you need it. Playwright is an optional dependency,
297
297
  so `login`, `check`, `init` and `brief` work without a browser installed;
298
- `run --driver playwright_web` is what asks for one. `keytar` is optional too,
298
+ `run --driver playwright_web` is what asks for one. The keychain module
299
+ (`@napi-rs/keyring`, a prebuilt binary with no install script) is optional too,
299
300
  which is why a machine with no keychain still installs cleanly.
300
301
 
301
302
  ## First run
@@ -310,7 +311,7 @@ ravensight-playtest run # prints the price, asks, then plays
310
311
  ```
311
312
 
312
313
  `login` stores the token in your OS keychain (macOS Keychain, Windows
313
- Credential Manager, libsecret on Linux). With no keychain available it falls
314
+ Credential Manager, the Secret Service on Linux). With no keychain available it falls
314
315
  back to a file with 0600 permissions under your home directory, and says so.
315
316
  In CI, set `RAVENSIGHT_TOKEN` instead and skip `login` entirely.
316
317
 
@@ -379,7 +380,7 @@ stores the token.
379
380
  | `--no-browser` | Do not try to open a browser. `RAVENSIGHT_NO_BROWSER=1` does the same thing. |
380
381
 
381
382
  The token goes in your OS keychain (macOS Keychain, Windows Credential Manager,
382
- libsecret on Linux). With no keychain available it falls back to a file with 0600
383
+ the Secret Service on Linux). With no keychain available it falls back to a file with 0600
383
384
  permissions under `RAVENSIGHT_HOME`, and says which store it used. In CI, set
384
385
  `RAVENSIGHT_TOKEN` and skip `login` entirely.
385
386
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ravensight-playtest",
3
- "version": "0.20.2",
3
+ "version": "0.21.2",
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/",
@@ -75,7 +75,7 @@
75
75
  "commander": "^13.0.0"
76
76
  },
77
77
  "optionalDependencies": {
78
- "keytar": "^7.9.0",
78
+ "@napi-rs/keyring": "^2.1.2",
79
79
  "playwright": "^1.51.0"
80
80
  }
81
81
  }
@@ -1,52 +1,187 @@
1
- import { mkdir } from 'node:fs/promises';
2
- import { unlink } from 'node:fs/promises';
1
+ import { execFile } from 'node:child_process';
2
+ import { mkdir, unlink } from 'node:fs/promises';
3
3
  import { paths } from '../paths.js';
4
4
  import { readJson, writeJson } from '../fsutil.js';
5
5
 
6
6
  export const KEYCHAIN_SERVICE = 'ravensight-playtest';
7
7
  const FILE_MODE = 0o600;
8
8
 
9
- let keytarModule;
10
- let keytarTried = false;
9
+ let backendModule;
10
+ let backendTried = false;
11
+ let service = KEYCHAIN_SERVICE;
11
12
 
12
13
  /**
13
- * `keytar` is a native module, and every realistic reason it is missing is a
14
- * reason the CLI still has to work: it is an optional dependency whose install
15
- * script may not have run, a headless Linux box with no libsecret, or a CI
16
- * container. So it is required lazily, once, inside a try, and a failure means
17
- * "use the file backend" rather than "crash".
14
+ * The OS keychain, through `@napi-rs/keyring`. It ships a prebuilt binary per
15
+ * platform as an optional package, so there is no install script, and every
16
+ * realistic reason it is missing is a reason the CLI still has to work: an
17
+ * optional dependency that was skipped, a platform with no prebuilt binary, a
18
+ * headless Linux box with no Secret Service, or a CI container. So it is loaded
19
+ * lazily, once, inside a try, and a failure means "use the file backend"
20
+ * rather than "crash".
21
+ *
22
+ * On Linux the entry is pinned to the Secret Service. Left to itself the module
23
+ * would fall back to the kernel keyring, which forgets everything at a reboot;
24
+ * a token that vanishes at a reboot is worse than the 0600 file, so a machine
25
+ * with no Secret Service uses the file, as it did before.
18
26
  *
19
27
  * @returns {Promise<object|null>}
20
28
  */
21
- async function keytar() {
22
- if (keytarTried) return keytarModule || null;
23
- keytarTried = true;
29
+ async function keychain() {
30
+ if (backendTried) return backendModule || null;
31
+ backendTried = true;
32
+ try {
33
+ const mod = await import('@napi-rs/keyring');
34
+ backendModule = keyringBackend(mod.default || mod);
35
+ } catch {
36
+ backendModule = null;
37
+ }
38
+ return backendModule;
39
+ }
40
+
41
+ /**
42
+ * Wrap the module in the small shape this file uses, or null when it loaded
43
+ * but cannot work here. Exported for tests, with the platform and the legacy
44
+ * Linux lookup injectable, so every platform's branch runs on any machine.
45
+ *
46
+ * Entries keep the names the CLI used before (service `ravensight-playtest`,
47
+ * account the API host), so on macOS a token stored by the old keychain module
48
+ * is the same Keychain item and is read with no migration at all. Windows and
49
+ * Linux name their entries differently in the two modules, so a token the old
50
+ * module stored is read from its old place when the new one has none, and
51
+ * logout clears both (see `readLegacy` and `deleteLegacy`).
52
+ *
53
+ * @param {object} mod the loaded `@napi-rs/keyring`
54
+ * @param {{platform?: string, secretTool?: Function}} [options]
55
+ * @returns {object|null}
56
+ */
57
+ export function keyringBackend(mod, options = {}) {
58
+ const platform = options.platform || process.platform;
59
+ const { AsyncEntry } = mod || {};
60
+ if (typeof AsyncEntry !== 'function') return null;
61
+ const entryOptions = platform === 'linux' ? { linux: { store: 'secret-service' } } : undefined;
62
+ const entry = (svc, account) => new AsyncEntry(svc, account, entryOptions);
63
+ // An import that resolves but cannot open the store (no Secret Service on
64
+ // Linux) is not a working backend: treat it exactly like an absent module.
65
+ // Making an entry touches no stored item on any platform.
24
66
  try {
25
- const mod = await import('keytar');
26
- const candidate = mod.default || mod;
27
- // An import that resolves but has no getPassword is a broken build, not a
28
- // working backend: treat it exactly like an absent module.
29
- keytarModule = typeof candidate.getPassword === 'function' ? candidate : null;
67
+ entry(service, 'probe');
30
68
  } catch {
31
- keytarModule = null;
69
+ return null;
32
70
  }
33
- return keytarModule;
71
+ const legacy = legacyStore(platform, mod, options.secretTool || secretTool);
72
+ return {
73
+ getPassword: (svc, account) => entry(svc, account).getPassword(),
74
+ setPassword: (svc, account, value) => entry(svc, account).setPassword(value),
75
+ deletePassword: (svc, account) => entry(svc, account).deletePassword(),
76
+ readLegacy: legacy.read,
77
+ deleteLegacy: legacy.remove
78
+ };
79
+ }
80
+
81
+ /**
82
+ * Where the old keychain module (keytar, archived) kept a token on each
83
+ * platform, read and cleared without loading it.
84
+ *
85
+ * - macOS: the same generic password item (service, account), so nothing.
86
+ * - Windows: a generic credential named `<service>/<account>`, holding the
87
+ * token's UTF-8 bytes. The new module names its own `<account>.<service>`.
88
+ * It is found by enumerating that exact name, never by making an entry for
89
+ * it: the module writes an empty secret into a named entry as it makes it,
90
+ * which would wipe the very token being read. The module decodes the bytes
91
+ * as UTF-16, so they are turned back into the bytes and read as UTF-8.
92
+ * - Linux: a Secret Service item with the attributes `service` and `account`,
93
+ * where the new module uses `username`. Read and cleared with `secret-tool`
94
+ * when it is installed; without it the old token is not found and one more
95
+ * login stores it in the new place.
96
+ */
97
+ function legacyStore(platform, mod, runSecretTool) {
98
+ const none = { read: async () => null, remove: async () => false };
99
+ if (platform === 'win32') {
100
+ const { AsyncEntry, findCredentialsAsync } = mod;
101
+ if (typeof findCredentialsAsync !== 'function') return none;
102
+ const target = (svc, account) => `${svc}/${account}`;
103
+ const find = (svc, account) => findCredentialsAsync(svc, target(svc, account));
104
+ return {
105
+ async read(svc, account) {
106
+ const found = (await find(svc, account)).find(c => c && c.account === account);
107
+ return found ? fromWideString(found.password) : null;
108
+ },
109
+ async remove(svc, account) {
110
+ let present;
111
+ try {
112
+ present = (await find(svc, account)).length > 0;
113
+ } catch {
114
+ // Found but unreadable (an odd number of bytes) is still there.
115
+ present = true;
116
+ }
117
+ if (!present) return false;
118
+ return Boolean(await AsyncEntry.withTarget(target(svc, account), svc, account).deleteCredential());
119
+ }
120
+ };
121
+ }
122
+ if (platform === 'linux') {
123
+ const attributes = (svc, account) => ['service', svc, 'account', account];
124
+ return {
125
+ async read(svc, account) {
126
+ const out = await runSecretTool(['lookup', ...attributes(svc, account)]);
127
+ return out ? out.replace(/\r?\n$/, '') || null : null;
128
+ },
129
+ async remove(svc, account) {
130
+ if (!(await runSecretTool(['lookup', ...attributes(svc, account)]))) return false;
131
+ await runSecretTool(['clear', ...attributes(svc, account)]);
132
+ return true;
133
+ }
134
+ };
135
+ }
136
+ return none;
137
+ }
138
+
139
+ /**
140
+ * The token keytar stored on Windows, from the string the new module read it
141
+ * as. A token is printable ASCII, so anything else is not one.
142
+ * @param {string} value
143
+ * @returns {string|null}
144
+ */
145
+ export function fromWideString(value) {
146
+ if (typeof value !== 'string' || !value) return null;
147
+ const decoded = Buffer.from(value, 'utf16le').toString('utf8');
148
+ return /^[\x21-\x7e]+$/.test(decoded) ? decoded : null;
149
+ }
150
+
151
+ /**
152
+ * `secret-tool` with arguments, never a shell. Its stdout, or null when it is
153
+ * not installed, found nothing or failed.
154
+ * @param {string[]} args
155
+ * @returns {Promise<string|null>}
156
+ */
157
+ function secretTool(args) {
158
+ return new Promise(resolve => {
159
+ execFile('secret-tool', args, { timeout: 5000, windowsHide: true }, (error, stdout) => {
160
+ resolve(error ? null : String(stdout || ''));
161
+ });
162
+ });
34
163
  }
35
164
 
36
- /** Test seam: forget the cached probe so a stub can be installed. */
37
- export function resetKeychainProbe(stub) {
38
- keytarTried = stub !== undefined;
39
- keytarModule = stub === undefined ? undefined : stub;
165
+ /**
166
+ * Test seam: forget the cached probe so a stub can be installed, and
167
+ * optionally name a test-only keychain service so a test against the real
168
+ * keychain can never touch the developer's own token.
169
+ */
170
+ export function resetKeychainProbe(stub, testService) {
171
+ backendTried = stub !== undefined;
172
+ backendModule = stub === undefined ? undefined : stub;
173
+ service = testService || KEYCHAIN_SERVICE;
40
174
  }
41
175
 
42
176
  /**
43
- * Which backend is in use, for `check` to report. The OS keychain when keytar
44
- * loaded, otherwise the 0600 file, and `env` is not a backend at all: it is a
45
- * credential this process was handed and will not store.
177
+ * Which backend is in use, for `check` to report. The OS keychain when the
178
+ * keyring module loaded and can open the store, otherwise the 0600 file, and
179
+ * `env` is not a backend at all: it is a credential this process was handed
180
+ * and will not store.
46
181
  * @returns {Promise<'keychain'|'file'>}
47
182
  */
48
183
  export async function backendName() {
49
- return (await keytar()) ? 'keychain' : 'file';
184
+ return (await keychain()) ? 'keychain' : 'file';
50
185
  }
51
186
 
52
187
  async function fileStore() {
@@ -76,15 +211,27 @@ async function writeFileStore(store) {
76
211
  * @returns {Promise<{token: string|null, backend: 'keychain'|'file'|null}>}
77
212
  */
78
213
  export async function readStoredToken(host) {
79
- const kt = await keytar();
80
- if (kt) {
214
+ const kc = await keychain();
215
+ if (kc) {
81
216
  try {
82
- const found = await kt.getPassword(KEYCHAIN_SERVICE, host);
217
+ const found = await kc.getPassword(service, host);
83
218
  if (found) return { token: found, backend: 'keychain' };
84
219
  } catch {
85
220
  // A locked or unavailable keychain falls through to the file, rather than
86
221
  // failing a command that could have worked.
87
222
  }
223
+ if (kc.readLegacy) {
224
+ try {
225
+ // A token the previous keychain module stored, where this one names
226
+ // its entries differently. Read only: it is not copied or moved, so
227
+ // a command that only reads changes nothing, and the next login or
228
+ // logout clears it.
229
+ const legacy = await kc.readLegacy(service, host);
230
+ if (legacy) return { token: legacy, backend: 'keychain' };
231
+ } catch {
232
+ // Same as above: the file is still worth a look.
233
+ }
234
+ }
88
235
  }
89
236
  const store = await fileStore();
90
237
  const entry = store[host];
@@ -109,10 +256,13 @@ export async function getStoredToken(host) {
109
256
  * @returns {Promise<{backend: 'keychain'|'file'}>}
110
257
  */
111
258
  export async function setStoredToken(host, token) {
112
- const kt = await keytar();
113
- if (kt) {
259
+ const kc = await keychain();
260
+ if (kc) {
114
261
  try {
115
- await kt.setPassword(KEYCHAIN_SERVICE, host, token);
262
+ await kc.setPassword(service, host, token);
263
+ // The new token is stored, so an old one the previous module kept for
264
+ // this host is only a stale credential left behind: clear it.
265
+ await deleteLegacy(kc, host);
116
266
  return { backend: 'keychain' };
117
267
  } catch {
118
268
  // Fall through: a token we cannot store is a login the developer has to
@@ -126,20 +276,37 @@ export async function setStoredToken(host, token) {
126
276
  }
127
277
 
128
278
  /**
129
- * Forget the token for one host. Answers whether anything was there, so
130
- * `logout` can tell "revoked and cleared" from "nothing to clear".
279
+ * Clear the previous module's entry for one host, where it differs from this
280
+ * module's. Never throws: a stale entry that could not be cleared must not
281
+ * fail a login or a logout.
282
+ * @returns {Promise<boolean>} whether one was there and is gone
283
+ */
284
+ async function deleteLegacy(kc, host) {
285
+ if (!kc.deleteLegacy) return false;
286
+ try {
287
+ return Boolean(await kc.deleteLegacy(service, host));
288
+ } catch {
289
+ return false;
290
+ }
291
+ }
292
+
293
+ /**
294
+ * Forget the token for one host: this module's keychain entry, the previous
295
+ * module's entry where it differs, and the file. Answers whether anything was
296
+ * there, so `logout` can tell "revoked and cleared" from "nothing to clear".
131
297
  * @param {string} host
132
298
  * @returns {Promise<boolean>}
133
299
  */
134
300
  export async function deleteStoredToken(host) {
135
301
  let removed = false;
136
- const kt = await keytar();
137
- if (kt) {
302
+ const kc = await keychain();
303
+ if (kc) {
138
304
  try {
139
- removed = Boolean(await kt.deletePassword(KEYCHAIN_SERVICE, host));
305
+ removed = Boolean(await kc.deletePassword(service, host));
140
306
  } catch {
141
307
  removed = false;
142
308
  }
309
+ if (await deleteLegacy(kc, host)) removed = true;
143
310
  }
144
311
  const store = await fileStore();
145
312
  if (Object.prototype.hasOwnProperty.call(store, host)) {
package/src/cli.js CHANGED
@@ -264,6 +264,7 @@ export function buildProgram() {
264
264
  .option('--avoid <thing>', 'something every persona stays out of, such as "the settings menu"; up to five times', (v, list) => [...list, v], [])
265
265
  .option('--save <file>', 'a save file every persona starts from, at most 1 MiB; uploaded before the quote, free')
266
266
  .option('--save-target <where>', 'where the game reads the save: localstorage:<key>, godot:user://<path>, idbfs:/<mount>/<path>, or hook (the default: the game reads it through window.RavensightPlaytest.save)')
267
+ .option('--sessions <n>', 'play each persona as 2 or 3 sessions: the game is closed and started again on its own saved data between them, inside the same minutes and price; an uploaded web build only, each session at least 4 minutes')
267
268
  .requiredOption('--output <file>', 'save the original quote and immutable consent here')
268
269
  .option('--game <id>', 'game id, overriding this repo’s configuration')
269
270
  .addOption(new Option('--geri-provider <name>', "Geri's model provider: primary or alternate (ravensight.io/legal/subprocessors names both); unavailable choices are refused").choices(['primary', 'alternate']))
@@ -275,7 +276,7 @@ export function buildProgram() {
275
276
  const { hostedQuote, HOSTED_URL_REFUSAL } = await import('./commands/hosted.js');
276
277
  if (options.url !== undefined || options.buildUrl !== undefined) throw new CliError(HOSTED_URL_REFUSAL, ExitCode.ENVIRONMENT);
277
278
  return hostedQuote(flagsFrom(command.optsWithGlobals(), { build: options.build, profile: options.profile,
278
- persona: options.persona, personas: options.personas, tier: options.tier, minutes: options.minutes, start: options.start, focus: options.focus, avoid: options.avoid, save: options.save, saveTarget: options.saveTarget, output: options.output, game: options.game,
279
+ persona: options.persona, personas: options.personas, tier: options.tier, minutes: options.minutes, start: options.start, focus: options.focus, avoid: options.avoid, sessions: options.sessions, save: options.save, saveTarget: options.saveTarget, output: options.output, game: options.game,
279
280
  geriProvider: options.geriProvider,
280
281
  video: options.video }));
281
282
  }));
@@ -292,6 +293,7 @@ export function buildProgram() {
292
293
  .option('--avoid <thing>', 'something every persona stays out of, such as "the settings menu"; up to five times', (v, list) => [...list, v], [])
293
294
  .option('--save <file>', 'a save file every persona starts from, at most 1 MiB; uploaded before the quote, free')
294
295
  .option('--save-target <where>', 'where the game reads the save: localstorage:<key>, godot:user://<path>, idbfs:/<mount>/<path>, or hook (the default: the game reads it through window.RavensightPlaytest.save)')
296
+ .option('--sessions <n>', 'play each persona as 2 or 3 sessions: the game is closed and started again on its own saved data between them, inside the same minutes and price; an uploaded web build only, each session at least 4 minutes')
295
297
  .option('--game <id>', 'game id, overriding this repo’s configuration')
296
298
  .option('--video', 'save a video of each persona\'s game session in its report')
297
299
  .option('--wait', 'stay until the report is ready, printing each phase change (with or without a saved quote)')
@@ -305,12 +307,12 @@ export function buildProgram() {
305
307
  const { hostedRun, hostedRunDirect, HOSTED_URL_REFUSAL } = await import('./commands/hosted.js');
306
308
  if (options.url !== undefined || options.buildUrl !== undefined) throw new CliError(HOSTED_URL_REFUSAL, ExitCode.ENVIRONMENT);
307
309
  if (filename) {
308
- const extra = ['build', 'nativeBuild', 'persona', 'personas', 'tier', 'minutes', 'start', 'save', 'saveTarget', 'game', 'video'].filter(name => options[name] !== undefined).concat(['focus', 'avoid'].filter(name => options[name]?.length));
310
+ const extra = ['build', 'nativeBuild', 'persona', 'personas', 'tier', 'minutes', 'start', 'sessions', 'save', 'saveTarget', 'game', 'video'].filter(name => options[name] !== undefined).concat(['focus', 'avoid'].filter(name => options[name]?.length));
309
311
  if (extra.length) throw new CliError(`A saved quote already fixes its build, personas and options. Drop --${extra.map(name => name.replace(/[A-Z]/g, c => `-${c.toLowerCase()}`)).join(', --')}, or run "hosted run" without a quote file.`);
310
312
  return hostedRun(filename, flagsFrom(command.optsWithGlobals(), { wait: options.wait, waitForCapacity: options.waitForCapacity,
311
313
  evenIfUnknown: options.evenIfUnknown }));
312
314
  }
313
- return hostedRunDirect(flagsFrom(command.optsWithGlobals(), { build: options.build, nativeBuild: options.nativeBuild, persona: options.persona, personas: options.personas, tier: options.tier, minutes: options.minutes, start: options.start, focus: options.focus, avoid: options.avoid, save: options.save, saveTarget: options.saveTarget, game: options.game,
315
+ return hostedRunDirect(flagsFrom(command.optsWithGlobals(), { build: options.build, nativeBuild: options.nativeBuild, persona: options.persona, personas: options.personas, tier: options.tier, minutes: options.minutes, start: options.start, focus: options.focus, avoid: options.avoid, sessions: options.sessions, save: options.save, saveTarget: options.saveTarget, game: options.game,
314
316
  video: options.video, wait: options.wait, waitForCapacity: options.waitForCapacity, evenIfUnknown: options.evenIfUnknown }));
315
317
  }));
316
318
  common(hosted.command('status [run-id]'))
@@ -463,7 +463,7 @@ export async function runChecks(flags = {}, deps = {}) {
463
463
  'pass',
464
464
  storeDetail(),
465
465
  source === 'file' || (source === null && backend === 'file')
466
- ? 'install libsecret for a real keychain on Linux'
466
+ ? 'on Linux, run a Secret Service (GNOME Keyring or KWallet) for a real keychain'
467
467
  : null
468
468
  ));
469
469
 
@@ -18,12 +18,12 @@ import { ANDROID_FORMAT, ANDROID_UNAVAILABLE, ANDROID_UNAVAILABLE_CODE, androidP
18
18
  /** Machine output names a Geri provider by its role, never by the server's wire id. */
19
19
  const printJson = value => ui.json(providerRoles(value));
20
20
 
21
- /** --tier, --minutes, --start, --focus and --avoid as the quote request takes them. */
21
+ /** --tier, --minutes, --start, --focus, --avoid and --sessions as the quote request takes them. */
22
22
  export function scopeFrom(flags = {}) {
23
23
  const minutes = flags.minutes === undefined ? undefined : Number(flags.minutes);
24
- const named = flags.start !== undefined || (flags.focus || []).length || (flags.avoid || []).length;
24
+ const named = flags.start !== undefined || (flags.focus || []).length || (flags.avoid || []).length || flags.sessions !== undefined;
25
25
  return { ...(flags.tier ? { tier: flags.tier } : {}), ...(minutes !== undefined ? { minutes } : {}),
26
- ...(named ? { focus: focusFor({ start: flags.start, focus: flags.focus || [], avoid: flags.avoid || [] }) } : {}) };
26
+ ...(named ? { focus: focusFor({ start: flags.start, focus: flags.focus || [], avoid: flags.avoid || [], sessions: flags.sessions }) } : {}) };
27
27
  }
28
28
 
29
29
  /**
@@ -77,6 +77,7 @@ export function assertNativeRunFlags(flags = {}) {
77
77
  if (flags.start !== undefined || flags.save !== undefined || flags.saveTarget !== undefined) {
78
78
  throw new CliError(ANDROID_FOCUS_REFUSAL, ExitCode.ENVIRONMENT);
79
79
  }
80
+ if (flags.sessions !== undefined) throw new CliError('A cloud playtest of an Android build plays as one session: drop --sessions. Nothing was uploaded or charged.', ExitCode.ENVIRONMENT);
80
81
  }
81
82
 
82
83
  /**
@@ -94,13 +94,15 @@ export async function readHostedQuote(filename) {
94
94
  */
95
95
  export const TIERS = Object.freeze(['jam', 'small', 'medium', 'large']);
96
96
  const plainLine = value => typeof value === 'string' && value.trim().length > 0 && value.length <= 200 && !/[\u0000-\u001f\u007f]/.test(value);
97
- /** The focus block: a start query or hash, and up to five focus and avoid lines. */
98
- export function focusFor({ start, focus = [], avoid = [] } = {}) {
97
+ /** The focus block: a start query or hash, up to five focus and avoid lines, and the sessions a persona plays (2 or 3). */
98
+ export function focusFor({ start, focus = [], avoid = [], sessions } = {}) {
99
99
  if (start !== undefined && start !== null && start !== '' && (typeof start !== 'string' || !/^[?#][^\s\\]{0,199}$/.test(start))) fail('Choose --start as a query or hash on the build, such as ?level=3 or #boss.');
100
100
  for (const [name, list] of [['--focus', focus], ['--avoid', avoid]]) {
101
101
  if (!Array.isArray(list) || list.length > 5 || !list.every(plainLine)) fail(`Give ${name} at most five times, each plain text of at most 200 characters.`);
102
102
  }
103
- return { ...(start ? { start } : {}), focus: focus.map(x => x.trim()), avoid: avoid.map(x => x.trim()) };
103
+ const n = sessions === undefined || sessions === null ? 1 : Number(sessions);
104
+ if (!Number.isSafeInteger(n) || n < 1 || n > 3) fail('Choose --sessions as 1, 2 or 3.');
105
+ return { ...(start ? { start } : {}), focus: focus.map(x => x.trim()), avoid: avoid.map(x => x.trim()), ...(n > 1 ? { sessions: n } : {}) };
104
106
  }
105
107
 
106
108
  /** Why a cloud playtest of an Android build takes no --start, --save or --save-target. Its --focus and --avoid goals are taken. */
@@ -157,6 +159,7 @@ function requestFor({ buildId, profileVersion, personas, controllers = COMBINED,
157
159
  // An Android build plays on a device with its network off and has no web address: no start and no save. Its goals,
158
160
  // --focus and --avoid, are taken as on any combined playtest (the server's focus block).
159
161
  if (profile.driver === ANDROID_DRIVER && focus !== undefined && (focus.start || focus.save)) fail(ANDROID_FOCUS_REFUSAL);
162
+ if (profile.driver === ANDROID_DRIVER && focus?.sessions) fail('A cloud playtest of an Android build plays as one session: drop --sessions. Nothing was charged.');
160
163
  return { kind: 'recorded_graphical', buildId, personas: [...list], controllers: [...controllers],
161
164
  driver: profile.driver, runLength: 'standard', profileVersion, includeVideo, includeTranscript,
162
165
  ...(standardProvider === undefined ? {} : { standardProvider }),
@@ -270,6 +273,7 @@ export function hostedQuoteLines(offer) {
270
273
  ...(focus.save ? [`Start from the save file: ${printable(String(focus.save.name))} (${Number(focus.save.bytes) || 0} bytes), ${focus.save.target?.kind === 'hook' ? 'read by the game through the playtest save hook' : focus.save.target?.kind === 'local_storage' ? 'placed in local storage before the game loads' : 'placed in the game\'s browser file storage before the game loads'}.`] : []),
271
274
  ...(focus.focus?.length ? [`Focus: ${focus.focus.map(printable).join('; ')}`] : []),
272
275
  ...(focus.avoid?.length ? [`Avoid: ${focus.avoid.map(printable).join('; ')}`] : []),
276
+ ...(Number.isSafeInteger(focus.sessions) && focus.sessions > 1 ? [`Sessions: ${focus.sessions} per persona, the game closed and started again on its own saved data between them, inside the same minutes and price.`] : []),
273
277
  ...(r.standardProvider ? [`Geri's model provider: ${providerLabel(r.standardProvider)}; policy ${q.standardProviderPolicyHash}.`] : []),
274
278
  ...personaPrices(q, r).map(row => `${row.persona}${row.persona === ALWAYS_INCLUDED_PERSONA ? ' (always included)' : ''}: ${money(row.priceCents)}.`),
275
279
  ...(q.setupFeeCents ? [`Includes a non-refundable setup fee: ${money(q.setupFeeCents)} (${money(q.setupFeeCents / r.personas.length)} a persona). It is kept even when a persona is refunded, unless it never got a machine.`] : []),
@@ -34,7 +34,9 @@ export function hostedPlaytestStatus(admission, job = null, runs = [], now = Dat
34
34
  let detail = 'Waiting for hosted capacity.';
35
35
 
36
36
  if (CANCELED.has(jobState) || CANCELED.has(admissionState)) {
37
- phase = 'canceled'; label = 'Canceled'; detail = 'The hosted run was canceled.';
37
+ phase = 'canceled'; label = 'Canceled';
38
+ // A cancel the platform made itself (no machine could be started) says why, in the server's own words.
39
+ detail = (admission.canceledBy === 'platform' && boundedReason(admission.cancelReason)) || 'The hosted run was canceled.';
38
40
  } else if (FAILED.has(jobState) || FAILED.has(admissionState) || job?.summary_report === 'failed') {
39
41
  phase = 'failed'; label = 'Failed'; detail = 'The hosted run stopped before a report was ready.';
40
42
  } else if (job?.summary_report === 'ready' || admissionState === 'recorded_closed') {