ravensight-playtest 0.10.1 → 0.10.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ravensight-playtest",
3
- "version": "0.10.1",
3
+ "version": "0.10.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",
@@ -17,7 +17,10 @@ import { WEBDRIVER_NAMES } from '../run/drivers/webdriver.js';
17
17
  import { inspectNativeBuild, probeAutomation, platformWords } from '../run/drivers/webdriver-probe.js';
18
18
  import { CHECK_PLAYTEST_IDENTITY, DEFAULT_VIEWPORT, WEB_OBSERVATION_MAX_CHARS, injectPlaytestIdentity, measureSnapshot, readSnapshot } from '../run/drivers/web.js';
19
19
  import { inspectReadiness } from '../run/readiness.js';
20
+ import { isGodotProject } from '../run/drivers/godot-project.js';
20
21
  import path from 'node:path';
22
+ import { readFileSync } from 'node:fs';
23
+ import { createRequire } from 'node:module';
21
24
 
22
25
  export const NODE_MIN_MAJOR = 22;
23
26
  const DISK_WARN_BYTES = 2 * 1024 * 1024 * 1024;
@@ -30,6 +33,39 @@ const plural = (count, noun) => `${count} ${noun}${count === 1 ? '' : 's'}`;
30
33
  /** The two commands that make the playwright_web driver work. */
31
34
  export const BROWSER_FIX = 'npm i -D playwright && npx playwright install chromium';
32
35
 
36
+ /**
37
+ * The version of the Playwright this tool launches its browser with (its own
38
+ * optional dependency, resolved from here as the web driver resolves it), or
39
+ * null when it is not installed.
40
+ *
41
+ * @param {{resolve?: (id: string) => string, read?: (file: string) => string}} [seams]
42
+ * @returns {string|null}
43
+ */
44
+ export function playwrightVersion({ resolve = createRequire(import.meta.url).resolve, read = file => readFileSync(file, 'utf8') } = {}) {
45
+ try {
46
+ const version = JSON.parse(read(resolve('playwright/package.json'))).version;
47
+ return /^\d+\.\d+\.\d+/.test(String(version || '')) ? version : null;
48
+ } catch {
49
+ return null;
50
+ }
51
+ }
52
+
53
+ /**
54
+ * The one line that fixes a browser that will not start. Playwright itself
55
+ * missing needs it installed; Playwright present with its browser build
56
+ * missing (the 0.10.1 run that wanted chromium_headless_shell-1255) needs that
57
+ * exact Playwright's own browser, which a plain `npx playwright` from another
58
+ * folder may not install.
59
+ *
60
+ * @param {string} detail what the launch said
61
+ * @param {string|null} [version] see {@link playwrightVersion}
62
+ * @returns {string}
63
+ */
64
+ export function browserFixFor(detail, version = playwrightVersion()) {
65
+ if (/Cannot find (?:package|module) '?playwright/i.test(String(detail || '')) || !version) return BROWSER_FIX;
66
+ return `npx -y playwright@${version} install chromium`;
67
+ }
68
+
33
69
  /**
34
70
  * The repo config, for deciding whether this is a web game. A config that
35
71
  * cannot be read is reported by the rows that need it, not here.
@@ -49,23 +85,28 @@ async function configForBrowser(flags) {
49
85
  /**
50
86
  * How much a missing browser matters here, or null when the row is skipped.
51
87
  *
52
- * `fail` when `--web` asks for it or the linked build is a URL: a web run
53
- * cannot start without one. `warn` when only the configured driver says
54
- * `playwright_web` and no build is linked yet, because that is the untouched
55
- * default `init` writes, and a Godot developer who never changed it must not
56
- * get exit 3 over a browser they will never launch. Skipped otherwise.
88
+ * `fail` when `--web` asks for it, the linked build is a URL, or the
89
+ * configured driver is `playwright_web` with no other build linked: the next
90
+ * run here is a web run, and it cannot start without one (a --build-dir run
91
+ * of 0.10.1 was charged, failed at the browser launch and was refunded while
92
+ * this row only warned). `warn` only for that untouched default in a Godot
93
+ * project (an `init` from before it chose godot_driver for one), whose
94
+ * developer must not get exit 3 over a browser they will never launch.
95
+ * Skipped otherwise.
57
96
  *
58
97
  * @param {Object} flags
59
98
  * @param {Object|null} config
99
+ * @param {{godotRepo?: boolean}} [where]
60
100
  * @returns {'fail'|'warn'|null}
61
101
  */
62
- export function browserSeverity(flags, config) {
102
+ export function browserSeverity(flags, config, { godotRepo = false } = {}) {
63
103
  if (flags.web) return 'fail';
64
104
  if (!config) return null;
65
105
  const kind = config.build && config.build.kind;
66
106
  if (kind === 'url') return 'fail';
67
107
  if (kind) return null;
68
- return config.driver === 'playwright_web' ? 'warn' : null;
108
+ if (config.driver !== 'playwright_web') return null;
109
+ return godotRepo ? 'warn' : 'fail';
69
110
  }
70
111
 
71
112
  /** How long `check` waits for a web build's first screen before it warns instead. */
@@ -647,7 +688,7 @@ export async function runChecks(flags = {}, deps = {}) {
647
688
  'needed only to re-encode a session video before upload'
648
689
  ));
649
690
 
650
- const browserNeed = browserSeverity(flags, await configForBrowser(flags));
691
+ const browserNeed = browserSeverity(flags, await configForBrowser(flags), { godotRepo: await isGodotProject(repoRoot).catch(() => false) });
651
692
  if (browserNeed) {
652
693
  const firstScreenUrl = plan.driverName === 'playwright_web' && /^https?:\/\//i.test(String(plan.target || '')) ? plan.target : null;
653
694
  const probe = await probeBrowser(deps.importer, { url: firstScreenUrl, timeoutMs: deps.firstScreenTimeoutMs });
@@ -655,7 +696,7 @@ export async function runChecks(flags = {}, deps = {}) {
655
696
  'browser',
656
697
  probe.ok ? 'pass' : browserNeed,
657
698
  probe.detail,
658
- probe.ok ? null : BROWSER_FIX
699
+ probe.ok ? null : browserFixFor(probe.detail, deps.playwrightVersion !== undefined ? deps.playwrightVersion : playwrightVersion())
659
700
  ));
660
701
  if (probe.firstScreen) {
661
702
  rows.push(await firstScreenRow(probe.firstScreen, firstScreenUrl, { authed, gameId, priced }));
@@ -25,7 +25,7 @@ import { jobDir, runDir as runDirFor, JOB_FILES, RUN_FILES } from '../run/paths.
25
25
  import { capabilityNoteLines } from '../run/readiness.js';
26
26
  import { readBridgeConfig } from "../run/drivers/stdio.js";
27
27
  import { WEBDRIVER_NAMES, readDriverConfig } from '../run/drivers/webdriver.js';
28
- import { BROWSER_FIX, automationChecks } from './check.js';
28
+ import { BROWSER_FIX, automationChecks, probeBrowser, browserFixFor, playwrightVersion } from './check.js';
29
29
  import { runPersona } from '../run/personaLoop.js';
30
30
  import { runModelBudgetUsd } from '../run/budgetReserve.js';
31
31
  import { missingScopeMessage, missingScopes } from '../auth/scopes.js';
@@ -197,6 +197,11 @@ async function run(flags, injected, deps, log) {
197
197
  log(noGodot);
198
198
  return EXIT.ENVIRONMENT;
199
199
  }
200
+ const noBrowser = await browserRefusal({ driverName, injected });
201
+ if (noBrowser) {
202
+ log(noBrowser);
203
+ return EXIT.ENVIRONMENT;
204
+ }
200
205
 
201
206
  // `aggregate_report` is asked for explicitly: it is what buys the run the
202
207
  // `aggregate.*` steps are spendable from, and it is free (the price list has
@@ -1553,6 +1558,29 @@ export async function godotRefusal({ driverName, godotPath, projectDir, injected
1553
1558
  }
1554
1559
  }
1555
1560
 
1561
+ /**
1562
+ * Why a web run cannot start its browser, or null when it can. Checked before
1563
+ * anything is priced or registered: 0.10.1 registered and charged a
1564
+ * --build-dir run, failed it at the browser launch (its Playwright wanted
1565
+ * chromium_headless_shell-1255, which was not installed) and refunded it.
1566
+ * Launching headless Chromium and closing it is what `check` does, so the
1567
+ * answer is the same one, with the one line that installs this tool's own
1568
+ * browser.
1569
+ *
1570
+ * @param {{driverName: string, injected?: Object}} input
1571
+ * @returns {Promise<string|null>}
1572
+ */
1573
+ export async function browserRefusal({ driverName, injected = {} }) {
1574
+ if (driverName !== 'playwright_web') return null;
1575
+ // A test with its own driver has no use for a real browser.
1576
+ const probe = injected.browserProbe || (injected.driverFactory ? null : probeBrowser);
1577
+ if (!probe) return null;
1578
+ const result = await probe(injected.importer);
1579
+ if (result.ok) return null;
1580
+ const fix = browserFixFor(result.detail, injected.playwrightVersion !== undefined ? injected.playwrightVersion : playwrightVersion());
1581
+ return `The browser a web run needs could not start (${String(result.detail || 'it did not launch').slice(0, 240)}). Install it with this one line, then run again: ${fix}\nNothing was registered or charged.`;
1582
+ }
1583
+
1556
1584
  /**
1557
1585
  * Resolve the context, the game and the credential, or answer with an exit
1558
1586
  * code. Shared with `profile`.